Getting Started
This guide will help you set up the BONKswap AMM Integration SDK and create your first integration.
Prerequisites
Before you begin, ensure you have:
- Node.js (v16 or higher)
- TypeScript knowledge
- Solana development experience
- Git for cloning the repository
Installation
The BONKswap AMM Integration SDK is available as a GitHub repository. Choose one of the following installation methods:
Option 1: Clone the Repository
# Clone the SDK repository
git clone git@github.com:BonkLabs/bonkswap-amm-integration.git
# Or use HTTPS
git clone https://github.com/BonkLabs/bonkswap-amm-integration.git
# Navigate to the directory
cd bonkswap-amm-integration
# Install dependencies
npm install
Option 2: Copy Files to Your Project
# Clone the repository
git clone https://github.com/BonkLabs/bonkswap-amm-integration.git
# Copy the SDK files to your project
cp -r bonkswap-amm-integration/amm.ts your-project/src/
cp -r bonkswap-amm-integration/idl/ your-project/src/
cp -r bonkswap-amm-integration/tsconfig.json your-project/
Option 3: Use as Local Dependency
# In your project's package.json, add:
{
"dependencies": {
"bonkswap-amm-integration": "file:../bonkswap-amm-integration"
}
}
# Then install
npm install
Environment Setup
Required Dependencies
Add these dependencies to your project:
npm install @solana/web3.js @coral-xyz/anchor @solana/spl-token
TypeScript Configuration
Ensure your tsconfig.json includes:
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
}
}
Basic Usage
1. Initialize the AMM
import { Connection, PublicKey } from "@solana/web3.js";
import { BN } from "@coral-xyz/anchor";
import BONKSwapAMM, { QuoteParams } from "./bonkswap-amm-integration/amm";
// Initialize Solana connection
const connection = new Connection("https://api.mainnet-beta.solana.com");
// Define pool address (BONK/SOL pool)
const poolAddress = new PublicKey("GBmzQL7BTKwSV9Qg7h5iXQad1q61xwMSzMpdbBkCyo2p");
// Get pool account info
const accountInfo = await connection.getAccountInfo(poolAddress);
if (!accountInfo) {
throw new Error("Pool account not found");
}
// Initialize AMM instance
const amm = new BONKSwapAMM(poolAddress, accountInfo);
2. Get a Quote
// Define quote parameters
const quoteParams: QuoteParams = {
sourceMint: amm.pool.tokenX, // BONK token mint
destinationMint: amm.pool.tokenY, // SOL token mint
amount: new BN(1000 * 1e5), // 1000 BONK tokens (5 decimals)
swapMode: "ExactIn" // Exact input amount
};
// Get quote
const quote = amm.getQuote(quoteParams);
// Check for liquidity
if (quote.notEnoughLiquidity) {
console.log("❌ Insufficient liquidity for this swap");
return;
}
// Display results
console.log("📊 Quote Results:");
console.log("Input Amount:", quote.inAmount.toString());
console.log("Output Amount:", quote.outAmount.toString());
console.log("Fee Amount:", quote.feeAmount.toString());
console.log("Price Impact:", quote.priceImpactPct.toFixed(4) + "%");
3. Create Swap Instructions
import { Keypair, PublicKey } from "@solana/web3.js";
import BONKSwapAMM, { SwapParams } from "./bonkswap-amm-integration/amm";
// User wallet and accounts
const userWallet = Keypair.generate(); // Replace with actual wallet
const userBONKAccount = new PublicKey("..."); // User's BONK token account
const userSOLAccount = new PublicKey("..."); // User's SOL account
// Define swap parameters
const swapParams: SwapParams = {
sourceMint: amm.pool.tokenX,
destinationMint: amm.pool.tokenY,
userSourceTokenAccount: userBONKAccount,
userDestinationTokenAccount: userSOLAccount,
userTransferAuthority: userWallet.publicKey,
inAmount: new BN(1000 * 1e5) // 1000 BONK tokens
};
// Generate swap instructions
const instructions = amm.createSwapInstructions(swapParams);
console.log("🔧 Generated", instructions.length, "swap instructions");
Complete Example
Here's a complete example that demonstrates the full workflow:
import { Connection, PublicKey, Keypair } from "@solana/web3.js";
import { BN } from "@coral-xyz/anchor";
import BONKSwapAMM, { QuoteParams, SwapParams } from "./bonkswap-amm-integration/amm";
async function main() {
// 1. Setup connection
const connection = new Connection("https://api.mainnet-beta.solana.com");
// 2. Initialize AMM
const poolAddress = new PublicKey("GBmzQL7BTKwSV9Qg7h5iXQad1q61xwMSzMpdbBkCyo2p");
const accountInfo = await connection.getAccountInfo(poolAddress);
if (!accountInfo) {
throw new Error("Pool account not found");
}
const amm = new BONKSwapAMM(poolAddress, accountInfo);
// 3. Get quote
const quoteParams: QuoteParams = {
sourceMint: amm.pool.tokenX,
destinationMint: amm.pool.tokenY,
amount: new BN(1000 * 1e5),
swapMode: "ExactIn"
};
const quote = amm.getQuote(quoteParams);
if (quote.notEnoughLiquidity) {
console.log("❌ Insufficient liquidity");
return;
}
console.log("✅ Quote received:");
console.log("Output:", quote.outAmount.toString());
console.log("Fees:", quote.feeAmount.toString());
console.log("Impact:", quote.priceImpactPct.toFixed(4) + "%");
// 4. Create swap instructions (example)
const userWallet = Keypair.generate();
const swapParams: SwapParams = {
sourceMint: amm.pool.tokenX,
destinationMint: amm.pool.tokenY,
userSourceTokenAccount: new PublicKey("11111111111111111111111111111111"),
userDestinationTokenAccount: new PublicKey("11111111111111111111111111111111"),
userTransferAuthority: userWallet.publicKey,
inAmount: new BN(1000 * 1e5)
};
const instructions = amm.createSwapInstructions(swapParams);
console.log("🔧 Generated", instructions.length, "instructions");
}
main().catch(console.error);
Project Structure
After cloning the repository, you'll have:
bonkswap-amm-integration/
├── amm.ts # Main AMM integration class
├── idl/ # Anchor IDL files
│ ├── bonkswap.json # BONKswap program IDL
│ └── bonkswap.ts # Generated TypeScript types
├── example-get-quote.ts # Quote example
├── create-swap-instructions.ts # Swap instructions example
├── simple-swap-instructions.ts # Simple swap example
├── package.json # Dependencies and scripts
└── tsconfig.json # TypeScript configuration