Skip to content

Technical Steps

Keno Dressel edited this page Nov 18, 2021 · 9 revisions

Swap in uniswap

  1. Select ExactIn or ExactOut (depends on which number the user entered and which number is calculated)
  2. Find all existing pairs by search for direct T1<-->T2 trades or via defined base pairs (eg. T1 --> WETH + WETH --> T2)
  3. Search all existing trade pairs for a path via the sdk with a maximum of 3 total trades
  4. the sdk maps the trade request from the interface to actual contract calls in the router

A very condensed example can be seen here: https://github.com/jklepatch/eattheblocks/blob/master/screencast/217-uniswap-v2/javascript/index.js

Adaptation for AE-DEX

  1. Select ExactIn or ExactOut (depends on which number the user entered and which number is calculated)
  2. Check if there is a pair that maps this exact trade
  3. Execute trade directly via swapExactETHForTokens, swapExactTokensForETH or swapTokensForExactTokens

Add Liquidity

  1. Grant the router an allowance for the desired token amount(s)
  2. Call addLiquidity or addLiquidityETH with the according ratio defined by the pool
  3. Ratio can be obtained getAmountsIn

Remove Liquidity

  1. Call removeLiquidity or removeLiquidityETH
Clone this wiki locally