Skip to main content

VaultV3.vy

vyper: 0.3.7 author: yearn.finance license: GNU AGPLv3

Yearn V3 Vault**​

The Yearn VaultV3 is designed as a non-opinionated system to distribute funds of depositors for a specific asset into different opportunities (aka Strategies) and manage accounting in a robust way. Depositors receive shares (aka vaults tokens) proportional to their deposit amount. Vault tokens are yield-bearing and can be redeemed at any time to get back deposit plus any yield generated. Addresses that are given different permissioned roles by the role_manager are then able to allocate funds as they best see fit to different strategies and adjust the strategies and allocations as needed, as well as reporting realized profits or losses. Strategies are any ERC-4626 compliant contracts that use the same underlying asset as the vault. The vault provides no assurances as to the safety of any strategy and it is the responsibility of those that hold the corresponding roles to choose and fund strategies that best fit their desired specifications. Those holding vault tokens are able to redeem the tokens for the corresponding amount of underlying asset based on any reported profits or losses since their initial deposit. The vault is built to be customized by the management to be able to fit their specific desired needs. Including the customization of strategies, accountants, ownership etc.

Functions​

initialize​

Initialize a new vault. Sets the asset, name, symbol, and role manager.

function initialize(address,string,string,address,uint256)

Parameters​

NameTypeDescription
assetaddressThe address of the asset that the vault will accept.
namestringThe name of the vault token.
symbolstringThe symbol of the vault token.
role_manageraddressThe address that can add and remove roles to addresses
profit_max_unlock_timeuint256The amount of time that the profit will be locked for

setName​

Change the vault name.

Can only be called by the Role Manager.

function setName(string)

Parameters​

NameTypeDescription
namestringThe new name for the vault.

setSymbol​

Change the vault symbol.

Can only be called by the Role Manager.

function setSymbol(string)

Parameters​

NameTypeDescription
symbolstringThe new name for the vault.

set_accountant​

Set the new accountant address.

function set_accountant(address)

Parameters​

NameTypeDescription
new_accountantaddressThe new accountant address.

set_default_queue​

Set the new default queue array.

Will check each strategy to make sure it is active. But will not check that the same strategy is not added twice. maxRedeem and maxWithdraw return values may be inaccurate if a strategy is added twice.

function set_default_queue(address[])

Parameters​

NameTypeDescription
new_default_queueaddress[]The new default queue array.

set_use_default_queue​

Set a new value for use_default_queue.

If set True the default queue will always be used no matter whats passed in.

function set_use_default_queue(bool)

Parameters​

NameTypeDescription
use_default_queueboolnew value.

set_auto_allocate​

Set new value for auto_allocate

If True every deposit and mint call will try and allocate the deposited amount to the strategy at position 0 of the default_queue atomically. NOTE: An empty default_queue will cause deposits to fail.

function set_auto_allocate(bool)

Parameters​

NameTypeDescription
auto_allocateboolnew value.

set_deposit_limit​

Set the new deposit limit.

Can not be changed if a deposit_limit_module is set unless the override flag is true or if shutdown.

function set_deposit_limit(uint256)

Parameters​

NameTypeDescription
deposit_limituint256The new deposit limit.
overrideunknownIf a deposit_limit_module already set should be overridden.

set_deposit_limit​

Can not be changed if a deposit_limit_module is set unless the override flag is true or if shutdown.

function set_deposit_limit(uint256,bool)

Parameters​

NameTypeDescription
deposit_limituint256The new deposit limit.
overrideboolIf a deposit_limit_module already set should be overridden.

set_deposit_limit_module​

Set a contract to handle the deposit limit.

The default deposit_limit will need to be set to max uint256 since the module will override it or the override flag must be set to true to set it to max in 1 tx..

function set_deposit_limit_module(address)

Parameters​

NameTypeDescription
deposit_limit_moduleaddressAddress of the module.
overrideunknownIf a deposit_limit already set should be overridden.

set_deposit_limit_module​

The default deposit_limit will need to be set to max uint256 since the module will override it or the override flag must be set to true to set it to max in 1 tx..

