orca
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOrca Whirlpools Development Guide
Orca Whirlpools 开发指南
Orca is the most trusted DEX on Solana and Eclipse, built on a concentrated liquidity automated market maker (CLMM) called Whirlpools. This guide covers the Whirlpools SDK for building trading, liquidity provision, and pool management applications.
Orca是Solana和Eclipse上最值得信赖的去中心化交易所(DEX),基于名为Whirlpools的集中流动性自动做市商(CLMM)构建。本指南涵盖了使用Whirlpools SDK构建交易、流动性提供和资金池管理应用的相关内容。
Overview
概述
Orca Whirlpools provides:
- Token Swaps - Efficient token exchanges with low slippage and competitive rates
- Concentrated Liquidity - Provide liquidity within custom price ranges for higher capital efficiency
- Splash Pools - Simple full-range liquidity provision for beginners
- Position Management - Open, increase, decrease, and close liquidity positions
- Fee Harvesting - Collect trading fees and rewards from positions
- Pool Creation - Permissionless creation of new liquidity pools
Orca Whirlpools 提供以下功能:
- 代币兑换 - 低滑点、具竞争力费率的高效代币交易
- 集中流动性 - 在自定义价格区间内提供流动性,提升资金使用效率
- Splash 资金池 - 面向新手的简单全区间流动性提供方式
- 仓位管理 - 开启、增加、减少和关闭流动性仓位
- 手续费收割 - 从仓位中收取交易手续费和奖励
- 资金池创建 - 无需许可即可创建新的流动性资金池
Program IDs
程序ID
| Network | Program ID |
|---|---|
| Solana Mainnet | |
| Solana Devnet | |
| Eclipse Mainnet | |
| Eclipse Testnet | |
| 网络 | 程序ID |
|---|---|
| Solana 主网 | |
| Solana 测试网 | |
| Eclipse 主网 | |
| Eclipse 测试网 | |
Quick Start
快速开始
Installation
安装
New SDK (Solana Web3.js v2):
bash
npm install @orca-so/whirlpools @solana/kitLegacy SDK (Solana Web3.js v1):
bash
npm install @orca-so/whirlpools-sdk @orca-so/common-sdk @coral-xyz/anchor@0.29.0 @solana/web3.js @solana/spl-token decimal.jsCore Utilities (optional):
bash
npm install @orca-so/whirlpools-core @orca-so/whirlpools-client新SDK(Solana Web3.js v2):
bash
npm install @orca-so/whirlpools @solana/kit旧版SDK(Solana Web3.js v1):
bash
npm install @orca-so/whirlpools-sdk @orca-so/common-sdk @coral-xyz/anchor@0.29.0 @solana/web3.js @solana/spl-token decimal.js核心工具(可选):
bash
npm install @orca-so/whirlpools-core @orca-so/whirlpools-clientBasic Setup (New SDK)
基础配置(新SDK)
typescript
import {
setWhirlpoolsConfig,
setRpc,
setPayerFromBytes
} from "@orca-so/whirlpools";
import { createSolanaRpc, devnet } from "@solana/kit";
import fs from "fs";
// Configure for Solana Devnet
await setWhirlpoolsConfig("solanaDevnet");
await setRpc("https://api.devnet.solana.com");
// Load wallet from keypair file
const keyPairBytes = new Uint8Array(
JSON.parse(fs.readFileSync("./keypair.json", "utf8"))
);
const wallet = await setPayerFromBytes(keyPairBytes);
// Create RPC connection
const rpc = createSolanaRpc(devnet("https://api.devnet.solana.com"));
console.log("Wallet:", wallet.address);typescript
import {
setWhirlpoolsConfig,
setRpc,
setPayerFromBytes
} from "@orca-so/whirlpools";
import { createSolanaRpc, devnet } from "@solana/kit";
import fs from "fs";
// Configure for Solana Devnet
await setWhirlpoolsConfig("solanaDevnet");
await setRpc("https://api.devnet.solana.com");
// Load wallet from keypair file
const keyPairBytes = new Uint8Array(
JSON.parse(fs.readFileSync("./keypair.json", "utf8"))
);
const wallet = await setPayerFromBytes(keyPairBytes);
// Create RPC connection
const rpc = createSolanaRpc(devnet("https://api.devnet.solana.com"));
console.log("Wallet:", wallet.address);Basic Setup (Legacy SDK)
基础配置(旧版SDK)
typescript
import { WhirlpoolContext, buildWhirlpoolClient, ORCA_WHIRLPOOL_PROGRAM_ID } from "@orca-so/whirlpools-sdk";
import { AnchorProvider, Wallet } from "@coral-xyz/anchor";
import { Connection, Keypair } from "@solana/web3.js";
import fs from "fs";
// Setup connection
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
// Load wallet
const secretKey = JSON.parse(fs.readFileSync("./keypair.json", "utf8"));
const wallet = new Wallet(Keypair.fromSecretKey(new Uint8Array(secretKey)));
// Create provider and context
const provider = new AnchorProvider(connection, wallet, {});
const ctx = WhirlpoolContext.from(connection, wallet, ORCA_WHIRLPOOL_PROGRAM_ID);
const client = buildWhirlpoolClient(ctx);
console.log("Wallet:", wallet.publicKey.toString());typescript
import { WhirlpoolContext, buildWhirlpoolClient, ORCA_WHIRLPOOL_PROGRAM_ID } from "@orca-so/whirlpools-sdk";
import { AnchorProvider, Wallet } from "@coral-xyz/anchor";
import { Connection, Keypair } from "@solana/web3.js";
import fs from "fs";
// Setup connection
const connection = new Connection("https://api.mainnet-beta.solana.com", "confirmed");
// Load wallet
const secretKey = JSON.parse(fs.readFileSync("./keypair.json", "utf8"));
const wallet = new Wallet(Keypair.fromSecretKey(new Uint8Array(secretKey)));
// Create provider and context
const provider = new AnchorProvider(connection, wallet, {});
const ctx = WhirlpoolContext.from(connection, wallet, ORCA_WHIRLPOOL_PROGRAM_ID);
const client = buildWhirlpoolClient(ctx);
console.log("Wallet:", wallet.publicKey.toString());Token Swaps
代币兑换
Swap with New SDK
使用新SDK进行兑换
typescript
import { swap, swapInstructions, setWhirlpoolsConfig } from "@orca-so/whirlpools";
import { address } from "@solana/kit";
await setWhirlpoolsConfig("solanaMainnet");
const poolAddress = address("POOL_ADDRESS_HERE");
const inputMint = address("INPUT_TOKEN_MINT");
const amount = 1_000_000n; // Amount in smallest units
const slippageTolerance = 100; // 100 bps = 1%
// Option 1: Use the simple swap function (builds and sends)
const txId = await swap(
rpc,
{ inputAmount: amount, mint: inputMint },
poolAddress,
slippageTolerance,
wallet
);
console.log("Swap transaction:", txId);
// Option 2: Get instructions for custom transaction building
const { instructions, quote } = await swapInstructions(
rpc,
{ inputAmount: amount, mint: inputMint },
poolAddress,
slippageTolerance,
wallet
);
console.log("Expected output:", quote.tokenEstOut);
console.log("Minimum output:", quote.tokenMinOut);
console.log("Price impact:", quote.priceImpact);typescript
import { swap, swapInstructions, setWhirlpoolsConfig } from "@orca-so/whirlpools";
import { address } from "@solana/kit";
await setWhirlpoolsConfig("solanaMainnet");
const poolAddress = address("POOL_ADDRESS_HERE");
const inputMint = address("INPUT_TOKEN_MINT");
const amount = 1_000_000n; // Amount in smallest units
const slippageTolerance = 100; // 100 bps = 1%
// Option 1: Use the simple swap function (builds and sends)
const txId = await swap(
rpc,
{ inputAmount: amount, mint: inputMint },
poolAddress,
slippageTolerance,
wallet
);
console.log("Swap transaction:", txId);
// Option 2: Get instructions for custom transaction building
const { instructions, quote } = await swapInstructions(
rpc,
{ inputAmount: amount, mint: inputMint },
poolAddress,
slippageTolerance,
wallet
);
console.log("Expected output:", quote.tokenEstOut);
console.log("Minimum output:", quote.tokenMinOut);
console.log("Price impact:", quote.priceImpact);Exact Output Swap
精确输出兑换
typescript
// Swap to get exact output amount
const { instructions, quote } = await swapInstructions(
rpc,
{ outputAmount: 1_000_000n, mint: outputMint },
poolAddress,
slippageTolerance,
wallet
);
console.log("Max input required:", quote.tokenMaxIn);typescript
// Swap to get exact output amount
const { instructions, quote } = await swapInstructions(
rpc,
{ outputAmount: 1_000_000n, mint: outputMint },
poolAddress,
slippageTolerance,
wallet
);
console.log("Max input required:", quote.tokenMaxIn);Swap with Legacy SDK
使用旧版SDK进行兑换
typescript
import { WhirlpoolContext, swapQuoteByInputToken, buildWhirlpoolClient } from "@orca-so/whirlpools-sdk";
import { DecimalUtil, Percentage } from "@orca-so/common-sdk";
import Decimal from "decimal.js";
// Get the pool
const whirlpool = await client.getPool(poolAddress);
const whirlpoolData = whirlpool.getData();
// Get swap quote
const inputAmount = new Decimal("1.0"); // 1 token
const quote = await swapQuoteByInputToken(
whirlpool,
whirlpoolData.tokenMintA,
DecimalUtil.toBN(inputAmount, 9), // 9 decimals
Percentage.fromFraction(1, 100), // 1% slippage
ctx.program.programId,
ctx.fetcher
);
console.log("Estimated output:", quote.estimatedAmountOut.toString());
// Execute swap
const tx = await whirlpool.swap(quote);
const signature = await tx.buildAndExecute();
console.log("Swap signature:", signature);typescript
import { WhirlpoolContext, swapQuoteByInputToken, buildWhirlpoolClient } from "@orca-so/whirlpools-sdk";
import { DecimalUtil, Percentage } from "@orca-so/common-sdk";
import Decimal from "decimal.js";
// Get the pool
const whirlpool = await client.getPool(poolAddress);
const whirlpoolData = whirlpool.getData();
// Get swap quote
const inputAmount = new Decimal("1.0"); // 1 token
const quote = await swapQuoteByInputToken(
whirlpool,
whirlpoolData.tokenMintA,
DecimalUtil.toBN(inputAmount, 9), // 9 decimals
Percentage.fromFraction(1, 100), // 1% slippage
ctx.program.programId,
ctx.fetcher
);
console.log("Estimated output:", quote.estimatedAmountOut.toString());
// Execute swap
const tx = await whirlpool.swap(quote);
const signature = await tx.buildAndExecute();
console.log("Swap signature:", signature);Liquidity Provision
流动性提供
Position Types
开启集中流动性仓位
Concentrated Liquidity Position: Provide liquidity within a specific price range for higher capital efficiency.
Full Range Position (Splash Pool): Provide liquidity across the entire price range, similar to traditional AMMs.
typescript
import { openPosition, openPositionInstructions } from "@orca-so/whirlpools";
import { address } from "@solana/kit";
const poolAddress = address("POOL_ADDRESS");
const lowerPrice = 0.001; // Lower bound of price range
const upperPrice = 100.0; // Upper bound of price range
const slippageTolerance = 100; // 1%
// Specify liquidity by token amount
const param = { tokenA: 1_000_000_000n }; // 1 token with 9 decimals
// Option 1: Simple function that builds and sends
const txId = await openPosition(
rpc,
poolAddress,
param,
lowerPrice,
upperPrice,
slippageTolerance,
wallet
);
// Option 2: Get instructions for custom transaction
const {
instructions,
quote,
positionMint,
initializationCost
} = await openPositionInstructions(
rpc,
poolAddress,
param,
lowerPrice,
upperPrice,
slippageTolerance,
wallet
);
console.log("Position mint:", positionMint);
console.log("Token A required:", quote.tokenEstA);
console.log("Token B required:", quote.tokenEstB);
console.log("Initialization cost:", initializationCost);Open Concentrated Liquidity Position
开启全区间仓位
typescript
import { openPosition, openPositionInstructions } from "@orca-so/whirlpools";
import { address } from "@solana/kit";
const poolAddress = address("POOL_ADDRESS");
const lowerPrice = 0.001; // Lower bound of price range
const upperPrice = 100.0; // Upper bound of price range
const slippageTolerance = 100; // 1%
// Specify liquidity by token amount
const param = { tokenA: 1_000_000_000n }; // 1 token with 9 decimals
// Option 1: Simple function that builds and sends
const txId = await openPosition(
rpc,
poolAddress,
param,
lowerPrice,
upperPrice,
slippageTolerance,
wallet
);
// Option 2: Get instructions for custom transaction
const {
instructions,
quote,
positionMint,
initializationCost
} = await openPositionInstructions(
rpc,
poolAddress,
param,
lowerPrice,
upperPrice,
slippageTolerance,
wallet
);
console.log("Position mint:", positionMint);
console.log("Token A required:", quote.tokenEstA);
console.log("Token B required:", quote.tokenEstB);
console.log("Initialization cost:", initializationCost);typescript
import { openFullRangePosition, openFullRangePositionInstructions } from "@orca-so/whirlpools";
const poolAddress = address("POOL_ADDRESS");
const param = { tokenA: 1_000_000_000n };
const slippageTolerance = 100;
const {
instructions,
quote,
positionMint,
callback: sendTx
} = await openFullRangePositionInstructions(
rpc,
poolAddress,
param,
slippageTolerance,
wallet
);
console.log("Position mint:", positionMint);
console.log("Token max B:", quote.tokenMaxB);
// Send the transaction
const txId = await sendTx();
console.log("Transaction:", txId);Open Full Range Position
增加仓位流动性
typescript
import { openFullRangePosition, openFullRangePositionInstructions } from "@orca-so/whirlpools";
const poolAddress = address("POOL_ADDRESS");
const param = { tokenA: 1_000_000_000n };
const slippageTolerance = 100;
const {
instructions,
quote,
positionMint,
callback: sendTx
} = await openFullRangePositionInstructions(
rpc,
poolAddress,
param,
slippageTolerance,
wallet
);
console.log("Position mint:", positionMint);
console.log("Token max B:", quote.tokenMaxB);
// Send the transaction
const txId = await sendTx();
console.log("Transaction:", txId);typescript
import { increaseLiquidity, increaseLiquidityInstructions } from "@orca-so/whirlpools";
const positionMint = address("POSITION_MINT");
const param = { tokenA: 500_000_000n }; // Add 0.5 tokens
const slippageTolerance = 100;
const { instructions, quote } = await increaseLiquidityInstructions(
rpc,
positionMint,
param,
slippageTolerance,
wallet
);
console.log("Additional Token A:", quote.tokenEstA);
console.log("Additional Token B:", quote.tokenEstB);Increase Position Liquidity
减少仓位流动性
typescript
import { increaseLiquidity, increaseLiquidityInstructions } from "@orca-so/whirlpools";
const positionMint = address("POSITION_MINT");
const param = { tokenA: 500_000_000n }; // Add 0.5 tokens
const slippageTolerance = 100;
const { instructions, quote } = await increaseLiquidityInstructions(
rpc,
positionMint,
param,
slippageTolerance,
wallet
);
console.log("Additional Token A:", quote.tokenEstA);
console.log("Additional Token B:", quote.tokenEstB);typescript
import { decreaseLiquidity, decreaseLiquidityInstructions } from "@orca-so/whirlpools";
const positionMint = address("POSITION_MINT");
const param = { liquidity: 1000000n }; // Or use tokenA/tokenB
const slippageTolerance = 100;
const { instructions, quote } = await decreaseLiquidityInstructions(
rpc,
positionMint,
param,
slippageTolerance,
wallet
);
console.log("Token A received:", quote.tokenEstA);
console.log("Token B received:", quote.tokenEstB);Decrease Position Liquidity
收割手续费和奖励
typescript
import { decreaseLiquidity, decreaseLiquidityInstructions } from "@orca-so/whirlpools";
const positionMint = address("POSITION_MINT");
const param = { liquidity: 1000000n }; // Or use tokenA/tokenB
const slippageTolerance = 100;
const { instructions, quote } = await decreaseLiquidityInstructions(
rpc,
positionMint,
param,
slippageTolerance,
wallet
);
console.log("Token A received:", quote.tokenEstA);
console.log("Token B received:", quote.tokenEstB);typescript
import { harvestPosition, harvestPositionInstructions, harvestAllPositionFees } from "@orca-so/whirlpools";
// Harvest single position
const positionMint = address("POSITION_MINT");
const { instructions, feesQuote, rewardsQuote } = await harvestPositionInstructions(
rpc,
positionMint,
wallet
);
console.log("Fee Token A:", feesQuote.feeOwedA);
console.log("Fee Token B:", feesQuote.feeOwedB);
console.log("Rewards:", rewardsQuote);
// Harvest all positions at once
const { instructions: harvestAllIx, fees, rewards } = await harvestAllPositionFees(
rpc,
wallet.address
);Harvest Fees and Rewards
关闭仓位
typescript
import { harvestPosition, harvestPositionInstructions, harvestAllPositionFees } from "@orca-so/whirlpools";
// Harvest single position
const positionMint = address("POSITION_MINT");
const { instructions, feesQuote, rewardsQuote } = await harvestPositionInstructions(
rpc,
positionMint,
wallet
);
console.log("Fee Token A:", feesQuote.feeOwedA);
console.log("Fee Token B:", feesQuote.feeOwedB);
console.log("Rewards:", rewardsQuote);
// Harvest all positions at once
const { instructions: harvestAllIx, fees, rewards } = await harvestAllPositionFees(
rpc,
wallet.address
);typescript
import { closePosition, closePositionInstructions } from "@orca-so/whirlpools";
const positionMint = address("POSITION_MINT");
const slippageTolerance = 100;
const { instructions, quote, feesQuote } = await closePositionInstructions(
rpc,
positionMint,
slippageTolerance,
wallet
);
console.log("Token A returned:", quote.tokenEstA);
console.log("Token B returned:", quote.tokenEstB);
console.log("Fees collected:", feesQuote);Close Position
资金池管理
—
创建全区间资金池(Splash Pool)
typescript
import { closePosition, closePositionInstructions } from "@orca-so/whirlpools";
const positionMint = address("POSITION_MINT");
const slippageTolerance = 100;
const { instructions, quote, feesQuote } = await closePositionInstructions(
rpc,
positionMint,
slippageTolerance,
wallet
);
console.log("Token A returned:", quote.tokenEstA);
console.log("Token B returned:", quote.tokenEstB);
console.log("Fees collected:", feesQuote);typescript
import { createSplashPool, createSplashPoolInstructions } from "@orca-so/whirlpools";
import { address } from "@solana/kit";
const tokenMintA = address("TOKEN_A_MINT");
const tokenMintB = address("TOKEN_B_MINT");
const initialPrice = 1.5; // Price of token B in terms of token A
const {
instructions,
poolAddress,
initializationCost
} = await createSplashPoolInstructions(
rpc,
tokenMintA,
tokenMintB,
initialPrice,
wallet
);
console.log("Pool address:", poolAddress);
console.log("Initialization cost:", initializationCost, "lamports");Pool Management
创建集中流动性资金池
Create Splash Pool (Full Range)
—
typescript
import { createSplashPool, createSplashPoolInstructions } from "@orca-so/whirlpools";
import { address } from "@solana/kit";
const tokenMintA = address("TOKEN_A_MINT");
const tokenMintB = address("TOKEN_B_MINT");
const initialPrice = 1.5; // Price of token B in terms of token A
const {
instructions,
poolAddress,
initializationCost
} = await createSplashPoolInstructions(
rpc,
tokenMintA,
tokenMintB,
initialPrice,
wallet
);
console.log("Pool address:", poolAddress);
console.log("Initialization cost:", initializationCost, "lamports");typescript
import { createConcentratedLiquidityPool, createConcentratedLiquidityPoolInstructions } from "@orca-so/whirlpools";
const tokenMintA = address("TOKEN_A_MINT");
const tokenMintB = address("TOKEN_B_MINT");
const tickSpacing = 64; // Common values: 1, 8, 64, 128
const initialPrice = 1.5;
const {
instructions,
poolAddress,
initializationCost
} = await createConcentratedLiquidityPoolInstructions(
rpc,
tokenMintA,
tokenMintB,
tickSpacing,
initialPrice,
wallet
);
console.log("Pool address:", poolAddress);Create Concentrated Liquidity Pool
获取资金池数据
typescript
import { createConcentratedLiquidityPool, createConcentratedLiquidityPoolInstructions } from "@orca-so/whirlpools";
const tokenMintA = address("TOKEN_A_MINT");
const tokenMintB = address("TOKEN_B_MINT");
const tickSpacing = 64; // Common values: 1, 8, 64, 128
const initialPrice = 1.5;
const {
instructions,
poolAddress,
initializationCost
} = await createConcentratedLiquidityPoolInstructions(
rpc,
tokenMintA,
tokenMintB,
tickSpacing,
initialPrice,
wallet
);
console.log("Pool address:", poolAddress);typescript
import {
fetchSplashPool,
fetchConcentratedLiquidityPool,
fetchWhirlpoolsByTokenPair
} from "@orca-so/whirlpools";
// Fetch specific pool
const pool = await fetchConcentratedLiquidityPool(rpc, poolAddress);
console.log("Current price:", pool.price);
console.log("Liquidity:", pool.liquidity);
console.log("Fee rate:", pool.feeRate);
// Fetch all pools for a token pair
const pools = await fetchWhirlpoolsByTokenPair(rpc, tokenMintA, tokenMintB);
for (const pool of pools) {
console.log("Pool:", pool.address, "Tick spacing:", pool.tickSpacing);
}Fetch Pool Data
获取仓位数据
typescript
import {
fetchSplashPool,
fetchConcentratedLiquidityPool,
fetchWhirlpoolsByTokenPair
} from "@orca-so/whirlpools";
// Fetch specific pool
const pool = await fetchConcentratedLiquidityPool(rpc, poolAddress);
console.log("Current price:", pool.price);
console.log("Liquidity:", pool.liquidity);
console.log("Fee rate:", pool.feeRate);
// Fetch all pools for a token pair
const pools = await fetchWhirlpoolsByTokenPair(rpc, tokenMintA, tokenMintB);
for (const pool of pools) {
console.log("Pool:", pool.address, "Tick spacing:", pool.tickSpacing);
}typescript
import { fetchPositionsForOwner, fetchPositionsInWhirlpool } from "@orca-so/whirlpools";
// Get all positions owned by a wallet
const positions = await fetchPositionsForOwner(rpc, wallet.address);
for (const position of positions) {
console.log("Position:", position.positionMint);
console.log("Liquidity:", position.liquidity);
console.log("Lower tick:", position.tickLowerIndex);
console.log("Upper tick:", position.tickUpperIndex);
}
// Get all positions in a specific pool
const poolPositions = await fetchPositionsInWhirlpool(rpc, poolAddress);Fetch Positions
SDK配置
—
网络配置
typescript
import { fetchPositionsForOwner, fetchPositionsInWhirlpool } from "@orca-so/whirlpools";
// Get all positions owned by a wallet
const positions = await fetchPositionsForOwner(rpc, wallet.address);
for (const position of positions) {
console.log("Position:", position.positionMint);
console.log("Liquidity:", position.liquidity);
console.log("Lower tick:", position.tickLowerIndex);
console.log("Upper tick:", position.tickUpperIndex);
}
// Get all positions in a specific pool
const poolPositions = await fetchPositionsInWhirlpool(rpc, poolAddress);typescript
import { setWhirlpoolsConfig } from "@orca-so/whirlpools";
// Built-in presets
await setWhirlpoolsConfig("solanaMainnet");
await setWhirlpoolsConfig("solanaDevnet");
await setWhirlpoolsConfig("eclipseMainnet");
await setWhirlpoolsConfig("eclipseTestnet");
// Custom configuration
await setWhirlpoolsConfig({
whirlpoolsConfigAddress: address("CUSTOM_CONFIG_ADDRESS"),
// ... other custom settings
});SDK Configuration
交易设置
Network Configuration
—
typescript
import { setWhirlpoolsConfig } from "@orca-so/whirlpools";
// Built-in presets
await setWhirlpoolsConfig("solanaMainnet");
await setWhirlpoolsConfig("solanaDevnet");
await setWhirlpoolsConfig("eclipseMainnet");
await setWhirlpoolsConfig("eclipseTestnet");
// Custom configuration
await setWhirlpoolsConfig({
whirlpoolsConfigAddress: address("CUSTOM_CONFIG_ADDRESS"),
// ... other custom settings
});typescript
import {
setRpc,
setPriorityFeeSetting,
setJitoTipSetting,
setComputeUnitMarginMultiplier,
setDefaultSlippageToleranceBps,
setDefaultFunder,
setNativeMintWrappingStrategy
} from "@orca-so/whirlpools";
// Set RPC endpoint
await setRpc("https://api.mainnet-beta.solana.com");
// Configure priority fees
await setPriorityFeeSetting({
type: "dynamic",
percentile: 75, // Use 75th percentile of recent fees
});
// Or set fixed priority fee
await setPriorityFeeSetting({
type: "fixed",
microLamports: 10000,
});
// Configure Jito tips for MEV protection
await setJitoTipSetting({
type: "dynamic",
percentile: 50,
});
// Set compute unit margin (for larger transactions)
await setComputeUnitMarginMultiplier(1.2);
// Set default slippage tolerance (in bps)
await setDefaultSlippageToleranceBps(100); // 1%
// Set default funder for transactions
await setDefaultFunder(wallet);
// Configure SOL wrapping behavior
await setNativeMintWrappingStrategy("ata"); // or "none"Transaction Settings
重置配置
typescript
import {
setRpc,
setPriorityFeeSetting,
setJitoTipSetting,
setComputeUnitMarginMultiplier,
setDefaultSlippageToleranceBps,
setDefaultFunder,
setNativeMintWrappingStrategy
} from "@orca-so/whirlpools";
// Set RPC endpoint
await setRpc("https://api.mainnet-beta.solana.com");
// Configure priority fees
await setPriorityFeeSetting({
type: "dynamic",
percentile: 75, // Use 75th percentile of recent fees
});
// Or set fixed priority fee
await setPriorityFeeSetting({
type: "fixed",
microLamports: 10000,
});
// Configure Jito tips for MEV protection
await setJitoTipSetting({
type: "dynamic",
percentile: 50,
});
// Set compute unit margin (for larger transactions)
await setComputeUnitMarginMultiplier(1.2);
// Set default slippage tolerance (in bps)
await setDefaultSlippageToleranceBps(100); // 1%
// Set default funder for transactions
await setDefaultFunder(wallet);
// Configure SOL wrapping behavior
await setNativeMintWrappingStrategy("ata"); // or "none"typescript
import { resetConfiguration } from "@orca-so/whirlpools";
// Reset all settings to defaults
await resetConfiguration();Reset Configuration
刻度间距参考
typescript
import { resetConfiguration } from "@orca-so/whirlpools";
// Reset all settings to defaults
await resetConfiguration();刻度间距决定了价格区间的粒度:
| 刻度间距 | 使用场景 | 手续费层级 |
|---|---|---|
| 1 | 稳定币对(如 USDC/USDT) | 0.01% |
| 8 | 关联代币对 | 0.04% |
| 64 | 标准代币对 | 0.30% |
| 128 | 小众/高波动代币对 | 1.00% |
Tick Spacing Reference
最佳实践
—
安全
Tick spacing determines the granularity of price ranges:
| Tick Spacing | Use Case | Fee Tier |
|---|---|---|
| 1 | Stablecoins (e.g., USDC/USDT) | 0.01% |
| 8 | Correlated pairs | 0.04% |
| 64 | Standard pairs | 0.30% |
| 128 | Exotic/volatile pairs | 1.00% |
- 切勿暴露私钥 - 使用环境变量或安全的密钥管理方式
- 验证资金池地址 - 始终确认你正在与合法的资金池交互
- 使用滑点保护 - 设置合适的滑点容忍度以防止抢先交易
- 先在测试网测试 - 在主网部署前验证所有操作
Best Practices
性能
Security
—
- Never expose private keys - Use environment variables or secure key management
- Verify pool addresses - Always confirm you're interacting with legitimate pools
- Use slippage protection - Set appropriate slippage tolerance to prevent front-running
- Test on devnet first - Validate all operations before mainnet deployment
- 使用优先级手续费 - 在主网拥堵期间,优先级手续费对交易至关重要
- 批量操作 - 尽可能合并多个交易指令
- 预获取数据 - 缓存资金池和仓位数据以减少RPC调用
Performance
流动性提供
- Use priority fees - Essential for mainnet transactions during high congestion
- Batch operations - Combine multiple instructions when possible
- Pre-fetch data - Cache pool and position data to reduce RPC calls
- 监控仓位 - 跟踪仓位何时超出价格区间
- 战略性再平衡 - 调整仓位时考虑gas成本
- 定期收割 - 收取手续费和奖励以复利收益
- 理解无常损失 - 集中流动性仓位的无常损失风险更高
Liquidity Provision
错误处理
- Monitor positions - Track when positions go out of range
- Rebalance strategically - Consider gas costs when adjusting positions
- Harvest regularly - Collect fees and rewards to compound returns
- Understand impermanent loss - Concentrated positions have amplified IL risk
typescript
try {
const txId = await swap(rpc, swapParams, poolAddress, slippage, wallet);
} catch (error) {
if (error.message.includes("SlippageExceeded")) {
console.error("Slippage tolerance exceeded, try increasing slippage");
} else if (error.message.includes("InsufficientFunds")) {
console.error("Not enough tokens in wallet");
} else if (error.message.includes("TickArrayNotInitialized")) {
console.error("Price range tick arrays not initialized");
} else {
throw error;
}
}Error Handling
资源
—
官方文档
typescript
try {
const txId = await swap(rpc, swapParams, poolAddress, slippage, wallet);
} catch (error) {
if (error.message.includes("SlippageExceeded")) {
console.error("Slippage tolerance exceeded, try increasing slippage");
} else if (error.message.includes("InsufficientFunds")) {
console.error("Not enough tokens in wallet");
} else if (error.message.includes("TickArrayNotInitialized")) {
console.error("Price range tick arrays not initialized");
} else {
throw error;
}
}Resources
GitHub仓库
Official Documentation
—
GitHub Repositories
NPM包
- @orca-so/whirlpools - 新SDK
- @orca-so/whirlpools-sdk - 旧版SDK
- @orca-so/whirlpools-core - 核心工具
- @orca-so/whirlpools-client - 底层客户端
NPM Packages
安全审计
- @orca-so/whirlpools - New SDK
- @orca-so/whirlpools-sdk - Legacy SDK
- @orca-so/whirlpools-core - Core utilities
- @orca-so/whirlpools-client - Low-level client
- Kudelski Security 审计
- Neodyme 审计
Security Audits
技能结构
- Kudelski Security audit
- Neodyme audit
orca/
├── SKILL.md # 本文档
├── resources/
│ ├── api-reference.md # 完整SDK函数参考
│ └── program-addresses.md # 程序ID和常用资金池地址
├── examples/
│ ├── swap/
│ │ └── token-swap.ts # 代币兑换示例
│ ├── liquidity/
│ │ ├── open-position.ts # 开启流动性仓位示例
│ │ ├── manage-position.ts # 增减流动性示例
│ │ └── harvest-fees.ts # 收取手续费和奖励示例
│ └── pools/
│ └── create-pool.ts # 资金池创建示例
├── templates/
│ └── setup.ts # 即用型客户端模板
└── docs/
└── troubleshooting.md # 常见问题与解决方案Skill Structure
—
orca/
├── SKILL.md # This file
├── resources/
│ ├── api-reference.md # Complete SDK function reference
│ └── program-addresses.md # Program IDs and common pool addresses
├── examples/
│ ├── swap/
│ │ └── token-swap.ts # Token swap examples
│ ├── liquidity/
│ │ ├── open-position.ts # Open liquidity positions
│ │ ├── manage-position.ts # Increase/decrease liquidity
│ │ └── harvest-fees.ts # Collect fees and rewards
│ └── pools/
│ └── create-pool.ts # Pool creation examples
├── templates/
│ └── setup.ts # Ready-to-use client template
└── docs/
└── troubleshooting.md # Common issues and solutions—