Here is the list of accounts I passed in (the ...
is extra constraints and stuff I removed for readability)
#[derive(Accounts)]
pub struct SendTokens<'info> {
#[account(mut, seeds = [...], bump)]
pub pda: Box<Account<'info, VmData>>,
#[account(mut, seeds=[])],
bump,
token::mint=...,
token::authority=pda,
)]
pub escrow_wallet: Account<'info, TokenAccount>,
#[account()]
pub receiver_1: SystemAccount<'info>,
#[account(mut, ...)]
receiver_1_token_wallet: Account<'info, TokenAccount>,
#[account(mut, ...)]
pub receiver_2: SystemAccount<'info>,
#[account(mut]
pub receiver_2_token_wallet: Account<'info, TokenAccount>,
#[account(mut)]
pub receiver_3_token_wallet: Account<'info, TokenAccount>,
pub token_program: Program<'info, Token>,
}
here is the instruction:
pub fn send_tokens(ctx: Context<SendTokens>) -> Result<()> {
let nonce = ctx.accounts.vm_pda.nonce.to_be_bytes();
let inner_seeds = vec![...];
let seeds = vec![inner_seeds.as_slice()];
let transfer_to_taker_ix = spl_token::instruction::transfer(
&ctx.accounts.token_program.key(),
&ctx.accounts.escrow_wallet.key(),
&ctx.accounts.receiver_1_wallet.key(),
&ctx.accounts.pda.key(),
&[&ctx.accounts.pda.key()],
1,
)?;
msg!("Calling the token program to transfer tokens to the taker...");
anchor_lang::solana_program::program::invoke_signed(
&transfer_to_taker_ix,
&[
ctx.accounts.escrow_wallet.to_account_info().clone(),
ctx.accounts.reciever_1_token_wallet.to_account_info().clone(),
ctx.accounts.pda.to_account_info().clone(),
ctx.accounts.token_program.to_account_info().clone(),
],
&seeds,
)?;
and finally, snippet of the error:
Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account"
"Program log: Calling the token program to transfer tokens to the taker...", "[PDA]'s signer privilege escalated",
some extra information:
- the pda does have authority over the escrow_wallet (checked on solana explorer)
- I also tried to use
anchor_spl::token::Transfer
andCpiContext::new_with_signer()
withanchor_spl::token::transfer(cpi_ctx, 1)?;
(same error) - I am able to use the
anchor_spl::token::transfer(cpi_ctx, amount)?;
to transfer tokens from a user token wallet into a pda owned token (escrow) wallet - there are 3 receivers because I am trying to split the tokens 3 ways, but it doesn't work even when I only have the one transfer