Skip to content

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed Oct 11, 2024
1 parent 504fff1 commit 0c0d090
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -862,7 +862,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
bytes32 thawRequestId = _createThawRequest(
_serviceProvider,
_verifier,
beneficiary,
_beneficiary,
thawingShares,
thawingUntil,
pool.thawingNonce
Expand Down
16 changes: 8 additions & 8 deletions packages/horizon/contracts/staking/HorizonStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,19 @@ 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.
*/
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;
}
}
28 changes: 14 additions & 14 deletions packages/subgraph-service/contracts/utilities/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}

0 comments on commit 0c0d090

Please sign in to comment.