# Integration Guide

The integration comprises of two components:

* Wallet-Client which is to be implemented by the Web3 Wallet provider and run natively on the Web3 Wallet UI.
* `Optimex SDK-API` that runs inside a Trusted Execution Environment (TEE) on Optimex infrastructure. The TEE ensures integrity and attested execution of `Optimex SDK-API` logic, so that no attacker can tamper with its execution and cause it to deviate from the prescribed protocol.

As Optimex focuses on BTC trading, all supported trading pairs involve BTC and an asset on a smart contract-enabled blockchain (e.g., EVM or Solana blockchains). Swaps that have BTC as the base asset (i.e., User want to swap from BTC to other assets such as ETH or SOL), the swap workflow is slightly different in comparison with swaps whose base assets are on EVM or Solana chains.&#x20;

### <mark style="color:orange;">BTC as base asset</mark>&#x20;

In this flow, `Optimex SDK-API` first requests indicative quotes from the MMs via Solver. These quotes are indicative in a sense that MMs are not bound to execute trade at these quoted rate. Among the responding MMs, a selected few will be chosen (say 3 or 4 MMs). One of these pre-selected MMs will facilitate the swap and subsequently receive the user's BTC asset.

The `Optimex SDK-API` then builds a BTCScript that implements the following logic:

* Within the expiry time T: Fund held in the BTCScript can be spent using a combination of 2 standard ECDSA signatures (i.e., 2-of-2 multisig). The two signers are:
  * the *Settlement Committee* (denoted as MPC in the figure below)
  * *the `Optimex SDK-API`*
* After time T: The funds can be spent unilaterally by the User (via his/her Wallet-Client) if no action has been taken.

Upon completing payment to the User, the PMM is expected to post the payment information onto Optimex L2. Once the Settlement Committee (aka MPC) verifies that PMM's payment to user is valid, it will present use the `Optimex SDK-API`'s signature along with its own (threshold) signature to settle the Vault.

### <mark style="color:orange;">EVM and Solana tokens as base asset</mark>

User Deposit Vault on EVM chains and Solana are implemented using smart contract, as opposed to a restricted script under UTXO model as in the case of BTC asset.

The swap starts with the user identifying a few best indicative quotes and their corresponding MMs. The `Optimex SDK-API` then provides the necessary parameters for the Wallet-Client to make a deposit transaction, sending the user's asset to the corresponding Deposit Vault. The deposit transaction contains the list of pre-selected MMs. The Vault's smart contract ensures that the user asset can only be sent to one of the pre-selected MMs that facilitates the user's swap.

For more technical details, including API and code example, please refer to our repository at this [link](https://github.com/optimex-xyz/provider-api-docs).


---

# 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/wallet-client-integration/overview.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.
