FIX: CLP formula msising on swap calc
Problem
The front end changes have broken the CLP formula on the swap calculations and now seems to calculate the tokensEmitted
based on the ratio of assets only.
Solution
Restore CLP formula which existed previously to calculate 'TOKENS YOU WILL RECEIVE' based on 'TOKENS YOU ARE SWAPPING' and the depths of the pools. eg. tokensEmitted = ( x * X * Y ) / ( x + X )^2
Steps to reproduce
- Restore an existing pool to 10:1 ratio RUNE:token (or create new pool)
- Enter swap amount 100 RUNE > BNB. The tokensEmitted doesn't honour the CLP formula.
Using /v1/pools/BNB.BNB
for pool depths and the input amount:
x = 100
X = 110
Y = 11
y = 2.7437
Where:
x = input amount (in RUNE)
X = runeDepth
from BNB.BNB pool
Y = assetDepth
from BNB.BNB pool
y = output amount (in BNB)
Nb. Also make sure tradeslip is calculated and shown properly: tradeSlip = x * ( 2X + x) / ( x + X )^2
Edited by Níðhöggr