Programs

PumpSwap recipe: pools and swaps after migration

PumpSwap is where a pump.fun token trades once its bonding curve completes. This recipe finds the pool from the migration, decodes pool creations and every swap variant with the published IDL, and was checked against the balances and vaults of real mainnet transactions.

For a PumpSwap swap decode, match each top-level instruction to the PumpSwap program ID and decode it with the IDL that pump.fun publishes. A buy fixes either the tokens received or the quote spent, and a sell fixes the tokens given up. Before any of that, the pump.fun migrate instruction names the pool a graduating token will trade in.

Program IDs and IDLs#

WhatValue
PumpSwap program IDpAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA
pump.fun program ID6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P
IDLspump_amm.json and pump.json from pump-fun/pump-public-docs, commit 639b87f
Decoderanchor.ts from the Anchor decoding guide, plus the two files below
RuntimeNode 24, no dependencies

Both IDLs carry an address field equal to the program ID, and both programs were executable on mainnet when we checked. The program IDs page lists them with the other DEX programs.

From bonding curve to pool#

A pump.fun token trades on its bonding curve until the curve completes. Then a top-level pump.fun migrate instruction moves the liquidity into a PumpSwap pool. Its account list, in IDL order, includes the token as mint (position 3) and the new pool as pool (position 10), so a decoder sees the pool address in the same transaction that creates it, before the pool has traded at all.

The pool itself is created by a PumpSwap create_pool that migrate calls internally. That call is a cross-program invocation: it is not in the transaction bytes, so a shred decoder never sees it directly. It appears only in the inner instructions that RPC returns after execution. In the migration we decoded at slot 470,939,696, that inner create_pool put 206,900,000,000,000 raw units of the token and 150,941,143 lamports of wrapped SOL into the pool.

Do not treat every successful migrate as a new pool. The other migration in our sample, at slot 470,939,762, succeeded but did nothing: its log reads "Bonding curve already migrated", and it has no inner instructions. Its pool already existed. In both cases the pool's earliest swaps we found were in the same slot as the migration, so a decoder should expect trades on a new pool immediately.

PumpSwap pools can also be created directly, by a top-level create_pool. All three direct creations in our sample were signed by the account named as the coin creator.

Swap instructions and what they fix#

InstructionUser fixesAmount fieldLimit fieldTokens leaveTokens arrive
buytokens outbase_amount_outmax_quote_amount_inuser_quote_token_accountuser_base_token_account
buy_exact_quote_inquote inspendable_quote_inmin_base_amount_outuser_quote_token_accountuser_base_token_account
selltokens inbase_amount_inmin_quote_amount_outuser_base_token_accountuser_quote_token_account
create_pooldepositbase_amount_in, quote_amount_innonecreatorthe new pool

The IDL also has _v2 forms of buy, buy_exact_quote_in and sell; the recipe maps them the same way, and one sell_v2 appeared in our sample. The user is the user account and must sign.

Steps#

  1. Keep the transactions whose top-level instructions call PumpSwap or pump.fun. Resolve lookup table addresses first if the transaction is v0 or v1.
  2. For pump.fun migrate, record the mint and pool from its accounts as a candidate pool.
  3. For PumpSwap, decode with SwapDecoder and PoolDecoder below. Each returns one plain object or null.
  4. Join swaps to pools on the pool address, and order them by slot and position in the block.
  5. After confirmation, use RPC to settle what the instructions could not say: whether the transaction succeeded, whether a migrate actually created a pool, and the amounts that really moved.

src/swaps.ts#

One module covers the swaps of six DEX programs; the PumpSwap mapping is the first entry in MAPS.

