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:
uniswapV2transfers the WETH to the pair and calls itsswap, andcurveapproves exactlyusdcfor the 3pool to pull inexchange. 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 withminUsdcandminUsdtunder the program’s own revert reasons. The library’sminOutis0because 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, ...),1and2are the 3pool’s coin indices for USDC and USDT, andfalseselects theint128index 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.minUsdt at 2,400 USDT (2400000000), the second leg’s check reverts the cook, the first leg’s swap included:
Next steps
- Oracle-guarded swap: one leg, gated on Chainlink’s price and stopped by a price limit.
- Distributed swap: one order across several price-limited pools.
sauce simulate,sauce run,sauce tx, Names
