> For the complete documentation index, see [llms.txt](https://docs.gofundmeme.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gofundmeme.io/developers/gfm-methods/bonding-curve/pool-interaction.md).

# 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.

```typescript
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**.

```typescript
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**.

```typescript
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**.

```typescript
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

{% hint style="danger" %}
NOT supported on **GFM-SDK-Frontend**
{% endhint %}

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

```typescript
const summary = await bondingCurvePool.actions.harvestUtils.getLpStateSummary();
console.log("📊 LP Fee Summary:", summary);
```

#### 📌 Example Response:

```json
{
  "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.

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

<br>