function set_deposit_limit_module(address,bool)

Parameters​

NameTypeDescription
deposit_limit_moduleaddressAddress of the module.
overrideboolIf a deposit_limit already set should be overridden.

set_withdraw_limit_module​

Set a contract to handle the withdraw limit.

This will override the default max_withdraw.

function set_withdraw_limit_module(address)

Parameters​

NameTypeDescription
withdraw_limit_moduleaddressAddress of the module.

set_minimum_total_idle​

Set the new minimum total idle.

function set_minimum_total_idle(uint256)

Parameters​

NameTypeDescription
minimum_total_idleuint256The new minimum total idle.

setProfitMaxUnlockTime​

Set the new profit max unlock time.

The time is denominated in seconds and must be less than 1 year. We only need to update locking period if setting to 0, since the current period will use the old rate and on the next report it will be reset with the new unlocking time. Setting to 0 will cause any currently locked profit to instantly unlock and an immediate increase in the vaults Price Per Share.

function setProfitMaxUnlockTime(uint256)

Parameters​

NameTypeDescription
new_profit_max_unlock_timeuint256The new profit max unlock time.

set_role​

Set the roles for an account.

This will fully override an accounts current roles so it should include all roles the account should hold.

function set_role(address,uint256)

Parameters​

NameTypeDescription
accountaddressThe account to set the role for.
roleuint256The roles the account should hold.

add_role​

Add a new role/s to an address.

This will add a new role/s to the account without effecting any of the previously held roles.

function add_role(address,uint256)

Parameters​

NameTypeDescription
accountaddressThe account to add a role to.
roleuint256The new role/s to add to account.

remove_role​

Remove a role/s from an account.

This will leave all other roles for the account unchanged.

function remove_role(address,uint256)

Parameters​

NameTypeDescription
accountaddressThe account to remove a Role/s from.
roleuint256The Role/s to remove.

transfer_role_manager​

Step 1 of 2 in order to transfer the role manager to a new address. This will set the future_role_manager. Which will then need to be accepted by the new manager.

function transfer_role_manager(address)

Parameters​

NameTypeDescription
role_manageraddressThe new role manager address.

isShutdown​

Get if the vault is shutdown.

function isShutdown()

Return Values​

NameTypeDescription
_output0boolBool representing the shutdown status

unlockedShares​

Get the amount of shares that have been unlocked.

function unlockedShares()

Return Values​

NameTypeDescription
_output0uint256The amount of shares that are have been unlocked.

pricePerShare​

Get the price per share (pps) of the vault.

This value offers limited precision. Integrations that require exact precision should use convertToAssets or convertToShares instead.

function pricePerShare()

Return Values​

NameTypeDescription
_output0uint256The price per share.

get_default_queue​

Get the full default queue currently set.

function get_default_queue()

Return Values​

NameTypeDescription
_output0address[]The current default withdrawal queue.

process_report​

Process the report of a strategy.

function process_report(address)

Parameters​

NameTypeDescription
strategyaddressThe strategy to process the report for.

Return Values​

NameTypeDescription
_output0uint256The gain and loss of the strategy.

| _output1 | uint256 | |

buy_debt​

Used for governance to buy bad debt from the vault.

This should only ever be used in an emergency in place of force revoking a strategy in order to not report a loss. It allows the DEBT_PURCHASER role to buy the strategies debt for an equal amount of asset.

function buy_debt(address,uint256)

Parameters​

NameTypeDescription
strategyaddressThe strategy to buy the debt for
amountuint256The amount of debt to buy from the vault.

add_strategy​

Add a new strategy.

function add_strategy(address)

Parameters​

NameTypeDescription
new_strategyaddressThe new strategy to add.

add_strategy​

function add_strategy(address,bool)

Parameters​

NameTypeDescription
new_strategyaddressThe new strategy to add.

revoke_strategy​

Revoke a strategy.

function revoke_strategy(address)

Parameters​

NameTypeDescription
strategyaddressThe strategy to revoke.

force_revoke_strategy​

Force revoke a strategy.

