Cross-Chain Swap API Handling
Powered by THORChain
Configuration:
Ordiswap is configured with retry and rate-limiting capabilities. This ensures robustness in case of network issues and prevents abuse of the Thorswap API by limiting the number of requests per second.
API Endpoints:
Ordiswap defines constants for Thorswap API endpoints (THORSWAP_STATUS_API
and THORSWAP_QUOTE_API
), which are used for checking the status of swaps and obtaining quotes for swap transactions.
Quote Retrieval:
getThorswapQuote
: Retrieves a quote for a swap transaction based on specified parameters like source asset, target asset, amount, and destination.
Order Management in MongoDB Collection:
getOrder
: Retrieves a order from the DB collection based on a given filter.
addOrder
: Adds a order to the DB collection. It checks if the order already exists and processes the order after insertion.
Order Processing:
processOrder
: Processes a order by checking the status of the corresponding swap on Thorswap. If the swap has been finalized, it updates the order status and details in the DB collection.
Order Status Constants:
Ordiswap defines constants (ORDER_STATUS_ORDERED
, ORDER_STATUS_FAILED
, ORDER_STATUS_SUCCESS
) representing different states of orders.
Error Handling:
Ordiswap includes error handling for HTTP requests and other potential errors during order processing. It logs errors for further analysis.
System Flow:
Order Placement:
Users can add a order (addOrder
) by providing an order ID. The system checks if the order already exists and, if not, adds it to the DB collection.
Order Processing:
The background thread (thorswapThread
) continuously processes orders. It checks the status, updates the order details, and finalizes orders when applicable.
Last updated