Skip to main content
The program sells amount WETH for USDC on the Uniswap V2 WETH/USDC pair, then exactly the USDC that leg delivered for USDT in Curve’s 3pool, paid to recipient, and returns each leg’s output. The cook reverts when the pair is missing, the first leg delivers less than minUsdc, the recipient receives less than minUsdt, or either leg leaves its input token in the Pot. Target chains: Ethereum. The recorded simulation uses an Ethereum fork.

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).
multi-venue-route.sauce.ts

How it works

  • Both venues are paid before they swap: uniswapV2 transfers the WETH to the pair and calls its swap, and curve approves exactly usdc for the 3pool to pull in exchange. A paid-first swap spends its whole input or reverts, and each leg checks the Pot’s input balance afterwards (leg 1 left WETH in the Pot, leg 2 left USDC in the Pot).
  • Each leg’s output is a measured balance change, the Pot’s USDC and then recipient.USDT, compared with minUsdc and minUsdt under the program’s own revert reasons. The library’s minOut is 0 because the program checks the measured amount in the same cook.
  • The second leg sells usdc, what the first leg delivered, not the Pot’s USDC balance, so USDC the Pot held before the cook is not sold.
  • In curve(Curve.ThreePool, USDC, USDT, usdc, 1, 2, false, ...), 1 and 2 are the 3pool’s coin indices for USDC and USDT, and false selects the int128 index form of a StableSwap pool.

Run the example

1

Compile

2

Simulate

--assume-balance WETH:1 gives the Pot 1 WETH for this simulation only. The result lists each leg’s output and every transfer the cook made.
3

Send

--fund WETH:1 pulls 1 WETH from the wallet into the Pot in the same cook. 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 Ethereum at block 26278321 with the current contracts. Nothing was signed or sent; values change with the block.
The first leg sold 1 WETH to the pair (0xB4e1…C9Dc) for 2,319.192518 USDC, and the second sold all of it in the 3pool for 2,321.732711 USDT, paid to the recipient. The Pot’s net change is the 1 WETH sold; the 3pool’s approval is the exact USDC it pulled. On the same fork, with minUsdt at 2,400 USDT (2400000000), the second leg’s check reverts the cook, the first leg’s swap included:

Next steps