The vault will remove the strategy and write off any debt left in it as a loss. This function is a dangerous function as it can force a strategy to take a loss. All possible assets should be removed from the strategy first via update_debt. If a strategy is removed erroneously it can be re-added and the loss will be credited as profit. Fees will apply.

function force_revoke_strategy(address)

Parameters​

NameTypeDescription
strategyaddressThe strategy to force revoke.

update_max_debt_for_strategy​

Update the max debt for a strategy.

function update_max_debt_for_strategy(address,uint256)

Parameters​

NameTypeDescription
strategyaddressThe strategy to update the max debt for.
new_max_debtuint256The new max debt for the strategy.

update_debt​

Update the debt for a strategy.

Pass max uint256 to allocate as much idle as possible.

function update_debt(address,uint256)

Parameters​

NameTypeDescription
strategyaddressThe strategy to update the debt for.
target_debtuint256The target debt for the strategy.
max_lossunknownOptional to check realized losses on debt decreases.

Return Values​

NameTypeDescription
_output0uint256The new current debt of the strategy.

update_debt​

Pass max uint256 to allocate as much idle as possible.

function update_debt(address,uint256,uint256)

Parameters​

NameTypeDescription
strategyaddressThe strategy to update the debt for.
target_debtuint256The target debt for the strategy.
max_lossuint256Optional to check realized losses on debt decreases.

Return Values​

NameTypeDescription
_output0uint256The new current debt of the strategy.

deposit​

Deposit assets into the vault.

Pass max uint256 to deposit full asset balance.

function deposit(uint256,address)

Parameters​

NameTypeDescription
assetsuint256The amount of assets to deposit.
receiveraddressThe address to receive the shares.

Return Values​

NameTypeDescription
_output0uint256The amount of shares minted.

mint​

Mint shares for the receiver.

function mint(uint256,address)

Parameters​

NameTypeDescription
sharesuint256The amount of shares to mint.
receiveraddressThe address to receive the shares.

Return Values​

NameTypeDescription
_output0uint256The amount of assets deposited.

withdraw​

Withdraw an amount of asset to receiver burning owners shares.

The default behavior is to not allow any loss.

function withdraw(uint256,address,address)

Parameters​

NameTypeDescription
assetsuint256The amount of asset to withdraw.
receiveraddressThe address to receive the assets.
owneraddressThe address who's shares are being burnt.
max_lossunknownOptional amount of acceptable loss in Basis Points.
strategiesunknownOptional array of strategies to withdraw from.

Return Values​

NameTypeDescription
_output0uint256The amount of shares actually burnt.

withdraw​

The default behavior is to not allow any loss.

function withdraw(uint256,address,address,uint256)

Parameters​

NameTypeDescription
assetsuint256The amount of asset to withdraw.
receiveraddressThe address to receive the assets.
owneraddressThe address who's shares are being burnt.
max_lossuint256Optional amount of acceptable loss in Basis Points.
strategiesunknownOptional array of strategies to withdraw from.

Return Values​

NameTypeDescription
_output0uint256The amount of shares actually burnt.

withdraw​

The default behavior is to not allow any loss.

function withdraw(uint256,address,address,uint256,address[])

Parameters​

NameTypeDescription
assetsuint256The amount of asset to withdraw.
receiveraddressThe address to receive the assets.
owneraddressThe address who's shares are being burnt.
max_lossuint256Optional amount of acceptable loss in Basis Points.
strategiesaddress[]Optional array of strategies to withdraw from.

Return Values​

NameTypeDescription
_output0uint256The amount of shares actually burnt.

redeem​

Redeems an amount of shares of owners shares sending funds to receiver.

The default behavior is to allow losses to be realized.

function redeem(uint256,address,address)

Parameters​

NameTypeDescription
sharesuint256The amount of shares to burn.
receiveraddressThe address to receive the assets.
owneraddressThe address who's shares are being burnt.
max_lossunknownOptional amount of acceptable loss in Basis Points.
strategiesunknownOptional array of strategies to withdraw from.

Return Values​

NameTypeDescription
_output0uint256The amount of assets actually withdrawn.

redeem​

The default behavior is to allow losses to be realized.

function redeem(uint256,address,address,uint256)

