API Reference
Complete reference for the BONKswap AMM Integration SDK.
Table of Contents
BONKSwapAMM Class
The main class for interacting with BONKswap AMM pools.
Constructor
constructor(address: PublicKey, accountInfo: AccountInfo<Buffer>)
Parameters:
address- The pool addressaccountInfo- The pool account info from Solana
Example:
import BONKSwapAMM from "./bonkswap-amm-integration/amm";
const amm = new BONKSwapAMM(poolAddress, accountInfo);
Properties
reserveTokenMints: PublicKey[]
Array of token mints in the pool (usually 2 elements).
pool: PoolStructure
The current pool state structure.
poolAddress: PublicKey
The address of the pool.
Methods
getAccountsForUpdate(): PublicKey[]
Returns the accounts needed to update the pool state.
Returns: Array of PublicKeys that need to be fetched for updates.
update(accountInfoMap: AccountInfo<Buffer>[]): void
Updates the pool state with new account information.
Parameters:
accountInfoMap- Array of account info objects
getQuote(quoteParams: QuoteParams): Quote
Gets a quote for a potential swap.
Parameters:
quoteParams- Quote parameters including source/destination mints and amount
Returns: Quote object with swap details
Example:
import BONKSwapAMM, { QuoteParams } from "./bonkswap-amm-integration/amm";
const quote = amm.getQuote({
sourceMint: amm.pool.tokenX,
destinationMint: amm.pool.tokenY,
amount: new BN(1000 * 1e5),
swapMode: "ExactIn"
});
createSwapInstructions(swapParams: SwapParams): TransactionInstruction[]
Creates transaction instructions for executing a swap.
Parameters:
swapParams- Swap parameters including user accounts and amounts
Returns: Array of transaction instructions
Example:
import BONKSwapAMM, { SwapParams } from "./bonkswap-amm-integration/amm";
const instructions = amm.createSwapInstructions({
sourceMint: amm.pool.tokenX,
destinationMint: amm.pool.tokenY,
userSourceTokenAccount: userBONKAccount,
userDestinationTokenAccount: userSOLAccount,
userTransferAuthority: userWallet.publicKey,
inAmount: new BN(1000 * 1e5)
});
Interfaces
QuoteParams
Parameters for getting a quote.
interface QuoteParams {
sourceMint: PublicKey; // Token mint address you're swapping from
destinationMint: PublicKey; // Token mint address you're swapping to
amount: BN; // Amount to swap (in smallest units)
swapMode: SwapMode; // "ExactIn" or "ExactOut"
}
Quote
Result of a quote request.
interface Quote {
notEnoughLiquidity: boolean; // True if pool doesn't have enough liquidity
inAmount: BN; // Input amount
outAmount: BN; // Output amount after fees
feeAmount: BN; // Total fees charged
feeMint: TokenMintAddress; // Token mint for fees
feePct: number; // Fee percentage (0-1)
priceImpactPct: number; // Price impact percentage
}
SwapParams
Parameters for creating swap instructions.
interface SwapParams {
sourceMint: PublicKey; // Token mint you're swapping from
destinationMint: PublicKey; // Token mint you're swapping to
userSourceTokenAccount: PublicKey; // User's source token account
userDestinationTokenAccount: PublicKey; // User's destination token account
userTransferAuthority: PublicKey; // User's wallet (signer)
inAmount: BN; // Amount to swap
}
PoolStructure
Complete pool state structure.
interface PoolStructure {
tokenX: PublicKey; // First token mint
tokenY: PublicKey; // Second token mint
poolXAccount: PublicKey; // Pool's X token account
poolYAccount: PublicKey; // Pool's Y token account
admin: PublicKey; // Pool admin
projectOwner: PublicKey; // Project owner
constK: Product; // Constant product (K)
price: FixedPoint; // Current price
lpFee: FixedPoint; // LP fee rate
buybackFee: FixedPoint; // Buyback fee rate
projectFee: FixedPoint; // Project fee rate
mercantiFee: FixedPoint; // Referrer fee rate
tokenXReserve: Token; // X token reserve
tokenYReserve: Token; // Y token reserve
selfShares: Token; // Self shares
allShares: Token; // Total shares
buybackAmountX: Token; // Buyback X amount
buybackAmountY: Token; // Buyback Y amount
projectAmountX: Token; // Project X amount
projectAmountY: Token; // Project Y amount
mercantiAmountX: Token; // Referrer X amount
mercantiAmountY: Token; // Referrer Y amount
lpAccumulatorX: Token; // LP accumulator X
lpAccumulatorY: Token; // LP accumulator Y
farmCount: BN; // Farm count
bump: number; // Bump seed
}
FixedPoint
Fixed-point number representation.
interface FixedPoint {
v: BN; // Value as BigNumber
}
Token
Token amount representation.
interface Token {
v: BN; // Amount as BigNumber
}
Product
Product representation.
interface Product {
v: BN; // Value as BigNumber
}
Types
TokenMintAddress
type TokenMintAddress = PublicKey;
SwapMode
type SwapMode = "ExactIn" | "ExactOut";
Error Handling
The SDK includes comprehensive error handling for various scenarios:
Common Errors
Pool Account Not Found
if (!accountInfo) {
throw new Error("Pool account not found");
}
Insufficient Liquidity
const quote = amm.getQuote(quoteParams);
if (quote.notEnoughLiquidity) {
console.log("Insufficient liquidity for this swap");
}
Fee Exceeds Output
// This error is thrown internally if fees would exceed the output amount
// The SDK prevents this from happening by validating the quote
Error Handling Best Practices
import BONKSwapAMM, { QuoteParams } from "./bonkswap-amm-integration/amm";
try {
const amm = new BONKSwapAMM(poolAddress, accountInfo);
const quote = amm.getQuote(quoteParams);
if (quote.notEnoughLiquidity) {
console.log("❌ Insufficient liquidity");
return;
}
if (quote.priceImpactPct > 5) {
console.log("⚠️ High price impact:", quote.priceImpactPct + "%");
}
// Proceed with swap
const instructions = amm.createSwapInstructions(swapParams);
} catch (error) {
if (error.message.includes("Pool account not found")) {
console.log("❌ Invalid pool address or network issue");
} else if (error.message.includes("Fees exceed deltaOut")) {
console.log("❌ Swap amount too small for fees");
} else {
console.log("❌ Unexpected error:", error.message);
}
}
Constants
Program IDs
// BONKswap Program ID
const BONKSWAP_PROGRAM_ID = "BSwp6bEBihVLdqJRKGgzjcGLHkcTuzmSo1TQkHepzH8p";
// Program Authority
const PROGRAM_AUTHORITY = "8NyaPDJeC2eaBGpkRpZKnD9S448AZGgjSvumFe92DRK2";
// State Address
const STATE_ADDRESS = "2QWN6WjrJ3RAk51ecxLxaLPfFCYLAnmWJwJ1oKA92CRD";
Default Values
// Default denominator for price calculations
const DEFAULT_DENOMINATOR = new BN(10).pow(new BN(12));
// Default slippage (100%)
const DEFAULT_SLIPPAGE = new BN(100);
Type Definitions
Amm Interface
The base interface that BONKSwapAMM implements:
interface Amm {
reserveTokenMints: PublicKey[];
getAccountsForUpdate(): PublicKey[];
update(accountInfoMap: any): void;
getQuote(quoteParams: QuoteParams): Quote;
createSwapInstructions(swapParams: SwapParams): TransactionInstruction[];
}