diff --git a/packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol b/packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol index 6252f63fa..5b47de961 100644 --- a/packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol +++ b/packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol @@ -774,12 +774,12 @@ interface IHorizonStakingMain { * @param beneficiary The address where the tokens will be withdrawn after thawing * @return The ID of the thaw request */ - // function undelegateWithBeneficiary( - // address serviceProvider, - // address verifier, - // uint256 shares, - // address beneficiary - // ) external returns (bytes32); + function undelegateWithBeneficiary( + address serviceProvider, + address verifier, + uint256 shares, + address beneficiary + ) external returns (bytes32); /** * @notice Withdraw undelegated tokens from a provision after thawing. @@ -815,11 +815,11 @@ interface IHorizonStakingMain { * @param verifier The verifier address * @param nThawRequests The number of thaw requests to fulfill. Set to 0 to fulfill all thaw requests. */ - // function withdrawDelegatedWithBeneficiary( - // address serviceProvider, - // address verifier, - // uint256 nThawRequests - // ) external; + function withdrawDelegatedWithBeneficiary( + address serviceProvider, + address verifier, + uint256 nThawRequests + ) external; /** * @notice Re-delegate undelegated tokens from a provision after thawing to a `newServiceProvider` and `newVerifier`. @@ -864,26 +864,6 @@ interface IHorizonStakingMain { uint256 feeCut ) external; - /** - * @notice Delegate tokens to the subgraph data service provision. - * This function is for backwards compatibility with the legacy staking contract. - * 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 - */ - function delegate(address serviceProvider, uint256 tokens) external; - - /** - * @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 undelegating from the subgraph data service. - * @dev See {undelegate}. - * @param serviceProvider The service provider address - * @param shares The amount of shares to undelegate - */ - function undelegate(address serviceProvider, uint256 shares) external; - /** * @notice Withdraw undelegated tokens from the subgraph data service provision after thawing. * This function is for backwards compatibility with the legacy staking contract. diff --git a/packages/horizon/contracts/staking/HorizonStaking.sol b/packages/horizon/contracts/staking/HorizonStaking.sol index 97fb30ca9..d565d7ef5 100644 --- a/packages/horizon/contracts/staking/HorizonStaking.sol +++ b/packages/horizon/contracts/staking/HorizonStaking.sol @@ -310,15 +310,15 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain { /** * @notice See {IHorizonStakingMain-undelegate}. */ - // function undelegateWithBeneficiary( - // address serviceProvider, - // address verifier, - // uint256 shares, - // address beneficiary - // ) external override notPaused returns (bytes32) { - // require(beneficiary != address(0), HorizonStakingInvalidBeneficiaryZeroAddress()); - // return _undelegate(ThawRequestType.DelegationWithBeneficiary, serviceProvider, verifier, shares, beneficiary); - // } + function undelegateWithBeneficiary( + address serviceProvider, + address verifier, + uint256 shares, + address beneficiary + ) external override notPaused returns (bytes32) { + require(beneficiary != address(0), HorizonStakingInvalidBeneficiaryZeroAddress()); + return _undelegate(ThawRequestType.DelegationWithBeneficiary, serviceProvider, verifier, shares, beneficiary); + } /** * @notice See {IHorizonStakingMain-withdrawDelegated}. @@ -342,21 +342,21 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain { /** * @notice See {IHorizonStakingMain-withdrawDelegatedWithBeneficiary}. */ - // function withdrawDelegatedWithBeneficiary( - // address serviceProvider, - // address verifier, - // uint256 nThawRequests - // ) external override notPaused { - // _withdrawDelegated( - // ThawRequestType.DelegationWithBeneficiary, - // serviceProvider, - // verifier, - // address(0), - // address(0), - // 0, - // nThawRequests - // ); - // } + function withdrawDelegatedWithBeneficiary( + address serviceProvider, + address verifier, + uint256 nThawRequests + ) external override notPaused { + _withdrawDelegated( + ThawRequestType.DelegationWithBeneficiary, + serviceProvider, + verifier, + address(0), + address(0), + 0, + nThawRequests + ); + } /** * @notice See {IHorizonStakingMain-redelegate}. @@ -396,22 +396,6 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain { emit DelegationFeeCutSet(serviceProvider, verifier, paymentType, feeCut); } - /** - * @notice See {IHorizonStakingMain-delegate}. - */ - function delegate(address serviceProvider, uint256 tokens) external override notPaused { - require(tokens != 0, HorizonStakingInvalidZeroTokens()); - _graphToken().pullTokens(msg.sender, tokens); - _delegate(serviceProvider, SUBGRAPH_DATA_SERVICE_ADDRESS, tokens, 0); - } - - /** - * @notice See {IHorizonStakingMain-undelegate}. - */ - function undelegate(address serviceProvider, uint256 shares) external override notPaused { - _undelegate(ThawRequestType.Delegation, serviceProvider, SUBGRAPH_DATA_SERVICE_ADDRESS, shares, msg.sender); - } - /** * @notice See {IHorizonStakingMain-withdrawDelegated}. */ diff --git a/packages/horizon/foundry.toml b/packages/horizon/foundry.toml index 56cb8a0b6..d63d6786a 100644 --- a/packages/horizon/foundry.toml +++ b/packages/horizon/foundry.toml @@ -6,4 +6,4 @@ test = 'test' cache_path = 'cache_forge' fs_permissions = [{ access = "read", path = "./"}] optimizer = true -optimizer_runs = 200 \ No newline at end of file +optimizer_runs = 50 \ No newline at end of file diff --git a/packages/horizon/scripts/migrate.ts b/packages/horizon/scripts/migrate.ts index 0940aa869..e62dd56a7 100644 --- a/packages/horizon/scripts/migrate.ts +++ b/packages/horizon/scripts/migrate.ts @@ -23,6 +23,7 @@ async function main() { console.log('Using deployer account:', deployer.address) console.log('Using governor account:', governor.address) + console.log('==============================================') const HorizonMigrateConfig = removeNFromBigInts(require('../ignition/configs/horizon-migrate.hardhat.json5')) diff --git a/packages/horizon/test/shared/horizon-staking/HorizonStakingShared.t.sol b/packages/horizon/test/shared/horizon-staking/HorizonStakingShared.t.sol index 3be6633fb..ace665a74 100644 --- a/packages/horizon/test/shared/horizon-staking/HorizonStakingShared.t.sol +++ b/packages/horizon/test/shared/horizon-staking/HorizonStakingShared.t.sol @@ -826,11 +826,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest { } function _delegate(address serviceProvider, address verifier, uint256 tokens, uint256 minSharesOut) internal { - __delegate(serviceProvider, verifier, tokens, minSharesOut, false); - } - - function _delegate(address serviceProvider, uint256 tokens) internal { - __delegate(serviceProvider, subgraphDataServiceLegacyAddress, tokens, 0, true); + bool legacy = verifier == subgraphDataServiceLegacyAddress; + __delegate(serviceProvider, verifier, tokens, minSharesOut, legacy); } function __delegate( @@ -865,11 +862,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest { token.approve(address(staking), tokens); vm.expectEmit(); emit IHorizonStakingMain.TokensDelegated(serviceProvider, verifier, delegator, tokens); - if (legacy) { - staking.delegate(serviceProvider, tokens); - } else { - staking.delegate(serviceProvider, verifier, tokens, minSharesOut); - } + staking.delegate(serviceProvider, verifier, tokens, minSharesOut); // after DelegationPoolInternalTest memory afterPool = _getStorage_DelegationPoolInternal( @@ -905,7 +898,8 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest { function _undelegate(address serviceProvider, address verifier, uint256 shares) internal { (, address caller, ) = vm.readCallers(); - __undelegate(IHorizonStakingTypes.ThawRequestType.Delegation, serviceProvider, verifier, shares, false, caller); + bool legacy = verifier == subgraphDataServiceLegacyAddress; + __undelegate(IHorizonStakingTypes.ThawRequestType.Delegation, serviceProvider, verifier, shares, legacy, caller); } function _undelegateWithBeneficiary(address serviceProvider, address verifier, uint256 shares, address beneficiary) internal { @@ -919,18 +913,6 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest { ); } - function _undelegate(address serviceProvider, uint256 shares) internal { - (, address caller, ) = vm.readCallers(); - __undelegate( - IHorizonStakingTypes.ThawRequestType.Delegation, - serviceProvider, - subgraphDataServiceLegacyAddress, - shares, - true, - caller - ); - } - struct BeforeValues_Undelegate { DelegationPoolInternalTest pool; DelegationInternal delegation; @@ -988,9 +970,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest { ); vm.expectEmit(); emit IHorizonStakingMain.TokensUndelegated(serviceProvider, verifier, delegator, calcValues.tokens); - if (legacy) { - staking.undelegate(serviceProvider, shares); - } else if (thawRequestType == IHorizonStakingTypes.ThawRequestType.Delegation) { + if (thawRequestType == IHorizonStakingTypes.ThawRequestType.Delegation) { staking.undelegate(serviceProvider, verifier, shares); } else if (thawRequestType == IHorizonStakingTypes.ThawRequestType.DelegationWithBeneficiary) { staking.undelegateWithBeneficiary(serviceProvider, verifier, shares, beneficiary); diff --git a/packages/horizon/test/staking/delegation/delegate.t.sol b/packages/horizon/test/staking/delegation/delegate.t.sol index 043453e10..dfe02af0a 100644 --- a/packages/horizon/test/staking/delegation/delegate.t.sol +++ b/packages/horizon/test/staking/delegation/delegate.t.sol @@ -81,7 +81,7 @@ contract HorizonStakingDelegateTest is HorizonStakingTest { _createProvision(users.indexer, subgraphDataServiceLegacyAddress, amount, 0, 0); resetPrank(users.delegator); - _delegate(users.indexer, delegationAmount); + _delegate(users.indexer, subgraphDataServiceLegacyAddress, delegationAmount, 0); } function testDelegate_RevertWhen_InvalidPool( diff --git a/packages/horizon/test/staking/delegation/undelegate.t.sol b/packages/horizon/test/staking/delegation/undelegate.t.sol index e23fdadb8..2d3129042 100644 --- a/packages/horizon/test/staking/delegation/undelegate.t.sol +++ b/packages/horizon/test/staking/delegation/undelegate.t.sol @@ -148,7 +148,7 @@ contract HorizonStakingUndelegateTest is HorizonStakingTest { _createProvision(users.indexer, subgraphDataServiceLegacyAddress, amount, 0, 0); resetPrank(users.delegator); - _delegate(users.indexer, delegationAmount); + _delegate(users.indexer, subgraphDataServiceLegacyAddress, delegationAmount, 0); DelegationInternal memory delegation = _getStorage_Delegation( users.indexer, @@ -156,7 +156,7 @@ contract HorizonStakingUndelegateTest is HorizonStakingTest { users.delegator, true ); - _undelegate(users.indexer, delegation.shares); + _undelegate(users.indexer, subgraphDataServiceLegacyAddress, delegation.shares); } function testUndelegate_RevertWhen_InvalidPool( diff --git a/packages/horizon/test/staking/delegation/withdraw.t.sol b/packages/horizon/test/staking/delegation/withdraw.t.sol index ab286c279..5f97abf0c 100644 --- a/packages/horizon/test/staking/delegation/withdraw.t.sol +++ b/packages/horizon/test/staking/delegation/withdraw.t.sol @@ -68,14 +68,14 @@ contract HorizonStakingWithdrawDelegationTest is HorizonStakingTest { _createProvision(users.indexer, subgraphDataServiceLegacyAddress, 10_000_000 ether, 0, MAX_THAWING_PERIOD); resetPrank(users.delegator); - _delegate(users.indexer, delegationAmount); + _delegate(users.indexer, subgraphDataServiceLegacyAddress, delegationAmount, 0); DelegationInternal memory delegation = _getStorage_Delegation( users.indexer, subgraphDataServiceAddress, users.delegator, true ); - _undelegate(users.indexer, delegation.shares); + _undelegate(users.indexer, subgraphDataServiceLegacyAddress, delegation.shares); LinkedList.List memory thawingRequests = staking.getThawRequestList( IHorizonStakingTypes.ThawRequestType.Delegation, diff --git a/packages/subgraph-service/contracts/utilities/AllocationManagerStorage.sol b/packages/subgraph-service/contracts/utilities/AllocationManagerStorage.sol index f11e18d1b..a18b85f77 100644 --- a/packages/subgraph-service/contracts/utilities/AllocationManagerStorage.sol +++ b/packages/subgraph-service/contracts/utilities/AllocationManagerStorage.sol @@ -6,7 +6,7 @@ import { LegacyAllocation } from "../libraries/LegacyAllocation.sol"; abstract contract AllocationManagerV1Storage { /// @notice Allocation details - mapping(address allocationId => Allocation.State allocation) public allocations; + mapping(address allocationId => Allocation.State allocation) internal allocations; /// @notice Legacy allocation details mapping(address allocationId => LegacyAllocation.State allocation) public legacyAllocations; @@ -15,14 +15,14 @@ abstract contract AllocationManagerV1Storage { mapping(address indexer => uint256 tokens) public allocationProvisionTracker; /// @notice Maximum amount of time, in seconds, allowed between presenting POIs to qualify for indexing rewards - uint256 public maxPOIStaleness; + uint256 internal maxPOIStaleness; /// @notice Destination of accrued indexing rewards mapping(address indexer => address destination) public rewardsDestination; /// @notice Track total tokens allocated per subgraph deployment /// @dev Used to calculate indexing rewards - mapping(bytes32 subgraphDeploymentId => uint256 tokens) public subgraphAllocatedTokens; + mapping(bytes32 subgraphDeploymentId => uint256 tokens) internal subgraphAllocatedTokens; /// @dev Gap to allow adding variables in future upgrades uint256[50] private __gap;