ERC-5753 · Stagnant(정체) · ERC · 2022-10-05
ERC-5753: Lockable Extension for EIP-721
소유자가 자신의 지갑 안에서 NFT를 잠그고, 지정된 unlocker 주소가 풀어줄 때까지 전송을 막을 수 있게 하는 ERC-721 확장. NFT를 보유자의 지갑 밖으로 내보내지 않고도 담보나 대여에 쓸 수 있다.
어떤 문제를 해결하나요?
DeFi에서 토큰을 담보로 쓰려면 보통 대출 컨트랙트에 예치해야 합니다. ETH나 ERC-20 토큰은 그래도 되지만, NFT의 효용은 어디에 있느냐에 달려 있습니다. 소셜 미디어에서 인증된 프로필 사진, 토큰으로 접근을 제한한 Discord 역할, 게임 아이템 등입니다. NFT를 에스크로 컨트랙트로 옮기면 이 모든 것이 깨집니다.
ERC-5753은 다른 패턴을 제안합니다. NFT는 소유자의 지갑에 남아 있되 잠기고, 지명된 unlocker만 이를 풀거나 옮길 수 있습니다. 명세는 다음과 같은 용도를 듭니다.
- 에스크로 없는 NFT 담보 대출
- 큰 담보 없는 대여(빌리는 사람은 토큰을 가지고 있지만 팔 수 없음)
- 분할 결제 구매
- 추가 안전장치: 가치 있는 NFT를 핫 월렛에서 잠그고 콜드 월렛을 unlocker로 지정
- 비수탁형 스테이킹과, 행사 도중 되팔 수 없는 행사 티켓
어떻게 동작하나요?
이 인터페이스는 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는 잠긴 토큰의 unlocker를 반환하고, 잠기지 않았으면address(0)을 반환합니다.- 잠겨 있는 동안 모든 ERC-721 전송은 unlocker가 시작한 것이 아닌 한 반드시 revert해야 하며,
approve도 revert해야 합니다. getApproved는 unlocker를 반환해야 하며, 그래야 unlocker가 표준 전송 호출로 토큰을 옮길 수 있습니다.- 이미 잠긴 토큰에
lock을 호출하면 revert해야 합니다. - unlocker가 토큰을 전송하면 전송 후에 잠금이 풀립니다.
address(1)을 unlocker로 하여 잠그면 토큰은 영구히 잠깁니다.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.