Parameters​

NameTypeDescription
sharesuint256The amount of shares to burn.
receiveraddressThe address to receive the assets.
owneraddressThe address who's shares are being burnt.
max_lossuint256Optional amount of acceptable loss in Basis Points.
strategiesunknownOptional array of strategies to withdraw from.

Return Values​

NameTypeDescription
_output0uint256The amount of assets actually withdrawn.

redeem​

The default behavior is to allow losses to be realized.

function redeem(uint256,address,address,uint256,address[])

Parameters​

NameTypeDescription
sharesuint256The amount of shares to burn.
receiveraddressThe address to receive the assets.
owneraddressThe address who's shares are being burnt.
max_lossuint256Optional amount of acceptable loss in Basis Points.
strategiesaddress[]Optional array of strategies to withdraw from.

Return Values​

NameTypeDescription
_output0uint256The amount of assets actually withdrawn.

approve​

Approve an address to spend the vault's shares.

function approve(address,uint256)

Parameters​

NameTypeDescription
spenderaddressThe address to approve.
amountuint256The amount of shares to approve.

Return Values​

NameTypeDescription
_output0boolTrue if the approval was successful.

transfer​

Transfer shares to a receiver.

function transfer(address,uint256)

Parameters​

NameTypeDescription
receiveraddressThe address to transfer shares to.
amountuint256The amount of shares to transfer.

Return Values​

NameTypeDescription
_output0boolTrue if the transfer was successful.

transferFrom​

Transfer shares from a sender to a receiver.

function transferFrom(address,address,uint256)

Parameters​

NameTypeDescription
senderaddressThe address to transfer shares from.
receiveraddressThe address to transfer shares to.
amountuint256The amount of shares to transfer.

Return Values​

NameTypeDescription
_output0boolTrue if the transfer was successful.

permit​

Approve an address to spend the vault's shares.

function permit(address,address,uint256,uint256,uint8,bytes32,bytes32)

Parameters​

NameTypeDescription
owneraddressThe address to approve.
spenderaddressThe address to approve.
amountuint256The amount of shares to approve.
deadlineuint256The deadline for the permit.
vuint8The v component of the signature.
rbytes32The r component of the signature.
sbytes32The s component of the signature.

Return Values​

NameTypeDescription
_output0boolTrue if the approval was successful.

balanceOf​

Get the balance of a user.

function balanceOf(address)

Parameters​

NameTypeDescription
addraddressThe address to get the balance of.

Return Values​

NameTypeDescription
_output0uint256The balance of the user.

totalSupply​

Get the total supply of shares.

function totalSupply()

Return Values​

NameTypeDescription
_output0uint256The total supply of shares.

totalAssets​

Get the total assets held by the vault.

function totalAssets()

Return Values​

NameTypeDescription
_output0uint256The total assets held by the vault.

totalIdle​

Get the amount of loose asset the vault holds.

function totalIdle()

Return Values​

NameTypeDescription
_output0uint256The current total idle.

totalDebt​

Get the total amount of funds invested across all strategies.

function totalDebt()

Return Values​

NameTypeDescription
_output0uint256The current total debt.

convertToShares​

Convert an amount of assets to shares.

function convertToShares(uint256)

Parameters​

NameTypeDescription
assetsuint256The amount of assets to convert.

Return Values​

NameTypeDescription
_output0uint256The amount of shares.

previewDeposit​

Preview the amount of shares that would be minted for a deposit.

function previewDeposit(uint256)

Parameters​

NameTypeDescription
assetsuint256The amount of assets to deposit.

Return Values​

NameTypeDescription
_output0uint256The amount of shares that would be minted.

previewMint​

Preview the amount of assets that would be deposited for a mint.

function previewMint(uint256)

Parameters​

NameTypeDescription
sharesuint256The amount of shares to mint.

Return Values​

NameTypeDescription
_output0uint256The amount of assets that would be deposited.

convertToAssets​

Convert an amount of shares to assets.

function convertToAssets(uint256)

Parameters​

NameTypeDescription
sharesuint256The amount of shares to convert.

Return Values​

