Skip to content

Commit

Permalink
feat: use library instead of free variables
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Nov 8, 2024
1 parent 2b5a988 commit 8607835
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 45 deletions.
18 changes: 14 additions & 4 deletions solidity/contracts/modules/dispute/BondEscalationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {FixedPointMathLib} from 'solmate/src/utils/FixedPointMathLib.sol';

import {IBondEscalationModule} from '../../../interfaces/modules/dispute/IBondEscalationModule.sol';

import {_PLEDGE_AGAINST_DISPUTE_TYPEHASH, _PLEDGE_FOR_DISPUTE_TYPEHASH} from '../../utils/Typehash.sol';

import {ModuleAccessController} from '../access/ModuleAccessController.sol';

import {ModuleTypehash} from '../../utils/ModuleTypehash.sol';

contract BondEscalationModule is ModuleAccessController, IBondEscalationModule {
/// @inheritdoc IBondEscalationModule
mapping(bytes32 _requestId => mapping(address _pledger => uint256 pledges)) public pledgesForDispute;
Expand Down Expand Up @@ -218,7 +218,12 @@ contract BondEscalationModule is ModuleAccessController, IBondEscalationModule {
AccessControl calldata _accessControl
)
external
hasAccess(_request.accessModule, _PLEDGE_FOR_DISPUTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl)
hasAccess(
_request.accessModule,
ModuleTypehash._PLEDGE_FOR_DISPUTE_TYPEHASH,
abi.encode(_request, _dispute),
_accessControl
)
{
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = _pledgeChecks(_request, _dispute, true);
Expand All @@ -245,7 +250,12 @@ contract BondEscalationModule is ModuleAccessController, IBondEscalationModule {
AccessControl calldata _accessControl
)
external
hasAccess(_request.accessModule, _PLEDGE_AGAINST_DISPUTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl)
hasAccess(
_request.accessModule,
ModuleTypehash._PLEDGE_AGAINST_DISPUTE_TYPEHASH,
abi.encode(_request, _dispute),
_accessControl
)
{
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = _pledgeChecks(_request, _dispute, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ import {IBondEscalationResolutionModule} from
'../../../interfaces/modules/resolution/IBondEscalationResolutionModule.sol';
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

import {
_CLAIM_PLEDGE_TYPEHASH,
_PLEDGE_AGAINST_DISPUTE_TYPEHASH,
_PLEDGE_FOR_DISPUTE_TYPEHASH
} from '../../utils/Typehash.sol';
import {ModuleTypehash} from '../../utils/ModuleTypehash.sol';

contract BondEscalationResolutionModule is ModuleAccessController, IBondEscalationResolutionModule {
using SafeERC20 for IERC20;
Expand Down Expand Up @@ -75,7 +71,7 @@ contract BondEscalationResolutionModule is ModuleAccessController, IBondEscalati
external
hasAccess(
_request.accessModule,
_PLEDGE_FOR_DISPUTE_TYPEHASH,
ModuleTypehash._PLEDGE_FOR_DISPUTE_TYPEHASH,
abi.encode(_request, _dispute, _pledgeAmount),
_accessControl
)
Expand All @@ -99,7 +95,7 @@ contract BondEscalationResolutionModule is ModuleAccessController, IBondEscalati
external
hasAccess(
_request.accessModule,
_PLEDGE_AGAINST_DISPUTE_TYPEHASH,
ModuleTypehash._PLEDGE_AGAINST_DISPUTE_TYPEHASH,
abi.encode(_request, _dispute, _pledgeAmount),
_accessControl
)
Expand Down Expand Up @@ -162,7 +158,15 @@ contract BondEscalationResolutionModule is ModuleAccessController, IBondEscalati
IOracle.Request calldata _request,
IOracle.Dispute calldata _dispute,
AccessControl calldata _accessControl
) external hasAccess(_request.accessModule, _CLAIM_PLEDGE_TYPEHASH, abi.encode(_request, _dispute), _accessControl) {
)
external
hasAccess(
_request.accessModule,
ModuleTypehash._CLAIM_PLEDGE_TYPEHASH,
abi.encode(_request, _dispute),
_accessControl
)
{
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation storage _escalation = escalations[_disputeId];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle

import {IERC20ResolutionModule} from '../../../interfaces/modules/resolution/IERC20ResolutionModule.sol';

import {_CAST_VOTE_TYPEHASH, _CLAIM_VOTE_TYPEHASH} from '../../utils/Typehash.sol';
import {ModuleTypehash} from '../../utils/ModuleTypehash.sol';
import {ModuleAccessController} from '../access/ModuleAccessController.sol';

contract ERC20ResolutionModule is ModuleAccessController, IERC20ResolutionModule {
Expand Down Expand Up @@ -62,7 +62,7 @@ contract ERC20ResolutionModule is ModuleAccessController, IERC20ResolutionModule
external
hasAccess(
_request.accessModule,
_CAST_VOTE_TYPEHASH,
ModuleTypehash._CAST_VOTE_TYPEHASH,
abi.encode(_request, _dispute, _numberOfVotes, _numberOfVotes),
_accessControl
)
Expand Down Expand Up @@ -138,7 +138,10 @@ contract ERC20ResolutionModule is ModuleAccessController, IERC20ResolutionModule
IOracle.Request calldata _request,
IOracle.Dispute calldata _dispute,
AccessControl calldata _accessControl
) external hasAccess(_request.accessModule, _CLAIM_VOTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl) {
)
external
hasAccess(_request.accessModule, ModuleTypehash._CLAIM_VOTE_TYPEHASH, abi.encode(_request, _dispute), _accessControl)
{
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation memory _escalation = escalations[_disputeId];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

import {_COMMIT_VOTE_TYPEHASH, _REVEAL_VOTE_TYPEHASH} from '../../utils/Typehash.sol';
import {ModuleTypehash} from '../../utils/ModuleTypehash.sol';
import {IModule, Module} from '@defi-wonderland/prophet-core/solidity/contracts/Module.sol';
import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';

Expand Down Expand Up @@ -59,7 +59,12 @@ contract PrivateERC20ResolutionModule is ModuleAccessController, IPrivateERC20Re
AccessControl calldata _accessControl
)
external
hasAccess(_request.accessModule, _COMMIT_VOTE_TYPEHASH, abi.encode(_request, _dispute, _commitment), _accessControl)
hasAccess(
_request.accessModule,
ModuleTypehash._COMMIT_VOTE_TYPEHASH,
abi.encode(_request, _dispute, _commitment),
_accessControl
)
{
bytes32 _disputeId = _validateDispute(_request, _dispute);
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
Expand Down Expand Up @@ -90,7 +95,7 @@ contract PrivateERC20ResolutionModule is ModuleAccessController, IPrivateERC20Re
external
hasAccess(
_request.accessModule,
_REVEAL_VOTE_TYPEHASH,
ModuleTypehash._REVEAL_VOTE_TYPEHASH,
abi.encode(_request, _dispute, _numberOfVotes, _salt),
_accessControl
)
Expand Down
26 changes: 26 additions & 0 deletions solidity/contracts/utils/ModuleTypehash.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

library ModuleTypehash {
bytes32 internal constant _PLEDGE_FOR_DISPUTE_TYPEHASH =
keccak256('pledgeForDispute(Request _request, Dispute _dispute,IAccessController.AccessControl _accessControl)');

bytes32 internal constant _PLEDGE_AGAINST_DISPUTE_TYPEHASH =
keccak256('pledgeAgainstDispute(Request _request,Dispute _dispute,IAccessController.AccessControl _accessControl)');

bytes32 internal constant _CLAIM_PLEDGE_TYPEHASH =
keccak256('claimPledge(Request _request,Dispute _dispute,AccessControl _accessControl)');

bytes32 internal constant _CLAIM_VOTE_TYPEHASH =
keccak256('claimVote(Request _request,Dispute _dispute,AccessControl _accessControl)');

bytes32 internal constant _CAST_VOTE_TYPEHASH =
keccak256('castVote(Request _request,Dispute _dispute,uint256 _numberOfVotes,AccessControl _accessControl)');

bytes32 internal constant _COMMIT_VOTE_TYPEHASH =
keccak256('commitVote(Request _request,Dispute _dispute,bytes32 _commitment,AccessControl _accessControl)');

bytes32 internal constant _REVEAL_VOTE_TYPEHASH = keccak256(
'revealVote(Request _request,Dispute _dispute,uint256 _numberOfVotes,bytes32 _salt,AccessControl _accessControl)'
);
}
22 changes: 0 additions & 22 deletions solidity/contracts/utils/Typehash.sol

This file was deleted.

8 changes: 3 additions & 5 deletions solidity/test/unit/modules/dispute/BondEscalationModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import {
BondEscalationModule, IBondEscalationModule
} from '../../../../contracts/modules/dispute/BondEscalationModule.sol';

import {
_PLEDGE_AGAINST_DISPUTE_TYPEHASH, _PLEDGE_FOR_DISPUTE_TYPEHASH
} from '../../../../contracts/utils/Typehash.sol';
import {ModuleTypehash} from '../../../../contracts/utils/ModuleTypehash.sol';
import {IAccountingExtension} from '../../../../interfaces/extensions/IAccountingExtension.sol';
import {IBondEscalationAccounting} from '../../../../interfaces/extensions/IBondEscalationAccounting.sol';
import {IModuleAccessController} from '../../../../interfaces/modules/access/IModuleAccessController.sol';
Expand Down Expand Up @@ -1552,7 +1550,7 @@ contract BondEscalationModule_Unit_AccessControl is BaseTest {
IAccessModule.AccessControlParameters({
sender: _caller,
accessControl: _accessControl,
typehash: _PLEDGE_FOR_DISPUTE_TYPEHASH,
typehash: ModuleTypehash._PLEDGE_FOR_DISPUTE_TYPEHASH,
typehashParams: abi.encode(mockRequest, _dispute)
})
)
Expand Down Expand Up @@ -1647,7 +1645,7 @@ contract BondEscalationModule_Unit_AccessControl is BaseTest {
IAccessModule.AccessControlParameters({
sender: _caller,
accessControl: _accessControl,
typehash: _PLEDGE_AGAINST_DISPUTE_TYPEHASH,
typehash: ModuleTypehash._PLEDGE_AGAINST_DISPUTE_TYPEHASH,
typehashParams: abi.encode(mockRequest, _dispute)
})
)
Expand Down

0 comments on commit 8607835

Please sign in to comment.