Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions contracts/CompoundV3InvestStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,44 @@ contract CompoundV3InvestStrategy is IInvestStrategy {
_baseToken = cToken_.baseToken();
}

/// @inheritdoc IInvestStrategy
function connect(bytes memory initData) external virtual override onlyDelegCall {
_setSwapConfig(SwapLibrary.SwapConfig(SwapLibrary.SwapProtocol.undefined, 0, bytes("")), initData);
}

/// @inheritdoc IInvestStrategy
function disconnect(bool force) external virtual override onlyDelegCall {
if (!force && _cToken.balanceOf(address(this)) != 0) revert CannotDisconnectWithAssets();
}

/// @inheritdoc IInvestStrategy
function maxWithdraw(address contract_) public view virtual override returns (uint256) {
if (_cToken.isWithdrawPaused()) return 0;
return _cToken.balanceOf(contract_);
}

/// @inheritdoc IInvestStrategy
function maxDeposit(address /*contract_*/) public view virtual override returns (uint256) {
if (_cToken.isSupplyPaused()) return 0;
return type(uint256).max;
}

/// @inheritdoc IInvestStrategy
function asset(address) public view virtual override returns (address) {
return _baseToken;
}

/// @inheritdoc IInvestStrategy
function totalAssets(address contract_) public view virtual override returns (uint256 assets) {
return _cToken.balanceOf(contract_);
}

/// @inheritdoc IInvestStrategy
function withdraw(uint256 assets) external virtual override onlyDelegCall {
_cToken.withdraw(_baseToken, assets);
}

/// @inheritdoc IInvestStrategy
function deposit(uint256 assets) external virtual override onlyDelegCall {
_supply(assets);
}
Expand Down Expand Up @@ -118,6 +126,7 @@ contract CompoundV3InvestStrategy is IInvestStrategy {
StorageSlot.getBytesSlot(storageSlot).value = newSwapConfigAsBytes;
}

