Skip to content

Commit

Permalink
chore: staking interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed May 21, 2024
1 parent fe747d1 commit fd8ad11
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
20 changes: 6 additions & 14 deletions packages/horizon/contracts/interfaces/IHorizonStakingExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma abicoder v2;

import { IHorizonStakingTypes } from "./IHorizonStakingTypes.sol";

interface IHorizonStakingExtension {
interface IHorizonStakingExtension is IHorizonStakingTypes {
/**
* @dev Emitted when an operator is allowed or denied by a service provider for a particular data service
*/
Expand Down Expand Up @@ -41,29 +41,21 @@ interface IHorizonStakingExtension {
uint32 delegationRatio
) external view returns (uint256);

function getServiceProvider(
address serviceProvider
) external view returns (IHorizonStakingTypes.ServiceProvider memory);
function getServiceProvider(address serviceProvider) external view returns (ServiceProvider memory);

function getMaxThawingPeriod() external view returns (uint64);

function getDelegationPool(
address serviceProvider,
address verifier
) external view returns (IHorizonStakingTypes.DelegationPool memory);
function getDelegationPool(address serviceProvider, address verifier) external view returns (DelegationPool memory);

function getDelegation(
address delegator,
address serviceProvider,
address verifier
) external view returns (IHorizonStakingTypes.Delegation memory);
) external view returns (Delegation memory);

function getThawRequest(bytes32 thawRequestId) external view returns (IHorizonStakingTypes.ThawRequest memory);
function getThawRequest(bytes32 thawRequestId) external view returns (ThawRequest memory);

function getProvision(
address serviceProvider,
address verifier
) external view returns (IHorizonStakingTypes.Provision memory);
function getProvision(address serviceProvider, address verifier) external view returns (Provision memory);

function getDelegationFeeCut(
address serviceProvider,
Expand Down
3 changes: 2 additions & 1 deletion packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IGraphToken } from "../interfaces/IGraphToken.sol";
import { TokenUtils } from "../libraries/TokenUtils.sol";
import { MathUtils } from "../libraries/MathUtils.sol";

import { Multicall } from "@openzeppelin/contracts/utils/Multicall.sol";
import { Managed } from "./utilities/Managed.sol";
import { HorizonStakingV1Storage } from "./HorizonStakingStorage.sol";

Expand All @@ -20,7 +21,7 @@ import { HorizonStakingV1Storage } from "./HorizonStakingStorage.sol";
* It uses a HorizonStakingExtension contract to implement the full IHorizonStaking interface through delegatecalls.
* This is due to the contract size limit on Arbitrum (24kB like mainnet).
*/
contract HorizonStaking is HorizonStakingV1Storage, IHorizonStakingBase, GraphUpgradeable {
contract HorizonStaking is GraphUpgradeable, Multicall, HorizonStakingV1Storage, IHorizonStakingBase {
/// @dev 100% in parts per million
uint32 internal constant MAX_PPM = 1000000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { StakingBackwardsCompatibility } from "./StakingBackwardsCompatibility.s
* to receive an indexer's stake or delegation from L1. Note that this contract inherits Staking,
* which uses a StakingExtension contract to implement the full IStaking interface through delegatecalls.
*/
contract HorizonStakingExtension is StakingBackwardsCompatibility, IHorizonStakingExtension, IL2StakingBase {
contract HorizonStakingExtension is StakingBackwardsCompatibility, IL2StakingBase, IHorizonStakingExtension {
/// @dev Minimum amount of tokens that can be delegated
uint256 private constant MINIMUM_DELEGATION = 1e18;

Expand Down
14 changes: 8 additions & 6 deletions packages/horizon/contracts/staking/HorizonStakingStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Managed } from "./utilities/Managed.sol";
* @notice This contract holds all the storage variables for the Staking contract, version 1
*/
// solhint-disable-next-line max-states-count
abstract contract HorizonStakingV1Storage is Managed, IHorizonStakingTypes {
abstract contract HorizonStakingV1Storage is Managed {
// -- Staking --

/// @dev Minimum amount of tokens an indexer needs to stake.
Expand Down Expand Up @@ -53,7 +53,7 @@ abstract contract HorizonStakingV1Storage is Managed, IHorizonStakingTypes {
uint32 internal __DEPRECATED_alphaDenominator;

/// @dev Service provider stakes : serviceProviderAddress => ServiceProvider
mapping(address serviceProvider => ServiceProviderInternal details) internal _serviceProviders;
mapping(address serviceProvider => IHorizonStakingTypes.ServiceProviderInternal details) internal _serviceProviders;

/// @dev Allocations : allocationID => Allocation
/// Deprecated, now applied on the SubgraphService
Expand Down Expand Up @@ -94,7 +94,8 @@ abstract contract HorizonStakingV1Storage is Managed, IHorizonStakingTypes {

/// @dev Delegation pools : serviceProvider => DelegationPoolInternal
/// These are for the subgraph data service.
mapping(address serviceProvider => DelegationPoolInternal delegationPool) internal _legacyDelegationPools;
mapping(address serviceProvider => IHorizonStakingTypes.DelegationPoolInternal delegationPool)
internal _legacyDelegationPools;

// -- Operators --

Expand Down Expand Up @@ -124,7 +125,8 @@ abstract contract HorizonStakingV1Storage is Managed, IHorizonStakingTypes {

/// @dev Provisions from each service provider for each data service
/// ServiceProvider => Verifier => Provision
mapping(address serviceProvider => mapping(address verifier => Provision provision)) internal _provisions;
mapping(address serviceProvider => mapping(address verifier => IHorizonStakingTypes.Provision provision))
internal _provisions;

/// @dev Delegation fee cuts for each service provider on each provision, by fee type:
/// ServiceProvider => Verifier => Fee Type => Fee Cut.
Expand All @@ -135,7 +137,7 @@ abstract contract HorizonStakingV1Storage is Managed, IHorizonStakingTypes {
mapping(address serviceProvider => mapping(address verifier => mapping(uint256 feeType => uint256 feeCut)))
public delegationFeeCut;

mapping(bytes32 thawRequestId => ThawRequest thawRequest) internal _thawRequests;
mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest) internal _thawRequests;

// indexer => verifier => operator => authorized
mapping(address serviceProvider => mapping(address verifier => mapping(address operator => bool authorized)))
Expand All @@ -145,7 +147,7 @@ abstract contract HorizonStakingV1Storage is Managed, IHorizonStakingTypes {
bool public delegationSlashingEnabled;

// delegation pools for each service provider and verifier
mapping(address serviceProvider => mapping(address verifier => DelegationPoolInternal delegationPool))
mapping(address serviceProvider => mapping(address verifier => IHorizonStakingTypes.DelegationPoolInternal delegationPool))
internal _delegationPools;

// allowed verifiers for locked provisions (i.e. from GraphTokenLockWallets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { IRewardsManager } from "@graphprotocol/contracts/contracts/rewards/IRew
import { IEpochManager } from "@graphprotocol/contracts/contracts/epochs/IEpochManager.sol";
import { IGraphToken } from "../interfaces/IGraphToken.sol";
import { IStakingBackwardsCompatibility } from "../interfaces/IStakingBackwardsCompatibility.sol";
import { IHorizonStakingTypes } from "../interfaces/IHorizonStakingTypes.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 { Managed } from "./utilities/Managed.sol";
import { HorizonStakingV1Storage } from "./HorizonStakingStorage.sol";

Expand All @@ -27,12 +26,7 @@ import { HorizonStakingV1Storage } from "./HorizonStakingStorage.sol";
* Note that this contract delegates part of its functionality to a StakingExtension contract.
* This is due to the 24kB contract size limit on Ethereum.
*/
abstract contract StakingBackwardsCompatibility is
HorizonStakingV1Storage,
GraphUpgradeable,
Multicall,
IStakingBackwardsCompatibility
{
abstract contract StakingBackwardsCompatibility is HorizonStakingV1Storage, IStakingBackwardsCompatibility {
/// @dev 100% in parts per million
uint32 internal constant MAX_PPM = 1000000;

Expand Down Expand Up @@ -415,7 +409,7 @@ abstract contract StakingBackwardsCompatibility is
*/
function _collectDelegationQueryRewards(address _indexer, uint256 _tokens) private returns (uint256) {
uint256 delegationRewards = 0;
DelegationPoolInternal storage pool = _legacyDelegationPools[_indexer];
IHorizonStakingTypes.DelegationPoolInternal storage pool = _legacyDelegationPools[_indexer];
if (pool.tokens > 0 && pool.__DEPRECATED_queryFeeCut < MAX_PPM) {
uint256 indexerCut = (uint256(pool.__DEPRECATED_queryFeeCut) * _tokens) / MAX_PPM;
delegationRewards = _tokens - indexerCut;
Expand All @@ -433,7 +427,7 @@ abstract contract StakingBackwardsCompatibility is
*/
function _collectDelegationIndexingRewards(address _indexer, uint256 _tokens) private returns (uint256) {
uint256 delegationRewards = 0;
DelegationPoolInternal storage pool = _legacyDelegationPools[_indexer];
IHorizonStakingTypes.DelegationPoolInternal storage pool = _legacyDelegationPools[_indexer];
if (pool.tokens > 0 && pool.__DEPRECATED_indexingRewardCut < MAX_PPM) {
uint256 indexerCut = (uint256(pool.__DEPRECATED_indexingRewardCut) * _tokens) / MAX_PPM;
delegationRewards = _tokens - indexerCut;
Expand Down

0 comments on commit fd8ad11

Please sign in to comment.