Skip to main content
The program pays recipient cash of USDC and shares of TSLAx from the Pot and returns what arrived in the recipient’s two token accounts. The cook reverts when the Pot holds less than either amount or the recipient’s USDC account receives less than cash. Target chains: Solana. Use --chain solana; the recorded simulation is described below.

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 and TSLAx in the Pot’s token accounts. --fund is EVM only: transfer each token to its token account owned by the Pot 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 accounts’ owner. See Installation.

Program

pot is the Pot the program runs on, available without declaring it; pot.USDC and pot.TSLAx read its token accounts (Names).
solana-payment.sauce.ts

How it works

  • Both payments are token methods written as on an EVM chain. Compiling adds eight accounts to main, each derived when the cook is built: the Pot, its USDC and TSLAx accounts, the recipient’s two, SPL Token, Token-2022 and TSLAx’s mint. USDC moves by SPL Token’s transfer; TSLAx, a Token-2022 mint, by the checked transfer with its 8 decimals and the mint as one more account.
  • recipient.USDC and recipient.TSLAx read the recipient’s associated token account for each mint. Each is read before and after its transfer: USDC is required to arrive in full, and sharesReceived is returned as measured, because a Token-2022 mint with a transfer fee delivers the amount less the fee.
  • After each transfer the token method checks that the account it paid belongs to recipient, and reverts with wrong recipient account otherwise.
  • sauce compile --json measures the cook at 2,292 bytes against the 1,232-byte limit, so sauce run stages the 1,653-byte payload in a code buffer. The recipient had no TSLAx account: the simulation made it empty, and sauce run creates it before the cook, the owner paying its rent.

Run the example

1

Compile

--json lists the eight accounts in manifest, each with its derive, and cook: 2,292 bytes against the 1,232-byte limit, "fits": false.
2

Simulate

The two --assume-balance flags give the Pot 1 USDC and 1 TSLAx in a local LiteSVM copy of the cook’s accounts, read from the cluster. --owner must be a wallet’s address.
3

Send

sauce run creates the Pot and the missing token accounts the cook names (asking first, or with --yes), stages the program, sends the cook and closes the buffer. --wallet <name> signs with a Solana wallet instead. sauce tx with --owner <your-pubkey> in place of --keypair <keypair> prints the run as a plan of unsigned transactions for another signer.
recipient 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 460260738 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.
Both amounts arrived in full: 1 USDC and 0.5 TSLAx, so TSLAx withheld no transfer fee. The other 0.5 TSLAx the simulation assumed stays in the Pot. Asking for 2 TSLAx (200000000) with 1 in the Pot, and --expect-revert "not enough TSLAx in the Pot":

Next steps