Skip to content

Commit eeb8f5b

Browse files
Merge pull request #43 from consenlabs/rm-version-and-set-init
Adjust init function for new network
2 parents 0efc169 + cc8abb4 commit eeb8f5b

File tree

5 files changed

+34
-77
lines changed

5 files changed

+34
-77
lines changed

contracts/PermanentStorage.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ contract PermanentStorage is IPermanentStorage {
8686
* Constructor and init functions *
8787
*************************************************************/
8888
/// @dev Replacing constructor and initialize the contract. This function should only be called once.
89-
function initialize() external {
90-
require(keccak256(abi.encodePacked(version)) == keccak256(abi.encodePacked("5.2.0")), "PermanentStorage: not upgrading from 5.2.0 version");
91-
// upgrade from 5.2.0 to 5.3.0
89+
function initialize(address _operator) external {
90+
require(keccak256(abi.encodePacked(version)) == keccak256(abi.encodePacked("")), "PermanentStorage: not upgrading from empty");
91+
require(_operator != address(0), "PermanentStorage: operator can not be zero address");
92+
operator = _operator;
93+
94+
// Upgrade version
9295
version = "5.3.0";
9396
}
9497

contracts/UserProxy.sol

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,10 @@ contract UserProxy is Multicall {
4646
* Constructor and init functions *
4747
*************************************************************/
4848
/// @dev Replacing constructor and initialize the contract. This function should only be called once.
49-
function initialize(address _limitOrderAddr) external {
50-
require(_limitOrderAddr != address(0), "UserProxy: _limitOrderAddr should not be 0");
51-
require(keccak256(abi.encodePacked(version)) == keccak256(abi.encodePacked("5.2.0")), "UserProxy: not upgrading from version 5.2.0");
52-
53-
// Set Limit Order
54-
LimitOrderStorage.getStorage().limitOrderAddr = _limitOrderAddr;
55-
LimitOrderStorage.getStorage().isEnabled = true;
49+
function initialize(address _operator) external {
50+
require(keccak256(abi.encodePacked(version)) == keccak256(abi.encodePacked("")), "UserProxy: not upgrading from empty");
51+
require(_operator != address(0), "UserProxy: operator can not be zero address");
52+
operator = _operator;
5653

5754
// Upgrade version
5855
version = "5.3.0";

contracts/test/PermanentStorage.t.sol

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,8 @@ contract PermanentStorageTest is Test {
3737
// Deploy
3838
permanentStorage = new PermanentStorage();
3939
strategy = address(new MockStrategy());
40-
// Setup
4140
// Set this contract as operator
42-
// prettier-ignore
43-
vm.store(
44-
address(permanentStorage), // address
45-
bytes32(uint256(0)), // key
46-
bytes32(uint256(address(this))) // value
47-
);
48-
// Set version
49-
// prettier-ignore
50-
vm.store(
51-
address(permanentStorage), // address
52-
bytes32(uint256(1)), // key
53-
bytes32(uint256(bytes32("5.2.0")) + uint256(5 * 2)) // value
54-
);
41+
permanentStorage.initialize(address(this));
5542

5643
// Label addresses for easier debugging
5744
vm.label(user, "User");
@@ -79,13 +66,20 @@ contract PermanentStorageTest is Test {
7966
/*********************************
8067
* Test: initialize *
8168
*********************************/
69+
function testCannotInitializeToZeroAddress() public {
70+
PermanentStorage ps = new PermanentStorage();
71+
vm.expectRevert("PermanentStorage: operator can not be zero address");
72+
ps.initialize(address(0));
73+
}
8274

8375
function testCannotInitializeAgain() public {
84-
permanentStorage.initialize();
85-
assertEq(permanentStorage.version(), "5.3.0");
76+
PermanentStorage ps = new PermanentStorage();
77+
ps.initialize(address(this));
78+
assertEq(ps.version(), "5.3.0");
79+
assertEq(ps.operator(), address(this));
8680

87-
vm.expectRevert("PermanentStorage: not upgrading from 5.2.0 version");
88-
permanentStorage.initialize();
81+
vm.expectRevert("PermanentStorage: not upgrading from empty");
82+
ps.initialize(address(this));
8983
}
9084

9185
/***********************************

contracts/test/UserProxy.t.sol

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,8 @@ contract UserProxyTest is Test {
2020
// Deploy
2121
userProxy = new UserProxy();
2222
strategy = new MockStrategy();
23-
// Setup
2423
// Set this contract as operator
25-
// prettier-ignore
26-
vm.store(
27-
address(userProxy), // address
28-
bytes32(uint256(0)), // key
29-
bytes32(uint256(address(this))) // value
30-
);
31-
// Set version
32-
// prettier-ignore
33-
vm.store(
34-
address(userProxy), // address
35-
bytes32(uint256(1)), // key
36-
bytes32(uint256(bytes32("5.2.0")) + uint256(5 * 2)) // value
37-
);
24+
userProxy.initialize(address(this));
3825

3926
// Deal 100 ETH to each account
4027
deal(user, 100 ether);
@@ -68,15 +55,19 @@ contract UserProxyTest is Test {
6855
*********************************/
6956

7057
function testCannotInitializeToZeroAddress() public {
71-
vm.expectRevert("UserProxy: _limitOrderAddr should not be 0");
72-
userProxy.initialize(address(0));
58+
UserProxy up = new UserProxy();
59+
vm.expectRevert("UserProxy: operator can not be zero address");
60+
up.initialize(address(0));
7361
}
7462

7563
function testCannotInitializeAgain() public {
76-
userProxy.initialize(address(this));
64+
UserProxy up = new UserProxy();
65+
up.initialize(address(this));
66+
assertEq(up.version(), "5.3.0");
67+
assertEq(up.operator(), address(this));
7768

78-
vm.expectRevert("UserProxy: not upgrading from version 5.2.0");
79-
userProxy.initialize(address(this));
69+
vm.expectRevert("UserProxy: not upgrading from empty");
70+
up.initialize(address(this));
8071
}
8172

8273
/***************************************************

contracts/test/utils/StrategySharedSetup.sol

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,8 @@ contract StrategySharedSetup is BalanceUtil, RegisterCurveIndexes {
3535
bytes("") // Skip initialization during deployment
3636
);
3737
userProxy = UserProxy(address(tokenlon));
38-
39-
// Setup
4038
// Set this contract as operator
41-
// prettier-ignore
42-
vm.store(
43-
address(userProxy), // address
44-
bytes32(uint256(0)), // key
45-
bytes32(uint256(address(this))) // value
46-
);
47-
// Set version
48-
// prettier-ignore
49-
vm.store(
50-
address(userProxy), // address
51-
bytes32(uint256(1)), // key
52-
bytes32(uint256(bytes32("5.2.0")) + uint256(5 * 2)) // value
53-
);
39+
userProxy.initialize(address(this));
5440
}
5541

5642
function _deployPermanentStorageAndProxy() internal {
@@ -61,22 +47,8 @@ contract StrategySharedSetup is BalanceUtil, RegisterCurveIndexes {
6147
bytes("") // Skip initialization during deployment
6248
);
6349
permanentStorage = PermanentStorage(address(permanentStorageProxy));
64-
65-
// Setup
6650
// Set this contract as operator
67-
// prettier-ignore
68-
vm.store(
69-
address(permanentStorage), // address
70-
bytes32(uint256(0)), // key
71-
bytes32(uint256(address(this))) // value
72-
);
73-
// Set version
74-
// prettier-ignore
75-
vm.store(
76-
address(permanentStorage), // address
77-
bytes32(uint256(1)), // key
78-
bytes32(uint256(bytes32("5.2.0")) + uint256(5 * 2)) // value
79-
);
51+
permanentStorage.initialize(address(this));
8052
permanentStorage.upgradeWETH(WETH_ADDRESS);
8153
// Set Curve indexes
8254
permanentStorage.setPermission(permanentStorage.curveTokenIndexStorageId(), address(this), true);

0 commit comments

Comments
 (0)