ERC-5058 Lockable NFT standard (Lockable Non-Fungible Tokens)
Stagnant · NFTs & multi-token · created 2022-04-30
A standard that locks an NFT in place in the wallet without transferring it to another contract, allowing safe participation in NFTFi services such as collateralized lending or staking.
Why it is needed
Using existing NFT lending (NFTFi) or collateralized loan services requires transferring the NFT to the service contract. This creates the risk of losing or having the NFT stolen if the contract has a bug or vulnerability. Moving the NFT out of the owner's wallet also means losing utility value such as use as a profile picture or proof of eligibility for a specific community. In addition, airdrops paid to that NFT can no longer be received directly by the owner, causing them to be missed or delayed. The EIP-721 standard itself has no native locking feature, so avoiding these problems required building a separate escrow structure every time.
What to implement
event Locked(address indexed operator, address indexed from, uint256 indexed tokenId, uint256 expired);: Emitted when an operator locks a tokenId owned by from until the expired block number.event Unlocked(address indexed operator, address indexed from, uint256 indexed tokenId);: Emitted when an operator unlocks a tokenId owned by from.event LockApproval(address indexed owner, address indexed approved, uint256 indexed tokenId);: Emitted when an owner grants approved the authority to lock a specific tokenId.event LockApprovalForAll(address indexed owner, address indexed operator, bool approved);: Emitted when an owner grants or revokes an operator's authority to lock all of their tokens.function lockerOf(uint256 tokenId) external view returns (address locker);: Returns the address of the party (locker) that locked the tokenId.function lock(uint256 tokenId, uint256 expired) external;: Locks the tokenId until the expired block number, preventing transfer.function unlock(uint256 tokenId) external;: Unlocks the tokenId.function lockApprove(address to, uint256 tokenId) external;: Grants to the authority to lock a single tokenId.function setLockApprovalForAll(address operator, bool approved) external;: Grants or revokes an operator's authority to lock all tokens owned by the caller.function getLockApproved(uint256 tokenId) external view returns (address operator);: Returns the address approved to lock the tokenId.function isLockApprovedForAll(address owner, address operator) external view returns (bool);: Returns whether the operator has authority to lock all of the owner's tokens.function isLocked(uint256 tokenId) external view returns (bool);: Returns whether the tokenId is currently locked.function lockExpiredTime(uint256 tokenId) external view returns (uint256);: Returns the block number at which the tokenId's lock expires.
In depth
Lock approval structure
The NFT owner grants lock authority to a trusted operator via lockApprove() or setLockApprovalForAll(). lockApprove() applies to a single specified token, while setLockApprovalForAll() applies to the entire collection of tokens held in that wallet. When a user participates in an NFTFi project, the project contract calls lock() to lock the user's NFT, and the locked NFT cannot be transferred.
Lock and unlock authority
Only an approved project contract can lock an NFT via the lock function, and a locked NFT cannot be transferred until the lock period ends. The project contract also has the authority to release the lock early via the unlock function before the period ends. However, only the party that locked the NFT (the locker) has the authority to unlock it.
How the lock period is specified
When locking an NFT, the block number at which the lock ends (expired) must be specified, and this value must be greater than the current block number. Once the current block number passes the specified expiration block number, the NFT is automatically unlocked without any additional call and can be transferred again.
Bound NFT extension
Bound NFT is a concept that extends this standard, allowing a boundNFT with identical metadata to be issued while the NFT is locked. The boundNFT is transferable, exists only during the original NFT's lock period, and is destroyed once the lock is released. The boundNFT can be used as proof of a loan or of staking against a contract, and can either remain with the user or be used for renting out.
Bound NFT Factory
Similar to Uniswap's EIP-20 pair factory, the Bound NFT Factory is a shared factory that uses the create2 method to generate a deterministic boundNFT contract address for each NFT contract. The resulting boundNFT contract can only be controlled by the original NFT contract.
Compatibility with EIP-721
This standard is designed to be compatible with EIP-721, functioning as an extension interface that adds locking functionality to existing EIP-721 tokens.
Proposal status
This EIP is currently in Stagnant status, meaning it is no longer actively discussed or progressing. Its content may change or may never be adopted.
Things to watch out for
- Risk of being unable to unlock: Before granting lock authority to another project contract, you must verify that the contract can actually unlock the NFT. Otherwise there is a risk that the NFT will remain permanently locked.
- Setting an appropriate lock period: Projects are recommended to set a reasonable lock period when in use. Since the lock is automatically released once the expiration block number passes, this somewhat reduces the risk of permanent locking.