EIPs Explained

ERC-4987 · Stagnant · ERC · 2021-09-21

ERC-4987: Held token interface

Lets staking pools, vaults and other contracts that hold tokens report who the real (functional) owner is, so depositing an NFT or token does not break governance votes, gated access or PFP checks.

What problem does it solve?

When you deposit a token into a staking contract, lending pool, vesting vault or fractionalisation contract, the token's ownerOf or balanceOf now points at that contract, not at you. Any system that checks ownership (a governance vote, a token-gated Discord, a game, a PFP verifier) suddenly thinks you own nothing.

So users must choose between earning yield and keeping the utility of their tokens. ERC-4987 gives holder contracts a standard way to say "this token is held here on behalf of this user".

How it works

There is one small interface per token type, each detectable through ERC-165:

Interface ERC-165 ID Main function
IERC20Holder 0x74c89d54 heldBalanceOf(token, owner)
IERC721Holder 0x16b900ff heldOwnerOf(token, tokenId), heldBalanceOf(token, owner)
IERC1155Holder 0xced24c37 heldBalanceOf(token, owner, tokenId)

Each also emits Hold when tokens are deposited and Release when they are returned. The token address parameter lets one holder contract manage many token contracts at once.

A consumer that wants the functional owner does a chained lookup: read ownerOf; if the owner is a contract that supports the holder interface, ask it for heldOwnerOf; if that returns a non-zero address, use it.

Sample code

Consumer-side lookup of the functional owner of an ERC-721 token:

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";

interface IERC721Holder {
    function heldOwnerOf(address tokenAddress, uint256 tokenId) external view returns (address);
    function heldBalanceOf(address tokenAddress, address owner) external view returns (uint256);
}

library FunctionalOwner {
    bytes4 constant HOLDER_ID = 0x16b900ff;

    function of(IERC721 token, uint256 tokenId) internal view returns (address) {
        address owner = token.ownerOf(tokenId);
        if (owner.code.length == 0) return owner; // EOA

        try IERC165(owner).supportsInterface(HOLDER_ID) returns (bool ok) {
            if (!ok) return owner;
        } catch {
            return owner;
        }

        try IERC721Holder(owner).heldOwnerOf(address(token), tokenId) returns (address user) {
            if (user != address(0)) return user;
        } catch {}
        return owner;
    }
}

Note: the name IERC721Holder here is ERC-4987's interface, not OpenZeppelin's unrelated IERC721Receiver helper.

Things to know

  • Status: Stagnant. It is not in wide use; check whether the vaults you care about actually implement it.
  • A malicious contract can implement the interface and report any owner it likes. Consumers should only trust holder contracts they know, and sanity-check that the holder really owns the tokens it reports.
  • Existing token contracts need no changes; only holders and consumers do.
  • The reverse question, how much value is locked inside an NFT, is addressed by ERC-4353.

#nft #defi #ownership #staking #interface

Details

Authors
Devin Conley (@devinaconley)
Status
Stagnant
Type
Standards Track / ERC
Created
2021-09-21
Requires

Machine-readable: Markdown · JSON