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

# Non-Deliverable Forwards (NDFs)

> Cash-settled FX forward contracts that pay the difference between agreed strike and fixing price at maturity — the most traded instrument in emerging market FX, now onchain with Nile Markets.

An FX forward is one of the oldest financial instruments in existence. The Nile Markets protocol
brings this concept onchain as a **non-deliverable forward (NDF)** -- a cash-settled product with no
bank accounts, no physical currency delivery, and no counterparty credit risk beyond locked margin.

<Info>
  An NDF is a forward contract where no physical currency delivery occurs -- instead, the profit or
  loss is cash-settled in a single settlement currency (USDC). NDFs are the standard instrument for
  offshore FX hedging in traditional finance, widely used for emerging market currencies and
  institutional cross-border exposure management.
</Info>

## What Is an FX Forward?

In traditional finance, an FX forward is a binding agreement between two parties to exchange a
specific amount of one currency for another at a predetermined rate on a future date. Banks,
corporations, and institutional traders use FX forwards to hedge currency exposure or speculate on
exchange rate movements.

<Info>
  FX forwards are the second most traded instrument in global foreign exchange markets, accounting for
  over \$1 trillion in daily turnover according to the Bank for International Settlements.
</Info>

For example, a European exporter expecting to receive USD in 30 days might enter a forward contract
to sell USD and buy EUR at a locked-in rate. If EUR/USD moves against them, the forward offsets the
loss. If it moves in their favor, the forward caps their upside -- but they gain certainty.

## How NDFs Differ from Deliverable Forwards

The Nile Markets protocol creates **non-deliverable** FX forwards. Instead of exchanging EUR and USD
at maturity, positions are **cash-settled in USDC** based on the difference between the entry price
and the settlement price.

<Columns cols={2}>
  <Card title="Traditional Deliverable Forward" icon="building-columns">
    * Physical delivery of currencies at maturity
    * Requires bank accounts in both currencies
    * Counterparty credit risk (the other party might default)
    * Minimum sizes typically \$100,000+
    * KYC/AML required, restricted access
    * Opaque pricing, negotiated bilaterally
  </Card>

  <Card title="Nile Markets NDF" icon="link">
    * Cash-settled in USDC -- no currency delivery
    * Only need a wallet with USDC
    * Isolated margin model -- risk capped at locked collateral
    * Minimum notional of 1 USDC (configurable)
    * Permissionless -- anyone with a wallet can participate
    * Transparent onchain pricing from Pyth oracle
  </Card>
</Columns>

## The EUR/USD Forward Contract

Each position on Nile Markets represents a directional bet on the future EUR/USD exchange rate.
When you open a position, the protocol records your **entry strike price** from the current oracle
forward price for your chosen tenor. At maturity (or when you close early), your profit or loss is
computed from the difference between your entry strike and the settlement price.

<Steps>
  <Step title="Choose your parameters">
    Select a **side** (LONG or SHORT), a **tenor** (1 Day, 1 Week, or 1 Month), a **notional** size
    (the face value of the contract in USDC), and your **margin** (the collateral you lock).
  </Step>

  <Step title="Position opens at the forward price">
    The protocol reads the current forward price for your chosen tenor from the oracle and locks it as
    your entry strike. Your margin is transferred from your account to the position.
  </Step>

  <Step title="Monitor unrealized PnL">
    As the forward price moves, your unrealized PnL updates in real time. You can add margin, remove
    excess margin, or close the position early at any point.
  </Step>

  <Step title="Settlement at maturity">
    When the position reaches its maturity date, the fixing price (Pyth EUR/USD spot at 4 PM UTC) is
    recorded. PnL is computed against this fixing price, and the position is cash-settled.
  </Step>
</Steps>

## PnL Mechanics

The profit and loss calculation is straightforward and symmetric:

```
LONG PnL  = notional * (currentPrice - entryStrike) / PRICE_PRECISION
SHORT PnL = notional * (entryStrike - currentPrice) / PRICE_PRECISION
```

Where `PRICE_PRECISION` is 1e18 (all prices use 18-decimal fixed-point representation) and notional
is denominated in raw USDC units (6 decimals).

