Skip to main content
The protocol combines onchain smart contracts with off-chain services to deliver non-deliverable FX forward (NDF) trading with full collateral transparency and deterministic settlement.

System Architecture

Three layers work together: external services (Pyth oracle, The Graph indexer) provide market data and event indexing, off-chain services (publisher, keeper, frontend) bridge data to the chain, and onchain contracts enforce all trading rules, margin, and settlement. For step-by-step interaction flows, see Trading Flows and System Flows.

Contract Architecture

The Protocol Registry is the root — all contracts discover each other through it rather than storing direct addresses. Solid arrows show ownership, dotted arrows show runtime reads. Each pool can have its own operating mode. M2 deploys a single USDC pool; the architecture supports future multi-collateral pools.

Shared Infrastructure

Singleton contracts that serve all pools:
  • Config — Stores all tunable parameters: margin factors, fee rates, tenor durations, risk caps, and oracle thresholds. The admin can adjust parameters without redeploying contracts.
  • OracleModule — Manages two price feeds: Pyth spot prices (read onchain) and publisher-submitted forward prices (with safeguard checks on staleness, deviation, and price movement).
  • ModeController — Implements a four-state operating mode machine (NORMAL → DEGRADED → REDUCE_ONLY → PAUSED) that progressively restricts protocol operations during adverse conditions.
  • RiskManager — Enforces per-position, per-account, and pool-level risk caps, plus rate-of-change throttling to prevent sudden large exposures.

Pool Contracts

Instantiated per collateral token (currently USDC only):
  • MarginAccounts — Holds trader collateral. Manages deposits, withdrawals, and per-position margin locking so that each position’s risk is isolated.
  • PoolVault — ERC-4626 vault for LP deposits. Serves as the counterparty to all trader positions, paying out trader profits and absorbing trader losses.
  • PositionManager — Handles the full position lifecycle: opening new positions, increasing existing ones, reducing exposure, and managing margin adjustments.
  • SettlementEngine — Executes settlement at maturity, liquidation of underwater positions, and early termination requests.
For contract API details and function signatures, see the Build tab.
For design rationale (zero-sum pool model, immutable contracts, isolated margin, ERC-4626 vault), see Core Design.

Access Control

For operation restrictions by mode (which actions are allowed in NORMAL vs DEGRADED vs REDUCE_ONLY vs PAUSED), see Mode Escalation.

Technology Stack

Next Steps

Trading Flows

Sequence diagrams for open, increase, reduce, margin adjust, and settlement.

System Flows

Oracle publishing, keeper automation, fee distribution, and LP deposits.

Core Design

Zero-sum pool model, immutable contracts, and design principles.