Engine
Smart order routing
How the engine decides where a MOTION trade fills. The Ascend pool, the HyperCore order book, or a split across both, with a cost report for every order.
| Code | engine/src/router/ (router.ts, curve.ts) |
| Used by | Ascend pool making |
| Venues | The token's Ascend pool (MOTION-HYPE) and its HyperCore spot book (MOTION-USDC) |
| Today | One venue. MOTION has no HyperCore market yet, so every order is a single pool swap |
A strategy does not say "swap on Ascend". It says what it wants, spend $60 on MOTION or sell 20,000 MOTION, with the worst price it accepts, and the router decides where the order fills.
The router is not a strategy: it has no capital, no tick and no P&L of its own. Fills still belong to the strategy that asked.
What happens to an order
- Check which venues are usable. The Ascend pool, and the HyperCore book once
MOTION_HL_COINis set. A venue is left out if its data is stale (pool price older than 60 s, book older than 15 s) or if the side of the book the order needs is empty. - Price each venue with executable numbers. Ascend's on-chain quoter is asked for exact sizes: once when the pool is the only venue, at 25 %, 50 %, 75 % and 100 % of the order when a split is possible. HyperCore's book is walked level by level. Fees are inside both: the pool fee is in the quote, HyperCore's spot taker fee (7 bps) is added.
- Find the pool's depth. The quoter refuses a size the pool cannot take whole. That is not an error, it is how deep the pool is. See Pool depth.
- Cap each venue at what the vault can use there. See Limits. Nothing is bridged in the middle of a trade.
- Split the order. It is cut into
ROUTER_SLICESequal slices (default 20, so each decision moves 5 % of the order). Each slice goes to the venue that returns the most for it at that point. Because every venue gets worse as it fills, this equalises the marginal price across venues, which is the best split. - Keep it simple unless splitting pays. If two legs beat the best single venue by less than
ROUTER_MIN_IMPROVEMENT_BPS(default 5 bps), the whole order goes to that single venue. - Refuse a bad price. If the best all-in average price is worse than the strategy's limit, nothing is sent and the order is recorded as
rejected. - Send the legs together, each with its own worst case. See Execution.
- Write a cost report. See The cost report.
With one venue the same path runs with a single leg, so every token trade gets the same checks and the same report.
Limits
| Venue | Buying (input is USD) | Selling (input is tokens) |
|---|---|---|
| Ascend | 90 % of the HYPE on Elysium, and never more than the Treasury's per-call limit or what is left of its daily limit | The tokens held on Elysium |
| HyperCore | 95 % of the free USDC: the balance minus perp margin (a third of the perp's notional, as the hedge keeps) and minus USDC promised to resting bids | The tokens held on HyperCore |
On both venues the leg is also capped at what the venue can fill: the pool's depth, and the size resting in the book.
A leg also has a minimum size: 0.01 HYPE on Ascend (a smaller swap is not worth its gas) and $10 on HyperCore (Hyperliquid rejects smaller orders). A leg under its venue's minimum is handed to the other venue if that one has room. Otherwise that part of the order stays unfilled. A venue whose cap is under its minimum is left out of the order.
Pool depth
The quoter refuses any trade the pool cannot take whole:
- A sell is paid from the HYPE in the pool. A pool at or near its launch price holds little or none, so it cannot take sells.
- A buy cannot go past the top of the pool's curve.
When a size is refused, the router asks again at smaller sizes (50 %, 25 %, 10 % and 4 % of the smallest size that failed, never under the 0.01 HYPE minimum) and caps the pool at the largest size it could quote. If no size at or above the minimum can be quoted, the pool is left out of this order, with the reason the pool cannot take a sell of this size right now. The strategy waits and tries again on a later tick.
Execution
| Venue | How the leg is sent | Worst case |
|---|---|---|
| Ascend | The pool is quoted again at the leg's exact size, then swapped | minOut = the fresh quote minus ROUTER_MAX_SLIPPAGE_BPS (default 100 bps, so 99 %) |
| HyperCore | One immediate-or-cancel order | A limit at the deepest price the plan reaches, plus the same tolerance. What does not fill inside it is cancelled |
Legs go out at the same time. One leg failing does not undo the other: the order is then reported as partial, with the error of the leg that failed.
In live mode the pool leg is simulated before it is sent. If the contracts would refuse it (the swap adapter's price guard or sell caps, the Treasury's HYPE limits, a pause), nothing is sent, no gas is spent, and the leg's error says why in words. See Risk controls.
The cost report
Every order produces one, filled or not.
| Field | Meaning |
|---|---|
status | filled, partial, rejected (never sent) or failed (sent, nothing filled) |
reason | Why it was rejected, or what happened |
arrivalPxUsd | The mid price when the order was decided, averaged over the venues the order could use |
expectedPxUsd | The all-in average price the router planned for |
executedPxUsd | The all-in average price it got |
costBps | Executed price against arrival price, fees and impact included. Positive means it paid more (buy) or received less (sell) |
improvementBps | How much more the split returned than the best single venue. null when the order went to one venue |
legs | Per venue: share of the order, USD, tokens, HYPE (pool leg), expected and executed price, status, transaction hash, error |
The last 25 reports are kept in engine_state.router and returned by GET /api/v1/router, together with each venue's status and the reason when one is unavailable. The state is also refreshed every 30 s.
A split, a partial fill or a failure is written to the ledger with kind route. A plain single-venue fill is not, because the strategy already logs its own swap event with the route attached. The same refusal repeated on every tick is kept as one line.
Settings
| Variable | Default | What it does |
|---|---|---|
MOTION_HL_COIN | none | MOTION's HyperCore spot coin, like @1234. Gives the router its second venue and turns arbitrage on. Set the same value on Vercel so the app lists the market. ARB_HL_COIN is the older name and is still read |
MOTION_HL_SZ_DECIMALS | 0 | That market's size decimals on Hyperliquid (szDecimals in their spot metadata) |
ROUTER_ENABLED | true | false = always the Ascend pool, never split |
ROUTER_SLICES | 20 | How finely an order is cut when it is split (1 to 200) |
ROUTER_MAX_SLIPPAGE_BPS | 100 | Worst case each leg accepts against its own quote |
ROUTER_MIN_IMPROVEMENT_BPS | 5 | A split must beat the best single venue by this much |
What it does not do
- It never moves funds between venues. Capital crosses only through the Safe, so the router can only use what already sits on each side.
- It does not route the hedge or the HyperCore quotes. The HYPE perp and the HYPE and KNTQ spot books exist on one venue.
- It does not route arbitrage. Arbitrage trades the two venues against each other on purpose and sends its own legs.
Note
Routing across two venues has only run in tests and in paper mode. It cannot run for real before MOTION is listed on HyperCore.