Context: We are creating a smart contract which integrates Uniswap DEX for swapping Tokens to ETH. We need to make sure one swap does not impact the token price more than 3%.
We are in need to write a function which takes in input the
reserve0: uint and
reserve1: uint and outputs the maximum
amount of tokens which when swapped for ETH on uniswap will have the given price impact on the token price.
So, can someone please help in understanding how is the price impact calculated on the uniswap swap page, and also in writing a function which ouputs maximum number of tokens to be swapped for ETH which would have the given price impact?