Skip to main content
Use CPI when your Solana program needs to call Zap directly. Most client apps should use the TypeScript SDK instead because Zap flows require careful transaction ordering, token account setup, and downstream remaining accounts.

Program ID

Generated Bindings

Generate bindings from the IDL with Anchor’s declare_program!. Do not type account orders from memory. A misplaced optional account or remaining account is the usual cause of a failing CPI. The IDL ships in the Zap SDK repository at src/idl/zap/idl.json. declare_program!(zap) reads idls/zap.json. The macro looks for an idls directory in the crate directory and then in each parent directory, and uses the nearest one. Copy the file from the SDK release you pin and save it as idls/zap.json.
The -f flag makes curl fail instead of saving an error page as the IDL. Take the IDL from the SDK release you pin, and update it when you upgrade the SDK.
The published Zap IDL does not compile with declare_program! as it is. Some types in the IDL share a name, such as two types called Pool, so Anchor’s IDL builder names them by their full module path, for example cp_amm::state::pool::Pool. declare_program! cannot turn a name that contains :: into a Rust identifier, and the build fails because "cp_amm::state::pool::Pool" is not a valid identifier. Give these types valid, unique names in your copy of the IDL, or generate the bindings another way.
declare_program!(zap) creates a zap module in your crate. The examples on this page use zap::cpi and zap::cpi::accounts from that module.

CPI Pattern

declare_program!(zap) generates the CPI helpers. For low-level zap out:
The remaining accounts are forwarded by Zap to the whitelisted downstream swap instruction. Their order, signer flags, and writable flags must match the downstream program’s expected account list.

Common CPI Calls

declare_program! names each accounts struct from the instruction name. The Ctx suffix on the program’s Rust accounts structs is not part of these types. CpiContext::new takes zap::ID.

Zap-Out CPI Requirements

Zap-In CPI Requirements

Zap does not emit its own custom events, but DAMM v2 and DLMM downstream CPI calls require their event authority accounts.

Token And Account Planning

Common CPI Failures

Best Practices