Bonding Curve Account
Understanding and working with Bonding Curve Accounts in the PumpFundler SDK
Bonding Curve Account
The Bonding Curve Account is a fundamental concept in the PumpFun protocol. It represents the state of a token’s bonding curve, which determines the pricing dynamics of the token.
Structure
The BondingCurveAccount
class has the following properties:
discriminator
: A unique identifier for the account typevirtualTokenReserves
: The virtual token balance used for price calculationsvirtualSolReserves
: The virtual SOL balance used for price calculationsrealTokenReserves
: The actual token balance in the bonding curverealSolReserves
: The actual SOL balance in the bonding curvetokenTotalSupply
: The total supply of tokenscomplete
: A flag indicating if the bonding curve is complete (all tokens sold)
Key Methods
getBuyPrice
Calculates the price in SOL for buying a specific amount of tokens. This method:
- Checks if the curve is complete
- Calculates the new virtual reserves after the purchase
- Determines the amount of tokens to be purchased
- Returns the minimum of the calculated tokens and real token reserves
getSellPrice
Calculates the amount of SOL received for selling a specific amount of tokens. This method:
- Checks if the curve is complete
- Calculates the proportional amount of virtual SOL reserves to be received
- Applies the fee based on the provided fee basis points
- Returns the net amount after deducting the fee
getMarketCapSOL
Calculates the current market cap of the token in SOL. This is done by:
- Checking if there are any virtual token reserves
- Calculating the market cap based on the total supply and virtual reserves ratio
getFinalMarketCapSOL
Estimates the final market cap of the token in SOL when all tokens are sold. This method:
- Calculates the total sell value of remaining real token reserves
- Determines the total virtual value and remaining virtual tokens
- Computes the final market cap based on these values
getBuyOutPrice
Calculates the price to buy out a specific amount of tokens from the bonding curve. This method:
- Determines the amount of SOL tokens to use in the calculation
- Calculates the total sell value based on the virtual reserves
- Applies the fee based on the provided fee basis points
- Returns the total buyout price
Creating a BondingCurveAccount
The BondingCurveAccount
can be created from a buffer, typically obtained from on-chain data:
This static method:
- Defines the structure of the account data
- Decodes the buffer into a JavaScript object
- Creates and returns a new
BondingCurveAccount
instance with the decoded data
Usage in the SDK
The BondingCurveAccount
is primarily used in the PumpFundler SDK for:
- Calculating buy and sell prices for tokens
- Determining the current and projected market cap of tokens
- Managing the state of individual token bonding curves
When interacting with the PumpFun protocol, you’ll often work with BondingCurveAccount
instances to make informed decisions about trading and to understand the current state of a token’s bonding curve.
Example: Fetching and Using a Bonding Curve Account
Here’s an example of how to fetch and use a BondingCurveAccount
in the PumpFundler SDK:
This example demonstrates how to fetch a BondingCurveAccount
, analyze its current state, and use its methods to calculate important metrics like buy price and market cap.