The type of swap (exact input or output).
The Solana RPC client.
The swap parameters, specifying either the input or output amount and the mint address of the token being swapped.
The address of the Whirlpool against which the swap will be made.
Optional
slippageToleranceBps: number = SLIPPAGE_TOLERANCE_BPSThe maximum acceptable slippage tolerance for the swap, in basis points (BPS).
Optional
signer: TransactionSigner = FUNDERThe wallet or signer executing the swap.
import { setWhirlpoolsConfig, swapInstructions } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/web3.js';
import { loadWallet } from './utils';
await setWhirlpoolsConfig('solanaDevnet');
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
const wallet = await loadWallet(); // CAUTION: This wallet is not persistent.
const whirlpoolAddress = address("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt");
const mintAddress = address("BRjpCHtyQLNCo8gqRUr8jtdAj5AjPYQaoqbvcZiHok1k");
const inputAmount = 1_000_000n;
const { instructions, quote } = await swapInstructions(
devnetRpc,
{ inputAmount, mint: mintAddress },
whirlpoolAddress,
100,
wallet
);
console.log(`Quote estimated token out: ${quote.tokenEstOut}`);
console.log(`Number of instructions:, ${instructions.length}`);
Generates the instructions necessary to execute a token swap in an Orca Whirlpool. It handles both exact input and exact output swaps, fetching the required accounts, tick arrays, and determining the swap quote.