关于 raydium
raydium 是面向开发者的技能指南,介绍如何集成 Solana 上的 Raydium 交易所和流动性基础设施,涵盖池类型、SDK 操作、API 与代币发行。
主要功能
- 01CLMM、CPMM 和 AMM 池介绍
- 02TypeScript SDK 集成指南
- 03HTTP Trade API 与 Data API
- 04交换、流动性和建池操作
- 05LaunchLab 代币发行说明
适用场景
- 01为应用集成 Raydium 交易
- 02查询池数据并执行交换
- 03创建池或添加流动性
- 04通过 LaunchLab 配置代币发行
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ sendaifun/ skills --skill raydium安装后在 Claude Code 中输入/raydium确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
docs/clmm-guide.mdtroubleshooting.mdexamples/clmm-pool/README.mdexamples/clmm-position/README.mdexamples/cpmm-pool/README.mdexamples/farming/README.mdexamples/launchlab/README.mdexamples/liquidity/README.mdexamples/swap/README.mdresources/github-repos.mdlaunchlab.mdpool-types.mdprogram-ids.mdsdk-api-reference.mdtrade-api.mdtemplates/raydium-setup.ts详细介绍
Raydium Protocol - 完整集成指南
Raydium 集成权威指南——自 2021 年以来,为 DeFi 提供动力的 Solana 领先 AMM 和流动性基础设施。
什么是 Raydium?
Raydium 是 Solana 上的去中心化交易所,提供:
- 代币兑换 - 通过跨所有池类型的智能路由,实现快速、低成本兑换
- 提供流动性 - 提供流动性即可赚取交易手续费和奖励
- 代币发行 - LaunchLab 支持通过联合曲线进行无需许可的代币发行
- 永续交易 - 对加密资产进行杠杆交易
关键数据
- Solana 上集成最广泛的流动性基础设施
- 通过 LaunchLab 发行的代币超过 35,000 个(2025 年)
- 多种池类型适用于不同场景
核心产品
池类型
| 类型 | 描述 | 最适合 |
|---|---|---|
| CLMM | 集中流动性做市商 | 专业 LP、稳定币交易对、主动管理 |
| CPMM | 基于 Token22 的恒定乘积(x*y=k) | 新代币发行、简单集成 |
| AMM V4 | 经典 AMM + OpenBook CLOB | 现有市场、混合流动性 |
其他功能
- LaunchLab - 通过联合曲线进行无需许可的代币发行
- Farm - 收益耕作和质押奖励
- Burn & Earn - 永久锁定流动性
- Trade API - 用于兑换路由的 HTTP API
API 概览
1. SDK(TypeScript)
包: @raydium-io/raydium-sdk-v2
用于以编程方式集成,可全面控制池、头寸和交易。
2. Trade API(HTTP)
基础 URL: https://transaction-v1.raydium.io
用于兑换路由——通过 HTTP 获取报价和序列化交易。
3. Data API
基础 URL: https://api-v3.raydium.io
用于获取池数据、代币列表、Farm 信息和配置。
快速开始
安装
npm install @raydium-io/raydium-sdk-v2
# or
yarn add @raydium-io/raydium-sdk-v2
基础设置
import { Raydium } from '@raydium-io/raydium-sdk-v2';
import { Connection, Keypair } from '@solana/web3.js';
import bs58 from 'bs58';
// Setup connection and wallet
const connection = new Connection('https://api.mainnet-beta.solana.com');
const owner = Keypair.fromSecretKey(bs58.decode('YOUR_SECRET_KEY'));
// Initialize SDK
const raydium = await Raydium.load({
connection,
owner,
cluster: 'mainnet',
disableLoadToken: false, // Load token list
});
// Access token data
const tokenList = raydium.token.tokenList;
const tokenMap = raydium.token.tokenMap;
// Access account data
const tokenAccounts = raydium.account.tokenAccounts;
池类型
CLMM(集中流动性)
允许 LP 在特定价格区间内集中提供流动性,以提高资金效率。
// Fetch CLMM pool
const poolId = 'POOL_ID_HERE';
const poolInfo = await raydium.clmm.getPoolInfoFromRpc(poolId);
// Or from API (mainnet only)
const poolData = await raydium.api.fetchPoolById({ ids: poolId });
CPMM(恒定乘积)
无需 OpenBook 市场的简化 AMM,支持 Token22。
// Fetch CPMM pool
const cpmmPool = await raydium.cpmm.getPoolInfoFromRpc(poolId);
AMM(传统)
与 OpenBook 中央限价订单簿集成的经典 AMM。
// Fetch AMM pool
const ammPool = await raydium.liquidity.getPoolInfoFromRpc({ poolId });
核心操作
兑换
import { CurveCalculator } from '@raydium-io/raydium-sdk-v2';
// Calculate swap
const { amountOut, fee } = CurveCalculator.swapBaseInput({
poolInfo,
amountIn: 1000000n, // lamports
mintIn: inputMint,
mintOut: outputMint,
});
// Execute CPMM swap
const { execute } = await raydium.cpmm.swap({
poolInfo,
inputAmount: 1000000n,
inputMint,
slippage: 0.01, // 1%
txVersion: 'V0',
});
await execute({ sendAndConfirm: true });
添加流动性
// CPMM deposit
const { execute } = await raydium.cpmm.addLiquidity({
poolInfo,
inputAmount: 1000000n,
baseIn: true,
slippage: 0.01,
});
await execute({ sendAndConfirm: true });
创建池
// Create CPMM pool
const { execute } = await raydium.cpmm.createPool({
mintA,
mintB,
mintAAmount: 1000000n,
mintBAmount: 1000000n,
startTime: new BN(0),
feeConfig, // from API
txVersion: 'V0',
});
const { txId } = await execute({ sendAndConfirm: true });
程序 ID
| 程序 | Mainnet | Devnet |
|---|---|---|
| AMM | 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 | DRaya7Kj3aMWQSy19kSjvmuwq9docCHofyP9kanQGaav |
| CLMM | CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK | devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH |
| CPMM | CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C | CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW |
API 端点
// Mainnet API
const API_URL = 'https://api-v3.raydium.io';
// Devnet API
const DEVNET_API = 'https://api-v3.raydium.io/main/';
// Common endpoints
const endpoints = {
tokenList: '/mint/list',
poolList: '/pools/info/list',
poolById: '/pools/info/ids',
farmList: '/farms/info/list',
clmmConfigs: '/clmm/configs',
};
交易选项
const { execute } = await raydium.cpmm.swap({
poolInfo,
inputAmount,
inputMint,
slippage: 0.01,
txVersion: 'V0', // or 'LEGACY'
computeBudgetConfig: {
units: 600000,
microLamports: 100000, // priority fee
},
});
// Execute with options
const { txId } = await execute({
sendAndConfirm: true,
skipPreflight: true,
});
console.log(`https://solscan.io/tx/${txId}`);
主要功能
| 功能 | CLMM | CPMM | AMM |
|---|---|---|---|
| 集中流动性 | 是 | 否 | 否 |
| Token22 支持 | 有限 | 是 | 否 |
| 需要 OpenBook | 否 | 否 | 是 |
| 自定义价格区间 | 是 | 否 | 否 |
| LP NFT 头寸 | 是 | 否 | 否 |
LaunchLab(新增)
LaunchLab 通过可自定义的联合曲线,简化 Solana 上的代币发行:
// Create token with bonding curve via LaunchLab
const { execute } = await raydium.launchLab.createToken({
name: "My Token",
symbol: "MTK",
uri: "https://arweave.net/metadata.json",
initialSupply: 1_000_000_000n,
bondingCurve: "linear", // or "exponential"
graduationThreshold: 85_000_000_000n, // 85 SOL
txVersion: "V0",
});
const { txId } = await execute({ sendAndConfirm: true });
联合曲线迁移
代币达到毕业阈值后(默认:85 SOL),会自动迁移到 AMM 池。迁移后,创建者可获得 10% 的交易手续费。
重要里程碑(2025 年)
- 通过 LaunchLab 发行的代币超过 35,000 个
- 推出用于链上分析的 Orb Explorer
V3 协议(即将推出)
Raydium V3 引入混合流动性模型,结合:
- AMM 池与 OpenBook 的去中心化订单簿
- 使用 Solana DeFi 中多出 40% 的流动性
- 提高 LP 的资金效率
Resources
- SDK: https://github.com/raydium-io/raydium-sdk-V2
- Demos: https://github.com/raydium-io/raydium-sdk-V2-demo
- IDL: https://github.com/raydium-io/raydium-idl
- CLMM Program: https://github.com/raydium-io/raydium-clmm
- CPMM Program: https://github.com/raydium-io/raydium-cp-swap
- AMM Program: https://github.com/raydium-io/raydium-amm
- CPI Examples: https://github.com/raydium-io/raydium-cpi
Skill Structure
raydium/
├── SKILL.md # This file - complete integration guide
├── resources/
│ ├── sdk-api-reference.md # Complete SDK API
│ ├── trade-api.md # HTTP Trade API reference
│ ├── program-ids.md # All program addresses
│ ├── pool-types.md # Pool type comparison
│ ├── launchlab.md # LaunchLab documentation
│ └── github-repos.md # GitHub repositories reference
├── examples/
│ ├── swap/README.md # Token swap examples
│ ├── clmm-pool/README.md # CLMM pool creation
│ ├── clmm-position/README.md # CLMM position management
│ ├── cpmm-pool/README.md # CPMM pool operations
│ ├── liquidity/README.md # Liquidity management
│ ├── farming/README.md # Farming and staking
│ └── launchlab/README.md # LaunchLab token launches
├── templates/
│ └── raydium-setup.ts # SDK setup template
└── docs/
├── clmm-guide.md # CLMM deep dive
└── troubleshooting.md # Common issues
GitHub Repositories
| Repository | Description |
|---|---|
| raydium-sdk-V2 | TypeScript SDK |
| raydium-sdk-V2-demo | SDK examples |
| raydium-clmm | CLMM program (Rust) |
| raydium-cp-swap | CPMM program (Rust) |
| raydium-amm | AMM V4 program (Rust) |
| raydium-cpi | CPI integration examples |
| raydium-idl | IDL definitions |
评论
支持 Markdown