Pump.fun swap (quote + unsigned build)
Default keyless endpoints
Use RPC_URL=https://musebook-proxy.mynameisjeffspicoli.workers.dev/api/solana/rpc unless the owner set their own (fallback public mainnet). Jupiter quote: GET https://musebook-proxy.mynameisjeffspicoli.workers.dev/api/trade/quote?inputMint=&outputMint=&amount=&slippageBps=; prices: GET .../api/trade/jupiter/prices?ids=<mints>; unsigned build: .../api/trade/jupiter/build.
Safety rules (always)
- Never sign, send, or broadcast. Never ask for or accept a private key or seed phrase. Output only an unsigned base64 transaction plus a human summary for the user to review and sign in their own wallet.
- Ask for anything missing: token (mint/CA/name), side, size, the user's wallet pubkey (for builds), slippage (default 8%, accept 5–10% unless the user says otherwise).
- Before any build, show: venue (bonding curve or PumpSwap), quote asset (SOL/USDC/pump coin), price, market cap (quote + SOL), graduation %, fee tier, expected out, price impact, min-out / max-in after slippage.
- Warn clearly when: graduation > 90%; price impact > 5% (strong warning > 15%) or pool/curve liquidity is thin; curve real reserves ≈ 0, no tokens left, or anything looks drained/suspicious; mayhem or cashback coin; creator holds or just dumped a large share.
- Simulate the unsigned tx (RPC simulateTransaction with sigVerify=false, replaceRecentBlockhash=true, encoding base64) and report the result. Funding errors (custom 0x1, AccountNotInitialized 3012) just mean the wallet lacks that balance.
- Units: SOL 9 decimals, pump coins 6, USDC 6. Read the token program from the mint account owner on-chain, never from an HTTP API.
Steps
- Resolve the token. A mint/CA is used as is. For a name or symbol, search (pump.fun coins API
https://frontend-api-v3.pump.fun/coins/search?searchTerm=<q> from a server, DexScreener https://api.dexscreener.com/latest/dex/search?q=<q>, or any connected token-search tool). Show the candidates and confirm the mint if there's any doubt (copycats are common).
- Make sure the toolkit below exists in a scratch folder (for example
~/pumpbot). If it's missing, create it: npm init -y && npm i @solana/web3.js@^1.98 @solana/spl-token ws, then save the script at the end of this skill as pump.js. Set RPC_URL if the user has a better RPC (default keyless musebook proxy /api/solana/rpc, fallback public mainnet).
- State:
node pump.js state <mint>. It returns the venue, quote asset, price, market cap (quote and SOL), graduation %, liquidity, fee tier and warnings.
- Quote:
node pump.js quote <mint> buy <quoteAmount> or ... sell <tokenAmount>. Present the numbers and every warning.
- Only if the user wants a trade:
node pump.js build <mint> buy|sell <amount> <walletPubkey> [slip%=8]. Return unsignedTxBase64, the min-out/max-in limits and the simulation result. Never sign.
- If the script can't be used, build with the pump.fun agent API instead (below), then simulate and summarize the same way.
- Live launches:
node pump.js tape 10 token-launch streams new coins from wss://clawd-ws.fly.dev/ws. Musebook connector tools (pump_stream_snapshot, live_launches) also work when they're connected.
Fee schedule
Bonding curve: 1.25% total (creator 0.30, protocol 0.95).
PumpSwap tiers by market cap (upper bound SOL / USD → creator / total; protocol 0.05 + LP 0.20 on every tier above the first):
0–420 SOL (0–85k): creator .30, protocol .93, LP .02 = 1.25 | 1,470 (300k): .95→1.20 | 2,460 (500k): .90→1.15 | 3,440 (700k): .85→1.10 | 4,420 (900k): .80→1.05 | 9,820 (2M): .75→1.00 | 14,740 (3M): .70→.95 | 19,650 (4M): .65→.90 | 24,560 (5M): .60→.85 | 29,470 (6M): .55→.80 | 34,380 (7M): .50→.75 | 39,300 (8M): .45→.70 | 44,210 (9M): .40→.65 | 49,120 (10M): .35→.60 | 54,030 (11M): .30→.55 | 58,940 (12M): .275→.53 | 63,860 (13M): .25→.50 | 68,770 (14M): .225→.48 | 73,681 (15M): .20→.45 | 78,590 (16M): .175→.43 | 83,500 (17M): .15→.40 | 88,400 (18M): .125→.38 | 93,330 (19M): .10→.35 | 98,240 (20M): .075→.33 | above 98,240 SOL (20M+): .05→.30.
On-chain tiers key off SOL market cap; use the USD column for USDC-quoted pools.
Building via the pump.fun agent API (no local code needed)
POST https://fun-block.pump.fun/agents/swap with JSON {"inputMint","outputMint","amount","user","slippagePct","encoding":"base64"}. Buy: inputMint = So11111111111111111111111111111111111111112, amount = lamports. Sell: outputMint = that wSOL mint, amount = token base units (6 decimals). It picks curve vs PumpSwap itself and returns {transaction, pumpMintInfo}. Always pass encoding base64. Run it with curl in a shell.
Script (pump.js)
#!/usr/bin/env node
// pumpbot v2: read-only state/quotes + UNSIGNED tx building (curve buy_v3/sell_v3, PumpSwap buy_v2/sell_v2).
// SOL, USDC and pump-coin-quoted curves/pools. NEVER signs or sends. No secrets.
const {Connection,PublicKey,TransactionInstruction,TransactionMessage,VersionedTransaction,ComputeBudgetProgram,SystemProgram}=require('@solana/web3.js');
const spl=require('@solana/spl-token');
const WebSocket=require('ws');
const conn=new Connection(process.env.RPC_URL||'https://musebook-proxy.mynameisjeffspicoli.workers.dev/api/solana/rpc','confirmed');
const PK=s=>new PublicKey(s);
const PUMP=PK('6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P'),AMM=PK('pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA'),FEEP=PK('pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ');
const WSOL=PK('So11111111111111111111111111111111111111112'),USDC=PK('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
const pda=(s,p=PUMP)=>PublicKey.findProgramAddressSync(s,p)[0],B=x=>Buffer.from(x);
const GLOBAL=pda([B('global')]),EV=pda([B('__event_authority')]),FEE_CFG=pda([B('fee_config'),PUMP.toBuffer()],FEEP);
const AMM_GC=pda([B('global_config')],AMM),AMM_EV=pda([B('__event_authority')],AMM),AMM_FEE_CFG=pda([B('fee_config'),AMM.toBuffer()],FEEP);
const ata=(m,o,tp)=>spl.getAssociatedTokenAddressSync(m,o,true,tp);
// Exact PumpSwap tier table: [upper bound SOL mcap, upper bound USD mcap, creator, protocol, lp, total]
const UPS=[420,1470,2460,3440,4420,9820,14740,19650,24560,29470,34380,39300,44210,49120,54030,58940,63860,68770,73681,78590,83500,88400,93330,98240,Infinity];
const UPU=[85e3,3e5,5e5,7e5,9e5,2e6,3e6,4e6,5e6,6e6,7e6,8e6,9e6,1e7,1.1e7,1.2e7,1.3e7,1.4e7,1.5e7,1.6e7,1.7e7,1.8e7,1.9e7,2e7,Infinity];
const CR=[.30,.95,.90,.85,.80,.75,.70,.65,.60,.55,.50,.45,.40,.35,.30,.275,.25,.225,.20,.175,.15,.125,.10,.075,.05];
const TIERS=CR.map((c,i)=>i?{maxSOL:UPS[i],maxUSD:UPU[i],creator:c,protocol:.05,lp:.20,total:+(c+.25).toFixed(3)}:{maxSOL:420,maxUSD:85e3,creator:.30,protocol:.93,lp:.02,total:1.25});
const CURVE_FEE={creator:.30,protocol:.95,lp:0,total:1.25};
const tierFor=(mcap,unit)=>TIERS.find(t=>mcap<(unit==='USD'?t.maxUSD:t.maxSOL));
class R{constructor(b,o=8){this.b=b;this.o=o}u64(){const v=this.b.readBigUInt64LE(this.o);this.o+=8;return v}i128(){const lo=this.b.readBigUInt64LE(this.o),hi=this.b.readBigInt64LE(this.o+8);this.o+=16;return(hi<<64n)+lo}u16(){const v=this.b.readUInt16LE(this.o);this.o+=2;return v}u8(){return this.b[this.o++]}bool(){return!!this.u8()}pk(){const p=new PublicKey(this.b.subarray(this.o,this.o+32));this.o+=32;return p}skip(n){this.o+=n}}
async function curveGlobal(){const r=new R((await conn.getAccountInfo(GLOBAL)).data),g={};r.bool();r.pk();r.pk();g.initVT=r.u64();g.initVS=r.u64();g.initRealT=r.u64();r.u64();r.u64();r.pk();r.bool();r.u64();r.u64();r.skip(32*7);r.pk();r.pk();r.bool();r.pk();r.pk();r.bool();r.skip(32*7);r.bool();g.buyback=[...Array(8)].map(()=>r.pk());return g}
async function ammGlobal(){const r=new R((await conn.getAccountInfo(AMM_GC)).data),g={};r.pk();r.u64();r.u64();r.u8();r.skip(32*8);r.u64();r.pk();r.pk();r.pk();r.bool();r.skip(32*7);r.bool();g.buyback=[...Array(8)].map(()=>r.pk());return g}
async function mintInfo(m){const a=await conn.getAccountInfo(m);if(!a)throw Error('mint not found '+m.toBase58());return{program:a.owner,decimals:a.data[44],supply:a.data.readBigUInt64LE(36)}}
const quoteLabel=q=>q.equals(WSOL)?'SOL':q.equals(USDC)?'USDC':'PUMPCOIN:'+q.toBase58();
async function solPerQuote(q){ // value of 1 quote unit in SOL (for tier lookup / display)
if(q.equals(WSOL))return 1;
try{const j=await(await fetch(`https://lite-api.jup.ag/price/v3?ids=${q.toBase58()},${WSOL.toBase58()}`)).json();return j[q.toBase58()].usdPrice/j[WSOL.toBase58()].usdPrice}catch{return null}}
async function getState(mintStr){
const mint=PK(mintStr),bc=pda([B('bonding-curve'),mint.toBuffer()]);
const [a,mi]=await Promise.all([conn.getAccountInfo(bc),mintInfo(mint)]);
const s={mint:mintStr,baseTokenProgram:mi.program.toBase58(),supply:Number(mi.supply)/10**mi.decimals,warnings:[]};
let c=null;
if(a){const r=new R(a.data);c={vT:r.u64(),vQ:r.u64(),rT:r.u64(),rQ:r.u64(),supply:r.u64(),complete:r.bool(),creator:r.pk(),mayhem:r.bool(),cashback:r.bool(),quoteMint:r.pk()};
if(c.quoteMint.equals(PublicKey.default))c.quoteMint=WSOL;}
if(c&&!c.complete){
const g=await curveGlobal(),qi=await mintInfo(c.quoteMint),qd=10**qi.decimals,price=Number(c.vQ)/qd/(Number(c.vT)/10**mi.decimals);
const grad=Math.max(0,100*(1-Number(c.rT)/Number(g.initRealT)));
Object.assign(s,{venue:'curve',bondingCurve:bc.toBase58(),quoteMint:c.quoteMint.toBase58(),quoteSymbol:quoteLabel(c.quoteMint),quoteDecimals:qi.decimals,quoteTokenProgram:qi.program.toBase58(),
creator:c.creator.toBase58(),price,mcap:price*s.supply,graduationPct:grad,realQuoteInCurve:Number(c.rQ)/qd,mayhem:c.mayhem,cashback:c.cashback,fees:CURVE_FEE,_c:c,_g:g});
const spq=await solPerQuote(c.quoteMint);if(spq)s.mcapSOL=s.mcap*spq;
if(grad>90)s.warnings.push(`Graduation very close (${grad.toFixed(1)}%) — migration to PumpSwap imminent`);
if(Number(c.rQ)/qd*(spq||1)<0.05)s.warnings.push('Curve holds ~0 real quote (brand new or drained): thin liquidity, high rug/dump risk');
if(c.rT===0n)s.warnings.push('Curve has no tokens left (drained/suspicious)');
if(c.mayhem)s.warnings.push('Mayhem-mode coin (no synthetic migration; different curve params)');
if(c.cashback)s.warnings.push('Cashback coin (deprecated mode; creator fee routes to buyer)');
return s}
// graduated / non-curve → canonical PumpSwap pool. Try SOL then USDC then curve quote.
const auth=pda([B('pool-authority'),mint.toBuffer()]),idx=Buffer.alloc(2);
const qs=[...(c?[c.quoteMint]:[]),WSOL,USDC];let pool,pa;
for(const q of qs){pool=pda([B('pool'),idx,auth.toBuffer(),mint.toBuffer(),q.toBuffer()],AMM);pa=await conn.getAccountInfo(pool);if(pa)break}
if(!pa){s.venue='none';s.warnings.push(c?'Curve complete but canonical pool not found yet (migrating?) — retry shortly':'Not a pump.fun coin (no curve/pool); use an aggregator');return s}
const r=new R(pa.data);const p={bump:r.u8(),index:r.u16(),creator:r.pk(),baseMint:r.pk(),quoteMint:r.pk(),lpMint:r.pk(),baseVault:r.pk(),quoteVault:r.pk(),lpSupply:r.u64(),coinCreator:r.pk(),mayhem:r.bool(),cashback:r.bool(),vQuote:r.i128()};
const [bv,qv,qi]=await Promise.all([conn.getTokenAccountBalance(p.baseVault),conn.getTokenAccountBalance(p.quoteVault),mintInfo(p.quoteMint)]);
const baseR=BigInt(bv.value.amount),quoteR=BigInt(qv.value.amount)+p.vQuote,qd=10**qi.decimals;
const price=Number(quoteR)/qd/(Number(baseR)/10**mi.decimals),mcap=price*s.supply,spq=await solPerQuote(p.quoteMint),mcapSOL=spq?mcap*spq:null;
const tier=p.quoteMint.equals(USDC)?tierFor(mcap,'USD'):tierFor(mcapSOL??mcap,'SOL');
Object.assign(s,{venue:'pumpswap',pool:pool.toBase58(),quoteMint:p.quoteMint.toBase58(),quoteSymbol:quoteLabel(p.quoteMint),quoteDecimals:qi.decimals,quoteTokenProgram:qi.program.toBase58(),
coinCreator:p.coinCreator.toBase58(),price,mcap,mcapSOL,graduationPct:100,poolQuoteLiquidity:Number(quoteR)/qd,mayhem:p.mayhem,cashback:p.cashback,fees:tier,_p:{...p,baseR,quoteR}});
if(p.quoteMint.equals(WSOL)&&Number(quoteR)/qd<20)s.warnings.push(`Thin pool: only ${(Number(quoteR)/qd).toFixed(2)} ${s.quoteSymbol} of quote liquidity`);
if(p.cashback)s.warnings.push('Cashback pool: v2 trades unsupported (CashbackCoinNotSupported); use v1 / aggregator');
return s}
// amt: quote units (SOL/USDC/coin) for buy, base tokens for sell
function quote(s,side,amt){
const fee=s.fees.total/100,bd=1e6,qd=10**s.quoteDecimals;let baseR,quoteR,cap=Infinity;
if(s.venue==='curve'){baseR=Number(s._c.vT);quoteR=Number(s._c.vQ);cap=Number(s._c.rT)}else if(s.venue==='pumpswap'){baseR=Number(s._p.baseR);quoteR=Number(s._p.quoteR)}else throw Error('no venue');
const spot=quoteR/baseR;let q;
if(side==='buy'){const qin=amt*qd,net=qin/(1+fee);let out=Math.min(baseR*net/(quoteR+net),cap);if(s.venue==='pumpswap')out=Math.min(out,baseR-1);
q={side,in:amt,inUnit:s.quoteSymbol,fee:(qin-net)/qd,tokensOut:out/bd,avgPrice:(net/out)*bd/qd,impactPct:100*((net/out)/spot-1),raw:{out:Math.floor(out),qin:Math.floor(qin)}}}
else{const t=amt*bd,gross=quoteR*t/(baseR+t),net=gross*(1-fee);q={side,inTokens:amt,outGross:gross/qd,fee:(gross-net)/qd,out:net/qd,outUnit:s.quoteSymbol,impactPct:100*(1-(gross/t)/spot),raw:{t:Math.floor(t),net:Math.floor(net)}}}
q.feeTierPct=s.fees;q.warnings=q.impactPct>15?[`HIGH price impact ${q.impactPct.toFixed(1)}%`]:q.impactPct>5?[`Notable price impact ${q.impactPct.toFixed(1)}%`]:[];
if(s.venue==='curve'&&side==='buy'&&q.raw.out>=cap)q.warnings.push('Buy exceeds tokens left on curve: rest goes through synthetic migration / may fail on mayhem coins');
return q}
const meta=(pubkey,w,sg)=>({pubkey,isWritable:!!w,isSigner:!!sg});
const u64s=(disc,a,b)=>{const d=Buffer.alloc(24);B(disc).copy(d);d.writeBigUInt64LE(BigInt(a),8);d.writeBigUInt64LE(BigInt(b),16);return d};
async function build(s,side,amt,walletStr,slip=8){
if(!(amt>0))throw Error('amount must be > 0');if(slip<0||slip>50)throw Error('slippage % out of range');
const user=PK(walletStr),mint=PK(s.mint),btp=PK(s.baseTokenProgram),qm=PK(s.quoteMint),qtp=PK(s.quoteTokenProgram),isSol=qm.equals(WSOL);
const q=quote(s,side,amt),userBase=ata(mint,user,btp),userQuote=ata(qm,user,qtp),ixs=[ComputeBudgetProgram.setComputeUnitLimit({units:250000}),ComputeBudgetProgram.setComputeUnitPrice({microLamports:100000})];
const maxIn=Math.floor(q.raw.qin*(1+slip/100)),minOut=Math.floor((q.raw.net??0)*(1-slip/100));
if(s.venue==='curve'){
const bc=PK(s.bondingCurve),wbb=s._g.buyback[Math.floor(Math.random()*8)],bb=isSol?wbb:ata(qm,wbb,qtp);
if(side==='buy')ixs.push(spl.createAssociatedTokenAccountIdempotentInstruction(user,userBase,user,mint,btp));
if(!isSol&&side==='sell')ixs.push(spl.createAssociatedTokenAccountIdempotentInstruction(user,userQuote,user,qm,qtp));
const keys=[meta(GLOBAL),meta(mint),meta(qm),meta(btp),meta(qtp),meta(bc,1),meta(ata(mint,bc,btp),1),meta(ata(qm,bc,qtp),1),meta(user,1,1),meta(userBase,1),meta(userQuote,1),
meta(pda([B('user_volume_accumulator'),user.toBuffer()]),1),meta(FEE_CFG),meta(bb,1),meta(SystemProgram.programId),meta(EV),meta(PUMP)];
const data=side==='buy'?u64s([7,5,29,196,245,23,101,80],Math.floor(q.raw.out),maxIn):u64s([28,146,222,119,38,196,105,213],q.raw.t,minOut);
ixs.push(new TransactionInstruction({programId:PUMP,keys,data}));
}else if(s.venue==='pumpswap'){
const p=s._p,g=await ammGlobal(),bb=ata(qm,g.buyback[Math.floor(Math.random()*8)],qtp);
ixs.push(spl.createAssociatedTokenAccountIdempotentInstruction(user,userBase,user,mint,btp),spl.createAssociatedTokenAccountIdempotentInstruction(user,userQuote,user,qm,qtp));
if(isSol&&side==='buy')ixs.push(SystemProgram.transfer({fromPubkey:user,toPubkey:userQuote,lamports:maxIn}),spl.createSyncNativeInstruction(userQuote));
const keys=[meta(PK(s.pool),1),meta(user,1,1),meta(AMM_GC),meta(mint),meta(qm),meta(userBase,1),meta(userQuote,1),meta(p.baseVault,1),meta(p.quoteVault,1),meta(btp),meta(qtp),meta(SystemProgram.programId),
meta(pda([B('user_volume_accumulator'),user.toBuffer()],AMM),1),meta(AMM_FEE_CFG),meta(bb,1),meta(AMM_EV),meta(AMM)];
const data=side==='buy'?u64s([184,23,238,97,103,197,211,61],Math.floor(q.raw.out),maxIn):u64s([93,246,130,60,231,233,64,178],q.raw.t,minOut);
ixs.push(new TransactionInstruction({programId:AMM,keys,data}));
if(isSol)ixs.push(spl.createCloseAccountInstruction(userQuote,user,user)); // unwrap leftover WSOL
}else throw Error('no tradable venue');
const {blockhash}=await conn.getLatestBlockhash();
const tx=new VersionedTransaction(new TransactionMessage({payerKey:user,recentBlockhash:blockhash,instructions:ixs}).compileToV0Message());
const sim=await conn.simulateTransaction(tx,{sigVerify:false,replaceRecentBlockhash:true}).catch(e=>({value:{err:e.message}}));
return {venue:s.venue,instruction:s.venue==='curve'?side+'_v3':side+'_v2',quote:q,slippagePct:slip,limits:side==='buy'?{maxQuoteIn:maxIn/10**s.quoteDecimals}:{minQuoteOut:minOut/10**s.quoteDecimals},
unsignedTxBase64:Buffer.from(tx.serialize()).toString('base64'),simulation:{err:sim.value.err,logsTail:(sim.value.logs||[]).slice(-3)},note:'UNSIGNED — review and sign in your own wallet. Nothing was sent.'}}
function tape(n=10,filter){return new Promise(res=>{const ws=new WebSocket('wss://clawd-ws.fly.dev/ws'),ev=[];
ws.on('message',m=>{try{const e=JSON.parse(m);if(!filter||e.type===filter){ev.push(e);console.log(JSON.stringify({type:e.type,time:e.time,name:e.name,symbol:e.symbol,mint:e.mint,creator:e.creator,quoteMint:e.quoteMint}))}}catch{}if(ev.length>=n){ws.terminate();res(ev)}});
ws.on('error',e=>{console.error(e.message);res(ev)});setTimeout(()=>{ws.terminate();res(ev)},60000)})}
const pub=s=>Object.fromEntries(Object.entries(s).filter(([k])=>!k.startsWith('_')));
module.exports={getState,quote,build,tape,TIERS,tierFor};
if(require.main===module)(async()=>{const[cmd,a,b,c,d,e]=process.argv.slice(2);let r;
if(cmd==='tape'){await tape(+a||10,b);process.exit(0)}
if(cmd==='tiers')r=TIERS;
else if(!a)r='usage: node pump.js tape [n] [type] | tiers | state <mint> | quote <mint> buy|sell <amt> | build <mint> buy|sell <amt> <wallet> [slip%=8]';
else{const s=await getState(a);
if(cmd==='state')r=pub(s);else if(cmd==='quote'){const q=quote(s,b,+c);r={...pub(s),quote:q,warnings:[...s.warnings,...q.warnings]}}
else if(cmd==='build'){r=await build(s,b,+c,d,+e||8);r.warnings=[...s.warnings,...r.quote.warnings]}}
console.log(JSON.stringify(r,(k,v)=>typeof v==='bigint'?v.toString():v===Infinity?'inf':v,2))})().catch(e=>{console.error('ERROR',e.message);process.exit(1)});
1---2name: pumpfun-swap3description: "Use for any Pump.fun trade, quote or token check (/swap). Resolves a token, reads live bonding-curve or PumpSwap state, quotes with the exact fee tiers and price impact, and builds an UNSIGNED buy or sell (curve buy_v3/sell_v3 or PumpSwap buy_v2/sell_v2; SOL, USDC or pump-coin quoted) for the user t"4metadata:5 source: https://skillmd.com/skills/solizardking/pumpfun-swap6---78# Pump.fun swap (quote + unsigned build)910## Default keyless endpoints11Use `RPC_URL=https://musebook-proxy.mynameisjeffspicoli.workers.dev/api/solana/rpc` unless the owner set their own (fallback public mainnet). Jupiter quote: `GET https://musebook-proxy.mynameisjeffspicoli.workers.dev/api/trade/quote?inputMint=&outputMint=&amount=&slippageBps=`; prices: `GET .../api/trade/jupiter/prices?ids=<mints>`; unsigned build: `.../api/trade/jupiter/build`.1213## Safety rules (always)14- Never sign, send, or broadcast. Never ask for or accept a private key or seed phrase. Output only an unsigned base64 transaction plus a human summary for the user to review and sign in their own wallet.15- Ask for anything missing: token (mint/CA/name), side, size, the user's wallet pubkey (for builds), slippage (default 8%, accept 5–10% unless the user says otherwise).16- Before any build, show: venue (bonding curve or PumpSwap), quote asset (SOL/USDC/pump coin), price, market cap (quote + SOL), graduation %, fee tier, expected out, price impact, min-out / max-in after slippage.17- Warn clearly when: graduation > 90%; price impact > 5% (strong warning > 15%) or pool/curve liquidity is thin; curve real reserves ≈ 0, no tokens left, or anything looks drained/suspicious; mayhem or cashback coin; creator holds or just dumped a large share.18- Simulate the unsigned tx (RPC simulateTransaction with sigVerify=false, replaceRecentBlockhash=true, encoding base64) and report the result. Funding errors (custom 0x1, AccountNotInitialized 3012) just mean the wallet lacks that balance.19- Units: SOL 9 decimals, pump coins 6, USDC 6. Read the token program from the mint account owner on-chain, never from an HTTP API.2021## Steps221. Resolve the token. A mint/CA is used as is. For a name or symbol, search (pump.fun coins API `https://frontend-api-v3.pump.fun/coins/search?searchTerm=<q>` from a server, DexScreener `https://api.dexscreener.com/latest/dex/search?q=<q>`, or any connected token-search tool). Show the candidates and confirm the mint if there's any doubt (copycats are common).232. Make sure the toolkit below exists in a scratch folder (for example `~/pumpbot`). If it's missing, create it: `npm init -y && npm i @solana/web3.js@^1.98 @solana/spl-token ws`, then save the script at the end of this skill as `pump.js`. Set `RPC_URL` if the user has a better RPC (default keyless musebook proxy `/api/solana/rpc`, fallback public mainnet).243. State: `node pump.js state <mint>`. It returns the venue, quote asset, price, market cap (quote and SOL), graduation %, liquidity, fee tier and warnings.254. Quote: `node pump.js quote <mint> buy <quoteAmount>` or `... sell <tokenAmount>`. Present the numbers and every warning.265. Only if the user wants a trade: `node pump.js build <mint> buy|sell <amount> <walletPubkey> [slip%=8]`. Return `unsignedTxBase64`, the min-out/max-in limits and the simulation result. Never sign.276. If the script can't be used, build with the pump.fun agent API instead (below), then simulate and summarize the same way.287. Live launches: `node pump.js tape 10 token-launch` streams new coins from `wss://clawd-ws.fly.dev/ws`. Musebook connector tools (pump_stream_snapshot, live_launches) also work when they're connected.2930## Fee schedule31Bonding curve: 1.25% total (creator 0.30, protocol 0.95).32PumpSwap tiers by market cap (upper bound SOL / USD → creator / total; protocol 0.05 + LP 0.20 on every tier above the first):330–420 SOL (0–85k): creator .30, protocol .93, LP .02 = 1.25 | 1,470 (300k): .95→1.20 | 2,460 (500k): .90→1.15 | 3,440 (700k): .85→1.10 | 4,420 (900k): .80→1.05 | 9,820 (2M): .75→1.00 | 14,740 (3M): .70→.95 | 19,650 (4M): .65→.90 | 24,560 (5M): .60→.85 | 29,470 (6M): .55→.80 | 34,380 (7M): .50→.75 | 39,300 (8M): .45→.70 | 44,210 (9M): .40→.65 | 49,120 (10M): .35→.60 | 54,030 (11M): .30→.55 | 58,940 (12M): .275→.53 | 63,860 (13M): .25→.50 | 68,770 (14M): .225→.48 | 73,681 (15M): .20→.45 | 78,590 (16M): .175→.43 | 83,500 (17M): .15→.40 | 88,400 (18M): .125→.38 | 93,330 (19M): .10→.35 | 98,240 (20M): .075→.33 | above 98,240 SOL (20M+): .05→.30.34On-chain tiers key off SOL market cap; use the USD column for USDC-quoted pools.3536## Building via the pump.fun agent API (no local code needed)37`POST https://fun-block.pump.fun/agents/swap` with JSON `{"inputMint","outputMint","amount","user","slippagePct","encoding":"base64"}`. Buy: inputMint = So11111111111111111111111111111111111111112, amount = lamports. Sell: outputMint = that wSOL mint, amount = token base units (6 decimals). It picks curve vs PumpSwap itself and returns `{transaction, pumpMintInfo}`. Always pass encoding base64. Run it with curl in a shell.3839## Script (pump.js)40```js41#!/usr/bin/env node42// pumpbot v2: read-only state/quotes + UNSIGNED tx building (curve buy_v3/sell_v3, PumpSwap buy_v2/sell_v2).43// SOL, USDC and pump-coin-quoted curves/pools. NEVER signs or sends. No secrets.44const {Connection,PublicKey,TransactionInstruction,TransactionMessage,VersionedTransaction,ComputeBudgetProgram,SystemProgram}=require('@solana/web3.js');45const spl=require('@solana/spl-token');46const WebSocket=require('ws');47const conn=new Connection(process.env.RPC_URL||'https://musebook-proxy.mynameisjeffspicoli.workers.dev/api/solana/rpc','confirmed');48const PK=s=>new PublicKey(s);49const PUMP=PK('6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P'),AMM=PK('pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA'),FEEP=PK('pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ');50const WSOL=PK('So11111111111111111111111111111111111111112'),USDC=PK('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');51const pda=(s,p=PUMP)=>PublicKey.findProgramAddressSync(s,p)[0],B=x=>Buffer.from(x);52const GLOBAL=pda([B('global')]),EV=pda([B('__event_authority')]),FEE_CFG=pda([B('fee_config'),PUMP.toBuffer()],FEEP);53const AMM_GC=pda([B('global_config')],AMM),AMM_EV=pda([B('__event_authority')],AMM),AMM_FEE_CFG=pda([B('fee_config'),AMM.toBuffer()],FEEP);54const ata=(m,o,tp)=>spl.getAssociatedTokenAddressSync(m,o,true,tp);55// Exact PumpSwap tier table: [upper bound SOL mcap, upper bound USD mcap, creator, protocol, lp, total]56const UPS=[420,1470,2460,3440,4420,9820,14740,19650,24560,29470,34380,39300,44210,49120,54030,58940,63860,68770,73681,78590,83500,88400,93330,98240,Infinity];57const UPU=[85e3,3e5,5e5,7e5,9e5,2e6,3e6,4e6,5e6,6e6,7e6,8e6,9e6,1e7,1.1e7,1.2e7,1.3e7,1.4e7,1.5e7,1.6e7,1.7e7,1.8e7,1.9e7,2e7,Infinity];58const CR=[.30,.95,.90,.85,.80,.75,.70,.65,.60,.55,.50,.45,.40,.35,.30,.275,.25,.225,.20,.175,.15,.125,.10,.075,.05];59const TIERS=CR.map((c,i)=>i?{maxSOL:UPS[i],maxUSD:UPU[i],creator:c,protocol:.05,lp:.20,total:+(c+.25).toFixed(3)}:{maxSOL:420,maxUSD:85e3,creator:.30,protocol:.93,lp:.02,total:1.25});60const CURVE_FEE={creator:.30,protocol:.95,lp:0,total:1.25};61const tierFor=(mcap,unit)=>TIERS.find(t=>mcap<(unit==='USD'?t.maxUSD:t.maxSOL));6263class R{constructor(b,o=8){this.b=b;this.o=o}u64(){const v=this.b.readBigUInt64LE(this.o);this.o+=8;return v}i128(){const lo=this.b.readBigUInt64LE(this.o),hi=this.b.readBigInt64LE(this.o+8);this.o+=16;return(hi<<64n)+lo}u16(){const v=this.b.readUInt16LE(this.o);this.o+=2;return v}u8(){return this.b[this.o++]}bool(){return!!this.u8()}pk(){const p=new PublicKey(this.b.subarray(this.o,this.o+32));this.o+=32;return p}skip(n){this.o+=n}}64async function curveGlobal(){const r=new R((await conn.getAccountInfo(GLOBAL)).data),g={};r.bool();r.pk();r.pk();g.initVT=r.u64();g.initVS=r.u64();g.initRealT=r.u64();r.u64();r.u64();r.pk();r.bool();r.u64();r.u64();r.skip(32*7);r.pk();r.pk();r.bool();r.pk();r.pk();r.bool();r.skip(32*7);r.bool();g.buyback=[...Array(8)].map(()=>r.pk());return g}65async function ammGlobal(){const r=new R((await conn.getAccountInfo(AMM_GC)).data),g={};r.pk();r.u64();r.u64();r.u8();r.skip(32*8);r.u64();r.pk();r.pk();r.pk();r.bool();r.skip(32*7);r.bool();g.buyback=[...Array(8)].map(()=>r.pk());return g}66async function mintInfo(m){const a=await conn.getAccountInfo(m);if(!a)throw Error('mint not found '+m.toBase58());return{program:a.owner,decimals:a.data[44],supply:a.data.readBigUInt64LE(36)}}67const quoteLabel=q=>q.equals(WSOL)?'SOL':q.equals(USDC)?'USDC':'PUMPCOIN:'+q.toBase58();68async function solPerQuote(q){ // value of 1 quote unit in SOL (for tier lookup / display)69 if(q.equals(WSOL))return 1;70 try{const j=await(await fetch(`https://lite-api.jup.ag/price/v3?ids=${q.toBase58()},${WSOL.toBase58()}`)).json();return j[q.toBase58()].usdPrice/j[WSOL.toBase58()].usdPrice}catch{return null}}71async function getState(mintStr){72 const mint=PK(mintStr),bc=pda([B('bonding-curve'),mint.toBuffer()]);73 const [a,mi]=await Promise.all([conn.getAccountInfo(bc),mintInfo(mint)]);74 const s={mint:mintStr,baseTokenProgram:mi.program.toBase58(),supply:Number(mi.supply)/10**mi.decimals,warnings:[]};75 let c=null;76 if(a){const r=new R(a.data);c={vT:r.u64(),vQ:r.u64(),rT:r.u64(),rQ:r.u64(),supply:r.u64(),complete:r.bool(),creator:r.pk(),mayhem:r.bool(),cashback:r.bool(),quoteMint:r.pk()};77 if(c.quoteMint.equals(PublicKey.default))c.quoteMint=WSOL;}78 if(c&&!c.complete){79 const g=await curveGlobal(),qi=await mintInfo(c.quoteMint),qd=10**qi.decimals,price=Number(c.vQ)/qd/(Number(c.vT)/10**mi.decimals);80 const grad=Math.max(0,100*(1-Number(c.rT)/Number(g.initRealT)));81 Object.assign(s,{venue:'curve',bondingCurve:bc.toBase58(),quoteMint:c.quoteMint.toBase58(),quoteSymbol:quoteLabel(c.quoteMint),quoteDecimals:qi.decimals,quoteTokenProgram:qi.program.toBase58(),82 creator:c.creator.toBase58(),price,mcap:price*s.supply,graduationPct:grad,realQuoteInCurve:Number(c.rQ)/qd,mayhem:c.mayhem,cashback:c.cashback,fees:CURVE_FEE,_c:c,_g:g});83 const spq=await solPerQuote(c.quoteMint);if(spq)s.mcapSOL=s.mcap*spq;84 if(grad>90)s.warnings.push(`Graduation very close (${grad.toFixed(1)}%) — migration to PumpSwap imminent`);85 if(Number(c.rQ)/qd*(spq||1)<0.05)s.warnings.push('Curve holds ~0 real quote (brand new or drained): thin liquidity, high rug/dump risk');86 if(c.rT===0n)s.warnings.push('Curve has no tokens left (drained/suspicious)');87 if(c.mayhem)s.warnings.push('Mayhem-mode coin (no synthetic migration; different curve params)');88 if(c.cashback)s.warnings.push('Cashback coin (deprecated mode; creator fee routes to buyer)');89 return s}90 // graduated / non-curve → canonical PumpSwap pool. Try SOL then USDC then curve quote.91 const auth=pda([B('pool-authority'),mint.toBuffer()]),idx=Buffer.alloc(2);92 const qs=[...(c?[c.quoteMint]:[]),WSOL,USDC];let pool,pa;93 for(const q of qs){pool=pda([B('pool'),idx,auth.toBuffer(),mint.toBuffer(),q.toBuffer()],AMM);pa=await conn.getAccountInfo(pool);if(pa)break}94 if(!pa){s.venue='none';s.warnings.push(c?'Curve complete but canonical pool not found yet (migrating?) — retry shortly':'Not a pump.fun coin (no curve/pool); use an aggregator');return s}95 const r=new R(pa.data);const p={bump:r.u8(),index:r.u16(),creator:r.pk(),baseMint:r.pk(),quoteMint:r.pk(),lpMint:r.pk(),baseVault:r.pk(),quoteVault:r.pk(),lpSupply:r.u64(),coinCreator:r.pk(),mayhem:r.bool(),cashback:r.bool(),vQuote:r.i128()};96 const [bv,qv,qi]=await Promise.all([conn.getTokenAccountBalance(p.baseVault),conn.getTokenAccountBalance(p.quoteVault),mintInfo(p.quoteMint)]);97 const baseR=BigInt(bv.value.amount),quoteR=BigInt(qv.value.amount)+p.vQuote,qd=10**qi.decimals;98 const price=Number(quoteR)/qd/(Number(baseR)/10**mi.decimals),mcap=price*s.supply,spq=await solPerQuote(p.quoteMint),mcapSOL=spq?mcap*spq:null;99 const tier=p.quoteMint.equals(USDC)?tierFor(mcap,'USD'):tierFor(mcapSOL??mcap,'SOL');100 Object.assign(s,{venue:'pumpswap',pool:pool.toBase58(),quoteMint:p.quoteMint.toBase58(),quoteSymbol:quoteLabel(p.quoteMint),quoteDecimals:qi.decimals,quoteTokenProgram:qi.program.toBase58(),101 coinCreator:p.coinCreator.toBase58(),price,mcap,mcapSOL,graduationPct:100,poolQuoteLiquidity:Number(quoteR)/qd,mayhem:p.mayhem,cashback:p.cashback,fees:tier,_p:{...p,baseR,quoteR}});102 if(p.quoteMint.equals(WSOL)&&Number(quoteR)/qd<20)s.warnings.push(`Thin pool: only ${(Number(quoteR)/qd).toFixed(2)} ${s.quoteSymbol} of quote liquidity`);103 if(p.cashback)s.warnings.push('Cashback pool: v2 trades unsupported (CashbackCoinNotSupported); use v1 / aggregator');104 return s}105// amt: quote units (SOL/USDC/coin) for buy, base tokens for sell106function quote(s,side,amt){107 const fee=s.fees.total/100,bd=1e6,qd=10**s.quoteDecimals;let baseR,quoteR,cap=Infinity;108 if(s.venue==='curve'){baseR=Number(s._c.vT);quoteR=Number(s._c.vQ);cap=Number(s._c.rT)}else if(s.venue==='pumpswap'){baseR=Number(s._p.baseR);quoteR=Number(s._p.quoteR)}else throw Error('no venue');109 const spot=quoteR/baseR;let q;110 if(side==='buy'){const qin=amt*qd,net=qin/(1+fee);let out=Math.min(baseR*net/(quoteR+net),cap);if(s.venue==='pumpswap')out=Math.min(out,baseR-1);111 q={side,in:amt,inUnit:s.quoteSymbol,fee:(qin-net)/qd,tokensOut:out/bd,avgPrice:(net/out)*bd/qd,impactPct:100*((net/out)/spot-1),raw:{out:Math.floor(out),qin:Math.floor(qin)}}}112 else{const t=amt*bd,gross=quoteR*t/(baseR+t),net=gross*(1-fee);q={side,inTokens:amt,outGross:gross/qd,fee:(gross-net)/qd,out:net/qd,outUnit:s.quoteSymbol,impactPct:100*(1-(gross/t)/spot),raw:{t:Math.floor(t),net:Math.floor(net)}}}113 q.feeTierPct=s.fees;q.warnings=q.impactPct>15?[`HIGH price impact ${q.impactPct.toFixed(1)}%`]:q.impactPct>5?[`Notable price impact ${q.impactPct.toFixed(1)}%`]:[];114 if(s.venue==='curve'&&side==='buy'&&q.raw.out>=cap)q.warnings.push('Buy exceeds tokens left on curve: rest goes through synthetic migration / may fail on mayhem coins');115 return q}116const meta=(pubkey,w,sg)=>({pubkey,isWritable:!!w,isSigner:!!sg});117const u64s=(disc,a,b)=>{const d=Buffer.alloc(24);B(disc).copy(d);d.writeBigUInt64LE(BigInt(a),8);d.writeBigUInt64LE(BigInt(b),16);return d};118async function build(s,side,amt,walletStr,slip=8){119 if(!(amt>0))throw Error('amount must be > 0');if(slip<0||slip>50)throw Error('slippage % out of range');120 const user=PK(walletStr),mint=PK(s.mint),btp=PK(s.baseTokenProgram),qm=PK(s.quoteMint),qtp=PK(s.quoteTokenProgram),isSol=qm.equals(WSOL);121 const q=quote(s,side,amt),userBase=ata(mint,user,btp),userQuote=ata(qm,user,qtp),ixs=[ComputeBudgetProgram.setComputeUnitLimit({units:250000}),ComputeBudgetProgram.setComputeUnitPrice({microLamports:100000})];122 const maxIn=Math.floor(q.raw.qin*(1+slip/100)),minOut=Math.floor((q.raw.net??0)*(1-slip/100));123 if(s.venue==='curve'){124 const bc=PK(s.bondingCurve),wbb=s._g.buyback[Math.floor(Math.random()*8)],bb=isSol?wbb:ata(qm,wbb,qtp);125 if(side==='buy')ixs.push(spl.createAssociatedTokenAccountIdempotentInstruction(user,userBase,user,mint,btp));126 if(!isSol&&side==='sell')ixs.push(spl.createAssociatedTokenAccountIdempotentInstruction(user,userQuote,user,qm,qtp));127 const keys=[meta(GLOBAL),meta(mint),meta(qm),meta(btp),meta(qtp),meta(bc,1),meta(ata(mint,bc,btp),1),meta(ata(qm,bc,qtp),1),meta(user,1,1),meta(userBase,1),meta(userQuote,1),128 meta(pda([B('user_volume_accumulator'),user.toBuffer()]),1),meta(FEE_CFG),meta(bb,1),meta(SystemProgram.programId),meta(EV),meta(PUMP)];129 const data=side==='buy'?u64s([7,5,29,196,245,23,101,80],Math.floor(q.raw.out),maxIn):u64s([28,146,222,119,38,196,105,213],q.raw.t,minOut);130 ixs.push(new TransactionInstruction({programId:PUMP,keys,data}));131 }else if(s.venue==='pumpswap'){132 const p=s._p,g=await ammGlobal(),bb=ata(qm,g.buyback[Math.floor(Math.random()*8)],qtp);133 ixs.push(spl.createAssociatedTokenAccountIdempotentInstruction(user,userBase,user,mint,btp),spl.createAssociatedTokenAccountIdempotentInstruction(user,userQuote,user,qm,qtp));134 if(isSol&&side==='buy')ixs.push(SystemProgram.transfer({fromPubkey:user,toPubkey:userQuote,lamports:maxIn}),spl.createSyncNativeInstruction(userQuote));135 const keys=[meta(PK(s.pool),1),meta(user,1,1),meta(AMM_GC),meta(mint),meta(qm),meta(userBase,1),meta(userQuote,1),meta(p.baseVault,1),meta(p.quoteVault,1),meta(btp),meta(qtp),meta(SystemProgram.programId),136 meta(pda([B('user_volume_accumulator'),user.toBuffer()],AMM),1),meta(AMM_FEE_CFG),meta(bb,1),meta(AMM_EV),meta(AMM)];137 const data=side==='buy'?u64s([184,23,238,97,103,197,211,61],Math.floor(q.raw.out),maxIn):u64s([93,246,130,60,231,233,64,178],q.raw.t,minOut);138 ixs.push(new TransactionInstruction({programId:AMM,keys,data}));139 if(isSol)ixs.push(spl.createCloseAccountInstruction(userQuote,user,user)); // unwrap leftover WSOL140 }else throw Error('no tradable venue');141 const {blockhash}=await conn.getLatestBlockhash();142 const tx=new VersionedTransaction(new TransactionMessage({payerKey:user,recentBlockhash:blockhash,instructions:ixs}).compileToV0Message());143 const sim=await conn.simulateTransaction(tx,{sigVerify:false,replaceRecentBlockhash:true}).catch(e=>({value:{err:e.message}}));144 return {venue:s.venue,instruction:s.venue==='curve'?side+'_v3':side+'_v2',quote:q,slippagePct:slip,limits:side==='buy'?{maxQuoteIn:maxIn/10**s.quoteDecimals}:{minQuoteOut:minOut/10**s.quoteDecimals},145 unsignedTxBase64:Buffer.from(tx.serialize()).toString('base64'),simulation:{err:sim.value.err,logsTail:(sim.value.logs||[]).slice(-3)},note:'UNSIGNED — review and sign in your own wallet. Nothing was sent.'}}146function tape(n=10,filter){return new Promise(res=>{const ws=new WebSocket('wss://clawd-ws.fly.dev/ws'),ev=[];147 ws.on('message',m=>{try{const e=JSON.parse(m);if(!filter||e.type===filter){ev.push(e);console.log(JSON.stringify({type:e.type,time:e.time,name:e.name,symbol:e.symbol,mint:e.mint,creator:e.creator,quoteMint:e.quoteMint}))}}catch{}if(ev.length>=n){ws.terminate();res(ev)}});148 ws.on('error',e=>{console.error(e.message);res(ev)});setTimeout(()=>{ws.terminate();res(ev)},60000)})}149const pub=s=>Object.fromEntries(Object.entries(s).filter(([k])=>!k.startsWith('_')));150module.exports={getState,quote,build,tape,TIERS,tierFor};151if(require.main===module)(async()=>{const[cmd,a,b,c,d,e]=process.argv.slice(2);let r;152 if(cmd==='tape'){await tape(+a||10,b);process.exit(0)}153 if(cmd==='tiers')r=TIERS;154 else if(!a)r='usage: node pump.js tape [n] [type] | tiers | state <mint> | quote <mint> buy|sell <amt> | build <mint> buy|sell <amt> <wallet> [slip%=8]';155 else{const s=await getState(a);156 if(cmd==='state')r=pub(s);else if(cmd==='quote'){const q=quote(s,b,+c);r={...pub(s),quote:q,warnings:[...s.warnings,...q.warnings]}}157 else if(cmd==='build'){r=await build(s,b,+c,d,+e||8);r.warnings=[...s.warnings,...r.quote.warnings]}}158 console.log(JSON.stringify(r,(k,v)=>typeof v==='bigint'?v.toString():v===Infinity?'inf':v,2))})().catch(e=>{console.error('ERROR',e.message);process.exit(1)});159```