Skip to main content

Module cpi

Module cpi 

Source
Expand description

Const-generic CPI builder – stack-only, zero-allocation CPI calls.

Both account count and data size are const generics, ensuring everything lives on the SBF stack (4096 bytes). No heap allocation ever.

§Design

  • HopperCpi<A, D> – fully const-generic: accounts + data
  • HopperCpiBuf<A, MAX> – const accounts, runtime data length
  • Uses MaybeUninit for zero-cost initialization
  • Direct sol_invoke_signed_c syscall on SBF
let cpi = HopperCpi::<3, 9>::new(token_program_id)
    .account(source, true, false)   // writable, not signer
    .account(dest, true, false)
    .account(authority, false, true) // not writable, signer
    .data(&[3, /* transfer discriminator + amount */]);
cpi.invoke()?;

Structs§

HopperCpi
Stack-allocated CPI call with compile-time-known account count and data size.
HopperCpiBuf
Variable-data CPI builder – const accounts, runtime data length.