Replicate Solidity code math results in JS

Hi everyone,
I am trying to replicate the result Uniswap provides (for ETH/DAI) with this Tx (https://etherscan.io/tx/0x65e3d4e2d13874d68040a7a142a77ddb18a559720c77d8666da62842e27a469a/) knowing that the last Tx was (https://etherscan.io/tx/0x50f3103e569f8e89ea14ea6bd08de2ce06a67402a4181692d6c9fc9514cacec8/), this is where I got the reserves from (communicated above).
I replicated the getAmountOut() function in Uni v2 (Solidity) and adapted it to JS using FixedNumber and/or BigNumber with ethers.js)

BUT I always find 160522461258881396040 instead of 160523449249855866787 :frowning:
Same results in Python…

Could someone confirm it is a lib issue and/or explain to me how to replicate the Solidity code behavior in JS?

Thanks a lot for your help!

1 Like

Hi @ibox,

You may want to check with the Uniswap community on the calculation differences.

will do, thanks @abcoathup