I am working on a program that invokes drift.
It all works fine, just adding assertions now.
I have changed this account:
#[account(mut)]
pub user_stats: AccountInfo<'info>,
To this:
#[account(
mut,
seeds = [b"user_stats", drift_adapter.key().as_ref()],
bump,
seeds::program = main.stored_program_id
)]
pub user_stats: AccountInfo<'info>,
user_stats
is an account required for most of drift calls, it is derived from the PDA that deposits SPL tokens into drift.
After adding that validation everything breaks, and in a weird way.
This is the error I receive:
'Instruction references an unknown account 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d',
And after narrowing it down it refers to the account drift_vault
which should have the pubkey JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw but for some reason it thinks it receives 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d.
Seems like an easy enough case of providing the wrong account, but logging in tests all accounts before providing them shows that I am provided correct account. Additionally there is no account 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d at all being derived, initialised or otherwise used.
Test log:
console.log("driftVault:", driftVault.toBase58());
shows:
driftVault: JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw
But in the contract, the very first log:
msg!("drift vault {:?}", accounts.drift_vault.key());
shows:
'Program log: drift vault 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d',
So right now, it seems to be that adding a PDA validation somehow swaps out what account is provided?
It really doesn't make much sense to me. Removing the validation allows for everything to go through. I will probably rederive the account myself instead of using a macro or store it hardcoded.
Has anyone else encountered something similar? I can't share much more code because this is a proprietary and unpolished contract, but any advice would be appreciated.
Thanks
'Program log: drift vault 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d',
) when validation fails on sending the transaction. How it is? B) My first tip would be that the8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d
is the address derived from theseeds = [b"user_stats", drift_adapter.key().as_ref()]
and the programmain.stored_program_id
and that's the address that mentioned to be expected while a different address is passed in.stored_program_id
match to what you expect?