src/swaps.ts
// One shape for swaps on PumpSwap, Raydium CPMM and CLMM, Orca Whirlpool and Meteora DLMM and DAMM v2, decoded with
// each program's published IDL (fixtures/idls/SOURCES.tsv) through anchor.ts. Names on the right are the IDLs' own.
import { AnchorDecoder } from "./anchor.ts";
export type Swap = {
program: string; instruction: string;
pool: string; user: string; // the pool traded against and the signer that owns the user accounts
source: string; destination: string; // the user's token accounts: tokens leave source, arrive in destination
exact: "in" | "out"; // which side the user fixed
amount: bigint; // the fixed side: exact input, or exact output
limit: bigint; // exact in: least output accepted; exact out: most input accepted
partial: boolean; // true only for DAMM v2 PartialFill: up to `amount` in may be spent
};
export const DEX = {
pumpswap: "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA",
raydiumCpmm: "CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C",
raydiumClmm: "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK",
orcaWhirlpool: "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc",
meteoraDlmm: "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo",
meteoraDammV2: "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG",
} as const;
type Map = (name: string, x: Record<string, any>, a: Record<string, string | null>) => Omit<Swap, "program" | "instruction" | "partial"> | null;
const MAPS: Record<string, Map> = {
// PumpSwap: buy fixes the base tokens out; buy_exact_quote_in fixes the quote in; sell fixes the base tokens in.
[DEX.pumpswap]: (n, x, a) => {
const base = { pool: a.pool!, user: a.user! };
if (n === "buy" || n === "buy_v2") return { ...base, source: a.user_quote_token_account!, destination: a.user_base_token_account!, exact: "out", amount: x.base_amount_out, limit: x.max_quote_amount_in };
if (n.startsWith("buy_exact_quote_in")) return { ...base, source: a.user_quote_token_account!, destination: a.user_base_token_account!, exact: "in", amount: x.spendable_quote_in, limit: x.min_base_amount_out };
if (n === "sell" || n === "sell_v2") return { ...base, source: a.user_base_token_account!, destination: a.user_quote_token_account!, exact: "in", amount: x.base_amount_in, limit: x.min_quote_amount_out };
return null;
},
// Raydium CPMM: one instruction per direction of exactness.
[DEX.raydiumCpmm]: (n, x, a) => {
const base = { pool: a.pool_state!, user: a.payer!, source: a.input_token_account!, destination: a.output_token_account! };
if (n === "swap_base_input") return { ...base, exact: "in", amount: x.amount_in, limit: x.minimum_amount_out };
if (n === "swap_base_output") return { ...base, exact: "out", amount: x.amount_out, limit: x.max_amount_in };
return null;
},
// Raydium CLMM: a flag says which side `amount` is; `other_amount_threshold` is the limit on the other side.
[DEX.raydiumClmm]: (n, x, a) => n === "swap" || n === "swap_v2"
? { pool: a.pool_state!, user: a.payer!, source: a.input_token_account!, destination: a.output_token_account!,
exact: x.is_base_input ? "in" : "out", amount: x.amount, limit: x.other_amount_threshold } : null,
// Orca Whirlpool: accounts are named by token A and B, so direction comes from `a_to_b`.
[DEX.orcaWhirlpool]: (n, x, a) => n === "swap" || n === "swap_v2"
? { pool: a.whirlpool!, user: a.token_authority!,
source: (x.a_to_b ? a.token_owner_account_a : a.token_owner_account_b)!, destination: (x.a_to_b ? a.token_owner_account_b : a.token_owner_account_a)!,
exact: x.amount_specified_is_input ? "in" : "out", amount: x.amount, limit: x.other_amount_threshold } : null,
// Meteora DLMM: separate exact-in and exact-out instructions, each with a "2" variant that adds remaining accounts.
[DEX.meteoraDlmm]: (n, x, a) => {
const base = { pool: a.lb_pair!, user: a.user!, source: a.user_token_in!, destination: a.user_token_out! };
if (n === "swap" || n === "swap2") return { ...base, exact: "in", amount: x.amount_in, limit: x.min_amount_out };
if (n === "swap_exact_out" || n === "swap_exact_out2") return { ...base, exact: "out", amount: x.out_amount, limit: x.max_in_amount };
return null;
},
// Meteora DAMM v2: swap is exact in; swap2 carries a mode byte (damm-v2 ix_swap.rs SwapMode: 0 ExactIn, 1 PartialFill, 2 ExactOut).
[DEX.meteoraDammV2]: (n, x, a) => {
const base = { pool: a.pool!, user: a.payer!, source: a.input_token_account!, destination: a.output_token_account! };
const p = x._params;
if (n === "swap") return { ...base, exact: "in", amount: p.amount_in, limit: p.minimum_amount_out };
if (n === "swap2") return p.swap_mode === 2 ? { ...base, exact: "out", amount: p.amount_0, limit: p.amount_1 }
: { ...base, exact: "in", amount: p.amount_0, limit: p.amount_1 }; // PartialFill fills up to amount_0 in
return null;
},
};
export class SwapDecoder {
private decoders = new Map<string, AnchorDecoder>();
/** idls: program id -> that program's IDL */
constructor(idls: Record<string, object>) { for (const [p, idl] of Object.entries(idls)) this.decoders.set(p, new AnchorDecoder(idl as any)); }
decode(programId: string, data: Uint8Array, accounts: string[]): Swap | null {
const dec = this.decoders.get(programId), map = MAPS[programId];
if (!dec || !map) return null;
const d = dec.decodeWithAccounts(data, accounts, programId);
if (!d) return null;
const s = map(d.name, d.args as Record<string, any>, d.accounts);
if (!s) return null;
const partial = programId === DEX.meteoraDammV2 && d.name === "swap2" && (d.args as any)._params.swap_mode === 1;
return { program: programId, instruction: d.name, ...s, partial };
}
}