/// @inheritdoc IInvestStrategy
function forwardEntryPoint(uint8 method, bytes memory params) external onlyDelegCall returns (bytes memory) {
ForwardMethods checkedMethod = ForwardMethods(method);
if (checkedMethod == ForwardMethods.harvestRewards) {
Expand Down
18 changes: 17 additions & 1 deletion contracts/InvestStrategyClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ library InvestStrategyClient {
return
address(strategy).functionDelegateCall(abi.encodeCall(IInvestStrategy.forwardEntryPoint, (method, extraData)));
}

/**
* @dev Checks if the asset given is the correct one for the strategy detailed.
* @param strategy Strategy to be checked.
* @param asset Assets of the strategy to be checked.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Está mal la descripción...

  /**
   * @dev Checks the strategy asset() to ensure it is the same as the asset of the vault.
   * @param strategy Strategy to be checked.
   * @param asset Asset of the vault.
   */

*/
function checkAsset(IInvestStrategy strategy, address asset) internal view {
if (strategy.asset(address(this)) != asset) revert InvalidStrategyAsset();
}
Expand Down Expand Up @@ -104,14 +108,26 @@ library InvestStrategyClient {
return keccak256(abi.encode("co.ensuro.InvestStrategyClient", strategy));
}

/**
* @dev Returns the current assets in the strategy given.
* @param strategy Strategy to be checked.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cambiar a

  /**
   * @dev Returns the total assets in the strategy given.
   *
   * See {IInvestStrategy.totalAssets()}
   */

Es decir, sacar la descripción de los parámetros (que igual está incompleta, porque te falta documentar el valor de retorno) y hacer referencia al método de IInvestStrategy que se llama.

*/
function totalAssets(IInvestStrategy strategy) internal view returns (uint256) {
return strategy.totalAssets(address(this));
}

/**
* @dev Returns the maximum amount of assets that can be deposited in the strategy.
* @param strategy Strategy to be checked.
*/
function maxDeposit(IInvestStrategy strategy) internal view returns (uint256) {
return strategy.maxDeposit(address(this));
}

/**
* @dev Returns the maximum amount of assets that can be withdrawn from the strategy.
* @param strategy Strategy to be checked.
*/
function maxWithdraw(IInvestStrategy strategy) internal view returns (uint256) {
return strategy.maxWithdraw(address(this));
}
Expand Down
28 changes: 27 additions & 1 deletion contracts/MSVBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ abstract contract MSVBase is IExposeStorage {
return ret;
}

/**
* @dev For each strategy in the deposit queue, calculates the max deposit and sum it up to finally return the total assets could be deposited.
*/
function _maxDepositable() internal view returns (uint256 ret) {
for (uint256 i; address(_strategies[i]) != address(0) && i < MAX_STRATEGIES; i++) {
uint256 maxDep = _strategies[i].maxDeposit();
Expand All @@ -103,12 +106,20 @@ abstract contract MSVBase is IExposeStorage {
return ret;
}

/**
* @dev Sum up the total assets of each strategy in the vault and returns the total value.
*/
function _totalAssets() internal view returns (uint256 assets) {
for (uint256 i; address(_strategies[i]) != address(0) && i < MAX_STRATEGIES; i++) {
assets += _strategies[i].totalAssets();
}
}

/**
* @dev Withdraw assets from the strategies in the withdraw queue order until zero assets remains to be withdrawn.
* After finishing the withdraw, left must be zero, otherwise reverts, and should never happen.
* @param assets The amount of assets to be withdrawn from the strategies.
*/
function _withdrawFromStrategies(uint256 assets) internal {
uint256 left = assets;
for (uint256 i; left != 0 && _withdrawQueue[i] != 0 && i < MAX_STRATEGIES; i++) {
Expand All @@ -121,6 +132,11 @@ abstract contract MSVBase is IExposeStorage {
if (left != 0) revert WithdrawError(); // This shouldn't happen, since assets must be <= maxWithdraw(owner)
}

/**
* @dev Deposit assets to the strategies in the deposit queue order until zero assets remains to be deposited.
* After finishing the deposit, left must be zero, otherwise reverts, and should never happen.
* @param assets The amount of assets to be deposited to the strategies.
*/
function _depositToStrategies(uint256 assets) internal {
// Transfers the assets from the caller and supplies to compound
uint256 left = assets;
Expand Down Expand Up @@ -281,7 +297,10 @@ abstract contract MSVBase is IExposeStorage {
strategy.dcDisconnect(force);
emit StrategyRemoved(strategy, strategyIndex);
}

/**
* @dev Updated the deposit queue with a new one.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates

Documentar además los eventos que se emiten.

Documentar el parámetro y qué requisitos se esperan de ese parámetro, por ejemplo que sea igual a la cantidad de estrategias que hay, y que los índices sean desde 0 para referirse a la primer estrategia, etc. etc.

* It verifies the length of the new queue and that there are no address(0) strategies.
*/
function changeDepositQueue(uint8[] memory newDepositQueue_) public virtual {
bool[MAX_STRATEGIES] memory seen;
uint256 i = 0;
Expand All @@ -297,6 +316,10 @@ abstract contract MSVBase is IExposeStorage {
emit DepositQueueChanged(newDepositQueue_);
}

/**
* @dev Updated the withdraw queue with a new one.
* It verifies the length of the new queue and that there are no address(0) strategies.
*/
function changeWithdrawQueue(uint8[] memory newWithdrawQueue_) public virtual {
bool[MAX_STRATEGIES] memory seen;
uint8 i = 0;
Expand Down Expand Up @@ -333,6 +356,9 @@ abstract contract MSVBase is IExposeStorage {
return amount;
}

/**
* @dev Returns the list of strategies in the vault in order.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indicar que el valor devuelto va a tener las estrategias instaladas y que a partir de la primera que es address(0) el resto son 0.

function strategies() external view returns (IInvestStrategy[MAX_STRATEGIES] memory) {
return _strategies;
}
Expand Down
16 changes: 16 additions & 0 deletions contracts/OutflowLimitedAMMSV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,34 @@ contract OutflowLimitedAMMSV is AccessManagedMSV {
emit LimitChanged(slotSize, limit);
}

/**
* @dev Returns the current time slot size in seconds.
*/
function getOutflowLimitSlotSize() external view returns (uint256) {
return _getLOMStorage().slotSize;
}

/**
* @dev Returns the current withdraw limit for each slot.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns the net outflow limit that will be applied on two consecutive time slots

*/
function getOutflowLimit() external view returns (uint256) {
return _getLOMStorage().limit;
}

/**
* @dev Returns the current delta variation in assets for the given slot.
* Calculated as the sum of limit + deposits - withdrawals.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Qué es lo de limit? Sería deposits - withdrawals...

* @param slot The given slot to check the delta.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En la documentación del parámetro slot de tipo SlotIndex, indicá que es un valor compatible con el generado con makeOutflowSlot

*/
function getAssetsDelta(SlotIndex slot) external view returns (int256) {
return _getLOMStorage().assetsDelta[slot];
}

/**
* @dev Returns a slot calculated by the slotSize and the timestamp. This slot is the one used for example in getAssetsDelta.
* @param slotSize The size of the slot we want to calculate.
* @param timestamp The slot timestamp tried to be calculated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@return The resulting value is the combination of the slotSize (first 128 bits) and the index of the timestamp / slotSize

*/
function makeOutflowSlot(uint256 slotSize, uint40 timestamp) external pure returns (SlotIndex) {
return SlotIndex.wrap((slotSize << 128) + timestamp / slotSize);
}
Expand Down
6 changes: 6 additions & 0 deletions contracts/SwapStableInvestStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,27 @@ contract SwapStableInvestStrategy is IInvestStrategy {
return 10 ** (18 - token.decimals());
}

/// @inheritdoc IInvestStrategy
function connect(bytes memory initData) external virtual override onlyDelegCall {
_setSwapConfig(SwapLibrary.SwapConfig(SwapLibrary.SwapProtocol.undefined, 0, bytes("")), initData);
}

/// @inheritdoc IInvestStrategy
function disconnect(bool force) external virtual override onlyDelegCall {
if (!force && _investAsset.balanceOf(address(this)) != 0) revert CannotDisconnectWithAssets();
}

/// @inheritdoc IInvestStrategy
function maxWithdraw(address contract_) public view virtual override returns (uint256) {
return totalAssets(contract_); // TODO: check how much can be swapped without breaking the slippage
}

/// @inheritdoc IInvestStrategy
function maxDeposit(address /*contract_*/) public view virtual override returns (uint256) {
return type(uint256).max; // TODO: check how much can be swapped without breaking the slippage
}

/// @inheritdoc IInvestStrategy
function asset(address) public view virtual override returns (address) {
return address(_asset);
}
Expand All @@ -95,6 +100,7 @@ contract SwapStableInvestStrategy is IInvestStrategy {
) / _toWadFactor(_asset);
}

/// @inheritdoc IInvestStrategy
function totalAssets(address contract_) public view virtual override returns (uint256 assets) {
return _convertAssets(_investAsset.balanceOf(contract_), contract_);
}
Expand Down
Loading