Skip to content

Commit 58c518c

Browse files
authored
Merge branch 'horizon' into horizon-gre
2 parents 8f3e0f1 + 170572f commit 58c518c

File tree

147 files changed

+3304
-283093
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+3304
-283093
lines changed

packages/horizon/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ Graph Horizon is the next evolution of the Graph Protocol.
44

55
## Deployment
66

7-
We use Hardhat Ignition to deploy the contracts. To build and deploy the contracts run the following commands:
7+
We use Hardhat Ignition to deploy the contracts. To build and deploy Graph Horizon run the following commands:
88

99
```bash
1010
yarn install
1111
yarn build
1212
npx hardhat ignition deploy ./ignition/modules/horizon.ts \
13-
--parameters ./ignition/configs/horizon.hardhat.json \
13+
--parameters ./ignition/configs/horizon.hardhat.json5 \
1414
--network hardhat
1515
```
1616

17-
You can use any network defined in `hardhat.config.ts` by replacing `hardhat` with the network name.
17+
You can use any network defined in `hardhat.config.ts` by replacing `hardhat` with the network name.
18+
19+
Note that this will deploy a standalone version of Graph Horizon contracts, meaning the Subgraph Service or any other data service will not be deployed. If you want to deploy the Subgraph Service please refer to the [Subgraph Service README](../subgraph-service/README.md) for deploy instructions.

