I am struggling to figure out how can we deduce the formula used in getAmountIn. Basically here if we want to maximize our profit those two pools must have almost the same price at final stage. Hence we have:
(x1 + delta_x1) / (y1 - delta_y1) = (x2 - delta_x2) / (y2 + delta_y1)
Also we know how the pair pool is updating accordingly after swap:
(x1 + 0.997 * delta_x1) (y1 - delta_y1) = x1y1
(x2 - delta_x2)(y2 + 0.997 * delta_y1) = x2y2
Based on equations mentioned above, i just have no clue how can i simplify it to the formula in the code. Do i miss anything here ?
|
function getAmountIn(PairReserves memory firstPairData, PairReserves memory secondPairData) internal pure returns (uint256) { |
I am struggling to figure out how can we deduce the formula used in
getAmountIn. Basically here if we want to maximize our profit those two pools must have almost the same price at final stage. Hence we have:Also we know how the pair pool is updating accordingly after swap:
Based on equations mentioned above, i just have no clue how can i simplify it to the formula in the code. Do i miss anything here ?
simple-blind-arbitrage/src/blindBackrun.sol
Line 83 in 6258205