# Stage: Trade Initialization

The trade is initialized when a user deposits funds into the designated `Vault` on the source asset-chain network (such as Bitcoin, EVM-compatible networks, or Solana). At this point, deposit confirmation is not required. A `Solver` submits the trade via the `Router` contract while awaiting deposit confirmation.

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

```plaintext
submitTrade(
    bytes32 tradeId,
    TradeData calldata tradeData,
    Affiliate calldata affiliateInfo,
    SettlementPresign[] calldata settlementPresigns,
    RefundPresign calldata refundPresign
) external;
```

#### Permissioned Execution

* Must be initiated through the `Router` contract.
* Caller must be an authorized `Solver`.

#### Trade Stage Validation

* **Stage & Trade ID**: Ensure the trade is in the `SUBMIT` stage with a matching tradeId derived from session-specific inputs.
* **Timeout**: Verify that the trade has not expired (`scriptTimeout`).
* **Whitelisting**: Both source/destination chains and tokens must be whitelisted via the `Management` contract.
* **MPC Key**: Ensure `mpcAssetPubkey` is active and not expired.
* **PMM Check**: All participating PMMs must be registered in the Management contract.
* **Affiliate Fee**: Total affiliate fees must not exceed protocol-defined limits.

#### Refund Presign

* **Bitcoin**: Requires a valid `refundPresign` for MPC validation.
* **EVM/Solana**: Pre-signature must be empty, and `refundAddress` must match the one in `tradeData`.

#### Settlement Presigns

* User-submitted signatures stored, but not verified at this stage. Verification occurs at `CONFIRM_DEPOSIT`.

#### Fee Calculation

* **EVM/Solana**: Protocol and affiliate fees are computed when submitted.
* **Bitcoin**: Protocol fee is deferred to PMM selection.

Fee details (`pFeeAmount` and `aFeeAmount`) are calculated based on the trade amount and rates.

#### Trade State Transition

* Trade progresses to `CONFIRM_DEPOSIT`.
* Records trade details, pre-signatures, and fee amounts on-chain.

#### Event Emission

* Emits `TradeInfoSubmitted` event providing crucial trade details. This signals the MPC to begin subsequent processing.

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

Once submitted, the following trade information is publicly queryable:

* **Get Trade Stage**:

  ```plaintext
  getCurrentStage(bytes32 tradeId) external view returns (uint256);
  ```
* **Get Trade Data**:

  ```plaintext
  getTradeData(bytes32 tradeId) external view returns (TradeData memory);
  ```
* **Get Settlement Presigns**:

  ```plaintext
  getSettlementPresigns(bytes32 tradeId) external view returns (SettlementPresign[] memory);
  ```
* **Get Refund Presign**:

  ```plaintext
  getRefundPresigns(bytes32 tradeId) external view returns (RefundPresign memory);
  ```
* **Get Affiliate Info**:

  ```plaintext
  getAffiliateInfo(bytes32 tradeId) external view returns (Affiliate memory);
  ```


---

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