The transaction has instructions for paying fee and swapping the SPL token back into the bonding curve. And the user's account did have sol increased and the bonding curve decreased from the sol balance change. But I can't see any instructions to do the transfer.
1 Answer
The withdrawal must be happening from a program-owned account. As such this isn't a traditional transfer
IX that's being called but the authority of an account manipulating its lamport balance.
Check out a similar transaction here, where our WithdrawSol works by modifying the escrow account.
code-wise
As noted, the account you are mutating must be marked as mut
in Anchor
#[account(mut)]
pub wallet: Account<'info, Wallet>,
Also, to note, the sub_lamports
methods are available from version 0.29.0
// transfer amount from program-owned `wallet` account to receiver
wallet.sub_lamports(amount)?;
ctx.accounts.receive.add_lamports(amount)?;
-
Thanks, it resolves my confusion. I also found this solana.stackexchange.com/a/8124/18318. add_lamports is only available after Anchor 0.29.0. Also from Anchor's API I found that the account must be marked as mut docs.rs/anchor-lang/latest/anchor_lang/…– mefor syCommented Jun 6 at 10:42
-