Skip to content

Commit 9a296b6

Browse files
f: public buildStakeClaimId
1 parent 0ddb615 commit 9a296b6

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

packages/horizon/contracts/data-service/extensions/DataServiceFees.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
4747
claims,
4848
claimsLists,
4949
_graphStaking(),
50+
address(this),
5051
_delegationRatio,
5152
_serviceProvider,
5253
_tokens,

packages/horizon/contracts/data-service/libraries/StakeClaims.sol

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ library StakeClaims {
2222
* @param claims The mapping that stores stake claims by their ID
2323
* @param claimsLists The mapping that stores linked lists of stake claims by service provider
2424
* @param graphStaking The Horizon staking contract used to lock the tokens
25+
* @param _dataService The address of the data service
2526
* @param _delegationRatio The delegation ratio to use for the stake claim
2627
* @param _serviceProvider The address of the service provider
2728
* @param _tokens The amount of tokens to lock in the claim
@@ -32,6 +33,7 @@ library StakeClaims {
3233
mapping(bytes32 => IDataServiceFees.StakeClaim) storage claims,
3334
mapping(address serviceProvider => LinkedList.List list) storage claimsLists,
3435
IHorizonStaking graphStaking,
36+
address _dataService,
3537
uint32 _delegationRatio,
3638
address _serviceProvider,
3739
uint256 _tokens,
@@ -43,7 +45,7 @@ library StakeClaims {
4345
LinkedList.List storage claimsList = claimsLists[_serviceProvider];
4446

4547
// Save item and add to list
46-
bytes32 claimId = _buildStakeClaimId(_serviceProvider, claimsList.nonce);
48+
bytes32 claimId = _buildStakeClaimId(_dataService, _serviceProvider, claimsList.nonce);
4749
claims[claimId] = IDataServiceFees.StakeClaim({
4850
tokens: _tokens,
4951
createdAt: block.timestamp,
@@ -121,11 +123,31 @@ library StakeClaims {
121123

122124
/**
123125
* @notice Builds a stake claim ID
126+
* @param dataService The address of the data service
124127
* @param serviceProvider The address of the service provider
125128
* @param nonce A nonce of the stake claim
126129
* @return The stake claim ID
127130
*/
128-
function _buildStakeClaimId(address serviceProvider, uint256 nonce) internal view returns (bytes32) {
129-
return keccak256(abi.encodePacked(address(this), serviceProvider, nonce));
131+
function buildStakeClaimId(
132+
address dataService,
133+
address serviceProvider,
134+
uint256 nonce
135+
) public pure returns (bytes32) {
136+
return _buildStakeClaimId(dataService, serviceProvider, nonce);
137+
}
138+
139+
/**
140+
* @notice Builds a stake claim ID
141+
* @param _dataService The address of the data service
142+
* @param _serviceProvider The address of the service provider
143+
* @param _nonce A nonce of the stake claim
144+
* @return The stake claim ID
145+
*/
146+
function _buildStakeClaimId(
147+
address _dataService,
148+
address _serviceProvider,
149+
uint256 _nonce
150+
) internal pure returns (bytes32) {
151+
return keccak256(abi.encodePacked(_dataService, _serviceProvider, _nonce));
130152
}
131153
}

packages/subgraph-service/test/unit/subgraphService/SubgraphService.t.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
1212
import { LinkedList } from "@graphprotocol/horizon/contracts/libraries/LinkedList.sol";
1313
import { IDataServiceFees } from "@graphprotocol/horizon/contracts/data-service/interfaces/IDataServiceFees.sol";
1414
import { IHorizonStakingTypes } from "@graphprotocol/horizon/contracts/interfaces/internal/IHorizonStakingTypes.sol";
15+
import { StakeClaims } from "@graphprotocol/horizon/contracts/data-service/libraries/StakeClaims.sol";
1516

1617
import { Allocation } from "../../../contracts/libraries/Allocation.sol";
1718
import { AllocationManager } from "../../../contracts/utilities/AllocationManager.sol";
@@ -513,7 +514,7 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {
513514
}
514515

515516
function _buildStakeClaimId(address _indexer, uint256 _nonce) private view returns (bytes32) {
516-
return keccak256(abi.encodePacked(address(subgraphService), _indexer, _nonce));
517+
return StakeClaims.buildStakeClaimId(address(subgraphService), _indexer, _nonce);
517518
}
518519

519520
function _getStakeClaim(bytes32 _claimId) private view returns (IDataServiceFees.StakeClaim memory) {

0 commit comments

Comments
 (0)