Skip to content

Commit 766c04d

Browse files
committed
staking: reorg to keep older implemntation contracts
1 parent 708d511 commit 766c04d

File tree

5 files changed

+1796
-44
lines changed

5 files changed

+1796
-44
lines changed

contracts/staking/IStaking.sol

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
pragma solidity >=0.6.12 <0.8.0;
44
pragma experimental ABIEncoderV2;
55

6-
interface IStaking {
6+
import "./IStakingData.sol";
7+
8+
interface IStaking is IStakingData {
79
// -- Allocation Data --
810

911
/**
@@ -17,21 +19,6 @@ interface IStaking {
1719
*/
1820
enum AllocationState { Null, Active, Closed, Finalized, Claimed }
1921

20-
/**
21-
* @dev Allocate GRT tokens for the purpose of serving queries of a subgraph deployment
22-
* An allocation is created in the allocate() function and consumed in claim()
23-
*/
24-
struct Allocation {
25-
address indexer;
26-
bytes32 subgraphDeploymentID;
27-
uint256 tokens; // Tokens allocated to a SubgraphDeployment
28-
uint256 createdAtEpoch; // Epoch when it was created
29-
uint256 closedAtEpoch; // Epoch when it was closed
30-
uint256 collectedFees; // Collected fees for the allocation
31-
uint256 effectiveAllocation; // Effective allocation when closed
32-
uint256 accRewardsPerAllocatedToken; // Snapshot used for reward calc
33-
}
34-
3522
/**
3623
* @dev Represents a request to close an allocation with a specific proof of indexing.
3724
* This is passed when calling closeAllocationMany to define the closing parameters for
@@ -42,30 +29,6 @@ interface IStaking {
4229
bytes32 poi;
4330
}
4431

45-
// -- Delegation Data --
46-
47-
/**
48-
* @dev Delegation pool information. One per indexer.
49-
*/
50-
struct DelegationPool {
51-
uint32 cooldownBlocks; // Blocks to wait before updating parameters
52-
uint32 indexingRewardCut; // in PPM
53-
uint32 queryFeeCut; // in PPM
54-
uint256 updatedAtBlock; // Block when the pool was last updated
55-
uint256 tokens; // Total tokens as pool reserves
56-
uint256 shares; // Total shares minted in the pool
57-
mapping(address => Delegation) delegators; // Mapping of delegator => Delegation
58-
}
59-
60-
/**
61-
* @dev Individual delegation data of a delegator in a pool.
62-
*/
63-
struct Delegation {
64-
uint256 shares; // Shares owned by a delegator in the pool
65-
uint256 tokensLocked; // Tokens locked for undelegation
66-
uint256 tokensLockedUntil; // Block when locked tokens can be withdrawn
67-
}
68-
6932
// -- Configuration --
7033

7134
function setMinimumIndexerStake(uint256 _minimumIndexerStake) external;

contracts/staking/IStakingData.sol

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity >=0.6.12 <0.8.0;
4+
pragma experimental ABIEncoderV2;
5+
6+
interface IStakingData {
7+
/**
8+
* @dev Allocate GRT tokens for the purpose of serving queries of a subgraph deployment
9+
* An allocation is created in the allocate() function and consumed in claim()
10+
*/
11+
struct Allocation {
12+
address indexer;
13+
bytes32 subgraphDeploymentID;
14+
uint256 tokens; // Tokens allocated to a SubgraphDeployment
15+
uint256 createdAtEpoch; // Epoch when it was created
16+
uint256 closedAtEpoch; // Epoch when it was closed
17+
uint256 collectedFees; // Collected fees for the allocation
18+
uint256 effectiveAllocation; // Effective allocation when closed
19+
uint256 accRewardsPerAllocatedToken; // Snapshot used for reward calc
20+
}
21+
22+
// -- Delegation Data --
23+
24+
/**
25+
* @dev Delegation pool information. One per indexer.
26+
*/
27+
struct DelegationPool {
28+
uint32 cooldownBlocks; // Blocks to wait before updating parameters
29+
uint32 indexingRewardCut; // in PPM
30+
uint32 queryFeeCut; // in PPM
31+
uint256 updatedAtBlock; // Block when the pool was last updated
32+
uint256 tokens; // Total tokens as pool reserves
33+
uint256 shares; // Total shares minted in the pool
34+
mapping(address => Delegation) delegators; // Mapping of delegator => Delegation
35+
}
36+
37+
/**
38+
* @dev Individual delegation data of a delegator in a pool.
39+
*/
40+
struct Delegation {
41+
uint256 shares; // Shares owned by a delegator in the pool
42+
uint256 tokensLocked; // Tokens locked for undelegation
43+
uint256 tokensLockedUntil; // Block when locked tokens can be withdrawn
44+
}
45+
}

contracts/staking/IStakingV1.sol

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity >=0.6.12 <0.8.0;
4+
pragma experimental ABIEncoderV2;
5+
6+
import "./IStakingData.sol";
7+
8+
interface IStakingV1 is IStakingData {
9+
// -- Allocation Data --
10+
11+
/**
12+
* @dev Possible states an allocation can be
13+
* States:
14+
* - Null = indexer == address(0)
15+
* - Active = not Null && tokens > 0
16+
* - Closed = Active && closedAtEpoch != 0
17+
* - Finalized = Closed && closedAtEpoch + channelDisputeEpochs > now()
18+
* - Claimed = not Null && tokens == 0
19+
*/
20+
enum AllocationState { Null, Active, Closed, Finalized, Claimed }
21+
22+
/**
23+
* @dev Represents a request to close an allocation with a specific proof of indexing.
24+
* This is passed when calling closeAllocationMany to define the closing parameters for
25+
* each allocation.
26+
*/
27+
struct CloseAllocationRequest {
28+
address allocationID;
29+
bytes32 poi;
30+
}
31+
32+
// -- Configuration --
33+
34+
function setMinimumIndexerStake(uint256 _minimumIndexerStake) external;
35+
36+
function setThawingPeriod(uint32 _thawingPeriod) external;
37+
38+
function setCurationPercentage(uint32 _percentage) external;
39+
40+
function setProtocolPercentage(uint32 _percentage) external;
41+
42+
function setChannelDisputeEpochs(uint32 _channelDisputeEpochs) external;
43+
44+
function setMaxAllocationEpochs(uint32 _maxAllocationEpochs) external;
45+
46+
function setRebateRatio(uint32 _alphaNumerator, uint32 _alphaDenominator) external;
47+
48+
function setDelegationRatio(uint32 _delegationRatio) external;
49+
50+
function setDelegationParameters(
51+
uint32 _indexingRewardCut,
52+
uint32 _queryFeeCut,
53+
uint32 _cooldownBlocks
54+
) external;
55+
56+
function setDelegationParametersCooldown(uint32 _blocks) external;
57+
58+
function setDelegationUnbondingPeriod(uint32 _delegationUnbondingPeriod) external;
59+
60+
function setDelegationTaxPercentage(uint32 _percentage) external;
61+
62+
function setSlasher(address _slasher, bool _allowed) external;
63+
64+
function setAssetHolder(address _assetHolder, bool _allowed) external;
65+
66+
// -- Operation --
67+
68+
function setOperator(address _operator, bool _allowed) external;
69+
70+
function isOperator(address _operator, address _indexer) external view returns (bool);
71+
72+
// -- Staking --
73+
74+
function stake(uint256 _tokens) external;
75+
76+
function stakeTo(address _indexer, uint256 _tokens) external;
77+
78+
function unstake(uint256 _tokens) external;
79+
80+
function slash(
81+
address _indexer,
82+
uint256 _tokens,
83+
uint256 _reward,
84+
address _beneficiary
85+
) external;
86+
87+
function withdraw() external;
88+
89+
// -- Delegation --
90+
91+
function delegate(address _indexer, uint256 _tokens) external returns (uint256);
92+
93+
function undelegate(address _indexer, uint256 _shares) external returns (uint256);
94+
95+
function withdrawDelegated(address _indexer, address _newIndexer) external returns (uint256);
96+
97+
// -- Channel management and allocations --
98+
99+
function allocate(
100+
bytes32 _subgraphDeploymentID,
101+
uint256 _tokens,
102+
address _allocationID,
103+
bytes32 _metadata,
104+
bytes calldata _proof
105+
) external;
106+
107+
function allocateFrom(
108+
address _indexer,
109+
bytes32 _subgraphDeploymentID,
110+
uint256 _tokens,
111+
address _allocationID,
112+
bytes32 _metadata,
113+
bytes calldata _proof
114+
) external;
115+
116+
function closeAllocation(address _allocationID, bytes32 _poi) external;
117+
118+
function closeAllocationMany(CloseAllocationRequest[] calldata _requests) external;
119+
120+
function closeAndAllocate(
121+
address _oldAllocationID,
122+
bytes32 _poi,
123+
address _indexer,
124+
bytes32 _subgraphDeploymentID,
125+
uint256 _tokens,
126+
address _allocationID,
127+
bytes32 _metadata,
128+
bytes calldata _proof
129+
) external;
130+
131+
function collect(uint256 _tokens, address _allocationID) external;
132+
133+
function claim(address _allocationID, bool _restake) external;
134+
135+
function claimMany(address[] calldata _allocationID, bool _restake) external;
136+
137+
// -- Getters and calculations --
138+
139+
function hasStake(address _indexer) external view returns (bool);
140+
141+
function getIndexerStakedTokens(address _indexer) external view returns (uint256);
142+
143+
function getIndexerCapacity(address _indexer) external view returns (uint256);
144+
145+
function getAllocation(address _allocationID) external view returns (Allocation memory);
146+
147+
function getAllocationState(address _allocationID) external view returns (AllocationState);
148+
149+
function isAllocation(address _allocationID) external view returns (bool);
150+
151+
function getSubgraphAllocatedTokens(bytes32 _subgraphDeploymentID)
152+
external
153+
view
154+
returns (uint256);
155+
156+
function getDelegation(address _indexer, address _delegator)
157+
external
158+
view
159+
returns (Delegation memory);
160+
161+
function isDelegator(address _indexer, address _delegator) external view returns (bool);
162+
}

contracts/staking/StakingStorage.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
pragma solidity ^0.7.3;
44

55
import "../governance/Managed.sol";
6-
import "../staking/IStaking.sol";
7-
import "./IStaking.sol";
6+
7+
import "./IStakingData.sol";
88
import "./libs/Rebates.sol";
99
import "./libs/Stakes.sol";
1010

@@ -39,7 +39,7 @@ contract StakingV1Storage is Managed {
3939
mapping(address => Stakes.Indexer) public stakes;
4040

4141
// Allocations : allocationID => Allocation
42-
mapping(address => IStaking.Allocation) public allocations;
42+
mapping(address => IStakingData.Allocation) public allocations;
4343

4444
// Subgraph Allocations: subgraphDeploymentID => tokens
4545
mapping(bytes32 => uint256) public subgraphAllocations;
@@ -70,7 +70,7 @@ contract StakingV1Storage is Managed {
7070
uint32 public delegationTaxPercentage;
7171

7272
// Delegation pools : indexer => DelegationPool
73-
mapping(address => IStaking.DelegationPool) public delegationPools;
73+
mapping(address => IStakingData.DelegationPool) public delegationPools;
7474

7575
// -- Operators --
7676

0 commit comments

Comments
 (0)