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

RoleCapabilities
DEFAULT_ADMIN_ROLEFull admin — set config, manage roles, mode transitions
PAUSER_ROLEEmergency pause/unpause only
PUBLISHER_ROLESubmit forward prices via OracleModule
ORACLE_ADMIN_ROLEConfigure oracle safeguard parameters
RISK_ADMIN_ROLEConfigure risk caps and rate-of-change limits
For operation restrictions by mode (which actions are allowed in NORMAL vs DEGRADED vs REDUCE_ONLY vs PAUSED), see Mode Escalation.

Technology Stack

LayerTechnologyPurpose
ContractsSolidity 0.8.34, OpenZeppelin 5.6.1Core protocol logic
UpgradeabilityNone (immutable bytecode)All contracts are deployed without proxies
Oracle (Spot)Pyth NetworkEUR/USD spot price
Oracle (Forward)Custom ForwardPublisherComputed forward prices via interest rate parity
IndexerThe Graph (Subgraph)Event indexing and GraphQL API
API GatewayCloudflare WorkersRead-only REST API over subgraph + RPC
PublisherRust + Tokio + alloy-rsForward price computation and onchain publishing
KeeperRust + Tokio + alloy-rsBatch settlement and liquidation
RiskRiskManagerPosition, account, and pool exposure caps
FrontendNext.js 16 + shadcn/ui + Tailwind 4.x + wagmi 3.x + viem 2.xUser interface
NetworkEthereum SepoliaTestnet deployment

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.