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().sqrtPriceX96and converts it to USDC base units per WETH. TheWETH < USDCcomparison picks the formula, because the pool orders its tokens by address and that order differs between chains. - A skipped tick returns
spent: 0instead 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. spentandboughtare the changes in the Pot’s USDC and WETH balances. The finalrequirechecks 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
--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 withpriceLimit 2,500 USDC. Nothing was signed or sent.
priceLimit set to 1,000 USDC, under the market, the tick skips:
Next steps
- Stop-loss and take-profit: sell the WETH the plan accumulates when an oracle price crosses a threshold.
- Buy the dip: buy a tranche only after the oracle price falls a set percentage.
- Rebalance: hold WETH and USDC at a target share of value.
- Sweep the Pot: move what the Pot holds to a wallet.
sauce simulate,sauce tx, The Pot.
