diff --git a/packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol b/packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol index fef392302..25449909b 100644 --- a/packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol +++ b/packages/horizon/contracts/data-service/libraries/ProvisionTracker.sol @@ -42,6 +42,20 @@ library ProvisionTracker { self[serviceProvider] += tokens; } + /** + * @notice Releases tokens for a service provider + * @dev Requirements: + * - `tokens` must be less than or equal to the amount of tokens locked for the service provider + * @param self The provision tracker mapping + * @param serviceProvider The service provider address + * @param tokens The amount of tokens to release + */ + function release(mapping(address => uint256) storage self, address serviceProvider, uint256 tokens) internal { + if (tokens == 0) return; + require(self[serviceProvider] >= tokens, ProvisionTrackerInsufficientTokens(self[serviceProvider], tokens)); + self[serviceProvider] -= tokens; + } + /** * @notice Checks if a service provider has enough tokens available to lock * @param self The provision tracker mapping @@ -58,18 +72,4 @@ library ProvisionTracker { uint256 tokensAvailable = graphStaking.getTokensAvailable(serviceProvider, address(this), delegationRatio); return self[serviceProvider] <= tokensAvailable; } - - /** - * @notice Releases tokens for a service provider - * @dev Requirements: - * - `tokens` must be less than or equal to the amount of tokens locked for the service provider - * @param self The provision tracker mapping - * @param serviceProvider The service provider address - * @param tokens The amount of tokens to release - */ - function release(mapping(address => uint256) storage self, address serviceProvider, uint256 tokens) internal { - if (tokens == 0) return; - require(self[serviceProvider] >= tokens, ProvisionTrackerInsufficientTokens(self[serviceProvider], tokens)); - self[serviceProvider] -= tokens; - } } diff --git a/packages/horizon/contracts/staking/HorizonStaking.sol b/packages/horizon/contracts/staking/HorizonStaking.sol index c46670dcb..8df8f20f6 100644 --- a/packages/horizon/contracts/staking/HorizonStaking.sol +++ b/packages/horizon/contracts/staking/HorizonStaking.sol @@ -836,7 +836,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain { address _serviceProvider, address _verifier, uint256 _shares, - address beneficiary + address _beneficiary ) private returns (bytes32) { require(_shares > 0, HorizonStakingInvalidZeroShares()); DelegationPoolInternal storage pool = _getDelegationPool(_serviceProvider, _verifier); @@ -862,7 +862,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain { bytes32 thawRequestId = _createThawRequest( _serviceProvider, _verifier, - beneficiary, + _beneficiary, thawingShares, thawingUntil, pool.thawingNonce diff --git a/packages/horizon/contracts/staking/HorizonStakingBase.sol b/packages/horizon/contracts/staking/HorizonStakingBase.sol index 54e55e1cc..d29d3edec 100644 --- a/packages/horizon/contracts/staking/HorizonStakingBase.sol +++ b/packages/horizon/contracts/staking/HorizonStakingBase.sol @@ -288,14 +288,6 @@ abstract contract HorizonStakingBase is return _provisions[_serviceProvider][_verifier].tokens - _provisions[_serviceProvider][_verifier].tokensThawing; } - /** - * @notice See {IHorizonStakingBase-getDelegatedTokensAvailable}. - */ - function _getDelegatedTokensAvailable(address _serviceProvider, address _verifier) private view returns (uint256) { - DelegationPoolInternal storage poolInternal = _getDelegationPool(_serviceProvider, _verifier); - return poolInternal.tokens - poolInternal.tokensThawing; - } - /** * @notice Gets the next thaw request after `_thawRequestId`. * @dev This function is used as a callback in the thaw requests linked list traversal. @@ -303,4 +295,12 @@ abstract contract HorizonStakingBase is function _getNextThawRequest(bytes32 _thawRequestId) internal view returns (bytes32) { return _thawRequests[_thawRequestId].next; } + + /** + * @notice See {IHorizonStakingBase-getDelegatedTokensAvailable}. + */ + function _getDelegatedTokensAvailable(address _serviceProvider, address _verifier) private view returns (uint256) { + DelegationPoolInternal storage poolInternal = _getDelegationPool(_serviceProvider, _verifier); + return poolInternal.tokens - poolInternal.tokensThawing; + } } diff --git a/packages/subgraph-service/contracts/utilities/AllocationManager.sol b/packages/subgraph-service/contracts/utilities/AllocationManager.sol index 5da237ee6..669cd9bf8 100644 --- a/packages/subgraph-service/contracts/utilities/AllocationManager.sol +++ b/packages/subgraph-service/contracts/utilities/AllocationManager.sol @@ -457,20 +457,6 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca return legacyAllocations.get(_allocationId); } - /** - * @notice Verifies ownership of an allocation id by verifying an EIP712 allocation proof - * @dev Requirements: - * - Signer must be the allocation id address - * @param _indexer The address of the indexer - * @param _allocationId The id of the allocation - * @param _proof The EIP712 proof, an EIP712 signed message of (indexer,allocationId) - */ - function _verifyAllocationProof(address _indexer, address _allocationId, bytes memory _proof) private view { - bytes32 digest = _encodeAllocationProof(_indexer, _allocationId); - address signer = ECDSA.recover(digest, _proof); - require(signer == _allocationId, AllocationManagerInvalidAllocationProof(signer, _allocationId)); - } - /** * @notice Encodes the allocation proof for EIP712 signing * @param _indexer The address of the indexer @@ -489,4 +475,18 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca function _isOverAllocated(address _indexer, uint32 _delegationRatio) internal view returns (bool) { return !allocationProvisionTracker.check(_graphStaking(), _indexer, _delegationRatio); } + + /** + * @notice Verifies ownership of an allocation id by verifying an EIP712 allocation proof + * @dev Requirements: + * - Signer must be the allocation id address + * @param _indexer The address of the indexer + * @param _allocationId The id of the allocation + * @param _proof The EIP712 proof, an EIP712 signed message of (indexer,allocationId) + */ + function _verifyAllocationProof(address _indexer, address _allocationId, bytes memory _proof) private view { + bytes32 digest = _encodeAllocationProof(_indexer, _allocationId); + address signer = ECDSA.recover(digest, _proof); + require(signer == _allocationId, AllocationManagerInvalidAllocationProof(signer, _allocationId)); + } }