Use Pump.fun

The Use Pump.fun tool, part of AgentiPy, allows users to interact with the Pump.fun platform on Solana. This includes functionalities to buy and sell tokens listed on Pump.fun, and to get information about a token's bonding curve state and price. Pump.fun is known for facilitating the launch and trading of new tokens, often with high volatility.

Functionality

This tool is implemented in the PumpfunManager class. It interacts directly with the Pump.fun on-chain program (PUMP_PROGRAM) by constructing and sending Solana transactions.

Key Methods:

  • get_pump_curve_state(conn: AsyncClient, curve_address: Pubkey) -> BondingCurveState:

    • (Static method) Fetches and parses the account data for a given curve_address (bonding curve) to determine its current state (e.g., virtual token reserves, virtual SOL reserves).

    • Returns a BondingCurveState object.

  • calculate_pump_curve_price(curve_state: BondingCurveState) -> float:

    • (Static method) Calculates the current price of the token based on the curve_state.

    • Returns the price in SOL per token.

  • get_token_balance(conn: AsyncClient, associated_token_account: Pubkey) -> int:

    • (Static method) Fetches the balance of a given associated_token_account.

    • Returns the balance as an integer (in the smallest unit of the token).

  • buy_token(agent: SolanaAgentKit, mint: Pubkey, bonding_curve: Pubkey, associated_bonding_curve: Pubkey, amount: float, slippage: float = 0.01, max_retries=5):

    • (Static async method) Buys a token from its Pump.fun bonding curve.

    • Parameters:

      • agent: The SolanaAgentKit instance.

      • mint: The Pubkey of the token to buy.

      • bonding_curve: The Pubkey of the token's bonding curve account.

      • associated_bonding_curve: The Pubkey of the curve's associated token account.

      • amount: The amount of SOL to spend.

      • slippage: Allowed slippage (e.g., 0.01 for 1%).

      • max_retries: Number of times to retry the transaction if it fails.

    • Calculates the expected token amount and maximum SOL to spend with slippage.

    • Creates the buyer's Associated Token Account (ATA) if it doesn't exist.

    • Constructs and sends a transaction to the Pump.fun program to execute the buy.

    • Returns the transaction signature.

  • sell_token(agent: SolanaAgentKit, mint: Pubkey, bonding_curve: Pubkey, associated_bonding_curve: Pubkey, slippage: float = 0.25, max_retries=5):

    • (Static async method) Sells a token back to its Pump.fun bonding curve.

    • Parameters are similar to buy_token, but amount is not directly passed; instead, it fetches the full token balance from the agent's ATA to sell.

    • Calculates the minimum SOL output to receive based on slippage.

    • Constructs and sends a transaction to the Pump.fun program to execute the sell.

    • Returns the transaction signature.

Important Considerations:

  • Direct On-Chain Interaction: This tool interacts directly with the Solana blockchain and the Pump.fun smart contract. It does not use a proxy.

  • Extreme Financial Risk: Pump.fun is a platform for newly launched tokens which are often extremely volatile and can result in significant or total loss of funds. This is not an endorsement or recommendation to use Pump.fun.

  • Mainnet Operations: Pump.fun primarily operates on Solana Mainnet. All transactions are real and involve real SOL and tokens.

  • Slippage: High slippage tolerance is often necessary due to the volatility of tokens on Pump.fun, which further increases risk.

  • Associated Token Accounts: The tool attempts to create the Associated Token Account (ATA) for the buyer if it doesn't exist.

Source Code

You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_pumpfun.py

Last updated