# Stage: Confirm Deposit & Failure Handling

This phase follows the submission of a trade and the user's deposit of funds into a Vault on the source asset-chain. Here, Multi-Party Computation (MPC) nodes validate the trade before it continues. The MPC's key roles include:

* Verifying the deposit amount and source addresses match the trade data.
* Validating pre-signatures for both settlement and refund paths.
* Ensuring data and signatures are consistent and untampered.

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

**✅ Successful Deposit Match**

If the MPC confirms the deposits match expectations, `confirmDeposit` is called, moving the trade to `SELECT_PMM`.

**❌ Failure or Timeout**

If there's a mismatch, the trade is marked `Failure`, halting progress. After `scriptTimeout`, MPC triggers a refund of the user's funds.

**✅ Valid Deposit: `confirmDeposit()`**

**Function**: `confirmDeposit(bytes32 tradeId, bytes memory signature, bytes[] memory depositFromList) external`

**Requirements**:

* Called via the `Router` contract by an authorized MPC Node.
* Validates trade is at `CONFIRM_DEPOSIT` stage.
* Uses EIP-712 for signature verification.
* Transition trade to `SELECT_PMM` upon validation.

**Event**: Emits `DepositConfirmed`, indicating progression to `SELECT_PMM`.

**❌ Invalid Deposit or Error: `report()`**

**Function**: `report(bytes32 tradeId, bytes calldata msgError, bytes calldata signature) external`

**Requirements**:

* Called via the `Router` contract by an authorized MPC Node.
* Trade should not be finalized as `COMPLETED`, `FAILURE`, or `REFUNDED`.
* Invalid deposits trigger halt and a `FailureReported` event.

**⚠️ Key Aspects to Report Failure**

* Mismatch with `amountIn`.
* Invalid pre-signatures.
* Tampered data in `scriptInfo`.

**Event**: `FailureReported`, providing transparency on failed trades.

### <mark style="color:orange;">Queryable Trade Data</mark>

**✅ On Successful Deposit Confirmation**

* **Get Trade Stage**: `getCurrentStage(bytes32 tradeId)` - Returns the stage (e.g., `SELECT_PMM`).
* **Get Deposit Address List**: `getDepositAddressList(bytes32 tradeId)` - Lists addresses that deposited into the Vault.

**❌ On Invalid Deposit or Timeout**

* **Get Trade Stage**: `getCurrentStage(bytes32 tradeId)` - Returns the stage (e.g., `FAILURE`).
* **Get Failure Details**: `getFailureInfo(bytes32 tradeId)` - Provides error metadata, including stage and failure reason.


---

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