I am trying to transfer tokens in a PDA and withdraw from that program, deposit works fine but it throws the error when I withdraw.
pub fn withdraw_token(
ctx: Context<TokenPaymentAccounts>,
bump: u8,
currency: String,
) -> Result<()> {
let bump = &[bump][..];
let binding = [&[bump][..]];
let program_data_account = &mut ctx.accounts.program_data;
let mint = &ctx.accounts.mint;
if ctx.accounts.signer.key().ne(&program_data_account.owner) {
return err!(Error::InvalidAdmin);
}
transfer_checked(
CpiContext::new(
ctx.accounts.token_program.to_account_info(),
TransferChecked {
authority: ctx.accounts.program_pda.to_account_info(),
from: ctx.accounts.program_token_account.to_account_info(),
to: ctx.accounts.user_token_account.to_account_info(),
mint: mint.to_account_info(),
},
)
.with_signer(&binding),
program_data_account.total_usdc,
mint.decimals,
)?;
program_data_account.total_usdc = 0
Ok(())
}
#[derive(Accounts)]
#[instruction(bump: u8)]
pub struct TokenPaymentAccounts<'info> {
#[account(
mut,
seeds = [PROGRAM_DATA_SEED, ID.key().as_ref()],
bump = program_data.bump
)]
pub program_data: Account<'info, ProgramData>,
#[account(
mut,
token::mint = mint,
token::authority = program_pda
)]
pub program_token_account: Account<'info, TokenAccount>,
#[account(
mut,
token::mint = mint,
token::authority = signer
)]
pub user_token_account: Account<'info, TokenAccount>,
pub mint: Account<'info, Mint>,
/// CHECK: Program PDA
#[account(
mut,
seeds = [PROGRAM_PDA_SEED],
bump = bump
)]
pub program_pda: UncheckedAccount<'info>,
#[account(mut)]
pub signer: Signer<'info>,
pub token_program: Program<'info, Token>,
pub system_program: Program<'info, System>,
}```