NameTypeDescription
_output0uint256The amount of assets.

maxDeposit​

Get the maximum amount of assets that can be deposited.

function maxDeposit(address)

Parameters​

NameTypeDescription
receiveraddressThe address that will receive the shares.

Return Values​

NameTypeDescription
_output0uint256The maximum amount of assets that can be deposited.

maxMint​

Get the maximum amount of shares that can be minted.

function maxMint(address)

Parameters​

NameTypeDescription
receiveraddressThe address that will receive the shares.

Return Values​

NameTypeDescription
_output0uint256The maximum amount of shares that can be minted.

maxWithdraw​

Get the maximum amount of assets that can be withdrawn.

Complies to normal 4626 interface and takes custom params. NOTE: Passing in a incorrectly ordered queue may result in incorrect returns values.

function maxWithdraw(address)

Parameters​

NameTypeDescription
owneraddressThe address that owns the shares.
max_lossunknownCustom max_loss if any.
strategiesunknownCustom strategies queue if any.

Return Values​

NameTypeDescription
_output0uint256The maximum amount of assets that can be withdrawn.

maxWithdraw​

Complies to normal 4626 interface and takes custom params. NOTE: Passing in a incorrectly ordered queue may result in incorrect returns values.

function maxWithdraw(address,uint256)

Parameters​

NameTypeDescription
owneraddressThe address that owns the shares.
max_lossuint256Custom max_loss if any.
strategiesunknownCustom strategies queue if any.

Return Values​

NameTypeDescription
_output0uint256The maximum amount of assets that can be withdrawn.

maxWithdraw​

Complies to normal 4626 interface and takes custom params. NOTE: Passing in a incorrectly ordered queue may result in incorrect returns values.

function maxWithdraw(address,uint256,address[])

Parameters​

NameTypeDescription
owneraddressThe address that owns the shares.
max_lossuint256Custom max_loss if any.
strategiesaddress[]Custom strategies queue if any.

Return Values​

NameTypeDescription
_output0uint256The maximum amount of assets that can be withdrawn.

maxRedeem​

Get the maximum amount of shares that can be redeemed.

Complies to normal 4626 interface and takes custom params. NOTE: Passing in a incorrectly ordered queue may result in incorrect returns values.

function maxRedeem(address)

Parameters​

NameTypeDescription
owneraddressThe address that owns the shares.
max_lossunknownCustom max_loss if any.
strategiesunknownCustom strategies queue if any.

Return Values​

NameTypeDescription
_output0uint256The maximum amount of shares that can be redeemed.

maxRedeem​

Complies to normal 4626 interface and takes custom params. NOTE: Passing in a incorrectly ordered queue may result in incorrect returns values.

function maxRedeem(address,uint256)

Parameters​

NameTypeDescription
owneraddressThe address that owns the shares.
max_lossuint256Custom max_loss if any.
strategiesunknownCustom strategies queue if any.

Return Values​

NameTypeDescription
_output0uint256The maximum amount of shares that can be redeemed.

maxRedeem​

Complies to normal 4626 interface and takes custom params. NOTE: Passing in a incorrectly ordered queue may result in incorrect returns values.

function maxRedeem(address,uint256,address[])

Parameters​

NameTypeDescription
owneraddressThe address that owns the shares.
max_lossuint256Custom max_loss if any.
strategiesaddress[]Custom strategies queue if any.

Return Values​

NameTypeDescription
_output0uint256The maximum amount of shares that can be redeemed.

previewWithdraw​

Preview the amount of shares that would be redeemed for a withdraw.

function previewWithdraw(uint256)

Parameters​

NameTypeDescription
assetsuint256The amount of assets to withdraw.

Return Values​

NameTypeDescription
_output0uint256The amount of shares that would be redeemed.

previewRedeem​

Preview the amount of assets that would be withdrawn for a redeem.

function previewRedeem(uint256)

Parameters​

NameTypeDescription
sharesuint256The amount of shares to redeem.

Return Values​

NameTypeDescription
_output0uint256The amount of assets that would be withdrawn.

FACTORY​

Address of the factory that deployed the vault.

