Welcome to our Help Center 👋

How is slippage calculated in the backend when I zap into a pool?

Written by zes
Updated 2 months ago

For the slippage calculation we assign a USD ($) price to each pool token. Then if you know the USD price of the input you can calculate the number of pool tokens you should receive given 0 slippage. and subtract from that to get the desired minimum tokens. 

The expected amount of tokens received is calculated by: input in USD / pool token price in USD, where pool token price is reserveValueInUSD / totalSupply. reserveValueInUSD is the sum of USD price of token * number of tokens in reserve for both reserves. 

As an example: for DAI/ETH, reserveValueInUSD is

DAI price in $ * number of DAI in reserve + 
ETH price in $ * number of ETH in reserve

Alternatively the Graph QL API returns reserveValueInUSD pre-computed for each pool. The total supply is the total supply of LP tokens for that pool.

Did this answer your question?