Skip to content

Commit 835519f

Browse files
authored
Merge branch 'horizon' into tmigone/ignition-refactor
2 parents 5e16b7e + 519c5d8 commit 835519f

File tree

9 files changed

+104
-3
lines changed

9 files changed

+104
-3
lines changed

packages/hardhat-graph-protocol/src/sdk/deployments/horizon/address-book.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { logDebug, logError } from '../../../logger'
33
import { Provider, Signer } from 'ethers'
44
import { AddressBook } from '../../address-book'
55
import { assertObject } from '../../utils/assertion'
6+
import { Contract } from 'ethers'
7+
import { loadArtifact } from '../../lib/artifact'
8+
import { mergeABIs } from '../../utils/abi'
69

710
import type { GraphHorizonContractName, GraphHorizonContracts } from './contracts'
811

@@ -23,6 +26,20 @@ export class GraphHorizonAddressBook extends AddressBook<number, GraphHorizonCon
2326
GraphHorizonArtifactsMap,
2427
signerOrProvider,
2528
)
29+
30+
// Handle HorizonStaking specially to include extension functions
31+
if (contracts.HorizonStaking) {
32+
const stakingOverride = new Contract(
33+
this.getEntry('HorizonStaking').address,
34+
mergeABIs(
35+
loadArtifact('HorizonStaking', GraphHorizonArtifactsMap.HorizonStaking).abi,
36+
loadArtifact('HorizonStakingExtension', GraphHorizonArtifactsMap.HorizonStaking).abi,
37+
),
38+
signerOrProvider,
39+
)
40+
contracts.HorizonStaking = stakingOverride
41+
}
42+
2643
this._assertGraphHorizonContracts(contracts)
2744

2845
// Aliases
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function mergeABIs(abi1: any[], abi2: any[]) {
2+
for (const item of abi2) {
3+
if (abi1.find((v) => v.name === item.name) === undefined) {
4+
abi1.push(item)
5+
}
6+
}
7+
return abi1
8+
}

packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ contract SubgraphService is
313313
/**
314314
* @notice See {ISubgraphService.closeStaleAllocation}
315315
*/
316-
function closeStaleAllocation(address allocationId) external override {
316+
function closeStaleAllocation(address allocationId) external override whenNotPaused {
317317
Allocation.State memory allocation = allocations.get(allocationId);
318318
require(allocation.isStale(maxPOIStaleness), SubgraphServiceCannotForceCloseAllocation(allocationId));
319319
require(!allocation.isAltruistic(), SubgraphServiceAllocationIsAltruistic(allocationId));

packages/subgraph-service/test/SubgraphBaseTest.t.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ abstract contract SubgraphBaseTest is Utils, Constants {
7575
delegator: createUser("delegator"),
7676
arbitrator: createUser("arbitrator"),
7777
fisherman: createUser("fisherman"),
78-
rewardsDestination: createUser("rewardsDestination")
78+
rewardsDestination: createUser("rewardsDestination"),
79+
pauseGuardian: createUser("pauseGuardian")
7980
});
8081

8182
deployProtocolContracts();
@@ -191,6 +192,7 @@ abstract contract SubgraphBaseTest is Utils, Constants {
191192
epochManager.setEpochLength(EPOCH_LENGTH);
192193
subgraphService.setMaxPOIStaleness(maxPOIStaleness);
193194
subgraphService.setCurationCut(curationCut);
195+
subgraphService.setPauseGuardian(users.pauseGuardian, true);
194196
}
195197

196198
function unpauseProtocol() private {

packages/subgraph-service/test/shared/HorizonStakingShared.t.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ abstract contract HorizonStakingSharedTest is SubgraphBaseTest {
3333
staking.delegate(_indexer, _verifier, _tokens, _minSharesOut);
3434
}
3535

36+
function _undelegate(address _indexer, address _verifier, uint256 _shares) internal {
37+
staking.undelegate(_indexer, _verifier, _shares);
38+
}
39+
3640
function _setDelegationFeeCut(
3741
address _indexer,
3842
address _verifier,

packages/subgraph-service/test/shared/SubgraphServiceShared.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract contract SubgraphServiceSharedTest is HorizonStakingSharedTest {
3131
}
3232

3333
modifier useAllocation(uint256 tokens) {
34-
vm.assume(tokens > minimumProvisionTokens);
34+
vm.assume(tokens >= minimumProvisionTokens);
3535
vm.assume(tokens < 10_000_000_000 ether);
3636
_createProvision(users.indexer, tokens, maxSlashingPercentage, disputePeriod);
3737
_register(users.indexer, abi.encode("url", "geoHash", address(0)));

packages/subgraph-service/test/subgraphService/allocation/forceClose.t.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity 0.8.27;
33

44
import "forge-std/Test.sol";
55

6+
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
67
import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol";
78

89
import { Allocation } from "../../../contracts/libraries/Allocation.sol";
@@ -91,4 +92,13 @@ contract SubgraphServiceAllocationForceCloseTest is SubgraphServiceTest {
9192
);
9293
subgraphService.closeStaleAllocation(allocationID);
9394
}
95+
96+
function test_SubgraphService_Allocation_ForceClose_RevertIf_Paused() public useIndexer useAllocation(1000 ether) {
97+
resetPrank(users.pauseGuardian);
98+
subgraphService.pause();
99+
100+
resetPrank(permissionlessBob);
101+
vm.expectRevert(abi.encodeWithSelector(PausableUpgradeable.EnforcedPause.selector));
102+
subgraphService.closeStaleAllocation(allocationID);
103+
}
94104
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.27;
3+
4+
import "forge-std/Test.sol";
5+
6+
import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol";
7+
import { IHorizonStakingTypes } from "@graphprotocol/horizon/contracts/interfaces/internal/IHorizonStakingTypes.sol";
8+
9+
import { Allocation } from "../../../contracts/libraries/Allocation.sol";
10+
import { ISubgraphService } from "../../../contracts/interfaces/ISubgraphService.sol";
11+
import { SubgraphServiceTest } from "../SubgraphService.t.sol";
12+
13+
contract SubgraphServiceAllocationOverDelegatedTest is SubgraphServiceTest {
14+
15+
/*
16+
* TESTS
17+
*/
18+
19+
function test_SubgraphService_Allocation_OverDelegated_NotOverAllocatedAfterUndelegation(
20+
uint256 delegationTokens,
21+
uint256 undelegationTokens
22+
) public useIndexer {
23+
// Use minimum provision tokens
24+
uint256 indexerTokens = minimumProvisionTokens;
25+
uint256 allocationTokens = indexerTokens * delegationRatio;
26+
// Bound delegation tokens to be over delegated
27+
delegationTokens = bound(delegationTokens, allocationTokens, MAX_TOKENS);
28+
// Assume undelegation tokens to still leave indexer over delegated
29+
vm.assume(undelegationTokens > 1);
30+
vm.assume(undelegationTokens < delegationTokens - allocationTokens);
31+
32+
// Create provision
33+
token.approve(address(staking), indexerTokens);
34+
_createProvision(users.indexer, indexerTokens, maxSlashingPercentage, disputePeriod);
35+
_register(users.indexer, abi.encode("url", "geoHash", address(0)));
36+
37+
// Delegate so that indexer is over allocated
38+
resetPrank(users.delegator);
39+
token.approve(address(staking), delegationTokens);
40+
_delegate(users.indexer, address(subgraphService), delegationTokens, 0);
41+
42+
// Create allocation
43+
resetPrank(users.indexer);
44+
bytes memory data = _createSubgraphAllocationData(
45+
users.indexer,
46+
subgraphDeployment,
47+
allocationIDPrivateKey,
48+
allocationTokens
49+
);
50+
_startService(users.indexer, data);
51+
52+
// Undelegate
53+
resetPrank(users.delegator);
54+
_undelegate(users.indexer, address(subgraphService), undelegationTokens);
55+
56+
// Check that indexer is not over allocated
57+
assertFalse(subgraphService.isOverAllocated(users.indexer));
58+
}
59+
}

packages/subgraph-service/test/utils/Users.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ struct Users {
1212
address arbitrator;
1313
address fisherman;
1414
address rewardsDestination;
15+
address pauseGuardian;
1516
}

0 commit comments

Comments
 (0)