Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Proof-labs/trading-sdk/llms.txt

Use this file to discover all available pages before exploring further.

Every mutation sent to the Proof Exchange — placing an order, depositing funds, updating oracle prices, creating a market — is represented as a member of the Action discriminated union. Actions always carry the shape { type: string, data: object }, where type is a human-readable string selector and data is the typed payload for that action. Under the hood each action maps to a single wire byte (defined in the ActionType constant object) that the encoder writes into the MessagePack envelope before signing. Understanding this union is the starting point for everything you can do with the SDK.

The Action Type

export type Action =
  | { type: "PlaceOrder";           data: PlaceOrder }
  | { type: "CancelOrder";          data: CancelOrder }
  | { type: "CancelClientOrder";    data: CancelClientOrder }
  | { type: "CancelAllOrders";      data: CancelAllOrders }
  | { type: "CancelReplaceOrder";   data: CancelReplaceOrder }
  | { type: "AmendOrder";           data: AmendOrder }
  | { type: "AtomicBasketOrder";    data: AtomicBasketOrder }
  | { type: "OracleUpdate";         data: OracleUpdate }
  | { type: "MarketOrder";          data: MarketOrder }
  | { type: "Deposit";              data: Deposit }
  | { type: "Withdraw";             data: Withdraw }
  | { type: "CreateMarket";         data: CreateMarket }
  | { type: "WithdrawRequest";      data: WithdrawRequest }
  | { type: "ConfirmDeposit";       data: ConfirmDeposit }
  | { type: "ConfirmWithdrawal";    data: ConfirmWithdrawal }
  | { type: "FailWithdrawal";       data: FailWithdrawal }
  | { type: "ApproveAgent";         data: ApproveAgent }
  | { type: "RevokeAgent";          data: RevokeAgent }
  | { type: "CreateImpactMarket";   data: CreateImpactMarket }
  | { type: "ResolveEvent";         data: ResolveEvent }
  | { type: "UpdateMarketFees";     data: UpdateMarketFees }
  | { type: "SetUserMarketLeverage"; data: SetUserMarketLeverage }
  | { type: "ClosePosition";        data: ClosePosition };
Pass any Action value directly to client.submitTx() — the SDK signs, encodes, and broadcasts it for you:
const result = await client.submitTx({
  type: "PlaceOrder",
  data: {
    market: 1,
    owner: address, // pubkeyToOwner(publicKey)
    side: Side.Buy,
    price: 6675234n, // $66,752.34 in integer cents
    quantity: 1n,
  },
});

if (result.code !== 0) {
  throw new Error(`Action failed: code=${result.code} log=${result.log}`);
}

ActionType Wire Bytes

The ActionType constant maps every action name to its single-byte wire identifier. These values are embedded in the signed MessagePack envelope and must never change for a deployed chain.
export const ActionType = {
  PlaceOrder:            0x01,
  CancelOrder:           0x02,
  OracleUpdate:          0x03,
  MarketOrder:           0x04,
  Deposit:               0x05,
  Withdraw:              0x06,
  CreateMarket:          0x07,
  WithdrawRequest:       0x08,
  ConfirmDeposit:        0x09,
  ConfirmWithdrawal:     0x0a,
  FailWithdrawal:        0x0b,
  ApproveAgent:          0x0c,
  RevokeAgent:           0x0d,
  CreateImpactMarket:    0x0e,
  ResolveEvent:          0x0f,
  UpdateMarketFees:      0x10,
  SetUserMarketLeverage: 0x16,
  ClosePosition:         0x17,
  CancelClientOrder:     0x18,
  CancelAllOrders:       0x19,
  CancelReplaceOrder:    0x1a,
  AmendOrder:            0x1b,
  AtomicBasketOrder:     0x1c,
} as const;

All Actions at a Glance

