ERC-2615 NFT Rental and Mortgage Extension (Non-Fungible Token with mortgage and rental functions)
Stagnant · NFTs & multi-token · created 2020-04-25
Adds User and Lien Holder roles to ERC721 NFTs, allowing NFTs to be rented out or used as collateral without a security deposit or ownership escrow.
Why it is needed
ERC721 only defines an Owner role, so renting out or using an NFT as collateral required building a separate mechanism outside the standard. Trustless rental required the lessor to hold a security deposit against potential abuse by the tenant, and using an NFT as collateral meant transferring ownership of the NFT into a contract and locking it in escrow. Since most NFT services only offer functionality to the owner, an NFT locked in escrow could no longer be used. Logic for tracking and relaying rental and lien relationships was also separate from the ERC721 standard, requiring a custom implementation every time.
What to implement
event TransferUser(address indexed from, address indexed to, uint256 indexed itemId, address operator);: Event emitted when the User role is transferred to another address.event ApprovalForUser(address indexed user, address indexed approved, uint256 itemId);: Event emitted when approval is set for transferring the User role of a specific token.event TransferOwner(address indexed from, address indexed to, uint256 indexed itemId, address operator);: Event emitted when the Owner role is transferred to another address.event ApprovalForOwner(address indexed owner, address indexed approved, uint256 itemId);: Event emitted when approval is set for transferring the Owner role of a specific token.event ApprovalForAll(address indexed owner, address indexed operator, bool approved);: Event emitted when authority over all tokens is batch delegated to or revoked from a specific operator.event LienApproval(address indexed to, uint256 indexed itemId);: Event emitted when a specific address is approved to set a lien.event TenantRightApproval(address indexed to, uint256 indexed itemId);: Event emitted when a specific address is approved to set a tenant right.event LienSet(address indexed to, uint256 indexed itemId, bool status);: Event emitted when a lien is set or released on a token.event TenantRightSet(address indexed to, uint256 indexed itemId,bool status);: Event emitted when a tenant right is set or released on a token.function balanceOfOwner(address owner) public view returns (uint256);: Returns the number of tokens a specific address holds as Owner.function balanceOfUser(address user) public view returns (uint256);: Returns the number of tokens a specific address holds as User.function userOf(uint256 itemId) public view returns (address);: Returns the current User address of a token.function ownerOf(uint256 itemId) public view returns (address);: Returns the current Owner address of a token.function safeTransferOwner(address from, address to, uint256 itemId) public;: Safely transfers the Owner role to another address.function safeTransferOwner(address from, address to, uint256 itemId, bytes memory data) public;: Safely transfers the Owner role along with data.function safeTransferUser(address from, address to, uint256 itemId) public;: Safely transfers the User role to another address.function safeTransferUser(address from, address to, uint256 itemId, bytes memory data) public;: Safely transfers the User role along with data.function approveForOwner(address to, uint256 itemId) public;: Approves a specific address to transfer the Owner role of a token.function getApprovedForOwner(uint256 itemId) public view returns (address);: Looks up the address approved to transfer the Owner role.function approveForUser(address to, uint256 itemId) public;: Approves a specific address to transfer the User role of a token.function getApprovedForUser(uint256 itemId) public view returns (address);: Looks up the address approved to transfer the User role.function setApprovalForAll(address operator, bool approved) public;: Batch delegates or revokes authority over all of one's tokens to a specific operator.function isApprovedForAll(address requester, address operator) public view returns (bool);: Checks whether an operator has received batch delegation from a given address.function approveLien(address to, uint256 itemId) public;: Approves a specific address to set a lien on a token.function getApprovedLien(uint256 itemId) public view returns (address);: Looks up the address approved to set a lien.function setLien(uint256 itemId) public;: Lets an approved address set a lien on a token.function getCurrentLien(uint256 itemId) public view returns (address);: Looks up the lien holder currently set on a token.function revokeLien(uint256 itemId) public;: Releases a set lien.function approveTenantRight(address to, uint256 itemId) public;: Approves a specific address to set a tenant right on a token.function getApprovedTenantRight(uint256 itemId) public view returns (address);: Looks up the address approved to set a tenant right.function setTenantRight(uint256 itemId) public;: Lets an approved address set a tenant right on a token.function getCurrentTenantRight(uint256 itemId) public view returns (address);: Looks up the tenant right holder currently set on a token.function revokeTenantRight(uint256 itemId) public;: Releases a set tenant right.function onERCXReceived(address operator, address from, uint256 itemId, uint256 layer, bytes memory data) public returns(bytes4);: The callback function that a contract must implement to safely receive an Owner or User role.
In depth
Three roles: Lien Holder, Owner, User
This standard splits ERC721's single Owner structure into three roles. The Lien Holder has the right to transfer both the Owner and User roles, the Owner has the right to transfer both the Owner and User roles, and the User has the right to transfer only the User role. In other words, on a token with a lien set, the lien holder holds the broadest authority, and on a token with a tenant right set, the Owner cannot arbitrarily change the User role.
Owner/User query and transfer functions
balanceOfOwner and balanceOfUser look up the holdings for each role, while ownerOf and userOf look up the current Owner and User address of a token. Role transfers are performed via safeTransferOwner and safeTransferUser respectively, both of which provide an overload that also passes data. Approval is separated by role via approveForOwner/getApprovedForOwner and approveForUser/getApprovedForUser, and setApprovalForAll lets a specific operator be granted batch authority over all tokens.
Setting and releasing a lien
To place a lien, a specific address is first approved via approveLien, and the approved address then calls setLien to actually set the lien. getCurrentLien looks up the current lien holder, and revokeLien releases the lien. Once a lien is set on a token, the Lien Holder gains the authority to transfer both the Owner and User roles, which serves as the basis for reclaiming ownership if the loan agreement is breached.
Setting and releasing a tenant right
As a protection mechanism for rentals, a specific address is approved via approveTenantRight and the tenant right is set via setTenantRight. getCurrentTenantRight checks the current tenant right holder, and revokeTenantRight releases it. Once a tenant right is set, the Owner cannot arbitrarily change the User role, guaranteeing the tenant the right to safely use the NFT for the duration of the agreement.
ERC721-compatible extension
Implementing additional functions such as balanceOf, ownerOf, approve, getApproved, transferFrom, and safeTransferFrom allows existing ERC721 ecosystem tools to be used as-is. In this extension, the transfer family of functions transfers both the Owner and User roles together if no tenant right is set on the token, and transfers only the Owner role if a tenant right is set.
Enumerable and Metadata extensions
Optional extensions are also provided that serve the same role as ERC721's Enumerable and Metadata extensions. totalNumberOfItems, itemOfOwnerByIndex, and itemByIndex enumerate tokens, while itemURI, name, and symbol expose metadata.
Actual movement of money is out of scope
This standard itself does not handle the movement of tokens or value. Delivering loan funds, repayment, and verifying rent payments must all be handled by a separate mortgage or rental contract; ERC-2615 only standardizes the Owner/User/Lien Holder role transitions and the approval system.
A proposal still stalled
This proposal is currently in Stagnant status and is no longer being actively discussed or revised. Check its status before applying it in practice.
Things to watch out for
- A flaw in an external contract becomes a flaw in the standard: The actual setting and enforcement of liens and tenant rights is controlled by external mortgage and rental contracts, so any flaw in those external contracts will immediately cause the standard to behave in unexpected ways.