Closed ygorgeurts closed 3 years ago
This comes from the invariant formula of uniswap V2 AMM, which is a*b = k.
So when you calculate the output amount of a swap, that is (a + \delta a) (b - \delta b) = a b. You can calculate the delta a by given a delta b or do a reverse calculation.
For more, you can see the Uniswap source code: https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L42-L59
The formula \delta a_1 = \delta b_1 * a1 / (b_1 - \delta b_1)
is in the getAmountIn
function. And for simplicity, we do not consider the fee calculation in this project.(In uniswap, there's a swap fee of 0.3%).
Hi,
Can you elaborate on where the first set of formula's come from: \delta a_1 = \delta b_1 * a1 / (b_1 - \delta b_1) ?
Thanks!
Ygor