-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
137 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
pragma solidity 0.8.15; | ||
|
||
import {console, Script} from "forge-std/Script.sol"; | ||
import {ZkBobPoolUSDC} from "../../src/zkbob/ZkBobPoolUSDC.sol"; | ||
import {ZkBobAccounting} from "../../src/zkbob/utils/ZkBobAccounting.sol"; | ||
import {EIP1967Proxy} from "../../src/proxy/EIP1967Proxy.sol"; | ||
import {AccountingMigrator} from "./helpers/AccountingMigrator.sol"; | ||
|
||
/** | ||
* @dev OP-USDC pool proxy address. | ||
*/ | ||
address constant zkBobPool = 0x1CA8C2B9B20E18e86d5b9a72370fC6c91814c97C; | ||
|
||
/** | ||
* @dev The address of the timelock | ||
*/ | ||
address constant zkBobTimelock = 0xbe7D4E55D80fC3e67D80ebf988eB0E551cCA4eB7; | ||
|
||
/** | ||
* @dev Don't forget to set ZkBobPool.TOKEN_NUMERATOR to 1000 for USDC pools. | ||
*/ | ||
contract PreMigrateAccounting is Script { | ||
function run() external { | ||
ZkBobPoolUSDC pool = ZkBobPoolUSDC(address(zkBobPool)); | ||
|
||
vm.startBroadcast(); | ||
|
||
// 1. Deploy new ZkBobPoolUSDC implementation | ||
ZkBobPoolUSDC newImpl = new ZkBobPoolUSDC( | ||
pool.pool_id(), | ||
pool.token(), | ||
pool.transfer_verifier(), | ||
pool.tree_verifier(), | ||
pool.batch_deposit_verifier(), | ||
address(pool.direct_deposit_queue()) | ||
); | ||
|
||
// 2. Deploy new ZkBobAccounting implementation | ||
ZkBobAccounting accounting = new ZkBobAccounting(address(pool), 1_000_000_000); | ||
|
||
// 3. Set timelock as the owner of the accounting | ||
accounting.transferOwnership(zkBobTimelock); | ||
|
||
// 4. Deploy one-time Migrator | ||
AccountingMigrator migrator = new AccountingMigrator(); | ||
|
||
vm.stopBroadcast(); | ||
|
||
assert(accounting.owner() == zkBobTimelock); | ||
|
||
console.log("ZkBobPool implementation:", address(newImpl)); | ||
console.log("ZkBobAccounting: ", address(accounting)); | ||
console.log("AccountingMigrator: ", address(migrator)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: CC0-1.0 | ||
|
||
pragma solidity 0.8.15; | ||
|
||
import {ZkBobPool} from "../../../src/zkbob/ZkBobPoolUSDC.sol"; | ||
import {IZkBobAccounting, IKycProvidersManager, ZkBobAccounting} from "../../../src/zkbob/utils/ZkBobAccounting.sol"; | ||
import {EIP1967Proxy} from "../../../src/proxy/EIP1967Proxy.sol"; | ||
|
||
contract AccountingMigrator { | ||
constructor() {} | ||
|
||
// TODO: Check limits | ||
function migrate( | ||
address _pool, | ||
address _accounting, | ||
address _kycManager, | ||
address _accountingOwner, | ||
address _proxyAdmin | ||
) | ||
external | ||
{ | ||
ZkBobAccounting accounting = ZkBobAccounting(_accounting); | ||
|
||
bytes memory dump = ZkBobPool(_pool).extsload(bytes32(uint256(1)), 2); | ||
uint32 txCount = uint32(_load(dump, 0, 4)); | ||
uint88 cumTvl = uint88(_load(dump, 4, 11)); | ||
uint32 maxWeeklyTxCount = uint32(_load(dump, 21, 4)); | ||
uint56 maxWeeklyAvgTvl = uint56(_load(dump, 25, 7)); | ||
uint72 tvl = uint72(_load(dump, 55, 9)); | ||
|
||
ZkBobPool(_pool).initializePoolIndex(txCount * 128); | ||
ZkBobPool(_pool).setAccounting(IZkBobAccounting(accounting)); | ||
|
||
accounting.initialize(txCount, tvl, cumTvl, maxWeeklyTxCount, maxWeeklyAvgTvl); | ||
accounting.setKycProvidersManager(IKycProvidersManager(_kycManager)); | ||
accounting.setLimits( | ||
0, 2_000_000 gwei, 300_000 gwei, 300_000 gwei, 10_000 gwei, 10_000 gwei, 10_000 gwei, 1_000 gwei | ||
); | ||
accounting.setLimits( | ||
1, 2_000_000 gwei, 300_000 gwei, 300_000 gwei, 100_000 gwei, 100_000 gwei, 10_000 gwei, 1_000 gwei | ||
); | ||
accounting.setLimits( | ||
254, 2_000_000 gwei, 300_000 gwei, 300_000 gwei, 20_000 gwei, 20_000 gwei, 10_000 gwei, 1_000 gwei | ||
); | ||
|
||
accounting.transferOwnership(_accountingOwner); | ||
EIP1967Proxy(payable(address(_pool))).setAdmin(_proxyAdmin); | ||
} | ||
|
||
function _load(bytes memory _dump, uint256 _from, uint256 _len) internal pure returns (uint256 res) { | ||
assembly { | ||
res := shr(sub(256, shl(3, _len)), mload(add(_dump, add(32, _from)))) | ||
} | ||
} | ||
} |