Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article examines ERC-7565, a proposal for borrowing funds in DeFi using NFTs that represent locked assets as collateral, while continuing to supply liquidity.
The explanation below translates, summarizes, and expands on the original proposal.
I also cover a range of other EIPs.
Overview
This standard proposes a mechanism for borrowing funds using an NFT that represents locked assets as collateral. After the specified maturity, the NFT entitles its holder to receive the deposited assets and the returns earned.
Motivation
In the rapidly developing DeFi ecosystem, users can lock assets to earn interest or obtain benefits such as voting rights. Maintaining access to liquidity while the assets are locked, however, remains a challenge. The proposal addresses this problem using ERC-721 and ERC-4907 to enable users to benefit from locked assets.
For more on ERC-721, see the following article.
For more on ERC-4907, see the following article.
[ERC-4907] Granting a Time-Limited Role for NFT Usage
In DeFi services that operate automated market makers (AMMs), liquidity providers can deposit assets into a pool and receive NFTs representing their positions. These NFTs represent claims on assets and returns. However, locked assets are temporarily unavailable, and emergency withdrawals can reduce the pool's overall liquidity and increase slippage.
To address these issues, the ERC proposes using NFTs representing locked assets as collateral. Liquidity providers can obtain temporary liquidity without withdrawing their underlying assets, helping preserve the pool's liquidity. The approach also applies to other DeFi services involving asset locks, including lending and trading. It therefore aims to maintain access to liquidity while assets remain locked across a range of DeFi applications.
The ERC also introduces a new type of NFT called a Perpetual Contract NFT. Drawing on the concept of perpetual contracts in cryptocurrency derivatives markets, the NFT represents contractual rights and collateral that can be used across composable DeFi applications. Perpetual Contract NFTs aim to provide liquidity without sacrificing the benefits associated with locking assets.
Specification
Interface
interface IPerpetualContractNFT {
// Emitted when an NFT is collateralized for obtaining a loan
event Collateralized(uint256 indexed tokenId, address indexed owner, uint256 loanAmount, uint256 interestRate, uint256 loanDuration);
// Emitted when a loan secured by an NFT is fully repaid, releasing the NFT from collateral
event LoanRepaid(uint256 indexed tokenId, address indexed owner);
// Emitted when a loan defaults, resulting in the transfer of the NFT to the lender
event Defaulted(uint256 indexed tokenId, address indexed lender);
// Enables an NFT owner to collateralize their NFT in exchange for a loan
// @param tokenId The NFT to be used as collateral
// @param loanAmount The amount of funds to be borrowed
// @param interestRate The interest rate for the loan
// @param loanDuration The duration of the loan
function collateralize(uint256 tokenId, uint256 loanAmount, uint256 interestRate, uint64 loanDuration) external;
// Enables a borrower to repay their loan and regain ownership of the collateralized NFT
// @param tokenId The NFT that was used as collateral
// @param repayAmount The amount of funds to be repaid
function repayLoan(uint256 tokenId, uint256 repayAmount) external;
// Allows querying the loan terms for a given NFT
// @param tokenId The NFT used as collateral
// @return loanAmount The amount of funds borrowed
// @return interestRate The interest rate for the loan
// @return loanDuration The duration of the loan
// @return loanDueDate The due date for the loan repayment
function getLoanTerms(uint256 tokenId) external view returns (uint256 loanAmount, uint256 interestRate, uint256 loanDuration, uint256 loanDueDate);
// Allows querying the current owner of the NFT
// @param tokenId The NFT in question
// @return The address of the current owner
function currentOwner(uint256 tokenId) external view returns (address);
// View the total amount required to repay the loan for a given NFT
// @param tokenId The NFT used as collateral
// @return The total amount required to repay the loan, including interest
function viewRepayAmount(uint256 tokenId) external view returns (uint256);
}Collateralized
An event emitted when an NFT is used as collateral for a loan. It records key details such as the loan amount, interest rate, and loan duration.
LoanRepaid
An event emitted when the loan is repaid and the NFT is released from collateral. It records repayment of the loan.
Defaulted
An event emitted when a loan defaults and the NFT is transferred to the lender. It records the default and transfer of the NFT.
A loan default occurs when a borrower fails to meet the terms of the loan agreement, such as failing to repay the borrowed funds by the specified due date.
- Missing the repayment deadline
- The borrower fails to repay the principal and interest by the due date.
- Violating loan conditions
- The borrower fails to satisfy other conditions of the agreement, such as providing additional collateral or maintaining a specified financial ratio.
When a loan defaults, the lender typically has the right to recover the assets pledged as collateral. In this case, the pledged NFT is transferred to the lender, and the borrower loses ownership of the NFT.
For example, suppose a borrower takes out a loan of 10 ETH with a repayment deadline one month later and interest of 5% for that period.
If the borrower cannot repay 10.5 ETH (10 ETH in principal plus 0.5 ETH in interest) by the deadline, the loan defaults and the lender can exercise the right to recover the NFT pledged as collateral.
collateralize
Allows an NFT owner to use the NFT as collateral for a loan.
The parameters include the ID of the NFT used as collateral (tokenId), the amount to borrow (loanAmount), the interest rate (interestRate), and the loan duration (loanDuration).
repayLoan
Allows the borrower to repay the loan and recover the NFT used as collateral.
The parameters include the ID of the pledged NFT (tokenId) and the amount to repay (repayAmount).
getLoanTerms
Retrieves the loan terms associated with a particular NFT.
The parameter is the ID of the pledged NFT (tokenId).
The return values are the borrowed amount (loanAmount), interest rate (interestRate), loan duration (loanDuration), and repayment due date (loanDueDate).
currentOwner
Retrieves the current owner of a particular NFT.
The parameter is the target NFT ID (tokenId).
The return value is the address of the current owner.
viewRepayAmount
Retrieves the total amount required to repay the loan associated with a particular NFT.
The parameter is the ID of the pledged NFT (tokenId).
The return value is the total repayment amount, including interest.
Rationale
Design motivation
The standard is designed to address challenges in managing and accessing liquidity from locked assets used as collateral in decentralized finance (DeFi). Conventional DeFi mechanisms often require holders to lock assets to participate in lending, staking, or yield farming, limiting access to their liquidity. The standard aims to make DeFi more accessible and attractive by allowing asset holders to retain some access to liquidity while their assets remain locked.
Design decisions
-
Dual-role system (asset owner and DeFi platform or contract)
- The standard clearly distinguishes the NFT owner (asset holder) from the DeFi platform or contract using the NFT as collateral.
- This separation simplifies management of rights and responsibilities and reduces potential conflicts.
-
Improving liquidity without sacrificing the benefits of asset locking
- A central feature is the ability to borrow against an NFT representing locked assets.
- This allows asset holders to access liquidity without withdrawing assets from pools or staking programs, while continuing to receive benefits such as interest or voting rights.
-
Automated loan and collateral management
- The standard integrates automated management of the terms associated with collateralized NFTs, aiming to minimize transaction costs and complexity.
-
DeFi composability
- By focusing on the integration of asset-locking and collateral services, the standard aims to facilitate adoption across different DeFi platforms and services.
- This approach promotes interoperability within the DeFi ecosystem.
Alternative designs and related work
-
Comparison with ERC-4907
- ERC-4907 also introduces a dual-role NFT model consisting of an owner and a user, but ERC-7565 focuses specifically on using NFTs as collateral in financial transactions.
- Its focus differs from the rental-oriented approach of ERC-4907.
-
Improvements over conventional collateralization
- Conventional DeFi collateralization requires assets to be locked. This standard proposes a more dynamic and flexible model that enables continued access to liquidity.
Backward compatibility
The standard is fully compatible with ERC-721 and can be integrated with ERC-4907 to support NFT rentals.
Implementation
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.0;
//import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./IPerpetualContractNFT.sol";
import "./ERC4907/ERC4907.sol";
contract PerpetualContractNFT is ERC4907, IPerpetualContractNFT {
struct LoanInfo {
address borrower; // Address that borrowed against the NFT
uint256 loanAmount; // Amount of funds borrowed
uint256 interestRate; // Interest rate for the loan
uint64 loanDuration; // Duration of the loan
uint256 loanStartTime; // Timestamp when the loan starts
}
mapping(uint256 => LoanInfo) internal _loans;
//Constructor to initialize the Perpetual Contract NFT contract with the given name and symbo
constructor(string memory name_, string memory symbol_)
ERC4907(name_, symbol_)
{}
function collateralize(uint256 tokenId, uint256 loanAmount, uint256 interestRate, uint64 loanDuration) public override {
require(ownerOf(tokenId) == msg.sender || isApprovedForAll(ownerOf(tokenId), msg.sender) || getApproved(tokenId) == msg.sender, "Not owner nor approved");
LoanInfo storage info = _loans[tokenId];
info.borrower = msg.sender;
// The loan amount should reflect the asset's value as represented by the NFT, considering an appropriate loan-to-value (LTV) ratio.
info.loanAmount = loanAmount;
info.interestRate = interestRate;
info.loanDuration = loanDuration;
info.loanStartTime = block.timestamp;
setUser(tokenId, address(this), loanDuration);
emit Collateralized(tokenId, msg.sender, loanAmount, interestRate, loanDuration);
// Further logic can be implemented here to manage the lending of assets
}
function repayLoan(uint256 tokenId, uint256 repayAmount) public override {
require(_loans[tokenId].borrower == msg.sender, "Not the borrower.");
// Calculate the total amount due for repayment
uint256 totalDue = viewRepayAmount(tokenId);
// Check if the repayAmount is sufficient to cover at least a part of the total due amount
require(repayAmount <= totalDue, "Repay amount exceeds total due.");
// Calculate the remaining loan amount after repayment
_loans[tokenId].loanAmount = totalDue - repayAmount;
// Resets the user of the NFT to the default state if the entire loan amount is fully repaid
if(_loans[tokenId].loanAmount == 0) {
setUser(tokenId, address(0), 0);
}
emit LoanRepaid(tokenId, msg.sender);
}
function getLoanTerms(uint256 tokenId) public view override returns (uint256, uint256, uint256, uint256) {
LoanInfo storage info = _loans[tokenId];
return (info.loanAmount, info.interestRate, info.loanDuration, info.loanStartTime);
}
function currentOwner(uint256 tokenId) public view override returns (address) {
return ownerOf(tokenId);
}
function viewRepayAmount(uint256 tokenId) public view returns (uint256) {
if (_loans[tokenId].loanAmount == 0) {
// If the loan amount is zero, there is nothing to repay
return 0;
}
// The interest is calculated on an hourly basis, prorated based on the actual duration for which the loan was held.
// If the borrower repays before the loan duration ends, they are charged interest only for the time the loan was held.
// For example, if the annual interest rate is 5% and the borrower repays in half the loan term, they pay only 2.5% interest.
uint256 elapsed = block.timestamp > (_loans[tokenId].loanStartTime + _loans[tokenId].loanDuration)
? _loans[tokenId].loanDuration / 1 hours
: (block.timestamp - _loans[tokenId].loanStartTime) / 1 hours;
// Round up
// Example: 15/4 = 3.75
// round((15 + 4 - 1)/4) = 4, round((15/4) = 3)
uint256 interest = ((_loans[tokenId].loanAmount * _loans[tokenId].interestRate / 100) * elapsed + (_loans[tokenId].loanDuration / 1 hours) - 1) /
(_loans[tokenId].loanDuration / 1 hours);
// Calculate the total amount due
uint256 totalDue = _loans[tokenId].loanAmount + interest;
return totalDue;
}
// Additional functions and logic to handle loan defaults, transfers, and other aspects of the NFT lifecycle
}Citation
Hyoungsung Kim (@HyoungsungKim) hyougnsung@keti.re.kr, Yong-Suk Park yspark@keti.re.kr, Hyun-Sik Kim hskim@keti.re.kr, "ERC-7565: Perpetual Contract NFTs as Collateral [DRAFT]," Ethereum Improvement Proposals, no. 7565, November 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7565.
Conclusion
This article covered ERC-7565, a proposal for borrowing funds in DeFi using NFTs that represent locked assets as collateral while continuing to supply liquidity.
If you have questions, feel free to reach out via Twitter DM.
I also publish on the following platforms.



