EIPs Explained

ERC-7695 · Draft · ERC · 2024-04-02

ERC-7695: Ownership Delegation and Context for ERC-721

An ERC-721 extension that lets an NFT be used, locked and even temporarily delegated in different app 'contexts' without the owner ever transferring it, so staking, rentals and loans don't cost owners their holder benefits.

What problem does it solve?

To stake, rent out or borrow against an ERC-721 NFT today, you usually transfer it into a protocol contract. The NFT then no longer sits in your wallet, so other apps that reward holders (airdrops, tiered perks) stop recognising you, unless they integrate every staking contract out there.

ERC-7695 keeps the NFT with its owner and instead adds two concepts on top of ERC-721: contexts, where an app can assign a user and lock the token, and ownership delegation, where the owner temporarily hands the rights of ownership to someone else.

How it works

Contexts. Anyone can createContext(controller, detachingDuration, ctxMsg), which returns a ctxHash. Each context has:

  • a Controller that can set the context's User (setContextUser) and lock or unlock the token in that context (setContextLock);
  • a detachingDuration, capped by the contract's maxDetachingDuration().

The owner attaches the token with attachContext. To leave, they call requestDetachContext: if the token is unlocked it detaches immediately; if locked, they must wait detachingDuration and then call execDetachContext. The controller cannot block this, so a lost or malicious controller cannot trap a token forever. A controller that is a contract gets callbacks (onAttached, onDetachRequested, onExecDetachContext); only onAttached can reject.

Ownership delegation. The owner calls startDelegateOwnership(tokenId, delegatee, until); the delegatee confirms with acceptOwnershipDelegation. Until expiry the delegatee is the ownership manager: they can transfer and attach/detach contexts. Ownership reverts automatically at until, or earlier if the delegatee calls stopOwnershipDelegation.

Transfers revoke any delegation and detach every context; they revert if a locked context has not finished its detach wait.

The interface ID is 0x486b6fba; the optional enumerable extension is 0xcebf44b7 and the controller callback interface is 0xad0491f1.

Sample code

A rental app as context controller (ethers v6):

import { Contract } from "ethers";

const nft = new Contract(nftAddress, [
  "function createContext(address,uint64,bytes) returns (bytes32)",
  "function attachContext(bytes32,uint256,bytes)",
  "function setContextUser(bytes32,uint256,address)",
  "function setContextLock(bytes32,uint256,bool)",
  "function getContextUser(bytes32,uint256) view returns (address)",
], signer);

// Owner attaches token 42 to the rental app's context
await (await nft.connect(owner).attachContext(ctxHash, 42n, "0x")).wait();

// The app (controller) locks it and assigns the renter as user
await (await nft.connect(controller).setContextLock(ctxHash, 42n, true)).wait();
await (await nft.connect(controller).setContextUser(ctxHash, 42n, renter)).wait();

console.log(await nft.getContextUser(ctxHash, 42n)); // renter

Things to know

  • Status is Draft.
  • For rental-only use cases, simpler standards exist: ERC-4907 and ERC-5006 add a time-limited "user" role.
  • Phishing: tricking an owner into startDelegateOwnership is as dangerous as a malicious setApprovalForAll, since the delegatee can transfer the token.
  • Systems built on delegation should request a delegation period longer than maxDetachingDuration, otherwise the owner could lock the token in another context so it cannot be moved before delegation ends.
  • Controllers' callback functions should check that msg.sender is the expected token contract.
  • Two contexts in the same app can lead to the same token being used twice; controllers should coordinate.

#nft #erc721 #delegation #rental #staking

Details

Authors
Duc Tho Tran (@ducthotran2010)
Status
Draft
Type
Standards Track / ERC
Created
2024-04-02
Requires

Machine-readable: Markdown · JSON