Skip to content

Commit

Permalink
Merge branch 'horizon' into tmigone/update-hsa
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigone authored Dec 17, 2024
2 parents b234104 + 0f2100d commit b1c1f8e
Show file tree
Hide file tree
Showing 81 changed files with 3,211 additions and 1,342 deletions.
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
106 changes: 3 additions & 103 deletions packages/horizon/contracts/interfaces/IPaymentsEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,6 @@ interface IPaymentsEscrow {
uint256 thawEndTimestamp;
}

/// @notice Details for a payer-collector pair
/// @dev Collectors can be removed only after a thawing period
struct Collector {
// Amount of tokens the collector is allowed to collect
uint256 allowance;
// Timestamp at which the collector thawing period ends (zero if not thawing)
uint256 thawEndTimestamp;
}

/**
* @notice Emitted when a payer authorizes a collector to collect funds
* @param payer The address of the payer
* @param collector The address of the collector
* @param addedAllowance The amount of tokens added to the collector's allowance
* @param newTotalAllowance The new total allowance after addition
*/
event AuthorizedCollector(
address indexed payer,
address indexed collector,
uint256 addedAllowance,
uint256 newTotalAllowance
);

/**
* @notice Emitted when a payer thaws a collector
* @param payer The address of the payer
* @param collector The address of the collector
*/
event ThawCollector(address indexed payer, address indexed collector);

/**
* @notice Emitted when a payer cancels the thawing of a collector
* @param payer The address of the payer
* @param collector The address of the collector
*/
event CancelThawCollector(address indexed payer, address indexed collector);

/**
* @notice Emitted when a payer revokes a collector authorization.
* @param payer The address of the payer
* @param collector The address of the collector
*/
event RevokeCollector(address indexed payer, address indexed collector);

/**
* @notice Emitted when a payer deposits funds into the escrow for a payer-collector-receiver tuple
* @param payer The address of the payer
Expand Down Expand Up @@ -152,13 +108,6 @@ interface IPaymentsEscrow {
*/
error PaymentsEscrowThawingPeriodTooLong(uint256 thawingPeriod, uint256 maxWaitPeriod);

/**
* @notice Thrown when a collector has insufficient allowance to collect funds
* @param allowance The current allowance
* @param minAllowance The minimum required allowance
*/
error PaymentsEscrowInsufficientAllowance(uint256 allowance, uint256 minAllowance);

/**
* @notice Thrown when the contract balance is not consistent with the collection amount
* @param balanceBefore The balance before the collection
Expand All @@ -172,54 +121,6 @@ interface IPaymentsEscrow {
*/
error PaymentsEscrowInvalidZeroTokens();

/**
* @notice Authorize a collector to collect funds from the payer's escrow
* @dev This function can only be used to increase the allowance of a collector.
* To reduce it the authorization must be revoked and a new one must be created.
*
* Requirements:
* - `allowance` must be greater than zero
*
* Emits an {AuthorizedCollector} event
*
* @param collector The address of the collector
* @param allowance The amount of tokens to add to the collector's allowance
*/
function approveCollector(address collector, uint256 allowance) external;

/**
* @notice Thaw a collector's collector authorization
* @dev The thawing period is defined by the `REVOKE_COLLECTOR_THAWING_PERIOD` constant
*
* Emits a {ThawCollector} event
*
* @param collector The address of the collector
*/
function thawCollector(address collector) external;

/**
* @notice Cancel a collector's authorization thawing
* @dev Requirements:
* - `collector` must be thawing
*
* Emits a {CancelThawCollector} event
*
* @param collector The address of the collector
*/
function cancelThawCollector(address collector) external;

/**
* @notice Revoke a collector's authorization.
* Removes the collector from the list of authorized collectors.
* @dev Requirements:
* - `collector` must have thawed
*
* Emits a {RevokeCollector} event
*
* @param collector The address of the collector
*/
function revokeCollector(address collector) external;

/**
* @notice Deposits funds into the escrow for a payer-collector-receiver tuple, where
* the payer is the transaction caller.
Expand Down Expand Up @@ -277,8 +178,6 @@ interface IPaymentsEscrow {
* @notice Collects funds from the payer-collector-receiver's escrow and sends them to {GraphPayments} for
* distribution using the Graph Horizon Payments protocol.
* The function will revert if there are not enough funds in the escrow.
* @dev Requirements:
* - `collector` needs to be authorized by the payer and have enough allowance
*
* Emits an {EscrowCollected} event
*
Expand All @@ -287,19 +186,20 @@ interface IPaymentsEscrow {
* @param receiver The address of the receiver
* @param tokens The amount of tokens to collect
* @param dataService The address of the data service
* @param tokensDataService The amount of tokens that {GraphPayments} should send to the data service
* @param dataServiceCut The data service cut in PPM that {GraphPayments} should send
*/
function collect(
IGraphPayments.PaymentTypes paymentType,
address payer,
address receiver,
uint256 tokens,
address dataService,
uint256 tokensDataService
uint256 dataServiceCut
) external;

/**
* @notice Get the balance of a payer-collector-receiver tuple
* This function will return 0 if the current balance is less than the amount of funds being thawed.
* @param payer The address of the payer
* @param collector The address of the collector
* @param receiver The address of the receiver
Expand Down
Loading

0 comments on commit b1c1f8e

Please sign in to comment.