ERC-5753 · Stagnant(停滞) · ERC · 2022-10-05
ERC-5753: Lockable Extension for EIP-721
一项 ERC-721 扩展,让所有者在自己的钱包里锁定 NFT,在指定的解锁者地址释放它之前阻止转移,使 NFT 可以在不离开持有者钱包的情况下用作抵押或出租。
它解决什么问题?
在 DeFi 中,把代币用作抵押通常意味着把它存入借贷合约。这对 ETH 或 ERC-20 代币行得通,但 NFT 的效用取决于它放在哪里:在社交媒体上验证过的头像、需要持有代币才能进入的 Discord 角色、游戏道具。把 NFT 转入托管合约会破坏这一切。
ERC-5753 提出了另一种模式:NFT 留在所有者的钱包里,但被锁定,只有指定的**解锁者(unlocker)**才能释放或转移它。规范列出了这些用途:
- 无需托管的 NFT 抵押贷款
- 无需大额抵押的租赁(租户持有代币但不能出售)
- 分期付款购买
- 额外的安全性:把贵重的 NFT 锁在热钱包里,并以冷钱包作为解锁者
- 非托管质押,以及活动期间无法转售的活动门票
它如何运作
该接口在 ERC-721 之上增加三个函数和两个事件:
interface ILockable {
event Lock(address indexed unlocker, uint256 indexed id);
event Unlock(uint256 indexed id);
function lock(address unlocker, uint256 id) external;
function unlock(uint256 id) external;
function getLocked(uint256 tokenId) external view returns (address);
}
规范中的规则:
getLocked对已锁定的代币返回其解锁者,未锁定则返回address(0)。- 锁定期间,每一次 ERC-721 转移都必须 revert,除非由解锁者发起,并且
approve必须 revert。 getApproved应返回解锁者,使其可以用标准的转移调用来移动代币。- 对已锁定的代币调用
lock必须 revert。 - 如果解锁者转移了代币,转移之后它就变为未锁定。
- 以
address(1)作为解锁者进行锁定,会永久锁定代币。 supportsInterface(0x72b68110)必须返回true(ERC-165)。
市场应检查 getLocked,并隐藏已锁定代币的挂单,因为这类订单无法成交。
示例代码
借贷协议检查并使用锁定(ethers v6):
import { Contract, ZeroAddress } from "ethers";
const nft = new Contract(nftAddress, [
"function supportsInterface(bytes4) view returns (bool)",
"function getLocked(uint256) view returns (address)",
"function lock(address unlocker, uint256 id)",
], borrowerSigner);
if (!(await nft.supportsInterface("0x72b68110"))) throw new Error("not lockable");
if ((await nft.getLocked(tokenId)) !== ZeroAddress) throw new Error("already locked");
// Borrower locks the NFT with the lending contract as unlocker.
await (await nft.lock(lendingContract, tokenId)).wait();
// On repayment the lender calls unlock(id); on default it can transferFrom
// the NFT to itself, which also clears the lock.