1 Emit event at the end of the function to save gas.
There are so many places in which events will be emitted in the middle of a function. I know that the position of events does not matter. But I checked and confirmed that gas will be saved with the position of the event. you can save gas if you emit your events at the end of functions.
function _impound(
TurboSafe safe,
uint256 feiAmount,
uint256 assetAmount,
address to
) internal {
Emit ImpoundExecuted(msg.sender, safe, feiAmount, assetAmount);
fei.mint(address(this), feiAmount);
require(feiTurboCToken.repayBorrowBehalf(address(safe), feiAmount) ==0, “REPAY_FAILED”);
safe.gib(to, assetAmount);
}
and use it in Impound and impoundAll.
6 input validation for amount or shares can save gas if they are zero.
2022-02-tribe-turbo Gas Optimization
1 Emit event at the end of the function to save gas.
There are so many places in which events will be emitted in the middle of a function. I know that the position of events does not matter. But I checked and confirmed that gas will be saved with the position of the event. you can save gas if you emit your events at the end of functions.
2 Delete unused import statement.
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboMaster.sol#L13
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/modules/TurboGibber.sol#L4
3 Delete unused params in canSafeBoostVault.
safe and feiAmount are not used in canSafeBootVault, so you can delete these params.
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/modules/TurboBooster.sol#L100-L113
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboMaster.sol#L232-L242
And following import statement will be deleted too.
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/modules/TurboBooster.sol#L8
4 Input validation can save gas in case the auth will try to update with the present frozen state.
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/modules/TurboBooster.sol#L37-L42
Add require(freeze != frozen, “frozen will be not updated”);
5 code duplication
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/modules/TurboGibber.sol#L83-L92
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/modules/TurboGibber.sol#L111-L120 Create an internal function to save gas. For example
function _impound( TurboSafe safe, uint256 feiAmount, uint256 assetAmount, address to
) internal { Emit ImpoundExecuted(msg.sender, safe, feiAmount, assetAmount); fei.mint(address(this), feiAmount); require(feiTurboCToken.repayBorrowBehalf(address(safe), feiAmount) ==0, “REPAY_FAILED”); safe.gib(to, assetAmount); } and use it in Impound and impoundAll.
6 input validation for amount or shares can save gas if they are zero.
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L49 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L57-L64 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L74 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L84 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L94 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L104 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L118 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L122 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L126 https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/TurboRouter.sol#L130
7 Delete unused import statement.
https://github.com/code-423n4/2022-02-tribe-turbo/blob/main/src/modules/TurboGibber.sol#L4