You can wrap Sol into a wrapped sol Token via the SPL Token program. From there you can use the Wrapped SOL like any SPL Token. Here is a pretty good example
https://github.com/project-serum/serum-dex-ui/blob/5b4487634e3738c57ace6da1377704e95f53c588/src/pages/pools/PoolPage/PoolAdminPanel.tsx#L250-L272
const wrappedSolAccount = new Account();
transaction.add(
SystemProgram.createAccount({
fromPubkey: wallet.publicKey,
lamports: parsedQuantity + 2.04e6,
newAccountPubkey: wrappedSolAccount.publicKey,
programId: TokenInstructions.TOKEN_PROGRAM_ID,
space: 165,
}),
TokenInstructions.initializeAccount({
account: wrappedSolAccount.publicKey,
mint: TokenInstructions.WRAPPED_SOL_MINT,
owner: wallet.publicKey,
}),
TokenInstructions.transfer({
source: wrappedSolAccount.publicKey,
destination: vaultAddress,
amount: parsedQuantity,
owner: wallet.publicKey,
}),
TokenInstructions.closeAccount({
source: wrappedSolAccount.publicKey,
destination: walletTokenAccount.pubkey,
owner: wallet.publicKey,
}),
);
So essentially what it's doing here is
- Create a random account where you can deposit some SOL into and deposit the amount required plus the rent amount (hence parsedQuantity + 2.04e6)
- Use the token program to initialise the account as a WRAPPED_SOL_ACCOUNT
- Transfer the wrapped SOL (or in your case, you may just want to call the program and put the wrapped SOL account as a parameter)
- Close the Wrapped SOL account so that the user gets back their rent