ERC-7721 ERC-1155 locking extension (Lockable Extension for ERC-1155)
Draft · NFTs & multi-token · created 2023-05-25
An extension that allows a specified quantity of ERC-1155 tokens to be locked while remaining in the owner's wallet. While locked, transfers are blocked, and only the designated unlock authority (locker) can unlock them.
Why it is needed
Currently, to use an NFT as loan collateral or to lend it out, the token must be moved to that service's contract. Moving it into this kind of custodial account (escrow) creates three problems. First, since the token leaves the owner's hands, its utility value, such as Discord server entry verification or in-game use, is lost. Second, multiple financial tools cannot be combined, such as using a single NFT for both borrowing and lending at the same time. Third, if the custodial contract has a bug or vulnerability, the NFT can be stolen or lost. This standard adds a mechanism to ERC-1155 that locks the token within the owner's wallet instead of moving it. During the lock period, only transfers are restricted while all other properties are retained, so the owner can continue to use the token, much like someone can keep living in a house even while it is pledged as collateral.
What to implement
event Lock(uint256 indexed tokenId, address account, address _locker, uint256 amount);: An event emitted when a token is locked.event Unlock (uint256 indexed tokenId, address account, address _locker, uint256 amount);: An event emitted when a token's lock is released.function lock(uint256 tokenId, address account, uint256 amount) external;: When the caller is the owner or an approved address, this locks the token and sets the unlock authority to the caller itself.function lock(uint256 tokenId, address account, address _locker, uint256 amount) external;: When the caller is the owner, this locks the token and sets the unlock authority to _locker.function unlock(uint256 tokenId, address account, uint256 amount) external;: When the caller is the unlock authority, this releases the lock.function transferAndLock(address from, address to, uint256 tokenId, uint256 amount, bool setApprove) external;: Transfers the token while immediately locking it at the receiving address. If setApprove is true, approval is also granted to the caller.function getLocked(uint256 tokenId, address account, address operator) external view returns (uint256);: Returns the quantity that operator has locked for account. 0 means it is not locked.function setApprovalForId(uint256 tokenId, address operator, uint256 amount) external;: Approves the quantity that operator can use for a specific tokenId.
In depth
The two lock functions and locker designation
There are two forms of lock. lock(uint256 tokenId, address account, address _locker, uint256 amount) is called by the owner and MUST set the locker to _locker. lock(uint256 tokenId, address account, uint256 amount) is called by the owner or an approved address and must set the locker to msg.sender. lock MUST revert if account's balance is insufficient or if the caller is neither the owner nor an approved address for tokenId. These authorities are extinguished once the token is transferred.
Per-quantity locking and transfer restriction
Since ERC-1155 can have multiple tokens under a single tokenId, locking also operates on a per-quantity basis. getLocked(uint256 tokenId, address account, address operator) MUST return the quantity that operator has locked for account, and MUST return 0 for tokens that are not locked. ERC-1155's safeTransferFrom MUST revert if it attempts to transfer a locked quantity, and the maximum transferable quantity MUST be balance - getLocked. unlock(uint256 tokenId, address account, uint256 amount) MUST revert if the specified quantity is not locked.
Per-tokenId approval
The owner can use setApprovalForId(uint256 tokenId, address operator, uint256 amount) to approve an operator for a quantity limit on a specific tokenId only. This way, the operator can use only the approved tokenId. getApprovalForId(uint256 tokenId, address account, address operator) returns the approved quantity. An approved address can lock the asset while holding token approval, in which case the locker becomes itself.
transferAndLock and recovery after transfer
transferAndLock(address from, address to, uint256 tokenId, uint256 amount, bool setApprove) transfers the token while locking it at the receiving address. If setApprove is true, approval is granted to the locker together, allowing the locker to later revoke the token. The revocation condition is defined in the contract, and approval is granted to that contract. This allows granting the recipient conditional ownership without transfer rights, which is recommended for uses such as buy-now-pay-later (BNPL) that require recovery after transfer.
Differences from other locking proposals
This proposal defines only a minimal implementation of lock and unlock. Conditions such as time-limited locks are not built into the token contract, on the view that they can be implemented via a separate smart contract, leaving it open to lock and unlock under any condition such as repayment or expiration. It also separates the rights of the locker from those of an approved address. Locking together with approval allows the approved party to also unlock and withdraw, which can be used for lending, borrowing, and BNPL, while locking without recovery rights allows only unlocking, which can be used for account-bound tokens.
ERC-1155 Compatibility
This standard is compatible with ERC-1155 and requires ERC-165 and ERC-1155. Existing upgradeable ERC-1155 contracts can be upgraded to this standard to build in locking functionality and unlock liquidity features. The interface IERCLockable1155 inherits from IERC1155.
Proposal status
This proposal is currently in Draft status. Since its contents may still change, it is advisable to check the latest original text before implementing it.
Things to watch out for
- A locked quantity cannot be transferred: Once a given quantity is locked, that quantity cannot be transferred from the locked account. A contract handling this must calculate the transferable quantity separately.
- When holding both the locker role and approval: While a token is locked, if the caller is both the locker and an approved address, that caller can transfer the token.
- Risk of permanent lock: Locking by designating an inaccessible account or an unverified contract address as the locker can result in the token being permanently locked.