Hi, we recently have conducted a systematic study about Solidity event usage, evolution, and impact, and we are attempting to build a tool to improve the practice of Solidity event use based on our findings. We have tried our prototype tool on some of the most popular GitHub Solidity repositories, and for your repository, we find a potential optimization of gas consumption arisen from event use.
The point is that when we use emit operation to store the value of a certain variable, local memory type variable would be preferable to global storage type (state) variable if they hold the same value. The reason is that an extra SLOAD operation would be needed to access the variable if it is storage type, and the SLOAD operation costs 800 gas.
For your repository, we find that the following event use can be improved:
- FraxUniV3Farm_V2.sol
function name:โsetMultipliers
event name:โโMaxVeFXSMultiplierโโ
โโโโโโโโLockedStakeMaxMultiplierUpdatedโโ
โโโโโโโโveFXSPerFraxForMaxBoostUpdatedโโ
โโโโโโโโveFXSBoostScaleFactor
variable:โโโโvefxs_max_multiplier->_vefxs_max_multiplierโโ
โโโโโโโโlock_max_multiplier->_lock_max_multiplierโโ
โโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boostโโ
โโโโโโโโvefxs_boost_scale_factor->_vefxs_boost_scale_factor
function setMultipliers(
uint256 _lock_max_multiplier,
uint256 _vefxs_max_multiplier,
uint256 _vefxs_per_frax_for_max_boost,
uint256 _vefxs_boost_scale_factor
) external onlyByOwnGov {
require(_lock_max_multiplier >= MULTIPLIER_PRECISION, "Mult must be >= MULTIPLIER_PRECISION");
require(_vefxs_max_multiplier >= 0, "veFXS mul must be >= 0");
require(_vefxs_per_frax_for_max_boost > 0, "veFXS pct max must be >= 0");
require(_vefxs_boost_scale_factor > 0, "veFXS boost scale factor must be >= 0");
lock_max_multiplier = _lock_max_multiplier;
vefxs_max_multiplier = _vefxs_max_multiplier;
vefxs_per_frax_for_max_boost = _vefxs_per_frax_for_max_boost;
vefxs_boost_scale_factor = _vefxs_boost_scale_factor;
emit MaxVeFXSMultiplier(vefxs_max_multiplier);
emit LockedStakeMaxMultiplierUpdated(lock_max_multiplier);
emit veFXSPerFraxForMaxBoostUpdated(vefxs_per_frax_for_max_boost);
emit veFXSBoostScaleFactor(vefxs_boost_scale_factor);
}
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
function setLockedStakeTimeForMinAndMaxMultiplier(uint256 _lock_time_for_max_multiplier, uint256 _lock_time_min) external onlyByOwnGov {
require(_lock_time_for_max_multiplier >= 1, "Mul max time must be >= 1");
require(_lock_time_min >= 1, "Mul min time must be >= 1");
lock_time_for_max_multiplier = _lock_time_for_max_multiplier;
lock_time_min = _lock_time_min;
emit LockedStakeTimeForMaxMultiplier(lock_time_for_max_multiplier);
emit LockedStakeMinTime(_lock_time_min);
}
- veFXSYieldDistributor.sol
function name:โsetYieldDuration
event name:โโYieldDurationUpdated
variable:โโโโyieldDuration->_yieldDuration
function setYieldDuration(uint256 _yieldDuration) external onlyByOwnGov {
require(periodFinish == 0 || block.timestamp > periodFinish, "Previous yield period must be complete before changing the duration for the new period");
yieldDuration = _yieldDuration;
emit YieldDurationUpdated(yieldDuration);
}
- FraxCrossChainFarmSushi.sol
function name:โsetMultipliers
event name:โโMaxVeFXSMultiplierโโ
โโโโโโโโLockedStakeMaxMultiplierUpdatedโโ
โโโโโโโโveFXSPerFraxForMaxBoostUpdatedโโ
variable:โโโโvefxs_max_multiplier->_vefxs_max_multiplierโโ
โโโโโโโโlock_max_multiplier->_lock_max_multiplierโโ
โโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boostโโ
function setMultipliers(uint256 _lock_max_multiplier, uint256 _vefxs_max_multiplier, uint256 _vefxs_per_frax_for_max_boost) external onlyByOwnGov {
require(_lock_max_multiplier >= MULTIPLIER_PRECISION, "Mult must be >= MULTIPLIER_PRECISION");
require(_vefxs_max_multiplier >= 0, "veFXS mul must be >= 0");
require(_vefxs_per_frax_for_max_boost > 0, "veFXS pct max must be >= 0");
lock_max_multiplier = _lock_max_multiplier;
vefxs_max_multiplier = _vefxs_max_multiplier;
vefxs_per_frax_for_max_boost = _vefxs_per_frax_for_max_boost;
emit MaxVeFXSMultiplier(vefxs_max_multiplier);
emit LockedStakeMaxMultiplierUpdated(lock_max_multiplier);
emit veFXSPerFraxForMaxBoostUpdated(vefxs_per_frax_for_max_boost);
}
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
function setLockedStakeTimeForMinAndMaxMultiplier(uint256 _lock_time_for_max_multiplier, uint256 _lock_time_min) external onlyByOwnGov {
require(_lock_time_for_max_multiplier >= 1, "Mul max time must be >= 1");
require(_lock_time_min >= 1, "Mul min time must be >= 1");
lock_time_for_max_multiplier = _lock_time_for_max_multiplier;
lock_time_min = _lock_time_min;
emit LockedStakeTimeForMaxMultiplier(lock_time_for_max_multiplier);
emit LockedStakeMinTime(_lock_time_min);
}
- StakingRewards.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
function setRewardsDuration(uint256 _rewardsDuration) external onlyByOwnGov {
require(
periodFinish == 0 || block.timestamp > periodFinish,
"Reward period incomplete"
);
rewardsDuration = _rewardsDuration;
emit RewardsDurationUpdated(rewardsDuration);
}
โโfunction name:โsetMultipliers
โโevent name:โโMaxCRBoostMultiplier
โโโโโโโโโโLockedStakeMaxMultiplierUpdated
โโvariable:โโโโcr_boost_max_multiplier->_cr_boost_max_multiplier
โโโโโโโโโโlocked_stake_max_multiplier->_locked_stake_max_multiplier
function setMultipliers(uint256 _locked_stake_max_multiplier, uint256 _cr_boost_max_multiplier) external onlyByOwnGov {
require(_locked_stake_max_multiplier >= 1, "Multiplier must be greater than or equal to 1");
require(_cr_boost_max_multiplier >= 1, "Max CR Boost must be greater than or equal to 1");
locked_stake_max_multiplier = _locked_stake_max_multiplier;
cr_boost_max_multiplier = _cr_boost_max_multiplier;
emit MaxCRBoostMultiplier(cr_boost_max_multiplier);
emit LockedStakeMaxMultiplierUpdated(locked_stake_max_multiplier);
}
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlocked_stake_time_for_max_multiplier->_locked_stake_time_for_max_multiplier
- StakingRewardsDualV2.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโMaxCRBoostMultiplier
โโโโโโโโโโLockedStakeMaxMultiplierUpdated
โโvariable:โโโโcr_boost_max_multiplier->_cr_boost_max_multiplier
โโโโโโโโโโlocked_stake_max_multiplier->_locked_stake_max_multiplier
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlocked_stake_time_for_max_multiplier->_locked_stake_time_for_max_multiplier
-
veFXSYieldDistributorV3.sol
function name:โsetYieldDuration
event name:โโYieldDurationUpdated
variable:โโโโyieldDuration->_yieldDuration
-
FraxUniV3Farm_Volatile.sol
function name:โsetMultipliers
event name:โโMaxVeFXSMultiplier
โโโโโโโโLockedNFTMaxMultiplierUpdated
โโโโโโโโveFXSPctForMaxBoostUpdated
variable:โโโโvefxs_max_multiplier->_vefxs_max_multiplier
โโโโโโโโlock_max_multiplier->_lock_max_multiplier
โโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boost
โโfunction name:โsetLockedNFTTimeForMinAndMaxMultiplier
โโevent name:โโLockedNFTTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
-
veFXSYieldDistributorV2.sol
function name:โsetYieldDuration
event name:โโYieldDurationUpdated
variable:โโโโyieldDuration->_yieldDuration
-
StakingRewardsDualV4.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโMaxVeFXSMultiplier
โโโโโโโโโโLockedStakeMaxMultiplierUpdated
โโโโโโโโโโveFXSPerFraxForMaxBoostUpdated
โโvariable:โโโโvefxs_max_multiplier->_vefxs_max_multiplier
โโโโโโโโโโlock_max_multiplier->_lock_max_multiplier
โโโโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boost
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
- StakingRewardsDual.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโMaxCRBoostMultiplier
โโโโโโโโโโLockedStakeMaxMultiplierUpdated
โโvariable:โโโโcr_boost_max_multiplier->_cr_boost_max_multiplier
โโโโโโโโโโlocked_stake_max_multiplier->_locked_stake_max_multiplier
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlocked_stake_time_for_max_multiplier->_locked_stake_time_for_max_multiplier
- StakingRewardsDualV3.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโMaxVeFXSMultiplier
โโโโโโโโโโLockedStakeMaxMultiplierUpdated
โโโโโโโโโโveFXSPerFraxForMaxBoostUpdated
โโvariable:โโโโvefxs_max_multiplier->_vefxs_max_multiplier
โโโโโโโโโโlock_max_multiplier->_lock_max_multiplier
โโโโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boost
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
- FraxFarmBSC_Dual_V5.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโLockedStakeMaxMultiplierUpdated
โโvariable:โโโโlock_max_multiplier->_lock_max_multiplier
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
- MigratableFarmBSC.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโLockedStakeMaxMultiplierUpdated
โโvariable:โโโโlocked_stake_max_multiplier->_locked_stake_max_multiplier
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlocked_stake_time_for_max_multiplier->_locked_stake_time_for_max_multiplier
- AnyswapV4ERC20.sol
function name:โchangeVault
event name:โโLogChangeVault
variable:โโโโpendingVault->newVault
โโfunction name:โchangeMPCOwner
โโevent name:โโLogChangeMPCOwner
โโvariable:โโโโpendingVault->newVault
- FraxCrossChainFarm.sol
function name:โsetMultipliers
event name:โโMaxVeFXSMultiplier
โโโโโโโโLockedStakeMaxMultiplierUpdated
โโโโโโโโveFXSPerFraxForMaxBoostUpdated
variable:โโโโvefxs_max_multiplier->_vefxs_max_multiplier
โโโโโโโโlock_max_multiplier->_lock_max_multiplier
โโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boost
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
- FraxCrossChainFarmV2.sol
function name:โsetMultipliers
event name:โโMaxVeFXSMultiplier
โโโโโโโโLockedStakeMaxMultiplierUpdated
โโโโโโโโveFXSPerFraxForMaxBoostUpdated
variable:โโโโvefxs_max_multiplier->_vefxs_max_multiplier
โโโโโโโโlock_max_multiplier->_lock_max_multiplier
โโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boost
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
-
veFXSYieldDistributorV4.sol
function name:โsetYieldDuration
event name:โโYieldDurationUpdated
variable:โโโโyieldDuration->_yieldDuration
-
CommunalFarm.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโLockedStakeMaxMultiplierUpdated
โโvariable:โโโโlock_max_multiplier->_lock_max_multiplier
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
- FraxUniV3Farm_Stable.sol
function name:โsetMultipliers
event name:โโMaxVeFXSMultiplier
โโโโโโโโLockedStakeMaxMultiplierUpdated
โโโโโโโโveFXSPerFraxForMaxBoostUpdated
variable:โโโโvefxs_max_multiplier->_vefxs_max_multiplier
โโโโโโโโlock_max_multiplier->_lock_max_multiplier
โโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boost
โโfunction name:โsetLockedNFTTimeForMinAndMaxMultiplier
โโevent name:โโLockedNFTTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
- StakingRewardsDualV5.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโMaxVeFXSMultiplier
โโโโโโโโโโLockedStakeMaxMultiplierUpdated
โโโโโโโโโโveFXSPerFraxForMaxBoostUpdated
โโvariable:โโโโvefxs_max_multiplier->_vefxs_max_multiplier
โโโโโโโโโโlock_max_multiplier->_lock_max_multiplier
โโโโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boost
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
โโfunction name:โsetRewardsDuration
โโevent name:โโRewardsDurationUpdated
โโvariable:โโโโrewardsDuration->_rewardsDuration
- StakingRewardsMultiGauge.sol
function name:โsetRewardsDuration
event name:โโRewardsDurationUpdated
variable:โโโโrewardsDuration->_rewardsDuration
โโfunction name:โsetMultipliers
โโevent name:โโMaxVeFXSMultiplier
โโโโโโโโโโLockedStakeMaxMultiplierUpdated
โโโโโโโโโโveFXSPerFraxForMaxBoostUpdated
โโvariable:โโโโvefxs_max_multiplier->_vefxs_max_multiplier
โโโโโโโโโโlock_max_multiplier->_lock_max_multiplier
โโโโโโโโโโvefxs_per_frax_for_max_boost->_vefxs_per_frax_for_max_boost
โโfunction name:โsetLockedStakeTimeForMinAndMaxMultiplier
โโevent name:โโLockedStakeTimeForMaxMultiplier
โโvariable:โโโโlock_time_for_max_multiplier->_lock_time_for_max_multiplier
-
celrFRAX.sol
function name:โupdateBridge
event name:โโBridgeUpdated
variable:โโโโbridge->_bridge
-
AnyswapV5ERC20.sol
function name:โchangeVault
event name:โโLogChangeVault
variable:โโโโpendingVault->newVault
โโfunction name:โchangeMPCOwner
โโevent name:โโLogChangeMPCOwner
โโvariable:โโโโpendingVault->newVault
-
celrFXS.sol
function name:โupdateBridge
event name:โโBridgeUpdated
variable:โโโโbridge->_bridge
-
AnyswapV4ERC20.sol
function name:โchangeVault
event name:โโLogChangeVault
variable:โโโโpendingVault->newVault
โโfunction name:โchangeMPCOwner
โโevent name:โโLogChangeMPCOwner
โโvariable:โโโโpendingVault->newVault
Do you find our results useful? Your reply and invaluable suggestions would be greatly appreciated, and are vital for improving our tool. Thanks a lot for your time!