> ## Documentation Index
> Fetch the complete documentation index at: https://docs.solanatracker.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Pump.fun 程序 ID、IDL 与买卖指令

> Pump.fun 联合曲线程序 ID 为 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P，附 Anchor IDL、鉴别器和 web3.js 买卖代码。

Pump.fun 联合曲线的程序 ID 是 `6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P`。构建或解码其指令时可以参考本文，内容包括账户、鉴别器和买入/卖出布局。毕业后的交易请参考 PumpSwap 程序文档。

> [!NOTE]
>
> 不想手动构建指令？[Raptor Swap API](https://docs.solanatracker.io/cn/raptor/overview.md) 会自动在 Pump.fun 联合曲线和 PumpSwap 之间路由买单和卖单。

## 官方程序 ID

| 程序 | 地址 | 作用 |
| - | - | - |
| **Pump.fun（联合曲线）** | `6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P` | 创建代币、在曲线上买卖、迁移 |
| **Pump.fun AMM（PumpSwap）** | `pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA` | 毕业后的恒定乘积池 |
| **Pump Fees** | `pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ` | 买入/卖出使用的费用配置 |

请准确复制程序 ID。Base58 地址区分大小写，`6EF8` 后面的 `r` 是小写。

### 常见 PDA

| 账户 | 种子 | 地址 |
| - | - | - |
| `global` | `["global"]` | `4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf` |
| `event_authority` | `["__event_authority"]` | Pump 程序的 PDA |
| `bonding_curve` | `["bonding-curve", mint]` | 每个代币各自的曲线账户 |

Solana Tracker 市场筛选值：`pumpfun`（联合曲线）、`pumpfun-amm`（已毕业 / PumpSwap）。

## Anchor IDL

下载官方 Anchor IDL（镜像自 [pump-fun/pump-public-docs](https://github.com/pump-fun/pump-public-docs)）：

* **JSON IDL：** [/idl/pump.json](https://docs.solanatracker.io/idl/pump.json)
* 上游：[idl/pump.json](https://github.com/pump-fun/pump-public-docs/blob/main/idl/pump.json)

```javascript theme={null}
import idl from "./idl/pump.json" assert { type: "json" };
// or: const idl = require("./idl/pump.json");

console.log(idl.address);
// 6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P
```

用 Anchor 的 `Program` 或 `BorshInstructionCoder` 加载 IDL，解析原始指令时也可以直接使用下面的鉴别器。

## 指令鉴别器

Anchor 鉴别器是 `sha256("global:<instruction_name>")` 的前 **8 个字节**。解析交易或手动构建指令时需要匹配这些值。

| 指令 | 鉴别器（字节） | Hex |
| - | - | - |
| `buy` | `[102, 6, 61, 18, 1, 218, 235, 234]` | `0x66063d1201daebea` |
| `sell` | `[51, 230, 133, 164, 1, 127, 131, 173]` | `0x33e685a4017f83ad` |
| `create` | `[24, 30, 200, 40, 5, 28, 7, 119]` | `0x181ec828051c0777` |
| `create_v2` | `[214, 144, 76, 236, 95, 139, 49, 180]` | `0xd6904cec5f8b31b4` |
| `buy_exact_sol_in` | `[56, 252, 116, 8, 158, 223, 205, 95]` | `0x38fc74089edfcd5f` |
| `buy_v2` | `[184, 23, 238, 97, 103, 197, 211, 61]` | `0xb817ee6167c5d33d` |
| `sell_v2` | `[93, 246, 130, 60, 231, 233, 64, 178]` | `0x5df6823ce7e940b2` |
| `migrate` | `[155, 234, 231, 146, 236, 158, 162, 30]` | `0x9beae792ec9ea21e` |

**AMM** 上的 `buy` / `sell` 复用相同的 sighash，分类交易时务必检查**程序 ID**（`6EF8rrecth…` 和 `pAMMBay…`）。

主网上很多曲线兑换使用 `buy_exact_sol_in`（`0x38fc74089edfcd5f`），而不是经典的 `buy`。解析器应同时处理这两种指令。

### 在 Rust 中判断买入或卖出

```rust theme={null}
const BUY: [u8; 8] = [102, 6, 61, 18, 1, 218, 235, 234];
const SELL: [u8; 8] = [51, 230, 133, 164, 1, 127, 131, 173];
const CREATE: [u8; 8] = [24, 30, 200, 40, 5, 28, 7, 119];

fn classify(data: &[u8]) -> Option<&'static str> {
    let disc = data.get(..8)?;
    if disc == BUY { Some("buy") }
    else if disc == SELL { Some("sell") }
    else if disc == CREATE { Some("create") }
    else { None }
}
```

## `buy` 指令

**参数**

| 参数 | 类型 | 含义 |
| - | - | - |
| `amount` | `u64` | 输出代币数量（基础单位） |
| `max_sol_cost` | `u64` | 滑点上限，单位为 lamports |
| `track_volume` | `OptionBool` | `{ 0 }` = false，`{ 1 }` = true |

**账户**

| # | 账户 | 可写 | 签名者 |
| - | - | - | - |
| 0 | `global` | | |
| 1 | `fee_recipient` | ✓ | |
| 2 | `mint` | | |
| 3 | `bonding_curve` | ✓ | |
| 4 | `associated_bonding_curve` | ✓ | |
| 5 | `associated_user` | ✓ | |
| 6 | `user` | ✓ | ✓ |
| 7 | `system_program` | | |
| 8 | `token_program` | | |
| 9 | `creator_vault` | ✓ | |
| 10 | `event_authority` | | |
| 11 | `program` | | |
| 12 | `global_volume_accumulator` | | |
| 13 | `user_volume_accumulator` | ✓ | |
| 14 | `fee_config` | | |
| 15 | `fee_program` | | |

从 `global` 账户读取 `fee_recipient`（以及 `fee_recipients` 数组）。`fee_program` 传 `pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ`。

## `sell` 指令

**参数**

| 参数 | 类型 | 含义 |
| - | - | - |
| `amount` | `u64` | 输入代币数量（基础单位） |
| `min_sol_output` | `u64` | 滑点下限，单位为 lamports |

**账户**

| # | 账户 | 可写 | 签名者 |
| - | - | - | - |
| 0 | `global` | | |
| 1 | `fee_recipient` | ✓ | |
| 2 | `mint` | | |
| 3 | `bonding_curve` | ✓ | |
| 4 | `associated_bonding_curve` | ✓ | |
| 5 | `associated_user` | ✓ | |
| 6 | `user` | ✓ | ✓ |
| 7 | `system_program` | | |
| 8 | `creator_vault` | ✓ | |
| 9 | `token_program` | | |
| 10 | `event_authority` | | |
| 11 | `program` | | |
| 12 | `fee_config` | | |
| 13 | `fee_program` | | |

## `create` 指令

**参数：** `name: string`、`symbol: string`、`uri: string`、`creator: pubkey`\
**鉴别器：** `[24, 30, 200, 40, 5, 28, 7, 119]`

较新的发行通常使用 `create_v2`（Token-2022 / Mayhem / cashback 字段）。集成创建流程时，优先对照实际交易或 IDL。

## 使用 `@solana/web3.js` 买入和卖出

先编码 Anchor 鉴别器，再按小端序编码 `u64` 参数。`OptionBool` 占一个字节（`0` 或 `1`）。

```javascript theme={null}
import {
  PublicKey,
  TransactionInstruction,
  SystemProgram,
} from "@solana/web3.js";
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from "@solana/spl-token";
import bs58 from "bs58";

export const PUMP_PROGRAM_ID = new PublicKey(
  "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"
);
export const PUMP_FEE_PROGRAM_ID = new PublicKey(
  "pfeeUxB6jkeY1Hxd7CsFCAjcbHA9rWtchMGdZ6VojVZ"
);
export const GLOBAL = new PublicKey(
  "4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf"
);

const BUY_DISC = Buffer.from([102, 6, 61, 18, 1, 218, 235, 234]);
const SELL_DISC = Buffer.from([51, 230, 133, 164, 1, 127, 131, 173]);

function u64le(n) {
  const b = Buffer.alloc(8);
  b.writeBigUInt64LE(BigInt(n));
  return b;
}

export function bondingCurvePda(mint) {
  return PublicKey.findProgramAddressSync(
    [Buffer.from("bonding-curve"), mint.toBuffer()],
    PUMP_PROGRAM_ID
  )[0];
}

export function eventAuthorityPda() {
  return PublicKey.findProgramAddressSync(
    [Buffer.from("__event_authority")],
    PUMP_PROGRAM_ID
  )[0];
}

export function creatorVaultPda(creator) {
  return PublicKey.findProgramAddressSync(
    [Buffer.from("creator-vault"), creator.toBuffer()],
    PUMP_PROGRAM_ID
  )[0];
}

export function feeConfigPda() {
  // seeds: ["fee_config", pump_program_id] on the fee program
  return PublicKey.findProgramAddressSync(
    [Buffer.from("fee_config"), PUMP_PROGRAM_ID.toBuffer()],
    PUMP_FEE_PROGRAM_ID
  )[0];
}

/** Build a Pump.fun bonding-curve buy instruction */
export function buildBuyIx({
  mint,
  user,
  feeRecipient,
  creator, // bonding_curve.creator
  amount, // tokens out
  maxSolCost, // lamports
  trackVolume = false,
}) {
  const bondingCurve = bondingCurvePda(mint);
  const associatedBondingCurve = getAssociatedTokenAddressSync(
    mint,
    bondingCurve,
    true
  );
  const associatedUser = getAssociatedTokenAddressSync(mint, user);
  const [globalVolume] = PublicKey.findProgramAddressSync(
    [Buffer.from("global_volume_accumulator")],
    PUMP_PROGRAM_ID
  );
  const [userVolume] = PublicKey.findProgramAddressSync(
    [Buffer.from("user_volume_accumulator"), user.toBuffer()],
    PUMP_PROGRAM_ID
  );

  const data = Buffer.concat([
    BUY_DISC,
    u64le(amount),
    u64le(maxSolCost),
    Buffer.from([trackVolume ? 1 : 0]),
  ]);

  return new TransactionInstruction({
    programId: PUMP_PROGRAM_ID,
    keys: [
      { pubkey: GLOBAL, isSigner: false, isWritable: false },
      { pubkey: feeRecipient, isSigner: false, isWritable: true },
      { pubkey: mint, isSigner: false, isWritable: false },
      { pubkey: bondingCurve, isSigner: false, isWritable: true },
      { pubkey: associatedBondingCurve, isSigner: false, isWritable: true },
      { pubkey: associatedUser, isSigner: false, isWritable: true },
      { pubkey: user, isSigner: true, isWritable: true },
      { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
      { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: creatorVaultPda(creator), isSigner: false, isWritable: true },
      { pubkey: eventAuthorityPda(), isSigner: false, isWritable: false },
      { pubkey: PUMP_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: globalVolume, isSigner: false, isWritable: false },
      { pubkey: userVolume, isSigner: false, isWritable: true },
      { pubkey: feeConfigPda(), isSigner: false, isWritable: false },
      { pubkey: PUMP_FEE_PROGRAM_ID, isSigner: false, isWritable: false },
    ],
    data,
  });
}

/** Build a Pump.fun bonding-curve sell instruction */
export function buildSellIx({
  mint,
  user,
  feeRecipient,
  creator,
  amount,
  minSolOutput,
}) {
  const bondingCurve = bondingCurvePda(mint);
  const associatedBondingCurve = getAssociatedTokenAddressSync(
    mint,
    bondingCurve,
    true
  );
  const associatedUser = getAssociatedTokenAddressSync(mint, user);

  const data = Buffer.concat([SELL_DISC, u64le(amount), u64le(minSolOutput)]);

  return new TransactionInstruction({
    programId: PUMP_PROGRAM_ID,
    keys: [
      { pubkey: GLOBAL, isSigner: false, isWritable: false },
      { pubkey: feeRecipient, isSigner: false, isWritable: true },
      { pubkey: mint, isSigner: false, isWritable: false },
      { pubkey: bondingCurve, isSigner: false, isWritable: true },
      { pubkey: associatedBondingCurve, isSigner: false, isWritable: true },
      { pubkey: associatedUser, isSigner: false, isWritable: true },
      { pubkey: user, isSigner: true, isWritable: true },
      { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
      { pubkey: creatorVaultPda(creator), isSigner: false, isWritable: true },
      { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: eventAuthorityPda(), isSigner: false, isWritable: false },
      { pubkey: PUMP_PROGRAM_ID, isSigner: false, isWritable: false },
      { pubkey: feeConfigPda(), isSigner: false, isWritable: false },
      { pubkey: PUMP_FEE_PROGRAM_ID, isSigner: false, isWritable: false },
    ],
    data,
  });
}

// Identify buy/sell from a confirmed transaction
export function parsePumpInstructionData(dataBase58) {
  const data = Buffer.from(bs58.decode(dataBase58));
  const disc = data.subarray(0, 8);
  if (disc.equals(BUY_DISC)) {
    return {
      name: "buy",
      amount: data.readBigUInt64LE(8),
      maxSolCost: data.readBigUInt64LE(16),
    };
  }
  if (disc.equals(SELL_DISC)) {
    return {
      name: "sell",
      amount: data.readBigUInt64LE(8),
      minSolOutput: data.readBigUInt64LE(16),
    };
  }
  return null;
}
```

> [!WARNING]
>
> 主网上的实际指令常在 IDL 账户列表后追加**剩余账户**（`buy` / `buy_exact_sol_in` / `sell` 通常多 2 个，用于 cashback 或 bonding-curve-v2 流程）。Token-2022 mint 使用 `TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb`，而不是旧版 Token 程序。上线前务必对照近期成功的交易和最新的 [/idl/pump.json](https://docs.solanatracker.io/idl/pump.json)。Token-2022 或多计价代币流程优先使用 IDL 中的 `buy_v2` / `sell_v2`。

### 更简单的方式：Raptor 兑换 API

```javascript theme={null}
const res = await fetch("https://swap-v2.solanatracker.io/swap", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    wallet: "YOUR_WALLET_ADDRESS",
    from: "So11111111111111111111111111111111111111112",
    to: "TOKEN_MINT_ADDRESS",
    amount: 0.1,
    slippage: 15,
    priorityFee: 0.0005,
  }),
});
const { txn } = await res.json();
// Sign and send txn
```

参见 [Swap API](https://docs.solanatracker.io/cn/guides/swap-api.md) 和 [Raptor 概览](https://docs.solanatracker.io/cn/raptor/overview.md)。

## 用 Solana Tracker 订阅和索引数据

根据需要的数据层级选择接口：

| 产品 | 用途 |
| - | - |
| [Pump.fun API](https://www.solanatracker.io/pumpfun-api) | 已索引的发行、曲线、交易、持有者 |
| [Data API](https://www.solanatracker.io/data-api) | REST：`/tokens/latest`、`/search?launchpad=pumpfun`、毕业中/已毕业 |
| [Datastream](https://www.solanatracker.io/data-api) | WebSocket 房间：`latest`、`graduating:pumpfun:50`、`pumpfun:curve:50` |
| [Memescope](https://www.solanatracker.io/memescope) | 实时展示发行、冲刺和已迁移阶段的界面 |
| [Raptor](https://www.solanatracker.io/raptor) | 在曲线和 AMM 上路由买卖 |
| [Yellowstone gRPC](https://www.solanatracker.io/yellowstone-grpc) | 原始程序交易和账户流 |
| [Solana RPC](https://www.solanatracker.io/solana-rpc) | 针对这些程序 ID 调用 `getTransaction` / `getProgramAccounts` |

文档：

* [Pump.fun 与联合曲线](https://docs.solanatracker.io/cn/guides/pumpfun.md)：结合 Data API 和 Datastream 的完整生命周期
* [gRPC 买卖检测](https://docs.solanatracker.io/cn/yellowstone-grpc/examples/pumpfun-transactions.md)：用 IDL 解码
* [gRPC 账户流](https://docs.solanatracker.io/cn/yellowstone-grpc/examples/pumpfun-accounts.md)：联合曲线状态
* [Pump.fun AMM 程序](https://docs.solanatracker.io/cn/guides/pumpfun-amm.md)：PumpSwap 的 `buy` / `sell`

> [card] [PumpSwap 程序](https://docs.solanatracker.io/cn/guides/pumpfun-amm.md)
>
> PumpSwap 程序 ID、IDL 和买入/卖出鉴别器。

> [card] [发行与毕业](https://docs.solanatracker.io/cn/guides/pumpfun.md)
>
> 通过 Solana Tracker 发现代币、追踪曲线和毕业，并完成兑换。

> [card] [Yellowstone 买卖检测](https://docs.solanatracker.io/cn/yellowstone-grpc/examples/pumpfun-transactions.md)
>
> 通过 gRPC 实时解析指令。

> [card] [Raptor Swap](https://docs.solanatracker.io/cn/raptor/overview.md)
>
> 无需构建指令即可执行 Pump.fun 和 PumpSwap 兑换。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.