-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathMigrateAccounting.s.sol
More file actions
122 lines (102 loc) · 5.08 KB
/
MigrateAccounting.s.sol
File metadata and controls
122 lines (102 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.15;
import {Script} from "forge-std/Script.sol";
import {Test} from "forge-std/Test.sol";
import {ZkBobPool, ZkBobPoolUSDC} from "../../src/zkbob/ZkBobPoolUSDC.sol";
import {IZkBobAccounting, IKycProvidersManager, ZkBobAccounting} from "../../src/zkbob/utils/ZkBobAccounting.sol";
import {EIP1967Proxy} from "../../src/proxy/EIP1967Proxy.sol";
import {AccountingMigrator} from "./DeployAccountingMigrator.s.sol";
// WARN: Update this values before running the script
address constant newZkBobPoolImpl = 0x84605eA206A1d5b39f13dC7add690dbD1e038525;
address constant zkBobAccounting = 0xbF3D58f026642951990C0421964179C83E2c9C1B;
address constant accountingMigrator = 0xbfF0020638011357315302727eD55C5193a95F7b;
address constant accountingOwner = 0x14fc6a1a996A2EB889cF86e5c8cD17323bC85290;
/**
* @dev OP-USDC pool proxy address.
*/
address constant zkBobPool = 0x1CA8C2B9B20E18e86d5b9a72370fC6c91814c97C;
// Used to check that the relayer fee is correctly migrated
address constant relayer = 0xb9CD01c0b417b4e9095f620aE2f849A84a9B1690;
contract UpgradeTest is Test {
struct PoolSnapshot {
address proxyAdmin;
address owner;
bytes32 slot0;
bytes32 slot1;
uint256 poolIndex;
uint256 oneNullifier;
uint256 lastRoot;
bytes32 all_messages_hash;
uint256 relayerFee;
address tokenSeller;
address kycManager;
}
function makeSnapshot(ZkBobPoolUSDC _pool) internal view returns (PoolSnapshot memory) {
return PoolSnapshot({
proxyAdmin: EIP1967Proxy(payable(address(_pool))).admin(),
owner: _pool.owner(),
slot0: vm.load(address(_pool), bytes32(uint256(1))),
slot1: vm.load(address(_pool), bytes32(uint256(2))),
poolIndex: _pool.pool_index(),
oneNullifier: _pool.nullifiers(0x39a833a5c374a0a3328f65ae9a9bf883945694cca613a8415c3a555bda388cd),
lastRoot: _pool.roots(_pool.pool_index()),
all_messages_hash: _pool.all_messages_hash(),
relayerFee: _pool.accumulatedFee(relayer),
tokenSeller: address(_pool.tokenSeller()),
kycManager: address(ZkBobAccounting(address(_pool)).kycProvidersManager())
});
}
function postCheck(ZkBobPoolUSDC _pool, PoolSnapshot memory _snapshot) internal {
assertEq(_snapshot.proxyAdmin, EIP1967Proxy(payable(address(_pool))).admin());
assertEq(_snapshot.owner, _pool.owner());
assertEq(address(_pool.redeemer()), address(0)); // redeemer is not set by script
assertNotEq(address(_pool.accounting()), address(0));
assertEq(_snapshot.poolIndex, uint256(_pool.pool_index()));
assertEq(
_snapshot.oneNullifier, _pool.nullifiers(0x39a833a5c374a0a3328f65ae9a9bf883945694cca613a8415c3a555bda388cd)
);
assertEq(_snapshot.lastRoot, _pool.roots(_pool.pool_index()));
assertEq(_snapshot.all_messages_hash, _pool.all_messages_hash());
assertEq(_snapshot.relayerFee, _pool.accumulatedFee(relayer));
assertEq(_snapshot.tokenSeller, address(_pool.tokenSeller()));
assertEq(_snapshot.kycManager, address(ZkBobAccounting(address(_pool.accounting())).kycProvidersManager()));
assertEq(accountingOwner, ZkBobAccounting(address(_pool.accounting())).owner());
checkSlot0(uint256(_snapshot.slot0), ZkBobAccounting(address(_pool.accounting())));
checkSlot1(uint256(_snapshot.slot1), ZkBobAccounting(address(_pool.accounting())));
}
function checkSlot0(uint256 slot0, ZkBobAccounting accounting) internal {
(
uint56 maxWeeklyAvgTvl,
uint32 maxWeeklyTxCount,
uint24 tailSlot,
uint24 headSlot,
uint88 cumTvl,
uint32 txCount
) = accounting.slot0();
uint24 curSlot = uint24(block.timestamp / 1 hours);
assertEq(uint56(slot0), maxWeeklyAvgTvl);
assertEq(uint32(slot0 >> 56), maxWeeklyTxCount);
assertEq(curSlot, tailSlot);
assertEq(curSlot, headSlot);
assertEq(uint88(slot0 >> (56 + 32 + 24 + 24)), cumTvl);
assertEq(uint32(slot0 >> (56 + 32 + 24 + 24 + 88)), txCount);
}
function checkSlot1(uint256 slot1, ZkBobAccounting accounting) internal {
(uint72 tvl) = accounting.slot1();
assertEq(uint72(slot1), tvl);
}
}
contract MigrateAccounting is Script, UpgradeTest {
function run() external {
ZkBobPoolUSDC pool = ZkBobPoolUSDC(address(zkBobPool));
AccountingMigrator migrator = AccountingMigrator(accountingMigrator);
PoolSnapshot memory snapshot = makeSnapshot(pool);
vm.startBroadcast(snapshot.proxyAdmin);
EIP1967Proxy(payable(address(pool))).upgradeTo(address(newZkBobPoolImpl));
EIP1967Proxy(payable(address(pool))).setAdmin(accountingMigrator);
ZkBobAccounting(zkBobAccounting).transferOwnership(accountingMigrator);
migrator.migrate(address(pool), zkBobAccounting, accountingOwner, snapshot.proxyAdmin);
vm.stopBroadcast();
postCheck(ZkBobPoolUSDC(address(pool)), snapshot);
}
}