From 0a4a784713e7703ab91cec8aaa469618de407036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Fingen?= Date: Mon, 2 Dec 2024 17:53:21 +0000 Subject: [PATCH] fix: Some minor gas optimizations --- src/Governance.sol | 10 +++++----- src/UserProxy.sol | 4 ++-- src/utils/Math.sol | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Governance.sol b/src/Governance.sol index 00adefb3..138ff952 100644 --- a/src/Governance.sol +++ b/src/Governance.sol @@ -468,8 +468,10 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, Ownable, IG InitiativeVoteSnapshot memory _votesForInitiativeSnapshot, InitiativeState memory _initiativeState ) public view returns (InitiativeStatus status, uint16 lastEpochClaim, uint256 claimableAmount) { + uint16 initiativeRegistrationEpoch = registeredInitiatives[_initiative]; + // == Non existent Condition == // - if (registeredInitiatives[_initiative] == 0) { + if (initiativeRegistrationEpoch == 0) { return (InitiativeStatus.NONEXISTENT, 0, 0); /// By definition it has zero rewards } @@ -477,7 +479,7 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, Ownable, IG uint16 currentEpoch = epoch(); // == Just Registered Condition == // - if (registeredInitiatives[_initiative] == currentEpoch) { + if (initiativeRegistrationEpoch == currentEpoch) { return (InitiativeStatus.WARM_UP, 0, 0); /// Was registered this week, cannot have rewards } @@ -486,7 +488,7 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, Ownable, IG lastEpochClaim = initiativeStates[_initiative].lastEpochClaim; // == Disabled Condition == // - if (registeredInitiatives[_initiative] == UNREGISTERED_INITIATIVE) { + if (initiativeRegistrationEpoch == UNREGISTERED_INITIATIVE) { return (InitiativeStatus.DISABLED, lastEpochClaim, 0); /// By definition it has zero rewards } @@ -877,8 +879,6 @@ contract Governance is Multicall, UserProxyFactory, ReentrancyGuard, Ownable, IG (InitiativeStatus status,,) = getInitiativeState(_initiative, votesSnapshot_, votesForInitiativeSnapshot_, initiativeState); - require(status != InitiativeStatus.NONEXISTENT, "Governance: initiative-not-registered"); - require(status != InitiativeStatus.WARM_UP, "Governance: initiative-in-warm-up"); require(status == InitiativeStatus.UNREGISTERABLE, "Governance: cannot-unregister-initiative"); // Remove weight from current state diff --git a/src/UserProxy.sol b/src/UserProxy.sol index e42fa5e1..dc801f35 100644 --- a/src/UserProxy.sol +++ b/src/UserProxy.sol @@ -56,7 +56,7 @@ contract UserProxy is IUserProxy { PermitParams calldata _permitParams, bool _doSendRewards, address _recipient - ) public onlyStakingV2 returns (uint256 lusdAmount, uint256 ethAmount) { + ) external onlyStakingV2 returns (uint256 lusdAmount, uint256 ethAmount) { require(_lqtyFrom == _permitParams.owner, "UserProxy: owner-not-sender"); uint256 initialLUSDAmount = lusd.balanceOf(address(this)); @@ -80,7 +80,7 @@ contract UserProxy is IUserProxy { /// @inheritdoc IUserProxy function unstake(uint256 _amount, bool _doSendRewards, address _recipient) - public + external onlyStakingV2 returns (uint256 lusdAmount, uint256 ethAmount) { diff --git a/src/utils/Math.sol b/src/utils/Math.sol index dd608737..9b9d6dec 100644 --- a/src/utils/Math.sol +++ b/src/utils/Math.sol @@ -5,7 +5,7 @@ function add(uint88 a, int88 b) pure returns (uint88) { if (b < 0) { return a - abs(b); } - return a + abs(b); + return a + b; } function max(uint256 a, uint256 b) pure returns (uint256) {