Vault.sol
Implementation of the {IVault} interface.
All vault instances are meant to be deployed via the Controller as a proxy and will not be recognizable by the Spool if they are not done so. The vault contract is capable of supporting a single currency underlying asset and deposit to multiple strategies at once, including dual-collateral ones. The vault also supports the additional distribution of extra reward tokens as an incentivization mechanism proportionate to each user's deposit amount within the vhe vault. Vault implementation consists of following contracts: 1. VaultImmutable: reads vault specific immutable variable from vault proxy contract 2. VaultBase: holds vault state variables and provides some of the common vault functions 3. RewardDrip: distributes vault incentivized rewards to users participating in the vault 4. VaultIndexActions: implements functions to synchronize the vault with central Spool contract 5. VaultRestricted: exposes functions restricted for other Spool specific contracts 6. Vault: exposes unrestricted functons to interact with the core vault functionality (deposit/withdraw/claim)
function addToken(contract IERC20 token, uint32 rewardsDuration, uint256 reward) external nonpayable
Allows a new token to be added to the reward system
Emits an {TokenAdded} event indicating the newly added reward token and configuration Requirements: - the caller must be the reward distributor - the reward duration must be non-zero - the token must not have already been added
Name | Type | Description |
---|---|---|
token | contract IERC20 | undefined |
rewardsDuration | uint32 | undefined |
reward | uint256 | undefined |
function claim(bool doRedeemVault, address[] vaultStrategies, bool doRedeemUser) external nonpayable returns (uint128 claimAmount)
Allows a user to claim their debt from the vault after withdrawn shares were processed.
Fee is taken from the profit Perform redeem on user demand Emits a {DebtClaim} event indicating the debt the user claimed. Requirements: - if
doRedeemVault
is true, the provided strategies must be valid - the caller must have a non-zero debt owed - the system should not be paused (if doRedeemVault)Name | Type | Description |
---|---|---|
doRedeemVault | bool | flag, to execute redeem for the vault (synchronize deposit/withdrawals with the system) |
vaultStrategies | address[] | vault stratigies |
doRedeemUser | bool | flag, to execute redeem for the caller |
Name | Type | Description |
---|---|---|
claimAmount | uint128 | amount of underlying asset, claimed by the caller |
function claimFinishedRewards(contract IERC20 token, uint256 amount) external nonpayable
Claim reward tokens
This is meant to be an emergency function to claim reward tokens. Users that have not claimed yet will not be able to claim as the rewards will be removed. Requirements: - the caller must be Spool DAO - cannot claim vault underlying token - cannot only execute if the reward finished
Name | Type | Description |
---|---|---|
token | contract IERC20 | Token address to remove |
amount | uint256 | Amount of tokens to claim |
function controller() external view returns (contract IController)
The controller contract that is consulted for a strategy's and vault's validity
Name | Type | Description |
---|---|---|
_0 | contract IController | undefined |
function deposit(address[] vaultStrategies, uint128 amount, bool transferFromVault) external nonpayable
Allows a user to perform a particular deposit to the vault.
Emits a {Deposit} event indicating the amount newly deposited for index. Perform redeem if possible: - Vault: Index has been completed (sync deposits/withdrawals) - User: Claim deposit shares or withdrawn amount Requirements: - the provided strategies must be valid - the caller must have pre-approved the contract for the token amount deposited - the caller cannot deposit zero value - the system should not be paused
Name | Type | Description |
---|---|---|
vaultStrategies | address[] | strategies of this vault (verified internally) |
amount | uint128 | amount to deposit |
transferFromVault | bool | if the transfer should occur from the funds transfer(controller) address |
function earned(contract IERC20 token, address account) external view returns (uint256)
Name | Type | Description |
---|---|---|
token | contract IERC20 | undefined |
account | address | undefined |
Name | Type | Description |
---|---|---|
_0 | uint256 | undefined |
function forceRemoveReward(contract IERC20 token) external nonpayable
Force remove reward from vault rewards configuration.
This is meant to be an emergency function if a reward token breaks. Requirements: - the caller must be Spool DAO
Name | Type | Description |
---|---|---|
token | contract IERC20 | Token address to remove |
function getActiveRewards(address account) external nonpayable
Name | Type | Description |
---|---|---|
account | address | undefined |
function getRewardForDuration(contract IERC20 token) external view returns (uint256)
Name | Type | Description |
---|---|---|
token | contract IERC20 | undefined |
Name | Type | Description |
---|---|---|
_0 | uint256 | undefined |
function getRewards(contract IERC20[] tokens) external nonpayable
Name | Type | Description |
---|---|---|
tokens | contract IERC20[] | undefined |
function getUpdatedUser(address[] vaultStrategies) external nonpayable returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256)
Redeem vault and user and return the user state
Intended to be called as a static call for view purposes Requirements: - the provided strategies must be valid
Name | Type | Description |
---|---|---|
vaultStrategies | address[] | vault strategies |
Name | Type | Description |
---|---|---|
_0 | uint256 | userShares current user shares |
_1 | uint256 | activeDeposit user active deposit (already processed by the DHW) |
_2 | uint256 | userOwed user total unclaimed amount |
_3 | uint256 | userWithdrawnDeposits unclaimed withdrawn deposit amount |
_4 | uint256 | userTotalUnderlying current user total underlying |
_5 | uint256 | pendingDeposit1 pending user deposit for the next index |
_6 | uint256 | pendingWithdrawalShares1 pending user withdrawal shares for the next index |
_7 | uint256 | pendingDeposit2 pending user deposit for the index after the next one |
_8 | uint256 | pendingWithdrawalShares2 pending user withdrawal shares for the after the next one |
function getUpdatedVault(address[] vaultStrategies) external nonpayable returns (uint256, uint256, uint256, uint256, uint256, uint256)
Redeem vault strategy deposits and withdrawals after do hard work.
Intended to be called as a static call for view purposes Requirements: - the provided strategies must be valid
Name | Type | Description |
---|---|---|
vaultStrategies | address[] | vault strategies |
Name | Type | Description |
---|---|---|
_0 | uint256 | totalUnderlying total vault underlying |
_1 | uint256 | totalShares total vault shares |
_2 | uint256 | pendingDeposit1 pending vault deposit for the next index |
_3 | uint256 | pendingWithdrawalShares1 pending vault withdrawal shares for the next index |
_4 | uint256 | pendingDeposit2 pending vault deposit for the index after the next one |
_5 | uint256 | pendingWithdrawalShares2 pending vault withdrawal shares for the after the next one |
function initialize(VaultInitializable vaultInitializable) external nonpayable
Initializes state of the vault at proxy creation.
Called only once by vault factory after deploying a vault proxy. All values have been sanitized by the controller contract, meaning that no additional checks need to be applied here.
Name | Type | Description |
---|---|---|
vaultInitializable | VaultInitializable | initial vault specific variables |
function lastIndexInteracted() external view returns (uint128 index1, uint128 index2)
Holds up to 2 global indexes vault last interacted at and havent been redeemed yet
Name | Type | Description |
---|---|---|
index1 | uint128 | undefined |
index2 | uint128 | undefined |
function lastTimeRewardApplicable(contract IERC20 token) external view returns (uint32)
Name | Type | Description |
---|---|---|
token | contract IERC20 | undefined |
Name | Type | Description |
---|---|---|
_0 | uint32 | undefined |
function lowerVaultFee(uint16 _vaultFee) external nonpayable
Set lower vault fee.
Name | Type | Description |
---|---|---|
_vaultFee | uint16 | new vault fee Requirements: - the caller can only be the vault owner - new vault fee must be lower than before |
function name() external view returns (string)
The name of the vault
Name | Type | Description |
---|---|---|
_0 | string | undefined |
function notifyRewardAmount(contract IERC20 token, uint256 reward, uint32 rewardsDuration) external nonpayable
Name | Type | Description |
---|---|---|
token | contract IERC20 | undefined |
reward | uint256 | undefined |
rewardsDuration | uint32 | undefined |
function notifyStrategyRemoved(address[] vaultStrategies, uint256 i) external nonpayable
Notify a vault a strategy was removed from the Spool system
This can be called by anyone after a strategy has been removed from the system. After the removal of the strategy that the vault contains, all actions calling central Spool contract will revert. This function must be called, to remove the strategy from the vault and update the strategy hash according to the new strategy array. Requirements: - The Spool system must finish reallocation if it's in progress - the provided strategies must be valid - The strategy must belong to this vault - The strategy must be removed from the system
Name | Type | Description |
---|---|---|
vaultStrategies | address[] | Array of current vault strategies (including the removed one) |
i | uint256 | Index of the removed strategy in the vaultStrategies |
function payFees(uint256 profit) external nonpayable returns (uint256)
Notifies fee handler of user realized profits to calculate and store the fee.
Called by fast withdraw contract. Fee handler updates the fee storage slots and returns calculated fee value Fast withdraw transfers the calculated fee to the fee handler after. Requirements: - Caller must be the fast withdraw contract
Name | Type | Description |
---|---|---|
profit | uint256 | Total profit made by the user |
Name | Type | Description |
---|---|---|
_0 | uint256 | Fee amount calculated from the profit |
function proportions() external view returns (uint256)
The proportions of each strategy when depositing
Name | Type | Description |
---|---|---|
_0 | uint256 | undefined |
function reallocate(address[] vaultStrategies, uint256 newVaultProportions, uint256 finishedIndex, uint24 activeIndex) external nonpayable returns (uint256[] withdrawProportionsArray, uint256 newDepositProportions)
Update vault strategy proportions and reallocate funds according to the new proportions.
- Requirements: - the caller must be the Spool contract - reallocation must not be in progress - new vault proportions must add up to
FULL_PERCENT
*
Name | Type | Description |
---|---|---|
vaultStrategies | address[] | Vault strategy addresses |
newVaultProportions | uint256 | New vault proportions |
finishedIndex | uint256 | Completed global index |
activeIndex | uint24 | current active global index, that we're setting reallocate for |
Name | Type | Description |
---|---|---|
withdrawProportionsArray | uint256[] | array of shares to be withdrawn from each vault strategy, and be later deposited back to other vault strategies |
newDepositProportions | uint256 | proportions to be deposited to strategies from all withdrawn funds (written in a uint word, 14bits each) values add up to FULL_PERCENT |
function reallocationIndex() external view returns (uint24)
Data if vault and at what index vault is reallocating
Name | Type | Description |
---|---|---|
_0 | uint24 | undefined |
function redeemUser() external nonpayable
Redeem user deposits and withdrawals
Can only redeem user up to last index vault has redeemed
function redeemVaultAndUser(address[] vaultStrategies) external nonpayable
Redeem vault and user deposit and withdrawals Requirements: - the provided strategies must be valid
Name | Type | Description |
---|---|---|
vaultStrategies | address[] | vault stratigies |
function redeemVaultStrategies(address[] vaultStrategies) external nonpayable
Redeem vault strategy deposits and withdrawals after do hard work. Requirements: - the provided strategies must be valid
Name | Type | Description |
---|---|---|
vaultStrategies | address[] | vault strategies |
function redeems(uint256) external view returns (uint128 depositShares, uint128 withdrawnAmount)
Global index to deposit and withdraw vault redeem
Name | Type | Description |
---|---|---|
_0 | uint256 | undefined |
Name | Type | Description |
---|---|---|
depositShares | uint128 | undefined |
withdrawnAmount | uint128 | undefined |
function removeReward(contract IERC20 token) external nonpayable
Remove reward from vault rewards configuration.
Used to sanitize vault and save on gas, after the reward has ended. Users will be able to claim rewards Requirements: - the caller must be the spool owner or Spool DAO - cannot claim vault underlying token - cannot only execute if the reward finished
Name | Type | Description |
---|---|---|
token | contract IERC20 | Token address to remove |
function rewardConfiguration(contract IERC20) external view returns (uint32 rewardsDuration, uint32 periodFinish, uint192 rewardRate, uint32 lastUpdateTime, uint224 rewardPerTokenStored)
Vault reward token incentive configuration
Name | Type | Description |
---|---|---|
_0 | contract IERC20 | undefined |
Name | Type | Description |
---|---|---|
rewardsDuration | uint32 | undefined |
periodFinish | uint32 | undefined |
rewardRate | uint192 | undefined |
lastUpdateTime | uint32 | undefined |
rewardPerTokenStored | uint224 | undefined |
function rewardPerToken(contract IERC20 token) external view returns (uint224)
Name | Type | Description |
---|---|---|
token | contract IERC20 | undefined |
Name | Type | Description |
---|---|---|
_0 | uint224 | undefined |
function rewardTokens(uint256) external view returns (contract IERC20)
All reward tokens supported by the contract
Name | Type | Description |
---|---|---|
_0 | uint256 | undefined |
Name | Type | Description |
---|---|---|
_0 | contract IERC20 | undefined |
function rewardTokensCount() external view returns (uint8)
Number of vault incentivized tokens
Name | Type | Description |
---|---|---|
_0 | uint8 | undefined |
function strategiesHash() external view returns (bytes32)