ERC-5501 NFT rental and delegation extension (Rental & Delegation NFT - EIP-721 Extension)
Stagnant · NFTs & multi-token · created 2022-08-18
Adds a 'user' role to ERC-721, separate from the owner, so an NFT can be lent out or delegated to another wallet while remaining in the owner's wallet.
Why it is needed
In ERC-721, only the owner can enjoy the token's benefits. There are many cases, such as game assets, metaverse land, and event tickets, where separating ownership from usage would be useful, but the standard itself makes no such distinction. Existing lending approaches commonly rely on staking, where the NFT is deposited into a contract as collateral; in that case the owner effectively gives up ownership and loses owner benefits such as airdrops or free mints. Also, if the owner can reset the user at any time, the lender can revoke usage rights during the lending period at will, leaving the borrower unprotected. Delegation has the same problem: if someone only wants to hand usage rights to a hot wallet, without a standardized method every service ends up using its own ad hoc workaround.
What to implement
event UpdateUser(uint256 indexed _tokenId, address indexed _user, uint64 _expires, bool _isBorrowed);: Emitted when a token's user information (address, expiry time, borrowed status) changes.function setUser(uint256 _tokenId, address _user, uint64 _expires, bool _isBorrowed) external;: Sets a token's user, expiry time, and borrowed status. The call is rejected if the token is currently borrowed and not yet expired.function userOf(uint256 _tokenId) external view returns (address);: Returns the token's current user address. Returns the zero address if unset or expired.function userExpires(uint256 _tokenId) external view returns (uint64);: Returns the Unix timestamp at which the user status expires.function userIsBorrowed(uint256 _tokenId) external view returns (bool);: Returns whether the token is currently in a borrowed state.function userBalanceOf(address _user) external view returns (uint256);: Returns the number of tokens for which a given address is designated as the user.function tokenOfUserByIndex(address _user, uint256 _index) external view returns (uint256);: Iterates by index over the tokens for which a given address is the user and returns the corresponding token ID.event AgreeToTerminateBorrow(uint256 indexed _tokenId, address indexed _party, bool _isLender);: Emitted when either the lender or the borrower agrees to early termination of the rental.event ResetTerminationAgreements(uint256 indexed _tokenId);: Emitted when the early termination agreement state is reset.event TerminateBorrow(uint256 indexed _tokenId, address indexed _lender, address indexed _borrower, address _caller);: Emitted when a rental actually ends.function setBorrowTermination(uint256 _tokenId) external;: Records the early termination agreement of the calling party (lender or borrower). If both are the same address, it records agreement from both sides at once.function getBorrowTermination(uint256 _tokenId) external view returns (bool, bool);: Returns whether the lender and the borrower have each agreed to termination.function terminateBorrow(uint256 _tokenId) external;: Ends the rental and clears the borrowed status once both parties have agreed. Can be called by anyone.
In depth
Scope of authority for the user role
The user is not the owner and cannot execute transfers or approvals. Beyond that, exactly what specific rights are granted to the user is left to the implementing contract to define.
setUser call conditions and rental protection
setUser should only be callable by the owner or an approved operator (SHOULD revert otherwise), and the user address must not be zero. If userIsBorrowed is true and userExpires is greater than or equal to block.timestamp, setUser must revert.
Handling the user on transfer
When a token is transferred, the user must be reset if it is not currently borrowed, and must remain unchanged if it is currently borrowed.
EIP-165 interface identifier
IERC5501 is 0xf808ec37, IERC5501Balance is 0x0cb22289, IERC5501Enumerable is 0x1d350ef8, and IERC5501Terminable is 0x6a26417e. supportsInterface(0xf808ec37) must return true.
Balance and Enumerable extensions
Both are optional. userBalanceOf should revert for the zero address, and tokenOfUserByIndex should handle the case where the address is zero or the index is greater than or equal to userBalanceOf. How to determine expiry of user status and reflect it in balance is left to the implementation.
Terminable extension: early termination
setBorrowTermination records the agreement of the calling party (lender = ownerOf, borrower = userOf); if both are the same address, it records agreement from both sides at once. getBorrowTermination returns each party's agreement status separately. terminateBorrow only executes once both parties have agreed, and must revert otherwise. On success it should (SHOULD) change isBorrowed from true to false. On transfer, the termination agreement status of a token that was being borrowed must be reset.
The meaning of retaining ownership
Because the token stays in the owner's wallet even while on loan, benefits such as receiving airdrops, claiming free mints, and keeping a sale listing active are preserved. Existing collateral (staking) based rental approaches required a separate implementation to obtain these benefits.
Proposal status
This proposal is a follow-up to EIP-4400 and EIP-4907, written on 2022-08-18, but its current status is Stagnant, with discussion stalled.
Things to watch out for
- Care in designing permissions: Implementers and applications must carefully consider what rights to grant to the owner versus the user respectively. Because both roles can be active at the same time, double-spending issues must be prevented.
- Gas cost of the Balance extension: The Balance extension must be implemented in a way that does not cause gas problems.
- Disclosure of rental status: Marketplaces must inform users whether a listed token is currently on loan or not.