Thesettlementlayerforthemachineeconomy.

LayerX agent domain

Trade perps and spot in the kernel

Perpetual and spot markets

Matching, margin, funding and liquidation run as kernel activities, gated on signed oracle prices.

You submit one activity and the kernel matches it, checks margin, and applies the settlement legs in the same batch, so no off-chain matcher sits in the path. Perps covers market creation and halt, orders, positions, funding ticks, liquidation and automatic position reduction. Spot escrows base and quote assets, settling each fill as transfer legs. The price path refuses stale, out-of-bounds or out-of-sequence observations and halts the market. Both modules stay off until you set their enable flag.

What it does

LayerX carries two trading modules inside the kernel: a perpetual futures module with eleven activity types and a spot module with five. Perps covers market creation and halt, order place and cancel, position open, increase and close, funding ticks, liquidation and automatic position reduction (ADL); spot covers market creation, limit and market orders with good-til-cancelled or immediate-or-cancel, cancel, halt and resume. Prices come from authorized oracles that push signed observations, and an observation is accepted only after signer authority, sequence, staleness, absolute bounds and maximum-deviation checks pass. Every fill, funding payment and liquidation settles through the same kernel transfer-set primitive the rest of the agent domain uses.

Key capabilities

  • Perpetual markets with initial and maintenance margin ratios, funding intervals and per-market oracle key sets.
  • Spot markets that escrow base and quote assets and settle each fill as transfer legs.
  • Liquidation that pays a liquidator share, charges a fee and draws on an insurance account.
  • Automatic position reduction when the insurance account cannot cover a deficit, with deficit records kept per market.
  • Oracle intake that refuses stale, out-of-bounds, out-of-sequence or deviant prices and halts the market.
  • Halted markets still accept order cancellation and margin top-ups, so positions can be unwound.

Who it's for

Developers and agent operators running trading strategies or administering a market on the agent domain.

Why it matters

Matching, margin checks, funding and liquidation run in the kernel, so an agent submits one activity and the settlement legs are produced and applied in the same batch rather than by an off-chain matcher. Because the price path fails closed, a market stops taking risk-increasing orders as soon as its feed goes stale or jumps past its deviation limit.

Differentiators

Per-dispatch work is bounded by constants rather than by input size: at most 8 fills per perps or spot dispatch and at most 16 positions per ADL activity. A liquidation that leaves any balance in the margin account fails the batch as an invariant violation rather than settling short.

Outcomes

  • Settle fills, funding and liquidations through the same kernel transfer sets.
  • A halted market still accepts cancels and margin top-ups, so you unwind.
  • Each perps or spot activity costs 1/10 of a cent.

Technical notes

  • Perps activity types are 0x00060001 to 0x0006000b; spot ordinals are 0x000a0001 to 0x000a0005. Each one is a LayerX activity and costs 1/10 of a cent.
  • Sizes and capacities: perps market record 622 bytes, book 256 orders, fills 256, positions 128, deficits 128, ADL candidates 128, up to 8 permitted oracle keys, margin ratios capped at 10000 bps. Spot markets 64, book 256, market record 225 bytes, order record 201 bytes, up to 18 transfer legs per dispatch.
  • Oracle state: observation 72 bytes, store 512 accepted observations, 128 markets, 8 keys per market. Observations are Ed25519-signed and must strictly increase in sequence per market.
  • System account kinds carry the money: agent margin (5), system funding long (7) and short (8), system insurance (9). Both modules are registered at genesis behind an enable flag and are off unless that flag is set.
  • Errors: MARKET_HALTED (-703), ORACLE_STALE (-704), MARGIN_INSUFFICIENT (-705), UNAUTHORIZED_ORACLE (-729), ORACLE_SEQUENCE (-730), ORACLE_BOUNDS (-731), ORACLE_DEVIATION (-732), MARKET_ALREADY_EXISTS (-733).
  • Not yet wired: there is no src/modules/oracle/. The oracle code sits in src/modules/perps/, src/sequencer/ and src/network/. The six enumerated oracle-gated actions (lx_oracle_market_action_check) and the fail-closed evaluator (lx_oracle_fail_closed_eval) have no caller outside tests; the perps dispatch path applies its own halt and staleness checks instead. lx_oracle_push_execute, lx_oracle_root_compute, lx_batch_header_set_oracle_root and the polling adapter lx_oracle_adapter_run likewise have no production caller yet, and the batch header's oracle root is built from the sequencer's generic oracle-input list.
import { buildPerpsActivity, buildSpotActivity } from "layerx-sdk";

const open = buildPerpsActivity({
  activity: "position_open",
  marketId, positionId, marginAccountId,
  side: 1, size: 10n, entryNotional: 250000n, marginAmount: 25000n,
});
const bid = buildSpotActivity({
  activity: "order_place",
  marketId, orderId, baseAccountId, quoteAccountId,
  side: 1, kind: 1, timeInForce: 1, price: 25000n, quantity: 10n,
});

More in LayerX agent domain

Build on Paxeer.

Give your agent a wallet, set its policy, and settle your first call on LayerX.