@trends-fun/bonding-curve-solana-sdk
v1.0.0-beta.2
Published
TypeScript SDK for interacting with:
Readme
Bonding Curve Solana SDK
TypeScript SDK for interacting with:
BondingCurve(pool creation, quotes, buy/sell tx building)
Program ID:CURVEmPpijXDTNdqrA9PGP1io2rkgiVXH26xdXVGLLfzCreatorFeeDistributor(coin creator / fee recipient reward claim tx building)
Program ID:FEEsRsTdRJWECQDJJ4XghT7YUY8AVVoEnZQVipg7JGwB
This SDK builds transactions and quotes. It does not sign or send transactions for you.
What makes this SDK different: it uses a stateless, function-first API (client.*) so you do not need to instantiate a client with new; tx builders expose optional compute budget controls (computeUnitLimit, computeUnitPriceMicroLamports) for congestion-aware execution tuning; and quote APIs support optional pool caching via poolCacheTtlMs, so you can choose between maximum freshness and reduced RPC load based on your use case.
Features
- Quote APIs:
- buy by SOL / token out
- sell by token in / SOL out
- unified quote route (
quoteSwap)
- Transaction builders:
buildBuyTxbuildSellTxbuildSwapTx(quote + tx builder wrapper)buildInitializePoolTxbuildInitializePoolAndBuyTx(single transaction)
- Reward claim builders:
buildCoinCreatorClaimRewardTxbuildFeeRecipientClaimRewardTx(supports multiple mints)
- Pool readers:
getPoolInfogetMarketCap
Installation
Local development
bun installFrom NPM
npm install @trends-fun/bonding-curve-solana-sdkQuick Start
import BN from "bn.js";
import { PublicKey } from "@solana/web3.js";
import { client } from "@trends-fun/bonding-curve-solana-sdk";
const rpcEndpoint = "http://127.0.0.1:8899";
const baseMint = new PublicKey("<BASE_MINT>");
const trader = new PublicKey("<TRADER>");
const quote = await client.swap.quoteBuyBySol({
baseMint,
amountInLamports: new BN(1_000_000_000), // 1 SOL
slippageBps: 100,
rpcEndpoint,
});
const tx = await client.swap.buildBuyTx({
baseMint,
amountInLamports: new BN(1_000_000_000),
minAmountOut: quote.minAmountOut,
trader,
rpcEndpoint,
});
// sign/send in your app:
// const sig = await provider.sendAndConfirm(tx, [signers...]);API Usage
1) Quote
await client.swap.quoteBuyBySol({ ... });
await client.swap.quoteBuyByToken({ ... });
await client.swap.quoteSellByToken({ ... });
await client.swap.quoteSellBySol({ ... });
await client.swap.quoteSwap({ ... }); // unifiedAll quote methods require rpcEndpoint and baseMint.
2) Build Swap Transactions
await client.swap.buildBuyTx({
baseMint,
amountInLamports,
minAmountOut,
trader,
rpcEndpoint,
});
await client.swap.buildSellTx({
baseMint,
tokenAmountIn,
minAmountOut,
trader,
rpcEndpoint,
});
await client.swap.buildSwapTx({
baseMint,
side: "buy" | "sell",
amountAsset: "sol" | "token",
amount,
trader,
slippageBps,
rpcEndpoint,
});3) Initialize Pool
// initialize only
const { tx, poolPDA, baseVaultPDA, quoteVaultPDA } =
await client.pool.buildInitializePoolTx({
baseMint, // PublicKey
params: { name, symbol, uri },
creator,
rpcEndpoint,
});
// initialize + first buy in one tx (minAmountOut fixed to 0)
const createAndBuy = await client.pool.buildInitializePoolAndBuyTx({
baseMint,
params: { name, symbol, uri },
creator,
amountInLamports,
trader, // optional, defaults to creator
rpcEndpoint,
});4) Claim Distributor Rewards
// A.1) Read current coin creator reward account state first (recommended)
const coinCreatorReward =
await client.reward.getCoinCreatorRewardAccountByCreator({
coinCreator,
rpcEndpoint,
});
// A.2) Build claim tx only when reward account exists and reward > 0
await client.reward.buildCoinCreatorClaimRewardTx({
coinCreator,
rpcEndpoint,
});
// B.1) Read current fee recipient reward account state first (recommended)
const feeRecipientReward =
await client.reward.getFeeRecipientRewardAccountByMint({
mint,
rpcEndpoint,
});
// B.2) Build claim tx only when reward account exists and reward > 0
await client.reward.buildFeeRecipientClaimRewardTx({
feeRecipient,
mint,
additionalMints: [mintB, mintC], // optional
rpcEndpoint,
});Why read (get*) before claim:
- To confirm the reward account exists (uninitialized accounts return
null). - To avoid unnecessary claim attempts when reward is
0. - To validate account binding (
feeRecipient/mint) before sending a transaction.
Build
bun run buildArtifacts:
dist/index.js(ESM)dist/index.cjs(CJS)dist/index.d.ts(types)
Test (Anchor)
This workspace uses Anchor's test runner with the script configured in Anchor.toml:
test = "bash ./scripts/run-anchor-tests.sh"
Run full SDK test suite
anchor test --skip-local-validatorRun specific test files
anchor test --skip-local-validator tests/sdk_client_test.ts
anchor test --skip-local-validator tests/reward_client_test.tsDirect script usage (no Anchor wrapper)
bash ./scripts/run-anchor-tests.sh tests/sdk_client_test.ts
bash ./scripts/run-anchor-tests.sh tests/*_test.ts