Skip to main content
Each run spends up to tranche of the Pot’s USDC on WETH in Uniswap V3’s 0.05% WETH/USDC pool, as long as one WETH, fee included, costs at most priceLimit. When the price is above the limit or the Pot holds less than a tranche, the run returns without trading. The cook reverts when the pool does not exist or the average price paid exceeds priceLimit. Target chains: Base and Ethereum. The same source compiles for both; the recorded simulation uses a Base fork. This program evaluates conditions only when called. To run it repeatedly, use an external scheduler or caller that submits an authorized transaction.

Prerequisites

Install the Sauce CLI to compile and simulate. To send the transaction, configure a wallet with native coin for gas and the Kitchen fee. Fund the Pot once it is deployed, or use --fund; it needs at least tranche USDC when you run the program.

Program

pot is the Pot the program runs on, available without declaring it; pot.USDC and pot.WETH are its balances (Names).
dca.sauce.ts

How it works

  • The program reads the pool price from slot0().sqrtPriceX96 and converts it to USDC base units per WETH. The WETH < USDC comparison picks the formula, because the pool orders its tokens by address and that order differs between chains.
  • A skipped tick returns spent: 0 instead of reverting, so a scheduler that runs it every hour sees a successful cook. A skipped tick still costs gas and the Kitchen’s fee, which the cook pays in ETH.
  • The swap’s price limit is the sqrt price at which WETH, after the 0.05% fee, costs priceLimit. The pool stops filling there, so a tranche can be filled in part; the unspent USDC stays in the Pot for the next tick.
  • spent and bought are the changes in the Pot’s USDC and WETH balances. The final require checks the average price from those, independent of the router’s return value.

Run the example

1

Compile

2

Simulate

--assume-balance USDC:250 gives the Pot 250 USDC for this simulation only. The result lists the pool price the tick read and what the Pot spent and received.
3

Send

Add --fund USDC:250 to pull the tranche from your wallet into the Pot in the same cook. sauce tx dca.sauce.ts --chain base --owner <your-address> --args 250000000 2500000000 prints the unsigned transactions instead, for your own signer or scheduler.

Simulation result

Simulated on a local fork of Base at block 53159700 with the current contracts, a tranche of 250 USDC with priceLimit 2,500 USDC. Nothing was signed or sent.
The pool priced WETH at 2,327.204378 USDC, under the limit, so the tick bought. It spent the whole 250 USDC for 0.10737069914367198 WETH, an average of about 2,328.38 USDC per WETH with the 0.05% fee included. The WETH stays in the Pot. On the same fork, with priceLimit set to 1,000 USDC, under the market, the tick skips:
The cook succeeds and no token moves; the only transfer is the Kitchen’s fee in ETH. The 250 USDC stays in the Pot.

Next steps