I have a buy instruction for a token which initializes the user's token in the context and it runs absolutely fine the first time I run / call it. But on subsequent calls I get the following error:
1) learning.solana
Second Buy:
Error: Transaction resulted in an error.
Error processing Instruction 0: Provided owner is not allowed. Logs:
[
"Program xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx invoke [1]",
"Program log: Instruction: Buy",
"Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [2]",
"Program log: Create",
"Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 3459 of 188205 compute units",
"Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: Provided owner is not allowed",
"Program xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx consumed 15254 of 200000 compute units",
"Program xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx failed: Provided owner is not allowed"
].
Catch the `SendTransactionError` and call `getLogs()` on it for full details.
at sendWithErr (node_modules/anchor-bankrun/src/index.ts:77:10)
at BankrunProvider.sendAndConfirm (node_modules/anchor-bankrun/src/index.ts:158:3)
at MethodsBuilder.rpc [as _rpcFn] (node_modules/@coral-xyz/anchor/src/program/namespace/rpc.ts:29:16)
This is my context:
#[derive(Accounts)]
pub struct BuyContext<'info> {
#[account(mut)]
pub user: Signer<'info>,
#[account(
seeds = [GLOBAL_SEED_PREFIX.as_bytes()],
bump,
)]
pub global: Account<'info, GlobalState>,
#[account()]
pub mint: Account<'info, Mint>,
#[account(
mut,
seeds = [BONDING_CURVE_SEED_PREFIX.as_bytes(), mint.to_account_info().key.as_ref()],
bump,
)]
pub bonding_curve: Account<'info, BondingCurve>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = bonding_curve,
)]
pub bonding_curve_token_account: Account<'info, TokenAccount>,
#[account(
init,
payer = user,
associated_token::mint = mint,
associated_token::authority = user,
)]
pub user_token_account: Account<'info, TokenAccount>,
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
pub associated_token_program: Program<'info, AssociatedToken>,
}
I have a sell
instruction that has basically an identical struct that does work. The only diff is the init
vs mut
... so it must have something to do with that.
Diff screen shot.
Note: The buy definitely does work the first as in my test I query the token account balance and it has the appropriate number of tokens.