Orders and signing
Every order is an EIP-712 message signed by the trader. The engine forwards the signature with each fill and the exchange verifies it.
Domain and type
domain = { name: "EL-3", version: "1", chainId: 99901, verifyingContract: <El3Exchange> }
Order(address trader,uint32 market,bool isBuy,uint64 px,uint64 sz,uint8 tif,bool reduceOnly,uint64 nonce,uint64 expiry)
Cancel(address trader,uint32 market,uint64 nonce)The exchange address is in /api/deployment. The engine also serves the domain and types at /api/engine/v1/eip712.
Units
| Field | Meaning |
|---|---|
px | USDC micro-units (1e6) per whole base unit. 25.10 USDC is 25100000. |
sz | Base micro-units (1e6). 2 HYPE is 2000000. |
tif | 0 GTC (rests), 1 IOC (never rests), 2 ALO (post-only). |
nonce | Any unused 64-bit number. Cancelling it on chain kills every order that uses it. |
expiry | Unix seconds. A batch fails an order past its expiry. |
Collateral is USDC (6 decimals) on Elysium at 0xb47c4C8F73F009CC0C0d3f92B388d13E293F0B65. Margin is cross within an account, over up to 8 markets.
Sign with viem
import { createWalletClient, custom } from "viem";
const site = "https://<this site>";
const { exchange } = await fetch(site + "/api/deployment").then((r) => r.json());
const wallet = createWalletClient({ transport: custom(window.ethereum) });
const [trader] = await wallet.requestAddresses();
const order = {
trader, market: 1, isBuy: true,
px: 25_100_000n, sz: 2_000_000n, tif: 0, reduceOnly: false,
nonce: BigInt(Date.now()), expiry: BigInt(Math.floor(Date.now() / 1000) + 86_400),
};
const sig = await wallet.signTypedData({
account: trader,
domain: { name: "EL-3", version: "1", chainId: 99901, verifyingContract: exchange },
types: { Order: [
{ name: "trader", type: "address" }, { name: "market", type: "uint32" }, { name: "isBuy", type: "bool" },
{ name: "px", type: "uint64" }, { name: "sz", type: "uint64" }, { name: "tif", type: "uint8" },
{ name: "reduceOnly", type: "bool" }, { name: "nonce", type: "uint64" }, { name: "expiry", type: "uint64" },
] },
primaryType: "Order",
message: order,
});
const wire = { ...order, px: String(order.px), sz: String(order.sz), nonce: String(order.nonce), expiry: String(order.expiry) };
const res = await fetch(site + "/api/engine/v1/order", {
method: "POST", headers: { "content-type": "application/json" },
body: JSON.stringify({ order: wire, sig }),
}).then((r) => r.json());
// { id, status: "resting" | "filled" | "partial" | "cancelled" | "rejected", reason?, events }Contracts can trade too: the exchange accepts EIP-1271 signatures, which is how the house vault signs.
Cancels
An off-chain cancel is a signed Cancel posted to /v1/cancel; the engine pulls the order from the book. An on-chain cancel is cancelOrder(nonce) (or cancelOrders(nonces)) on the exchange; after it, no batch can settle that nonce, whatever the engine does.