Skip to content

Commit

Permalink
feat: declare local variable instead of using access control
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Nov 1, 2024
1 parent 5f875e4 commit ea1d17f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
16 changes: 10 additions & 6 deletions solidity/contracts/modules/dispute/BondEscalationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,19 @@ contract BondEscalationModule is AccessControllerModule, IBondEscalationModule {
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = _pledgeChecks(_request, _dispute, true);

address _pledger = _accessControl.user;

_escalations[_dispute.requestId].amountOfPledgesForDispute += 1;
pledgesForDispute[_dispute.requestId][_accessControl.user] += 1;
pledgesForDispute[_dispute.requestId][_pledger] += 1;
_params.accountingExtension.pledge({
_pledger: _accessControl.user,
_pledger: _pledger,
_request: _request,
_dispute: _dispute,
_token: _params.bondToken,
_amount: _params.bondSize
});

emit PledgedForDispute(_disputeId, _accessControl.user, _params.bondSize);
emit PledgedForDispute(_disputeId, _pledger, _params.bondSize);
}

/// @inheritdoc IBondEscalationModule
Expand All @@ -255,17 +257,19 @@ contract BondEscalationModule is AccessControllerModule, IBondEscalationModule {
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = _pledgeChecks(_request, _dispute, false);

address _pledger = _accessControl.user;

_escalations[_dispute.requestId].amountOfPledgesAgainstDispute += 1;
pledgesAgainstDispute[_dispute.requestId][_accessControl.user] += 1;
pledgesAgainstDispute[_dispute.requestId][_pledger] += 1;
_params.accountingExtension.pledge({
_pledger: _accessControl.user,
_pledger: _pledger,
_request: _request,
_dispute: _dispute,
_token: _params.bondToken,
_amount: _params.bondSize
});

emit PledgedAgainstDispute(_disputeId, _accessControl.user, _params.bondSize);
emit PledgedAgainstDispute(_disputeId, _pledger, _params.bondSize);
}

/// @inheritdoc IBondEscalationModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract BondEscalationResolutionModule is AccessControllerModule, IBondEscalati
_dispute: _dispute,
_pledgeAmount: _pledgeAmount,
_pledgingFor: true,
_pledger: _accessContro.user
_pledger: _accessControl.user
});
}

Expand All @@ -109,7 +109,7 @@ contract BondEscalationResolutionModule is AccessControllerModule, IBondEscalati
_dispute: _dispute,
_pledgeAmount: _pledgeAmount,
_pledgingFor: false,
_pledger: _accessContro.user
_pledger: _accessControl.user
});
}

Expand Down Expand Up @@ -253,6 +253,7 @@ contract BondEscalationResolutionModule is AccessControllerModule, IBondEscalati
* @param _dispute The dispute to vote for or against
* @param _pledgeAmount The amount to pledge
* @param _pledgingFor Whether the pledger is pledging for or against the dispute
* @param _pledger The address of the pledger
*/
function _pledge(
IOracle.Request calldata _request,
Expand All @@ -269,9 +270,11 @@ contract BondEscalationResolutionModule is AccessControllerModule, IBondEscalati
InequalityData storage _inequalityData = inequalityData[_disputeId];
RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData);

uint256 _pledgingDeadline = _escalation.startTime + _params.timeUntilDeadline;
// uint256 _pledgingDeadline = _escalation.startTime + _params.timeUntilDeadline;

if (block.timestamp >= _pledgingDeadline) revert BondEscalationResolutionModule_PledgingPhaseOver();
if (block.timestamp >= _escalation.startTime + _params.timeUntilDeadline) {
revert BondEscalationResolutionModule_PledgingPhaseOver();
}

// Revert if the inequality timer has passed
if (_inequalityData.time != 0 && block.timestamp >= _inequalityData.time + _params.timeToBreakInequality) {
Expand Down
23 changes: 13 additions & 10 deletions solidity/contracts/modules/resolution/ERC20ResolutionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,19 @@ contract ERC20ResolutionModule is AccessControllerModule, IERC20ResolutionModule
}

RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData);
uint256 _deadline = _escalation.startTime + _params.timeUntilDeadline;
if (block.timestamp >= _deadline) revert ERC20ResolutionModule_VotingPhaseOver();
if (block.timestamp >= _escalation.startTime + _params.timeUntilDeadline) {
revert ERC20ResolutionModule_VotingPhaseOver();
}