<Accordion title="Worked example: LONG position profit">
  A trader opens a LONG position with:

  * **Notional**: 1,000 USDC (1,000,000,000 raw)
  * **Entry strike**: 1.08000 (1,080,000,000,000,000,000 raw)
  * **Margin deposited**: 50 USDC (5% of notional)

  The EUR/USD rate rises to 1.10000 (1,100,000,000,000,000,000 raw):

  ```
  PnL = 1,000,000,000 * (1,100,000,000,000,000,000 - 1,080,000,000,000,000,000)
        / 1,000,000,000,000,000,000
      = 1,000,000,000 * 20,000,000,000,000,000 / 1,000,000,000,000,000,000
      = 20,000,000    (20 USDC profit)
  ```

  The trader deposited 50 USDC in margin and earned 20 USDC -- a 40% return on margin.
</Accordion>

<Accordion title="Worked example: SHORT position profit">
  A trader opens a SHORT position with:

  * **Notional**: 1,000 USDC (1,000,000,000 raw)
  * **Entry strike**: 1.08000 (1,080,000,000,000,000,000 raw)
  * **Margin deposited**: 50 USDC (5% of notional)

  The EUR/USD rate falls to 1.06000 (1,060,000,000,000,000,000 raw):

  ```
  PnL = 1,000,000,000 * (1,080,000,000,000,000,000 - 1,060,000,000,000,000,000)
        / 1,000,000,000,000,000,000
      = 1,000,000,000 * 20,000,000,000,000,000 / 1,000,000,000,000,000,000
      = 20,000,000    (20 USDC profit)
  ```

  The trader deposited 50 USDC in margin and earned 20 USDC -- a 40% return on margin.
</Accordion>

## Zero-Sum Nature

The protocol operates as a **zero-sum system**. Every dollar a trader makes, the liquidity pool
loses, and vice versa. There is no value creation or destruction in the PnL equation -- only
redistribution between traders and the pool.

```
TraderPnL + PoolPnL = 0    (excluding fees)
```

The liquidity pool (an ERC-4626 vault where LPs deposit USDC) serves as the counterparty to every
trade. When you open a LONG position, the pool is effectively SHORT against you. When you open a
SHORT position, the pool is effectively LONG.

<Note>
  Fees (trading fees, liquidation penalties) are extracted separately from the zero-sum equation.
  They are charged on top of PnL and distributed between the pool and the treasury. This means the
  pool has a structural edge: it earns fees on every trade regardless of PnL outcome.
</Note>

## Cash Settlement

At maturity, positions are settled using the **fixing price** -- the Pyth EUR/USD spot price
recorded at 4:00 PM UTC on the maturity business day. No EUR tokens change hands. The settlement
process computes PnL, distributes funds, and closes the position in a single atomic transaction.

<Tabs>
  <Tab title="Profitable settlement">
    If the position has positive PnL at settlement:

    1. The trader receives their locked margin back
    2. The trader receives their profit (paid from the pool)
    3. Settlement fees are deducted from the profit
    4. The position is marked as CLOSED with reason MATURED
  </Tab>

  <Tab title="Loss settlement">
    If the position has negative PnL at settlement:

    1. The loss is deducted from the trader's locked margin
    2. The remaining margin (if any) is returned to the trader
    3. The loss amount is credited to the pool
    4. Settlement fees are deducted from the returned margin
    5. The position is marked as CLOSED with reason MATURED
  </Tab>

  <Tab title="Bad debt settlement">
    If the loss exceeds the locked margin (bad debt):

    1. The trader receives nothing -- their entire margin is consumed
    2. The pool absorbs the bad debt (pays out more than the margin covers)
    3. The position is marked as CLOSED with reason MATURED
    4. Bad debt events are logged for monitoring
  </Tab>
</Tabs>

<Warning>
  Non-deliverable forwards carry the same directional risk as traditional forwards. If the market moves
  against your position, you can lose your entire locked margin. The isolated margin model limits your
  maximum loss to the margin deposited on each individual position, but that margin can be lost
  entirely.
</Warning>

## Why Non-Deliverable?

Non-deliverable instruments have several advantages over their physically delivered counterparts for
onchain implementation:

* **No multi-currency infrastructure** -- only USDC is needed. There is no need for onchain EUR
  tokens or cross-chain bridges.
* **Atomic settlement** -- PnL is computed and distributed in a single transaction. No delivery
  coordination or settlement lag.
* **Capital efficiency** -- traders only lock margin (a fraction of notional), not the full contract
  value. The pool provides the counterparty exposure.
* **Composability** -- positions are standard smart contract state. They can be queried, monitored,
  and acted upon by any onchain or off-chain system.
