Bonding Curve In Developers' Perspective
How to find the reserve/price/fdv from the circulating supply of a token?
Option1: Read from the Chain
/// @notice Get token state (V5)
/// @param token The address of the token
/// @return state The state of the token (V5) with all curve parameters (r, h, k)
function getTokenV5(address token) external view returns (TokenStateV5 memory state);
/// @dev Token version
/// Which token implementation is used
enum TokenVersion {
TOKEN_LEGACY_MINT_NO_PERMIT,
TOKEN_LEGACY_MINT_NO_PERMIT_DUPLICATE, // for historical reasons, both 0 and 1 are the same: TOKEN_LEGACY_MINT_NO_PERMIT
TOKEN_V2_PERMIT,
TOKEN_GOPLUS
}
/// @notice the status of a token
/// The token has 4 statuses:
// - Tradable: The token can be traded(buy/sell)
// - InDuel: (obsolete) The token is in a battle, it can only be bought but not sold.
// - Killed: (obsolete) The token is killed, it can not be traded anymore. Can only be redeemed for another token.
// - DEX: The token has been added to the DEX
enum TokenStatus {
Invalid, // The token does not exist
Tradable,
InDuel, // obsolete
Killed, // obsolete
DEX
}
/// @notice the state of a token (with all V4 fields plus all curve parameters)
struct TokenStateV5 {
/// The status of the token (see TokenStatus enum)
TokenStatus status;
/// The reserve amount of the quote token held by the bonding curve
uint256 reserve;
/// The circulating supply of the token
uint256 circulatingSupply;
/// The current price of the token (in quote token units, 18 decimals)
uint256 price;
/// The version of the token implementation (see TokenVersion enum)
TokenVersion tokenVersion;
/// The curve parameter 'r' used for the bonding curve
uint256 r;
/// The curve parameter 'h' - virtual token reserve
uint256 h;
/// The curve parameter 'k' - square of virtual liquidity
uint256 k;
/// The circulating supply threshold for adding the token to the DEX
uint256 dexSupplyThresh;
/// The address of the quote token (address(0) if native gas token)
address quoteTokenAddress;
/// Whether native-to-quote swap is enabled for this token
bool nativeToQuoteSwapEnabled;
/// The extension ID used by the token (bytes32(0) if no extension)
bytes32 extensionID;
}
Option 2: Derive price/fdv/reserve from the current circulating supply
How to calculate the progress of a token
Last updated