pumpswap-trading
v3.0.0
Published
Official package to buy and sell tokens on swap.pump.fun (AMM) with enhanced features
Readme
pumpswap-trading
Official package to buy and sell tokens on swap.pump.fun (AMM) with enhanced features
npm i pumpswap-tradingFeatures
- All the features of the original pump.fun AMM trading package
- 3% fee system to optimize your trading experience
- Simple API similar to standard trading packages
- Full support for buying and selling tokens
Usage
The API is similar to other trading packages for ease of use.
Get mint reserves, estimate the swap, create instructions, sign, and send.
const Pumpswap = require('pumpswap-trading')
const SOL = require('like-solana')
const rpc = new SOL.RPC()
const pumpswap = new Pumpswap(rpc)
main()
async function main () {
const baseMint = '2fWkVf417bfxEgUemymkYNagXVitnmNxvq7dhUwnpump'
const quoteMint = 'So11111111111111111111111111111111111111112'
const recentBlockhash = (await rpc.getLatestBlockhash()).blockhash
const user = new SOL.Keypair('<secret key...>')
// Buy 0.1 SOL of tokens with 3% slippage
const reserves = await pumpswap.getReserves(baseMint, quoteMint)
const swapBuy = pumpswap.quoteToBase(0.1, reserves, 0.03)
const ixBuy = pumpswap.buyExactOut(baseMint, quoteMint, swapBuy.baseAmountOut, swapBuy.quoteInMax, user.publicKey, reserves)
const txBuy = SOL.sign(ixBuy, { unitPrice: 0.0001, signers: [user], recentBlockhash })
console.log('Buy signature:', SOL.signature(txBuy))
await rpc.sendTransaction(txBuy)
// ... (could wait for confirmation)
await new Promise(resolve => setTimeout(resolve, 5000))
// Sell the tokens we bought with 3% slippage
const reserves2 = await pumpswap.getReserves(baseMint, quoteMint)
const swapSell = pumpswap.baseToQuote(swapBuy.baseAmountOut, reserves2, 0.03)
const ixSell = pumpswap.sellExactIn(baseMint, quoteMint, swapSell.baseAmountIn, swapSell.quoteOutMin, user.publicKey, reserves)
const txSell = SOL.sign(ixSell, { unitPrice: 0.0001, signers: [user], recentBlockhash })
console.log('Sell signature:', SOL.signature(txSell))
await rpc.sendTransaction(txSell)
// ...
}API
pumpswap = new Pumpswap(rpc)
Create a new Pumpswap instance.
A solana-rpc instance must be provided.
reserves = await pumpswap.getReserves(baseMint[, quoteMint])
Fetch the pool, base, and quote as reserves.
The quote mint is So11111111111111111111111111111111111111112 by default.
Returns:
{
baseReserve: BigInt,
quoteReserve: BigInt,
creator: String
}Buy
swap = pumpswap.quoteToBase(quoteAmountIn, reserves[, slippage, options])
Buy estimation on how many tokens you will receive based on quote (SOL).
Slippage is zero by default, you expect to receive what you estimated or more.
// 0.5 SOL to TOKENS at 3% slippage (Auto-converted to BigInt)
const swapBuy = pumpswap.quoteToBase(0.5, reserves, 0.03)
// BigInt(0.5 * 1e9) to TOKENS (Nine decimals)
const swapBuy = pumpswap.quoteToBase(500000000n, reserves, 0.03)Options:
{
sync: Boolean // For multiple continuous swaps
}Returns:
{
baseAmountOut: BigInt,
quoteAmountIn: BigInt,
quoteAmountInWithLpFee: BigInt,
userQuoteAmountIn: BigInt,
quoteInMax: BigInt,
pumpfunFee: BigInt // The 3% fee amount
}ix = pumpswap.buyExactOut(baseMint, quoteMint, baseAmountOut, quoteInMax, userPublicKey, reserves)
Create buy instructions for any pair of tokens.
Use quoteToBase to calculate the amounts, unless you already know them.
Sell
swap = pumpswap.baseToQuote(baseAmountIn, reserves[, slippage, options])
Sell estimation on how much SOL you will receive based on base (tokens).
Slippage is zero by default, you expect to receive what you estimated or more.
// 350000000 TOKENS to SOL at 3% slippage (Auto-converted to BigInt)
const swapSell = pumpswap.baseToQuote(350000000, reserves, 0.03)
// BigInt(350000000 * 1e6) to TOKENS (Six decimals)
const swapSell = pumpswap.baseToQuote(350000000000000n, reserves, 0.03)Options:
{
sync: Boolean // For multiple continuous swaps
}Returns:
{
baseAmountIn: BigInt,
quoteAmountOut: BigInt,
quoteAmountOutLessFees: BigInt,
userQuoteAmountOut: BigInt,
quoteOutMin: BigInt,
pumpfunFee: BigInt // The 3% fee amount
}ix = pumpswap.sellExactIn(baseMint, quoteMint, baseAmountIn, quoteOutMin, userPublicKey, reserves)
Create sell instructions for any pair of tokens.
Use baseToQuote to calculate the amounts, unless you already know them.
Fee System
This package includes a 3% trading fee that's automatically calculated and included in all transactions. The fee is charged in SOL and sent directly to a designated fee address during transactions.
API
pool = await pumpswap.getPool(poolAddress)
Fetch the latest pool data on-chain.
mint = await pumpswap.getMint(mintAddress)
Fetch the latest mint data on-chain.
tokenAccount = await pumpswap.getTokenAccount(address)
Fetch the latest token account data on-chain.
API (static)
Pumpswap.PROGRAM_ID
Indicates the program ID: pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA
marketCap = Pumpswap.marketCap(reserves)
Calculates the market capitalization of the token.
price = Pumpswap.price(reserves)
Calculates the price of 1 token in SOL (lamport units).
poolAddress = Pumpswap.poolAddress(mint)
Returns the pool address based on the mint public key.
config = Pumpswap.global()
Returns the global config (admin, fees, flags, etcetera).
License
MIT
