Trade

Quotes and swaps

SDK quotes use the same integer math as the program, with the same rounding. If the pool doesn't move between the quote and the swap, the swap returns exactly the quoted amount, to the unit.

proglet.fun sends its users' buys and sells to pump.fun (the bonding curve, then PumpSwap after graduation) with pump's own SDKs, because every pump.fun trade pays the creator fee that buys the coin back into its Proglet pool. The pool's own swap below is still open to anyone, for integrators who want to trade against the locked pool directly.

Quote a swap

ts
// Buy with 0.1 SOL, accept up to 1% slippage.
const q = await client.quote(mint, true, 100_000_000n, 100);

q.amountOut;      // tokens (base units) you get
q.minOut;         // amountOut minus 1%: the slippage guard
q.fee;            // the 1% fee, lamports
q.priceImpactBps; // execution vs spot, fee included

amountIn is lamports on a buy and token base units on a sell; amountOut is the other side. The default slippage is 1%.

amountOutbigintTokens on a buy, lamports on a sell.
feebigintThe total 1% fee in lamports, always charged in SOL.
teamFeebigintThe 20% of the fee that goes to the team; the rest stays in the pool.
priceImpactBpsbigintExecution price vs spot price, fee included.
spotPriceQ64bigintSpot price before the swap, Q64.64.
solReserveAfter, tokenReserveAfterbigintThe pool's reserves after this swap.
minOutbigintOnly on client.quote: amountOut reduced by the slippage you passed.

Swap

swapInstructions quotes and returns ready-to-sign instructions with min_out already set. It also creates the user's token account if needed.

ts
import { Transaction } from "@solana/web3.js";

const { quote, instructions } = await client.swapInstructions(mint, wallet.publicKey, true, 100_000_000n, 100);
const tx = new Transaction().add(...instructions);
const sig = await wallet.sendTransaction(tx, connection);

If the pool moves past your slippage before the swap lands, it fails with SlippageExceeded instead of filling at a worse price. Swaps are never paused.

Pure functions

When you already have the reserves (from the Data API or your own indexer), quote without any RPC call:

ts
import { quoteBuy, quoteSell, minOutWithSlippage, spotPrice, swapInstructions } from "@proglet/sdk";

const q = quoteBuy(pool.solReserve, pool.tokenReserve, 100_000_000n);
const minOut = minOutWithSlippage(q.amountOut, 50); // 0.5%

const ixs = swapInstructions({ mint, user, isBuy: true, amountIn: 100_000_000n, minOut });
const price = spotPrice(pool.solReserve, pool.tokenReserve); // SOL per whole token, for display

quote_swap on chain

The program has a read-only quote_swap(is_buy, amount_in) instruction. Simulate it and read the Anchor return data (a borsh SwapQuote) to quote without this SDK's math. simulateQuote does it for you:

ts
const onChain = await client.simulateQuote(mint, true, 100_000_000n, anyExistingAccount);
Simulation needs a fee payer that exists on chain; it never spends anything.

Fees

  • Every swap pays 1% (SWAP_FEE_BPS), always in SOL: taken from the SOL you pay on a buy, from the SOL you get on a sell.
  • 80% of the fee stays in the pool, so trading deepens it. 20% (TEAM_SHARE_BPS) goes to the pool's team fee vault.
  • Anyone can call sweep to move a pool's team fees, but only to the configured treasury.