amountIn of the Pot’s USDC at the pool Orca.Whirlpool.pool(USDC, WSOL, 4) finds and transfers what the swap returned to to. The cook reverts when the Pot holds less than amountIn, the pool’s price is already past priceLimit, the swap returns less than minOut, or the recipient’s WSOL balance does not rise by what the swap returned.
Target chains: Solana. Use --chain solana. The program does not compile for EVM chains because it uses the Solana-only Orca namespace.
Prerequisites
You need thesauce command (npm install -g @eco-incorp/sauce), a Solana key to send from (a keypair file, or sauce wallet new <name> --solana), and the USDC in the Pot’s USDC token account. --fund is EVM only: transfer the USDC to that token account before running the cook, not to the Pot’s address. sauce pot --chain solana --owner <your-pubkey> prints the Pot’s address; use it as the token account’s owner. See Installation.
Program
pot is the Pot the program runs on, available without declaring it; pot.USDC reads its USDC token account (Names).
solana-swap.sauce.ts
How it works
Orca.Whirlpool.pool(USDC, WSOL, 4)names the pool by its key, the tick spacing, as an EVM program asks a factory for a pool by its fee. Compiling adds the nine accounts a swap at the pool takes (program, pool, config, two vaults, one more account, three tick arrays) tomain, and the command reads them from the pool when it builds the cook, so no account is passed on the command line.priceLimitis USDC base units per WSOL base unit, times 10^18: 110 USDC per SOL is110 × 10^(18 + 6 − 9),110000000000000000.sauce pools --chain solana USDC WSOLprints each pool’s current price with its fee and as apriceLimit.swapreturns 0 and moves nothing when the pool’s price is already pastpriceLimit;require(got > 0, …)turns that into a revert with a reason.spentis measured from the Pot’s USDC balance, because a swap the limit stops early leaves the rest ofamountInin the Pot.sauce compile --jsonmeasures the cook at 4,032 bytes against Solana’s 1,232-byte transaction limit, sosauce runwrites the 3,063-byte program and arguments into a code buffer first and cooks from it.
Run the example
1
Read the pool
found by key: Orca.Whirlpool.pool(USDC, WSOL, 4)), its fee, its liquidity and its price paying USDC, with the fee and as a priceLimit. Set priceLimit above that price by the slippage you accept.2
Compile
--json adds the program’s size, the payload with the arguments, and cook: the cook’s size against Solana’s 1,232-byte limit, 4,032 bytes here, with "fits": false.3
Simulate
--assume-balance USDC:100 gives the Pot’s USDC account 100 USDC in a local LiteSVM copy of the accounts the cook names, read from the cluster; the cook is past one transaction, so the simulation runs there in any case. --owner must be a wallet’s address.4
Send
sauce run creates the Pot and its missing token accounts (asking first, or with --yes; the owner pays their rent), stages the program in a code buffer, sends the cook and closes the buffer. --wallet <name> signs with a Solana wallet instead of --keypair. sauce tx with --owner <your-pubkey> in place of --keypair <keypair> prints the same run as a plan of unsigned transactions for another signer.Simulation result
Simulated on Solana at slot 460260659 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 run closes it.
With priceLimit at 100 USDC per SOL (100000000000000000), below the pool’s price, and --expect-revert "pool skipped":
Next steps
- Distributed swap on Solana: one order over several pools at one price limit
- Quote, swap and supply: the EVM version of choosing a pool before swapping
sauce pools,sauce simulate,sauce run, Names
