Skip to main content
The program asks Uniswap’s QuoterV2 what the 0.05% and the 0.3% WETH/USDC pools would pay for amount WETH. It swaps on the pool with the higher quote, then supplies every USDC the swap delivered to Aave V3 for beneficiary. If the better quote or the swap returns less than minUsdc, or the supply fails, the cook reverts and nothing moves. Target chains: Base. The example uses UniswapV3.QuoterV2, UniswapV3.Factory and AaveV3.Pool.

Prerequisites

Install the Sauce CLI to compile and simulate. To send the transaction, configure a wallet with WETH for the program and native coin for gas and the Kitchen fee.

Program

pot is the Pot the program runs on, available without declaring it (Names).
quote-swap-supply.sauce.ts

How it works

  • The pool is chosen inside the transaction. Both quotes read the pools in the same state the swap then trades against, so no other transaction can land between the quote and the swap.
  • uniswapV3 gets a price limit of 0, so minUsdc is the only bound on the price. Set it from a fresh quote, such as the simulation below, minus the slippage you accept.
  • received is the change in the Pot’s USDC balance, not a return value. The program approves and supplies exactly that amount, then checks that the Pot’s USDC is back where it started.
  • supply credits beneficiary, Aave’s onBehalfOf, so the aUSDC belongs to that account. If it is an external account, a later cook on this Pot cannot withdraw it. If you pass the Pot’s own address, the Pot holds the aUSDC and a later cook can withdraw it.

Run the example

1

Compile

2

Simulate

--assume-balance WETH:1 gives the Pot 1 WETH for this simulation only. If your Pot is not deployed yet, the simulation deploys it first.
3

Send

--fund WETH:1 pulls 1 WETH from your wallet into the Pot in the same cook. To sign with your own wallet instead, print the unsigned transactions: the Pot’s deployment when it has no code yet, the WETH transfer into the Pot, then the cook.

Simulation result

Simulated on a local fork of Base at block 52965104 with the current contracts, with owner 0xf39F…2266 and beneficiary 0x7099…79C8. Nothing was signed or sent; the numbers change with the block.
The 0.05% pool quoted 2,380.895733 USDC and the 0.3% pool 2,378.922144, so the program swapped on the 0.05% pool (0xd0b5…F224). The swap delivered exactly the quoted amount, and all of it went to Aave. The beneficiary received 2,380.895732 aBasUSDC, one base unit less than the USDC supplied. The cook used 585,616 gas, and the cook’s value paid the Kitchen’s execution fee. On the same fork, with minUsdc set to 2,500 USDC, the cook reverts before any swap:

Next steps