GoFundMeme
  • GoFundMeme - Launch the next viral meme
  • FAQs
  • Getting Started
    • Referral Program
    • Reward System
    • Point System
    • Fees
  • GoFundMeme
    • Launch a Memecoin
      • Bonding Curve
        • Intro
      • Fair Launch
        • Tokenomics
        • Target Target
        • Boosters & Vesting
    • Harvest (LP LOCK)
      • How it works
      • Harvesting LP Fees
      • Claim Rewards
    • GFM Protocol
    • Defi x Memecoins
    • Staking
    • KYC Gating
    • SocialFi
      • Community Bubbles
  • Developers
    • GFM for Builders
    • Installation Guide
    • Init gfmSDK
    • GFM Methods
      • Bonding Curve
        • Pool Interaction
        • Pool Staking Network
      • Fair Launch
        • Pool Interaction
    • APIs
      • Create Pools
    • WebSockets
      • Subscriptions
Powered by GitBook
On this page
  • 🛠️ Fetching a Bonding Curve Pool
  • 📊 Checking Pool Status
  • 🛒 Buying Tokens on the Bonding Curve
  • 💰 Selling Tokens Back for SOL
  • 🏦 Fetching LP Fees & Harvester Rewards
  • 🌾 Harvesting LP Fees
  1. Developers
  2. GFM Methods
  3. Bonding Curve

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

NOT supported on GFM-SDK-Frontend

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}`);

PreviousBonding CurveNextPool Staking Network

Last updated 2 months ago