Skip to content

Commit

Permalink
fix: set new peram order various functions (OZ_N-05)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonBoi9001 committed Oct 7, 2024
1 parent 68157c0 commit 1693d76
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ interface IHorizonStakingMain {
/**
* @dev Emitted when an operator is allowed or denied by a service provider for a particular verifier
* @param serviceProvider The address of the service provider
* @param operator The address of the operator
* @param verifier The address of the verifier
* @param operator The address of the operator
* @param allowed Whether the operator is allowed or denied
*/
event OperatorSet(
address indexed serviceProvider,
address indexed operator,
address indexed verifier,
address indexed operator,
bool allowed
);

Expand Down Expand Up @@ -865,11 +865,11 @@ interface IHorizonStakingMain {
* Additional requirements:
* - The `verifier` must be allowed to be used for locked provisions.
*
* @param operator Address to authorize or unauthorize
* @param verifier The verifier / data service on which they'll be allowed to operate
* @param operator Address to authorize or unauthorize
* @param allowed Whether the operator is authorized or not
*/
function setOperatorLocked(address operator, address verifier, bool allowed) external;
function setOperatorLocked(address verifier, address operator, bool allowed) external;

/**
* @notice Sets a verifier as a globally allowed verifier for locked provisions.
Expand Down Expand Up @@ -904,11 +904,11 @@ interface IHorizonStakingMain {
/**
* @notice Authorize or unauthorize an address to be an operator for the caller on a data service.
* @dev Emits a {OperatorSet} event.
* @param operator Address to authorize or unauthorize
* @param verifier The verifier / data service on which they'll be allowed to operate
* @param operator Address to authorize or unauthorize
* @param allowed Whether the operator is authorized or not
*/
function setOperator(address operator, address verifier, bool allowed) external;
function setOperator(address verifier, address operator, bool allowed) external;

/**
* @notice Check if an operator is authorized for the caller on a specific verifier / data service.
Expand Down
10 changes: 5 additions & 5 deletions packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
/**
* @notice See {IHorizonStakingMain-setOperatorLocked}.
*/
function setOperatorLocked(address operator, address verifier, bool allowed) external override notPaused {
function setOperatorLocked(address verifier, address operator, bool allowed) external override notPaused {
require(_allowedLockedVerifiers[verifier], HorizonStakingVerifierNotAllowed(verifier));
_setOperator(operator, verifier, allowed);
_setOperator(verifier, operator, allowed);
}

/*
Expand Down Expand Up @@ -514,8 +514,8 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
/**
* @notice See {IHorizonStakingMain-setOperator}.
*/
function setOperator(address operator, address verifier, bool allowed) external override notPaused {
_setOperator(operator, verifier, allowed);
function setOperator(address verifier, address operator, bool allowed) external override notPaused {
_setOperator(verifier, operator, allowed);
}

/**
Expand Down Expand Up @@ -960,7 +960,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
* @dev Note that this function handles the special case where the verifier is the subgraph data service,
* where the operator settings are stored in the legacy mapping.
*/
function _setOperator(address _operator, address _verifier, bool _allowed) private {
function _setOperator(address _verifier, address _operator, bool _allowed) private {
require(_operator != msg.sender, HorizonStakingCallerIsServiceProvider());
if (_verifier == SUBGRAPH_DATA_SERVICE_ADDRESS) {
_legacyOperatorAuth[msg.sender][_operator] = _allowed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {

modifier useOperator() {
vm.startPrank(users.indexer);
_setOperator(users.operator, subgraphDataServiceAddress, true);
_setOperator(subgraphDataServiceAddress, users.operator, true);
vm.startPrank(users.operator);
_;
vm.stopPrank();
Expand Down Expand Up @@ -736,15 +736,15 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
assertEq(afterProvision.createdAt, beforeProvision.createdAt);
}

function _setOperator(address operator, address verifier, bool allow) internal {
__setOperator(operator, verifier, allow, false);
function _setOperator(address verifier, address operator, bool allow) internal {
__setOperator(verifier, operator, allow, false);
}

function _setOperatorLocked(address operator, address verifier, bool allow) internal {
__setOperator(operator, verifier, allow, true);
function _setOperatorLocked(address verifier, address operator, bool allow) internal {
__setOperator(verifier, operator, allow, true);
}

function __setOperator(address operator, address verifier, bool allow, bool locked) private {
function __setOperator(address verifier, address operator, bool allow, bool locked) private {
(, address msgSender, ) = vm.readCallers();

// staking contract knows the address of the legacy subgraph service
Expand All @@ -758,11 +758,11 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {

// setOperator
vm.expectEmit(address(staking));
emit IHorizonStakingMain.OperatorSet(msgSender, operator, verifier, allow);
emit IHorizonStakingMain.OperatorSet(msgSender, verifier, operator, allow);
if (locked) {
staking.setOperatorLocked(operator, verifier, allow);
staking.setOperatorLocked(verifier, operator, allow);
} else {
staking.setOperator(operator, verifier, allow);
staking.setOperator(verifier, operator, allow);
}

// after
Expand Down Expand Up @@ -1699,8 +1699,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
slot = uint256(
keccak256(
abi.encode(
verifier,
keccak256(abi.encode(operator, keccak256(abi.encode(serviceProvider, slotNumber))))
operator,
keccak256(abi.encode(verifier, keccak256(abi.encode(serviceProvider, slotNumber))))
)
)
);
Expand Down
8 changes: 4 additions & 4 deletions packages/horizon/test/staking/operator/locked.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ contract HorizonStakingOperatorLockedTest is HorizonStakingTest {
*/

function testOperatorLocked_Set() public useIndexer useLockedVerifier(subgraphDataServiceAddress) {
_setOperatorLocked(users.operator, subgraphDataServiceAddress, true);
_setOperatorLocked(subgraphDataServiceAddress, users.operator, true);
}

function testOperatorLocked_RevertWhen_VerifierNotAllowed() public useIndexer {
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingVerifierNotAllowed(address)", subgraphDataServiceAddress);
vm.expectRevert(expectedError);
staking.setOperatorLocked(users.operator, subgraphDataServiceAddress, true);
staking.setOperatorLocked(subgraphDataServiceAddress, users.operator, true);
}

function testOperatorLocked_RevertWhen_CallerIsServiceProvider() public useIndexer useLockedVerifier(subgraphDataServiceAddress) {
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingCallerIsServiceProvider()");
vm.expectRevert(expectedError);
staking.setOperatorLocked(users.indexer, subgraphDataServiceAddress, true);
staking.setOperatorLocked(subgraphDataServiceAddress, users.indexer, true);
}

function testOperatorLocked_SetLegacySubgraphService() public useIndexer useLockedVerifier(subgraphDataServiceLegacyAddress) {
_setOperatorLocked(users.operator, subgraphDataServiceLegacyAddress, true);
_setOperatorLocked(subgraphDataServiceLegacyAddress, users.operator, true);
}
}
8 changes: 4 additions & 4 deletions packages/horizon/test/staking/operator/operator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ contract HorizonStakingOperatorTest is HorizonStakingTest {
*/

function testOperator_SetOperator() public useIndexer {
_setOperator(users.operator, subgraphDataServiceAddress, true);
_setOperator(subgraphDataServiceAddress, users.operator, true);
}

function testOperator_RevertWhen_CallerIsServiceProvider() public useIndexer {
bytes memory expectedError = abi.encodeWithSignature("HorizonStakingCallerIsServiceProvider()");
vm.expectRevert(expectedError);
staking.setOperator(users.indexer, subgraphDataServiceAddress, true);
staking.setOperator(subgraphDataServiceAddress, users.indexer, true);
}

function testOperator_RemoveOperator() public useIndexer {
_setOperator(users.operator, subgraphDataServiceAddress, true);
_setOperator(users.operator, subgraphDataServiceAddress, false);
_setOperator(subgraphDataServiceAddress, users.operator, true);
_setOperator(subgraphDataServiceAddress, users.operator, false);
}
}
4 changes: 2 additions & 2 deletions packages/horizon/test/staking/provision/locked.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract HorizonStakingProvisionLockedTest is HorizonStakingTest {
uint256 provisionTokens = staking.getProviderTokensAvailable(users.indexer, subgraphDataServiceAddress);
assertEq(provisionTokens, 0);

_setOperatorLocked(users.operator, subgraphDataServiceAddress, true);
_setOperatorLocked(subgraphDataServiceAddress, users.operator, true);

vm.startPrank(users.operator);
_provisionLocked(
Expand All @@ -39,7 +39,7 @@ contract HorizonStakingProvisionLockedTest is HorizonStakingTest {
assertEq(provisionTokens, 0);

// Set operator
_setOperatorLocked(users.operator, subgraphDataServiceAddress, true);
_setOperatorLocked(subgraphDataServiceAddress, users.operator, true);

// Disable locked verifier
vm.startPrank(users.governor);
Expand Down
2 changes: 1 addition & 1 deletion packages/horizon/test/staking/provision/reprovision.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract HorizonStakingReprovisionTest is HorizonStakingTest {

// Switch to indexer to set operator for new data service
vm.startPrank(users.indexer);
_setOperator(users.operator, newDataService, true);
_setOperator(newDataService, users.operator, true);

// Switch back to operator
vm.startPrank(users.operator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract HorizonStakingServiceProviderTest is HorizonStakingTest {
assertEq(sp.tokensStaked, amount);
assertEq(sp.tokensProvisioned, amount);

_setOperator(users.operator, subgraphDataServiceAddress, true);
_setOperator(subgraphDataServiceAddress, users.operator, true);
resetPrank(users.operator);
_stakeTo(users.indexer, operatorAmount);
sp = staking.getServiceProvider(users.indexer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {

modifier useOperator() {
resetPrank(users.indexer);
staking.setOperator(users.operator, address(subgraphService), true);
staking.setOperator(address(subgraphService), users.operator, true);
resetPrank(users.operator);
_;
vm.stopPrank();
Expand Down

0 comments on commit 1693d76

Please sign in to comment.