I'm trying to build a program using anchor v0.25.0 that makes calls to Orca's Whirlpools. But whirlpools are built using anchor v0.20.2 and that raises errors when running anchor build.

I found this question that suggests using anchor-gen which is exactly what I need.

However, there is no usage example of how to use anchor-gen. What I did was add a folder at the root of my Anchor project called generated in which I have a subfolder for each external program I want to integrate. Inside these subfolders, there is a small crate that has anchor-gen v0.3.0 as dependency, the corresponding IDL and a src/lib.rs file that uses the generate_cpi_interface or generate_cpi_crate macro called.

The problem I run into is that when I import struct and functions from the generated whirlpool crate, I have an error saying that it is private.

I import the generated crate like this:

use whirlpools::{self, swap, Swap, TickArray, Whirlpool};

And I run into this error:

cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
Error: Function _ZN10whirlpools81_$LT$impl$u20$core..default..Default$u20$for$u20$whirlpools..state..TickArray$GT$7default17hc7fbe4eca82a6568E Stack offset of 9944 exceeded max offset of 4096 by 5848 bytes, please minimize large stack variables
   Compiling test v0.1.0 (programs/test)
error[E0603]: struct `Swap` is private
  --> programs/arb-bot/src/instructions/arb_that_shit.rs:6:24
6  | use whirlpools::{self, Swap, TickArray, Whirlpool};
   |                        ^^^^ private struct
note: the struct `Swap` is defined here
  --> programs/whirlpools/src/lib.rs:10:1
10 | / anchor_gen::generate_cpi_interface!(
11 | |     idl_path = "idl.json",
12 | |     zero_copy(TickArray, Tick),
13 | |     packed(TickArray, Tick)
14 | | );
   | |__^
   = note: this error originates in the macro `anchor_gen::generate_cpi_interface` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0603`.
error: could not compile `arb-bot` due to previous error

What causes this error and how can I fix it?


  • please add the exact error text to your post
    – trent.sol
    Jul 29, 2022 at 23:19

1 Answer 1


The crate needs to be imported like this:

// After
use whirlpools::{
    cpi::{accounts::Swap, swap},
    TickArray, Whirlpool,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.