paraswap-dex-lib
paraswap-dex-lib copied to clipboard
Feat: Add AirSwap
AirSwap (https://airswap.io/) is an RFQ DEX. Counter-party discovery and token pricing are communicated off-chain; atomic token swaps are settled on-chain. AirSwap itself is a technology provider and runs no infrastructure of its own. More info on our wiki.
Notes AirSwap uses a smart contract (Registry) for server URL discovery.
- We use StatefulEventSubscriber for the Registry.
- Registry is instantiated for every AirSwap instance.
AirSwap calls multiple third-party server URLs for pricing and orders.
- We use Fetcher to make HTTP calls on an interval.
- Fetcher is not instantiated for slave AirSwap instances.
- Prices are communicated to slaves via the cache.
Limitation: Tests cannot pass reliably on third-party servers, so:
- During tests an env var overrides URLs to point to a local server.
- Alternatively, we could pass a
isLocal
flag intoinitializePricing
- Alternatively, we could check
process.env.NODE_ENV
istest
Flow
-
initializePricing
is called by the engine a. Registry starts up; hydrates; listens for event updates to track active server URLs b. Worker starts up (if not a slave process); writes pricing from active servers URLs to cache. -
getPoolIdentifiers
returns unique identifiers for active server URLs for a given token pair. -
getPricesVolume
pulls identifiers for a pair and reads the cache for pricing. -
preProcessTransaction
calls get*SideOrder on winning server. -
getSimpleParam
encodes the function call for the SwapERC20 contract.
Tests
For the initial review, simple tests are passing.
airswap-e2e.test.ts
, airswap-events.test.ts
, airswap-integration.test.ts
.