1. Cheaper checks should be moved up
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #1
241 // Require freeVotes exceed the delegation size
242 uint256 free = freeVotes(delegator);
243 if (delegatee == address(0) || free < amount) revert DelegationError();
The address check should be split out and moved to before the call to freeVotes()
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L241-L243
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #2
393 require(signer != address(0));
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L393
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #3
259 if (cycle - block.timestamp <= incrementFreezeWindow) revert IncrementFreezeError();
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L259
2. Multiple address
mappings can be combined into a single mapping
of an address
to a struct
, where appropriate
Saves a storage slot for the mapping. Depending on the circumstances and sizes of types, can avoid a Gsset (20000 gas). Reads and subsequent writes can also be cheaper
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #1
59 mapping(address => mapping(address => uint112)) public getUserGaugeWeight;
60
61 /// @notice a mapping from a user to their total allocated weight across all gauges
62 /// @dev NOTE this may contain weights for deprecated gauges
63 mapping(address => uint112) public getUserWeight;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L59-L63
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #2
151 mapping(address => mapping(address => uint256)) private _delegatesVotesCount;
152
153 /// @notice mapping from a delegator to the total number of delegated votes.
154 mapping(address => uint256) public userDelegatedVotes;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L151-L154
3. State variables should be cached in stack variables rather than re-reading them from storage
The instances below point to the second access of a state variable within a function. Caching will replace each Gwarmaccess (100 gas) with a much cheaper stack read.
Less obvious fixes/optimizations include having local storage variables of mappings within state variable mappings or mappings within state variable structs, having local storage variables of structs within mappings, or having local caches of state variable contracts/addresses.
File: lib/ERC4626/src/xERC4626.sol #1
40 rewardsCycleEnd = (block.timestamp.safeCastTo32() / rewardsCycleLength) * rewardsCycleLength;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L40
File: lib/ERC4626/src/xERC4626.sol #2
89 uint32 end = ((timestamp + rewardsCycleLength) / rewardsCycleLength) * rewardsCycleLength;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L89
File: lib/flywheel-v2/src/FlywheelCore.sol #3
168 rewardToken.safeTransferFrom(address(flywheelRewards), address(newFlywheelRewards), oldRewardBalance);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L168
File: lib/flywheel-v2/src/FlywheelCore.sol #4
168 rewardToken.safeTransferFrom(address(flywheelRewards), address(newFlywheelRewards), oldRewardBalance);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L168
File: lib/flywheel-v2/src/FlywheelCore.sol #5
221 ? flywheelBooster.boostedTotalSupply(strategy)
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L221
File: lib/flywheel-v2/src/FlywheelCore.sol #6
259 ? flywheelBooster.boostedBalanceOf(strategy, user)
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L259
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #7
90 gaugeCycle = (block.timestamp.safeCastTo32() / gaugeCycleLength) * gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L90
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #8
103 uint32 currentCycle = (block.timestamp.safeCastTo32() / gaugeCycleLength) * gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L103
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #9
135 uint32 currentCycle = (block.timestamp.safeCastTo32() / gaugeCycleLength) * gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L135
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #10
158 uint112 queued = nextCycleQueuedRewards;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L158
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #11
146 uint32 offset = paginationOffset;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L146
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #12
174 address[] memory gauges = gaugeToken.gauges(offset, numRewards);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L174
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #13
92 return (nowPlusOneCycle / gaugeCycleLength) * gaugeCycleLength; // cannot divide by zero and always <= nowPlusOneCycle so no overflow
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L92
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #14
263 if (added && _userGauges[user].length() > maxGauges && !canContractExceedMaxGauges[user])
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L263
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #15
61 return pos == 0 ? 0 : _checkpoints[account][pos - 1].votes;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L61
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #16
269 _delegatesVotesCount[delegator][delegatee] = newDelegates;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L269
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #17
354 _delegatesVotesCount[user][delegatee] = 0;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L354
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #18
352 require(_delegates[user].remove(delegatee)); // Remove from set. Should never fail.
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L352
4. <x> += <y>
costs more gas than <x> = <x> + <y>
for state variables
File: lib/ERC4626/src/xERC4626.sol #1
67 storedTotalAssets -= amount;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L67
File: lib/ERC4626/src/xERC4626.sol #2
72 storedTotalAssets += amount;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L72
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #3
155 nextCycleQueuedRewards += uint112(newRewards); // in case a previous incomplete cycle had rewards, add on
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L155
5. ++i
/i++
should be unchecked{++i}
/unchecked{++i}
when it is not possible for them to overflow, as is the case when used in for
- and while
-loops
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #1
189 for (uint256 i = 0; i < size; i++) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L189
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #2
346 for (uint256 i = 0; i < size && (userFreeVotes + totalFreed) < votes; i++) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L346
6. require()
/revert()
strings longer than 32 bytes cost extra gas
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #1
379 require(block.timestamp <= expiry, "ERC20MultiVotes: signature expired");
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L379
7. Not using the named return variables when a function returns, wastes deployment gas
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #1
231 return 0;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L231
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #2
248 return _incrementUserAndGlobalWeights(msg.sender, weight, currentCycle);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L248
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #3
317 return _incrementUserAndGlobalWeights(msg.sender, weightsSum, currentCycle);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L317
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #4
331 return _decrementUserAndGlobalWeights(msg.sender, weight, currentCycle);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L331
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #5
394 return _decrementUserAndGlobalWeights(msg.sender, weightsSum, currentCycle);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L394
8. Using bool
s for storage incurs overhead
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/58f635312aa21f947cae5f8578638a85aa2519f5/contracts/security/ReentrancyGuard.sol#L23-L27
Use uint256(1)
and uint256(2)
for true/false
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #1
450 mapping(address => bool) public canContractExceedMaxGauges;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L450
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #2
111 mapping(address => bool) public canContractExceedMaxDelegates;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L111
9. Use a more recent version of solidity
Use a solidity version of at least 0.8.2 to get compiler automatic inlining
Use a solidity version of at least 0.8.3 to get better struct packing and cheaper multiple storage reads
Use a solidity version of at least 0.8.4 to get custom errors, which are cheaper at deployment than revert()/require()
strings
Use a solidity version of at least 0.8.10 to have external calls skip contract existence checks if the external call has a return value
File: lib/ERC4626/src/xERC4626.sol #1
4 pragma solidity ^0.8.0;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L4
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #2
3 pragma solidity ^0.8.0;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L3
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #3
4 pragma solidity ^0.8.0;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L4
File: lib/xTRIBE/src/xTRIBE.sol #4
4 pragma solidity ^0.8.0;
https://github.com/fei-protocol/xTRIBE/tree/989e47d176facbb0c38bc1e1ca58672f179159e1/src/xTRIBE.sol#L4
10. It costs more gas to initialize variables to zero than to let the default of zero be applied
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #1
189 for (uint256 i = 0; i < size; i++) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L189
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #2
134 for (uint256 i = 0; i < num; ) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L134
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #3
184 for (uint256 i = 0; i < num; ) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L184
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #4
307 for (uint256 i = 0; i < size; ) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L307
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #5
384 for (uint256 i = 0; i < size; ) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L384
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #6
564 for (uint256 i = 0; i < size && (userFreeWeight + totalFreed) < weight; ) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L564
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #7
79 uint256 low = 0;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L79
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #8
346 for (uint256 i = 0; i < size && (userFreeVotes + totalFreed) < votes; i++) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L346
File: lib/xTRIBE/src/xTRIBE.sol #9
95 for (uint256 i = 0; i < size; ) {
https://github.com/fei-protocol/xTRIBE/tree/989e47d176facbb0c38bc1e1ca58672f179159e1/src/xTRIBE.sol#L95
11. internal
functions only called once can be inlined to save gas
File: lib/flywheel-v2/src/FlywheelCore.sol #1
146 function _addStrategyForRewards(ERC20 strategy) internal {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L146
12. ++i
costs less gas than ++i
, especially when it's used in for
-loops (--i
/i--
too)
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #1
189 for (uint256 i = 0; i < size; i++) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L189
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #2
346 for (uint256 i = 0; i < size && (userFreeVotes + totalFreed) < votes; i++) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L346
13. Usage of uints
/ints
smaller than 32 bytes (256 bits) incurs overhead
When using elements that are smaller than 32 bytes, your contract’s gas usage may be higher. This is because the EVM operates on 32 bytes at a time. Therefore, if the element is smaller than that, the EVM must use more operations in order to reduce the size of the element from 32 bytes to the desired size.
https://docs.soliditylang.org/en/v0.8.11/internals/layout_in_storage.html
Use a larger size then downcast where needed
File: lib/ERC4626/src/xERC4626.sol #1
24 uint32 public immutable rewardsCycleLength;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L24
File: lib/ERC4626/src/xERC4626.sol #2
27 uint32 public lastSync;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L27
File: lib/ERC4626/src/xERC4626.sol #3
30 uint32 public rewardsCycleEnd;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L30
File: lib/ERC4626/src/xERC4626.sol #4
33 uint192 public lastRewardAmount;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L33
File: lib/ERC4626/src/xERC4626.sol #5
37 constructor(uint32 _rewardsCycleLength) {
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L37
File: lib/ERC4626/src/xERC4626.sol #6
48 uint192 lastRewardAmount_ = lastRewardAmount;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L48
File: lib/ERC4626/src/xERC4626.sol #7
49 uint32 rewardsCycleEnd_ = rewardsCycleEnd;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L49
File: lib/ERC4626/src/xERC4626.sol #8
50 uint32 lastSync_ = lastSync;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L50
File: lib/ERC4626/src/xERC4626.sol #9
79 uint192 lastRewardAmount_ = lastRewardAmount;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L79
File: lib/ERC4626/src/xERC4626.sol #10
80 uint32 timestamp = block.timestamp.safeCastTo32();
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L80
File: lib/ERC4626/src/xERC4626.sol #11
89 uint32 end = ((timestamp + rewardsCycleLength) / rewardsCycleLength) * rewardsCycleLength;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L89
File: lib/flywheel-v2/src/FlywheelCore.sol #12
195 uint224 index;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L195
File: lib/flywheel-v2/src/FlywheelCore.sol #13
197 uint32 lastUpdatedTimestamp;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L197
File: lib/flywheel-v2/src/FlywheelCore.sol #14
201 uint224 public constant ONE = 1e18;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L201
File: lib/flywheel-v2/src/FlywheelCore.sol #15
224 uint224 deltaIndex;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L224
File: lib/flywheel-v2/src/FlywheelCore.sol #16
244 uint224 strategyIndex = state.index;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L244
File: lib/flywheel-v2/src/FlywheelCore.sol #17
245 uint224 supplierIndex = userIndex[strategy][user];
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L245
File: lib/flywheel-v2/src/FlywheelCore.sol #18
256 uint224 deltaIndex = strategyIndex - supplierIndex;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L256
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #19
44 event CycleStart(uint32 indexed cycleStart, uint256 rewardAmount);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L44
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #20
47 event QueueRewards(address indexed gauge, uint32 indexed cycleStart, uint256 rewardAmount);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L47
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #21
50 uint32 public gaugeCycle;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L50
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #22
53 uint32 public immutable gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L53
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #23
56 uint32 internal nextCycle;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L56
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #24
59 uint112 internal nextCycleQueuedRewards;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L59
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #25
62 uint32 internal paginationOffset;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L62
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #26
66 uint112 priorCycleRewards;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L66
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #27
67 uint112 cycleRewards;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L67
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #28
68 uint32 storedCycle;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L68
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #29
103 uint32 currentCycle = (block.timestamp.safeCastTo32() / gaugeCycleLength) * gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L103
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #30
104 uint32 lastCycle = gaugeCycle;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L104
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #31
135 uint32 currentCycle = (block.timestamp.safeCastTo32() / gaugeCycleLength) * gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L135
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #32
136 uint32 lastCycle = gaugeCycle;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L136
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #33
146 uint32 offset = paginationOffset;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L146
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #34
158 uint112 queued = nextCycleQueuedRewards;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L158
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #35
181 uint32 currentCycle,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L181
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #36
182 uint32 lastCycle,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L182
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #37
198 uint112 completedRewards = queuedRewards.storedCycle == lastCycle ? queuedRewards.cycleRewards : 0;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L198
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #38
218 function getAccruedRewards(ERC20 gauge, uint32 lastUpdatedTimestamp)
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L218
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #39
226 uint32 cycle = gaugeCycle;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L226
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #40
237 uint32 cycleEnd = cycle + gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L237
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #41
241 uint112 cycleRewardsNext = queuedRewards.cycleRewards;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L241
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #42
250 uint32 beginning = lastUpdatedTimestamp > cycle ? lastUpdatedTimestamp : cycle;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L250
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #43
253 uint32 elapsed = block.timestamp.safeCastTo32() - beginning;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L253
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #44
254 uint32 remaining = cycleEnd - beginning;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L254
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #45
36 constructor(uint32 _gaugeCycleLength, uint32 _incrementFreezeWindow) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L36
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #46
36 constructor(uint32 _gaugeCycleLength, uint32 _incrementFreezeWindow) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L36
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #47
47 uint32 public immutable gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L47
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #48
50 uint32 public immutable incrementFreezeWindow;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L50
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #49
53 uint112 storedWeight;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L53
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #50
54 uint112 currentWeight;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L54
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #51
55 uint32 currentCycle;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L55
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #52
84 function getGaugeCycleEnd() public view returns (uint32) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L84
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #53
89 function _getGaugeCycleEnd() internal view returns (uint32) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L89
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #54
90 uint32 nowPlusOneCycle = block.timestamp.safeCastTo32() + gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L90
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #55
97 function getGaugeWeight(address gauge) public view returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L97
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #56
102 function getStoredGaugeWeight(address gauge) public view returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L102
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #57
108 function _getStoredWeight(Weight storage gaugeWeight, uint32 currentCycle) internal view returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L108
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #58
108 function _getStoredWeight(Weight storage gaugeWeight, uint32 currentCycle) internal view returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L108
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #59
113 function totalWeight() external view returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L113
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #60
118 function storedTotalWeight() external view returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L118
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #61
210 uint32 currentCycle = _getGaugeCycleEnd();
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L210
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #62
212 uint112 total = _getStoredWeight(_totalWeight, currentCycle);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L212
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #63
213 uint112 weight = _getStoredWeight(_getGaugeWeight[gauge], currentCycle);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L213
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #64
234 event IncrementGaugeWeight(address indexed user, address indexed gauge, uint256 weight, uint32 cycleEnd);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L234
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #65
237 event DecrementGaugeWeight(address indexed user, address indexed gauge, uint256 weight, uint32 cycleEnd);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L237
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #66
245 function incrementGauge(address gauge, uint112 weight) external returns (uint112 newUserWeight) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L245
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #67
245 function incrementGauge(address gauge, uint112 weight) external returns (uint112 newUserWeight) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L245
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #68
246 uint32 currentCycle = _getGaugeCycleEnd();
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L246
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #69
254 uint112 weight,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L254
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #70
255 uint32 cycle
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L255
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #71
275 uint112 weight,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L275
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #72
276 uint32 cycle
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L276
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #73
277 ) internal returns (uint112 newUserWeight) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L277
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #74
302 uint112 weightsSum;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L302
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #75
304 uint32 currentCycle = _getGaugeCycleEnd();
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L304
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #76
309 uint112 weight = weights[i];
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L309
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #77
326 function decrementGauge(address gauge, uint112 weight) external returns (uint112 newUserWeight) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L326
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #78
326 function decrementGauge(address gauge, uint112 weight) external returns (uint112 newUserWeight) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L326
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #79
327 uint32 currentCycle = _getGaugeCycleEnd();
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L327
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #80
337 uint112 weight,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L337
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #81
338 uint32 cycle
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L338
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #82
340 uint112 oldWeight = getUserGaugeWeight[user][gauge];
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L340
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #83
355 uint112 weight,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L355
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #84
356 uint32 cycle
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L356
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #85
357 ) internal returns (uint112 newUserWeight) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L357
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #86
372 returns (uint112 newUserWeight)
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L372
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #87
378 uint112 weightsSum;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L378
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #88
380 uint32 currentCycle = _getGaugeCycleEnd();
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L380
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #89
386 uint112 weight = weights[i];
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L386
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #90
404 function(uint112, uint112) view returns (uint112) op,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L404
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #91
404 function(uint112, uint112) view returns (uint112) op,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L404
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #92
404 function(uint112, uint112) view returns (uint112) op,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L404
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #93
405 uint112 delta,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L405
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #94
406 uint32 cycle
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L406
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #95
408 uint112 currentWeight = weight.currentWeight;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L408
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #96
410 uint112 stored = weight.currentCycle < cycle ? currentWeight : weight.storedWeight;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L410
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #97
411 uint112 newWeight = op(currentWeight, delta);
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L411
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #98
418 function _add(uint112 a, uint112 b) private pure returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L418
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #99
418 function _add(uint112 a, uint112 b) private pure returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L418
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #100
418 function _add(uint112 a, uint112 b) private pure returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L418
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #101
422 function _subtract(uint112 a, uint112 b) private pure returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L422
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #102
422 function _subtract(uint112 a, uint112 b) private pure returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L422
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #103
422 function _subtract(uint112 a, uint112 b) private pure returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L422
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #104
453 function addGauge(address gauge) external requiresAuth returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L453
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #105
457 function _addGauge(address gauge) internal returns (uint112 weight) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L457
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #106
463 uint32 currentCycle = _getGaugeCycleEnd();
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L463
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #107
483 uint32 currentCycle = _getGaugeCycleEnd();
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L483
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #108
486 uint112 weight = _getGaugeWeight[gauge].currentWeight;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L486
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #109
553 uint32 currentCycle = _getGaugeCycleEnd();
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L553
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #110
556 uint112 userFreed;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L556
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #111
557 uint112 totalFreed;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L557
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #112
566 uint112 userGaugeWeight = getUserGaugeWeight[user][gauge];
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L566
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #113
28 uint32 fromBlock;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L28
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #114
29 uint224 votes;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L29
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #115
36 function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoint memory) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L36
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #116
41 function numCheckpoints(address account) public view virtual returns (uint32) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L41
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #117
375 uint8 v,
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L375
File: lib/xTRIBE/src/xTRIBE.sol #118
18 returns (uint96);
https://github.com/fei-protocol/xTRIBE/tree/989e47d176facbb0c38bc1e1ca58672f179159e1/src/xTRIBE.sol#L18
File: lib/xTRIBE/src/xTRIBE.sol #119
20 function getCurrentVotes(address account) external view returns (uint96);
https://github.com/fei-protocol/xTRIBE/tree/989e47d176facbb0c38bc1e1ca58672f179159e1/src/xTRIBE.sol#L20
File: lib/xTRIBE/src/xTRIBE.sol #120
37 uint32 _rewardsCycleLength,
https://github.com/fei-protocol/xTRIBE/tree/989e47d176facbb0c38bc1e1ca58672f179159e1/src/xTRIBE.sol#L37
File: lib/xTRIBE/src/xTRIBE.sol #121
38 uint32 _incrementFreezeWindow
https://github.com/fei-protocol/xTRIBE/tree/989e47d176facbb0c38bc1e1ca58672f179159e1/src/xTRIBE.sol#L38
14. Expressions for constant values such as a call to keccak256()
, should use immutable
rather than constant
See this issue for a detail description of the issue
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #1
368 bytes32 public constant DELEGATION_TYPEHASH =
369 keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L368-L369
15. Using private
rather than public
for constants, saves gas
If needed, the value can be read from the verified contract source code
File: lib/ERC4626/src/xERC4626.sol #1
24 uint32 public immutable rewardsCycleLength;
https://github.com/fei-protocol/ERC4626/blob/643cd044fac34bcbf64e1c3790a5126fec0dbec1/src/xERC4626.sol#L24
File: lib/flywheel-v2/src/FlywheelCore.sol #2
201 uint224 public constant ONE = 1e18;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L201
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #3
53 uint32 public immutable gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L53
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #4
47 uint32 public immutable gaugeCycleLength;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L47
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #5
50 uint32 public immutable incrementFreezeWindow;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L50
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #6
368 bytes32 public constant DELEGATION_TYPEHASH =
369 keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L368-L369
16. Multiplication/division by two should use bit shifting
<x> * 2
is equivalent to <x> << 1
and <x> / 2
is the same as <x> >> 1
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #1
94 return (a & b) + (a ^ b) / 2;
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L94
17. require()
or revert()
statements that check input arguments should be at the top of the function
Checks that involve constants should come before checks that involve state variables
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #1
392 require(nonce == nonces[signer]++, "ERC20MultiVotes: invalid nonce");
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L392
18. Empty blocks should be removed
The code should be refactored such that they no longer exist, or the block should do something useful, such as emitting an event or reverting. If the block is an empty if-statement block to avoid doing subsequent checks in the else-if/else conditions, the else-if/else conditions should be nested under the negation of the if-statement, because they involve different classes of checks, which may lead to the introduction of errors when the code is later modified (if(x){}else if(y){...}else{...}
=> if(!x){if(y){...}else{...}}
)
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #1
243 if (incompleteCycle) {
244 // If current cycle queue incomplete, do nothing to current cycle rewards or accrued
245 } else if (block.timestamp >= cycleEnd) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L243-L245
19. Use custom errors rather than revert()
/require()
strings to save deployment gas
File: lib/flywheel-v2/src/FlywheelCore.sol (various lines) #1
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol (various lines) #2
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol
20. Functions guaranteed to revert when called by normal users can be marked payable
If a function modifier such as onlyOwner
is used, the function will revert if a normal user tries to pay the function. Marking the function as payable
will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.
File: lib/flywheel-v2/src/FlywheelCore.sol #1
142 function addStrategyForRewards(ERC20 strategy) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L142
File: lib/flywheel-v2/src/FlywheelCore.sol #2
165 function setFlywheelRewards(IFlywheelRewards newFlywheelRewards) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L165
File: lib/flywheel-v2/src/FlywheelCore.sol #3
183 function setBooster(IFlywheelBooster newBooster) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L183
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #4
101 function queueRewardsForCycle() external requiresAuth returns (uint256 totalQueuedForCycle) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L101
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #5
133 function queueRewardsForCyclePaginated(uint256 numRewards) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L133
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #6
218 function getAccruedRewards(ERC20 gauge, uint32 lastUpdatedTimestamp)
219 external
220 override
221 onlyFlywheel
222 returns (uint256 accruedRewards)
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L218-L222
File: lib/flywheel-v2/src/rewards/FlywheelGaugeRewards.sol #7
273 function setRewardsStream(IRewardsStream newRewardsStream) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelGaugeRewards.sol#L273
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #8
453 function addGauge(address gauge) external requiresAuth returns (uint112) {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L453
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #9
475 function removeGauge(address gauge) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L475
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #10
495 function replaceGauge(address oldGauge, address newGauge) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L495
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #11
502 function setMaxGauges(uint256 newMax) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L502
File: lib/flywheel-v2/src/token/ERC20Gauges.sol #12
510 function setContractExceedMaxGauges(address account, bool canExceedMax) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L510
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #13
114 function setMaxDelegates(uint256 newMax) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L114
File: lib/flywheel-v2/src/token/ERC20MultiVotes.sol #14
122 function setContractExceedMaxDelegates(address account, bool canExceedMax) external requiresAuth {
https://github.com/fei-protocol/flywheel-v2/tree/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20MultiVotes.sol#L122
File: lib/xTRIBE/src/xTRIBE.sol #15
89 function emitVotingBalances(address[] calldata accounts)
90 external
91 requiresAuth
https://github.com/fei-protocol/xTRIBE/tree/989e47d176facbb0c38bc1e1ca58672f179159e1/src/xTRIBE.sol#L89-L91
File: lib/xTRIBE/src/xTRIBE.sol #16
108 function syncRewards() public override requiresAuth {
https://github.com/fei-protocol/xTRIBE/tree/989e47d176facbb0c38bc1e1ca58672f179159e1/src/xTRIBE.sol#L108