|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | + |
| 3 | +pragma solidity 0.7.6; |
| 4 | +pragma abicoder v2; |
| 5 | + |
| 6 | +interface IHorizonStaking { |
| 7 | + struct Provision { |
| 8 | + // Service provider that created the provision |
| 9 | + address serviceProvider; |
| 10 | + // tokens in the provision |
| 11 | + uint256 tokens; |
| 12 | + // tokens that are being thawed (and will stop being slashable soon) |
| 13 | + uint256 tokensThawing; |
| 14 | + // timestamp of provision creation |
| 15 | + uint64 createdAt; |
| 16 | + // authority to slash the provision |
| 17 | + address verifier; |
| 18 | + // max amount that can be taken by the verifier when slashing, expressed in parts-per-million of the amount slashed |
| 19 | + uint32 maxVerifierCut; |
| 20 | + // time, in seconds, tokens must thaw before being withdrawn |
| 21 | + uint64 thawingPeriod; |
| 22 | + } |
| 23 | + |
| 24 | + // the new "Indexer" struct |
| 25 | + struct ServiceProviderInternal { |
| 26 | + // Tokens on the Service Provider stake (staked by the provider) |
| 27 | + uint256 tokensStaked; |
| 28 | + // Tokens used in allocations |
| 29 | + uint256 __DEPRECATED_tokensAllocated; |
| 30 | + // Tokens locked for withdrawal subject to thawing period |
| 31 | + uint256 __DEPRECATED_tokensLocked; |
| 32 | + // Block when locked tokens can be withdrawn |
| 33 | + uint256 __DEPRECATED_tokensLockedUntil; |
| 34 | + // tokens used in a provision |
| 35 | + uint256 tokensProvisioned; |
| 36 | + // tokens that initiated a thawing in any one of the provider's provisions |
| 37 | + uint256 tokensRequestedThaw; |
| 38 | + // tokens that have been removed from any one of the provider's provisions after thawing |
| 39 | + uint256 tokensFulfilledThaw; |
| 40 | + // provisions that take priority for undelegation force thawing |
| 41 | + bytes32[] forceThawProvisions; |
| 42 | + } |
| 43 | + |
| 44 | + struct ServiceProvider { |
| 45 | + // Tokens on the provider stake (staked by the provider) |
| 46 | + uint256 tokensStaked; |
| 47 | + // tokens used in a provision |
| 48 | + uint256 tokensProvisioned; |
| 49 | + // tokens that initiated a thawing in any one of the provider's provisions |
| 50 | + uint256 tokensRequestedThaw; |
| 51 | + // tokens that have been removed from any one of the provider's provisions after thawing |
| 52 | + uint256 tokensFulfilledThaw; |
| 53 | + // provisions that take priority for undelegation force thawing |
| 54 | + bytes32[] forceThawProvisions; |
| 55 | + } |
| 56 | + |
| 57 | + struct DelegationPool { |
| 58 | + uint32 __DEPRECATED_cooldownBlocks; // solhint-disable-line var-name-mixedcase |
| 59 | + uint32 __DEPRECATED_indexingRewardCut; // in PPM |
| 60 | + uint32 __DEPRECATED_queryFeeCut; // in PPM |
| 61 | + uint256 __DEPRECATED_updatedAtBlock; // Block when the pool was last updated |
| 62 | + uint256 tokens; // Total tokens as pool reserves |
| 63 | + uint256 shares; // Total shares minted in the pool |
| 64 | + mapping(address => Delegation) delegators; // Mapping of delegator => Delegation |
| 65 | + } |
| 66 | + |
| 67 | + struct Delegation { |
| 68 | + // shares owned by the delegator in the pool |
| 69 | + uint256 shares; |
| 70 | + // tokens delegated to the pool |
| 71 | + uint256 tokens; |
| 72 | + // Timestamp when locked tokens can be undelegated (after the timelock) |
| 73 | + uint256 tokensLockedUntil; |
| 74 | + } |
| 75 | + |
| 76 | + struct ThawRequest { |
| 77 | + // tokens that are being thawed by this request |
| 78 | + uint256 tokens; |
| 79 | + // the provision id to which this request corresponds to |
| 80 | + bytes32 provisionId; |
| 81 | + // the address that initiated the thaw request, allowed to remove the funds once thawed |
| 82 | + address owner; |
| 83 | + // the timestamp when the thawed funds can be removed from the provision |
| 84 | + uint64 thawingUntil; |
| 85 | + // the value of `ServiceProvider.tokensRequestedThaw` the moment the thaw request is created |
| 86 | + uint256 tokensRequestedThawSnapshot; |
| 87 | + } |
| 88 | + |
| 89 | + // whitelist/deny a verifier |
| 90 | + function allowVerifier(address verifier, bool allow) external; |
| 91 | + |
| 92 | + // deposit stake |
| 93 | + function stake(uint256 tokens) external; |
| 94 | + |
| 95 | + // create a provision |
| 96 | + function provision( |
| 97 | + uint256 tokens, |
| 98 | + address verifier, |
| 99 | + uint256 maxVerifierCut, |
| 100 | + uint256 thawingPeriod |
| 101 | + ) external; |
| 102 | + |
| 103 | + // initiate a thawing to remove tokens from a provision |
| 104 | + function thaw(bytes32 provisionId, uint256 tokens) external returns (bytes32); |
| 105 | + |
| 106 | + // moves thawed stake from a provision back into the provider's available stake |
| 107 | + function deprovision(bytes32 thawRequestId) external; |
| 108 | + |
| 109 | + // moves thawed stake from one provision into another provision |
| 110 | + function reprovision(bytes32 thawRequestId, bytes32 provisionId) external; |
| 111 | + |
| 112 | + // moves thawed stake back to the owner's account - stake is removed from the protocol |
| 113 | + function withdraw(bytes32 thawRequestId) external; |
| 114 | + |
| 115 | + // delegate tokens to a provider |
| 116 | + function delegate(address serviceProvider, uint256 tokens) external; |
| 117 | + |
| 118 | + // undelegate tokens |
| 119 | + function undelegate( |
| 120 | + address serviceProvider, |
| 121 | + uint256 tokens, |
| 122 | + bytes32[] provisions |
| 123 | + ) external returns (bytes32[]); |
| 124 | + |
| 125 | + // slash a service provider |
| 126 | + function slash( |
| 127 | + bytes32 provisionId, |
| 128 | + uint256 tokens, |
| 129 | + uint256 verifierAmount |
| 130 | + ) external; |
| 131 | + |
| 132 | + // set the Service Provider's preferred provisions to be force thawed |
| 133 | + function setForceThawProvisions(bytes32[] provisions); |
| 134 | + |
| 135 | + // total staked tokens to the provider |
| 136 | + // `ServiceProvider.tokensStaked + DelegationPool.serviceProvider.tokens` |
| 137 | + function getStake(address serviceProvider) public view returns (uint256 tokens); |
| 138 | + |
| 139 | + // staked tokens that are currently not provisioned, aka idle stake |
| 140 | + // `getStake(serviceProvider) - ServiceProvider.tokensProvisioned` |
| 141 | + function getIdleStake(address serviceProvider) public view returns (uint256 tokens); |
| 142 | + |
| 143 | + // staked tokens the provider can provision before hitting the delegation cap |
| 144 | + // `ServiceProvider.tokensStaked * Staking.delegationRatio - Provision.tokensProvisioned` |
| 145 | + function getCapacity(address serviceProvider) public view returns (uint256); |
| 146 | + |
| 147 | + // provisioned tokens that are not being used |
| 148 | + // `Provision.tokens - Provision.tokensThawing` |
| 149 | + function getTokensAvailable(bytes32 provision) public view returns (uint256 tokens); |
| 150 | + |
| 151 | + function getServiceProvider(address serviceProvider) |
| 152 | + public |
| 153 | + view |
| 154 | + returns (ServiceProvider memory); |
| 155 | + |
| 156 | + function getProvision(bytes32 provision) public view returns (Provision memory); |
| 157 | +} |
0 commit comments