Spool Tech Docs
Search
⌃K

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)

Methods

addToken

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

Parameters

Name
Type
Description
token
contract IERC20
undefined
rewardsDuration
uint32
undefined
reward
uint256
undefined

claim

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)

Parameters

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

Returns

Name
Type
Description
claimAmount
uint128
amount of underlying asset, claimed by the caller

claimFinishedRewards

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

Parameters

Name
Type
Description
token
contract IERC20
Token address to remove
amount
uint256
Amount of tokens to claim

controller

function controller() external view returns (contract IController)
The controller contract that is consulted for a strategy's and vault's validity

Returns

Name
Type
Description
_0
contract IController
undefined

deposit

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

Parameters

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

earned

function earned(contract IERC20 token, address account) external view returns (uint256)

Parameters

Name
Type
Description
token
contract IERC20
undefined
account
address
undefined

Returns

Name
Type
Description
_0
uint256
undefined

forceRemoveReward

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

Parameters

Name
Type
Description
token
contract IERC20
Token address to remove

getActiveRewards

function getActiveRewards(address account) external nonpayable

Parameters

Name
Type
Description
account
address
undefined

getRewardForDuration

function getRewardForDuration(contract IERC20 token) external view returns (uint256)

Parameters

Name
Type
Description
token
contract IERC20
undefined

Returns

Name
Type
Description
_0
uint256
undefined

getRewards

function getRewards(contract IERC20[] tokens) external nonpayable

Parameters

Name
Type
Description
tokens
contract IERC20[]
undefined

getUpdatedUser

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

Parameters

Name
Type
Description
vaultStrategies
address[]
vault strategies

Returns

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

getUpdatedVault

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

Parameters

Name
Type
Description
vaultStrategies
address[]
vault strategies

Returns

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

initialize

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.

Parameters

Name
Type
Description
vaultInitializable
VaultInitializable
initial vault specific variables

lastIndexInteracted

function lastIndexInteracted() external view returns (uint128 index1, uint128 index2)
Holds up to 2 global indexes vault last interacted at and havent been redeemed yet

Returns

Name
Type
Description
index1
uint128
undefined
index2
uint128
undefined

lastTimeRewardApplicable

function lastTimeRewardApplicable(contract IERC20 token) external view returns (uint32)

Parameters

Name
Type
Description
token
contract IERC20
undefined

Returns

Name
Type
Description
_0
uint32
undefined

lowerVaultFee

function lowerVaultFee(uint16 _vaultFee) external nonpayable
Set lower vault fee.

Parameters

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

name

function name() external view returns (string)
The name of the vault

Returns

Name
Type
Description
_0
string
undefined

notifyRewardAmount

function notifyRewardAmount(contract IERC20 token, uint256 reward, uint32 rewardsDuration) external nonpayable

Parameters

Name
Type
Description
token
contract IERC20
undefined
reward
uint256
undefined
rewardsDuration
uint32
undefined

notifyStrategyRemoved

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

Parameters

Name
Type
Description
vaultStrategies
address[]
Array of current vault strategies (including the removed one)
i
uint256
Index of the removed strategy in the vaultStrategies

payFees

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

Parameters

Name
Type
Description
profit
uint256
Total profit made by the user

Returns

Name
Type
Description
_0
uint256
Fee amount calculated from the profit

proportions

function proportions() external view returns (uint256)
The proportions of each strategy when depositing

Returns

Name
Type
Description
_0
uint256
undefined

reallocate

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*

Parameters

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

Returns

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

reallocationIndex

function reallocationIndex() external view returns (uint24)
Data if vault and at what index vault is reallocating

Returns

Name
Type
Description
_0
uint24
undefined

redeemUser

function redeemUser() external nonpayable
Redeem user deposits and withdrawals
Can only redeem user up to last index vault has redeemed

redeemVaultAndUser

function redeemVaultAndUser(address[] vaultStrategies) external nonpayable
Redeem vault and user deposit and withdrawals Requirements: - the provided strategies must be valid

Parameters

Name
Type
Description
vaultStrategies
address[]
vault stratigies

redeemVaultStrategies

function redeemVaultStrategies(address[] vaultStrategies) external nonpayable
Redeem vault strategy deposits and withdrawals after do hard work. Requirements: - the provided strategies must be valid

Parameters

Name
Type
Description
vaultStrategies
address[]
vault strategies

redeems

function redeems(uint256) external view returns (uint128 depositShares, uint128 withdrawnAmount)
Global index to deposit and withdraw vault redeem

Parameters

Name
Type
Description
_0
uint256
undefined

Returns

Name
Type
Description
depositShares
uint128
undefined
withdrawnAmount
uint128
undefined

removeReward

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

Parameters

Name
Type
Description
token
contract IERC20
Token address to remove

rewardConfiguration

function rewardConfiguration(contract IERC20) external view returns (uint32 rewardsDuration, uint32 periodFinish, uint192 rewardRate, uint32 lastUpdateTime, uint224 rewardPerTokenStored)
Vault reward token incentive configuration

Parameters

Name
Type
Description
_0
contract IERC20
undefined

Returns

Name
Type
Description
rewardsDuration
uint32
undefined
periodFinish
uint32
undefined
rewardRate
uint192
undefined
lastUpdateTime
uint32
undefined
rewardPerTokenStored
uint224
undefined

rewardPerToken

function rewardPerToken(contract IERC20 token) external view returns (uint224)

Parameters

Name
Type
Description
token
contract IERC20
undefined

Returns

Name
Type
Description
_0
uint224
undefined

rewardTokens

function rewardTokens(uint256) external view returns (contract IERC20)
All reward tokens supported by the contract

Parameters

Name
Type
Description
_0
uint256
undefined

Returns

Name
Type
Description
_0
contract IERC20
undefined

rewardTokensCount

function rewardTokensCount() external view returns (uint8)
Number of vault incentivized tokens

Returns

Name
Type
Description
_0
uint8
undefined

strategiesHash

function strategiesHash() external view returns (bytes32)