Skip to content

Commit

Permalink
fix: inonsistent coding style (OZ L-06)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed Aug 24, 2024
1 parent 4d25fcd commit 1c6bb31
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 42 deletions.
5 changes: 0 additions & 5 deletions packages/horizon/contracts/interfaces/IGraphPayments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ interface IGraphPayments {
*/
error GraphPaymentsInsufficientTokens(uint256 tokens, uint256 minTokens);

/**
* @notice Initialize the contract
*/
function initialize() external;

/**
* @notice Collects funds from a payer.
* It will pay cuts to all relevant parties and forward the rest to the receiver.
Expand Down
5 changes: 0 additions & 5 deletions packages/horizon/contracts/interfaces/IPaymentsEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ interface IPaymentsEscrow {
*/
error PaymentsEscrowInvalidZeroTokens();

/**
* @notice Initialize the contract
*/
function initialize() external;

/**
* @notice Authorize a collector to collect funds from the payer's escrow
* @dev This function can only be used to increase the allowance of a collector.
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 @@ -35,7 +35,7 @@ contract GraphPayments is Initializable, MulticallUpgradeable, GraphDirectory, I
}

/**
* @notice See {IGraphPayments-initialize}
* @notice Initialize the contract
*/
function initialize() external initializer {
__Multicall_init();
Expand Down
4 changes: 2 additions & 2 deletions packages/horizon/contracts/payments/PaymentsEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ contract PaymentsEscrow is


/**
* @notice See {PaymentsEscrow.initialize}
* @notice Initialize the contract
*/
function initialize() external override initializer {
function initialize() external initializer {
__Multicall_init();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
uint256 tokens,
uint256 minSharesOut
) external override notPaused {
require(tokens != 0, HorizonStakingInvalidZeroTokens());
_graphToken().pullTokens(msg.sender, tokens);
_delegate(serviceProvider, verifier, tokens, minSharesOut);
}
Expand Down Expand Up @@ -325,6 +326,7 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
* @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);
}
Expand Down Expand Up @@ -711,8 +713,6 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
* have been done before calling this function.
*/
function _delegate(address _serviceProvider, address _verifier, uint256 _tokens, uint256 _minSharesOut) private {
require(_tokens != 0, HorizonStakingInvalidZeroTokens());

// TODO: remove this after L2 transfer tool for delegation is removed
require(_tokens >= MIN_DELEGATION, HorizonStakingInsufficientTokens(_tokens, MIN_DELEGATION));
require(
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 @@ -273,7 +273,7 @@ abstract contract HorizonStakingBase is
address _serviceProvider,
address _verifier
) internal view returns (DelegationPoolInternal storage) {
IHorizonStakingTypes.DelegationPoolInternal storage pool;
DelegationPoolInternal storage pool;
if (_verifier == SUBGRAPH_DATA_SERVICE_ADDRESS) {
pool = _legacyDelegationPools[_serviceProvider];
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IL2StakingBase, IHorizon
IL2StakingTypes.ReceiveDelegationData memory _delegationData
) internal {
// Get the delegation pool of the indexer
IHorizonStakingTypes.DelegationPoolInternal storage pool = _legacyDelegationPools[_delegationData.indexer];
DelegationPoolInternal storage pool = _legacyDelegationPools[_delegationData.indexer];
IHorizonStakingTypes.DelegationInternal storage delegation = pool.delegators[_delegationData.delegator];

// If pool is in an invalid state, return the tokens to the delegator
Expand All @@ -366,7 +366,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IL2StakingBase, IHorizon
// If no shares would be issued (probably a rounding issue or attack),
// or if the amount is under the minimum delegation (which could be part of a rounding attack),
// return the tokens to the delegator
_graphToken().transfer(_delegationData.delegator, _tokens);
_graphToken().pushTokens(_delegationData.delegator, _tokens);
emit TransferredDelegationReturnedToDelegator(_delegationData.indexer, _delegationData.delegator, _tokens);
} else {
// Update the delegation pool
Expand Down Expand Up @@ -516,7 +516,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IL2StakingBase, IHorizon
*/
function _collectDelegationQueryRewards(address _indexer, uint256 _tokens) private returns (uint256) {
uint256 delegationRewards = 0;
IHorizonStakingTypes.DelegationPoolInternal storage pool = _legacyDelegationPools[_indexer];
DelegationPoolInternal storage pool = _legacyDelegationPools[_indexer];
if (pool.tokens > 0 && uint256(pool.__DEPRECATED_queryFeeCut).isValidPPM()) {
uint256 indexerCut = uint256(pool.__DEPRECATED_queryFeeCut).mulPPM(_tokens);
delegationRewards = _tokens - indexerCut;
Expand All @@ -534,7 +534,7 @@ contract HorizonStakingExtension is HorizonStakingBase, IL2StakingBase, IHorizon
*/
function _collectDelegationIndexingRewards(address _indexer, uint256 _tokens) private returns (uint256) {
uint256 delegationRewards = 0;
IHorizonStakingTypes.DelegationPoolInternal storage pool = _legacyDelegationPools[_indexer];
DelegationPoolInternal storage pool = _legacyDelegationPools[_indexer];
if (pool.tokens > 0 && uint256(pool.__DEPRECATED_indexingRewardCut).isValidPPM()) {
uint256 indexerCut = uint256(pool.__DEPRECATED_indexingRewardCut).mulPPM(_tokens);
delegationRewards = _tokens - indexerCut;
Expand Down
2 changes: 1 addition & 1 deletion packages/subgraph-service/contracts/DisputeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ contract DisputeManager is
uint256 disputeDeposit,
uint32 fishermanRewardCut_,
uint32 maxSlashingCut_
) external override initializer {
) external initializer {
__Ownable_init(msg.sender);
__AttestationManager_init();

Expand Down
13 changes: 9 additions & 4 deletions packages/subgraph-service/contracts/SubgraphService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.26;

import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol";
import { IGraphToken } from "@graphprotocol/contracts/contracts/token/IGraphToken.sol";
import { ITAPCollector } from "@graphprotocol/horizon/contracts/interfaces/ITAPCollector.sol";
import { IRewardsIssuer } from "@graphprotocol/contracts/contracts/rewards/IRewardsIssuer.sol";
import { ISubgraphService } from "./interfaces/ISubgraphService.sol";
Expand All @@ -15,6 +16,7 @@ import { Directory } from "./utilities/Directory.sol";
import { AllocationManager } from "./utilities/AllocationManager.sol";
import { SubgraphServiceV1Storage } from "./SubgraphServiceStorage.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 { LegacyAllocation } from "./libraries/LegacyAllocation.sol";
Expand All @@ -34,6 +36,7 @@ contract SubgraphService is
using PPMMath for uint256;
using Allocation for mapping(address => Allocation.State);
using Allocation for Allocation.State;
using TokenUtils for IGraphToken;

/**
* @notice Checks that an indexer is registered
Expand Down Expand Up @@ -79,18 +82,20 @@ contract SubgraphService is
}

/**
* @notice See {ISubgraphService.initialize}
* @notice Initialize the contract
* @dev The thawingPeriod and verifierCut ranges are not set here because they are variables
* on the DisputeManager. We use the {ProvisionManager} overrideable getters to get the ranges.
* @param minimumProvisionTokens The minimum amount of provisioned tokens required to create an allocation
* @param maximumDelegationRatio The maximum delegation ratio allowed for an allocation
*/
function initialize(uint256 minimumProvisionTokens, uint32 delegationRatio) external override initializer {
function initialize(uint256 minimumProvisionTokens, uint32 maximumDelegationRatio) external initializer {
__Ownable_init(msg.sender);
__DataService_init();
__DataServicePausable_init();
__AllocationManager_init("SubgraphService", "1.0");

_setProvisionTokensRange(minimumProvisionTokens, type(uint256).max);
_setDelegationRatio(delegationRatio);
_setDelegationRatio(maximumDelegationRatio);
}

/**
Expand Down Expand Up @@ -561,7 +566,7 @@ contract SubgraphService is
_graphRewardsManager().onSubgraphSignalUpdate(subgraphDeploymentId);

// Send GRT and bookkeep by calling collect()
_graphToken().transfer(address(_curation()), tokensCurators);
_graphToken().pushTokens(address(_curation()), tokensCurators);
_curation().collect(subgraphDeploymentId, tokensCurators);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,6 @@ interface IDisputeManager {
bytes32 subgraphDeploymentId2
);

function initialize(
address arbitrator,
uint64 disputePeriod,
uint256 disputeDeposit,
uint32 fishermanRewardCut,
uint32 maxSlashingCut
) external;

function setDisputePeriod(uint64 disputePeriod) external;

function setArbitrator(address arbitrator) external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ interface ISubgraphService is IDataServiceFees {
*/
error SubgraphServiceAllocationIsAltruistic(address allocationId);

/**
* @notice Initialize the contract
* @param minimumProvisionTokens The minimum amount of provisioned tokens required to create an allocation
* @param maximumDelegationRatio The maximum delegation ratio allowed for an allocation
*/
function initialize(uint256 minimumProvisionTokens, uint32 maximumDelegationRatio) external;

/**
* @notice Close a stale allocation
* @dev This function can be permissionlessly called when the allocation is stale.
Expand All @@ -141,6 +134,7 @@ interface ISubgraphService is IDataServiceFees {
function closeStaleAllocation(address allocationId) external;

/**
* @notice Change the amount of tokens in an allocation
* @dev Requirements:
* - The indexer must be registered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ library Attestation {
}

/// @notice Attestation size is the sum of the receipt (96) + signature (65)
uint256 private constant ATTESTATION_SIZE_BYTES = RECEIPT_SIZE_BYTES + SIG_SIZE_BYTES;
uint256 private constant RECEIPT_SIZE_BYTES = 96;

uint256 private constant SIG_R_LENGTH = 32;
Expand All @@ -34,6 +33,8 @@ library Attestation {
uint256 private constant SIG_S_OFFSET = RECEIPT_SIZE_BYTES + SIG_R_LENGTH;
uint256 private constant SIG_V_OFFSET = RECEIPT_SIZE_BYTES + SIG_R_LENGTH + SIG_S_LENGTH;
uint256 private constant SIG_SIZE_BYTES = SIG_R_LENGTH + SIG_S_LENGTH + SIG_V_LENGTH;

uint256 private constant ATTESTATION_SIZE_BYTES = RECEIPT_SIZE_BYTES + SIG_SIZE_BYTES;

uint256 private constant UINT8_BYTE_LENGTH = 1;
uint256 private constant BYTES32_BYTE_LENGTH = 32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
pragma solidity 0.8.26;

import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol";
import { IGraphToken } from "@graphprotocol/contracts/contracts/token/IGraphToken.sol";

import { GraphDirectory } from "@graphprotocol/horizon/contracts/utilities/GraphDirectory.sol";
import { AllocationManagerV1Storage } from "./AllocationManagerStorage.sol";

import { TokenUtils } from "@graphprotocol/contracts/contracts/utils/TokenUtils.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { EIP712Upgradeable } from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
import { Allocation } from "../libraries/Allocation.sol";
Expand All @@ -25,6 +28,7 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
using Allocation for Allocation.State;
using LegacyAllocation for mapping(address => LegacyAllocation.State);
using PPMMath for uint256;
using TokenUtils for IGraphToken;

///@dev EIP712 typehash for allocation proof
bytes32 private immutable EIP712_ALLOCATION_PROOF_TYPEHASH =
Expand Down Expand Up @@ -305,7 +309,7 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
_graphToken().approve(address(_graphStaking()), tokensIndexerRewards);
_graphStaking().stakeToProvision(allocation.indexer, address(this), tokensIndexerRewards);
} else {
_graphToken().transfer(rewardsDestination, tokensIndexerRewards);
_graphToken().pushTokens(rewardsDestination, tokensIndexerRewards);
}

emit IndexingRewardsCollected(
Expand Down

0 comments on commit 1c6bb31

Please sign in to comment.