Skip to main content
All shared type definitions live in Types.sol and are imported by every contract. This page is the canonical reference — individual contract pages link here rather than duplicating definitions.

Enums

Side

ValueOrdinalDescription
LONG0Trader profits when EUR/USD rises
SHORT1Trader profits when EUR/USD falls

Tenor

ValueOrdinalDefault DurationDescription
ONE_DAY086,400s (24h)Daily forward
ONE_WEEK1604,800s (7d)Weekly forward
ONE_MONTH22,592,000s (30d)Monthly forward
TEST_60S360sTesting only
Tenor durations are configurable via Config.setTimeConfig(). The values above are defaults. Tenors must be explicitly enabled via Config.setTenorEnabled() after deployment.

PositionStatus

ValueOrdinalDescription
OPEN0Position is active
CLOSED1Position has been settled, liquidated, or early-terminated

CloseReason

ValueOrdinalDescription
NONE0Position is still open
MATURED1Settled at fixing price after maturity
LIQUIDATED2Closed by liquidation (equity below MM threshold)
EARLY_TERMINATION3Closed early by trader at forward price

Mode

ValueOrdinalOpensClosesSettlementsLiquidations
NORMAL0YesYesYesYes
DEGRADED1NoYesYesYes
REDUCE_ONLY2NoYesYesYes
PAUSED3NoNoNoNo

MarginMode

ValueOrdinalDescription
ISOLATED0Each position has its own locked margin (M2 default)
CROSS1Shared margin across positions (future)

Structs

Position

Every position is stored onchain as a Position struct:
struct Position {
    address account;                     // Owner address
    bytes32 pairId;                      // Currency pair identifier (e.g., keccak256("EUR/USD"))
    Side side;                           // LONG or SHORT
    uint256 notional;                    // Position size in USDC (6 decimals)
    Tenor tenor;                         // Maturity tenor (ONE_DAY, ONE_WEEK, ONE_MONTH)
    uint32 tenorSeconds;                 // Tenor duration in seconds
    uint64 openTimestamp;                // Block timestamp when opened
    uint64 fixingTimestamp;              // Maturity date (business day adjusted)
    int256 entryStrike;                  // Forward price at open (18 decimals)
    uint64 entryOracleRoundId;           // Oracle round ID at open
    uint256 imLocked;                    // Locked initial margin (mutable via add/remove)
    uint256 mmThreshold;                 // Maintenance margin liquidation threshold
    PositionStatus status;               // OPEN or CLOSED
    CloseReason closeReason;             // Why it was closed (NONE while open)
    uint64 closeTimestamp;               // When closed (0 while open)
    int256 closePrice;                   // Settlement price at close (18 decimals)
    int256 realizedPnl;                  // Capped PnL used for accounting
    int256 marketPnl;                    // Uncapped true mathematical PnL
    uint16 snapshotImBps;                // IM factor at time of open
    uint16 snapshotMmBps;                // MM factor at time of open
    uint16 snapshotTradingFeeBps;        // Trading fee rate at time of open
    uint16 snapshotLiquidationPenaltyBps; // Liquidation penalty at time of open
    uint256 snapshotOracleFee;           // Oracle fee at time of open
    MarginMode marginMode;               // ISOLATED (M2 only)
}
The imLocked field is the only mutable economic field on an open position. It changes when the trader adds or removes margin. All snapshot* fields are immutable after position creation.

OpenPositionParams

struct OpenPositionParams {
    bytes32 pairId;       // Currency pair (e.g., EUR_USD_PAIR_ID)
    Side side;            // LONG or SHORT
    uint256 notional;     // Position size in USDC (6 decimals)
    Tenor tenor;          // Contract duration
    uint256 margin;       // Initial margin to lock (6 decimals)
}

MarginConfig

struct MarginConfig {
    uint16 imFactorBps;              // Initial margin factor (default: 200 = 2%)
    uint16 mmFactorBps;              // Maintenance margin factor (default: 100 = 1%)
    uint16 tradingFeeBps;            // Trading fee rate (default: 5 = 0.05%)
    uint16 liquidationPenaltyBps;    // Liquidation penalty (default: 30 = 0.3%)
}

FeeDestination

struct FeeDestination {
    address destination;  // Recipient address
    uint16 shareBps;      // Share of fees (must sum to 10000 across all destinations)
}

PricingConfig

struct PricingConfig {
    uint16 baseSpreadBps;            // Base spread (default: 5 = 0.05%)
    uint16 premiumDiscountAdjBps;    // Premium/discount adjustment (default: 5 = 0.05%)
}

TimeConfig

struct TimeConfig {
    uint32 tenorSecondsOneDay;     // ONE_DAY duration (default: 86400)
    uint32 tenorSecondsOneWeek;    // ONE_WEEK duration (default: 604800)
    uint32 tenorSecondsOneMonth;   // ONE_MONTH duration (default: 2592000)
    uint32 tenorSecondsTest;       // TEST_60S duration (default: 60)
}

FixingConfig

struct FixingConfig {
    uint8 fixingHourUtc;     // Hour of fixing time (0-23)
    uint8 fixingMinuteUtc;   // Minute of fixing time (0-59)
    uint8 fixingSecondUtc;   // Second of fixing time (0-59)
}

OracleConfig

struct OracleConfig {
    uint32 maxOracleAge;                // Max spot price age in seconds (default: 30)
    uint32 maxForwardAge;               // Max forward price age in seconds (default: 60)
    uint32 spotFixingWindowSeconds;     // Fixing window tolerance (default: 120 = ±2 min)
    uint32 minForwardUpdateSpacing;     // Min seconds between updates (default: 10)
    uint16 maxOracleMovePerUpdateBps;   // Max price move per update (default: 200 = 2%)
    uint16 maxDeviationVsPriorBps;      // Max deviation vs prior forward (default: 50 = 0.5%)
    uint16 maxDeviationVsLastCloseBps;  // Max deviation vs last close (default: 150 = 1.5%)
}

DegradedConfig

struct DegradedConfig {
    uint16 degradedThresholdBps;     // Deviation threshold to enter DEGRADED (default: 500 = 5%)
    uint32 degradedDurationSeconds;  // Max time in DEGRADED before PAUSED (default: 3600 = 1h)
    bool autoDegradeOnDeviation;     // Auto-degrade on oracle deviation (default: true)
}

ForwardRound

struct ForwardRound {
    int256 forwardPrice;       // Forward price (18 decimal precision)
    uint64 publishTimestamp;   // When the price was published
    uint64 roundId;            // Sequential round identifier
    bool isValid;              // Whether this round is valid
}

Constants

ConstantValueDescription
PRICE_PRECISION1e18All prices use 18 decimal precision
BPS_DENOMINATOR10_000Basis points divisor (100% = 10,000 bps)
EUR_USD_PAIR_IDkeccak256("EUR/USD")Pair identifier for EUR/USD

Contract Overview

Architecture diagram and contract summary.

Parameter Reference

Default parameter values and configuration.

Errors Reference

Custom errors by contract.