Skip to content

Commit 8c7e9c7

Browse files
committed
adjust init function specific for arbitrum deployment
1 parent 49b646e commit 8c7e9c7

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
@@ -44,13 +44,10 @@ contract UserProxy {
4444
* Constructor and init functions *
4545
*************************************************************/
4646
/// @dev Replacing constructor and initialize the contract. This function should only be called once.
47-
function initialize(address _limitOrderAddr) external {
48-
require(_limitOrderAddr != address(0), "UserProxy: _limitOrderAddr should not be 0");
49-
require(keccak256(abi.encodePacked(version)) == keccak256(abi.encodePacked("5.2.0")), "UserProxy: not upgrading from version 5.2.0");
50-
51-
// Set Limit Order
52-
LimitOrderStorage.getStorage().limitOrderAddr = _limitOrderAddr;
53-
LimitOrderStorage.getStorage().isEnabled = true;
47+
function initialize(address _operator) external {
48+
require(keccak256(abi.encodePacked(version)) == keccak256(abi.encodePacked("")), "UserProxy: not upgrading from empty");
49+
require(_operator != address(0), "UserProxy: operator can not be zero address");
50+
operator = _operator;
5451

5552
// Upgrade version
5653
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
@@ -19,21 +19,8 @@ contract UserProxyTest is Test {
1919
// Deploy
2020
userProxy = new UserProxy();
2121
strategy = new MockStrategy();
22-
// Setup
2322
// Set this contract as operator
24-
// prettier-ignore
25-
vm.store(
26-
address(userProxy), // address
27-
bytes32(uint256(0)), // key
28-
bytes32(uint256(address(this))) // value
29-
);
30-
// Set version
31-
// prettier-ignore
32-
vm.store(
33-
address(userProxy), // address
34-
bytes32(uint256(1)), // key
35-
bytes32(uint256(bytes32("5.2.0")) + uint256(5 * 2)) // value
36-
);
23+
userProxy.initialize(address(this));
3724

3825
// Deal 100 ETH to each account
3926
deal(user, 100 ether);
@@ -67,15 +54,19 @@ contract UserProxyTest is Test {
6754
*********************************/
6855

6956
function testCannotInitializeToZeroAddress() public {
70-
vm.expectRevert("UserProxy: _limitOrderAddr should not be 0");
71-
userProxy.initialize(address(0));
57+
UserProxy us = new UserProxy();
58+
vm.expectRevert("UserProxy: operator can not be zero address");
59+
us.initialize(address(0));
7260
}
7361

7462
function testCannotInitializeAgain() public {
75-
userProxy.initialize(address(this));
63+
UserProxy up = new UserProxy();
64+
up.initialize(address(this));
65+
assertEq(up.version(), "5.3.0");
66+
assertEq(up.operator(), address(this));
7667

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

8172
/***************************************************

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)