YearnVaultV2Helper
Helper functions for Yearn Vault V2 contracts. Since Yearn Vault V2 contracts are not ERC-4626 compliant,
they do not provide previewDeposit
, previewMint
, previewRedeem
, and previewWithdraw
functions. This library
provides these functions for previewing share based deposit/mint/redeem/withdraw estimations.
These functions are only to be used off-chain for previewing. Due to how Yearn Vault V2 contracts work, share based withdraw/redeem estimations may not be accurate if the vault incurs a loss, thus share price changes. Coverage is currently disabled for this library due to forge limitations. TODO: Once the fix PR is merged, https://github.com/foundry-rs/foundry/pull/7510 coverage should be re-enabled.
Functions
freeFunds
Calculates the currently free funds in a Yearn Vault V2 contract.
This is based on Yearn Vault V2 contract's free funds calculation logic. https://github.com/yearn/yearn-vaults/blob/97ca1b2e4fcf20f4be0ff456dabd020bfeb6697b/contracts/Vault.vy#L844-L847
function freeFunds(IYearnVaultV2 vault) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
vault | IYearnVaultV2 | The Yearn Vault V2 contract. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The free funds in the vault. |
previewDeposit
Preview the amount of shares to be issued for a given deposit amount.
function previewDeposit(IYearnVaultV2 vault, uint256 assetsIn) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
vault | IYearnVaultV2 | The Yearn Vault V2 contract. |
assetsIn | uint256 | The amount of assets to be deposited. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of shares that would be issued for the deposited assets. |
previewMint
Preview the amount of assets required to mint a given amount of shares.
function previewMint(IYearnVaultV2 vault, uint256 sharesOut) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
vault | IYearnVaultV2 | The Yearn Vault V2 contract. |
sharesOut | uint256 | The number of shares to be minted. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of assets required to mint the specified number of shares. |
previewRedeem
Preview the amount of assets to be received for redeeming a given amount of shares.
function previewRedeem(IYearnVaultV2 vault, uint256 sharesIn) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
vault | IYearnVaultV2 | The Yearn Vault V2 contract. |
sharesIn | uint256 | The number of shares to be redeemed. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The amount of assets that would be received for the redeemed shares. |
previewWithdraw
Preview the number of shares to be redeemed for a given withdrawal amount of assets.
function previewWithdraw(IYearnVaultV2 vault, uint256 assetsOut) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
vault | IYearnVaultV2 | The Yearn Vault V2 contract. |
assetsOut | uint256 | The amount of assets to be withdrawn. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The number of shares that would be redeemed for the withdrawn assets. |