yearn / Yearn-ERC4626-Router

ERC4626 Router for Yearn V3 vaults.
GNU Affero General Public License v3.0
9 stars 3 forks source link

Yearn ERC4626 Router

This repository contains an open-source ERC4626 Router implementation specific to the Yearn V3 protocol using EIP-4626, including ERC4626Router (the canonical ERC-4626 multicall router). Powered by forge and solmate.

This repository and code was made extending the original ERC4626 Router.

The main change is the addition of a maxLoss variable for withdraw and redeem calls that all Yearn V3 vaults and strategies accept as an optional parameter. As well as the addtion of migrateFromV2 options that is compliant with Yearn V2 vaults for withdraws. There is still 4626 compliant options by using withdrwDefault and redeemDefault.

Deployments

Ethereum - 0x1112dbCF805682e828606f74AB717abf4b4FD8DE

Polygon PoS - 0x1112dbCF805682e828606f74AB717abf4b4FD8DE

Optimism - 0x1112dbCF805682e828606f74AB717abf4b4FD8DE

Using the Router


Important

It is REQUIRED to use multicall to interact across multi-step user flows. The router is stateless other than holding token approvals for vaults it interacts with. Any tokens that end a transaction in the router can be permissionlessly withdrawn by any address, likely an MEV searcher, so make sure to complete all multicalls with token withdrawals to an end user address.

It is recommended to max approve vaults, and check whether a vault is already approved before interacting with the vault. This can save user gas. In cases where the number of required steps in a user flow is reduced to 1, a direct call can be used instead of multicall.


The router is a multicall-style router, meaning it can atomically perform any number of supported actions on behalf of the message sender.

Some example user flows are listed below.

Vault deposit (requires ERC-20 approval of vault underlying asset before calling OR use a self-permit):

WETH vault redeem (requires the router to have ERC-20 approval of the vault shares before calling OR use a self-permit):

2 to 1 vault consolidation (requires ERC-20 approval of both source vault underlying assets OR self-permit):

About ERC-4626

EIP-4626: The Tokenized Vault Standard is an ethereum application developer interface for building token vaults and strategies. It is meant to consolidate development efforts around "single token strategies" such as lending, yield aggregators, and single-sided staking.

ERC4626Router and Base

ERC-4626 standardizes the interface around depositing and withdrawing tokens from strategies.

The ERC4626 Router is an ecosystem utility contract (like WETH) which can route tokens in and out of multiple ERC-4626 strategies in a single call. Its architecture was inspired by the Uniswap V3 multicall router.

Basic supported features include:

Ultimately the ERC4626 router can support an arbitrary number of withdrawals, deposits, and even distinct token types in a single call, subject to the block gas limit.

The router is split between the base ERC4626RouterBase which only handles the ERC4626 mutable methods (deposit/withdraw/mint/redeem) and the main router ERC4626Router which includes support for common routing flows and max logic.

ERC4626RouterBase - basic ERC4626 methods

ERC4626Router - combined ERC4626 methods

PeripheryPayments - WETH and ERC-20 utility methods

Multicall - multicall utility

SelfPermit - user approvals to the router with EIP-712 and EIP-2612