ERC-7649 Built-in NFT bonding curve liquidity (Bonding curve-embedded liquidity for NFTs)
Draft · NFTs & multi-token · created 2024-02-28
A standard that, without modifying ERC-721 itself, attaches a separate 'TradeableShares' contract to an NFT so that shares in it can be bought and sold according to a bonding curve formula. Every trade guarantees a fee to the creator.
Why it is needed
The ERC-721 standard has no official way to attach bonding curve based liquidity to an NFT. A bonding curve is a structure in which price is automatically determined by a formula as the issued amount increases, but if every project that wants to use this builds it differently, wallets and apps cannot handle it consistently, and directly modifying ERC-721 means tampering with an already widely used standard. There is also no common mechanism guaranteeing that creators receive fees from trading activity centered on their own NFTs. This proposal aims to leave the NFT untouched while defining a standard framework for attaching a liquidity contract alongside it, so that NFTs can attract liquidity and creators can receive fees in places such as AI model marketplaces or allocation of decentralized GPU or storage resources.
What to implement
function getPrice(uint256 supply, uint256 amount) external pure returns(uint256);: Returns the price of amount shares, calculated via the bonding curve formula, based on the current total supply, supply.function getSharesSubject() external view returns(SharesSubject calldata);: Returns the NFT that the shares are bound to (the subject), as an ERC-721 contract address and token ID. This is an immutable value.function getFeePercent() external view returns(uint256);: Returns the cumulative fee rate applied to all buys and sells, expressed on an 18-decimal basis (10^18 equals 100%).function getSharesIssuer() external view returns(address nftOwner);: Returns the issuer address that receives the share fee, i.e. the NFT owner's address. It changes whenever the NFT owner changes.function getSharesBalance(address holder) external view returns(uint256 balance);: Returns the number of shares held by a given address. Similar to ERC20.balanceOf().function getSharesSupply() external view returns(uint256 supply);: Returns the total amount of shares in existence, i.e. the sum of all individual balances. Similar to ERC20.totalSupply().function getBuyPrice(uint256 supply, uint256 amount) external pure returns(uint256);: Calculates the buy price for amount shares based on the given total supply.function getSellPrice(uint256 supply, uint256 amount) external pure returns(uint256);: Calculates the sell price for amount shares based on the given total supply.function getBuyPrice(uint256 amount) external view returns(uint256);: Returns the buy price for amount shares based on the current total supply.function getSellPrice(uint256 amount) external view returns(uint256);: Returns the sell price for amount shares based on the current total supply.function getBuyPriceAfterFee(uint256 amount) external view returns(uint256);: Returns the fee-inclusive buy price based on the current supply and fee rate.function getSellPriceAfterFee(uint256 amount) external view returns(uint256);: Returns the fee-inclusive sell price based on the current supply and fee rate.function buyShares(uint256 amount) external payable;: Buys amount shares. The caller must send getBuyPriceAfterFee(amount) worth of ETH, and only the current issuer can buy the first share.function buySharesTo(uint256 amount, address beneficiary) external payable;: Buys amount shares on behalf of a specified beneficiary.function sellShares(uint256 amount) external;: Sells amount shares. The seller receives getSellPriceAfterFee(amount), and the last share cannot be sold.function sellSharesTo(uint256 amount, address payable beneficiary) external;: Sells shares and has the proceeds sent to a specified beneficiary.function getTradeVolume() external view returns(uint256);: Returns the cumulative sum of all trade amounts. It never decreases over time and can be used to drive cumulative fee incentives.
In depth
The ERC-721 non-modification principle
Bonding curve liquidity SHOULD be attached to an NFT via a separate contract and MUST NOT be built into or require modifying the ERC-721 standard itself. The bonding curve contract MUST manage the liquidity of the linked NFT through the curve mechanism. The existing NFT contract is left untouched, and all liquidity functionality is handled entirely by the external contract.
Bonding curve mechanism
The curve determines the price of the NFT's 'keys' (also called shares) as a function of supply, and this formula drives liquidity providers' buying and selling. getPrice(supply, amount) in the BondingCurve interface is the definition of the curve function, calculating the price of amount shares given the current total supply. Implementations MAY allow creators to customize not only parameters such as slope and intercept but also the shape (formula) of the curve itself.
The nature of TradeableShares
Shares are an asset similar to a fungible token in that they cannot be transferred but can be bought and sold. The only counterparty in a trade is the shares contract itself, and the price is predetermined by the bonding curve function. Shares are bound to an NFT defined by the SharesSubject struct (tokenAddress, tokenId), and that NFT's owner acts as the issuer, receiving the subject fee generated on every buy and sell. The subject and fee rate are immutable and clients may cache them, but the issuer address returned by getSharesIssuer() changes over time as NFT ownership transfers and can be a target of front-running attacks, so off-chain apps must not rely on it.
The price lookup function system
Price lookups are organized along two axes. There is a pure version that takes supply as an argument (e.g. getBuyPrice(supply, amount)) and a view version that uses the current supply (e.g. getBuyPrice(amount)), and each has a fee-exclusive and a fee-inclusive (AfterFee) variant. The fee-inclusive versions reflect three fee rates: protocolFeePercent, holdersFeePercent, and subjectFeePercent. The buyer must pay getBuyPriceAfterFee(amount), and the seller receives getSellPriceAfterFee(amount).
Buy and sell rules
In buyShares·buySharesTo, only the current issuer can buy the first share, and in sellShares·sellSharesTo, the last share cannot be sold. buySharesTo and sellSharesTo let a third party (beneficiary) receive the shares or payment. In implementations where settlement is an ERC-20 token, any incoming ETH must be rejected, effectively making the function behave as non-payable. Every trade is recorded via a Trade event, and getTradeVolume() returns the cumulative sum of all trade amounts. This value does not decrease over time.
Creator fee guarantee
The implementation MUST include a mechanism that guarantees fees for the NFT creator, meaning the creator is guaranteed to receive a fixed percentage of the buy/sell trade fees generated by the built-in liquidity contract. Leaving the fee rate definition up to the creator is optional (MAY). The cumulative fee rate returned by getFeePercent() is denominated in 18 decimals, where 10^18 equals 100%, and can be the sum of multiple fees going to different destinations.
Payment method
The built-in liquidity contract MUST support at least one of ERC-20 tokens or native ETH as a payment method, and MAY support both. The source Rationale explains that this implementation-agnostic approach is meant to let developers freely choose the liquidity mechanism that fits their project's needs.
Proposal status
This proposal is in Draft status, created in February 2024. Its content may change or stall, so its current status should be checked before implementation.
Things to watch out for
- Smart contract security: Implementation contracts must undergo thorough security audits so they can withstand vulnerabilities and attacks.
- Creator fee handling: The mechanism that handles and distributes creator fees must be secure and transparent enough to prevent malicious behavior.
- Compatibility: Compatibility with existing ERC-721 implementations must be ensured so that the built-in liquidity standard integrates smoothly.
- User experience: Complexity that could hinder adoption should be avoided, and a positive user experience should be maintained.