Type StringWire ByteDescription
PlaceOrder0x01Place a resting limit order on the book
CancelOrder0x02Cancel a resting order by engine-assigned ID
OracleUpdate0x03Submit an oracle price update (relayer only)
MarketOrder0x04Place an immediate-or-cancel crossing order
Deposit0x05Credit USDC to an account (relayer/dev; prefer ConfirmDeposit)
Withdraw0x06Debit USDC from an account, checking margin (relayer)
CreateMarket0x07Register a new perpetual market with risk parameters (admin)
WithdrawRequest0x08User initiates a USDC withdrawal to a Solana address
ConfirmDeposit0x09Relayer confirms an on-chain Solana USDC deposit
ConfirmWithdrawal0x0aRelayer confirms a USDC withdrawal was sent on Solana
FailWithdrawal0x0bRelayer marks a withdrawal permanently failed; refunds balance
ApproveAgent0x0cApprove a delegate wallet to trade on the owner’s behalf
RevokeAgent0x0dRevoke a previously approved agent wallet
CreateImpactMarket0x0eCreate a 5-book impact-market family (admin)
ResolveEvent0x0fResolve an impact-market event with an outcome (relayer)
UpdateMarketFees0x10Update live market config tunables without a chain rebase (relayer)
SetUserMarketLeverage0x16Set a per-account initial-margin override for one market
ClosePosition0x17Close an entire position via opposite-side IOC at oracle±spread
CancelClientOrder0x18Cancel a resting order by owner-scoped client order ID
CancelAllOrders0x19Cancel all resting orders for an account (optionally per-market)
CancelReplaceOrder0x1aAtomically cancel one resting order and place a replacement
AmendOrder0x1bAmend price or quantity on a resting order in place
AtomicBasketOrder0x1cNative all-or-revert multi-leg basket order

Shared Enums

These enums are used across multiple action types and are imported from the same types.ts module.

Side

export enum Side {
  /** Buy / long. */
  Buy  = 1,
  /** Sell / short. */
  Sell = 2,
}

TimeInForce

Controls how unmatched quantity is handled after crossing the book. Wire-encoded as the variant name string.
export enum TimeInForce {
  /** Good-Till-Cancelled: unmatched quantity rests on the book. The default. */
  Gtc = 0,
  /** Immediate-Or-Cancel: unmatched quantity is dropped after crossing. */
  Ioc = 1,
  /** Fill-Or-Kill: fully fill immediately or reject without mutation. */
  Fok = 2,
}

User Actions vs. Relayer / Admin Actions

Actions fall into two broad authorization tiers. The envelope signer’s derived address is checked against the action’s intent — the engine rejects any mismatch.

User-Signed Actions

These actions are signed by the account owner (or an approved agent). Any client with a valid Ed25519 keypair and sufficient margin can submit them.
ActionNotes
PlaceOrderLimit order; owner must match envelope signer
MarketOrderImmediate-or-cancel crossing order
CancelOrderCancel by engine order ID
CancelClientOrderCancel by client order ID
CancelAllOrdersBulk cancel, optionally scoped to one market
CancelReplaceOrderAtomic cancel + replace
AmendOrderIn-place price/quantity change
ClosePositionIOC close at oracle±spread; owner must equal signer
AtomicBasketOrderMulti-leg fill-or-kill; owner must equal signer
WithdrawRequestInitiates a Solana withdrawal; debits balance immediately
ApproveAgentGrants trading delegation to a 32-byte Ed25519 pubkey
RevokeAgentRevokes a delegation
SetUserMarketLeverageSets a per-market IM override; owner must equal signer

Relayer / Admin Actions

These actions require the envelope signer’s derived address to be on the engine’s on-chain relayer or admin allowlist. Unauthorized signers receive UnauthorizedRelayer.
ActionTierNotes
OracleUpdateRelayerMust use an authorized oracle signer; publishTimeMs strictly increasing
DepositRelayerLegacy credit action; prefer ConfirmDeposit for production
WithdrawRelayerDirect debit; checks margin requirements
ConfirmDepositRelayerTied to a Solana tx signature for idempotency
ConfirmWithdrawalRelayerMarks a pending withdrawal as completed
FailWithdrawalRelayerMarks a pending withdrawal as failed; refunds the debited balance
UpdateMarketFeesRelayerLive market config updates without a chain rebase
ResolveEventRelayerResolves an impact-market event; auto-verified when oracleSource is set
CreateMarketAdminRegisters a new perpetual market; szDecimals and ticker are mandatory
CreateImpactMarketAdminCreates a 5-book impact-market family

Detail Pages

Order Actions

PlaceOrder, CancelOrder, MarketOrder, ClosePosition, AtomicBasketOrder, and more

Account Actions

Leverage, agent delegation, deposits, and withdrawal flows

Admin Actions

OracleUpdate, CreateMarket, UpdateMarketFees, CreateImpactMarket, ResolveEvent

Build docs developers (and LLMs) love