diff --git a/packages/horizon/contracts/SimpleTest.sol b/packages/horizon/contracts/SimpleTest.sol deleted file mode 100644 index 5cc28d9cc..000000000 --- a/packages/horizon/contracts/SimpleTest.sol +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.4.0 <0.9.0; - -import { Test } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol"; - -contract SimpleTest is Test { - function test() external pure returns (uint256) { - return 42; - } -} diff --git a/packages/subgraph-service/contracts/data-service/DataService.sol b/packages/horizon/contracts/data-service/DataService.sol similarity index 96% rename from packages/subgraph-service/contracts/data-service/DataService.sol rename to packages/horizon/contracts/data-service/DataService.sol index 52f1e25b5..f256cbba7 100644 --- a/packages/subgraph-service/contracts/data-service/DataService.sol +++ b/packages/horizon/contracts/data-service/DataService.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IDataService } from "./IDataService.sol"; +import { IDataService } from "../interfaces/IDataService.sol"; -import { GraphDirectory } from "./GraphDirectory.sol"; import { DataServiceV1Storage } from "./DataServiceStorage.sol"; +import { GraphDirectory } from "./GraphDirectory.sol"; import { ProvisionManager } from "./utilities/ProvisionManager.sol"; /** diff --git a/packages/subgraph-service/contracts/data-service/DataServiceStorage.sol b/packages/horizon/contracts/data-service/DataServiceStorage.sol similarity index 100% rename from packages/subgraph-service/contracts/data-service/DataServiceStorage.sol rename to packages/horizon/contracts/data-service/DataServiceStorage.sol diff --git a/packages/subgraph-service/contracts/data-service/GraphDirectory.sol b/packages/horizon/contracts/data-service/GraphDirectory.sol similarity index 96% rename from packages/subgraph-service/contracts/data-service/GraphDirectory.sol rename to packages/horizon/contracts/data-service/GraphDirectory.sol index f35a7a663..b79d7de52 100644 --- a/packages/subgraph-service/contracts/data-service/GraphDirectory.sol +++ b/packages/horizon/contracts/data-service/GraphDirectory.sol @@ -3,7 +3,7 @@ pragma solidity 0.8.24; import { IController } from "@graphprotocol/contracts/contracts/governance/IController.sol"; -import { IHorizonStaking } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol"; +import { IHorizonStaking } from "../interfaces/IHorizonStaking.sol"; import { IGraphToken } from "@graphprotocol/contracts/contracts/token/IGraphToken.sol"; // import { IGraphTokenGateway } from "@graphprotocol/contracts/contracts/gateway/IGraphTokenGateway.sol"; import { IEpochManager } from "@graphprotocol/contracts/contracts/epochs/IEpochManager.sol"; diff --git a/packages/subgraph-service/contracts/data-service/extensions/DataServiceFees.sol b/packages/horizon/contracts/data-service/extensions/DataServiceFees.sol similarity index 98% rename from packages/subgraph-service/contracts/data-service/extensions/DataServiceFees.sol rename to packages/horizon/contracts/data-service/extensions/DataServiceFees.sol index 583f01efa..3978d9a48 100644 --- a/packages/subgraph-service/contracts/data-service/extensions/DataServiceFees.sol +++ b/packages/horizon/contracts/data-service/extensions/DataServiceFees.sol @@ -4,11 +4,11 @@ pragma solidity ^0.8.24; import { IDataServiceFees } from "./IDataServiceFees.sol"; import { IGraphPayments } from "../../interfaces/IGraphPayments.sol"; +import { ProvisionTracker } from "../libraries/ProvisionTracker.sol"; + import { DataService } from "../DataService.sol"; import { DataServiceFeesV1Storage } from "./DataServiceFeesStorage.sol"; -import { ProvisionTracker } from "../libraries/ProvisionTracker.sol"; - abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDataServiceFees { using ProvisionTracker for mapping(address => uint256); @@ -66,7 +66,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat uint256 _tokens, uint256 _unlockTimestamp ) internal { - feesProvisionTracker[_feeType].lock(GRAPH_STAKING, _serviceProvider, _tokens); + feesProvisionTracker[_feeType].lock(GRAPH_STAKING, _serviceProvider, _tokens, delegationRatio); StakeClaimsList storage claimsList = claimsLists[_feeType][_serviceProvider]; bytes32 claimId = _buildStakeClaimId(_serviceProvider, claimsList.nonce); diff --git a/packages/subgraph-service/contracts/data-service/extensions/DataServiceFeesStorage.sol b/packages/horizon/contracts/data-service/extensions/DataServiceFeesStorage.sol similarity index 96% rename from packages/subgraph-service/contracts/data-service/extensions/DataServiceFeesStorage.sol rename to packages/horizon/contracts/data-service/extensions/DataServiceFeesStorage.sol index 4296a952a..d64f99239 100644 --- a/packages/subgraph-service/contracts/data-service/extensions/DataServiceFeesStorage.sol +++ b/packages/horizon/contracts/data-service/extensions/DataServiceFeesStorage.sol @@ -15,6 +15,8 @@ abstract contract DataServiceFeesV1Storage { mapping(IGraphPayments.PaymentTypes feeType => mapping(address serviceProvider => IDataServiceFees.StakeClaimsList list)) public claimsLists; + uint32 public delegationRatio; + /// @dev Gap to allow adding variables in future upgrades uint256[50] private __gap; } diff --git a/packages/subgraph-service/contracts/data-service/extensions/DataServicePausable.sol b/packages/horizon/contracts/data-service/extensions/DataServicePausable.sol similarity index 100% rename from packages/subgraph-service/contracts/data-service/extensions/DataServicePausable.sol rename to packages/horizon/contracts/data-service/extensions/DataServicePausable.sol diff --git a/packages/subgraph-service/contracts/data-service/extensions/DataServiceRescuable.sol b/packages/horizon/contracts/data-service/extensions/DataServiceRescuable.sol similarity index 97% rename from packages/subgraph-service/contracts/data-service/extensions/DataServiceRescuable.sol rename to packages/horizon/contracts/data-service/extensions/DataServiceRescuable.sol index 7e6120783..76a25162a 100644 --- a/packages/subgraph-service/contracts/data-service/extensions/DataServiceRescuable.sol +++ b/packages/horizon/contracts/data-service/extensions/DataServiceRescuable.sol @@ -6,7 +6,7 @@ import { IDataServiceRescuable } from "./IDataServiceRescuable.sol"; import { DataService } from "../DataService.sol"; -import { Denominations } from "../libraries/Denominations.sol"; +import { Denominations } from "../../libraries/Denominations.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; /** diff --git a/packages/subgraph-service/contracts/data-service/extensions/IDataServiceFees.sol b/packages/horizon/contracts/data-service/extensions/IDataServiceFees.sol similarity index 91% rename from packages/subgraph-service/contracts/data-service/extensions/IDataServiceFees.sol rename to packages/horizon/contracts/data-service/extensions/IDataServiceFees.sol index 36caf73f1..fe75755fe 100644 --- a/packages/subgraph-service/contracts/data-service/extensions/IDataServiceFees.sol +++ b/packages/horizon/contracts/data-service/extensions/IDataServiceFees.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IDataService } from "../IDataService.sol"; +import { IDataService } from "../../interfaces/IDataService.sol"; import { IGraphPayments } from "../../interfaces/IGraphPayments.sol"; interface IDataServiceFees is IDataService { diff --git a/packages/subgraph-service/contracts/data-service/extensions/IDataServicePausable.sol b/packages/horizon/contracts/data-service/extensions/IDataServicePausable.sol similarity index 73% rename from packages/subgraph-service/contracts/data-service/extensions/IDataServicePausable.sol rename to packages/horizon/contracts/data-service/extensions/IDataServicePausable.sol index 5b2940d6c..302e8a67e 100644 --- a/packages/subgraph-service/contracts/data-service/extensions/IDataServicePausable.sol +++ b/packages/horizon/contracts/data-service/extensions/IDataServicePausable.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IDataService } from "../IDataService.sol"; +import { IDataService } from "../../interfaces/IDataService.sol"; interface IDataServicePausable is IDataService { function pause() external; diff --git a/packages/subgraph-service/contracts/data-service/extensions/IDataServiceRescuable.sol b/packages/horizon/contracts/data-service/extensions/IDataServiceRescuable.sol similarity index 79% rename from packages/subgraph-service/contracts/data-service/extensions/IDataServiceRescuable.sol rename to packages/horizon/contracts/data-service/extensions/IDataServiceRescuable.sol index 36ad6d68f..ee379315c 100644 --- a/packages/subgraph-service/contracts/data-service/extensions/IDataServiceRescuable.sol +++ b/packages/horizon/contracts/data-service/extensions/IDataServiceRescuable.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IDataService } from "../IDataService.sol"; +import { IDataService } from "../../interfaces/IDataService.sol"; interface IDataServiceRescuable is IDataService { function rescueGRT(address to, uint256 amount) external; diff --git a/packages/subgraph-service/contracts/data-service/libraries/ProvisionGetter.sol b/packages/horizon/contracts/data-service/libraries/ProvisionGetter.sol similarity index 87% rename from packages/subgraph-service/contracts/data-service/libraries/ProvisionGetter.sol rename to packages/horizon/contracts/data-service/libraries/ProvisionGetter.sol index 4de039012..6fdf1e2c4 100644 --- a/packages/subgraph-service/contracts/data-service/libraries/ProvisionGetter.sol +++ b/packages/horizon/contracts/data-service/libraries/ProvisionGetter.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IHorizonStaking } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol"; +import { IHorizonStaking } from "../../interfaces/IHorizonStaking.sol"; library ProvisionGetter { using ProvisionGetter for IHorizonStaking.Provision; diff --git a/packages/subgraph-service/contracts/data-service/libraries/ProvisionTracker.sol b/packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol similarity index 82% rename from packages/subgraph-service/contracts/data-service/libraries/ProvisionTracker.sol rename to packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol index 216bbe3dc..f0acc7f89 100644 --- a/packages/subgraph-service/contracts/data-service/libraries/ProvisionTracker.sol +++ b/packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IHorizonStaking } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol"; +import { IHorizonStaking } from "../../interfaces/IHorizonStaking.sol"; library ProvisionTracker { error ProvisionTrackerInsufficientTokens(uint256 tokensAvailable, uint256 tokensRequired); @@ -10,12 +10,13 @@ library ProvisionTracker { mapping(address => uint256) storage self, IHorizonStaking graphStaking, address serviceProvider, - uint256 tokens + uint256 tokens, + uint32 delegationRatio ) internal { if (tokens == 0) return; uint256 tokensRequired = self[serviceProvider] + tokens; - uint256 tokensAvailable = graphStaking.getTokensAvailable(serviceProvider, address(this)); + uint256 tokensAvailable = graphStaking.getTokensAvailable(serviceProvider, address(this), delegationRatio); if (tokensRequired > tokensAvailable) { revert ProvisionTrackerInsufficientTokens(tokensAvailable, tokensRequired); } @@ -34,9 +35,10 @@ library ProvisionTracker { function getTokensFree( mapping(address => uint256) storage self, IHorizonStaking graphStaking, - address serviceProvider + address serviceProvider, + uint32 delegationRatio ) internal view returns (uint256) { - uint256 tokensAvailable = graphStaking.getTokensAvailable(serviceProvider, address(this)); + uint256 tokensAvailable = graphStaking.getTokensAvailable(serviceProvider, address(this), delegationRatio); if (tokensAvailable >= self[serviceProvider]) return tokensAvailable - self[serviceProvider]; else return 0; } diff --git a/packages/subgraph-service/contracts/data-service/utilities/ProvisionManager.sol b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol similarity index 95% rename from packages/subgraph-service/contracts/data-service/utilities/ProvisionManager.sol rename to packages/horizon/contracts/data-service/utilities/ProvisionManager.sol index 581cff131..dd9d2677f 100644 --- a/packages/subgraph-service/contracts/data-service/utilities/ProvisionManager.sol +++ b/packages/horizon/contracts/data-service/utilities/ProvisionManager.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IHorizonStaking } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol"; +import { IHorizonStaking } from "../../interfaces/IHorizonStaking.sol"; + +import { ProvisionGetter } from "../libraries/ProvisionGetter.sol"; +import { UintRange } from "../../libraries/UintRange.sol"; import { GraphDirectory } from "../GraphDirectory.sol"; import { ProvisionManagerV1Storage } from "./ProvisionManagerStorage.sol"; -import { ProvisionGetter } from "../libraries/ProvisionGetter.sol"; -import { UintRange } from "../libraries/UintRange.sol"; - abstract contract ProvisionManager is GraphDirectory, ProvisionManagerV1Storage { using ProvisionGetter for IHorizonStaking; using UintRange for uint256; @@ -50,7 +50,7 @@ abstract contract ProvisionManager is GraphDirectory, ProvisionManagerV1Storage function _checkAndAcceptProvision(address _serviceProvider) internal virtual { _checkProvisionParameters(_serviceProvider); - GRAPH_STAKING.acceptProvision(_serviceProvider); + GRAPH_STAKING.acceptProvisionParameters(_serviceProvider); } // -- Provision Parameters: setters -- diff --git a/packages/subgraph-service/contracts/data-service/utilities/ProvisionManagerStorage.sol b/packages/horizon/contracts/data-service/utilities/ProvisionManagerStorage.sol similarity index 100% rename from packages/subgraph-service/contracts/data-service/utilities/ProvisionManagerStorage.sol rename to packages/horizon/contracts/data-service/utilities/ProvisionManagerStorage.sol diff --git a/packages/subgraph-service/contracts/data-service/IDataService.sol b/packages/horizon/contracts/interfaces/IDataService.sol similarity index 99% rename from packages/subgraph-service/contracts/data-service/IDataService.sol rename to packages/horizon/contracts/interfaces/IDataService.sol index 0e598b2cb..4064d4444 100644 --- a/packages/subgraph-service/contracts/data-service/IDataService.sol +++ b/packages/horizon/contracts/interfaces/IDataService.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IGraphPayments } from "../interfaces/IGraphPayments.sol"; +import { IGraphPayments } from "./IGraphPayments.sol"; /** * @title Interface of the base {DataService} contract as defined by the Graph Horizon specification. diff --git a/packages/subgraph-service/contracts/interfaces/IGraphEscrow.sol b/packages/horizon/contracts/interfaces/IGraphEscrow.sol similarity index 100% rename from packages/subgraph-service/contracts/interfaces/IGraphEscrow.sol rename to packages/horizon/contracts/interfaces/IGraphEscrow.sol diff --git a/packages/subgraph-service/contracts/interfaces/IGraphPayments.sol b/packages/horizon/contracts/interfaces/IGraphPayments.sol similarity index 100% rename from packages/subgraph-service/contracts/interfaces/IGraphPayments.sol rename to packages/horizon/contracts/interfaces/IGraphPayments.sol diff --git a/packages/horizon/contracts/IGraphToken.sol b/packages/horizon/contracts/interfaces/IGraphToken.sol similarity index 93% rename from packages/horizon/contracts/IGraphToken.sol rename to packages/horizon/contracts/interfaces/IGraphToken.sol index fd0b0a553..27f68a0d2 100644 --- a/packages/horizon/contracts/IGraphToken.sol +++ b/packages/horizon/contracts/interfaces/IGraphToken.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.24; -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IGraphToken is IERC20 { // -- Mint and Burn -- diff --git a/packages/horizon/contracts/IHorizonStaking.sol b/packages/horizon/contracts/interfaces/IHorizonStaking.sol similarity index 100% rename from packages/horizon/contracts/IHorizonStaking.sol rename to packages/horizon/contracts/interfaces/IHorizonStaking.sol diff --git a/packages/horizon/contracts/IHorizonStakingBase.sol b/packages/horizon/contracts/interfaces/IHorizonStakingBase.sol similarity index 100% rename from packages/horizon/contracts/IHorizonStakingBase.sol rename to packages/horizon/contracts/interfaces/IHorizonStakingBase.sol diff --git a/packages/horizon/contracts/IHorizonStakingExtension.sol b/packages/horizon/contracts/interfaces/IHorizonStakingExtension.sol similarity index 100% rename from packages/horizon/contracts/IHorizonStakingExtension.sol rename to packages/horizon/contracts/interfaces/IHorizonStakingExtension.sol diff --git a/packages/horizon/contracts/IHorizonStakingTypes.sol b/packages/horizon/contracts/interfaces/IHorizonStakingTypes.sol similarity index 100% rename from packages/horizon/contracts/IHorizonStakingTypes.sol rename to packages/horizon/contracts/interfaces/IHorizonStakingTypes.sol diff --git a/packages/horizon/contracts/IManaged.sol b/packages/horizon/contracts/interfaces/IManaged.sol similarity index 100% rename from packages/horizon/contracts/IManaged.sol rename to packages/horizon/contracts/interfaces/IManaged.sol diff --git a/packages/horizon/contracts/IStakingBackwardsCompatibility.sol b/packages/horizon/contracts/interfaces/IStakingBackwardsCompatibility.sol similarity index 100% rename from packages/horizon/contracts/IStakingBackwardsCompatibility.sol rename to packages/horizon/contracts/interfaces/IStakingBackwardsCompatibility.sol diff --git a/packages/subgraph-service/contracts/interfaces/ITAPVerifier.sol b/packages/horizon/contracts/interfaces/ITAPVerifier.sol similarity index 100% rename from packages/subgraph-service/contracts/interfaces/ITAPVerifier.sol rename to packages/horizon/contracts/interfaces/ITAPVerifier.sol diff --git a/packages/subgraph-service/contracts/data-service/libraries/Denominations.sol b/packages/horizon/contracts/libraries/Denominations.sol similarity index 100% rename from packages/subgraph-service/contracts/data-service/libraries/Denominations.sol rename to packages/horizon/contracts/libraries/Denominations.sol diff --git a/packages/horizon/contracts/utils/LibFixedMath.sol b/packages/horizon/contracts/libraries/LibFixedMath.sol similarity index 100% rename from packages/horizon/contracts/utils/LibFixedMath.sol rename to packages/horizon/contracts/libraries/LibFixedMath.sol diff --git a/packages/horizon/contracts/utils/MathUtils.sol b/packages/horizon/contracts/libraries/MathUtils.sol similarity index 100% rename from packages/horizon/contracts/utils/MathUtils.sol rename to packages/horizon/contracts/libraries/MathUtils.sol diff --git a/packages/subgraph-service/contracts/data-service/libraries/PPMMath.sol b/packages/horizon/contracts/libraries/PPMMath.sol similarity index 100% rename from packages/subgraph-service/contracts/data-service/libraries/PPMMath.sol rename to packages/horizon/contracts/libraries/PPMMath.sol diff --git a/packages/horizon/contracts/utils/TokenUtils.sol b/packages/horizon/contracts/libraries/TokenUtils.sol similarity index 96% rename from packages/horizon/contracts/utils/TokenUtils.sol rename to packages/horizon/contracts/libraries/TokenUtils.sol index 7bfc7203c..07b267451 100644 --- a/packages/horizon/contracts/utils/TokenUtils.sol +++ b/packages/horizon/contracts/libraries/TokenUtils.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.24; -import { IGraphToken } from "../IGraphToken.sol"; +import { IGraphToken } from "../interfaces/IGraphToken.sol"; /** * @title TokenUtils library diff --git a/packages/subgraph-service/contracts/data-service/libraries/UintRange.sol b/packages/horizon/contracts/libraries/UintRange.sol similarity index 100% rename from packages/subgraph-service/contracts/data-service/libraries/UintRange.sol rename to packages/horizon/contracts/libraries/UintRange.sol diff --git a/packages/subgraph-service/contracts/TAPVerifier.sol b/packages/horizon/contracts/payments/collectors/TAPVerifier.sol similarity index 99% rename from packages/subgraph-service/contracts/TAPVerifier.sol rename to packages/horizon/contracts/payments/collectors/TAPVerifier.sol index e7b3d5a7f..735cc38a0 100644 --- a/packages/subgraph-service/contracts/TAPVerifier.sol +++ b/packages/horizon/contracts/payments/collectors/TAPVerifier.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { ITAPVerifier } from "./interfaces/ITAPVerifier.sol"; +import { ITAPVerifier } from "../../interfaces/ITAPVerifier.sol"; import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; diff --git a/packages/horizon/contracts/HorizonStaking.sol b/packages/horizon/contracts/staking/HorizonStaking.sol similarity index 99% rename from packages/horizon/contracts/HorizonStaking.sol rename to packages/horizon/contracts/staking/HorizonStaking.sol index 7b97260be..883e1f611 100644 --- a/packages/horizon/contracts/HorizonStaking.sol +++ b/packages/horizon/contracts/staking/HorizonStaking.sol @@ -3,12 +3,13 @@ pragma solidity 0.8.24; import { GraphUpgradeable } from "@graphprotocol/contracts/contracts/upgrades/GraphUpgradeable.sol"; +import { IHorizonStakingBase } from "../interfaces/IHorizonStakingBase.sol"; +import { IGraphToken } from "../interfaces/IGraphToken.sol"; -import { IHorizonStakingBase } from "./IHorizonStakingBase.sol"; -import { TokenUtils } from "./utils/TokenUtils.sol"; -import { MathUtils } from "./utils/MathUtils.sol"; -import { Managed } from "./Managed.sol"; -import { IGraphToken } from "./IGraphToken.sol"; +import { TokenUtils } from "../libraries/TokenUtils.sol"; +import { MathUtils } from "../libraries/MathUtils.sol"; + +import { Managed } from "./utilities/Managed.sol"; import { HorizonStakingV1Storage } from "./HorizonStakingStorage.sol"; /** diff --git a/packages/horizon/contracts/HorizonStakingExtension.sol b/packages/horizon/contracts/staking/HorizonStakingExtension.sol similarity index 97% rename from packages/horizon/contracts/HorizonStakingExtension.sol rename to packages/horizon/contracts/staking/HorizonStakingExtension.sol index 1ec8b2c45..0183e73f9 100644 --- a/packages/horizon/contracts/HorizonStakingExtension.sol +++ b/packages/horizon/contracts/staking/HorizonStakingExtension.sol @@ -2,11 +2,13 @@ pragma solidity 0.8.24; -import { StakingBackwardsCompatibility } from "./StakingBackwardsCompatibility.sol"; import { IL2StakingBase } from "@graphprotocol/contracts/contracts/l2/staking/IL2StakingBase.sol"; import { IL2StakingTypes } from "@graphprotocol/contracts/contracts/l2/staking/IL2StakingTypes.sol"; -import { IHorizonStakingExtension } from "./IHorizonStakingExtension.sol"; -import { MathUtils } from "./utils/MathUtils.sol"; +import { IHorizonStakingExtension } from "../interfaces/IHorizonStakingExtension.sol"; + +import { MathUtils } from "../libraries/MathUtils.sol"; + +import { StakingBackwardsCompatibility } from "./StakingBackwardsCompatibility.sol"; /** * @title L2Staking contract @@ -28,9 +30,8 @@ contract HorizonStakingExtension is StakingBackwardsCompatibility, IHorizonStaki constructor( address _controller, - address _subgraphDataServiceAddress, - address _exponentialRebates - ) StakingBackwardsCompatibility(_controller, _subgraphDataServiceAddress, _exponentialRebates) {} + address _subgraphDataServiceAddress + ) StakingBackwardsCompatibility(_controller, _subgraphDataServiceAddress) {} /** * @notice Receive ETH into the Staking contract: this will always revert diff --git a/packages/horizon/contracts/HorizonStakingStorage.sol b/packages/horizon/contracts/staking/HorizonStakingStorage.sol similarity index 96% rename from packages/horizon/contracts/HorizonStakingStorage.sol rename to packages/horizon/contracts/staking/HorizonStakingStorage.sol index 6506429a7..80e25f6ae 100644 --- a/packages/horizon/contracts/HorizonStakingStorage.sol +++ b/packages/horizon/contracts/staking/HorizonStakingStorage.sol @@ -2,9 +2,10 @@ pragma solidity 0.8.24; -import { Managed } from "./Managed.sol"; -import { IStakingBackwardsCompatibility } from "./IStakingBackwardsCompatibility.sol"; -import { IHorizonStakingTypes } from "./IHorizonStakingTypes.sol"; +import { IStakingBackwardsCompatibility } from "../interfaces/IStakingBackwardsCompatibility.sol"; +import { IHorizonStakingTypes } from "../interfaces/IHorizonStakingTypes.sol"; + +import { Managed } from "./utilities/Managed.sol"; /** * @title HorizonStakingV1Storage diff --git a/packages/horizon/contracts/StakingBackwardsCompatibility.sol b/packages/horizon/contracts/staking/StakingBackwardsCompatibility.sol similarity index 96% rename from packages/horizon/contracts/StakingBackwardsCompatibility.sol rename to packages/horizon/contracts/staking/StakingBackwardsCompatibility.sol index 6e6261bd4..0d8c2749e 100644 --- a/packages/horizon/contracts/StakingBackwardsCompatibility.sol +++ b/packages/horizon/contracts/staking/StakingBackwardsCompatibility.sol @@ -2,20 +2,20 @@ pragma solidity 0.8.24; -import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; +import { ICuration } from "@graphprotocol/contracts/contracts/curation/ICuration.sol"; +import { IRewardsManager } from "@graphprotocol/contracts/contracts/rewards/IRewardsManager.sol"; +import { IEpochManager } from "@graphprotocol/contracts/contracts/epochs/IEpochManager.sol"; +import { IGraphToken } from "../interfaces/IGraphToken.sol"; +import { IStakingBackwardsCompatibility } from "../interfaces/IStakingBackwardsCompatibility.sol"; + +import { TokenUtils } from "../libraries/TokenUtils.sol"; +import { MathUtils } from "../libraries/MathUtils.sol"; +import { ExponentialRebates } from "./libraries/ExponentialRebates.sol"; import { Multicall } from "@graphprotocol/contracts/contracts/base/Multicall.sol"; import { GraphUpgradeable } from "@graphprotocol/contracts/contracts/upgrades/GraphUpgradeable.sol"; -import { TokenUtils } from "./utils/TokenUtils.sol"; -import { IGraphToken } from "./IGraphToken.sol"; +import { Managed } from "./utilities/Managed.sol"; import { HorizonStakingV1Storage } from "./HorizonStakingStorage.sol"; -import { MathUtils } from "./utils/MathUtils.sol"; -import { Managed } from "./Managed.sol"; -import { ICuration } from "@graphprotocol/contracts/contracts/curation/ICuration.sol"; -import { IRewardsManager } from "@graphprotocol/contracts/contracts/rewards/IRewardsManager.sol"; -import { IEpochManager } from "@graphprotocol/contracts/contracts/epochs/IEpochManager.sol"; -import { ExponentialRebates } from "./utils/ExponentialRebates.sol"; -import { IStakingBackwardsCompatibility } from "./IStakingBackwardsCompatibility.sol"; /** * @title Base Staking contract @@ -38,15 +38,8 @@ abstract contract StakingBackwardsCompatibility is address public immutable SUBGRAPH_DATA_SERVICE_ADDRESS; - address public immutable EXPONENTIAL_REBATES_ADDRESS; - - constructor( - address _controller, - address _subgraphDataServiceAddress, - address _exponentialRebatesAddress - ) Managed(_controller) { + constructor(address _controller, address _subgraphDataServiceAddress) Managed(_controller) { SUBGRAPH_DATA_SERVICE_ADDRESS = _subgraphDataServiceAddress; - EXPONENTIAL_REBATES_ADDRESS = _exponentialRebatesAddress; } /** @@ -128,7 +121,7 @@ abstract contract StakingBackwardsCompatibility is // No rebates if indexer has no stake or if lambda is zero uint256 newRebates = (alloc.tokens == 0 || __DEPRECATED_lambdaNumerator == 0) ? 0 - : ExponentialRebates(EXPONENTIAL_REBATES_ADDRESS).exponentialRebates( + : ExponentialRebates.exponentialRebates( alloc.collectedFees, alloc.tokens, __DEPRECATED_alphaNumerator, diff --git a/packages/horizon/contracts/utils/ExponentialRebates.sol b/packages/horizon/contracts/staking/libraries/ExponentialRebates.sol similarity index 96% rename from packages/horizon/contracts/utils/ExponentialRebates.sol rename to packages/horizon/contracts/staking/libraries/ExponentialRebates.sol index d53efdca3..50579cafb 100644 --- a/packages/horizon/contracts/utils/ExponentialRebates.sol +++ b/packages/horizon/contracts/staking/libraries/ExponentialRebates.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.24; -import { LibFixedMath } from "./LibFixedMath.sol"; +import { LibFixedMath } from "../../libraries/LibFixedMath.sol"; /** * @title ExponentialRebates contract @@ -10,7 +10,7 @@ import { LibFixedMath } from "./LibFixedMath.sol"; * @dev This is only used for backwards compatibility in HorizonStaking, and should * be removed after the transition period. */ -contract ExponentialRebates { +library ExponentialRebates { /// @dev Maximum value of the exponent for which to compute the exponential before clamping to zero. uint32 private constant MAX_EXPONENT = 15; diff --git a/packages/horizon/contracts/Managed.sol b/packages/horizon/contracts/staking/utilities/Managed.sol similarity index 96% rename from packages/horizon/contracts/Managed.sol rename to packages/horizon/contracts/staking/utilities/Managed.sol index 858156bbd..685c18184 100644 --- a/packages/horizon/contracts/Managed.sol +++ b/packages/horizon/contracts/staking/utilities/Managed.sol @@ -3,8 +3,9 @@ pragma solidity 0.8.24; import { IController } from "@graphprotocol/contracts/contracts/governance/IController.sol"; -import { IManaged } from "./IManaged.sol"; -import { GraphDirectory } from "./GraphDirectory.sol"; +import { IManaged } from "../../interfaces/IManaged.sol"; + +import { GraphDirectory } from "../../GraphDirectory.sol"; /** * @title Graph Managed contract diff --git a/packages/horizon/scripts/deploy.ts b/packages/horizon/scripts/deploy.ts deleted file mode 100644 index cf87ff10f..000000000 --- a/packages/horizon/scripts/deploy.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { ethers } from 'hardhat' - -async function main() { - const currentTimestampInSeconds = Math.round(Date.now() / 1000) - const unlockTime = currentTimestampInSeconds + 60 - - const lockedAmount = ethers.parseEther('0.001') - const a = 1 - console.log(a) - const lock = await ethers.deployContract('Lock', [unlockTime], { - value: lockedAmount, - }) - - await lock.waitForDeployment() - - console.log( - `Lock with ${ethers.formatEther( - lockedAmount, - )}ETH and unlock timestamp ${unlockTime} deployed to ${typeof lock.target == 'string' ? lock.target : ''}`, - ) -} - -// We recommend this pattern to be able to use async/await everywhere -// and properly handle errors. -main().catch((error) => { - console.error(error) - process.exitCode = 1 -}) diff --git a/packages/horizon/test/HorizonStaking.t.sol b/packages/horizon/test/HorizonStaking.t.sol index 144b0c7a5..55088f0fe 100644 --- a/packages/horizon/test/HorizonStaking.t.sol +++ b/packages/horizon/test/HorizonStaking.t.sol @@ -3,14 +3,13 @@ pragma solidity 0.8.24; import "forge-std/Test.sol"; import "forge-std/console.sol"; -import { HorizonStaking } from "../contracts/HorizonStaking.sol"; +import { HorizonStaking } from "../contracts/staking/HorizonStaking.sol"; import { ControllerMock } from "../contracts/mocks/ControllerMock.sol"; -import { HorizonStakingExtension } from "../contracts/HorizonStakingExtension.sol"; -import { ExponentialRebates } from "../contracts/utils/ExponentialRebates.sol"; -import { IHorizonStaking } from "../contracts/IHorizonStaking.sol"; +import { HorizonStakingExtension } from "../contracts/staking/HorizonStakingExtension.sol"; +import { ExponentialRebates } from "../contracts/staking/libraries/ExponentialRebates.sol"; +import { IHorizonStaking } from "../contracts/interfaces/IHorizonStaking.sol"; contract HorizonStakingTest is Test { - ExponentialRebates rebates; HorizonStakingExtension ext; IHorizonStaking staking; ControllerMock controller; @@ -19,8 +18,7 @@ contract HorizonStakingTest is Test { console.log("Deploying Controller mock"); controller = new ControllerMock(address(0x1)); console.log("Deploying HorizonStaking"); - rebates = new ExponentialRebates(); - ext = new HorizonStakingExtension(address(controller), address(0x1), address(rebates)); + ext = new HorizonStakingExtension(address(controller), address(0x1)); staking = IHorizonStaking(address(new HorizonStaking(address(controller), address(ext), address(0x1)))); } diff --git a/packages/horizon/test/HorizonStaking.ts b/packages/horizon/test/HorizonStaking.ts index 6f6e1ad88..28eb281f7 100644 --- a/packages/horizon/test/HorizonStaking.ts +++ b/packages/horizon/test/HorizonStaking.ts @@ -16,8 +16,8 @@ describe('HorizonStaking', function () { const ExponentialRebates = await ethers.getContractFactory('ExponentialRebates') const exponentialRebates = await ExponentialRebates.deploy() await exponentialRebates.waitForDeployment() - const HorizonStakingExtension = await ethers.getContractFactory('HorizonStakingExtension') - const horizonStakingExtension = await HorizonStakingExtension.deploy(controller.target, ZeroAddress, exponentialRebates.target) + const HorizonStakingExtension = await ethers.getContractFactory('HorizonStakingExtension', { libraries: { ExponentialRebates: exponentialRebates.target } }) + const horizonStakingExtension = await HorizonStakingExtension.deploy(controller.target, ZeroAddress) await horizonStakingExtension.waitForDeployment() const HorizonStaking = await ethers.getContractFactory('HorizonStaking') const horizonStakingContract = await HorizonStaking.deploy(controller.target, horizonStakingExtension.target, ZeroAddress) diff --git a/packages/horizon/test/SimpleTest.t.sol b/packages/horizon/test/SimpleTest.t.sol deleted file mode 100644 index b130e5d34..000000000 --- a/packages/horizon/test/SimpleTest.t.sol +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity 0.8.10; - -import "forge-std/Test.sol"; -import { SimpleTest } from "../contracts/SimpleTest.sol"; - -contract ContractTest is Test { - SimpleTest simpleTest; - - function setUp() public { - simpleTest = new SimpleTest(); - } - - function test_NumberIs42() public { - assertEq(simpleTest.test(), 42); - } -} diff --git a/packages/horizon/test/SimpleTest.ts b/packages/horizon/test/SimpleTest.ts deleted file mode 100644 index cfcfb1443..000000000 --- a/packages/horizon/test/SimpleTest.ts +++ /dev/null @@ -1,23 +0,0 @@ -import hardhat from 'hardhat' - -import { expect } from 'chai' -import { loadFixture } from '@nomicfoundation/hardhat-toolbox/network-helpers' - -const ethers = hardhat.ethers - -describe('SimpleTest', function () { - async function deployFixture() { - const [owner] = await ethers.getSigners() - const SimpleTest = await ethers.getContractFactory('SimpleTest') - const simpleTest = await SimpleTest.deploy() - return { simpleTest, owner } - } - - describe('Deployment', function () { - it('Should return 42', async function () { - const { simpleTest } = await loadFixture(deployFixture) - - expect(await simpleTest.test()).to.equal(42) - }) - }) -}) diff --git a/packages/subgraph-service/contracts/DisputeManager.sol b/packages/subgraph-service/contracts/DisputeManager.sol index dc5f785f2..e74ba0f0b 100644 --- a/packages/subgraph-service/contracts/DisputeManager.sol +++ b/packages/subgraph-service/contracts/DisputeManager.sol @@ -2,19 +2,19 @@ pragma solidity ^0.8.24; pragma abicoder v2; -import { IHorizonStaking } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol"; +import { IHorizonStaking } from "@graphprotocol/horizon/contracts/interfaces/IHorizonStaking.sol"; import { IDisputeManager } from "./interfaces/IDisputeManager.sol"; import { ISubgraphService } from "./interfaces/ISubgraphService.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { DisputeManagerV1Storage } from "./DisputeManagerStorage.sol"; -import { GraphDirectory } from "./data-service/GraphDirectory.sol"; +import { GraphDirectory } from "@graphprotocol/horizon/contracts/data-service/GraphDirectory.sol"; import { AttestationManager } from "./utilities/AttestationManager.sol"; import { Math } from "@openzeppelin/contracts/utils/math/Math.sol"; import { TokenUtils } from "@graphprotocol/contracts/contracts/utils/TokenUtils.sol"; +import { PPMMath } from "@graphprotocol/horizon/contracts/libraries/PPMMath.sol"; import { Allocation } from "./libraries/Allocation.sol"; -import { PPMMath } from "./data-service/libraries/PPMMath.sol"; import { Attestation } from "./libraries/Attestation.sol"; /* @@ -670,7 +670,11 @@ contract DisputeManager is Ownable, GraphDirectory, AttestationManager, DisputeM function _slashIndexer(address _indexer, uint256 _slashAmount) private returns (uint256 rewardsAmount) { // Get slashable amount for indexer IHorizonStaking.Provision memory provision = GRAPH_STAKING.getProvision(_indexer, address(subgraphService)); - uint256 totalProvisionTokens = provision.tokens + provision.delegatedTokens; // slashable tokens + IHorizonStaking.DelegationPool memory pool = GRAPH_STAKING.getDelegationPool( + _indexer, + address(subgraphService) + ); + uint256 totalProvisionTokens = provision.tokens + pool.tokens; // slashable tokens // Get slash amount uint256 maxSlashAmount = uint256(maxSlashingPercentage).mulPPM(totalProvisionTokens); diff --git a/packages/subgraph-service/contracts/SubgraphService.sol b/packages/subgraph-service/contracts/SubgraphService.sol index 9489373ab..896314bf8 100644 --- a/packages/subgraph-service/contracts/SubgraphService.sol +++ b/packages/subgraph-service/contracts/SubgraphService.sol @@ -1,20 +1,20 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IGraphPayments } from "./interfaces/IGraphPayments.sol"; +import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol"; +import { ITAPVerifier } from "@graphprotocol/horizon/contracts/interfaces/ITAPVerifier.sol"; import { ISubgraphService } from "./interfaces/ISubgraphService.sol"; -import { ITAPVerifier } from "./interfaces/ITAPVerifier.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; -import { DataService } from "./data-service/DataService.sol"; -import { DataServicePausable } from "./data-service/extensions/DataServicePausable.sol"; -import { DataServiceRescuable } from "./data-service/extensions/DataServiceRescuable.sol"; -import { DataServiceFees } from "./data-service/extensions/DataServiceFees.sol"; +import { DataServicePausable } from "@graphprotocol/horizon/contracts/data-service/extensions/DataServicePausable.sol"; +import { DataService } from "@graphprotocol/horizon/contracts/data-service/DataService.sol"; +import { DataServiceRescuable } from "@graphprotocol/horizon/contracts/data-service/extensions/DataServiceRescuable.sol"; +import { DataServiceFees } from "@graphprotocol/horizon/contracts/data-service/extensions/DataServiceFees.sol"; import { Directory } from "./utilities/Directory.sol"; import { AllocationManager } from "./utilities/AllocationManager.sol"; import { SubgraphServiceV1Storage } from "./SubgraphServiceStorage.sol"; -import { PPMMath } from "./data-service/libraries/PPMMath.sol"; +import { PPMMath } from "@graphprotocol/horizon/contracts/libraries/PPMMath.sol"; import { Allocation } from "./libraries/Allocation.sol"; import { LegacyAllocation } from "./libraries/LegacyAllocation.sol"; @@ -111,7 +111,7 @@ contract SubgraphService is data, (bytes32, uint256, address, bytes) ); - _allocate(indexer, allocationId, subgraphDeploymentId, tokens, allocationProof); + _allocate(indexer, allocationId, subgraphDeploymentId, tokens, allocationProof, delegationRatio); emit ServiceStarted(indexer); } @@ -138,7 +138,7 @@ contract SubgraphService is address allocationId, uint256 tokens ) external onlyProvisionAuthorized(indexer) onlyRegisteredIndexer(indexer) whenNotPaused { - _resizeAllocation(allocationId, tokens); + _resizeAllocation(allocationId, tokens, delegationRatio); } // TODO: Does this design allow custom payment types?! @@ -184,8 +184,8 @@ contract SubgraphService is return legacyAllocations[allocationId]; } - function encodeAllocationProof(address _indexer, address _allocationId) external view returns (bytes32) { - return _encodeAllocationProof(_indexer, _allocationId); + function encodeAllocationProof(address indexer, address allocationId) external view returns (bytes32) { + return _encodeAllocationProof(indexer, allocationId); } // -- Data service parameter getters -- diff --git a/packages/subgraph-service/contracts/SubgraphServiceStorage.sol b/packages/subgraph-service/contracts/SubgraphServiceStorage.sol index 27ebc13ff..c67702428 100644 --- a/packages/subgraph-service/contracts/SubgraphServiceStorage.sol +++ b/packages/subgraph-service/contracts/SubgraphServiceStorage.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; +import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol"; import { ISubgraphService } from "./interfaces/ISubgraphService.sol"; -import { IGraphPayments } from "./interfaces/IGraphPayments.sol"; abstract contract SubgraphServiceV1Storage { /// @notice Service providers registered in the data service diff --git a/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol b/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol index ab62a3d84..17dd7019c 100644 --- a/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol +++ b/packages/subgraph-service/contracts/interfaces/ISubgraphService.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IDataServiceFees } from "../data-service/extensions/IDataServiceFees.sol"; +import { IDataServiceFees } from "@graphprotocol/horizon/contracts/data-service/extensions/IDataServiceFees.sol"; import { Allocation } from "../libraries/Allocation.sol"; import { LegacyAllocation } from "../libraries/LegacyAllocation.sol"; @@ -28,5 +28,5 @@ interface ISubgraphService is IDataServiceFees { function getLegacyAllocation(address allocationId) external view returns (LegacyAllocation.State memory); - function encodeAllocationProof(address _indexer, address _allocationId) external view returns (bytes32); + function encodeAllocationProof(address indexer, address allocationId) external view returns (bytes32); } diff --git a/packages/subgraph-service/contracts/utilities/AllocationManager.sol b/packages/subgraph-service/contracts/utilities/AllocationManager.sol index bcd7f1097..3e43fc0fb 100644 --- a/packages/subgraph-service/contracts/utilities/AllocationManager.sol +++ b/packages/subgraph-service/contracts/utilities/AllocationManager.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { IGraphPayments } from "../interfaces/IGraphPayments.sol"; +import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol"; -import { GraphDirectory } from "../data-service/GraphDirectory.sol"; +import { GraphDirectory } from "@graphprotocol/horizon/contracts/data-service/GraphDirectory.sol"; import { AllocationManagerV1Storage } from "./AllocationManagerStorage.sol"; import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; import { Allocation } from "../libraries/Allocation.sol"; import { LegacyAllocation } from "../libraries/LegacyAllocation.sol"; -import { PPMMath } from "../data-service/libraries/PPMMath.sol"; -import { ProvisionTracker } from "../data-service/libraries/ProvisionTracker.sol"; +import { PPMMath } from "@graphprotocol/horizon/contracts/libraries/PPMMath.sol"; +import { ProvisionTracker } from "@graphprotocol/horizon/contracts/data-service/libraries/ProvisionTracker.sol"; abstract contract AllocationManager is EIP712, GraphDirectory, AllocationManagerV1Storage { using ProvisionTracker for mapping(address => uint256); @@ -89,7 +89,8 @@ abstract contract AllocationManager is EIP712, GraphDirectory, AllocationManager address _allocationId, bytes32 _subgraphDeploymentId, uint256 _tokens, - bytes memory _allocationProof + bytes memory _allocationProof, + uint32 __delegationRatio ) internal returns (Allocation.State memory) { if (_allocationId == address(0)) revert AllocationManagerInvalidAllocationId(); @@ -108,7 +109,7 @@ abstract contract AllocationManager is EIP712, GraphDirectory, AllocationManager ); // Check that the indexer has enough tokens available - allocationProvisionTracker.lock(GRAPH_STAKING, _indexer, _tokens); + allocationProvisionTracker.lock(GRAPH_STAKING, _indexer, _tokens, delegationRatio); // Update total allocated tokens for the subgraph deployment subgraphAllocatedTokens[allocation.subgraphDeploymentId] = @@ -146,13 +147,14 @@ abstract contract AllocationManager is EIP712, GraphDirectory, AllocationManager // Distribute rewards to delegators // TODO: remove the uint8 cast when PRs are merged - uint256 delegatorCut = GRAPH_STAKING.getDelegationCut( + uint256 delegatorCut = GRAPH_STAKING.getDelegationFeeCut( allocation.indexer, + address(this), uint8(IGraphPayments.PaymentTypes.IndexingFee) ); uint256 tokensDelegationRewards = tokensRewards.mulPPM(delegatorCut); GRAPH_TOKEN.approve(address(GRAPH_STAKING), tokensDelegationRewards); - GRAPH_STAKING.addToDelegationPool(allocation.indexer, tokensDelegationRewards); + GRAPH_STAKING.addToDelegationPool(allocation.indexer, address(this), tokensDelegationRewards); // Distribute rewards to indexer uint256 tokensIndexerRewards = tokensRewards - tokensDelegationRewards; @@ -177,7 +179,11 @@ abstract contract AllocationManager is EIP712, GraphDirectory, AllocationManager return tokensRewards; } - function _resizeAllocation(address _allocationId, uint256 _tokens) internal returns (Allocation.State memory) { + function _resizeAllocation( + address _allocationId, + uint256 _tokens, + uint3 _ _delegationRatio + ) internal returns (Allocation.State memory) { Allocation.State memory allocation = allocations.get(_allocationId); // Exit early if the allocation size is the same @@ -188,7 +194,7 @@ abstract contract AllocationManager is EIP712, GraphDirectory, AllocationManager // Update provision tracker uint256 oldTokens = allocation.tokens; if (_tokens > oldTokens) { - allocationProvisionTracker.lock(GRAPH_STAKING, allocation.indexer, _tokens - oldTokens); + allocationProvisionTracker.lock(GRAPH_STAKING, allocation.indexer, _tokens - oldTokens, delegationRatio); } else { allocationProvisionTracker.release(allocation.indexer, oldTokens - _tokens); } diff --git a/packages/subgraph-service/contracts/utilities/Directory.sol b/packages/subgraph-service/contracts/utilities/Directory.sol index cd87de102..bc452f072 100644 --- a/packages/subgraph-service/contracts/utilities/Directory.sol +++ b/packages/subgraph-service/contracts/utilities/Directory.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later pragma solidity ^0.8.24; -import { ITAPVerifier } from "../interfaces/ITAPVerifier.sol"; +import { ITAPVerifier } from "@graphprotocol/horizon/contracts/interfaces/ITAPVerifier.sol"; import { IDisputeManager } from "../interfaces/IDisputeManager.sol"; import { ISubgraphService } from "../interfaces/ISubgraphService.sol"; import { ICuration } from "@graphprotocol/contracts/contracts/curation/ICuration.sol"; diff --git a/packages/subgraph-service/package.json b/packages/subgraph-service/package.json index 144263417..8ad66358e 100644 --- a/packages/subgraph-service/package.json +++ b/packages/subgraph-service/package.json @@ -14,6 +14,7 @@ }, "devDependencies": { "@graphprotocol/contracts": "workspace:^7.0.0", + "@graphprotocol/horizon": "workspace:^0.0.1", "@nomicfoundation/hardhat-chai-matchers": "^2.0.0", "@nomicfoundation/hardhat-ethers": "^3.0.0", "@nomicfoundation/hardhat-foundry": "^1.1.1", diff --git a/packages/subgraph-service/remappings.txt b/packages/subgraph-service/remappings.txt index 1bd6482cd..d9bed44ec 100644 --- a/packages/subgraph-service/remappings.txt +++ b/packages/subgraph-service/remappings.txt @@ -1,4 +1,5 @@ @graphprotocol/contracts/=node_modules/@graphprotocol/contracts/ +@graphprotocol/horizon/=node_modules/@graphprotocol/horizon/ forge-std/=lib/forge-std/src/ ds-test/=lib/forge-std/lib/ds-test/src/ eth-gas-reporter/=node_modules/eth-gas-reporter/ diff --git a/packages/subgraph-service/test/mocks/MockHorizonStaking.sol b/packages/subgraph-service/test/mocks/MockHorizonStaking.sol index bd67a980c..b8f722bcf 100644 --- a/packages/subgraph-service/test/mocks/MockHorizonStaking.sol +++ b/packages/subgraph-service/test/mocks/MockHorizonStaking.sol @@ -3,10 +3,11 @@ pragma solidity ^0.8.24; import "forge-std/Test.sol"; -import { IHorizonStaking } from "@graphprotocol/contracts/contracts/staking/IHorizonStaking.sol"; +import { IHorizonStaking } from "@graphprotocol/horizon/contracts/interfaces/IHorizonStaking.sol"; +import { IHorizonStakingTypes } from "@graphprotocol/horizon/contracts/interfaces/IHorizonStakingTypes.sol"; import { MockGRTToken } from "./MockGRTToken.sol"; -contract MockHorizonStaking is IHorizonStaking { +contract MockHorizonStaking { mapping (address verifier => mapping (address serviceProvider => IHorizonStaking.Provision provision)) public _provisions; MockGRTToken public grtToken; @@ -22,15 +23,18 @@ contract MockHorizonStaking is IHorizonStaking { // create a provision function provision(uint256 tokens, address verifier, uint32 maxVerifierCut, uint64 thawingPeriod) external { - IHorizonStaking.Provision memory newProvision = IHorizonStaking.Provision({ - serviceProvider: msg.sender, + IHorizonStaking.Provision memory newProvision = IHorizonStakingTypes.Provision({ tokens: tokens, - delegatedTokens: 0, tokensThawing: 0, - createdAt: uint64(block.timestamp), - verifier: verifier, + sharesThawing: 0, maxVerifierCut: maxVerifierCut, - thawingPeriod: thawingPeriod + thawingPeriod: thawingPeriod, + createdAt: uint64(block.timestamp), + firstThawRequestId: bytes32(0), + lastThawRequestId: bytes32(0), + nThawRequests: 0, + maxVerifierCutPending: maxVerifierCut, + thawingPeriodPending: thawingPeriod }); _provisions[verifier][msg.sender] = newProvision; } @@ -86,9 +90,9 @@ contract MockHorizonStaking is IHorizonStaking { return _provisions[verifier][serviceProvider].tokens; } - function getServiceProvider(address serviceProvider) external view returns (ServiceProvider memory) {} + function getServiceProvider(address serviceProvider) external view returns (IHorizonStaking.ServiceProvider memory) {} - function getProvision(address serviceProvider, address verifier) external view returns (Provision memory) { + function getProvision(address serviceProvider, address verifier) external view returns (IHorizonStaking.Provision memory) { return _provisions[verifier][serviceProvider]; } diff --git a/yarn.lock b/yarn.lock index bed525f83..c105ba53f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2909,7 +2909,7 @@ __metadata: languageName: unknown linkType: soft -"@graphprotocol/horizon@workspace:packages/horizon": +"@graphprotocol/horizon@workspace:^0.0.1, @graphprotocol/horizon@workspace:packages/horizon": version: 0.0.0-use.local resolution: "@graphprotocol/horizon@workspace:packages/horizon" dependencies: @@ -2999,6 +2999,7 @@ __metadata: resolution: "@graphprotocol/subgraph-service@workspace:packages/subgraph-service" dependencies: "@graphprotocol/contracts": "workspace:^7.0.0" + "@graphprotocol/horizon": "workspace:^0.0.1" "@nomicfoundation/hardhat-chai-matchers": "npm:^2.0.0" "@nomicfoundation/hardhat-ethers": "npm:^3.0.0" "@nomicfoundation/hardhat-foundry": "npm:^1.1.1"