ERC-5143 Tokenized vault slippage protection (Slippage Protection for Tokenized Vault)

Stagnant · Vaults & DeFi · created 2022-06-09

Standardizes slippage protection functions that revert a transaction when an EOA depositing into or withdrawing from an Ethereum vault (ERC-4626 Vault) directly gets a result different from what was expected.

Why it is needed

The exchange rate between deposited assets and received shares in an ERC-4626 vault can change. A contract can atomically check the result with a preview right before calling deposit or mint, but an EOA that signs directly from a wallet is different. There is a time gap between signing a transaction based on the expected figures shown on the wallet screen and the transaction actually being included and executed in a block, and if the vault's state or price changes in that interval, the EOA may receive fewer shares than expected or have to pay more assets than expected. There is also a risk that this gap could be exploited through frontrunning. The ERC-4626 specification itself mentions this problem and states that a function to mitigate slippage is needed, but since it does not define that function's name or behavior, implementations vary from vault to vault, making it difficult for wallets and apps to write compatible code.

What to implement

In depth

deposit: exact deposit, guaranteed share floor

deposit is a function that overloads ERC-4626's deposit, depositing assets of the underlying asset to mint exactly shares to receiver. It MUST emit a Deposit event and MUST support the deposit flow via ERC-20's approve/transferFrom. A vault MAY optionally support a flow where it already holds the tokens before execution. If the full amount of assets cannot be deposited due to deposit limits, slippage, insufficient allowance, etc., it must revert, and in particular it MUST revert if the actual minted shares are fewer than minShares.

mint: exact share issuance, guaranteed asset ceiling

mint overloads ERC-4626's mint, minting exactly shares to receiver while depositing as many assets as required. It must emit a Deposit event and must support the ERC-20 approve/transferFrom flow. It reverts if the full amount of shares cannot be minted, and MUST revert if the assets required to mint those shares exceed maxAssets.

withdraw: exact withdrawal, guaranteed share-burn ceiling

withdraw overloads ERC-4626's withdraw, burning owner's shares to send exactly assets to receiver. It must support the withdrawal flow and emit a Withdraw event whenever owner is msg.sender, or msg.sender has ERC-20 approval over owner's shares. It reverts if the full amount of assets cannot be withdrawn due to withdrawal limits, slippage, insufficient shares, etc., and MUST revert if withdrawing assets requires burning more shares than maxShares. Some implementations may require a separate prior request before withdrawal.

redeem: exact share burn, guaranteed asset floor

redeem overloads ERC-4626's redeem, burning exactly shares from owner and sending the corresponding assets to receiver. It must support the flow for the owner themselves or an approved msg.sender, and must emit a Withdraw event. It reverts if the full amount of shares cannot be redeemed, and MUST revert if the assets receiver gets from the redemption are fewer than minAssets.

Overload design and frontrunning risk

The functions in this standard do not replace ERC-4626's existing mechanisms; they are added overload functions for EOA protection. A contract can atomically pre-check the result with a preview function before interacting with the vault, so it faces no price-change risk, but an EOA previews in the UI, signs the transaction, and has it mined later, so state can change in between, exposing it to frontrunning and similar risks. Other DeFi projects such as decentralized exchanges already have similar mechanisms that revert when the result falls short of the desired exchange rate.

Comparison with the router approach, and a simple implementation

An alternative is to handle slippage protection not in the vault itself but in a general-purpose router dedicated to ERC-4626, similar to Uniswap V2/V3's router. The router approach is more flexible and lets you swap out just the router later, but it has the downside of higher computation cost since the router has to temporarily hold the tokens going into the vault. In contrast, applying this ERC on top of an existing ERC-4626 implementation is simple: as the reference implementation shows, you just call the relevant ERC-4626 function and add a require check on the return value.

Proposal status

This proposal is currently in Stagnant status, meaning it is no longer being actively discussed and has stalled. The specification may change or resume, so its current status should be checked before any real-world application.

Things to watch out for

Original ERC · ← ERCs