4

Relating to a previous question: LINK, which covered SOL -> WSOL.

I am building an anchor program that transfers Tokens from one account to another (input and output):

pub struct Payment<'info> { 
    #[account(mut)]
    pub input_token_account: Account<'info, TokenAccount>
    pub output_token_account: Account<'info, TokenAccount>
    ...

}

Although, how would I be able to transfer WSOL from anchor-program-side to SOL user-side. That is, user can request e.g. 2 WSOL from program and get back the equivalent 2 SOL?

I know that you can close the WSOL account as a final instruction, but that just seems like a bad idea since you would be closing the ENTIRE WSOL account and not just the requested 2 SOL

1 Answer 1

9

There is no other way than closing a wrapped SOL token account to recover the SOL inside it, there is no "transfer x wSOL" capability in the token program.

However, there is a trick to perform if you want to unwrap only a certain amount of wrapped SOL.

The sequence:

  • Create a temporary wSOL token account
  • Transfer X amount from wSOL main token account to temporary wSOL
  • Close temporary wSOL token account into recipient

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.