ERC-7565 Perpetual contract NFT collateralized loans (Perpetual Contract NFTs as Collateral)

Draft · Vaults & DeFi · created 2023-11-27

A standard that lets users borrow money by pledging an NFT representing rights to assets locked in a liquidity pool or similar, as collateral. This allows temporary liquidity to be obtained without withdrawing the asset.

Why it is needed

In decentralized finance (DeFi), assets are often locked up for a period to receive benefits such as interest or voting rights. For example, a liquidity provider who deposits assets into a service running an automated market maker (AMM) receives an NFT representing their share, but the asset remains locked in the pool in the meantime. If they urgently need money, the only option is to withdraw the asset from the pool, which not only cuts off the benefits of locking but also reduces the pool's liquidity, which can worsen slippage, the unfavorable price shift that occurs during asset swaps. This standard proposes a way to pledge the NFT representing the locked asset itself as collateral to take out a loan, obtaining temporary liquidity without withdrawing the asset while keeping the pool's liquidity intact.

What to implement

In depth

The concept of a perpetual contract NFT

The NFT in this standard represents the right to claim, after a fixed maturity, the original asset plus any benefits accrued in the meantime, for assets that have been deposited or locked. The original text borrows the idea of a perpetual futures contract from the crypto derivatives market and calls this a perpetual contract NFT. The asset owner can pledge this NFT as collateral to borrow funds. The goal is to extend beyond AMM liquidity provision to broader DeFi services where asset locking is common, such as lending and trading.

Interface composition and requirement levels

The interface consists of three events and five functions. Collateralized MUST be emitted when collateralize succeeds, LoanRepaid MUST be emitted when repayLoan succeeds, and Defaulted MUST be emitted when the NFT is transferred to the lender due to default. collateralize and repayLoan SHOULD be implemented as external, and the query functions getLoanTerms, currentOwner, and viewRepayAmount MAY be implemented as external view. getLoanTerms returns four values: loanAmount, interestRate, loanDuration, and loanDueDate.

Relationship with ERC-721 and ERC-4907

This proposal requires ERC-721 and ERC-4907, is fully compatible with ERC-721, and integrates with ERC-4907, which is used for NFT rentals. ERC-4907 introduced a dual-role model separating owner and user, and this standard uses that model not for rentals but for collateralizing financial transactions. In the reference implementation, when collateralize is called, setUser(tokenId, address(this), loanDuration) designates the contract itself as the user of the NFT for the duration of the loan, representing the collateralized state.

How interest is calculated

The reference implementation's viewRepayAmount calculates interest on an hourly basis, charged in proportion to the actual time borrowed. If repaid before the duration ends, interest is charged only for the time held; as an example from the original text, if the annual interest rate is 5% and repayment occurs at the halfway point of the loan duration, only 2.5% is charged. The elapsed time, elapsed, is computed as loanDuration / 1 hours if the current time has passed loanStartTime + loanDuration, or otherwise as (block.timestamp - loanStartTime) / 1 hours. Interest is calculated with rounding up as ((loanAmount * interestRate / 100) * elapsed + (loanDuration / 1 hours) - 1) / (loanDuration / 1 hours), and the total repayment amount is loanAmount plus this interest.

Repayment and collateral release

The reference implementation's repayLoan can only be called by the borrower, and rejects the call if the repayment amount, repayAmount, exceeds the total amount due, totalDue. After repayment, the remaining loan amount is updated to totalDue - repayAmount, so partial repayments are possible. Once the remaining loan amount reaches zero, setUser(tokenId, address(0), 0) resets the NFT's user designation to default, releasing the collateral and emitting a LoanRepaid event. The rest of the lifecycle logic, such as handling default or transferring the NFT, is left for further implementation.

Design intent

The original text cites four design decisions. First, the dual-role separation between the NFT owner and the DeFi platform or contract using that NFT as collateral simplifies management of rights and responsibilities. Second, allowing collateralized loans without withdrawing assets from pools or staking adds liquidity while preserving locking benefits such as interest or voting rights. Third, automating management of the collateral NFT's terms reduces transaction cost and complexity. Fourth, it emphasizes connecting asset-locking services with collateral services, that is, DeFi composability, aiming for adoption across multiple platforms.

Draft status and gaps

This proposal's status is Draft, meaning its content may change or progress may stall going forward. Also, the Security Considerations section of the original text only contains a placeholder noting that discussion is still needed, with no actual content, so a formal analysis of security risks that could arise in collateralized lending is not yet in the document.

Original ERC · ← ERCs