Skip to main content
Use CPI when your Solana program must call DBC directly, for example to swap, add or remove liquidity, claim fees or rewards, or manage a DBC position as part of a larger protocol instruction.

Program ID

Generated Bindings

For a Rust program in the same workspace, enable the DBC program crate with the cpi feature:
If you are outside the repository, generate bindings from the published IDL and pin the IDL version you tested against.

CPI Instruction Scope

Event CPI Accounts

Most public DBC instructions use #[event_cpi]. Include these accounts when constructing CPI contexts:

Remaining Accounts

Swaps may require the instructions sysvar as the first remaining account. The program validates single-swap behavior for active rate limiter pools. The first-swap minimum-fee path also validates that pool initialization appears earlier in the top-level transaction; do not assume a CPI-only path is eligible for that minimum fee.

Swap CPI Shape

Use swap2 for new integrations because it supports exact-in, partial-fill, and exact-out modes. Before calling DBC from your program:
  1. Decode and validate VirtualPool and PoolConfig.
  2. Verify account ownership and data length before deserializing.
  3. Use the Rust quote library or TypeScript SDK math to calculate expected amounts.
  4. Pass user-controlled slippage limits into your own instruction args.
  5. Recheck token mints, vaults, token program IDs, and signer authorities in your account constraints.

Token Programs

DBC supports SPL Token and Token-2022 base mints. Migration and pool creation account lists differ by token type.

Common CPI Failures

Some DBC handlers wrap downstream CPIs with account invariant checks. If the downstream CPI unexpectedly changes account owner, data length, or reduces lamports, DBC can return AccountInvariantViolation.

Best Practices