paraswap-dex-lib icon indicating copy to clipboard operation
paraswap-dex-lib copied to clipboard

Feat: Add AirSwap

Open dmosites opened this issue 1 year ago • 0 comments

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.

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 into initializePricing
  • Alternatively, we could check process.env.NODE_ENV is test

Flow

  1. 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.
  2. getPoolIdentifiers returns unique identifiers for active server URLs for a given token pair.
  3. getPricesVolume pulls identifiers for a pair and reads the cache for pricing.
  4. preProcessTransaction calls get*SideOrder on winning server.
  5. 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.

dmosites avatar Jan 12 '24 10:01 dmosites