budget of the Pot’s USDC. It reads every Uniswap V3 fee tier of the pair, swaps on the pool whose share costs least with its fee paid, and stops where a share would cost more than priceLimit. The shares go to recipient and the USDC the pool did not take goes to refundTo. The cook reverts when no pool has liquidity, every pool is at or above priceLimit, or the recipient receives fewer than minShares.
Target chains: Ethereum. The example uses SPCXon (18 decimals); inspect the registry with sauce globals --chain ethereum --search spacex.
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 USDC in your Pot once it is deployed, or through--fund.
Program
pot is the Pot the program runs on, available without declaring it (Names).
buy-tokenized-stock.sauce.ts
How it works
- The loop asks
UniswapV3.Factory.getPoolfor the 100, 500, 3000 and 10000 tiers, skips a missing pool or one with no liquidity, and compares the rest by price with the fee on top,price * 1000000 / (1000000 - tier). A 1% pool with a lower mid price can lose to a 0.3% pool with a higher one. priceLimitis USDC per share with the fee included. The program turns it into the pool’s sqrt price atpriceLimit * (1 - fee). USDC is token0 on Ethereum, so paying it lowers the pool’s price and the limit is a floor: the pool stops there and the Router pays it only for what it filled.spentis the Pot’s USDC balance change, and onlybudget - spentgoes torefundTo; other USDC in the Pot stays.sharesis whatrecipientreceived, compared withminShares.require(cheapest < priceLimit, ...)refuses a limit at or below the chosen pool’s current price with its fee. Without it the limit would sit on the wrong side of the pool’s price and the pool would revert withSPL.
Run the example
1
Read the pools
priceLimit above the cheapest one.2
Compile
3
Simulate
--assume-balance USDC:5000 gives the Pot 5,000 USDC for this simulation only. The result lists the fee tier chosen, the USDC spent and the shares bought.4
Send
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. On the forksauce pools listed two pools with liquidity: the 0.3% pool at 149.129 USDC a share with its fee, and the 1% pool at 151.64.
fee: 3000). It stopped at the 149.40 limit after 3,257.687265 USDC, for 21.824931125703120628 SPCXon paid to the recipient, and the other 1,742.312735 USDC went to refundTo.
On the same fork, a priceLimit of 149.00 USDC (149000000) is below the 0.3% pool’s price with its fee, and the cook reverts before any swap:
sauce pools at the block you simulate on and set the limit from the prices it lists.
Next steps
- Distributed swap: a limit buy spread over the pools
sauce poolslists for a pair on Base’s Aerodrome Slipstream, Uniswap V3, PancakeSwap V3 and hookless Uniswap V4. - Tokens: the tokenized stocks each chain registers.
sauce pools,sauce globals,sauce simulate
