ERC-3386 · Stagnant · ERC · 2021-03-12
ERC-3386: ERC-721 and ERC-1155 to ERC-20 Wrapper
A stagnant interface for pools that lock ERC-721 or ERC-1155 tokens and mint fungible ERC-20 tokens against them, which can later be burned to redeem a random or a chosen NFT.
What problem does it solve?
NFTs (ERC-721) and multi-tokens (ERC-1155) move by individual ID, in whole units. That makes them hard to use in the large ecosystem built for ERC-20: AMMs, lending markets and index products cannot trade or price "one NFT from this collection" generically.
Several projects (NFTX, NFT20, wrapped CryptoKitties, wrapped MoonCats are cited in the spec) solved this by putting NFTs into a pool and issuing fungible tokens that represent a claim on some item in the pool. Each used its own interface. EIP-3386 proposes one common interface, IWrapper, for all of them.
How it works
The spec names three roles, which may all be the same contract:
- Base: the ERC-721 or ERC-1155 tokens being wrapped.
- Pool: the contract holding the deposited base tokens.
- Derivative: the ERC-20 token minted and burned by the wrapper.
Minting: mint(to, id, amount) or batchMint(to, ids, amounts) pulls base tokens from msg.sender into the pool and mints derivative tokens to to. Deposited base tokens must not leave the pool except through a burn.
Burning comes in two flavors:
burn(from, to, amount)/batchBurn(...): burn derivatives and receive some base token; no guarantee which one.idBurn(from, to, id, amount)/batchIdBurn(...): burn derivatives to redeem a specific ID, which an implementation may price differently.
Each operation emits MintSingle, MintBatch, BurnSingle or BurnBatch. For ERC-721, every amount is 1. The exchange rate between base and derivative is left to the implementation (fixed, or set by mechanisms such as Dutch auctions). Contracts must also implement ERC-165.
Sample code
The core of the interface, and a client wrapping one NFT (ethers v6):
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
interface IWrapper /* is ERC165 */ {
event MintSingle(address indexed _from, address indexed _to, uint256 _id, uint256 _amount, uint256 _value);
event BurnSingle(address indexed _from, address indexed _to, uint256 _id, uint256 _amount, uint256 _value);
function mint(address _to, uint256 _id, uint256 _amount) external;
function burn(address _from, address _to, uint256 _amount) external;
function idBurn(address _from, address _to, uint256 _id, uint256 _amount) external;
}
import { Contract } from "ethers";
const nft = new Contract(nftAddress, ["function setApprovalForAll(address,bool)"], signer);
const wrapper = new Contract(wrapperAddress, [
"function mint(address,uint256,uint256)",
"function idBurn(address,address,uint256,uint256)",
], signer);
await (await nft.setApprovalForAll(wrapperAddress, true)).wait();
await (await wrapper.mint(await signer.getAddress(), 42n, 1n)).wait(); // deposit NFT #42, receive ERC-20
Things to know
- Status is Stagnant: it never reached Final, and existing NFT pool protocols use their own interfaces.
- With a fixed exchange rate, the derivative tracks the floor value of the pool; a holder of a rare item loses value by depositing it unless the implementation prices IDs individually.
burnwithout an ID gives whatever the pool chooses, so users wanting a specific item must useidBurn.- The spec does not define a standard way to read the exchange rate or the pool's contents; implementations must document those themselves.