@trends-fun/bonding-curve-solana-sdk
v1.1.0
Published
TypeScript SDK for interacting with:
Downloads
98
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.
Version Notes
1.1.0 includes breaking API changes.
networkis now required for swap quote and tx builder APIs.- Venue routing is now automatic via pool state.
- Trading on completed but not migrated pools throws
PoolMigrationPending.
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:
getPoolInfogetMarketCapgetMarketInfo
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 network = "devnet";
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,
network,
});
const tx = await client.swap.buildBuyTx({
baseMint,
amountInLamports: new BN(1_000_000_000),
minAmountOut: quote.minAmountOut,
trader,
rpcEndpoint,
network,
});
// 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.
All swap quote and tx builder methods also require network.
2) Build Swap Transactions
await client.swap.buildBuyTx({
baseMint,
amountInLamports,
minAmountOut,
trader,
rpcEndpoint,
network,
});
await client.swap.buildSellTx({
baseMint,
tokenAmountIn,
minAmountOut,
trader,
rpcEndpoint,
network,
});
await client.swap.buildSwapTx({
baseMint,
side: "buy" | "sell",
amountAsset: "sol" | "token",
amount,
trader,
slippageBps,
rpcEndpoint,
network,
});network supports:
mainnet-betadevnet
2.1) Read Market Venue
const market = await client.getMarketInfo(baseMint, rpcEndpoint, network);
console.log(market.activeVenue);
// bondingCurve | migrationPending | raydiumCpmm3) 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