I want to calculate in solidity and uniswap dex the max amount of coins I can receive before touching 5% slippage with 0, 1 and 2 hops (or at least, approximately).
For example, suppose I want to convert COIN1 to COIN2. I want to calculate the max amount of ETH I can receive before hitting 5% slippage, supposing that exist a pair COIN1-COIN2.
Also, with one hop, for example, COIN1 to COIN2 and to COIN3, the max amount of ETH to receive in this case, supposing that exist pairs COIN1-COIN2 and COIN2-COIN3.
And with two hops, for example, COIN1 to COIN2 to COIN3 to COIN4, supposing that exist pairs COIN1-COIN2, COIN2-COIN3, COIN3-COIN4.
I'm not sure how to calculate this. Thanks appreciated.