Yearn4626RouterExt
Inherits: IYearn4626RouterExt, Yearn4626Router
Extends the Yearn4626Router with additional functionality for depositing to Yearn Vault V2 and pulling tokens with Permit2.
This contract introduces two key functions: depositing to Yearn Vault V2 and pulling tokens with a signature via Permit2. The contract holds an immutable reference to a Permit2 contract to facilitate token transfers with permits.
State Variables
_PERMIT2
IPermit2 private immutable _PERMIT2;
Functions
constructor
Constructs the Yearn4626RouterExt contract.
Sets up the router with the name for the vault, WETH address, and Permit2 contract address.
constructor(string memory name_, address weth_, address permit2_) payable Yearn4626Router(name_, IWETH9(weth_));
Parameters
Name | Type | Description |
---|---|---|
name_ | string | The name of the vault. |
weth_ | address | The address of the WETH contract. |
permit2_ | address | The address of the Permit2 contract. |
serializedDeposits
Deposits the specified amount
of assets into series of ERC4626 vaults or Yearn Vault V2.
function serializedDeposits(
address[] calldata path,
uint256 assetsIn,
address to,
uint256 minSharesOut
)
external
payable
returns (uint256 sharesOut);
Parameters
Name | Type | Description |
---|---|---|
path | address[] | The array of addresses that represents the vaults to deposit into. |
assetsIn | uint256 | The amount of assets to deposit into the first vault. |
to | address | The address to which the shares will be transferred. |
minSharesOut | uint256 | The minimum amount of shares expected to be received. |
Returns
Name | Type | Description |
---|---|---|
sharesOut | uint256 | The actual amount of shares received by the to address. |
serializedRedeems
Redeems the specified shares
from a series of ERC4626 vaults or Yearn Vault V2.
function serializedRedeems(
address[] calldata path,
bool[] calldata isYearnVaultV2,
uint256 sharesIn,
address to,
uint256 minAssetsOut
)
external
payable
returns (uint256 assetsOut);
Parameters
Name | Type | Description |
---|---|---|
path | address[] | The array of addresses that represents the vaults to redeem from. |
isYearnVaultV2 | bool[] | The array of boolean values that represent whether the vault is a Yearn Vault V2. |
sharesIn | uint256 | The amount of shares to redeem from the first vault. |
to | address | The address to which the assets will be transferred. |
minAssetsOut | uint256 | The minimum amount of assets expected to be received. |
Returns
Name | Type | Description |
---|---|---|
assetsOut | uint256 | The actual amount of assets received by the to address. |
redeemVaultV2
Redeems the specified shares
from the Yearn Vault V2.
The shares must exist in this router before calling this function.
function redeemVaultV2(
IYearnVaultV2 vault,
uint256 shares,
address to,
uint256 minAssetsOut
)
public
payable
returns (uint256 amountOut);
Parameters
Name | Type | Description |
---|---|---|
vault | IYearnVaultV2 | The Yearn Vault V2 contract instance. |
shares | uint256 | The amount of shares to redeem. |
to | address | The address to which the assets will be transferred. |
minAssetsOut | uint256 | The minimum amount of assets expected to be received. |
Returns
Name | Type | Description |
---|---|---|
amountOut | uint256 | The actual amount of assets received by the to address. |
redeemFromRouter
Redeems the specified IERC4626 vault shares
that this router is holding.
function redeemFromRouter(
IERC4626 vault,
uint256 shares,
address to,
uint256 minAmountOut
)
public
payable
virtual
returns (uint256 amountOut);
Parameters
Name | Type | Description |
---|---|---|
vault | IERC4626 | The IERC4626 vault contract instance. |
shares | uint256 | The amount of shares to redeem. |
to | address | The address to which the assets will be transferred. |
minAmountOut | uint256 | The minimum amount of assets expected to be received. |
Returns
Name | Type | Description |
---|---|---|
amountOut | uint256 | The actual amount of assets received by the to address. |
withdrawFromRouter
Withdraws the specified assets
from the IERC4626 vault.
function withdrawFromRouter(
IERC4626 vault,
uint256 assets,
address to,
uint256 maxSharesIn
)
public
payable
virtual
returns (uint256 sharesOut);
Parameters
Name | Type | Description |
---|---|---|
vault | IERC4626 | The IERC4626 vault contract instance. |
assets | uint256 | The amount of assets to withdraw. |
to | address | The address to which the assets will be transferred. |
maxSharesIn | uint256 | The maximum amount of vault shares expected to be burned. |
Returns
Name | Type | Description |
---|---|---|
sharesOut | uint256 | The actual amount of shares burned from the vault . |
redeemStakeDaoGauge
Redeems the specified shares
of the StakeDAO Gauge.
Assumes the assets withdrawn will be the the yearn vault tokens and will always be the same amount as the
shares
of the burned StakeDAO gauge tokens.
function redeemStakeDaoGauge(IStakeDaoGauge gauge, uint256 shares, address to) public payable returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
gauge | IStakeDaoGauge | The StakeDAO Gauge contract instance. |
shares | uint256 | The amount of StakeDAO gauge tokens to burn. |
to | address |
pullTokenWithPermit2
Pulls tokens to the contract using a signature via Permit2.
Verifies that the to
address in transferDetails
is the contract itself and then calls
permitTransferFrom
on the Permit2 contract.
Reverts with InvalidTo
if the to
address is not the contract itself.
function pullTokenWithPermit2(
ISignatureTransfer.PermitTransferFrom calldata permit,
ISignatureTransfer.SignatureTransferDetails calldata transferDetails,
bytes calldata signature
)
public
payable;
Parameters
Name | Type | Description |
---|---|---|
permit | ISignatureTransfer.PermitTransferFrom | The PermitTransferFrom struct containing the permit details. |
transferDetails | ISignatureTransfer.SignatureTransferDetails | The details of the transfer, including the to address. |
signature | bytes | The signature to authorize the token transfer. |
previewDeposits
Calculate the amount of shares to be received from a series of deposits to ERC4626 vaults or Yearn Vault V2.
function previewDeposits(
address[] calldata path,
uint256 assetsIn
)
external
view
returns (uint256[] memory sharesOut);
Parameters
Name | Type | Description |
---|---|---|
path | address[] | The array of addresses that represents the path from input token to output token |
assetsIn | uint256 | The amount of assets to deposit into the first vault. |
Returns
Name | Type | Description |
---|---|---|
sharesOut | uint256[] | The amount of shares to be received from each deposit. The length of the array is path.length - 1 . |
previewMints
Calculate the amount of assets required to mint a given amount of shares from a series of deposits to ERC4626 vaults or Yearn Vault V2.
Increment the loop index i
without checking for overflow.
This is safe because the loop's termination condition ensures that i
will not exceed
the bounds of the sharesOut
array, which would be the only case where an overflow could occur.
sharesOut is the expected result at the last vault, and the path = [tokenIn, vault0, vault1, ..., vaultN]. First calculate the amount of assets in to get the desired sharesOut from the last vault, then using that amount as the next sharesOut to get the amount of assets in for the penultimate vault.
function previewMints(address[] calldata path, uint256 sharesOut) external view returns (uint256[] memory assetsIn);
Parameters
Name | Type | Description |
---|---|---|
path | address[] | The array of addresses that represents the path from input to output. |
sharesOut | uint256 | The amount of shares to mint from the last vault. |
Returns
Name | Type | Description |
---|---|---|
assetsIn | uint256[] | The amount of assets required at each step. The length of the array is path.length - 1 . |
previewWithdraws
Calculate the amount of shares required to withdraw a given amount of assets from a series of withdraws from ERC4626 vaults or Yearn Vault V2.
Decrement the loop counter within an unchecked block to avoid redundant gas cost associated with
underflow checking. This is safe because the loop's initialization and exit condition ensure that i
will not underflow.
assetsOut is the desired result of the output token, and the path = [vault0, vault1, ..., vaultN, tokenOut]. First calculate the amount of shares in to get the desired assetsOut from the last vault, then using that amount as the next assetsOut to get the amount of shares in for the penultimate vault.
function previewWithdraws(
address[] calldata path,
uint256 assetsOut
)
external
view
returns (uint256[] memory sharesIn);
Parameters
Name | Type | Description |
---|---|---|
path | address[] | The array of addresses that represents the path from input to output. |
assetsOut | uint256 | The amount of assets to withdraw from the last vault. |
Returns
Name | Type | Description |
---|---|---|
sharesIn | uint256[] | The amount of shares required at each step. The length of the array is path.length - 1 . |
previewRedeems
Calculate the amount of assets to be received from a series of withdraws from ERC4626 vaults or Yearn Vault V2.
Decrement the loop counter without checking for overflow. This is safe because the for loop
naturally ensures that i
will not underflow as it is bounded by i == 0 check.
function previewRedeems(address[] calldata path, uint256 sharesIn) external view returns (uint256[] memory assetsOut);
Parameters
Name | Type | Description |
---|---|---|
path | address[] | The array of addresses that represents the path from input to output. |
sharesIn | uint256 | The amount of shares to withdraw from the first vault. |
Returns
Name | Type | Description |
---|---|---|
assetsOut | uint256[] | The amount of assets to be received at each step. The length of the array is path.length - 1 . |
Errors
InsufficientShares
Error for when the number of shares received is less than the minimum expected.
error InsufficientShares();
InsufficientAssets
Error for when the amount of assets received is less than the minimum expected.
error InsufficientAssets();
RequiresMoreThanMaxShares
Error for when the amount of shares burned is more than the maximum expected.
error RequiresMoreThanMaxShares();
InvalidPermit2TransferTo
Error for when the to
address in the Permit2 transfer is not the router contract.
error InvalidPermit2TransferTo();
InvalidPermit2TransferAmount
Error for when the amount in the Permit2 transfer is not the same as the requested amount.
error InvalidPermit2TransferAmount();
InvalidPathLength
Error for when the serialized deposit path is too short.
error InvalidPathLength();
PreviewPathIsTooShort
Error for when the path is too short to preview the deposits/mints/withdraws/redeems.
error PreviewPathIsTooShort();
PreviewNonVaultAddressInPath
Error for when the address in the path is not a vault.
error PreviewNonVaultAddressInPath(address invalidVault);
PreviewVaultMismatch
Error for when an address in the path does not match previous or next vault's asset.
error PreviewVaultMismatch();