Desks and API wallets
A desk is a small contract on HyperEVM, cloned from one implementation for every funded trader. Every HyperEVM address has its own HyperCore account, so each desk holds its capital in its own account.
Opening a desk
- The keeper calls
AthlosBook.openDesk(trader, agent, payoutTo, allocation)after a pass. - The book deposits the allocation in USDC straight into the desk's perp balance with Circle's deposit wallet on HyperEVM (
depositFor(desk, amount, 0)). - The keeper also places 1 USDC and a little HYPE on the desk's HyperCore spot balance: Hyperliquid charges a one-time 1 USDC activation fee on an account's first outbound transfer, and the desk's transfers (payouts, capital back to the book) need it in place.
- Once the desk's HyperCore account exists, anyone calls
arm(). The desk sends CoreWriter action 9, add API wallet, with the trader's API wallet under the nametrader.
Trading
The trader signs orders with the API wallet for the desk's account, from the Hyperliquid app or any SDK. An API wallet can place, modify and cancel orders and change leverage. It cannot withdraw, send USDC, move value between spot and perps or approve another wallet.
Why one account per trader: on Hyperliquid, an API wallet approved by a master account can sign for every sub-account of that master. Separate desk contracts keep each trader's API wallet on one account only.
Checks anyone can run
check() returns the reason (empty when the desk is inside its rules), the equity and the total notional. It reads:
0x080Faccount margin summary: account value and total notional0x0800position, for each allowed market0x0806mark price, for each allowed market0x0801spot USDC balance
poke() rolls the UTC day and, on a breach, stops the desk: it registers a fresh address under the name trader (Hyperliquid deregisters the trader's API wallet when a new one is approved with the same name) and sends a reduce-only IOC order through CoreWriter for every open position, priced 10% through the mark and rounded to five significant figures.
After a stop
| Call | Who | What |
|---|---|---|
flatten() | anyone | sends the closing orders again while positions remain |
cancel(asset, oid) | anyone | cancels a resting order |
recoverVault(vault) | anyone | withdraws capital an API wallet moved into a vault |
recoverSub(sub, usd) | anyone | pulls capital back from a sub-account |
returnCapital() | anyone, desk flat | sends the withdrawable balance back to the book |