votes[_disputeId][_accessControl.user] += _numberOfVotes;
address _voter = _accessControl.user;

_voters[_disputeId].add(_accessControl.user);
votes[_disputeId][_voter] += _numberOfVotes;

_voters[_disputeId].add(_voter);
escalations[_disputeId].totalVotes += _numberOfVotes;

_params.accountingExtension.bond(_accessControl.user, _dispute.requestId, _params.votingToken, _numberOfVotes);
emit VoteCast(_accessControl.user, _disputeId, _numberOfVotes);
_params.accountingExtension.bond(_voter, _dispute.requestId, _params.votingToken, _numberOfVotes);
emit VoteCast(_voter, _disputeId, _numberOfVotes);
}

/// @inheritdoc IERC20ResolutionModule
Expand Down Expand Up @@ -146,12 +149,12 @@ contract ERC20ResolutionModule is AccessControllerModule, IERC20ResolutionModule
RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData);
uint256 _deadline = _escalation.startTime + _params.timeUntilDeadline;
if (block.timestamp < _deadline) revert ERC20ResolutionModule_OnGoingVotingPhase();

address _voter = _accessControl.user;
// Transfer the tokens back to the voter
uint256 _amount = votes[_disputeId][_accessControl.user];
_params.accountingExtension.release(_accessControl.user, _dispute.requestId, _params.votingToken, _amount);
uint256 _amount = votes[_disputeId][_voter];
_params.accountingExtension.release(_voter, _dispute.requestId, _params.votingToken, _amount);

emit VoteClaimed(_accessControl.user, _disputeId, _amount);
emit VoteClaimed(_voter, _disputeId, _amount);
}

/// @inheritdoc IERC20ResolutionModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ contract PrivateERC20ResolutionModule is AccessControllerModule, IPrivateERC20Re
RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData);
uint256 _committingDeadline = _startTime + _params.committingTimeWindow;
if (block.timestamp >= _committingDeadline) revert PrivateERC20ResolutionModule_CommittingPhaseOver();

address _voter = _accessControl.user;
if (_commitment == bytes32('')) revert PrivateERC20ResolutionModule_EmptyCommitment();
_votersData[_disputeId][msg.sender] = VoterData({numOfVotes: 0, commitment: _commitment});
_votersData[_disputeId][_voter] = VoterData({numOfVotes: 0, commitment: _commitment});

emit VoteCommitted(msg.sender, _disputeId, _commitment);
emit VoteCommitted(_voter, _disputeId, _commitment);
}

/// @inheritdoc IPrivateERC20ResolutionModule
Expand Down Expand Up @@ -111,21 +111,22 @@ contract PrivateERC20ResolutionModule is AccessControllerModule, IPrivateERC20Re
if (block.timestamp > _escalation.startTime + _params.committingTimeWindow + _params.revealingTimeWindow) {
revert PrivateERC20ResolutionModule_RevealingPhaseOver();
}
address _voter = _accessControl.user;

VoterData storage _voterData = _votersData[_disputeId][_accessControl.user];
VoterData storage _voterData = _votersData[_disputeId][_voter];

if (_voterData.commitment != keccak256(abi.encode(_accessControl.user, _disputeId, _numberOfVotes, _salt))) {
if (_voterData.commitment != keccak256(abi.encode(_voter, _disputeId, _numberOfVotes, _salt))) {
revert PrivateERC20ResolutionModule_WrongRevealData();
}

_voterData.numOfVotes = _numberOfVotes;
_voterData.commitment = bytes32('');
_voters[_disputeId].add(_accessControl.user);
_voters[_disputeId].add(_voter);
escalations[_disputeId].totalVotes += _numberOfVotes;

_params.votingToken.safeTransferFrom(_accessControl.user, address(this), _numberOfVotes);
_params.votingToken.safeTransferFrom(_voter, address(this), _numberOfVotes);

emit VoteRevealed(_accessControl.user, _disputeId, _numberOfVotes);
emit VoteRevealed(_voter, _disputeId, _numberOfVotes);
}

/// @inheritdoc IPrivateERC20ResolutionModule
Expand Down

0 comments on commit ea1d17f

Please sign in to comment.