Skip to content
Swap

Prepare ExactIn and ExactOut swaps

Supply a selected pool and explicit execution bounds; keep quoting separate from transaction preparation.

The direct SDK prepares swaps against a caller-selected pool. It does not currently discover the best route or produce an executable native quote. Obtain complete, policy-aware bounds from a compatible quote engine before building. Spot price alone does not predict a CLMM trade across ticks.

Choose the mode

MethodRequired amount bounds
prepareSwapExactInamountIn budget and minimumOut
prepareSwapExactOutamountOut target and maximumIn

Both methods also need pool, inputMint, and sqrtPriceLimitX64. Amounts are bigint token atoms. The input mint determines direction; the price limit must be valid for that direction.

import type {
  GraplClient,
  PreparedTransaction,
  SwapExactInIntent,
} from "@grapl/sdk";

export async function prepareBoundedSwap(
  client: GraplClient,
  reviewedIntent: SwapExactInIntent,
): Promise<PreparedTransaction> {
  return client.prepareSwapExactIn(reviewedIntent);
}

Supply a complete reviewed intent; this wrapper does not calculate slippage or a quote. Read swap semantics for net output, partial input consumption, and rounding.

Account and policy resolution

The client resolves the pool's token accounts and required tick pages. Initial selection conservatively includes initialized pages in the trade direction and rejects a plan requiring more than 16 pages. Specialized native account plans can use generated builders with explicit composition.

A configured pool hook needs the matching resolver and dependencies. Missing eligibility, time, fee, or actor context must fail; do not substitute an unhooked quote. See Hook integration.

Native SOL and settlement

The client expects funded SPL token accounts, including WSOL when the pair uses wrapped SOL. It does not wrap native SOL or close token accounts implicitly. Keep wrapping and cleanup explicit in your application.

Preparation simulates but does not send. After explicit signing and submission, reconcile actual token debits, net credits, and hook effects. The optional API quote service is a distinct integration and is not called by these SDK methods.