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 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 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.USDCandrecipient.TSLAxread the recipient’s associated token account for each mint. Each is read before and after its transfer: USDC is required to arrive in full, andsharesReceivedis 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 withwrong recipient accountotherwise. sauce compile --jsonmeasures the cook at 2,292 bytes against the 1,232-byte limit, sosauce runstages the 1,653-byte payload in a code buffer. The recipient had no TSLAx account: the simulation made it empty, andsauce runcreates 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
--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.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.200000000) with 1 in the Pot, and --expect-revert "not enough TSLAx in the Pot":
Next steps
- Pay: one USDC payment from the Pot on Base, Ethereum or Arc
- Buy a tokenized stock: buying a stock token on Ethereum
- Wrap SOL: calls into the System Program and SPL Token with the accounts written out
- Tokens,
sauce pot,sauce simulate