packages/horizon/contracts/data-service/DataService.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { ProvisionManager } from "./utilities/ProvisionManager.sol";
2525
* - If the data service implementation is NOT upgradeable, it must initialize the contract by calling
2626
* {__DataService_init} or {__DataService_init_unchained} in the constructor. Note that the `initializer`
2727
* will be required in the constructor.
28+
* - Note that in both cases if using {__DataService_init_unchained} variant the corresponding parent
29+
* initializers must be called in the implementation.
2830
*/
2931
abstract contract DataService is GraphDirectory, ProvisionManager, DataServiceV1Storage, IDataService {
3032
/**

packages/horizon/contracts/data-service/DataServiceStorage.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ pragma solidity 0.8.27;
33

44
abstract contract DataServiceV1Storage {
55
/// @dev Gap to allow adding variables in future upgrades
6+
/// Note that this contract is not upgradeable but might be inherited by an upgradeable contract
67
uint256[50] private __gap;
78
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { DataServiceFeesV1Storage } from "./DataServiceFeesStorage.sol";
1414
* @dev Implementation of the {IDataServiceFees} interface.
1515
* @notice Extension for the {IDataService} contract to handle payment collateralization
1616
* using a Horizon provision. See {IDataServiceFees} for more details.
17+
* @dev This contract inherits from {DataService} which needs to be initialized, please see
18+
* {DataService} for detailed instructions.
1719
*/
1820
abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDataServiceFees {
1921
using ProvisionTracker for mapping(address => uint256);
@@ -127,9 +129,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
127129
* @param _claimId The ID of the stake claim
128130
*/
129131
function _getNextStakeClaim(bytes32 _claimId) private view returns (bytes32) {
130-
StakeClaim memory claim = claims[_claimId];
131-
require(claim.createdAt != 0, DataServiceFeesClaimNotFound(_claimId));
132-
return claim.nextClaim;
132+
return claims[_claimId].nextClaim;
133133
}
134134

135135
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ abstract contract DataServiceFeesV1Storage {
1818
mapping(address serviceProvider => LinkedList.List list) public claimsLists;
1919

2020
/// @dev Gap to allow adding variables in future upgrades
21+
/// Note that this contract is not upgradeable but might be inherited by an upgradeable contract
2122
uint256[50] private __gap;
2223
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { DataService } from "../DataService.sol";
1414
* pause guardians.
1515
* @dev Note that this extension does not provide an external function to set pause
1616
* guardians. This should be implemented in the derived contract.
17+
* @dev This contract inherits from {DataService} which needs to be initialized, please see
18+
* {DataService} for detailed instructions.
1719
*/
1820
abstract contract DataServicePausable is Pausable, DataService, IDataServicePausable {
1921
/// @notice List of pause guardians and their allowed status
@@ -51,6 +53,10 @@ abstract contract DataServicePausable is Pausable, DataService, IDataServicePaus
5153
* @param _allowed The allowed status of the pause guardian
5254
*/
5355
function _setPauseGuardian(address _pauseGuardian, bool _allowed) internal {
56+
require(
57+
pauseGuardians[_pauseGuardian] == !_allowed,
58+
DataServicePausablePauseGuardianNoChange(_pauseGuardian, _allowed)
59+
);
5460
pauseGuardians[_pauseGuardian] = _allowed;
5561
emit PauseGuardianSet(_pauseGuardian, _allowed);
5662
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ import { DataService } from "../DataService.sol";
1010
* @title DataServicePausableUpgradeable contract
1111
* @dev Implementation of the {IDataServicePausable} interface.
1212
* @dev Upgradeable version of the {DataServicePausable} contract.
13+
* @dev This contract inherits from {DataService} which needs to be initialized, please see
14+
* {DataService} for detailed instructions.
1315
*/
1416
abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataService, IDataServicePausable {
1517
/// @notice List of pause guardians and their allowed status
1618
mapping(address pauseGuardian => bool allowed) public pauseGuardians;
1719

20+
/// @dev Gap to allow adding variables in future upgrades
21+
uint256[50] private __gap;
22+
1823
/**
1924
* @notice Checks if the caller is a pause guardian.
2025
*/
@@ -61,7 +66,11 @@ abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataSer
6166
* @param _pauseGuardian The address of the pause guardian
6267
* @param _allowed The allowed status of the pause guardian
6368
*/
64-
function _setPauseGuardian(address _pauseGuardian, bool _allowed) internal whenNotPaused {
69+
function _setPauseGuardian(address _pauseGuardian, bool _allowed) internal {
70+
require(
71+
pauseGuardians[_pauseGuardian] == !_allowed,
72+
DataServicePausablePauseGuardianNoChange(_pauseGuardian, _allowed)
73+
);
6574
pauseGuardians[_pauseGuardian] = _allowed;
6675
emit PauseGuardianSet(_pauseGuardian, _allowed);
6776
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
1717
* that calls this contract's _rescueTokens.
1818
* @dev Note that this extension does not provide an external function to set
1919
* rescuers. This should be implemented in the derived contract.
20+
* @dev This contract inherits from {DataService} which needs to be initialized, please see
21+
* {DataService} for detailed instructions.
2022
*/
2123
abstract contract DataServiceRescuable is DataService, IDataServiceRescuable {
2224
/// @notice List of rescuers and their allowed status
2325
mapping(address rescuer => bool allowed) public rescuers;
2426

27+
/// @dev Gap to allow adding variables in future upgrades
28+
/// Note that this contract is not upgradeable but might be inherited by an upgradeable contract
29+
uint256[50] private __gap;
30+
2531
/**
2632
* @notice Checks if the caller is a rescuer.
2733
*/

packages/horizon/contracts/data-service/interfaces/IDataServicePausable.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ interface IDataServicePausable is IDataService {
2323
*/
2424
error DataServicePausableNotPauseGuardian(address account);
2525

26+
/**
27+
* @notice Emitted when a pause guardian is set to the same allowed status
28+
* @param account The address of the pause guardian
29+
* @param allowed The allowed status of the pause guardian
30+
*/
31+
error DataServicePausablePauseGuardianNoChange(address account, bool allowed);
32+
2633
/**
2734
* @notice Pauses the data service.
2835
* @dev Note that only functions using the modifiers `whenNotPaused`

packages/horizon/contracts/data-service/utilities/ProvisionManager.sol

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,16 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
202202

203203
/**
204204
* @notice Checks if the provision tokens of a service provider are within the valid range.
205+
* Note that thawing tokens are not considered in this check.
205206
* @param _provision The provision to check.
206207
*/
207208
function _checkProvisionTokens(IHorizonStaking.Provision memory _provision) internal view virtual {
208-
_checkValueInRange(_provision.tokens, minimumProvisionTokens, maximumProvisionTokens, "tokens");
209+
_checkValueInRange(
210+
_provision.tokens - _provision.tokensThawing,
211+
minimumProvisionTokens,
212+
maximumProvisionTokens,
213+
"tokens"
214+
);
209215
}
210216

211217
/**

packages/horizon/contracts/data-service/utilities/ProvisionManagerStorage.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ abstract contract ProvisionManagerV1Storage {
2828
uint32 public delegationRatio;
2929

3030
/// @dev Gap to allow adding variables in future upgrades
31+
/// Note that this contract is not upgradeable but might be inherited by an upgradeable contract
3132
uint256[50] private __gap;
3233
}

packages/horizon/contracts/interfaces/IGraphPayments.sol

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,57 @@ interface IGraphPayments {
2323
* @param payer The address of the payer
2424
* @param receiver The address of the receiver
2525
* @param dataService The address of the data service
26-
* @param tokensReceiver Amount of tokens for the receiver
27-
* @param tokensDelegationPool Amount of tokens for delegators
28-
* @param tokensDataService Amount of tokens for the data service
26+
* @param tokens The total amount of tokens being collected
2927
* @param tokensProtocol Amount of tokens charged as protocol tax
28+
* @param tokensDataService Amount of tokens for the data service
29+
* @param tokensDelegationPool Amount of tokens for delegators
30+
* @param tokensReceiver Amount of tokens for the receiver
3031
*/
31-
event PaymentCollected(
32+
event GraphPaymentCollected(
3233
address indexed payer,
3334
address indexed receiver,
3435
address indexed dataService,
35-
uint256 tokensReceiver,
36-
uint256 tokensDelegationPool,
36+
uint256 tokens,
37+
uint256 tokensProtocol,
3738
uint256 tokensDataService,
38-
uint256 tokensProtocol
39+
uint256 tokensDelegationPool,
40+
uint256 tokensReceiver
3941
);
4042

4143
/**
42-
* @notice Thrown when there are insufficient tokens to pay the required amount
43-
* @param tokens The amount of tokens available
44-
* @param minTokens The amount of tokens being collected
44+
* @notice Thrown when the calculated amount of tokens to be paid out to all parties is
45+
* not the same as the amount of tokens being collected
46+
* @param tokens The amount of tokens being collected
47+
* @param tokensCalculated The sum of all the tokens to be paid out
4548
*/
46-
error GraphPaymentsInsufficientTokens(uint256 tokens, uint256 minTokens);
49+
error GraphPaymentsBadAccounting(uint256 tokens, uint256 tokensCalculated);
4750

4851
/**
4952
* @notice Thrown when the protocol payment cut is invalid
5053
* @param protocolPaymentCut The protocol payment cut
5154
*/
5255
error GraphPaymentsInvalidProtocolPaymentCut(uint256 protocolPaymentCut);
5356

57+
/**
58+
* @notice Thrown when trying to use a cut that is not expressed in PPM
59+
* @param cut The cut
60+
*/
61+
error GraphPaymentsInvalidCut(uint256 cut);
62+
5463
/**
5564
* @notice Collects funds from a payer.
5665
* It will pay cuts to all relevant parties and forward the rest to the receiver.
5766
* @param paymentType The type of payment as defined in {IGraphPayments}
5867
* @param receiver The address of the receiver
5968
* @param tokens The amount of tokens being collected
6069
* @param dataService The address of the data service
61-
* @param tokensDataService The amount of tokens that should be sent to the data service
70+
* @param dataServiceCut The data service cut in PPM
6271
*/
6372
function collect(
6473
PaymentTypes paymentType,
6574
address receiver,
6675
uint256 tokens,
6776
address dataService,
68-
uint256 tokensDataService
77+
uint256 dataServiceCut
6978
) external;
7079
}

packages/horizon/contracts/interfaces/IPaymentsCollector.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ interface IPaymentsCollector {
1919
* @param paymentType The payment type collected as defined by {IGraphPayments}
2020
* @param payer The address of the payer
2121
* @param receiver The address of the receiver
22-
* @param tokensReceiver The amount of tokens received by the receiver
2322
* @param dataService The address of the data service
24-
* @param tokensDataService The amount of tokens received by the data service
23+
* @param tokens The amount of tokens being collected
2524
*/
2625
event PaymentCollected(
2726
IGraphPayments.PaymentTypes indexed paymentType,
2827
address indexed payer,
2928
address receiver,
30-
uint256 tokensReceiver,
3129
address indexed dataService,
32-
uint256 tokensDataService
30+
uint256 tokens
3331
);
3432

3533
/**

0 commit comments

Comments
 (0)