Execution on Uniswap

Orders that pass the risk engine become swaps on Uniswap v3 through the Universal Router, with tokens pulled by Permit2. The executor is engine/exec-live.mjs. It has no admin function and no way to send ETH or tokens anywhere except through these paths.

The pools

StockPoolFee
NVDA0xd4EB21209C4D6093f80B5b84f5C45cc093EA14a30.05%
AAPL0xAae0d815EE56e4092a5E5C2911E676Fea50B2d6D0.05%
MSFT0xeb60bCD1D920ad6E102690CCFC6fB488899E15100.3%
TSLA0xf4ACdAEEB7022862A763C9B1B885e11191c889E30.3%

Each pool trades the stock against USDG (0x5fc5360d0400a0fd4f2af552add042d716f1d168, 6 decimals). In three of the four pools USDG is token0, in TSLA it is token1: the price maths handles both and the tests check both. ETH is priced through the WETH/USDG pool and converted through its 0.05% pool.

One swap

  1. Approve the token to Permit2 once (maximum), and give the Universal Router a Permit2 allowance (30 days, renewed when it runs low).
  2. Send UniversalRouter.execute with the command V3_SWAP_EXACT_IN: recipient, amount in, minimum amount out, the path (token, fee, token) and payerIsUser = true.
  3. Measure the result from the wallet balances before and after.

The minimum out is the spot price times the pool fee times (1 - slippagePct). If the pool moved by more than that between the decision and the block, the swap reverts and costs only gas.

The deployed Universal Router decodes a sixth, trailing argument for swaps, an array of per-hop minimum prices. Without it the call reverts with SliceOutOfBounds. The engine sends an empty array, which means no extra per-hop check; amountOutMin is the guard.

Fills are measured, not assumed

The fill that goes into the ledger is the balance delta: how much USDG left, how much stock arrived. The price in the journal is the real average price of that swap. If a swap fails the cycle logs a RISK line and the ledger is untouched.

Guards in the executor

ETH to USDG and back

When fees are claimed, the share that goes to the book is wrapped and swapped in one transaction (WRAP_ETH then V3_SWAP_EXACT_IN, paid with the transaction value). For a buyback, USDG is swapped to WETH inside the router and unwrapped to the wallet (UNWRAP_WETH) before the coin is bought on its curve.

How it was tested

tests/fork-live.mjs runs the live executor against a local fork of the chain (real router, real Permit2, real pools, test money) and checks: the buy price against the pool, the balance delta against the reported fill, the inverted TSLA pool, a full sell with no dust, the refusal of an order above the book cash, and both ETH conversions.