Skip to main content
edited tags
Link
Source Link
Whiteseal
  • 3.6k
  • 3
  • 22

Account:try_from with different Anchor versions

I have a program which is on 0.28.0, and it uses an 0.26.0 dep. It builds without issue. Let's say the deps look like:

[dependencies]
anchor-lang = "0.28.0"
solana-program = "=1.16.23"

#This is an anchor 0.26.0 project (solana program 1.14.x)
whirlpool = { git = "https://github.com/orca-so/whirlpools", rev = "7f7ee90", features = ["cpi"] }

Now I have an account I want to load from the dep:

pub clp_pool: UncheckedAccount<'info>,

In my handler I can do:

let acc: Account<'info, whirlpool::state::Whirlpool> = Account::try_from(&clp_pool)?;

This works great if my program is on 0.26.0, but if I am on 0.28.0, it fails with the trait bound whirlpool::state::Whirlpool: anchor_lang::AccountSerialize is not satisfied perhaps two different versions of crate anchor_lang are being used?, probably because of the borsch changes in solana-program.

How can I get this 0.26.0 account to deserialize in 0.28.0?

Note that the account is not repr(C) so I can't bytemuck it. Also, if I downgrade to 1.14.28 (which would be the default if I didn't lock the version to 1.16.23), I'll get the Invoked an instruction with data that is too large (12884933804 > 10240) error because of those changes.