> ## 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.

# Config

> Protocol configuration contract storing margin factors (IM 2%, MM 1%), trading fees (0.05%), liquidation penalty (0.3%), tenor durations, per-pair fixing times, oracle fees, and fee distribution destinations — all adjustable by owner without redeployment

Config stores all tunable protocol parameters. The owner can adjust margin factors, fee rates, tenor durations, and other settings without redeploying contracts. Certain parameter changes (tenor durations, fixing times, margin mode) require all positions to be closed first.

## Contract Relationships

```mermaid theme={null}
graph LR
    config["Config"]
    pm["PositionManager"]
    se["SettlementEngine"]
    oracle["OracleModule"]
    config -. "margin, fees" .-> pm & se
    config -. "fixing times" .-> oracle
```

## Read Functions

### Margin Parameters

| Function                  | Returns                         | Default   |
| ------------------------- | ------------------------------- | --------- |
| `marginConfig()`          | Full MarginConfig struct        | —         |
| `imFactorBps()`           | Initial margin factor (bps)     | 200 (2%)  |
| `mmFactorBps()`           | Maintenance margin factor (bps) | 100 (1%)  |
| `tradingFeeBps()`         | Trading fee rate (bps)          | 5 (0.05%) |
| `liquidationPenaltyBps()` | Liquidation penalty (bps)       | 30 (0.3%) |

### Pricing Parameters

| Function                  | Returns                           | Default   |
| ------------------------- | --------------------------------- | --------- |
| `pricingConfig()`         | Full PricingConfig struct         | —         |
| `baseSpreadBps()`         | Base spread (bps)                 | 5 (0.05%) |
| `premiumDiscountAdjBps()` | Premium/discount adjustment (bps) | 5 (0.05%) |

### Tenor Registry

Tenors are tracked as a dynamic registry of `uint32` durations in seconds. There is no fixed enum — new maturities can be added post-deploy without contract upgrades.

| Function                       | Returns                                        |
| ------------------------------ | ---------------------------------------------- |
| `isTenorEnabled(tenorSeconds)` | Whether a duration (in seconds) is enabled     |
| `getEnabledTenors()`           | Array of all enabled tenor durations (seconds) |
| `getEnabledTenorCount()`       | Count of enabled tenors                        |

### Other Parameters

| Function                    | Returns                       | Default                |
| --------------------------- | ----------------------------- | ---------------------- |
| `minPositionNotional()`     | Minimum position size         | 100,000,000 (100 USDC) |
| `oracleFee()`               | Fee per oracle read           | 100,000 (\$0.10 USDC)  |
| `oracleFeeReceiver()`       | Oracle fee recipient address  | —                      |
| `marginMode()`              | Current margin mode           | ISOLATED               |
| `getFeeDestinations()`      | Fee distribution destinations | —                      |
| `getPairFixingTime(pairId)` | Per-pair fixing time config   | —                      |

## Admin Functions

All admin functions are restricted to the contract owner.

### setMarginConfig

```solidity theme={null}
function setMarginConfig(MarginConfig calldata newConfig) external
```

Updates margin factors and fee rates. Applied to all future positions (existing positions use snapshotted values).

**Validation:**

| # | Check                       | Revert Error       |
| - | --------------------------- | ------------------ |
| 1 | `imFactorBps > mmFactorBps` | `ImMustExceedMm`   |
| 2 | `imFactorBps <= 10000`      | `InvalidParameter` |

### setPricingConfig

```solidity theme={null}
function setPricingConfig(PricingConfig calldata newConfig) external
```

Updates pricing spread parameters.

**Validation:** `baseSpreadBps <= 1000` (max 10%)

### registerTenor

```solidity theme={null}
function registerTenor(uint32 tenorSeconds) external
```

Adds a new tenor duration (in seconds) to the enabled set. Idempotent — re-registering an already-enabled tenor is a no-op (no event emitted).

**Validation:** `tenorSeconds > 0` or reverts `InvalidParameter`

### disableTenor

```solidity theme={null}
function disableTenor(uint32 tenorSeconds) external
```

Removes a tenor duration from the enabled set. New positions cannot be opened on disabled tenors; existing positions on those tenors remain valid until matured.

### setPairFixingTime

```solidity theme={null}
function setPairFixingTime(bytes32 pairId, FixingConfig calldata config) external
```

Sets the daily fixing time for a currency pair.

**Validation:**

| # | Check                           | Revert Error         |
| - | ------------------------------- | -------------------- |
| 1 | `fixingHourUtc < 24`            | `InvalidParameter`   |
| 2 | `fixingMinuteUtc < 60`          | `InvalidParameter`   |
| 3 | `fixingSecondUtc < 60`          | `InvalidParameter`   |
| 4 | No open positions for this pair | `OpenPositionsExist` |

### setMarginMode

```solidity theme={null}
function setMarginMode(MarginMode newMode) external
```

Switches between ISOLATED and CROSS margin modes. Requires all positions to be closed.

### setPositionManager

```solidity theme={null}
function setPositionManager(address pm) external
```

One-shot wiring of the PositionManager address. Reverts if already set or if `pm` is not a contract address.

### setMinPositionNotional

```solidity theme={null}
function setMinPositionNotional(uint256 minNotional) external
```

Sets the minimum position notional in collateral decimals (6 for USDC).

### setOracleFee

```solidity theme={null}
function setOracleFee(uint256 fee) external
```

Sets the oracle fee per price read in collateral decimals.

### setOracleFeeReceiver

```solidity theme={null}
function setOracleFeeReceiver(address receiver) external
```

Sets the oracle fee recipient address.

### setFeeDestinations

```solidity theme={null}
function setFeeDestinations(FeeDestination[] calldata destinations) external
```

Sets fee distribution destinations. Shares must sum to exactly 10,000 bps (100%).

**Validation:**

| # | Check                          | Revert Error       |
| - | ------------------------------ | ------------------ |
| 1 | Each destination != address(0) | `ZeroAddress`      |
| 2 | Each shareBps > 0              | `InvalidParameter` |
| 3 | Total shares == 10,000         | `InvalidParameter` |

## Events

| Event                        | When Emitted                                                |
| ---------------------------- | ----------------------------------------------------------- |
| `MarginConfigUpdated`        | Margin factors or fee rates changed                         |
| `PricingConfigUpdated`       | Spread parameters changed                                   |
| `TenorRegistered`            | Tenor enabled (per-tenor event, indexed by `tenorSeconds`)  |
| `TenorDisabled`              | Tenor disabled (per-tenor event, indexed by `tenorSeconds`) |
| `PairFixingConfigUpdated`    | Per-pair fixing time changed                                |
| `MarginModeUpdated`          | Margin mode switched                                        |
| `MinPositionNotionalUpdated` | Minimum position size changed                               |
| `OracleFeeUpdated`           | Oracle fee amount changed                                   |
| `OracleFeeReceiverUpdated`   | Oracle fee receiver changed                                 |
| `FeeDestinationsUpdated`     | Fee distribution destinations changed                       |

## Related Pages

<Columns cols={3}>
  <Card title="Parameter Reference" icon="sliders" href="/protocol/parameter-reference">
    Complete parameter listing with defaults.
  </Card>

  <Card title="Types Reference" icon="code" href="/build/types-reference">
    MarginConfig, PricingConfig, MarginMode, FeeDestination struct definitions.
  </Card>

  <Card title="Fees" icon="coins" href="/protocol/fees">
    Fee calculation formulas and distribution.
  </Card>
</Columns>
