> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nilemarkets.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Types Reference

> Shared enums (Side, Mode, CloseReason, FeeType, MarginMode), structs (Position, MarginConfig, OracleConfig, ForwardRound), and constants (PRICE_PRECISION, BPS_DENOMINATOR, EUR_USD_PAIR_ID, USD_JPY_PAIR_ID) used across all protocol contracts

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

| Value   | Ordinal | Description                                   |
| ------- | ------- | --------------------------------------------- |
| `LONG`  | 0       | Trader profits when the base/quote rate rises |
| `SHORT` | 1       | Trader profits when the base/quote rate falls |

### Tenors (no enum)

There is **no** `Tenor` enum. Tenors are stored as raw `uint32 tenorSeconds` values in a dynamic registry on `Config`. New maturities are added permissionlessly via `Config.registerTenor(tenorSeconds)` and removed via `Config.disableTenor(tenorSeconds)`.

Currently registered on Sepolia:

| Label | Seconds    |
| ----- | ---------- |
| 1D    | 86,400     |
| 1W    | 604,800    |
| 1M    | 2,592,000  |
| 3M    | 7,776,000  |
| 6M    | 15,552,000 |
| 1Y    | 31,536,000 |

Read the live set with `Config.getEnabledTenors()`. The TypeScript and Rust SDKs ship a bundled cache (`TENORS`) sourced from the canonical defaults file, but consumers should prefer the on-chain getter for authoritative state.

### PositionStatus

| Value    | Ordinal | Description                                                |
| -------- | ------- | ---------------------------------------------------------- |
| `OPEN`   | 0       | Position is active                                         |
| `CLOSED` | 1       | Position has been settled, liquidated, or early-terminated |

### CloseReason

| Value               | Ordinal | Description                                       |
| ------------------- | ------- | ------------------------------------------------- |
| `NONE`              | 0       | Position is still open                            |
| `MATURED`           | 1       | Settled at fixing price after maturity            |
| `LIQUIDATED`        | 2       | Closed by liquidation (equity below MM threshold) |
| `EARLY_TERMINATION` | 3       | Closed early by trader at forward price           |

### Mode

| Value         | Ordinal | Opens | Closes | Settlements | Liquidations |
| ------------- | ------- | ----- | ------ | ----------- | ------------ |
| `NORMAL`      | 0       | Yes   | Yes    | Yes         | Yes          |
| `DEGRADED`    | 1       | No    | Yes    | Yes         | Yes          |
| `REDUCE_ONLY` | 2       | No    | Yes    | Yes         | Yes          |
| `PAUSED`      | 3       | No    | No     | No          | No           |

### MarginMode

| Value      | Ordinal | Description                                          |
| ---------- | ------- | ---------------------------------------------------- |
| `ISOLATED` | 0       | Each position has its own locked margin (M2 default) |
| `CROSS`    | 1       | Shared margin across positions (future)              |

### FeeType

Used as the indexed `feeType` of `SettlementEngine.FeesCollected`. The subgraph indexes these into the `FeeEvent` entity.

| Value                 | Ordinal | Description                                                                               |
| --------------------- | ------- | ----------------------------------------------------------------------------------------- |
| `LIQUIDATION_PENALTY` | 0       | Penalty portion of a liquidation (separate from the trading-fee leg)                      |
| `EARLY_TERMINATION`   | 1       | Reserved bucket for an early-termination surcharge (currently 0)                          |
| `MATURITY`            | 2       | Reserved bucket for a maturity-settlement surcharge (currently 0)                         |
| `TRADING`             | 3       | Trading fee charged at every position close (settlement, liquidation, early term, reduce) |

## Structs

### Position

Every position is stored onchain as a `Position` struct:

```solidity theme={null}
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)
    uint32 tenorSeconds;                 // Tenor duration in seconds (dynamic registry)
    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)
}
```

<Note>
  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.
</Note>

### OpenPositionParams

```solidity theme={null}
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)
    uint32 tenorSeconds;   // Contract duration in seconds (must be enabled in Config)
    uint256 margin;        // Initial margin to lock (6 decimals)
}
```

### MarginConfig

```solidity theme={null}
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

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

### PricingConfig

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

### FixingConfig

```solidity theme={null}
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

```solidity theme={null}
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 maxAnchorDeviationBps;       // Max deviation vs Pyth-verified spot × IRP carry (default: 150 = 1.5%)
}
```

### DegradedConfig

```solidity theme={null}
struct DegradedConfig {
    uint32 degradedDurationSeconds;  // Max time in DEGRADED before PAUSED (default: 3600 = 1h)
}
```

### ForwardRound

```solidity theme={null}
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

| Constant          | Value                  | Description                              |
| ----------------- | ---------------------- | ---------------------------------------- |
| `PRICE_PRECISION` | `1e18`                 | All prices use 18 decimal precision      |
| `BPS_DENOMINATOR` | `10_000`               | Basis points divisor (100% = 10,000 bps) |
| `EUR_USD_PAIR_ID` | `keccak256("EUR/USD")` | Pair identifier for EUR/USD              |
| `USD_JPY_PAIR_ID` | `keccak256("USD/JPY")` | Pair identifier for USD/JPY              |

## Related Pages

<Columns cols={3}>
  <Card title="Contract Overview" icon="sitemap" href="/build/contract-overview">
    Architecture diagram and contract summary.
  </Card>

  <Card title="Parameter Reference" icon="sliders" href="/protocol/parameter-reference">
    Default parameter values and configuration.
  </Card>

  <Card title="Errors Reference" icon="triangle-exclamation" href="/build/errors-reference">
    Custom errors by contract.
  </Card>
</Columns>