Is used to retrieve the protocol fees.

function FACTORY()

Return Values​

NameTypeDescription
_output0addressAddress of the vault factory.

apiVersion​

Get the API version of the vault.

function apiVersion()

Return Values​

NameTypeDescription
_output0stringThe API version of the vault.

assess_share_of_unrealised_losses​

Assess the share of unrealised losses that a strategy has.

function assess_share_of_unrealised_losses(address,uint256)

Parameters​

NameTypeDescription
strategyaddressThe address of the strategy.
assets_neededuint256The amount of assets needed to be withdrawn.

Return Values​

NameTypeDescription
_output0uint256The share of unrealised losses that the strategy has.

profitMaxUnlockTime​

Gets the current time profits are set to unlock over.

function profitMaxUnlockTime()

Return Values​

NameTypeDescription
_output0uint256The current profit max unlock time.

fullProfitUnlockDate​

Gets the timestamp at which all profits will be unlocked.

function fullProfitUnlockDate()

Return Values​

NameTypeDescription
_output0uint256The full profit unlocking timestamp

profitUnlockingRate​

The per second rate at which profits are unlocking.

This is denominated in EXTENDED_BPS decimals.

function profitUnlockingRate()

Return Values​

NameTypeDescription
_output0uint256The current profit unlocking rate.

lastProfitUpdate​

The timestamp of the last time shares were locked.

function lastProfitUpdate()

Return Values​

NameTypeDescription
_output0uint256The last profit update.

DOMAIN_SEPARATOR​

Get the domain separator.

function DOMAIN_SEPARATOR()

Return Values​

NameTypeDescription
_output0bytes32The domain separator.

accept_role_manager​

Accept the role manager transfer.

function accept_role_manager()

shutdown_vault​

Shutdown the vault.

function shutdown_vault()

Events​

Deposit​

NameTypeIndexed?
senderaddressYes
owneraddressYes
assetsuint256No
sharesuint256No

Withdraw​

NameTypeIndexed?
senderaddressYes
receiveraddressYes
owneraddressYes
assetsuint256No
sharesuint256No

Transfer​

NameTypeIndexed?
senderaddressYes
receiveraddressYes
valueuint256No

Approval​

NameTypeIndexed?
owneraddressYes
spenderaddressYes
valueuint256No

StrategyChanged​

NameTypeIndexed?
strategyaddressYes
change_typeuint256Yes

StrategyReported​

NameTypeIndexed?
strategyaddressYes
gainuint256No
lossuint256No
current_debtuint256No
protocol_feesuint256No
total_feesuint256No
total_refundsuint256No

DebtUpdated​

NameTypeIndexed?
strategyaddressYes
current_debtuint256No
new_debtuint256No

RoleSet​

NameTypeIndexed?
accountaddressYes
roleuint256Yes

UpdateFutureRoleManager​

NameTypeIndexed?
future_role_manageraddressYes

UpdateRoleManager​

NameTypeIndexed?
role_manageraddressYes

UpdateAccountant​

NameTypeIndexed?
accountantaddressYes

UpdateDepositLimitModule​

NameTypeIndexed?
deposit_limit_moduleaddressYes

UpdateWithdrawLimitModule​

NameTypeIndexed?
withdraw_limit_moduleaddressYes

UpdateDefaultQueue​

NameTypeIndexed?
new_default_queueaddress[]No

UpdateUseDefaultQueue​

NameTypeIndexed?
use_default_queueboolNo

UpdateAutoAllocate​

NameTypeIndexed?
auto_allocateboolNo

UpdatedMaxDebtForStrategy​

NameTypeIndexed?
senderaddressYes
strategyaddressYes
new_debtuint256No

UpdateDepositLimit​

NameTypeIndexed?
deposit_limituint256No

UpdateMinimumTotalIdle​

NameTypeIndexed?
minimum_total_idleuint256No

UpdateProfitMaxUnlockTime​

NameTypeIndexed?
profit_max_unlock_timeuint256No

DebtPurchased​

NameTypeIndexed?
strategyaddressYes
amountuint256No

Shutdown​

NameTypeIndexed?