Skip to main content
The program sells 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 try block holds a swap and two requires, 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, and venue = 1 with it, so venue is still 2 without the handler assigning it. Work before the block stays: the pool lookups and usdcBefore.
  • A try around 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 no finally, and try/catch is EVM only: Solana has no catch.
  • Venue B has no price limit (0), so minOut is the only bound on the price it gives for all of amount. WETH is token0 on Base, so venue A’s sqrtPriceLimitX96 is a floor: selling WETH lowers the pool’s price.

Run the example

1

Set venue A's limit

Its “Selling WETH” block gives the 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 A committed (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:
Simulated alone with that floor, venue A sells 0.477530653714293159 WETH for 1,112.834849 USDC and stops, below 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