Cross-Chain Swap Logic
Import Statements:
Ordiswap imports multiple modules (factory
, orderbook
, thorswap
) and various utilities and configurations, including constants and functions.
Order Type Constants:
Ordiswap defines constants (ORDER_TYPE_BTC_ETH
, ORDER_TYPE_ETH_BTC
, ORDER_TYPE_BRC_ETH
, ORDER_TYPE_ETH_BRC
) representing different types of bridge orders.
Send Bitcoin with Data:
sendBtcWithData
: Sends Bitcoin with data to a specified recipient address. It retrieves inputs, calculates fees, creates a raw transaction, signs it, and sends it. It supports attaching additional data to the transaction.
Success and Fail Order Processing:
successProcess
: Updates a bridge order with success details and status.
failProcess
: Updates a bridge order with failure details and status.
Order Retrieval and Listing:
getOrder
: Retrieves a bridge order from the DB collection based on a given filter.
getOrderList
: Retrieves a list of bridge orders based on specified filter, sort, start, and limit parameters.
Add Order:
addOrder
: Adds a bridge order to the DB collection. It also interacts with Thorswap if the order type is related to BTC-ETH, ETH-BTC, or ETH-BRC.
BRC-ETH Order Processing:
processBrcEthOrder
: Processes a BRC-ETH-related bridge order. It interacts with Ordiswap, obtains Thorswap quotes, and handles Bitcoin transactions with data.
ETH-BRC Order Processing:
processEthBrcOrder
: Processes an ETH-BRC-related bridge order. It interacts with Thorswap, Ordiswap, and handles Bitcoin transactions with data.
Bridge Order Processing Thread:
bridgeThread
: Runs an infinite loop to periodically process bridge orders. It fetches pending bridge orders, processes each order based on its type, and then waits for a specified duration.
Error Handling:
Ordiswap includes error handling for various scenarios, logging errors for further analysis.
System Flow:
Order Placement:
Users can add a bridge order (addOrder
) with various types, including BTC-ETH, ETH-BTC, BRC-ETH, ETH-BRC. The system checks conditions for each type and may interact with Thorswap or Ordiswap accordingly.
Order Processing:
The background thread (bridgeThread
) continuously processes ordered bridge orders. It interacts with Thorswap, Ordiswap, and handles Bitcoin transactions based on the type of order.
Last updated