Compose a zap
Combine a swap and a liquidity operation using the SDK's generated instructions.
The SDK exports getZapInInstruction and getZapOutInstruction. These are low-level builders; there is no prepareZap convenience method or Zap client class. Use your configured GraplClient to simulate the complete composition with prepareInstructions before wallet signing.
Choose the operation
| Operation | Builder | Protected result |
|---|---|---|
| Zap in | getZapInInstruction | Spend up to maximumInput and receive at least minimumLiquidity |
| Zap out | getZapOutInstruction | Remove principal and receive at least minimumOutput in the desired asset |
Both target a CLMM pool, including a graduated curve. Zap out does not collect accrued position fees. A full withdrawal may leave too little liquidity for the conversion leg; do not promise that every position can exit into one token. See zap semantics for budget isolation, rounding and rollback.
Build with resolved accounts
Resolve the actor, pool, ordered mints, vaults, actor token accounts, tick directory and owned position. Supply the hook program/authority and the exact remaining tick/hook accounts required by each leg. swapAccountsLen on zap in and liquidityAccountsLen on zap out delimit those account segments; they must agree with the instruction's account order.
The example accepts already resolved accounts and arguments. It does not infer a profitable swap amount, construct hook proofs or choose a liquidity range.
import { getZapInInstruction } from "@grapl/sdk";
import type {
GraplClient,
PreparedTransaction,
ZapInAccounts,
ZapInInput,
} from "@grapl/sdk";
import type { Address, AccountMeta } from "@solana/kit";
export async function prepareResolvedZapIn(
client: GraplClient,
program: Address,
accounts: ZapInAccounts,
input: ZapInInput,
remaining: readonly AccountMeta[],
): Promise<PreparedTransaction> {
const instruction = getZapInInstruction(program, accounts, input, remaining);
return client.prepareInstructions({
instructions: [instruction],
addresses: { pool: accounts.market.pool, position: accounts.position },
creations: [],
summary: { operation: "zap-in", maximumInput: input.args.maximumInput },
});
}The example assumes every required account already exists, hence creations: []. If the composition creates accounts, include their creation instructions and accurate deposit metadata. The supplied program must match your client's deployment. For zap out, use ZapOutAccounts, ZapOutInput and getZapOutInstruction with a negative liquidity delta and explicit aggregate output/price limits.
Review the complete transaction
Inspect all required signers, account privileges, simulation logs, compute and deposits. Supply hook descriptors independently for the swap and liquidity legs; a denied callback or failed bound rolls back the whole zap. Do not remove accounts to fit the message. Consider ALTs when address overhead is the constraint.
Continue with wallet review and confirmation. Generated builders only assemble instructions; successful preparation is not a settled zap.