EIPs Explained

ERC-7565 · Draft · ERC · 2023-11-27

ERC-7565: Perpetual Contract NFTs as Collateral

Lets holders of NFTs that represent locked DeFi positions (LP tokens, staking locks) borrow against them, using ERC-4907's 'user' role to mark the NFT as pledged while the owner keeps the position and its rewards.

What problem does it solve?

Many DeFi protocols hand you an NFT when you lock assets: an AMM liquidity position, a time-locked stake, a vote-escrow lock. The assets keep earning fees, interest or voting power, but they are illiquid. If you need cash, you have to withdraw, which loses those benefits and drains liquidity from the pool (raising slippage for everyone else).

ERC-7565 proposes treating such NFTs as "perpetual contract NFTs" that can be pledged as collateral for a loan. You get liquidity while the underlying position stays locked and productive. The idea comes from the authors' 2022 IEEE Access paper.

How it works

The standard builds on ERC-721 and the rental extension ERC-4907, which separates an NFT's owner from a time-limited user.

  • collateralize(tokenId, loanAmount, interestRate, loanDuration): the owner (or an approved operator) pledges the NFT. In the reference implementation the lending contract sets itself as the ERC-4907 user for loanDuration, and records the loan terms. Emits Collateralized.
  • repayLoan(tokenId, repayAmount): the borrower repays. Once the balance reaches zero the user is cleared and the NFT is free again. Emits LoanRepaid.
  • Defaulted(tokenId, lender) must be emitted if a loan defaults and the NFT goes to the lender.
  • Read helpers: getLoanTerms, viewRepayAmount (principal plus interest so far), currentOwner.

The reference viewRepayAmount pro-rates interest by whole hours elapsed, capped at the loan duration, and rounds up. Repaying halfway through the term therefore costs about half the interest.

Sample code

Interface from the spec:

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

interface IPerpetualContractNFT {
    event Collateralized(uint256 indexed tokenId, address indexed owner, uint256 loanAmount, uint256 interestRate, uint256 loanDuration);
    event LoanRepaid(uint256 indexed tokenId, address indexed owner);
    event Defaulted(uint256 indexed tokenId, address indexed lender);

    function collateralize(uint256 tokenId, uint256 loanAmount, uint256 interestRate, uint64 loanDuration) external;
    function repayLoan(uint256 tokenId, uint256 repayAmount) external;
    function getLoanTerms(uint256 tokenId) external view returns (uint256 loanAmount, uint256 interestRate, uint256 loanDuration, uint256 loanDueDate);
    function currentOwner(uint256 tokenId) external view returns (address);
    function viewRepayAmount(uint256 tokenId) external view returns (uint256);
}

Borrow, then repay in full (ethers v6):

import { parseEther } from "ethers";

await nft.collateralize(1n, parseEther("1"), 5n, 7n * 24n * 3600n); // 1 ETH, 5 %, 7 days
console.log(await nft.userOf(1n));          // lending contract while the loan is open

const due = await nft.viewRepayAmount(1n);
await nft.repayLoan(1n, due);
console.log(await nft.userOf(1n));          // zero address once repaid

Things to know

  • Status is Draft, and the Security Considerations section is still empty.
  • The interface records loan terms but does not specify how funds are actually lent or repaid, how the loan amount relates to the value of the locked asset, or how liquidation works. The reference code leaves default handling and fund transfers as "further logic".
  • Using ERC-4907's user role as the lock is a convention of the reference implementation. A lender must make sure the owner cannot simply transfer or withdraw the underlying position while the loan is open.

#nft #defi #collateral #lending #erc4907

Details

Authors
Hyoungsung Kim (@HyoungsungKim) <[email protected]>, Yong-Suk Park <[email protected]>, Hyun-Sik Kim <[email protected]>
Status
Draft
Type
Standards Track / ERC
Created
2023-11-27
Requires

Machine-readable: Markdown · JSON