Skip to main content
The program buys SPCXon, Ondo’s tokenized SpaceX on Ethereum, with up to 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.getPool for 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.
  • priceLimit is USDC per share with the fee included. The program turns it into the pool’s sqrt price at priceLimit * (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.
  • spent is the Pot’s USDC balance change, and only budget - spent goes to refundTo; other USDC in the Pot stays. shares is what recipient received, compared with minShares.
  • 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 with SPL.

Run the example

1

Read the pools

It lists each pool’s price per share with and without its fee. Set 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 fork sauce 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.
The program chose the 0.3% pool (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:
Both results, and the prices above, are from the fork at block 26278321. The pools’ prices move with every trade, so at another block 149.00 can be above the cheapest pool’s price with its fee, and the same command then buys instead of reverting. Read sauce pools at the block you simulate on and set the limit from the prices it lists.

Next steps