Pool Interaction

The Bonding Curve Pool is a dynamic pricing mechanism used in the GoFundMeme Protocol to enable seamless token swaps. Instead of relying on traditional order books, bonding curves establish an automated market maker (AMM)-style system where price adjusts based on supply and demand.

With the GoFundMeme SDK, you can: βœ… Fetch Bonding Curve pool details βœ… Buy tokens from the bonding curve βœ… Sell tokens back for SOL βœ… Harvest LP fees and staking rewards βœ… Stake, unstake, and claim rewards


πŸ› οΈ Fetching a Bonding Curve Pool

To interact with a Bonding Curve Pool, fetch its data using the mint address of the token launched in a Fair Launch.

import { Connection, PublicKey } from "@solana/web3.js";
import { initGoFundMemeSDK } from "@gofundmeme/sdk";

const connection = new Connection("https://api.mainnet-beta.solana.com");

(async () => {
  const gfmSDK = await initGoFundMemeSDK({ connection });

  // Replace with the token mint address
  const mintAddress = new PublicKey("THE TOKEN MINT ADDRESS");

  // Fetch the Bonding Curve Pool
  const bondingCurvePool = await gfmSDK.pools.bondingCurve.fetchBondingCurvePool(
    { mintB: mintAddress }
  );

  console.log("Bonding Curve Pool Data:", bondingCurvePool);
})();

πŸ“Š Checking Pool Status

Once you've fetched the Bonding Curve Pool, you can check its status, target raise, and funding progress.

import { LAMPORTS_PER_SOL } from "@solana/web3.js";

const { poolStatus, targetRaise, totalRaised } = bondingCurvePool.poolData;

if (poolStatus.raising) {
  console.log("βœ… The pool is still in the raising phase.");
}

if (targetRaise.toNumber() > totalRaised.toNumber()) {
  const remainingSolToRaise =
    (targetRaise.toNumber() - totalRaised.toNumber()) / LAMPORTS_PER_SOL;
  console.log("⚠️ Pool is NOT fully funded yet!", { remainingSolToRaise });
}

πŸ›’ Buying Tokens on the Bonding Curve

Purchasing tokens from the Bonding Curve Pool is simple. Specify the amount of SOL you wish to spend and set a slippage tolerance.

import { Keypair, sendAndConfirmTransaction } from "@solana/web3.js";
import Decimal from "decimal.js";

const payer = Keypair.generate(); // Replace with your actual signer

const { quote: buyQuote, transaction: buyTransaction } =
  await bondingCurvePool.actions.swap.buy({
    amountInUI: new Decimal(1.2), // Buy with 1.2 SOL
    funder: payer.publicKey,
    slippage: 1, // 1% slippage tolerance
  });

// View the purchase quote details
console.log("Buy Quote:", buyQuote);

// Sign and send the transaction
const buyTxid = await sendAndConfirmTransaction(connection, buyTransaction, [
  payer,
]);

console.log(
  `πŸŽ‰ Successfully bought tokens from the bonding curve! TXID: ${buyTxid}`
);

πŸ’° Selling Tokens Back for SOL

If you want to sell tokens back to the Bonding Curve Pool, specify the amount of tokens to sell and set your slippage tolerance.

const { quote: sellQuote, transaction: sellTransaction } =
  await bondingCurvePool.actions.swap.sell({
    amountInUI: new Decimal(10_000_000.1153), // Selling 10,000,000.1153 tokens
    funder: payer.publicKey,
    slippage: 2.5, // 2.5% slippage tolerance
  });

// View the sell quote details
console.log("Sell Quote:", sellQuote);

// Sign and send the transaction
const sellTxid = await sendAndConfirmTransaction(connection, sellTransaction, [
  payer,
]);

console.log(
  `πŸ’° Successfully sold tokens on the bonding curve for SOL! TXID: ${sellTxid}`
);

🏦 Fetching LP Fees & Harvester Rewards

Once the Bonding Curve Pool has completed its lifecycle, LP fees and harvester rewards can be retrieved.

const summary = await bondingCurvePool.actions.harvestUtils.getLpStateSummary();
console.log("πŸ“Š LP Fee Summary:", summary);

πŸ“Œ Example Response:

{
  "totalHarvested": {
    "tokenA": 33.013248883,
    "tokenB": 56016886.86489466
  },
  "availableForHarvest": {
    "tokenA": 0,
    "tokenB": 885.540800497
  },
  "harvesterRewards": {
    "tokenA": 0,
    "tokenB": 8.85540800497
  }
}

🌾 Harvesting LP Fees

LP fees generated from trades can be harvested by crankers.

const harvestTransaction = await bondingCurvePool.actions.harvestUtils.harvest({
  cranker: payer.publicKey,
});

const harvestTxid = await sendAndConfirmTransaction(
  connection,
  harvestTransaction,
  [payer]
);

console.log(`🌾 Successfully harvested LP fees! TXID: ${harvestTxid}`);

Last updated