Skip to content

Pre release gas savings#83

Merged
Joeysantoro merged 3 commits intoReleasefrom
Pre-Release-Gas-Savings
Mar 3, 2021
Merged

Pre release gas savings#83
Joeysantoro merged 3 commits intoReleasefrom
Pre-Release-Gas-Savings

Conversation

@Joeysantoro
Copy link
Contributor

Instead of double calculating the oracle update and incentives, infer the burn and mint via the token balances

@Joeysantoro Joeysantoro changed the base branch from Release to Add-Permit-Mint March 2, 2021 04:02
@Joeysantoro Joeysantoro changed the base branch from Add-Permit-Mint to Release March 2, 2021 04:03
Comment on lines 130 to 145
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);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from UniswapSingleEthRouter

Comment on lines -70 to -71
function incentiveContract() public view override returns(IUniswapIncentive) {
return IUniswapIncentive(CORE.fei().incentiveContract(address(PAIR)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer needed because call is removed

Comment on lines 109 to 127
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from UniswapSingleEthRouter

Comment on lines +104 to 107
if (effectiveAmountIn < amountIn) {
uint256 penalty = amountIn - effectiveAmountIn;
require(penalty <= maxPenalty, "FeiRouter: Penalty too high");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new penalty calculation

Comment on lines 95 to 102
(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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from UniswapSingleEthRouter with a variable rename

Comment on lines 52 to 68
(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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from UniswapSingleEthRouter

assert(IWETH(WETH).transfer(address(PAIR), amountIn));

address fei = isETH0 ? PAIR.token1() : PAIR.token0();
uint256 feiBalanceBefore = IERC20(fei).balanceOf(to);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check before balance for implied bonus comparison

Comment on lines +75 to +76
uint256 feiBalanceAfter = IERC20(fei).balanceOf(to);
uint256 reward = feiBalanceAfter.sub(feiBalanceBefore).sub(amountOut);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Difference should be the reward

Comment on lines +30 to 38
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
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from UniswapSingleEthRouter

IWETH(WETH).deposit{value: amountIn}();
assert(IWETH(WETH).transfer(address(PAIR), amountIn));

address fei = isETH0 ? PAIR.token1() : PAIR.token0();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Joeysantoro Joeysantoro merged commit e7eb24f into Release Mar 3, 2021
@xklob xklob deleted the Pre-Release-Gas-Savings branch September 19, 2021 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments