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.
Optionalconfig: SwapConfig = {}The parameters to build the swap instruction.
import { swapInstructions, SwapConfig, WhirlpoolDeployment } from '@orca-so/whirlpools';
import { createSolanaRpc, devnet, address } from '@solana/kit';
import { loadWallet } from './utils';
const devnetRpc = createSolanaRpc(devnet('https://api.devnet.solana.com'));
const wallet = await loadWallet();
const whirlpoolAddress = address("3KBZiL2g8C7tiJ32hTv5v3KM7aK9htpqTw4cTXz1HvPt");
const mintAddress = address("BRjpCHtyQLNCo8gqRUr8jtdAj5AjPYQaoqbvcZiHok1k");
const { instructions, quote } = await swapInstructions(
devnetRpc,
{ inputAmount: 1_000_000n, mint: mintAddress },
whirlpoolAddress,
{
slippageToleranceBps: 100,
signer: wallet,
whirlpoolDeployment: WhirlpoolDeployment.devnet,
},
);
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.