三明治最大盈利怎么计算

匿名用户 提出于 2023-06-13 03:55 3567 浏览

知道目标的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];
};
0xa8
0xa8 区块链开发工程师

采纳率 50% · 回答于 2023-06-13 13:37

其它 0 个回答

写回答

你需要登录后才可以回答问题,登录