Zum Hauptinhalt springen

Documentation Index

Fetch the complete documentation index at: https://docs.raydium.io/llms.txt

Use this file to discover all available pages before exploring further.

Diese Seite wurde mit KI automatisch übersetzt. Maßgeblich ist stets die englische Version.Englische Version ansehen →
Was dies tut. Erstellt einen brandneuen CPMM-Pool für zwei von Ihnen angegebene Mints, wählt die Gebührenstaffeln von 0,25 % aus, seedet die anfängliche Liquidität zum durch die Seed-Beträge implizierten Preis und gibt die neue Pool-ID und die Transaktionssignatur aus.

Setup

Stellen Sie sicher, dass Sie die Quick-Start-Voraussetzungen gelesen haben und RPC_URL, KEYPAIR und die Abhängigkeiten installiert haben. Sie müssen auch das Wallet mit den Seed-Beträgen beider Mints finanzieren, zuzüglich ausreichend SOL, um die einmalige Pool-Erstellungsgebühr zu decken (~0,15 SOL im Mainnet, siehe reference/program-addresses für den aktuellen Wert).

Das Skript

Speichern Sie es als create-cpmm.mjs:
// create-cpmm.mjs
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
import {
  Raydium,
  TxVersion,
  CREATE_CPMM_POOL_PROGRAM,
  CREATE_CPMM_POOL_FEE_ACC,
} from "@raydium-io/raydium-sdk-v2";
import BN from "bn.js";
import fs from "node:fs";

// ── Config from env ──────────────────────────────────────────────
const RPC_URL  = process.env.RPC_URL  ?? "https://api.mainnet-beta.solana.com";
const KEYPAIR  = process.env.KEYPAIR  ?? `${process.env.HOME}/.config/solana/id.json`;
const MINT_A   = process.env.MINT_A;   // required, base58
const MINT_B   = process.env.MINT_B;   // required, base58
const AMOUNT_A = process.env.AMOUNT_A; // required, integer raw units
const AMOUNT_B = process.env.AMOUNT_B; // required, integer raw units

if (!MINT_A || !MINT_B || !AMOUNT_A || !AMOUNT_B) {
  console.error("Set MINT_A, MINT_B, AMOUNT_A, AMOUNT_B env vars.");
  process.exit(1);
}

// ── Setup ────────────────────────────────────────────────────────
const connection = new Connection(RPC_URL, "confirmed");
const owner = Keypair.fromSecretKey(
  new Uint8Array(JSON.parse(fs.readFileSync(KEYPAIR, "utf8"))),
);
const raydium = await Raydium.load({
  owner,
  connection,
  cluster: "mainnet",
  disableFeatureCheck: true,
  blockhashCommitment: "finalized",
});

// ── Pick the 0.25% fee tier ─────────────────────────────────────
const feeConfigs = await raydium.api.getCpmmConfigs();
const feeConfig  = feeConfigs.find((c) => c.index === 0);
if (!feeConfig) throw new Error("0.25% fee tier not found in CPMM configs.");

// ── Resolve mint metadata (Token-2022-aware) ────────────────────
const mintA = await raydium.token.getTokenInfo(new PublicKey(MINT_A));
const mintB = await raydium.token.getTokenInfo(new PublicKey(MINT_B));

// ── Build and execute ───────────────────────────────────────────
const { execute, extInfo } = await raydium.cpmm.createPool({
  programId:       CREATE_CPMM_POOL_PROGRAM,
  poolFeeAccount:  CREATE_CPMM_POOL_FEE_ACC,
  mintA,
  mintB,
  mintAAmount:     new BN(AMOUNT_A),
  mintBAmount:     new BN(AMOUNT_B),
  startTime:       new BN(0), // open immediately
  feeConfig,
  associatedOnly:  false,
  ownerInfo:       { useSOLBalance: true },
  txVersion:       TxVersion.V0,
  computeBudgetConfig: {
    units: 600_000,
    microLamports: 100_000,
  },
});

const { txId } = await execute({ sendAndConfirm: true });

console.log(`Pool ID:  ${extInfo.address.poolId.toBase58()}`);
console.log(`LP mint:  ${extInfo.address.lpMint.toBase58()}`);
console.log(`Vault A:  ${extInfo.address.vaultA.toBase58()}`);
console.log(`Vault B:  ${extInfo.address.vaultB.toBase58()}`);
console.log(`Tx:       https://solscan.io/tx/${txId}`);

Führen Sie es aus

Beispiel: Erstellen Sie einen SOL/USDC-Pool mit 1 SOL und 160 USDC Seed:
export MINT_A="So11111111111111111111111111111111111111112"   # wSOL
export MINT_B="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"   # USDC
export AMOUNT_A="1000000000"   # 1 SOL (9 decimals)
export AMOUNT_B="160000000"    # 160 USDC (6 decimals)

node create-cpmm.mjs
Erwartete Ausgabe:
Pool ID:  HgC5...3kXb
LP mint:  4ZAS...9rkV
Vault A:  J9Mu...mP2k
Vault B:  AaJq...8wxx
Tx:       https://solscan.io/tx/5dQ...

Was gerade passiert ist

  1. getCpmmConfigs hat die aktuelle Liste der Gebührenstaffeln von api-v3.raydium.io abgerufen und Index 0 (die 0,25%-Staffel – siehe reference/fee-comparison für den vollständigen Satz) ausgewählt.
  2. getTokenInfo hat die Metadaten jedes Mints aufgelöst, einschließlich des Tokenprogramms, das es besitzt. CPMM akzeptiert sowohl SPL Token als auch Token-2022 Mints; das SDK routed automatisch.
  3. createPool hat eine Transaktion erstellt, die:
    • die Mints in kanonische Reihenfolge sortiert,
    • die Pool-PDA, Vaults, LP-Mint und Autorität ableitet,
    • die einmalige create_pool_fee an CREATE_CPMM_POOL_FEE_ACC zahlt,
    • die ATAs des Aufrufers erstellt, falls sie fehlen,
    • die Vaults mit AMOUNT_A und AMOUNT_B seedet.
  4. Der initiale Preis wird durch das Seed-Verhältnis festgelegt: price = AMOUNT_B / AMOUNT_A nach Dezimalanpassung. Wählen Sie dies sorgfältig aus – Bots werden jeden Preisfehler innerhalb von Sekunden nach dem Öffnen des Pools arbitragieren.
  5. startTime: new BN(0) öffnet den Handel sofort. Um Liquidität vor der Öffnung für die Öffentlichkeit zu stage, setzen Sie einen zukünftigen Unix-Timestamp.

Häufige Fehler

  • pool already exists — Für dieses Mintpaar mit dieser Gebührenstaffeln existiert bereits ein Pool. Suchen Sie ihn auf, bevor Sie ihn erstellen.
  • insufficient funds — Ihr Wallet hat nicht genug von MINT_A, MINT_B oder SOL (für die Pool-Erstellungsgebühr + Rent).
  • Token-2022 extension not supported — Einer Ihrer Mints verwendet eine Erweiterung, die CPMM nicht akzeptiert. Siehe reference/token-2022-support.

Nach der Bereitstellung

Sie können sofort gegen den neuen Pool swappen – das Skript Swap from CLI akzeptiert Ihre neue POOL_ID direkt. Aggregatoren (Jupiter, etc.) werden den neuen Pool innerhalb weniger Minuten indexieren.

Weiter