I have Googled about this and only found how to send tokens via command line:
But I need to stake/withdraw Native SOL, not tokens, into/from Rust programs.
Also I found this about Rust native token:
https://docs.rs/solana-program/1.7.10/solana_program/native_token/index.html
https://docs.rs/solana-program/1.7.10/solana_program/native_token/struct.Sol.html
It seems I have to declare this Sol struct
pub struct Sol(pub u64);
Then use its "send" trait to send it... right? Could somebody explain how to do this via Rust programs?
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
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