Uniswap charges 0.3% fee after swap
So how much you get after transaction fee? Get the value about
(uint amountIn, uint reserveIn, uint reserveOut) ⇒ (uint amountOut)
amountIn = 1000 reserveIn (WETH) = 43086702975516 reserveOut (USDC) = 41997552572672937696884
amountInWithFee = 1000*997 = 997000
numerator = 997000*41997552572672937696884
denominator = 43086702975516*1000 + 9997000
amountOut=(99700041997552572672937696884)/(430867029755161000+9997000)
⇒ 971797724440 ( 974721890337 : This value is using quote🌟 function)
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
//Solidity cannnot calculate decimal point so, using 997/1000 to get 0.3%
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
https://github.com/Uniswap/v2-periphery/blob/master/contracts/libraries/UniswapV2Library.sol#L43