嵌入式流动性合约__必须__支持 ERC-20 代币或原生 ETH 作为支付,
它__可以__同时支持两者。
BondingCurve 接口
/**
* @title Bonding Curve
*
* @notice A bonding curve definition
*
* @notice Bonding curve defines the price of the smallest unit of the asset as a function
* of the asset supply
*/
interface BondingCurve {
/**
* @notice Bonding curve function definition. The function calculating the price
* of the `amount` of shares given the current total supply `supply`
*
* @param supply total shares supply
* @param amount number of shares to buy/sell
* @return the price of the shares (all `amount` amount)
*/
function getPrice(uint256 supply, uint256 amount) external pure returns(uint256);
}
联合曲线嵌入式流动性 / TradeableShares 接口
/**
* @title Tradeable Shares
*
* @notice Tradeable shares is a non-transferable, but buyable/sellable fungible token-like asset,
* which is sold/bought solely by the shares contract at the predefined by
* the bonding curve function price
*
* @notice The shares is bound to its "subject" – an NFT; the NFT owner gets the subject fee
* emerging in every buy/sell operation
*/
interface TradeableShares is BondingCurve {
/**
* @notice Shares subject is an NFT defined by its ERC-721 contract address and NFT ID
* Shares subject is an NFT the liquidity is embedded to
*/
struct SharesSubject {
/// @dev ERC-721 contract address
address tokenAddress;
/// @dev NFT ID
uint256 tokenId;
}
/**
* @dev Fired in `buyShares` and `sellShares` functions, this event logs
* the entire trading activity happening on the curve
*
* @dev Trader, that is the buyer or seller, depending on the operation type is the transaction sender
*
* @param beneficiary the address which receives shares or funds, usually this is the trader itself
* @param issuer subject issuer, usually an owner of the NFT defined by the subject
* @param isBuy true if the event comes from the `buyShares` and represents the buy operation,
* false if the event comes from the `sellShares` and represents the sell operation
* @param sharesAmount amount of the shares bought or sold (see `isBuy`)
* @param paidAmount amount of ETH spent or gained by the buyer or seller;
* this is implementation dependent and can represent an amount of ERC-20 payment token
* @param feeAmount amount of all the fees paid, if any
* @param supply total shares supply after the operation
*/
event Trade(
address indexed beneficiary,
address indexed issuer,
bool indexed isBuy,
uint256 sharesAmount,
uint256 paidAmount,
uint256 feeAmount,
uint256 supply
);
/**
* @notice Shares subject, usually defined as NFT (ERC-721 contract address + NFT ID)
*
* @dev Immutable, client applications may cache this value
*
* @return Shares subject as a SharesSubject struct, this is an NFT if all currently known implementations
*/
function getSharesSubject() external view returns(SharesSubject calldata);
/**
* @notice Cumulative fee percent, applied to all the buy and sell operations;
* the fee percent is defined with the 18 decimals, 10^18 corresponds to 100%
*
* @notice The fee can be combined from multiple fees which are sent to the various destinations
*
* @dev Immutable, client applications may cache this value
*
* @return protocol fee percent with the 18 decimals (10^18 is 100%)
*/
function getFeePercent() external view returns(uint256);
/**
* @notice Shares issuer, the receiver of the shares fees
*
* @dev Mutable, changes (potentially frequently and unpredictably) when the NFT owner changes;
* subject to the front-run attacks, off-chain client applications must not rely on this address
* in anyway
*
* @return nftOwner subject issuer, the owner of the NFT
*/
function getSharesIssuer() external view returns(address nftOwner);
/**
* @notice Shares balance of the given holder; this function is similar to ERC20.balanceOf()
*
* @param holder the address to check the balance for
*
* @return balance number of shares the holder has
*/
function getSharesBalance(address holder) external view returns(uint256 balance);
/**
* @notice Total amount of the shares in existence, the sum of all individual shares balances;
* this function is similar to ERC20.totalSupply()
*
* @return supply total shares supply
*/
function getSharesSupply() external view returns(uint256 supply);
/**
* @notice The price of the `amount` of shares to buy calculated based on
* the specified total shares supply
*
* @param supply total shares supply
* @param amount number of shares to buy
* @return the price of the shares to buy
*/
function getBuyPrice(uint256 supply, uint256 amount) external pure returns(uint256);
/**
* @notice The price of the `amount` of shares to sell calculated based on
* the specified total shares supply
*
* @param supply total shares supply
* @param amount number of shares to sell
* @return the price of the shares to sell
*/
function getSellPrice(uint256 supply, uint256 amount) external pure returns(uint256);
/**
* @notice The price of the `amount` of shares to buy, including all fees;
* calculated based on the specified total shares supply and fees percentages
*
* @param supply total shares supply
* @param amount number of shares to buy
* @param protocolFeePercent protocol fee percent
* @param holdersFeePercent shares holders fee percent
* @param subjectFeePercent protocol fee percent
* @return the price of the shares to buy
*/
function getBuyPriceAfterFee(
uint256 supply,
uint256 amount,
uint256 protocolFeePercent,
uint256 holdersFeePercent,
uint256 subjectFeePercent
) external pure returns(uint256);
/**
* @notice The price of the `amount` of shares to sell, including all fees;
* calculated based on the specified total shares supply and fees percentages
*
* @param supply total shares supply
* @param amount number of shares to sell
* @param protocolFeePercent protocol fee percent
* @param holdersFeePercent shares holders fee percent
* @param subjectFeePercent protocol fee percent
* @return the price of the shares to sell
*/
function getSellPriceAfterFee(
uint256 supply,
uint256 amount,
uint256 protocolFeePercent,
uint256 holdersFeePercent,
uint256 subjectFeePercent
) external pure returns(uint256);
/**
* @notice Current price of the `amount` of shares to buy; calculated based on
* the current total shares supply
*
* @param amount number of shares to buy
* @return the price of the shares to buy
*/
function getBuyPrice(uint256 amount) external view returns(uint256);
/**
* @notice Current price of the `amount` of shares to sell; calculated based on
* the current total shares supply
*
* @param amount number of shares to sell
* @return the price of the shares to sell
*/
function getSellPrice(uint256 amount) external view returns(uint256);
/**
* @notice Current price of the `amount` of shares to buy, including all fees;
* calculated based on the current total shares supply and fees percentages
*
* @param amount number of shares to buy
* @return the price of the shares to buy
*/
function getBuyPriceAfterFee(uint256 amount) external view returns(uint256);
/**
* @notice Current price of the `amount` of shares to sell, including all fees;
* calculated based on the current total shares supply and fees percentages
*
* @param amount number of shares to sell
* @return the price of the shares to sell
*/
function getSellPriceAfterFee(uint256 amount) external view returns(uint256);
/**
* @notice Buy `amount` of shares. Sender has to supply `getBuyPriceAfterFee(amount)` ETH.
* First share can be bought only by current subject issuer.
*
* @dev Depending on the implementation, ERC-20 token payment may be required instead of ETH.
* In such a case, implementation must through if ETH is sent, effectively overriding
* the function definition as non-payable
*
* @param amount amount of the shares to buy
*/
function buyShares(uint256 amount) external payable;
/**
* @notice Buy `amount` of shares in the favor of the address specified (beneficiary).
* Sender has to supply `getBuyPriceAfterFee(amount)` ETH.
* First share can be bought only by current subject issuer.
*
* @dev Depending on the implementation, ERC-20 token payment may be required instead of ETH.
* In such a case, implementation must through if ETH is sent, effectively overriding
* the function definition as non-payable
*
* @param amount amount of the shares to buy
* @param beneficiary an address receiving the shares
*/
function buySharesTo(uint256 amount, address beneficiary) external payable;
/**
* @notice Sell `amount` of shares. Sender gets `getSellPriceAfterFee(amount)` of ETH.
* Last share cannot be sold.
*
* @dev Depending on the implementation, ERC-20 token may be payed instead of ETH.
*
* @param amount amount of the shares to sell
*/
function sellShares(uint256 amount) external;
/**
* @notice Sell `amount` of shares in the favor of the address specified (beneficiary).
* The beneficiary gets `getSellPriceAfterFee(amount)` of ETH.
* Last share cannot be sold.
*
* @dev Depending on the implementation, ERC-20 token may be payed instead of ETH.
*
* @param amount amount of the shares to sell
* @param beneficiary an address receiving the funds from the sale
*/
function sellSharesTo(uint256 amount, address payable beneficiary) external;
/**
* @notice Cumulative value of all trades; allows to derive cumulative fees paid
*
* @dev This value cannot decrease over time; it can increase or remain constant
* if no trades are happening
*
* @return Sum of the modulo of all trading operations
*/
function getTradeVolume() external view returns(uint256);