ERC-6120 · Review · ERC · 2022-12-12
ERC-6120: Universal Token Router
A single shared router that users approve once, which then moves tokens only in transactions they sign themselves and checks the resulting balances, replacing per-app approve-then-call.
What problem does it solve?
Sending ETH to a contract is one step: the value travels with the call. ERC-20 tokens cannot do that, so apps use approve-then-call: first you approve the app's contract, then it pulls your tokens. Each new app needs a new approval, approvals often point at upgradable or unaudited contracts, and leftover allowances have been the root of many exploits.
The Universal Token Router (UTR) separates the allowance from the application. You approve one router; the router only moves your tokens inside a transaction you sent to it, and can verify that you actually received what you expected.
How it works
Users call one function, exec(outputs, actions):
outputs— balance checks. For each item (recipient, token standard, token, id,amountOutMin), the router records the balance at the start and end ofexecand reverts withINSUFFICIENT_OUTPUT_AMOUNTif the gain is too small. The spec calls this security-by-result: what matters is that you ended up with the expected tokens.actions— a list of{inputs, code, data}. For each action, the router first handles theinputs, then callscodewithdata.
Each Input has a mode:
| Mode | Meaning |
|---|---|
PAYMENT (0) |
Allow up to amountIn to be pulled from the sender to recipient during this transaction only, via UTR.pay(...) (for callback-style apps such as flash loans or Uniswap v3 pools) |
TRANSFER (1) |
Transfer tokens from the sender to recipient right away |
CALL_VALUE (2) |
Forward this much ETH as the call value |
Tokens are identified by eip: 0 for ETH, otherwise 20, 721 or 1155.
To stop the router from being tricked into calling transferFrom on a token, the target code must look like a non-token: either inherit the NotToken helper or report ERC-165 interface 0x61206120. Pending payments are cleared before exec returns (the reference implementation uses transient storage), and leftover ETH is refunded.
New tokens can trust the UTR as an unlimited spender, so users never need an approval at all. The spec says the router is deployed at the same address on EVM chains via the EIP-1014 singleton factory.
Sample code
Swapping through a UTR-aware helper and requiring a minimum output (ethers v6):
import { Contract, MaxUint256 } from "ethers";
const TRANSFER = 1n;
// one-time approval for existing tokens
await tokenIn.approve(utrAddress, MaxUint256);
await utr.exec(
[{ recipient: me, eip: 20n, token: tokenOutAddr, id: 0n, amountOutMin: minOut }],
[{
inputs: [{ mode: TRANSFER, recipient: pairAddr, eip: 20n, token: tokenInAddr, id: 0n, amountIn }],
code: helperAddr, // must be a NotToken / 0x61206120 contract
data: helper.interface.encodeFunctionData("swapExactTokensForTokens",
[amountIn, minOut, [tokenInAddr, tokenOutAddr], me, deadline]),
}],
);
An app contract that the router is allowed to call:
abstract contract NotToken {
function allowance(address, address) external pure returns (string memory) { return "THIS IS NOT A TOKEN"; }
function isApprovedForAll(address, address) external pure returns (string memory) { return "THIS IS NOT A TOKEN"; }
}
contract SwapHelper is NotToken { /* swap logic that sends output to `recipient` */ }
Things to know
- Status: Review. Not Final; interfaces may still change.
- Token contracts must never report interface
0x61206120; if they do, anyone can spend balances approved to the UTR. - Tokens sent to the router itself are lost. Send only as much ETH as the actions spend, as excess could be taken by a re-entrant action.
discard(used for sender authentication) cannot be verified by balances, so only rely on it with a router you trust.- Apps that credit
msg.senderinstead of an explicitrecipientneed an adapter to work with the UTR. - For signature-based approvals of a single token, compare ERC-2612
permit; the UTR explicitly does not use permit signatures.