I am trying to unwrap SOL from a WSOL account and then initialize the token account again.
I am creating the account like so
pub authority_pda: UncheckedAccount<'info>,
#[account(
init,
payer = payer,
token::mint = mint,
token::authority = authority_pda,
)]
pub token_account: Account<'info, TokenAccount>,
To unwrap I close the account
anchor_spl::token::close_account(program_unwrap_wsol_context.with_signer(&[&[AUTH_SEED.as_bytes(), &[bump]][..]]))?;
Then I transfer part of the unwrapped amount (didnt include code). Then I transfer the rent amount to to the WSOL account I closed earlier.
anchor_lang::system_program::transfer(program_to_program_account_context.with_signer(&[&[AUTH_SEED.as_bytes(), &[bump]][..]]), account_rent)?;
And then I try to recreate the token account.
let program_open_wsol_account_context = CpiContext::new(
ctx.accounts.token_program.to_account_info(),
anchor_spl::token::InitializeAccount3 {
account: ctx.accounts.intermediate_wsol_account.to_account_info(),
mint: ctx.accounts.wsol_mint.to_account_info(),
authority: ctx.accounts.intermediate_authority.to_account_info()
}
);
anchor_spl::token::initialize_account3(program_open_wsol_account_context.with_signer(&[&[AUTH_SEED.as_bytes(), &[bump]][..]]))?;
Everything works except for the initialize_account3 instruction. I get this error in the logs.
"Program log: Instruction: InitializeAccount3",
"Program log: Error: InvalidAccountData",
What am I doing wrong?