stream.mts。以下示例使用相同的环境变量与依赖。
安装解码器与 IDL
解码更新
pump-accounts.mts
读取储备并保留精度
示例将原始储备整数输出为字符串。显示金额需要代币与报价 mint 的精度。原始储备比率不是 SOL/代币价格,quote_mint 也不一定为 SOL。格式化价格前先查询 mint 数据。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
订阅 Pump.fun bonding curve 账户,用配套 Anchor IDL 解码,并保留原始储备金额。
stream.mts。以下示例使用相同的环境变量与依赖。
npm install @coral-xyz/anchor @solana/web3.js
curl -L https://docs.solanatracker.io/idl/pump.json -o pump.json
import { readFileSync } from "node:fs";
import { BorshAccountsCoder, type Idl } from "@coral-xyz/anchor";
import bs58 from "bs58";
import { subscribe } from "./stream.mts";
const idl = JSON.parse(readFileSync("pump.json", "utf8")) as Idl;
const coder = new BorshAccountsCoder(idl);
const definition = idl.accounts?.find(account => account.name === "BondingCurve");
if (!definition) throw new Error("BondingCurve is missing from the IDL");
const discriminator = Buffer.from(definition.discriminator);
for await (const update of subscribe({
accounts: {
curves: {
account: [], owner: [idl.address],
filters: [{ memcmp: { offset: "0", bytes: discriminator } }],
},
},
})) {
const account = update.account?.account;
if (!account) continue;
try {
const curve = coder.decode("BondingCurve", Buffer.from(account.data));
console.log({
address: bs58.encode(account.pubkey),
slot: update.account!.slot,
complete: curve.complete,
quoteMint: curve.quote_mint.toString(),
virtualTokenReserves: curve.virtual_token_reserves.toString(),
virtualQuoteReserves: curve.virtual_quote_reserves.toString(),
});
} catch (error) {
console.error("Bonding curve decode failed; check IDL compatibility", error);
}
}
npx tsx pump-accounts.mts
quote_mint 也不一定为 SOL。格式化价格前先查询 mint 数据。
此页面对您有帮助吗?