# Trade Life Cycle

The `Optimex Protocol` enables secure cross-chain asset transfers through a structured, multi-step trade process that includes user deposits, market maker (`PMM`) execution, and final settlement. Each trade progresses through clearly defined stages and is continuously monitored by a decentralized Multi-Party Computation (`MPC`) network, ensuring consistency, validation, and reliable failure recovery.

<figure><img src="/files/QXg3m9QNoOc8Lg3g7FnY" alt=""><figcaption><p>Optimistic Swap - Trade Life Cycle</p></figcaption></figure>

### <mark style="color:orange;">Trade Completion States</mark>

Each trade concludes in one of two final states:

* `Completed` – The trade successfully progresses through all required lifecycle stages and the recipient receives the intended asset.
* `Refunded` – The trade encounters an issue that prevents completion. The protocol safely returns funds to the user.

### <mark style="color:orange;">Successful Trade Lifecycle</mark>

A trade is considered `Completed` only when it successfully passes through the following sequential stages:

* `Trade Submitted` – The Solver submits initial trade data to the protocol.
* `Deposit Confirmed` – The MPC verifies that the user's deposit was received on the source chain.
* `PMM Selected` – A Professional Market Maker (PMM) is selected to fulfill the trade.
* `Payment Transferred` – The PMM sends the target asset to the user on the destination chain.
* `Payment Confirmed` – The MPC validates that the payment has been successfully completed.
* `Completed` – The trade is finalized and marked as successful, triggering settlement and releasing funds to the PMM.

### <mark style="color:orange;">Failure Detection and Handling</mark>

While the protocol is designed for high success rates, failures may occur at specific stages. The MPC plays a key role in proactively detecting and resolving failures.

#### 🔍 Deposit Failure Detection

* After trade submission, the MPC validates deposit details.
* If a mismatch or timeout occurs, the MPC can mark the trade as `Failure`.
* A trade marked as `Failure` is permanently halted and cannot proceed.
* After a grace period (`timeout`), the MPC finalizes the trade and triggers an automatic refund of the user’s funds.

#### 🔍 Payment Failure Detection

* The payment (`paymentTxId`) may be submitted by the Solver or PMM.
* The MPC verifies payment accuracy and consistency.
* If a problem is detected:
  * The trade is moved to a `WARNING` state.
  * The PMM is notified and may attempt to make another payment.
    * If successful, the trade returns to `Confirm Payment`.
    * If not, the `MPC` escalates the trade to `FAILURE` after the timeout period and initiates the refund process accordingly.

#### 🔍 Other Failure Scenarios

* For all other stages (e.g., `Select PMM`, `Make Payment`, `Warning`, `Confirm Settlement`), failure handling is only triggered after a timeout.
* The MPC monitors pending trades and moves them to `Failure` if they remain stalled.
* Refund handling follows the same policy based on the auto-refund setting.

> **⚠️ Note: Auto-refund is mandatory. However, in rare cases, the MPC may process the refund with a delay. Users can still manually claim refunds via the DApp interface after the timeout period if the refund hasn't been issued automatically.**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.optimex.com/optimex-revolutionizing-bitcoin-finance/optimex-swap/optimex-swap-how-it-work/trade-life-cycle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
