amount WETH for USDC, paid to recipient. Venue A, Uniswap V3’s WETH/USDC 0.05% pool with a price limit, runs inside a try block with two checks: at least minOut USDC received, and all of amount sold. When any statement in the block fails, the block is undone and the catch sells on venue B, the Slipstream pool that AerodromeSlipstream.CLFactory keeps at tickSpacing. The cook reverts when B also delivers less than minOut or does not sell all of amount.
Target chains: Base. The program requires Aerodrome Slipstream. Compiling for Ethereum fails (`AerodromeSlipstream.CLFactory` is not deployed on ethereum.).
Prerequisites
Install the Sauce CLI to compile and simulate. To send the transaction, configure a wallet with funds for gas and the Kitchen fee, and provide WETH in your Pot once it is deployed, or through--fund.
Program
pot is the Pot the program runs on, available without declaring it (Names).
try-fallback-swap.sauce.ts
How it works
- The
tryblock holds a swap and tworequires, so it is atomic: when any of them fails, the block’s calls, transfers, storage writes and assignments are undone before the handler runs. That undoes A’s partial fill in the second simulation below, andvenue = 1with it, sovenueis still 2 without the handler assigning it. Work before the block stays: the pool lookups andusdcBefore. - A
tryaround one external call alone is that call’s.catch(): it catches the call’s failure, not its argument evaluation or the decoding of a successful return. The checks sit inside this block, which makes a short or partial fill a failure the handler sees. - The handler itself is not protected: a failure in it reverts the whole cook.
catch { … }discards the revert data;catch (error)would receive at most its first 256 bytes. There is nofinally, andtry/catchis EVM only: Solana has no catch. - Venue B has no price limit (
0), sominOutis the only bound on the price it gives for all ofamount. WETH is token0 on Base, so venue A’ssqrtPriceLimitX96is a floor: selling WETH lowers the pool’s price.
Run the example
1
Set venue A's limit
sqrtPriceLimitX96 for 2,320 USDC per WETH, 3816133648877761641136391, a floor.2
Compile
3
Simulate
--assume-balance WETH:1 gives the Pot 1 WETH for this simulation only. The result lists the venue that sold and the USDC received.4
Send
sauce tx prints the unsigned transaction instead, for your own signer, with the same funding and arguments:Simulation result
Simulated on a local fork of Base at block 53122981 with the current contracts. Nothing was signed or sent; values change with the block.venue: 1): the 0.05% pool (0xd0b5…F224) took the 1 WETH and paid 2,330.328573 USDC to the recipient.
On the same fork, with venue A’s floor at 2,331.50 USDC per WETH (3825580047006472742861822), under the 0.05% pool’s price, which sauce pools listed at 2,331.62 USDC per WETH before its fee:
minOut and short of amount. Inside the try block that fill was undone: the output lists no transfer with the 0.05% pool, venue is 2, and venue B (0xb2cc…DC59) sold the whole 1 WETH for 2,330.630475 USDC.
On the same fork, with minOut at 2,350 USDC, both venues are short and the cook reverts:
Next steps
- Multi-venue route: two venues in sequence, each leg with its own minimum.
- Distributed swap: one order across many pools, each stopped at its own limit.
- Built-ins:
try/catchand.catch(),sauce price,sauce simulate
