diff --git a/script/scripts/DeployZkBobPoolModules.s.sol b/script/scripts/DeployZkBobPoolModules.s.sol deleted file mode 100644 index 1715179..0000000 --- a/script/scripts/DeployZkBobPoolModules.s.sol +++ /dev/null @@ -1,85 +0,0 @@ -// SPDX-License-Identifier: CC0-1.0 - -pragma solidity 0.8.15; - -import "forge-std/Script.sol"; -import "forge-std/Test.sol"; -import "./Env.s.sol"; -import "../../src/zkbob/ZkBobPool.sol"; -import "../../src/zkbob/utils/ZkBobAccounting.sol"; -import "../../src/proxy/EIP1967Proxy.sol"; -import "../../src/zkbob/ZkBobPoolUSDC.sol"; - -contract DummyDelegateCall { - function delegate(address to, bytes calldata data) external { - (bool status,) = address(to).delegatecall(data); - require(status); - } -} - -contract Migrator { - function migrate(address _target, address _newImpl, address _accounting) external { - address kycManager = address(ZkBobAccounting(_target).kycProvidersManager()); - - EIP1967Proxy(payable(_target)).upgradeTo(_newImpl); - - bytes memory dump = ZkBobPool(_target).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(_target).initializePoolIndex(txCount * 128); - ZkBobPool(_target).setAccounting(IZkBobAccounting(_accounting)); - ZkBobAccounting(_accounting).initialize(txCount + 1, tvl, cumTvl, maxWeeklyTxCount, maxWeeklyAvgTvl); - ZkBobAccounting(_accounting).setKycProvidersManager(IKycProvidersManager(kycManager)); - ZkBobAccounting(_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 - ); - ZkBobAccounting(_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 - ); - ZkBobAccounting(_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 - ); - } - - function _load(bytes memory _dump, uint256 _from, uint256 _len) internal returns (uint256 res) { - assembly { - res := shr(sub(256, shl(3, _len)), mload(add(_dump, add(32, _from)))) - } - } -} - -contract DeployZkBobPoolModules is Script, Test { - function run() external { - ZkBobPoolUSDC pool = ZkBobPoolUSDC(address(zkBobPool)); - address owner = pool.owner(); - vm.etch(owner, type(DummyDelegateCall).runtimeCode); - - address tokenSeller = address(pool.tokenSeller()); - uint256 poolIndex = uint256(pool.pool_index()); - - vm.startBroadcast(); - - ZkBobPoolUSDC impl = new ZkBobPoolUSDC( - pool.pool_id(), pool.token(), pool.transfer_verifier(), pool.tree_verifier(), - pool.batch_deposit_verifier(), address(pool.direct_deposit_queue()) - ); - Migrator mig = new Migrator(); - ZkBobAccounting acc = new ZkBobAccounting(address(pool), 1_000_000_000); - acc.transferOwnership(owner); - DummyDelegateCall(owner).delegate( - address(mig), abi.encodeWithSelector(Migrator.migrate.selector, address(pool), address(impl), address(acc)) - ); - - vm.stopBroadcast(); - - acc.slot0(); - acc.slot1(); - - assertEq(address(pool.tokenSeller()), tokenSeller); - assertEq(uint256(pool.pool_index()), poolIndex); - } -} diff --git a/script/scripts/Local.s.sol b/script/scripts/Local.s.sol index 7f33ba5..eac51bc 100644 --- a/script/scripts/Local.s.sol +++ b/script/scripts/Local.s.sol @@ -45,12 +45,7 @@ contract DeployLocal is Script { EIP1967Proxy queueProxy = new EIP1967Proxy(tx.origin, mockImpl, ""); ZkBobPoolBOB poolImpl = new ZkBobPoolBOB( - zkBobPoolId, - address(bob), - transferVerifier, - treeVerifier, - batchDepositVerifier, - address(queueProxy) + zkBobPoolId, address(bob), transferVerifier, treeVerifier, batchDepositVerifier, address(queueProxy) ); { bytes memory initData = abi.encodeWithSelector(ZkBobPool.initialize.selector, zkBobInitialRoot); diff --git a/script/scripts/MigrateAccounting.s.sol b/script/scripts/MigrateAccounting.s.sol index fd84bd5..ff2acd4 100644 --- a/script/scripts/MigrateAccounting.s.sol +++ b/script/scripts/MigrateAccounting.s.sol @@ -94,6 +94,9 @@ contract UpgradeTest is Test { } } +/** + * @dev Don't forget to set ZkBobPool.TOKEN_NUMERATOR to 1000 for USDC pools. + */ contract MigrateAccounting is Script, UpgradeTest { function run() external { ZkBobPoolUSDC pool = ZkBobPoolUSDC(address(zkBobPool)); @@ -164,4 +167,4 @@ contract MigrateAccounting is Script, UpgradeTest { res := shr(sub(256, shl(3, _len)), mload(add(_dump, add(32, _from)))) } } -} \ No newline at end of file +} diff --git a/script/scripts/ZkBobPool.s.sol b/script/scripts/ZkBobPool.s.sol index 337c156..037ea91 100644 --- a/script/scripts/ZkBobPool.s.sol +++ b/script/scripts/ZkBobPool.s.sol @@ -53,27 +53,31 @@ contract DeployZkBobPool is Script { if (zkBobPoolType == PoolType.ETH) { vars.poolImpl = new ZkBobPoolETH( - zkBobPoolId, zkBobToken, - transferVerifier, treeVerifier, batchDepositVerifier, - address(vars.queueProxy), permit2 + zkBobPoolId, + zkBobToken, + transferVerifier, + treeVerifier, + batchDepositVerifier, + address(vars.queueProxy), + permit2 ); } else if (zkBobPoolType == PoolType.BOB) { vars.poolImpl = new ZkBobPoolBOB( - zkBobPoolId, zkBobToken, - transferVerifier, treeVerifier, batchDepositVerifier, - address(vars.queueProxy) + zkBobPoolId, zkBobToken, transferVerifier, treeVerifier, batchDepositVerifier, address(vars.queueProxy) ); } else if (zkBobPoolType == PoolType.USDC) { vars.poolImpl = new ZkBobPoolUSDC( - zkBobPoolId, zkBobToken, - transferVerifier, treeVerifier, batchDepositVerifier, - address(vars.queueProxy) + zkBobPoolId, zkBobToken, transferVerifier, treeVerifier, batchDepositVerifier, address(vars.queueProxy) ); } else if (zkBobPoolType == PoolType.ERC20) { vars.poolImpl = new ZkBobPoolERC20( - zkBobPoolId, zkBobToken, - transferVerifier, treeVerifier, batchDepositVerifier, - address(vars.queueProxy), permit2, + zkBobPoolId, + zkBobToken, + transferVerifier, + treeVerifier, + batchDepositVerifier, + address(vars.queueProxy), + permit2, vars.denominator ); } else { diff --git a/src/interfaces/IZkBobDirectDeposits.sol b/src/interfaces/IZkBobDirectDeposits.sol index 51caf36..72eedab 100644 --- a/src/interfaces/IZkBobDirectDeposits.sol +++ b/src/interfaces/IZkBobDirectDeposits.sol @@ -8,6 +8,7 @@ interface IZkBobDirectDeposits { Pending, // requested deposit was submitted and is pending in the queue Completed, // requested deposit was successfully processed Refunded // requested deposit was refunded to the fallback receiver + } struct DirectDeposit { diff --git a/src/zkbob/ZkBobPool.sol b/src/zkbob/ZkBobPool.sol index 6f79da1..fb89938 100644 --- a/src/zkbob/ZkBobPool.sol +++ b/src/zkbob/ZkBobPool.sol @@ -38,7 +38,7 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Ex uint256 internal constant FORCED_EXIT_MAX_DELAY = 24 hours; uint256 internal immutable TOKEN_DENOMINATOR; - uint256 internal constant TOKEN_NUMERATOR = 1000; + uint256 internal constant TOKEN_NUMERATOR = 1; uint256 public immutable pool_id; ITransferVerifier public immutable transfer_verifier; diff --git a/test/zkbob/ZkBobPool.t.sol b/test/zkbob/ZkBobPool.t.sol index 8428f9b..ceecd01 100644 --- a/test/zkbob/ZkBobPool.t.sol +++ b/test/zkbob/ZkBobPool.t.sol @@ -95,27 +95,42 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest { ZkBobPool impl; if (poolType == PoolType.ETH) { impl = new ZkBobPoolETH( - 0, token, - new TransferVerifierMock(), new TreeUpdateVerifierMock(), new BatchDepositVerifierMock(), - address(queueProxy), permit2 + 0, + token, + new TransferVerifierMock(), + new TreeUpdateVerifierMock(), + new BatchDepositVerifierMock(), + address(queueProxy), + permit2 ); } else if (poolType == PoolType.BOB) { impl = new ZkBobPoolBOB( - 0, token, - new TransferVerifierMock(), new TreeUpdateVerifierMock(), new BatchDepositVerifierMock(), + 0, + token, + new TransferVerifierMock(), + new TreeUpdateVerifierMock(), + new BatchDepositVerifierMock(), address(queueProxy) ); } else if (poolType == PoolType.USDC) { impl = new ZkBobPoolUSDC( - 0, token, - new TransferVerifierMock(), new TreeUpdateVerifierMock(), new BatchDepositVerifierMock(), + 0, + token, + new TransferVerifierMock(), + new TreeUpdateVerifierMock(), + new BatchDepositVerifierMock(), address(queueProxy) ); } else if (poolType == PoolType.ERC20) { impl = new ZkBobPoolERC20( - 0, token, - new TransferVerifierMock(), new TreeUpdateVerifierMock(), new BatchDepositVerifierMock(), - address(queueProxy), permit2, 1_000_000_000 + 0, + token, + new TransferVerifierMock(), + new TreeUpdateVerifierMock(), + new BatchDepositVerifierMock(), + address(queueProxy), + permit2, + 1_000_000_000 ); }