ERC-7695 ERC-721 ownership delegation and context (Ownership Delegation and Context for ERC-721)

Draft · NFTs & multi-token · created 2024-04-02

An ERC-721 extension standard that lets an NFT be lent out or locked by attaching it to a purpose-specific context without transferring it elsewhere, and that lets the right to exercise ownership be delegated to another account for a fixed period.

Why it is needed

The existing ERC-721 has only a single role, Owner. So to stake, pledge as collateral, or lend an NFT, the token itself has to be transferred to and locked in that contract. But many apps grant benefits like airdrops or tier-based rewards using the fact that a token sits in a wallet as proof of holding. Once a token is locked in a contract, the original owner loses access to those benefits, and reward systems can only fix this by individually supporting as many locking contracts as possible. There has also been no standard way to express use cases like lending or delegation, where the owner stays the same but the user changes, which has always made it hard to build such services on top of ERC-721. This standard tries to solve the problem by dividing use cases into contexts handled by controllers, and by adding ownership delegation to the standard, which separates the owner from the right to exercise ownership.

What to implement

In depth

Context and role structure

A context is a unit representing a specific use of a token, and each token-context pair has exactly one controller and one user. The controller can transfer the controller role, assign the user, and lock or unlock the token, while the user has the right to use the token within that context. Ownership Rights are defined as three things: token transfer, context attachment, and context detachment. The Ownership Manager is the party that actually exercises ownership rights, referring to the owner when there is no delegation and to the delegate when delegation is active. For a single token there is exactly one owner, one delegate, and one ownership manager, while up to n context roles can be attached.

Two-step ownership delegation

startDelegateOwnership is called by the owner, their operator, or an approved address. It must revert if there is already an accepted delegation, the expiration time must be in the future, and it reverts if the delegate is the owner themselves or the zero address. Any prior pending proposal is replaced. It only takes effect once the delegate (or their operator) calls acceptOwnershipDelegation, after which the delegate is recorded as the ownership manager until expiration. stopOwnershipDelegation can only be called by the delegate side for an accepted delegation, and on success the owner becomes the ownership manager again. Unlike approve or setApprovalForAll, which only add permissions while the owner keeps their status, delegation transfers the owner's rights themselves to the delegate and reverts automatically on expiration. This design is meant to prevent abuse where an owner keeps hold of the rights, takes collateral, and then siphons the token off to another account, and the two-step process (propose and accept) is meant to prevent mistakes in designating the delegate.

Lock and detach rules

setContextLock can only be called by the controller, and it cannot be called on a token for which detachment has already been requested. Detachment branches two ways. For an unlocked token, or when the controller itself requests it, a single call to requestDetachContext detaches it immediately and fires ContextDetached. For a locked token, the request fires ContextDetachRequested, and execDetachContext must be called after the detaching wait time (detachingDuration) has passed for detachment to occur. Eligibility to call both functions is limited to the ownership manager, their operator, and, when not under delegation, an approved address. The onDetachRequested and onExecDetachContext callbacks in the detachment process are called but their results are specified to be ignored, so the controller cannot block detachment. In contrast, onAttached on attachment reverts the entire operation on failure, allowing the controller to reject an unwanted attachment. This is designed so that the owner can free the token themselves even if the controller loses control.

Automatic cleanup on transfer

Transfers can only be performed by the ownership manager, their operator, or, when not under delegation, an approved address. When a transfer occurs, any ongoing ownership delegation must be stopped and all attached contexts must be detached. If there are locked contexts, detachment must first be requested and the wait time must have passed before the transfer can proceed. During detachment, if the controller is a contract, onExecDetachContext is called with an empty data argument, but the result is ignored. For gas efficiency, the OwnershipDelegationStopped and ContextDetached events are intentionally not fired during this process.

ERC-165 identifiers and optional extensions

A contract implementing this standard must implement all functions of IERC7695, and supportsInterface must return true for 0x486b6fba. The optional Enumerable extension, which allows querying the list of contexts, has the identifier 0xcebf44b7. It is recommended that the controller be a contract implementing the callback interface (IERC7695ContextCallback) that receives attachment and detachment requests, and the identifier for this interface is 0xad0491f1.

Proposal in Draft status

This proposal is in Draft status, created in April 2024. Since it is not yet a finalized standard, the interface and rules may still change, and the latest source text should be checked before implementation.

Things to watch out for

Original ERC · ← ERCs