Всем привет. Помогите пожалуйста разобраться с роутером панкейка, есть там такая функция:
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'PancakeLibrary: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'PancakeLibrary: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(998);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
у меня на контракте есть такая:
function getReserves(address pool, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniPair(pool).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
function getAmountOut(uint amountIn, address pool, address fromToken, address toToken) internal view returns (uint amountOut) {
(uint reserveIn, uint reserveOut) = getReserves(pool, fromToken, toToken);
uint amountInWithFee = mul(amountIn, 998);
uint numerator = mul(amountInWithFee, reserveOut);
uint denominator = add(mul(reserveIn, 1000), amountInWithFee);
amountOut = numerator / denominator;
}
я ее переносил из роутера (PancakeLibrary точнее, роутером она вызывается) в свой контракт и заменил вызовы safeMath на функции перенесенные в контракт из safeMath, с целью экономии газа, но получаю при тех же данных разные результаты (amount out). Не могу понять почему