Docs

Trade Hyperliquid
from your contract

Everything a Solidity developer needs: the bytes to send, the limits you set, the answers you get back and the API behind them.

Overview

Your contract on Elysium calls sendRawAction(bytes) on the KeeperLane contract, with the same bytes HyperEVM's CoreWriter takes. The lane checks the limits the account owner set, then emits an Intent event.

The keeper reads the event, signs the order as the account's trade-only agent and sends it to HyperCore. HyperCore's answer is written back on Elysium with deliver, which can call your contract.

Kinetiq has announced its own keeper lane for an upgrade after mainnet. Code written for Onbook uses the same encoding, so it keeps working when the native lane ships.

Quick start

Import CoreActions, build the order and hand it to the lane. Prices and sizes are scaled by 1e8.

import {CoreActions} from "./CoreActions.sol"; interface IKeeperLane { function sendRawAction(bytes calldata data) external returns (uint64 nonce); } // buy 1 HYPE (perp 159 on mainnet, read from Hyperliquid's meta) at $66.20, immediate or cancel bytes memory order = CoreActions.limitOrder(159, true, 66_20000000, 1_00000000, false, CoreActions.TIF_IOC, 0); uint64 nonce = lane.sendRawAction(order);

The account that trades is the caller by default. A contract that trades for several accounts uses sendRawActionFor(account, data), and each account must grant it first.

CoreWriter encoding

Byte 0 is the version (1). Bytes 1 to 3 are the action id. The rest is abi.encode of the parameters.

ActionIdParameters
Limit order1uint32 asset, bool isBuy, uint64 limitPx, uint64 sz, bool reduceOnly, uint8 tif, uint128 cloid
Cancel by order id10uint32 asset, uint64 oid
Cancel by client id11uint32 asset, uint128 cloid
  • tif: 1 add liquidity only, 2 good till cancelled, 3 immediate or cancel.
  • asset: a perp's index in Hyperliquid's universe, or 10000 plus the index for spot.
  • cloid: your own 16-byte id. With 0, the keeper derives one from the lane and the nonce, so an order is never sent twice.
  • Every other action id is refused by the lane.

Prices follow Hyperliquid's rules: at most 5 significant figures, and at most 6 minus the market's size decimals after the point (8 on spot). Sizes take at most the market's size decimals. The keeper refuses an order that breaks a rule. It never rounds it, because that would change what your contract asked for.

Limits

Each account decides which contracts may trade for it, and how much. Limits live in the lane, so anyone can read them.

lane.grant( sender, // the contract allowed to trade 100e6, // max notional per order, in $ with 6 decimals expiry, // unix time, 0 for none false, // allAssets false, // reduceOnly assets // allowed markets when allAssets is false ); lane.setDailyCap(1_000e6); // across all contracts, per day lane.pauseAccount(true); // stop everything at once lane.revoke(sender);

grantBySig takes the same grant signed off-chain (EIP-712, domain "KeeperLane", version 1), so an account with no HYPE on Elysium can start: the keeper pays the gas.

Results

The registrar writes HyperCore's answer back with deliver(nonce, status, oid, filledSz, avgPx). If the sending contract implements ICoreResultReceiver, the lane calls it, paid from HYPE the contract deposited with deposit(sender).

function onCoreResult(uint64 nonce, uint8 status, uint64 oid, uint64 filledSz, uint64 avgPx) external;
StatusMeaning
2Resting on the book
3Filled
4Partly filled (the keeper keeps following it)
5Refused by HyperCore or by the keeper's price rules
6Cancelled

The agent

Each account gets its own Hyperliquid API agent, generated by the keeper. The account approves it once, with approveAgent signed in its wallet. HyperCore lets an agent place and cancel orders, and never lets it withdraw or transfer. Revoke it on Hyperliquid at any time.

Public API

No key, CORS open, JSON. Try every route live in the builder hub.

RouteReturns
GET /api/v1/marketsEvery live perp: asset id, size decimals, max price decimals, live prices
GET /api/v1/markets/:coinOne market
GET /api/v1/encodeThe exact bytes for sendRawAction, refused rather than rounded if a rule is broken
GET /api/v1/laneChain, addresses, owner, keeper, fee, pause state, Kinetiq's native lane, read live
GET /api/v1/statsFrom the keeper: latency p50 p90 p99, success rate, filled volume, days ahead
GET /api/v1/intentsFrom the keeper: latest intents and their results
GET /api/v1/intents/:nonceFrom the keeper: one intent
GET /api/v1/healthFrom the keeper: network, registrar, dry run or live

The keeper also takes POST /v1/agents (issues the trade-only agent for an account) and POST /v1/grant (relays a signed grant and pays its gas).

Run your own keeper

Name your own registrar with setRegistrar(address). From then on, only that address can deliver results for your account, and the lane does not depend on Onbook. The keeper is a small Node service: it reads intents, signs with your agents and writes results back.

The code is open (MIT): github.com/351Origin/onbook. Clone it, copy keeper/.env.example to .env, fill in your keeper wallet and an agent secret, then run npx tsx --env-file=.env src/main.ts. It starts read-only: set KEEPER_LIVE=true when you are ready to trade.

Addresses

ContractElysium mainnet (99901)
KeeperLane0xfaF3501406e6694e929e3B8c46695DDD56904E9D
Playground0x6F43BF56c6ef654631e8839846115549Dbe7c272
Kinetiq's native lane0x3333333333333333333333333333333333333333 (empty until their upgrade)