Skip to content

Commit de1cb2d

Browse files
committed
chore: add first draft IHorizonStaking
1 parent b3b59db commit de1cb2d

File tree

2 files changed

+182
-25
lines changed

2 files changed

+182
-25
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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+
}

yarn.lock

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11343,31 +11343,6 @@ __metadata:
1134311343
languageName: node
1134411344
linkType: hard
1134511345

11346-
"horizon@workspace:packages/horizon":
11347-
version: 0.0.0-use.local
11348-
resolution: "horizon@workspace:packages/horizon"
11349-
dependencies:
11350-
"@nomicfoundation/hardhat-chai-matchers": "npm:^2.0.0"
11351-
"@nomicfoundation/hardhat-ethers": "npm:^3.0.0"
11352-
"@nomicfoundation/hardhat-network-helpers": "npm:^1.0.0"
11353-
"@nomicfoundation/hardhat-toolbox": "npm:^4.0.0"
11354-
"@nomicfoundation/hardhat-verify": "npm:^2.0.0"
11355-
"@typechain/ethers-v6": "npm:^0.5.0"
11356-
"@typechain/hardhat": "npm:^9.0.0"
11357-
"@types/chai": "npm:^4.2.0"
11358-
"@types/mocha": "npm:>=9.1.0"
11359-
"@types/node": "npm:>=16.0.0"
11360-
chai: "npm:^4.2.0"
11361-
ethers: "npm:^6.4.0"
11362-
hardhat: "npm:^2.20.1"
11363-
hardhat-gas-reporter: "npm:^1.0.8"
11364-
solidity-coverage: "npm:^0.8.0"
11365-
ts-node: "npm:>=8.0.0"
11366-
typechain: "npm:^8.3.0"
11367-
typescript: "npm:>=4.5.0"
11368-
languageName: unknown
11369-
linkType: soft
11370-
1137111346
"hosted-git-info@npm:^2.1.4, hosted-git-info@npm:^2.6.0":
1137211347
version: 2.8.9
1137311348
resolution: "hosted-git-info@npm:2.8.9"
@@ -18366,6 +18341,31 @@ __metadata:
1836618341
languageName: node
1836718342
linkType: hard
1836818343

18344+
"subgraph-service@workspace:packages/subgraph-service":
18345+
version: 0.0.0-use.local
18346+
resolution: "subgraph-service@workspace:packages/subgraph-service"
18347+
dependencies:
18348+
"@nomicfoundation/hardhat-chai-matchers": "npm:^2.0.0"
18349+
"@nomicfoundation/hardhat-ethers": "npm:^3.0.0"
18350+
"@nomicfoundation/hardhat-network-helpers": "npm:^1.0.0"
18351+
"@nomicfoundation/hardhat-toolbox": "npm:^4.0.0"
18352+
"@nomicfoundation/hardhat-verify": "npm:^2.0.0"
18353+
"@typechain/ethers-v6": "npm:^0.5.0"
18354+
"@typechain/hardhat": "npm:^9.0.0"
18355+
"@types/chai": "npm:^4.2.0"
18356+
"@types/mocha": "npm:>=9.1.0"
18357+
"@types/node": "npm:>=16.0.0"
18358+
chai: "npm:^4.2.0"
18359+
ethers: "npm:^6.4.0"
18360+
hardhat: "npm:^2.20.1"
18361+
hardhat-gas-reporter: "npm:^1.0.8"
18362+
solidity-coverage: "npm:^0.8.0"
18363+
ts-node: "npm:>=8.0.0"
18364+
typechain: "npm:^8.3.0"
18365+
typescript: "npm:>=4.5.0"
18366+
languageName: unknown
18367+
linkType: soft
18368+
1836918369
"supports-color@npm:8.1.1":
1837018370
version: 8.1.1
1837118371
resolution: "supports-color@npm:8.1.1"

0 commit comments

Comments
 (0)