Skip to main content
The program buys WSOL with 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 the sauce 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) to main, and the command reads them from the pool when it builds the cook, so no account is passed on the command line.
  • priceLimit is USDC base units per WSOL base unit, times 10^18: 110 USDC per SOL is 110 × 10^(18 + 6 − 9), 110000000000000000. sauce pools --chain solana USDC WSOL prints each pool’s current price with its fee and as a priceLimit.
  • swap returns 0 and moves nothing when the pool’s price is already past priceLimit; require(got > 0, …) turns that into a revert with a reason. spent is measured from the Pot’s USDC balance, because a swap the limit stops early leaves the rest of amountIn in the Pot.
  • sauce compile --json measures the cook at 4,032 bytes against Solana’s 1,232-byte transaction limit, so sauce run writes the 3,063-byte program and arguments into a code buffer first and cooks from it.

Run the example

1

Read the pool

The listing names each pool’s key (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.
to is a wallet’s public key. A token account given there is taken as a wallet, and the cook pays an associated token account it holds, which no one can spend from.

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.
The swap spent all 100 USDC and the recipient’s WSOL account received 0.96104422 WSOL, about 104.05 USDC per SOL, inside the 110 limit. The full output also lists what a first run on a new Pot costs the owner: 0.073099792 SOL in all, of which the code buffer’s 0.0173228 SOL comes back when sauce run closes it. With priceLimit at 100 USDC per SOL (100000000000000000), below the pool’s price, and --expect-revert "pool skipped":

Next steps