Skip to content

Commit

Permalink
Merge branch 'horizon' into fix_oz_n-02
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigone authored Sep 24, 2024
2 parents 95e0945 + 3e57ba3 commit 3b64387
Show file tree
Hide file tree
Showing 31 changed files with 562 additions and 133 deletions.
4 changes: 2 additions & 2 deletions packages/contracts/contracts/curation/Curation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {

/**
* @notice Get the amount of token reserves in a curation pool.
* @param _subgraphDeploymentID Subgraph deployment curation poool
* @param _subgraphDeploymentID Subgraph deployment curation pool
* @return Amount of token reserves in the curation pool
*/
function getCurationPoolTokens(bytes32 _subgraphDeploymentID) external view override returns (uint256) {
Expand Down Expand Up @@ -286,7 +286,7 @@ contract Curation is CurationV2Storage, GraphUpgradeable {

/**
* @notice Get the amount of signal in a curation pool.
* @param _subgraphDeploymentID Subgraph deployment curation poool
* @param _subgraphDeploymentID Subgraph deployment curation pool
* @return Amount of signal minted for the subgraph deployment
*/
function getCurationPoolSignal(bytes32 _subgraphDeploymentID) public view override returns (uint256) {
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/contracts/curation/ICuration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ interface ICuration {

/**
* @notice Get the amount of signal in a curation pool.
* @param _subgraphDeploymentID Subgraph deployment curation poool
* @param _subgraphDeploymentID Subgraph deployment curation pool
* @return Amount of signal minted for the subgraph deployment
*/
function getCurationPoolSignal(bytes32 _subgraphDeploymentID) external view returns (uint256);

/**
* @notice Get the amount of token reserves in a curation pool.
* @param _subgraphDeploymentID Subgraph deployment curation poool
* @param _subgraphDeploymentID Subgraph deployment curation pool
* @return Amount of token reserves in the curation pool
*/
function getCurationPoolTokens(bytes32 _subgraphDeploymentID) external view returns (uint256);
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/contracts/l2/curation/L2Curation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ contract L2Curation is CurationV3Storage, GraphUpgradeable, IL2Curation {

/**
* @notice Assign Graph Tokens collected as curation fees to the curation pool reserve.
* @dev This function can only be called by the Staking contract and will do the bookeeping of
* @dev This function can only be called by the Staking contract and will do the Bookkeeping of
* transferred tokens into this contract.
* @param _subgraphDeploymentID SubgraphDeployment where funds should be allocated as reserves
* @param _tokens Amount of Graph Tokens to add to reserves
Expand Down Expand Up @@ -326,7 +326,7 @@ contract L2Curation is CurationV3Storage, GraphUpgradeable, IL2Curation {

/**
* @notice Get the amount of token reserves in a curation pool.
* @param _subgraphDeploymentID Subgraph deployment curation poool
* @param _subgraphDeploymentID Subgraph deployment curation pool
* @return Amount of token reserves in the curation pool
*/
function getCurationPoolTokens(bytes32 _subgraphDeploymentID) external view override returns (uint256) {
Expand Down Expand Up @@ -355,7 +355,7 @@ contract L2Curation is CurationV3Storage, GraphUpgradeable, IL2Curation {

/**
* @notice Get the amount of signal in a curation pool.
* @param _subgraphDeploymentID Subgraph deployment curation poool
* @param _subgraphDeploymentID Subgraph deployment curation pool
* @return Amount of signal minted for the subgraph deployment
*/
function getCurationPoolSignal(bytes32 _subgraphDeploymentID) public view override returns (uint256) {
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/contracts/rewards/IRewardsIssuer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ interface IRewardsIssuer {
function getSubgraphAllocatedTokens(bytes32 _subgraphDeploymentId) external view returns (uint256);

/**
* @notice Wether or not an allocation is active (i.e open)
* @notice Whether or not an allocation is active (i.e open)
* @param _allocationId Allocation Id
* @return Wether or not the allocation is active
* @return Whether or not the allocation is active
*/
function isActiveAllocation(address _allocationId) external view returns (bool);
}
2 changes: 1 addition & 1 deletion packages/contracts/contracts/staking/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
if (curationFees > 0) {
// Transfer and call collect()
// This function transfer tokens to a trusted protocol contracts
// Then we call collect() to do the transfer bookeeping
// Then we call collect() to do the transfer Bookkeeping
rewardsManager().onSubgraphSignalUpdate(_subgraphDeploymentID);
TokenUtils.pushTokens(_graphToken, address(curation), curationFees);
curation.collect(_subgraphDeploymentID, curationFees);
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/staking/libs/Stakes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ library Stakes {
/**
* @dev Unlock tokens.
* @param stake Stake data
* @param _tokens Amount of tokens to unkock
* @param _tokens Amount of tokens to unlock
*/
function unlockTokens(Stakes.Indexer storage stake, uint256 _tokens) internal {
stake.tokensLocked = stake.tokensLocked.sub(_tokens);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ abstract contract DataServicePausable is Pausable, DataService, IDataServicePaus
/**
* @notice See {IDataServicePausable-pause}
*/
function pause() external onlyPauseGuardian whenNotPaused {
function pause() external override onlyPauseGuardian whenNotPaused {
_pause();
}

/**
* @notice See {IDataServicePausable-pause}
*/
function unpause() external onlyPauseGuardian whenPaused {
function unpause() external override onlyPauseGuardian whenPaused {
_unpause();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataSer
/**
* @notice See {IDataServicePausable-pause}
*/
function pause() external onlyPauseGuardian whenNotPaused {
function pause() external override onlyPauseGuardian whenNotPaused {
_pause();
}

/**
* @notice See {IDataServicePausable-pause}
*/
function unpause() external onlyPauseGuardian whenPaused {
function unpause() external override onlyPauseGuardian whenPaused {
_unpause();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/horizon/contracts/interfaces/ITAPCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface ITAPCollector is IPaymentsCollector {
}

/**
* Trown when the caller is not the data service the RAV was issued to
* Thrown when the caller is not the data service the RAV was issued to
* @param caller The address of the caller
* @param dataService The address of the data service
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ interface IHorizonStakingExtension is IRewardsIssuer, IL2StakingBase {
function isAllocation(address allocationID) external view returns (bool);

/**
* @notice Retrun the time in blocks to unstake
* @notice Return the time in blocks to unstake
* @return Thawing period in blocks
*/
// solhint-disable-next-line func-name-mixedcase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ interface IHorizonStakingMain {
* @param thawRequestId The ID of the thaw request
* @param tokens The amount of tokens being released
* @param shares The amount of shares being released
* @param thawingUntil The timestamp until the stake has thawn
* @param thawingUntil The timestamp until the stake has thawed
*/
event ThawRequestFulfilled(bytes32 indexed thawRequestId, uint256 tokens, uint256 shares, uint64 thawingUntil);

Expand Down Expand Up @@ -402,6 +402,13 @@ interface IHorizonStakingMain {
*/
error HorizonStakingInvalidDelegationPoolState(address serviceProvider, address verifier);

/**
* @notice Thrown when attempting to operate with a delegation pool that does not exist.
* @param serviceProvider The service provider address
* @param verifier The verifier address
*/
error HorizonStakingInvalidDelegationPool(address serviceProvider, address verifier);

// -- Errors: thaw requests --

error HorizonStakingNothingThawing();
Expand All @@ -417,7 +424,7 @@ interface IHorizonStakingMain {
error HorizonStakingStillThawing(uint256 until);

/**
* @notice Thrown when a service provider attempts to operate on verifieres that are not allowed.
* @notice Thrown when a service provider attempts to operate on verifiers that are not allowed.
* @dev Only applies to stake from locked wallets.
*/
error HorizonStakingVerifierNotAllowed(address verifier);
Expand Down Expand Up @@ -578,7 +585,7 @@ interface IHorizonStakingMain {
/**
* @notice Remove tokens from a provision and move them back to the service provider's idle stake.
* @dev The parameter `nThawRequests` can be set to a non zero value to fulfill a specific number of thaw
* requests in the event that fulfulling all of them results in a gas limit error.
* requests in the event that fulfilling all of them results in a gas limit error.
*
* Requirements:
* - Must have previously initiated a thaw request using {thaw}.
Expand Down Expand Up @@ -704,7 +711,7 @@ interface IHorizonStakingMain {
* @notice Withdraw undelegated tokens from a provision after thawing.
* Tokens can be automatically re-delegated to another provision by setting `newServiceProvider`.
* @dev The parameter `nThawRequests` can be set to a non zero value to fulfill a specific number of thaw
* requests in the event that fulfulling all of them results in a gas limit error.
* requests in the event that fulfilling all of them results in a gas limit error.
*
* Requirements:
* - Must have previously initiated a thaw request using {undelegate}.
Expand Down Expand Up @@ -744,7 +751,7 @@ interface IHorizonStakingMain {
/**
* @notice Delegate tokens to the subgraph data service provision.
* This function is for backwards compatibility with the legacy staking contract.
* It only allows delegting to the subgraph data service and DOES NOT have slippage protection.
* It only allows delegating to the subgraph data service and DOES NOT have slippage protection.
* @dev See {delegate}.
* @param serviceProvider The service provider address
* @param tokens The amount of tokens to delegate
Expand All @@ -754,7 +761,7 @@ interface IHorizonStakingMain {
/**
* @notice Undelegate tokens from the subgraph data service provision and start thawing them.
* This function is for backwards compatibility with the legacy staking contract.
* It only allows undelegting from the subgraph data service.
* It only allows undelegating from the subgraph data service.
* @dev See {undelegate}.
* @param serviceProvider The service provider address
* @param shares The amount of shares to undelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface IHorizonStakingTypes {
* @dev See {ServiceProviderInternal} for the actual storage representation
*/
struct ServiceProvider {
// Total amount of tokens on the provider stake (only staked by the provider, inludes all provisions)
// Total amount of tokens on the provider stake (only staked by the provider, includes all provisions)
uint256 tokensStaked;
// Total amount of tokens locked in provisions (only staked by the provider)
uint256 tokensProvisioned;
Expand All @@ -50,7 +50,7 @@ interface IHorizonStakingTypes {
* @dev It contains deprecated fields from the `Indexer` struct to maintain storage compatibility.
*/
struct ServiceProviderInternal {
// Total amount of tokens on the provider stake (only staked by the provider, inludes all provisions)
// Total amount of tokens on the provider stake (only staked by the provider, includes all provisions)
uint256 tokensStaked;
// (Deprecated) Tokens used in allocations
uint256 __DEPRECATED_tokensAllocated; // solhint-disable-line graph/leading-underscore
Expand Down
2 changes: 1 addition & 1 deletion packages/horizon/contracts/libraries/PPMMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library PPMMath {
*/
function mulPPMRoundUp(uint256 a, uint256 b) internal pure returns (uint256) {
require(isValidPPM(b), PPMMathInvalidPPM(b));
return a - mulPPM(MAX_PPM - b, a);
return a - mulPPM(a, MAX_PPM - b);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/horizon/contracts/payments/GraphPayments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract GraphPayments is Initializable, MulticallUpgradeable, GraphDirectory, I

/**
* @notice Constructor for the {GraphPayments} contract
* @dev This contract is upgradeable however we stil use the constructor to set
* @dev This contract is upgradeable however we still use the constructor to set
* a few immutable variables.
* @param controller The address of the Graph controller
* @param protocolPaymentCut The protocol tax in PPM
Expand Down
12 changes: 10 additions & 2 deletions packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
}

/**
* @dev The staking contract is upgradeable however we stil use the constructor to set
* @dev The staking contract is upgradeable however we still use the constructor to set
* a few immutable variables.
* @param controller The address of the Graph controller contract.
* @param stakingExtensionAddress The address of the staking extension contract.
Expand Down Expand Up @@ -279,7 +279,15 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
uint256 tokens
) external override notPaused {
require(tokens != 0, HorizonStakingInvalidZeroTokens());

// Provision must exist before adding to delegation pool
Provision memory prov = _provisions[serviceProvider][verifier];
require(prov.createdAt != 0, HorizonStakingInvalidProvision(serviceProvider, verifier));

// Delegation pool must exist before adding tokens
DelegationPoolInternal storage pool = _getDelegationPool(serviceProvider, verifier);
require(pool.shares > 0, HorizonStakingInvalidDelegationPool(serviceProvider, verifier));

pool.tokens = pool.tokens + tokens;
_graphToken().pullTokens(msg.sender, tokens);
emit TokensToDelegationPoolAdded(serviceProvider, verifier, tokens);
Expand Down Expand Up @@ -903,7 +911,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
*
* @param _thawRequestId The ID of the current thaw request
* @param _acc The accumulator data for the thaw requests being fulfilled
* @return Wether the thaw request is still thawing, indicating that the traversal should continue or stop.
* @return Whether the thaw request is still thawing, indicating that the traversal should continue or stop.
* @return The updated accumulator data
*/
function _fulfillThawRequest(bytes32 _thawRequestId, bytes memory _acc) private returns (bool, bytes memory) {
Expand Down
2 changes: 1 addition & 1 deletion packages/horizon/contracts/staking/HorizonStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract contract HorizonStakingBase is
address internal immutable SUBGRAPH_DATA_SERVICE_ADDRESS;

/**
* @dev The staking contract is upgradeable however we stil use the constructor to set
* @dev The staking contract is upgradeable however we still use the constructor to set
* a few immutable variables.
* @param controller The address of the Graph controller contract.
* @param subgraphDataServiceAddress The address of the subgraph data service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IL2StakingBase, IHorizon
}

/**
* @dev The staking contract is upgradeable however we stil use the constructor to set
* @dev The staking contract is upgradeable however we still use the constructor to set
* a few immutable variables.
* @param controller The address of the Graph controller contract.
* @param subgraphDataServiceAddress The address of the subgraph data service.
Expand Down Expand Up @@ -296,7 +296,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IL2StakingBase, IHorizon
}

/**
* @notice Retrun the time in blocks to unstake
* @notice Return the time in blocks to unstake
* Deprecated, now enforced by each data service (verifier)
* @return Thawing period in blocks
*/
Expand Down Expand Up @@ -569,7 +569,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IL2StakingBase, IHorizon
if (curationFees > 0) {
// Transfer and call collect()
// This function transfer tokens to a trusted protocol contracts
// Then we call collect() to do the transfer bookeeping
// Then we call collect() to do the transfer Bookkeeping
_graphRewardsManager().onSubgraphSignalUpdate(_subgraphDeploymentID);
_graphToken().pushTokens(address(curation), curationFees);
curation.collect(_subgraphDeploymentID, curationFees);
Expand Down
Loading

0 comments on commit 3b64387

Please sign in to comment.