SDK for interacting with the PumpFun AMM on Solana
npm install pumpfun-swap-sdkA TypeScript SDK for interacting with the PumpFun Automated Market Maker (AMM) on Solana.
- Create and manage liquidity pools
- Deposit and withdraw liquidity
- Swap tokens with slippage protection
- Admin functionality for pool management
``bash`
npm install pumpfun-swap-sdk
`typescript
import { PumpAmmSdk, Direction } from "pumpfun-swap-sdk";
import { Connection, PublicKey } from "@solana/web3.js";
import { BN } from "@coral-xyz/anchor";
// Initialize SDK with Solana connection
const connection = new Connection("https://api.mainnet-beta.solana.com");
const pumpAmmSdk = new PumpAmmSdk(connection);
// Create a pool
const index = 0;
const creator = new PublicKey("your-wallet-public-key");
const baseMint = new PublicKey("base-token-mint");
const quoteMint = new PublicKey("quote-token-mint");
const baseIn = new BN("1000000000"); // 1 token with 9 decimals
const quoteIn = new BN("1000000000"); // 1 token with 9 decimals
const createPoolInstructions = await pumpAmmSdk.createPoolInstructions(
index,
creator,
baseMint,
quoteMint,
baseIn,
quoteIn
);
// Get initial pool price for UI
const initialPoolPrice = await pumpAmmSdk.createAutocompleteInitialPoolPrice(
baseIn,
quoteIn
);
// Build and send transaction
const { transactionFromInstructions, sendAndConfirmTransaction } = require("pumpfun-swap-sdk");
const transaction = transactionFromInstructions(createPoolInstructions);
const signature = await sendAndConfirmTransaction(transaction);
`
For depositing into a pool:
`typescript
// When base input changes
const { quote, lpToken } =
await pumpAmmSdk.depositAutocompleteQuoteAndLpTokenFromBase(
pool,
base,
slippage
);
// When quote input changes
const { base, lpToken } =
await pumpAmmSdk.depositAutocompleteBaseAndLpTokenFromQuote(
pool,
quote,
slippage
);
// Execute deposit
const depositInstructions = await pumpAmmSdk.depositInstructions(
pool,
lpToken,
slippage,
user
);
const transaction = transactionFromInstructions(depositInstructions);
const signature = await sendAndConfirmTransaction(transaction);
`
The SDK supports bi-directional swaps using the Direction enum:
`typescript
// Quote to Base swap (⬇️)
const baseAmount = await pumpAmmSdk.swapAutocompleteBaseFromQuote(
pool,
quoteAmount,
slippage
);
// Base to Quote swap (⬆️)
const quoteAmount = await pumpAmmSdk.swapAutocompleteQuoteFromBase(
pool,
baseAmount,
slippage
);
// Execute swap
const swapInstructions = await pumpAmmSdk.swapBaseInstructions(
pool,
baseAmount,
slippage,
Direction.QuoteToBase,
user
);
const transaction = transactionFromInstructions(swapInstructions);
const signature = await sendAndConfirmTransaction(transaction);
`
`typescript
// Get expected output amounts
const { base, quote } = await pumpAmmSdk.withdrawAutoCompleteBaseAndQuoteFromLpToken(
pool,
lpToken,
slippage
);
// Execute withdrawal
const withdrawInstructions = await pumpAmmSdk.withdrawInstructions(
pool,
lpToken,
slippage,
user
);
const transaction = transactionFromInstructions(withdrawInstructions);
const signature = await sendAndConfirmTransaction(transaction);
``
MIT