Prerequisites
Read the introduction for the roles of a program, Pot and cook. To run the examples, complete the SDK quickstart. The examples use SauceScript globals such asUSDC and pot; only library functions need imports.
The programs target Base and Ethereum. The recorded simulations used a local fork of Base at block 53122981 with the documented release’s contracts and an owner without a Pot. The simulation created a Pot before running each cook. Output is abridged, addresses are shortened and results can differ at another block. These results are simulation evidence, not a record of live transactions.
A payment to several recipients
payout.sauce.ts
recipientsis an array parameter. The CLI takes it as JSON and encodes it after the bytecode withamount.amount * recipients.lengthis checked arithmetic: an overflow reverts the transaction instead of wrapping.requireruns before any transfer. If the Pot holds too little, nothing is paid.for...ofiterates over an array. EachUSDC.transferis a separate token call from the Pot.
to is known only inside the loop. EVM and Solana shows how a Solana program takes such accounts.
Reading a pool
A program can read a protocol and return a value. Running it withsauce simulate gives you the result without sending a transaction.
quote.sauce.ts
UniswapV3.QuoterV2is the chain’s deployment of Uniswap’s QuoterV2. The registry supplies its address and ABI, so the call is typed: its struct parameter is written as a record, and a misspelled or missing field fails the compile.quoteExactInputSinglereturns four values.const [amountOut] = …keeps the first.- A Uniswap V3 fee tier is in millionths:
500is 0.05%,3000is 0.3%. maindeclaresUint256as its return type, so the cook returns one 32-byte word and the CLI decodes it.
--args 10000000000000000, 0.01 WETH is quoted at 23.304536 USDC.
Comparing two pools
best-tier.sauce.ts
quoteis a helper: a top-level function with annotated parameters and return type. It exists because the program quotes twice.interface Quotedeclares a record type.mainreturns one, and the cook returns its fields as one word each.- Both quotes read the pools as they are when the transaction executes, not when it was built.
Swapping on the better pool
swap-best.sauce.ts
@sauce/routeris the SDK’s swap library.uniswapV3takes the pool, the input and output tokens, the input amount, a price limit, the minimum output and the recipient, and returns what the recipient received.minOutis the minimum accepted output, supplied as amainparameter. If the swap returns less,uniswapV3reverts; because this program does not catch the failure, the whole transaction reverts.- The price limit
0sets none, sominOutis the only bound on the price. Security considerations explains when to set one. UniswapV3.Factory.getPoolreads the pool’s address for the chosen fee tier.- A Uniswap V3 pool pays out first and then calls its caller back to be paid. The Pot’s Router answers that callback and pays the pool from the Pot.
@sauce/routerlists which venues work this way.
minOut remains the explicit lower bound on the output.
Supplying the output to Aave
swap-and-supply.sauce.ts
- The swap’s recipient is
pot, the Pot, so the USDC stays in the Pot for the next call. receivedis what the swap returned, the amount the pool reports it paid. The program approves and supplies exactly that amount, so no allowance is left standing after the supply.USDC.approveresets a non-zero allowance to zero before setting the new one, as OpenZeppelin’sforceApprovedoes.AaveV3.Pool.supply(asset, amount, onBehalfOf, referralCode)is Aave’s own function, called by name. Aave mints the aTokens tobeneficiary. Withpotinstead, they would stay in the Pot, and only a later cook could move them.- The
requirefails early with a readable reason.uniswapV3enforces the same floor on the amount the pool reports it paid.
supply then pulled the full 23.304536 USDC.
With minOut at 30 USDC, above both quotes, the same simulation reverts and nothing moves:
What these programs used
Next steps
- Layout of a program: the rules behind the programs above.
- Security considerations: price limits, minimum outputs and approvals.
- Sauce SDK quickstarts: more programs, by task.
