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

# How It Works

> The end-to-end settlement flow from order creation to atomic delivery.

Every FX trade on Musubi follows the same six-step flow — an RFQ on a competitive venue followed by CLS-style Payment-vs-Payment settlement. The entire process settles in approximately **15 seconds**.

<Steps>
  <Step title="Order Creation">
    The sender institution submits an FX order via their API, specifying the source currency, amount, target currency, and an optional cost guard (`source_amount_max`).

    The order is created in **PENDING** status.
  </Step>

  <Step title="Quote Request Broadcast">
    Musubi automatically broadcasts an **anonymized quote request** to all registered market makers. The request contains only the currency pair, amount, and expiry — no sender or receiver identity.
  </Step>

  <Step title="Quote Submission">
    Market makers evaluate the request and submit competitive quotes with an FX rate, target amount, and validity window. Multiple market makers can quote on the same request.

    The sender's custodian can see all incoming quotes.
  </Step>

  <Step title="Quote Acceptance">
    The sender institution selects the best quote, and the sender's custodian accepts it. This transitions the order to **QUOTED** status and authorizes the settlement.

    Musubi validates the quote against the cost guard before proceeding.
  </Step>

  <Step title="Atomic DvP Settlement">
    Musubi executes an atomic **Delivery vs. Payment (DvP)** swap:

    | Leg | From             | To                 | Asset                            |
    | --- | ---------------- | ------------------ | -------------------------------- |
    | 1   | Sender Custodian | Musubi             | Source stablecoin (e.g., JPYSC0) |
    | 2   | Market Maker     | Musubi             | Target stablecoin (e.g., USDCx)  |
    | 3   | Musubi           | Receiver Custodian | Target stablecoin                |
    | 4   | Musubi           | Market Maker       | Source stablecoin                |

    All four legs execute in a **single transaction**. If any leg fails, the entire settlement rolls back. No party is ever exposed to counterparty risk.
  </Step>

  <Step title="Settlement Confirmation">
    All participants see the settled order on their respective systems. The order moves to **SETTLED** status with a single `transaction_hash` that proves the atomic settlement.

    Each party can use this record for regulatory reporting and reconciliation.
  </Step>
</Steps>

## Order Status Flow

```mermaid actions=false theme={null}
graph LR
  PENDING --> QUOTED
  QUOTED --> EXECUTING
  EXECUTING --> SETTLED
  PENDING --> EXPIRED
  PENDING --> FAILED
  QUOTED -.-> EXPIRED
```

| Status        | Meaning                                            |
| ------------- | -------------------------------------------------- |
| **PENDING**   | Order created, awaiting market maker quotes        |
| **QUOTED**    | Best quote accepted, awaiting settlement execution |
| **EXECUTING** | Atomic DvP in progress                             |
| **SETTLED**   | Settlement complete, assets delivered              |
| **FAILED**    | Settlement reverted or validation failed           |
| **EXPIRED**   | Order expired before settlement could complete     |

## Timing

| Phase                         | Duration         |
| ----------------------------- | ---------------- |
| Order creation to first quote | \~8 seconds      |
| Quote acceptance              | \~3 seconds      |
| Atomic settlement             | \~4 seconds      |
| **Total end-to-end**          | **\~15 seconds** |

<Tip>
  Timing is based on testnet measurements. Production latency may vary based on network topology and participant node configuration.
</Tip>
