Conversation
| function _getReserves() | ||
| internal | ||
| view | ||
| returns ( | ||
| uint256 reservesETH, | ||
| uint256 reservesOther, | ||
| bool isETH0 | ||
| ) | ||
| { | ||
| (uint256 reserves0, uint256 reserves1, ) = PAIR.getReserves(); | ||
| isETH0 = PAIR.token0() == address(WETH); | ||
| return | ||
| isETH0 | ||
| ? (reserves0, reserves1, isETH0) | ||
| : (reserves1, reserves0, isETH0); | ||
| } |
There was a problem hiding this comment.
copied from UniswapSingleEthRouter
| function incentiveContract() public view override returns(IUniswapIncentive) { | ||
| return IUniswapIncentive(CORE.fei().incentiveContract(address(PAIR))); |
There was a problem hiding this comment.
no longer needed because call is removed
| amountOut = UniswapV2Library.getAmountOut( | ||
| effectiveAmountIn, | ||
| reservesOther, | ||
| reservesETH | ||
| ); | ||
| require( | ||
| amountOut >= amountOutMin, | ||
| "FeiRouter: Insufficient output amount" | ||
| ); | ||
|
|
||
| (uint256 amount0Out, uint256 amount1Out) = | ||
| isETH0 ? (amountOut, uint256(0)) : (uint256(0), amountOut); | ||
|
|
||
| PAIR.swap(amount0Out, amount1Out, address(this), new bytes(0)); | ||
|
|
||
| IWETH(WETH).withdraw(amountOut); | ||
|
|
||
| TransferHelper.safeTransferETH(to, amountOut); | ||
| return amountOut; |
There was a problem hiding this comment.
copied from UniswapSingleEthRouter
| if (effectiveAmountIn < amountIn) { | ||
| uint256 penalty = amountIn - effectiveAmountIn; | ||
| require(penalty <= maxPenalty, "FeiRouter: Penalty too high"); | ||
| } |
There was a problem hiding this comment.
new penalty calculation
contracts/router/FeiRouter.sol
Outdated
| (uint256 reservesETH, uint256 reservesOther, bool isETH0) = | ||
| _getReserves(); | ||
|
|
||
| address fei = isETH0 ? PAIR.token1() : PAIR.token0(); | ||
|
|
||
| IERC20(fei).transferFrom(msg.sender, address(PAIR), amountIn); | ||
|
|
||
| uint256 effectiveAmountIn = IERC20(fei).balanceOf(address(PAIR)).sub(reservesOther); |
There was a problem hiding this comment.
copied from UniswapSingleEthRouter with a variable rename
contracts/router/FeiRouter.sol
Outdated
| (uint256 reservesETH, uint256 reservesOther, bool isETH0) = _getReserves(); | ||
|
|
||
| uint256 amountIn = msg.value; | ||
| amountOut = UniswapV2Library.getAmountOut( | ||
| amountIn, | ||
| reservesETH, | ||
| reservesOther | ||
| ); | ||
|
|
||
| require( | ||
| amountOut >= amountOutMin, | ||
| "FeiRouter: Insufficient output amount" | ||
| ); | ||
| IWETH(WETH).deposit{value: amountIn}(); | ||
| assert(IWETH(WETH).transfer(address(PAIR), amountIn)); | ||
|
|
||
| address fei = isETH0 ? PAIR.token1() : PAIR.token0(); |
There was a problem hiding this comment.
copied from UniswapSingleEthRouter
| assert(IWETH(WETH).transfer(address(PAIR), amountIn)); | ||
|
|
||
| address fei = isETH0 ? PAIR.token1() : PAIR.token0(); | ||
| uint256 feiBalanceBefore = IERC20(fei).balanceOf(to); |
There was a problem hiding this comment.
check before balance for implied bonus comparison
| uint256 feiBalanceAfter = IERC20(fei).balanceOf(to); | ||
| uint256 reward = feiBalanceAfter.sub(feiBalanceBefore).sub(amountOut); |
There was a problem hiding this comment.
Difference should be the reward
| modifier ensure(uint256 deadline) { | ||
| // solhint-disable-next-line not-rely-on-time | ||
| require(deadline >= block.timestamp, "FeiRouter: Expired"); | ||
| _; | ||
| } | ||
|
|
||
| receive() external payable { | ||
| assert(msg.sender == address(WETH)); // only accept ETH via fallback from the WETH contract | ||
| } |
There was a problem hiding this comment.
copied from UniswapSingleEthRouter
contracts/router/FeiRouter.sol
Outdated
| IWETH(WETH).deposit{value: amountIn}(); | ||
| assert(IWETH(WETH).transfer(address(PAIR), amountIn)); | ||
|
|
||
| address fei = isETH0 ? PAIR.token1() : PAIR.token0(); |
There was a problem hiding this comment.
Great place to add comments about what is going on here. Code is clear enough given context, but we'll be glad to have them later
Instead of double calculating the oracle update and incentives, infer the burn and mint via the token balances