Skip to content

Commit

Permalink
Merge branch 'horizon' into horizon-gre
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigone authored Dec 17, 2024
2 parents 8f3e0f1 + 170572f commit 58c518c
Show file tree
Hide file tree
Showing 147 changed files with 3,304 additions and 283,093 deletions.
8 changes: 5 additions & 3 deletions packages/horizon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ Graph Horizon is the next evolution of the Graph Protocol.

## Deployment

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

```bash
yarn install
yarn build
npx hardhat ignition deploy ./ignition/modules/horizon.ts \
--parameters ./ignition/configs/horizon.hardhat.json \
--parameters ./ignition/configs/horizon.hardhat.json5 \
--network hardhat
```

You can use any network defined in `hardhat.config.ts` by replacing `hardhat` with the network name.
You can use any network defined in `hardhat.config.ts` by replacing `hardhat` with the network name.

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.
2 changes: 2 additions & 0 deletions packages/horizon/contracts/data-service/DataService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { ProvisionManager } from "./utilities/ProvisionManager.sol";
* - If the data service implementation is NOT upgradeable, it must initialize the contract by calling
* {__DataService_init} or {__DataService_init_unchained} in the constructor. Note that the `initializer`
* will be required in the constructor.
* - Note that in both cases if using {__DataService_init_unchained} variant the corresponding parent
* initializers must be called in the implementation.
*/
abstract contract DataService is GraphDirectory, ProvisionManager, DataServiceV1Storage, IDataService {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ pragma solidity 0.8.27;

abstract contract DataServiceV1Storage {
/// @dev Gap to allow adding variables in future upgrades
/// Note that this contract is not upgradeable but might be inherited by an upgradeable contract
uint256[50] private __gap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { DataServiceFeesV1Storage } from "./DataServiceFeesStorage.sol";
* @dev Implementation of the {IDataServiceFees} interface.
* @notice Extension for the {IDataService} contract to handle payment collateralization
* using a Horizon provision. See {IDataServiceFees} for more details.
* @dev This contract inherits from {DataService} which needs to be initialized, please see
* {DataService} for detailed instructions.
*/
abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDataServiceFees {
using ProvisionTracker for mapping(address => uint256);
Expand Down Expand Up @@ -127,9 +129,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
* @param _claimId The ID of the stake claim
*/
function _getNextStakeClaim(bytes32 _claimId) private view returns (bytes32) {
StakeClaim memory claim = claims[_claimId];
require(claim.createdAt != 0, DataServiceFeesClaimNotFound(_claimId));
return claim.nextClaim;
return claims[_claimId].nextClaim;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ abstract contract DataServiceFeesV1Storage {
mapping(address serviceProvider => LinkedList.List list) public claimsLists;

/// @dev Gap to allow adding variables in future upgrades
/// Note that this contract is not upgradeable but might be inherited by an upgradeable contract
uint256[50] private __gap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { DataService } from "../DataService.sol";
* pause guardians.
* @dev Note that this extension does not provide an external function to set pause
* guardians. This should be implemented in the derived contract.
* @dev This contract inherits from {DataService} which needs to be initialized, please see
* {DataService} for detailed instructions.
*/
abstract contract DataServicePausable is Pausable, DataService, IDataServicePausable {
/// @notice List of pause guardians and their allowed status
Expand Down Expand Up @@ -51,6 +53,10 @@ abstract contract DataServicePausable is Pausable, DataService, IDataServicePaus
* @param _allowed The allowed status of the pause guardian
*/
function _setPauseGuardian(address _pauseGuardian, bool _allowed) internal {
require(
pauseGuardians[_pauseGuardian] == !_allowed,
DataServicePausablePauseGuardianNoChange(_pauseGuardian, _allowed)
);
pauseGuardians[_pauseGuardian] = _allowed;
emit PauseGuardianSet(_pauseGuardian, _allowed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import { DataService } from "../DataService.sol";
* @title DataServicePausableUpgradeable contract
* @dev Implementation of the {IDataServicePausable} interface.
* @dev Upgradeable version of the {DataServicePausable} contract.
* @dev This contract inherits from {DataService} which needs to be initialized, please see
* {DataService} for detailed instructions.
*/
abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataService, IDataServicePausable {
/// @notice List of pause guardians and their allowed status
mapping(address pauseGuardian => bool allowed) public pauseGuardians;

/// @dev Gap to allow adding variables in future upgrades
uint256[50] private __gap;

/**
* @notice Checks if the caller is a pause guardian.
*/
Expand Down Expand Up @@ -61,7 +66,11 @@ abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataSer
* @param _pauseGuardian The address of the pause guardian
* @param _allowed The allowed status of the pause guardian
*/
function _setPauseGuardian(address _pauseGuardian, bool _allowed) internal whenNotPaused {
function _setPauseGuardian(address _pauseGuardian, bool _allowed) internal {
require(
pauseGuardians[_pauseGuardian] == !_allowed,
DataServicePausablePauseGuardianNoChange(_pauseGuardian, _allowed)
);
pauseGuardians[_pauseGuardian] = _allowed;
emit PauseGuardianSet(_pauseGuardian, _allowed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s
* that calls this contract's _rescueTokens.
* @dev Note that this extension does not provide an external function to set
* rescuers. This should be implemented in the derived contract.
* @dev This contract inherits from {DataService} which needs to be initialized, please see
* {DataService} for detailed instructions.
*/
abstract contract DataServiceRescuable is DataService, IDataServiceRescuable {
/// @notice List of rescuers and their allowed status
mapping(address rescuer => bool allowed) public rescuers;

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

/**
* @notice Checks if the caller is a rescuer.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ interface IDataServicePausable is IDataService {
*/
error DataServicePausableNotPauseGuardian(address account);

/**
* @notice Emitted when a pause guardian is set to the same allowed status
* @param account The address of the pause guardian
* @param allowed The allowed status of the pause guardian
*/
error DataServicePausablePauseGuardianNoChange(address account, bool allowed);

/**
* @notice Pauses the data service.
* @dev Note that only functions using the modifiers `whenNotPaused`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,16 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa

/**
* @notice Checks if the provision tokens of a service provider are within the valid range.
* Note that thawing tokens are not considered in this check.
* @param _provision The provision to check.
*/
function _checkProvisionTokens(IHorizonStaking.Provision memory _provision) internal view virtual {
_checkValueInRange(_provision.tokens, minimumProvisionTokens, maximumProvisionTokens, "tokens");
_checkValueInRange(
_provision.tokens - _provision.tokensThawing,
minimumProvisionTokens,
maximumProvisionTokens,
"tokens"
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ abstract contract ProvisionManagerV1Storage {
uint32 public delegationRatio;

/// @dev Gap to allow adding variables in future upgrades
/// Note that this contract is not upgradeable but might be inherited by an upgradeable contract
uint256[50] private __gap;
}
35 changes: 22 additions & 13 deletions packages/horizon/contracts/interfaces/IGraphPayments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,57 @@ interface IGraphPayments {
* @param payer The address of the payer
* @param receiver The address of the receiver
* @param dataService The address of the data service
* @param tokensReceiver Amount of tokens for the receiver
* @param tokensDelegationPool Amount of tokens for delegators
* @param tokensDataService Amount of tokens for the data service
* @param tokens The total amount of tokens being collected
* @param tokensProtocol Amount of tokens charged as protocol tax
* @param tokensDataService Amount of tokens for the data service
* @param tokensDelegationPool Amount of tokens for delegators
* @param tokensReceiver Amount of tokens for the receiver
*/
event PaymentCollected(
event GraphPaymentCollected(
address indexed payer,
address indexed receiver,
address indexed dataService,
uint256 tokensReceiver,
uint256 tokensDelegationPool,
uint256 tokens,
uint256 tokensProtocol,
uint256 tokensDataService,
uint256 tokensProtocol
uint256 tokensDelegationPool,
uint256 tokensReceiver
);

/**
* @notice Thrown when there are insufficient tokens to pay the required amount
* @param tokens The amount of tokens available
* @param minTokens The amount of tokens being collected
* @notice Thrown when the calculated amount of tokens to be paid out to all parties is
* not the same as the amount of tokens being collected
* @param tokens The amount of tokens being collected
* @param tokensCalculated The sum of all the tokens to be paid out
*/
error GraphPaymentsInsufficientTokens(uint256 tokens, uint256 minTokens);
error GraphPaymentsBadAccounting(uint256 tokens, uint256 tokensCalculated);

/**
* @notice Thrown when the protocol payment cut is invalid
* @param protocolPaymentCut The protocol payment cut
*/
error GraphPaymentsInvalidProtocolPaymentCut(uint256 protocolPaymentCut);

/**
* @notice Thrown when trying to use a cut that is not expressed in PPM
* @param cut The cut
*/
error GraphPaymentsInvalidCut(uint256 cut);

/**
* @notice Collects funds from a payer.
* It will pay cuts to all relevant parties and forward the rest to the receiver.
* @param paymentType The type of payment as defined in {IGraphPayments}
* @param receiver The address of the receiver
* @param tokens The amount of tokens being collected
* @param dataService The address of the data service
* @param tokensDataService The amount of tokens that should be sent to the data service
* @param dataServiceCut The data service cut in PPM
*/
function collect(
PaymentTypes paymentType,
address receiver,
uint256 tokens,
address dataService,
uint256 tokensDataService
uint256 dataServiceCut
) external;
}
6 changes: 2 additions & 4 deletions packages/horizon/contracts/interfaces/IPaymentsCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ interface IPaymentsCollector {
* @param paymentType The payment type collected as defined by {IGraphPayments}
* @param payer The address of the payer
* @param receiver The address of the receiver
* @param tokensReceiver The amount of tokens received by the receiver
* @param dataService The address of the data service
* @param tokensDataService The amount of tokens received by the data service
* @param tokens The amount of tokens being collected
*/
event PaymentCollected(
IGraphPayments.PaymentTypes indexed paymentType,
address indexed payer,
address receiver,
uint256 tokensReceiver,
address indexed dataService,
uint256 tokensDataService
uint256 tokens
);

/**
Expand Down
Loading

0 comments on commit 58c518c

Please sign in to comment.