Skip to content

Commit

Permalink
fix: Some minor gas optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Dec 2, 2024
1 parent 49776e9 commit 0a4a784
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -468,16 +468,18 @@ 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
}

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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/UserProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Math.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0a4a784

Please sign in to comment.