[G-01] Usage of uint256 instead of boolean state variable in storage and/or save a slot
You can save one slot by packing variable creationUnlocked with address state variables LBPairImplementation (L32) or feeRecipient (L34).
Or (resp and) you can change boolean state variable into a uint256 (resp uint64) to save gas from Gwarmaccess (100 gas) for the extra SLOAD plus it avoids Gsset (20000 gas) when changing from ‘false’ to ‘true’, after having been ‘true’ in the past.
[G-02] Set to payable permissionened functions that are guaranteed to revert for normal users
For example, this change only on function sweep in contract LBRouter.sol saves 2609 gas on deployement cost of the contract LBRouter and on average 22gas in function sweep usage.
I. Case for modifier onlyFactoryOwner
Function sweep in LBRouter.sol and change in interface ILBRouter.sol
Gas optimization report
[G-01] Usage of uint256 instead of boolean state variable in storage and/or save a slot
You can save one slot by packing variable
creationUnlocked
with address state variablesLBPairImplementation
(L32) orfeeRecipient
(L34).Or (resp and) you can change boolean state variable into a uint256 (resp uint64) to save gas from
Gwarmaccess
(100 gas) for the extraSLOAD
plus it avoidsGsset
(20000 gas) when changing from ‘false’ to ‘true’, after having been ‘true’ in the past.[G-02] Set to
payable
permissionened functions that are guaranteed to revert for normal usersFor example, this change only on function sweep in contract LBRouter.sol saves 2609 gas on deployement cost of the contract LBRouter and on average 22gas in function sweep usage.
I. Case for modifier
onlyFactoryOwner
Function sweep in LBRouter.sol and change in interface ILBRouter.sol
Function sweepLBToken in LBRouter.sol and change in interface ILBRouter.sol
II. Case for modifier
onlyFactory
Function setFeesParameters in LBRPair.sol and change in interface ILBRouter.sol
Function forceDecay in LBRPair.sol and change in interface ILBRouter.sol
[G-03] Postfixed index in loops are less gas efficient (i++/j++ and i--/j--) compared to prefixed index in loops
Saves 5 gas for each loop using postfixed indexes.
LBQuoter.sol
LBRouter.sol