-
Notifications
You must be signed in to change notification settings - Fork 3
New Documentation for vaults contracts #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
0f54412
4bb50fe
3319c5b
9827431
7f248ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
| */ | ||
| function checkAsset(IInvestStrategy strategy, address asset) internal view { | ||
| if (strategy.asset(address(this)) != asset) revert InvalidStrategyAsset(); | ||
| } | ||
|
|
@@ -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. | ||
|
||
| */ | ||
| 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)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); | ||
|
|
@@ -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++) { | ||
|
|
@@ -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; | ||
|
|
@@ -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. | ||
|
||
| * 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; | ||
|
|
@@ -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; | ||
|
|
@@ -333,6 +356,9 @@ abstract contract MSVBase is IExposeStorage { | |
| return amount; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Returns the list of strategies in the vault in order. | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
||
| */ | ||
| 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
||
| */ | ||
| 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. | ||
|
||
| */ | ||
| function makeOutflowSlot(uint256 slotSize, uint40 timestamp) external pure returns (SlotIndex) { | ||
| return SlotIndex.wrap((slotSize << 128) + timestamp / slotSize); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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...