Skip to content

Commit b105341

Browse files
committed
upgrades: support EIP1967 for Proxy Storage Slots
1 parent 315c12c commit b105341

22 files changed

+271
-130
lines changed

contracts/DisputeManager.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ contract DisputeManager is Governed {
143143
uint256 tokens
144144
);
145145

146+
/**
147+
* @dev Check if the caller is the arbitrator.
148+
*/
146149
modifier onlyArbitrator {
147150
require(msg.sender == arbitrator, "Caller is not the Arbitrator");
148151
_;
@@ -165,6 +168,7 @@ contract DisputeManager is Governed {
165168
uint256 _fishermanRewardPercentage,
166169
uint256 _slashingPercentage
167170
) public {
171+
Governed._initialize(msg.sender);
168172
arbitrator = _arbitrator;
169173
token = IGraphToken(_token);
170174
staking = IStaking(_staking);

contracts/GNS.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ contract GNS is Governed, BancorFormula {
179179
address _curation,
180180
address _token
181181
) public {
182+
Governed._initialize(msg.sender);
182183
erc1056Registry = IEthereumDIDRegistry(_didRegistry);
183184
curation = ICuration(_curation);
184185
token = IGraphToken(_token);

contracts/curation/Curation.sol

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
44

55
import "../governance/Governed.sol";
66
import "../upgrades/GraphProxy.sol";
7+
import "../upgrades/GraphUpgradeable.sol";
78

89
import "./CurationStorage.sol";
910
import "./ICuration.sol";
@@ -20,7 +21,7 @@ import "./ICuration.sol";
2021
* Holders can burn GST tokens using this contract to get GRT tokens back according to the
2122
* bonding curve.
2223
*/
23-
contract Curation is CurationV1Storage, ICuration, Governed {
24+
contract Curation is CurationV1Storage, GraphUpgradeable, ICuration, Governed {
2425
using SafeMath for uint256;
2526

2627
// 100% in parts per million
@@ -61,23 +62,18 @@ contract Curation is CurationV1Storage, ICuration, Governed {
6162
*/
6263
event Collected(bytes32 indexed subgraphDeploymentID, uint256 tokens);
6364

64-
/**
65-
* @dev Check if the caller is the governor or initializing the implementation.
66-
*/
67-
modifier onlyGovernorOrInit {
68-
require(msg.sender == governor || msg.sender == implementation, "Only Governor can call");
69-
_;
70-
}
71-
7265
/**
7366
* @dev Initialize this contract.
7467
*/
7568
function initialize(
69+
address _governor,
7670
address _token,
7771
uint32 _defaultReserveRatio,
7872
uint256 _minimumCurationStake
79-
) external onlyGovernorOrInit {
73+
) external onlyImpl {
74+
Governed._initialize(_governor);
8075
BancorFormula._initialize();
76+
8177
token = IGraphToken(_token);
8278
defaultReserveRatio = _defaultReserveRatio;
8379
minimumCurationStake = _minimumCurationStake;
@@ -96,21 +92,24 @@ contract Curation is CurationV1Storage, ICuration, Governed {
9692
uint32 _defaultReserveRatio,
9793
uint256 _minimumCurationStake
9894
) external {
99-
require(msg.sender == _proxy.governor(), "Only proxy governor can upgrade");
100-
10195
// Accept to be the implementation for this proxy
102-
_proxy.acceptImplementation();
96+
_acceptUpgrade(_proxy);
10397

10498
// Initialization
105-
Curation(address(_proxy)).initialize(_token, _defaultReserveRatio, _minimumCurationStake);
99+
Curation(address(_proxy)).initialize(
100+
_proxy.admin(), // default governor is proxy admin
101+
_token,
102+
_defaultReserveRatio,
103+
_minimumCurationStake
104+
);
106105
}
107106

108107
/**
109108
* @dev Set the staking contract used for fees distribution.
110109
* @notice Update the staking contract to `_staking`
111110
* @param _staking Address of the staking contract
112111
*/
113-
function setStaking(address _staking) external override onlyGovernorOrInit {
112+
function setStaking(address _staking) external override onlyGovernor {
114113
staking = IStaking(_staking);
115114
emit ParameterUpdated("staking");
116115
}
@@ -120,11 +119,7 @@ contract Curation is CurationV1Storage, ICuration, Governed {
120119
* @notice Update the default reserver ratio to `_defaultReserveRatio`
121120
* @param _defaultReserveRatio Reserve ratio (in PPM)
122121
*/
123-
function setDefaultReserveRatio(uint32 _defaultReserveRatio)
124-
external
125-
override
126-
onlyGovernorOrInit
127-
{
122+
function setDefaultReserveRatio(uint32 _defaultReserveRatio) external override onlyGovernor {
128123
// Reserve Ratio must be within 0% to 100% (exclusive, in PPM)
129124
require(_defaultReserveRatio > 0, "Default reserve ratio must be > 0");
130125
require(
@@ -141,11 +136,7 @@ contract Curation is CurationV1Storage, ICuration, Governed {
141136
* @notice Update the minimum stake amount to `_minimumCurationStake`
142137
* @param _minimumCurationStake Minimum amount of tokens required stake
143138
*/
144-
function setMinimumCurationStake(uint256 _minimumCurationStake)
145-
external
146-
override
147-
onlyGovernorOrInit
148-
{
139+
function setMinimumCurationStake(uint256 _minimumCurationStake) external override onlyGovernor {
149140
require(_minimumCurationStake > 0, "Minimum curation stake cannot be 0");
150141
minimumCurationStake = _minimumCurationStake;
151142
emit ParameterUpdated("minimumCurationStake");
@@ -155,7 +146,7 @@ contract Curation is CurationV1Storage, ICuration, Governed {
155146
* @dev Set the fee percentage to charge when a curator withdraws stake.
156147
* @param _percentage Percentage fee charged when withdrawing stake
157148
*/
158-
function setWithdrawalFeePercentage(uint32 _percentage) external override onlyGovernorOrInit {
149+
function setWithdrawalFeePercentage(uint32 _percentage) external override onlyGovernor {
159150
// Must be within 0% to 100% (inclusive)
160151
require(
161152
_percentage <= MAX_PPM,

contracts/curation/CurationStorage.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ pragma solidity ^0.6.4;
33
import "../bancor/BancorFormula.sol";
44
import "../staking/IStaking.sol";
55
import "../token/IGraphToken.sol";
6-
import "../upgrades/GraphProxyStorage.sol";
76

87
import "./GraphSignalToken.sol";
98

10-
contract CurationV1Storage is GraphProxyStorage, BancorFormula {
9+
contract CurationV1Storage is BancorFormula {
1110
// -- Pool --
1211

1312
struct CurationPool {

contracts/epochs/EpochManager.sol

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "@openzeppelin/contracts/math/SafeMath.sol";
44

55
import "../governance/Governed.sol";
66
import "../upgrades/GraphProxy.sol";
7+
import "../upgrades/GraphUpgradeable.sol";
78

89
import "./EpochManagerStorage.sol";
910
import "./IEpochManager.sol";
@@ -12,28 +13,22 @@ import "./IEpochManager.sol";
1213
* @title EpochManager contract
1314
* @dev Tracks epochs based on its block duration to sync contracts in the protocol.
1415
*/
15-
contract EpochManager is EpochManagerV1Storage, IEpochManager, Governed {
16+
contract EpochManager is EpochManagerV1Storage, GraphUpgradeable, IEpochManager, Governed {
1617
using SafeMath for uint256;
1718

1819
// -- Events --
1920

2021
event EpochRun(uint256 indexed epoch, address caller);
2122
event EpochLengthUpdate(uint256 indexed epoch, uint256 epochLength);
2223

23-
/**
24-
* @dev Check if the caller is the governor or initializing the implementation.
25-
*/
26-
modifier onlyGovernorOrInit {
27-
require(msg.sender == governor || msg.sender == implementation, "Only Governor can call");
28-
_;
29-
}
30-
3124
/**
3225
* @dev Initialize this contract.
3326
*/
34-
function initialize(uint256 _epochLength) external onlyGovernorOrInit {
27+
function initialize(address _governor, uint256 _epochLength) external onlyImpl {
3528
require(_epochLength > 0, "Epoch length cannot be 0");
3629

30+
Governed._initialize(_governor);
31+
3732
lastLengthUpdateEpoch = 0;
3833
lastLengthUpdateBlock = blockNum();
3934
epochLength = _epochLength;
@@ -47,13 +42,11 @@ contract EpochManager is EpochManagerV1Storage, IEpochManager, Governed {
4742
* @param _epochLength Epoch length in blocks
4843
*/
4944
function acceptProxy(GraphProxy _proxy, uint256 _epochLength) external {
50-
require(msg.sender == _proxy.governor(), "Only proxy governor can upgrade");
51-
5245
// Accept to be the implementation for this proxy
53-
_proxy.acceptImplementation();
46+
_acceptUpgrade(_proxy);
5447

5548
// Initialization
56-
EpochManager(address(_proxy)).initialize(_epochLength);
49+
EpochManager(address(_proxy)).initialize(_proxy.admin(), _epochLength);
5750
}
5851

5952
/**

contracts/epochs/EpochManagerStorage.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
pragma solidity ^0.6.4;
22

3-
import "../upgrades/GraphProxyStorage.sol";
4-
5-
contract EpochManagerV1Storage is GraphProxyStorage {
3+
contract EpochManagerV1Storage {
64
// -- State --
75

86
// Epoch length in blocks

contracts/governance/Governed.sol

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
pragma solidity ^0.6.4;
22

3-
import "./GovernedStorage.sol";
4-
53
/**
64
* @title Graph Governance contract
75
* @dev All contracts that will be owned by a Governor entity should extend this contract.
86
*/
9-
contract Governed is GovernedStorage {
7+
contract Governed {
8+
// -- State --
9+
10+
address public governor;
11+
address public pendingGovernor;
12+
1013
// -- Events --
1114

1215
event NewPendingOwnership(address indexed from, address indexed to);
@@ -22,10 +25,10 @@ contract Governed is GovernedStorage {
2225
}
2326

2427
/**
25-
* @dev Constructor. Set the governor to the contract caller.
28+
* @dev Initialize the governor to the contract caller.
2629
*/
27-
constructor() public {
28-
governor = msg.sender;
30+
function _initialize(address _governor) internal {
31+
governor = _governor;
2932
}
3033

3134
/**

contracts/governance/GovernedStorage.sol

Lines changed: 0 additions & 11 deletions
This file was deleted.

contracts/staking/Staking.sol

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import "../epochs/IEpochManager.sol";
88
import "../governance/Governed.sol";
99
import "../token/IGraphToken.sol";
1010
import "../upgrades/GraphProxy.sol";
11+
import "../upgrades/GraphUpgradeable.sol";
1112

1213
import "./IStaking.sol";
1314
import "./StakingStorage.sol";
@@ -17,7 +18,7 @@ import "./libs/Stakes.sol";
1718
/**
1819
* @title Staking contract
1920
*/
20-
contract Staking is StakingV1Storage, IStaking, Governed {
21+
contract Staking is StakingV1Storage, GraphUpgradeable, IStaking, Governed {
2122
using SafeMath for uint256;
2223
using Stakes for Stakes.Indexer;
2324
using Rebates for Rebates.Pool;
@@ -168,14 +169,6 @@ contract Staking is StakingV1Storage, IStaking, Governed {
168169
*/
169170
event SetOperator(address indexed indexer, address operator, bool allowed);
170171

171-
/**
172-
* @dev Check if the caller is the governor or initializing the implementation.
173-
*/
174-
modifier onlyGovernorOrInit {
175-
require(msg.sender == governor || msg.sender == implementation, "Only Governor can call");
176-
_;
177-
}
178-
179172
/**
180173
* @dev Check if the caller is the slasher.
181174
*/
@@ -199,11 +192,15 @@ contract Staking is StakingV1Storage, IStaking, Governed {
199192
}
200193

201194
/**
202-
* @dev Staking Contract Constructor.
203-
* @param _token Address of the Graph Protocol token
204-
* @param _epochManager Address of the EpochManager contract
195+
* @dev Initialize this contract.
205196
*/
206-
function initialize(address _token, address _epochManager) external onlyGovernorOrInit {
197+
function initialize(
198+
address _governor,
199+
address _token,
200+
address _epochManager
201+
) external onlyImpl {
202+
Governed._initialize(_governor);
203+
207204
token = IGraphToken(_token);
208205
epochManager = IEpochManager(_epochManager);
209206
}
@@ -219,13 +216,11 @@ contract Staking is StakingV1Storage, IStaking, Governed {
219216
address _token,
220217
address _epochManager
221218
) external {
222-
require(msg.sender == _proxy.governor(), "Only proxy governor can upgrade");
223-
224219
// Accept to be the implementation for this proxy
225-
_proxy.acceptImplementation();
220+
_acceptUpgrade(_proxy);
226221

227222
// Initialization
228-
Staking(address(_proxy)).initialize(_token, _epochManager);
223+
Staking(address(_proxy)).initialize(_proxy.admin(), _token, _epochManager);
229224
}
230225

231226
/**

contracts/staking/StakingStorage.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import "../curation/ICuration.sol";
44
import "../epochs/IEpochManager.sol";
55
import "../staking/IStaking.sol";
66
import "../token/IGraphToken.sol";
7-
import "../upgrades/GraphProxyStorage.sol";
87

98
import "./IStaking.sol";
109
import "./libs/Rebates.sol";
1110
import "./libs/Stakes.sol";
1211

13-
contract StakingV1Storage is GraphProxyStorage {
12+
contract StakingV1Storage {
1413
// -- Staking --
1514

1615
// Time in blocks to unstake

0 commit comments

Comments
 (0)