ERC-7417 · Review · ERC · 2023-07-27
ERC-7417: Token Converter
A proposed singleton converter contract that creates one canonical ERC-223 wrapper for any ERC-20 token (and vice versa) and swaps between the two versions 1:1 at any time.
What problem does it solve?
ERC-223 is an alternative fungible-token standard: transfers to a contract call a tokenReceived hook on the recipient, so tokens cannot silently get stuck in contracts that do not expect them. But almost the whole ecosystem is built on ERC-20, so a new token gains little by choosing ERC-223 alone, and existing tokens cannot switch.
ERC-7417 proposes a Token Converter: one contract that lets anyone create an ERC-223 version of any existing ERC-20 (or an ERC-20 version of an ERC-223 token), with free conversion in both directions. Both versions can then coexist, and a DEX can treat a token and its converter wrapper as provably the same asset.
How it works
- One wrapper per origin, per standard. The converter deploys wrappers with
CREATE2, sopredictWrapperAddress(token, isERC20)can compute the address before deployment.getERC223WrapperFor,getERC20WrapperFor,getERC20OriginFor,getERC223OriginForandisWrapperlet other contracts verify the link. - ERC-20 → ERC-223. The holder approves the converter and calls
wrapERC20toERC223(token, amount)(or the auto-detectingconvertERC20). The converter pulls the ERC-20 withtransferFrom, locks it, and mints exactly the same amount of the ERC-223 wrapper. It creates the wrapper first if needed. - ERC-223 → ERC-20. The holder simply
transfers the ERC-223 wrapper to the converter. ItstokenReceivedhook burns the wrapper and releases the locked originals. If an original ERC-223 token is sent instead, the converter issues its ERC-20 wrapper. - Wrapper features. Converter-made ERC-223 wrappers also implement
approve/transferFromfor compatibility, emit ERC-20 styleTransferevents so explorers recognise them, and exposestandard()returning223for introspection, because ERC-165 cannot tell ERC-20 and ERC-223transferlogic apart. - Stuck-token recovery. The converter records how much of each ERC-20 it received legitimately, so tokens sent to it by mistake can be computed and extracted with
extractStuckERC20.
Sample code
Upgrading 100 units of an ERC-20 to its ERC-223 version and back (ethers v6):
import { Contract, parseUnits } from "ethers";
const erc20 = new Contract(tokenAddr, ["function approve(address,uint256) returns (bool)"], signer);
const converter = new Contract(converterAddr, [
"function wrapERC20toERC223(address,uint256) returns (bool)",
"function getERC223WrapperFor(address) view returns (address)",
], signer);
const amount = parseUnits("100", 18);
await (await erc20.approve(converterAddr, amount)).wait();
await (await converter.wrapERC20toERC223(tokenAddr, amount)).wait();
// Back to ERC-20: just transfer the ERC-223 wrapper to the converter
const wrapperAddr = await converter.getERC223WrapperFor(tokenAddr);
const erc223 = new Contract(wrapperAddr, ["function transfer(address,uint256) returns (bool)"], signer);
await (await erc223.transfer(converterAddr, amount)).wait();
Things to know
- Status is Review. The spec says the canonical converter address should be listed in the proposal; check the current text before relying on any deployed instance.
- The spec text still has rough edges, for example
unwrapERC20toERC223repeats the wrap description and the conversion steps mention aconvertERC20toERC223function that is not defined. Follow the reference implementation for exact behaviour. - The converter cannot verify which standard a token really implements, so any token can end up with up to two wrappers. A wrapper's existence does not prove the origin is fully standard-compliant.
- Tokens whose balances can shrink on their own (rebasing down, fees on transfer, decay) should not be wrapped: the converter could not guarantee 1:1 redemption.
transferFromon an ERC-223 wrapper bypasses the recipient hook, so tokens can still get stuck that way. Prefertransfer.