Skip to content

Commit

Permalink
Reduce redundant calculations
Browse files Browse the repository at this point in the history
Reduce redundant calculations of `amountIn.mul(997)` in the function `_swap` of contract `SushiMaker.sol`
  • Loading branch information
tanliwei authored Apr 22, 2021
1 parent d49f444 commit cbccf12
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions contracts/SushiMaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ contract SushiMaker is Ownable {
uint256 amountInWithFee = amountIn.mul(997);
if (fromToken == pair.token0()) {
amountOut =
amountIn.mul(997).mul(reserve1) /
amountInWithFee.mul(reserve1) /
reserve0.mul(1000).add(amountInWithFee);
IERC20(fromToken).safeTransfer(address(pair), amountIn);
pair.swap(0, amountOut, to, new bytes(0));
// TODO: Add maximum slippage?
} else {
amountOut =
amountIn.mul(997).mul(reserve0) /
amountInWithFee.mul(reserve0) /
reserve1.mul(1000).add(amountInWithFee);
IERC20(fromToken).safeTransfer(address(pair), amountIn);
pair.swap(amountOut, 0, to, new bytes(0));
Expand Down

0 comments on commit cbccf12

Please sign in to comment.