ERC-7621 · Draft · ERC · 2024-02-11
ERC-7621: Basket Token
A draft standard for ERC-20 basket (index) tokens: the token holds several ERC-20s at target weights, users contribute and withdraw proportionally, and an ERC-173 owner can rebalance.
What problem does it solve?
Tokenised index funds, portfolio products and treasury diversification baskets all do the same thing: hold several tokens at target weights and issue a share token for them. Each protocol uses its own interface, so wallets, aggregators and DeFi protocols must integrate them one by one.
ERC-4626 covers single-asset vaults and ERC-7575 covers multi-asset entry points, but neither treats the composition (which tokens, at what weights) as standard state, or models a manager who rebalances. ERC-7621 does.
How it works
The basket contract is itself the ERC-20 share token. It also implements ERC-165 (interface ID 0xc9c80f73) and ERC-173 ownership.
- Composition:
getConstituents()returns token addresses and target weights in basis points (summing to 10000).getWeight,isConstituent,totalConstituentsandgetReserve(accounted reserve per token) are views. - Contribute:
contribute(amounts, receiver, minShares)pulls each constituent (pre-approved) and mints shares.amountsfollows the order fromgetConstituents(). Shares round down, andminSharesprotects against slippage. - Withdraw:
withdraw(lpAmount, receiver, minAmounts)burns shares first, then sendsreserve_i * lpAmount / totalSupplyof each constituent, rounded down. - Rebalance:
rebalance(newTokens, newWeights)is owner-only. It replaces the constituent list and weights and emitsRebalanced. Whether swaps happen is up to the implementation. - Valuation:
totalBasketValue()uses an implementation-defined, deterministic method (sum of balances, oracle prices, TWAP…). It is not comparable across baskets. previewContributeandpreviewWithdrawmust match what the real calls would return in the same transaction.
Fees, oracles and swap routing are explicitly out of scope.
Sample code
Contributing to a basket in its current order (ethers v6):
import { Contract, Wallet, JsonRpcProvider, MaxUint256 } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const signer = new Wallet(process.env.PRIVATE_KEY!, provider);
const basket = new Contract(basketAddress, [
"function getConstituents() view returns (address[] tokens, uint256[] weights)",
"function previewContribute(uint256[] amounts) view returns (uint256)",
"function contribute(uint256[] amounts, address receiver, uint256 minShares) returns (uint256)",
], signer);
const [tokens] = await basket.getConstituents();
const amounts: bigint[] = tokens.map(() => 10n ** 18n); // 1 unit each, same order
for (const t of tokens) {
const erc20 = new Contract(t, ["function approve(address,uint256) returns (bool)"], signer);
await (await erc20.approve(basketAddress, MaxUint256)).wait();
}
const expected = await basket.previewContribute(amounts);
await basket.contribute(amounts, signer.address, (expected * 99n) / 100n); // 1% slippage
Things to know
- Status: Draft. The interface was revised during discussion and may change again.
- Holders trust the owner: they can swap constituents for illiquid tokens or rebalance at bad prices. Timelocks or governance are optional, not required.
- If any constituent is paused or blacklists the basket,
withdrawcan revert for everyone. - Fee-on-transfer and rebasing tokens can desync internal reserves. Donations, first-depositor inflation and preview manipulation are also called out in the spec; never use preview functions as price oracles.
- Renouncing ownership disables
rebalancepermanently.