EIPs Explained

ERC-5143 · Stagnant · ERC · 2022-06-09

ERC-5143: Slippage Protection for Tokenized Vault

Proposed ERC-4626 vault extension adding deposit, mint, withdraw and redeem overloads with a min/max bound, so wallet users can revert if the share price moves against them.

What problem does it solve?

ERC-4626 standardises yield-bearing vaults: you deposit an underlying ERC-20 asset and receive shares. Smart contracts can call previewDeposit and then deposit in the same transaction, so they always get what they previewed.

A user with a normal wallet (EOA) cannot do that. They see a preview in a UI, sign, and the transaction is mined some time later. In between, the share price can change, or the transaction can be front-run, and the user gets fewer shares (or more cost) than expected. ERC-4626's own security notes say vaults serving EOAs should offer slippage-protected variants, but it never defined them. EIP-5143 standardises those functions so wallets and frontends can rely on them.

How it works

Each ERC-4626 action gets an overload with one extra bound. The function does the normal ERC-4626 operation and reverts if the bound is broken:

Function Extra parameter Reverts if
deposit(assets, receiver, minShares) minShares fewer than minShares shares minted
mint(shares, receiver, maxAssets) maxAssets it costs more than maxAssets
withdraw(assets, receiver, owner, maxShares) maxShares more than maxShares shares burned
redeem(shares, receiver, owner, minAssets) minAssets fewer than minAssets assets sent

They emit the usual Deposit / Withdraw events and follow the same approval rules as ERC-4626. Any contract implementing this must also implement ERC-4626. The original functions stay; these are additions.

Sample code

Vault side, from the spec's reference implementation (one function shown):

function deposit(uint256 assets, address receiver, uint256 minShares)
    public virtual returns (uint256 shares)
{
    shares = deposit(assets, receiver);                 // plain ERC-4626 deposit
    require(shares >= minShares, "ERC5143: deposit slippage protection");
}

Wallet side with ethers v6, allowing 0.5 % slippage:

import { Contract } from "ethers";

const vault = new Contract(vaultAddress, [
  "function previewDeposit(uint256) view returns (uint256)",
  "function deposit(uint256,address,uint256) returns (uint256)",
], signer);

const expected: bigint = await vault.previewDeposit(assets);
const minShares = (expected * 995n) / 1000n;
// Overloaded name, so select the 3-argument signature explicitly
const tx = await vault["deposit(uint256,address,uint256)"](assets, await signer.getAddress(), minShares);
await tx.wait();

Things to know

  • Status: Stagnant. Do not assume a given vault has these overloads; check its ABI first.
  • The functions are overloads, so in ethers and similar libraries you must call them by full signature.
  • The alternative the spec mentions is a router contract (like Uniswap's) that adds the slippage check on top of any ERC-4626 vault. That is more flexible but costs more gas, because the router has to take temporary custody of the tokens.
  • This addresses one ERC-4626 security consideration only; the others (rounding, inflation attacks on empty vaults, etc.) still apply.

#defi #vault #erc4626 #slippage #token

Details

Authors
Hadrien Croubois (@amxx)
Status
Stagnant
Type
Standards Track / ERC
Created
2022-06-09
Requires

Machine-readable: Markdown · JSON