SyncSwap Technical Docs
  • Documentation Overview
  • Pool Master
  • Fee Manager
    • Overview
    • Contract Details
    • Liquidity Pool Overview
  • Stable Pool
    • Overview
    • Pool Contract
    • Pool Factory
  • Classic Pool
    • Overview
    • Pool Contract
    • Pool Factory
  • Aqua Pool
    • Overview
    • Pool Contract
  • Integrations
    • Introduction to Protocol
    • Calculate a route
  • Routers
    • SyncSwap Smart Router
    • Deployment Addresses
  • Valut
    • Overview
Powered by GitBook
On this page
  • Get candidate pools
  • Get pool info and filtering
  • Calculate a swap
  1. Integrations

Calculate a route

PreviousIntroduction to ProtocolNextSyncSwap Smart Router

Last updated 6 months ago

To calculate a route for a swap, assuming we have the following input parameters.

For example, when swapping 1 ETH for 2500 USDC

  • Input token - ETH or WETH

  • Output token - USDC

  • Input amount - 1 ETH (or 1e18 in uint)

Get candidate pools

The first step is to look up candidate pools, assuming we use the direct route.

Call getPool() function in the Pool Master contract with encoded input/output tokens and pool types.

Different protocol versions have different pool master contracts, and need to be requested individually.

Get pool info and filtering

Once we got candidate pools, we could call pool functions to get pool info, including pool reservers, and pool's amplification coefficient, and fees (from fee manager).

Calculate a swap

The next step is to calculate a swap using the pool info, and input parameters. Applying different pool algorithms (xy=k for Classic, or hybrid algorithm of Stable and Aqua Pools).

We will get an output result - whether the swap can be handled by the pool, and the output amount.

Logocore-contracts/contracts/master/SyncSwapPoolMaster.sol at master · syncswap/core-contractsGitHub