# Stage: PMM Selection & Failure Handling

The `SELECT_PMM` stage follows after the `MPC` confirms the deposit. At this point, the `Solver` chooses the optimal `PMM` (Professional Market Maker) based on the user's `RFQ` constraints. If a valid `PMM` isn't matched before `scriptTimeout`, the trade is marked as `FAILURE`.

#### <mark style="color:orange;">Key Responsibilities</mark>

* **PMM Selection:** Choose a `PMM` offering a valid quote based on `minAmountOut`.
* **Quote Verification:** Confirm the quote is valid and linked to a pre-signed settlement.
* **Proof Submission:** Submit signed data from both parties to validate the trade terms.
* **Fee Policy Compliance:** Ensure fees align with the user's expectations.

#### <mark style="color:orange;">Scenarios</mark>

* **Successful PMM Selection:**
  * The protocol validates the PMM's data, locks fees, emits a `SelectedPMM` event, and advances to `MAKE_PAYMENT`.
* **No Match/Timeout:**
  * If no PMM is selected within `scriptTimeout`, the trade is stalled. It may be marked as `Failure`, eligible for refund, and no payment occurs.

#### <mark style="color:orange;">Function Descriptions</mark>

* **`selectPMM(tradeId, info)`**:
  * Executable only by the authorized `Solver` through the `Router`.
  * Validates the stage, timeout, fees, and signatures.
* **`report(tradeId, msgError, signature)`**:
  * Executable only by authorized `MPC Node`.
  * The trade transitions to `FAILURE`, enabling refunds after timeout.

#### <mark style="color:orange;">Refund and Query</mark>

* Post `SELECT_PMM`, query functions track trade status:
  * **For Success:** Use `getCurrentStage` to confirm advancement, `getPMMSelection` for selection data.
  * **For Failure:** Use `getCurrentStage` to confirm failure, `getFailureInfo` for error details.


---

# 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/optimex-l2-network/stage-pmm-selection-and-failure-handling.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.
