Skip to content

Commit

Permalink
Tmigone/horizon staking revamp (#973)
Browse files Browse the repository at this point in the history
* chore: typos

Signed-off-by: Tomás Migone <[email protected]>

* chore: refactor HorizonStaking

Signed-off-by: Tomás Migone <[email protected]>

---------

Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone authored May 24, 2024
1 parent f4802b2 commit a390aea
Show file tree
Hide file tree
Showing 14 changed files with 1,121 additions and 1,150 deletions.
12 changes: 6 additions & 6 deletions packages/horizon/contracts/interfaces/IBridgeEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ pragma solidity 0.8.24;
interface IBridgeEscrow {
/**
* @notice Initialize the BridgeEscrow contract.
* @param _controller Address of the Controller that manages this contract
* @param controller Address of the Controller that manages this contract
*/
function initialize(address ontroller) external;
function initialize(address controller) external;

/**
* @notice Approve a spender (i.e. a bridge that manages the GRT funds held by the escrow)
* @param _spender Address of the spender that will be approved
* @param spender Address of the spender that will be approved
*/
function approveAll(address sender) external;
function approveAll(address spender) external;

/**
* @notice Revoke a spender (i.e. a bridge that will no longer manage the GRT funds held by the escrow)
* @param _spender Address of the spender that will be revoked
* @param spender Address of the spender that will be revoked
*/
function revokeAll(address spnder) external;
function revokeAll(address spender) external;
}
5 changes: 3 additions & 2 deletions packages/horizon/contracts/interfaces/IHorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

pragma solidity 0.8.24;

import { IHorizonStakingBase } from "./IHorizonStakingBase.sol";
import { IHorizonStakingTypes } from "./IHorizonStakingTypes.sol";
import { IHorizonStakingMain } from "./IHorizonStakingMain.sol";
import { IHorizonStakingExtension } from "./IHorizonStakingExtension.sol";

interface IHorizonStaking is IHorizonStakingBase, IHorizonStakingExtension {}
interface IHorizonStaking is IHorizonStakingTypes, IHorizonStakingMain, IHorizonStakingExtension {}
228 changes: 33 additions & 195 deletions packages/horizon/contracts/interfaces/IHorizonStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,229 +3,67 @@
pragma solidity 0.8.24;

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

interface IHorizonStakingBase is IHorizonStakingTypes {
interface IHorizonStakingBase {
/**
* @dev Emitted when `serviceProvider` stakes `tokens` amount.
* @dev TODO(after transition period): move to IHorizonStakingMain
*/
event StakeDeposited(address indexed serviceProvider, uint256 tokens);

/**
* @dev Emitted when `serviceProvider` withdraws `tokens` amount.
* @dev Emitted when `delegator` delegated `tokens` to the `serviceProvider`, the delegator
* gets `shares` for the delegation pool proportionally to the tokens staked.
* This event is here for backwards compatibility, the tokens are delegated
* on the subgraph data service provision.
* @dev TODO(after transition period): move to IHorizonStakingMain
*/
event StakeWithdrawn(address indexed serviceProvider, uint256 tokens);
event StakeDelegated(address indexed serviceProvider, address indexed delegator, uint256 tokens, uint256 shares);

/**
* @dev Emitted when `serviceProvider` locks `tokens` amount until `until`.
*/
event StakeLocked(address indexed serviceProvider, uint256 tokens, uint256 until);

/**
* @dev Emitted when a service provider provisions staked tokens to a verifier
*/
event ProvisionCreated(
address indexed serviceProvider,
address indexed verifier,
uint256 tokens,
uint32 maxVerifierCut,
uint64 thawingPeriod
);

/**
* @dev Emitted when a service provider increases the tokens in a provision
*/
event ProvisionIncreased(address indexed serviceProvider, address indexed verifier, uint256 tokens);

/**
* @dev Emitted when a thawing request is initiated by a service provider
*/
event ProvisionThawInitiated(
address indexed serviceProvider,
address indexed verifier,
uint256 tokens,
uint64 thawingUntil,
bytes32 indexed thawRequestId
);
function getStake(address serviceProvider) external view returns (uint256);

/**
* @dev Emitted when a service provider removes tokens from a provision after thawing
*/
event ProvisionThawFulfilled(
address indexed serviceProvider,
address indexed verifier,
uint256 tokens,
bytes32 indexed thawRequestId
);

event ProvisionSlashed(address indexed serviceProvider, address indexed verifier, uint256 tokens);

event DelegationSlashed(address indexed serviceProvider, address indexed verifier, uint256 tokens);

event DelegationSlashingSkipped(address indexed serviceProvider, address indexed verifier, uint256 tokens);

event VerifierTokensSent(
address indexed serviceProvider,
address indexed verifier,
address indexed destination,
uint256 tokens
);

event TokensDelegated(
address indexed serviceProvider,
address indexed verifier,
address indexed delegator,
uint256 tokens
);

event TokensUndelegated(
address indexed serviceProvider,
address indexed verifier,
address indexed delegator,
uint256 tokens
);

event DelegatedTokensWithdrawn(
address indexed serviceProvider,
address indexed verifier,
address indexed delegator,
uint256 tokens
);

event DelegationSlashingEnabled(bool enabled);

event AllowedLockedVerifierSet(address verifier, bool allowed);

event TokensAddedToDelegationPool(address indexed serviceProvider, address indexed verifier, uint256 tokens);

event ProvisionParametersStaged(
address indexed serviceProvider,
address indexed verifier,
uint32 maxVerifierCut,
uint64 thawingPeriod
);

event ProvisionParametersSet(
address indexed serviceProvider,
address indexed verifier,
uint32 maxVerifierCut,
uint64 thawingPeriod
);

// deposit stake
function stake(uint256 tokens) external;

function stakeTo(address serviceProvider, uint256 tokens) external;

// can be called by anyone if the service provider has provisioned stake to this verifier
function stakeToProvision(address serviceProvider, address verifier, uint256 tokens) external;

// create a provision
function provision(
address serviceProvider,
address verifier,
uint256 tokens,
uint32 maxVerifierCut,
uint64 thawingPeriod
) external;
function getDelegatedTokensAvailable(address serviceProvider, address verifier) external view returns (uint256);

/**
* @notice Provision stake to a verifier using locked tokens (i.e. from GraphTokenLockWallets). The tokens will be locked with a thawing period
* and will be slashable by the verifier. This is the main mechanism to provision stake to a data
* service, where the data service is the verifier. Only authorized verifiers can be used.
* This function can be called by the service provider or by an operator authorized by the provider
* for this specific verifier.
* @param serviceProvider The service provider address
* @param verifier The verifier address for which the tokens are provisioned (who will be able to slash the tokens)
* @param tokens The amount of tokens that will be locked and slashable
* @param maxVerifierCut The maximum cut, expressed in PPM, that a verifier can transfer instead of burning when slashing
* @param thawingPeriod The period in seconds that the tokens will be thawing before they can be removed from the provision
*/
function provisionLocked(
function getTokensAvailable(
address serviceProvider,
address verifier,
uint256 tokens,
uint32 maxVerifierCut,
uint64 thawingPeriod
) external;

// initiate a thawing to remove tokens from a provision
function thaw(address serviceProvider, address verifier, uint256 tokens) external returns (bytes32);
uint32 delegationRatio
) external view returns (uint256);

// add more tokens from idle stake to an existing provision
function addToProvision(address serviceProvider, address verifier, uint256 tokens) external;
function getServiceProvider(
address serviceProvider
) external view returns (IHorizonStakingTypes.ServiceProvider memory);

// moves thawed stake from a provision back into the provider's available stake
function deprovision(address serviceProvider, address verifier, uint256 tokens) external;
function getMaxThawingPeriod() external view returns (uint64);

// moves thawed stake from one provision into another provision
function reprovision(address serviceProvider, address oldVerifier, address newVerifier, uint256 tokens) external;

// moves thawed stake back to the owner's account - stake is removed from the protocol
function unstake(uint256 tokens) external;

// delegate tokens to a provider on a data service
function delegate(address serviceProvider, address verifier, uint256 tokens, uint256 minSharesOut) external;

// undelegate (thaw) delegated tokens from a provision
function undelegate(address serviceProvider, address verifier, uint256 shares) external;

// withdraw delegated tokens after thawing
function withdrawDelegated(
function getDelegationPool(
address serviceProvider,
address verifier,
address newServiceProvider,
uint256 minSharesForNewProvider
) external;
address verifier
) external view returns (IHorizonStakingTypes.DelegationPool memory);

function slash(
function getDelegation(
address delegator,
address serviceProvider,
uint256 tokens,
uint256 tokensVerifier,
address verifierDestination
) external;

/**
* @notice Withdraw service provider tokens once the thawing period has passed.
* @dev This is only needed during the transition period while we still have
* a global lock. After that, unstake() will also withdraw.
*/
function withdraw() external;

function setDelegationSlashingEnabled(bool enabled) external;
address verifier
) external view returns (IHorizonStakingTypes.Delegation memory);

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

function setAllowedLockedVerifier(address verifier, bool allowed) external;

/**
* @notice Add tokens to a delegation pool (without getting shares).
* Used by data services to pay delegation fees/rewards.
* @param serviceProvider The service provider address
* @param verifier The verifier address for which the tokens are provisioned
* @param tokens The amount of tokens to add to the delegation pool
*/
function addToDelegationPool(address serviceProvider, address verifier, uint256 tokens) external;
function getProvision(
address serviceProvider,
address verifier
) external view returns (IHorizonStakingTypes.Provision memory);

function setProvisionParameters(
function getDelegationFeeCut(
address serviceProvider,
address verifier,
uint32 maxVerifierCut,
uint64 thawingPeriod
) external;

function acceptProvisionParameters(address serviceProvider) external;
IGraphPayments.PaymentTypes paymentType
) external view returns (uint256);

// staked tokens that are currently not provisioned, aka idle stake
// `getStake(serviceProvider) - ServiceProvider.tokensProvisioned`
function getIdleStake(address serviceProvider) external view returns (uint256 tokens);

/**
* @notice Check if an operator is authorized for the caller on a specific verifier / data service.
* @param operator The address to check for auth
* @param serviceProvider The service provider on behalf of whom they're claiming to act
* @param verifier The verifier / data service on which they're claiming to act
*/
function isAuthorized(address operator, address serviceProvider, address verifier) external view returns (bool);

function getProviderTokensAvailable(address serviceProvider, address verifier) external view returns (uint256);
}
Loading

0 comments on commit a390aea

Please sign in to comment.