TokenEngineeringCommunity / BalancerPools_Model

cadCAD model to simulate Balancer AMMs
MIT License
54 stars 29 forks source link

Compute slippage #9

Open AngelaKTE opened 3 years ago

AngelaKTE commented 3 years ago
VasilySumanov commented 3 years ago

A function for computing slippage in case of single-side liquidity provision for token_amount_in (number of tokens) tokens of token_in type - slippage_in:

  1. Calculate the lp_token_value_in by multiplying token_amount_in on current ?USD price of token_in type
  2. Call join_swap_extern_amount_in with token_in and token_amount_in input parameters. The function will return pool_amount_out, which is defined as lp_pool_out in our Naming Convention
  3. Calculate the current value of received BPT Tokens lp_pool_value using the algorithm presented in Issue 3
  4. The absolute slippage in decimal: (lp_token_value_in - lp_pool_value)/lp_token_value_in