100 三明治最大盈利怎么计算

知道目标的AmountIn和AmountOut,还有该pair的ReserveIn和ReserveOut。 最大的抢跑数量应该怎么计算

请先 登录 后评论

最佳答案 2023-06-14 19:22

const amounts = [AmountIn,AmountOut]
const reserves = [ReserveIn,ReserveOut]
const tolerance = 6n//你自己的滑点
const calculateAmountInMax = (amounts, reserves, tolerance) => {
    const amountsWithFee = [
        amounts[0] * (10000n - router.fee - tolerance) / 10000n,
        amounts[1]
    ];

    const k = reserves[0] * reserves[1];

    const a = amountsWithFee[1];
    const b = amountsWithFee[1] * amountsWithFee[0];
    const c = -(k * amountsWithFee[0]);

    const x = (-b + sqrt(b * b - 4n * a * c)) / (2n * a);

    return x - reserves[0];
};
请先 登录 后评论

其它 0 个回答

  • 1 关注
  • 1 收藏,1613 浏览
  • 提出于 2023-06-13 03:55