src/pools.ts#

src/pools.ts
// One shape for new pools on PumpSwap, Raydium CPMM and CLMM, Orca Whirlpool and Meteora DLMM and DAMM v2, decoded
// with each program's published IDL (fixtures/idls/SOURCES.tsv) through anchor.ts. Names on the right are the IDLs' own.
import { AnchorDecoder } from "./anchor.ts";
import { DEX } from "./swaps.ts";
export type PoolCreated = {
program: string; instruction: string;
pool: string; creator: string; // the new pool account and the account that pays for it
mintA: string; mintB: string; // in the program's own order (base/quote, 0/1, A/B or X/Y)
amountA: bigint | null; amountB: bigint | null; // initial deposit, when the creation instruction carries one
sqrtPriceX64: bigint | null; // starting price for the sqrt-price designs (Q64.64)
activeBinId: number | null; // starting bin for DLMM
};
type Map = (n: string, x: Record<string, any>, a: Record<string, string | null>) => Omit<PoolCreated, "program" | "instruction"> | null;
const none = { amountA: null, amountB: null, sqrtPriceX64: null, activeBinId: null };
const MAPS: Record<string, Map> = {
[DEX.pumpswap]: (n, x, a) => n === "create_pool"
? { ...none, pool: a.pool!, creator: a.creator!, mintA: a.base_mint!, mintB: a.quote_mint!, amountA: x.base_amount_in, amountB: x.quote_amount_in } : null,
[DEX.raydiumCpmm]: (n, x, a) => n === "initialize" || n === "initialize_with_permission"
? { ...none, pool: a.pool_state!, creator: a.creator!, mintA: a.token_0_mint!, mintB: a.token_1_mint!, amountA: x.init_amount_0, amountB: x.init_amount_1 } : null,
[DEX.raydiumClmm]: (n, x, a) => n === "create_pool"
? { ...none, pool: a.pool_state!, creator: a.pool_creator!, mintA: a.token_mint_0!, mintB: a.token_mint_1!, sqrtPriceX64: x.sqrt_price_x64 } : null,
[DEX.orcaWhirlpool]: (n, x, a) => n.startsWith("initialize_pool")
? { ...none, pool: a.whirlpool!, creator: a.funder!, mintA: a.token_mint_a!, mintB: a.token_mint_b!, sqrtPriceX64: x.initial_sqrt_price } : null,
[DEX.meteoraDlmm]: (n, x, a) => n === "initialize_lb_pair" || n === "initialize_lb_pair2" || n.startsWith("initialize_customizable_permissionless_lb_pair")
? { ...none, pool: a.lb_pair!, creator: a.funder!, mintA: a.token_mint_x!, mintB: a.token_mint_y!, activeBinId: x.active_id ?? x.params.active_id } : null,
[DEX.meteoraDammV2]: (n, x, a) => n === "initialize_pool" || n === "initialize_customizable_pool" || n === "initialize_pool_with_dynamic_config"
? { ...none, pool: a.pool!, creator: a.creator!, mintA: a.token_a_mint!, mintB: a.token_b_mint!, sqrtPriceX64: x.params.sqrt_price } : null,
};
export class PoolDecoder {
private decoders = new Map<string, AnchorDecoder>();
/** idls: program id -> that program's IDL */
constructor(idls: Record<string, object>) { for (const [p, idl] of Object.entries(idls)) this.decoders.set(p, new AnchorDecoder(idl as any)); }
decode(programId: string, data: Uint8Array, accounts: string[]): PoolCreated | null {
const dec = this.decoders.get(programId), map = MAPS[programId];
if (!dec || !map) return null;
const d = dec.decodeWithAccounts(data, accounts, programId);
if (!d) return null;
const p = map(d.name, d.args as Record<string, any>, d.accounts);
if (!p) return null;
return { program: programId, instruction: d.name, pool: p.pool, creator: p.creator, mintA: p.mintA, mintB: p.mintB,
amountA: p.amountA, amountB: p.amountB, sqrtPriceX64: p.sqrtPriceX64, activeBinId: p.activeBinId };
}
}

src/decode-dex.ts: one transaction#

