Overview
This section provides and overview on how a Web3 Wallet can integrate Optimex Swap as one of the core functions in its UI.
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 ofOptimex 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.
BTC as base asset
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.
EVM and Solana tokens as base asset
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.
Last updated