lamports of SOL from the owner to the Pot’s WSOL account and has SPL Token count them as WSOL. The cook reverts when the owner holds less than lamports or the Pot’s WSOL balance does not rise by exactly lamports.
Target chains: Solana. Use --chain solana; the recorded simulation is described below.
Prerequisites
You need thesauce command (npm install -g @eco-incorp/sauce), a Solana key holding the SOL to wrap (a keypair file, or sauce wallet new <name> --solana). See Installation.
Program
solana-wrap-sol.sauce.ts
How it works
- No token method wraps SOL, so the program makes the two calls itself with
svm.call: the System Program’s transfer (instruction 2 as 4 bytes, then the lamports as 8 little-endian bytes), signed by the owner, then SPL Token’s SyncNative (instruction 17,hex`11`). - Each account is written where it is used:
WSOL.accountOf(pot).writable(),pot.owner.writable().signer(),Account.systemProgram,Account.tokenProgram. Compiling adds five accounts tomain, each derived, so the command is given none. accountOfnames an account that exists: its check reads the Pot’s WSOL account when the program starts, andsauce runcreates a missing one before the cook.- The program reads
pot.WSOLonce after the calls and returns both values from that read. That keeps the cook at 1,173 of 1,232 bytes, small enough that one transaction also creates a new Pot ahead of the cook.
Run the example
1
Compile
--json output gives the program’s size, the payload with the argument, and the cook against Solana’s transaction limit:2
Simulate
--assume-balance WSOL:0 runs the cook in a local LiteSVM copy of the cook’s accounts, read from the cluster, with the Pot’s WSOL account made empty where it does not exist, as sauce run creates it before the cook. The owner must hold the lamports.3
Send
--wallet <name> signs with a Solana wallet instead. sauce tx with --owner <your-pubkey> in place of --keypair <keypair> planned two steps for a new Pot: a setup transaction that creates the Pot’s WSOL account, then one transaction that creates the Pot and runs the cook.Simulation result
Simulated on Solana at slot 462066340 with the command above, in a local LiteSVM copy. Nothing was signed or sent; values change with the slot. Lines that name the owner are left out.sauce tx plans the sent cook without one, as above.
Asking to wrap 100,000 SOL (100000000000000), more than the owner holds, at slot 462066347:
Next steps
- Solana swap: spend the Pot’s tokens at an Orca whirlpool
- Solana payment: pay tokens from the Pot with token methods
- Builtins, Pot,
sauce simulate
