Skip to content

Commit 07ef418

Browse files
committed
fix: operator check in closeAllocation (TRST-M12)
1 parent 91cda56 commit 07ef418

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/horizon/contracts/staking/HorizonStakingExtension.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IHorizonStakingExtension
443443
// Anyone is allowed to close ONLY under two concurrent conditions
444444
// - After maxAllocationEpochs passed
445445
// - When the allocation is for non-zero amount of tokens
446-
bool isIndexerOrOperator = msg.sender == alloc.indexer ||
447-
isOperator(alloc.indexer, SUBGRAPH_DATA_SERVICE_ADDRESS);
446+
bool isIndexerOrOperator = msg.sender == alloc.indexer || isOperator(msg.sender, alloc.indexer);
448447
if (epochs <= __DEPRECATED_maxAllocationEpochs || alloc.tokens == 0) {
449448
require(isIndexerOrOperator, "!auth");
450449
}

packages/horizon/test/staking/allocation/close.t.sol

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ contract HorizonStakingCloseAllocationTest is HorizonStakingTest {
1212

1313
bytes32 internal constant _poi = keccak256("poi");
1414

15+
/*
16+
* MODIFIERS
17+
*/
18+
19+
modifier useLegacyOperator() {
20+
resetPrank(users.indexer);
21+
_setOperator(subgraphDataServiceLegacyAddress, users.operator, true);
22+
vm.startPrank(users.operator);
23+
_;
24+
vm.stopPrank();
25+
}
26+
1527
/*
1628
* TESTS
1729
*/
@@ -26,6 +38,16 @@ contract HorizonStakingCloseAllocationTest is HorizonStakingTest {
2638
_closeAllocation(_allocationId, _poi);
2739
}
2840

41+
function testCloseAllocation_Operator(uint256 tokens) public useLegacyOperator() useAllocation(1 ether) {
42+
tokens = bound(tokens, 1, MAX_STAKING_TOKENS);
43+
_createProvision(users.indexer, subgraphDataServiceLegacyAddress, tokens, 0, 0);
44+
45+
// Skip 15 epochs
46+
vm.roll(15);
47+
48+
_closeAllocation(_allocationId, _poi);
49+
}
50+
2951
function testCloseAllocation_WithBeneficiaryAddress(uint256 tokens) public useIndexer useAllocation(1 ether) {
3052
tokens = bound(tokens, 1, MAX_STAKING_TOKENS);
3153
_createProvision(users.indexer, subgraphDataServiceLegacyAddress, tokens, 0, 0);

0 commit comments

Comments
 (0)