src/decode-dex.ts
// Print swaps and new pools for one transaction, for the six DEX programs in swaps.ts and pools.ts.
// node src/decode-dex.ts <idl-dir> <transaction-base64> [loaded-writable,...] [loaded-readonly,...]
import fs from "node:fs";
import { decodeTx } from "./tx.ts";
import { SwapDecoder, DEX } from "./swaps.ts";
import { PoolDecoder } from "./pools.ts";
const [idlDir, txBase64, loadedW = "", loadedR = ""] = process.argv.slice(2);
const idl = (f: string) => JSON.parse(fs.readFileSync(`${idlDir}/${f}`, "utf8"));
const idls = { [DEX.pumpswap]: idl("pump_amm.json"), [DEX.raydiumCpmm]: idl("raydium_cp_swap.json"), [DEX.raydiumClmm]: idl("raydium_clmm.json"),
[DEX.orcaWhirlpool]: idl("whirlpool.json"), [DEX.meteoraDlmm]: idl("dlmm.json"), [DEX.meteoraDammV2]: idl("cp_amm.json") };
const swaps = new SwapDecoder(idls), pools = new PoolDecoder(idls);
const tx = decodeTx(Buffer.from(txBase64, "base64"));
const keys = [...tx.staticKeys, ...loadedW.split(",").filter(Boolean), ...loadedR.split(",").filter(Boolean)];
for (const ix of tx.instructions) { // top-level calls only: a DEX called by a router or launchpad is a CPI
const program = keys[ix.programIndex], accounts = ix.accounts.map((i) => keys[i]);
const event = swaps.decode(program, ix.data, accounts) ?? pools.decode(program, ix.data, accounts);
if (event) console.log(JSON.stringify({ signature: tx.signatures[0], ...event }, (_k, v) => (typeof v === "bigint" ? v.toString() : v)));
}

Run it with the IDL folder, the transaction in base64, and any addresses loaded from lookup tables:

Shell
node src/decode-dex.ts fixtures/idls "$TX_BASE64" "$LOADED_WRITABLE" "$LOADED_READONLY"

A real pool and a real swap, decoded#

FieldPool creation, slot 470,928,022Swap, slot 470,928,476
instructioncreate_poolbuy_exact_quote_in
poolEiCNb6JWdg7H2UENoi5ZMDG69bFoNYkF39rdXusK5a8ZFVPeKS3rfrpF7ZzfXvo3PRGQ6XKpXc47ocyLhPpmN5vz
creator or user3kkqFc66Qp4K6NqK3opuM93PSYCBeGoWdo8z8mxUtLbK6MGz9PUXfW9GEKj1DsMiit2wv1txC54rx2qQTNegyHW9
amountsbase 86,990,000,000, quote 199,002,201,000,000exact in: 2,188,715
limitnoneat least 3,197,003,676 out
mintsbase So11111111111111111111111111111111111111112, quote EcygPriCFGis8k9w7fNMPnr8qvLjcSMq5jpmCxrK929Jnot in the swap's own fields

The pool creation has wrapped SOL as its base mint: the program accepts any pair, so never assume SOL is the quote side. Amounts are raw units; divide by each mint's decimals before showing them.

How this code was tested#

CheckResult
PumpSwap swaps decoded (successful transactions)buy 9, buy_exact_quote_in 63, sell 74, sell_v2 1
The user signed the transactionevery one
Exact side equals the user's token balance change, where no other instruction touched that account2/2 buy, 36/36 buy_exact_quote_in, 19/19 sell, 1/1 sell_v2
Limit respected on the other side, same condition7/7, 24/24, 56/56
Direct pool creations: decoded pool equals the pool the sample was found by; deposit equals the new vault balances3/3, 3/3
Migrations: migrate names the pool; inner create_pool has that pool and the token as base, or the log says already migrated; swaps on the pool follow2/2

The balance checks skip token accounts that another instruction in the same transaction also touched, such as a second swap in a route, because then the change is not the swap's alone. The tests are test-swaps.ts, test-pools.ts and test-migrations.ts, and they run in the examples' test-all.sh.

What the instructions cannot tell you#

The instruction gives the side the user fixed and the worst price they accepted, not the price they got: for the other side you need the token balance changes or the program's event after execution. A swap does not name the mints, only the user's token accounts and the pool, so join to the pool creation or read the pool account. A migrate names a pool even when it creates nothing. And swaps that a router or a bot program calls internally are inner instructions, invisible in shreds.

Earlier and later in a token's life#

Before migration, the token trades on pump.fun: the pump.fun recipe decodes creates, buys and sells on the curve. For swaps that pass through PumpSwap inside an aggregator, see the Jupiter recipe. To receive these transactions as the leader sends them, compare the plans.

Sources#

Raw shreds on your own server

Ultra Low Latency Shreds is $200 and Standard Shreds is $100. You pay in crypto, tell us which IPv4 address and UDP port should receive the stream, and we wire it up by hand.