From 1f7f34aab2984a129e5d55fc2b30f13a0e532777 Mon Sep 17 00:00:00 2001 From: agusduha Date: Mon, 23 Dec 2024 17:26:19 -0300 Subject: [PATCH 1/3] feat: liquidity migrator deployment --- .../interfaces/L1/ILiquidityMigrator.sol | 6 +++ .../scripts/deploy/ChainAssertions.sol | 8 +++ .../scripts/deploy/Deploy.s.sol | 7 +++ .../scripts/deploy/DeploySuperchain.s.sol | 34 +++++++++++-- .../contracts-bedrock/snapshots/.gas-snapshot | 4 +- .../snapshots/abi/LiquidityMigrator.json | 26 ++++++++++ .../snapshots/semver-lock.json | 4 ++ .../src/L1/LiquidityMigrator.sol | 10 +++- .../test/L1/LiquidityMigrator.t.sol | 50 +++++++++++++++---- .../test/opcm/DeploySuperchain.t.sol | 12 +++++ .../contracts-bedrock/test/setup/Setup.sol | 4 ++ .../test/universal/Specs.t.sol | 2 + 12 files changed, 149 insertions(+), 18 deletions(-) diff --git a/packages/contracts-bedrock/interfaces/L1/ILiquidityMigrator.sol b/packages/contracts-bedrock/interfaces/L1/ILiquidityMigrator.sol index 5c3cd7b03a92..f66b142bfdc6 100644 --- a/packages/contracts-bedrock/interfaces/L1/ILiquidityMigrator.sol +++ b/packages/contracts-bedrock/interfaces/L1/ILiquidityMigrator.sol @@ -1,6 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; +import { ISharedLockbox } from "interfaces/L1/ISharedLockbox.sol"; + /// @title ILiquidityMigrator /// @notice Interface for the LiquidityMigrator contract interface ILiquidityMigrator { @@ -8,5 +10,9 @@ interface ILiquidityMigrator { function __constructor__(address _sharedLockbox) external; + function SHARED_LOCKBOX() external view returns (ISharedLockbox); + function migrateETH() external; + + function version() external view returns (string memory); } diff --git a/packages/contracts-bedrock/scripts/deploy/ChainAssertions.sol b/packages/contracts-bedrock/scripts/deploy/ChainAssertions.sol index d9912bde6ed6..fc8cd599bf51 100644 --- a/packages/contracts-bedrock/scripts/deploy/ChainAssertions.sol +++ b/packages/contracts-bedrock/scripts/deploy/ChainAssertions.sol @@ -24,6 +24,7 @@ import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol"; import { IL2OutputOracle } from "interfaces/L1/IL2OutputOracle.sol"; import { ISuperchainConfig } from "interfaces/L1/ISuperchainConfig.sol"; import { ISharedLockbox } from "interfaces/L1/ISharedLockbox.sol"; +import { ILiquidityMigrator } from "interfaces/L1/ILiquidityMigrator.sol"; import { IL1CrossDomainMessenger } from "interfaces/L1/IL1CrossDomainMessenger.sol"; import { IOptimismPortal } from "interfaces/L1/IOptimismPortal.sol"; import { IOptimismPortal2 } from "interfaces/L1/IOptimismPortal2.sol"; @@ -601,4 +602,11 @@ library ChainAssertions { require(address(sharedLockbox) != address(0), "CHECK-SLB-10"); require(sharedLockbox.SUPERCHAIN_CONFIG() == superchainConfig, "CHECK-SLB-20"); } + + /// @notice Asserts that the LiquidityMigrator is setup correctly + function checkLiquidityMigrator(Types.ContractSet memory _contracts, address _liquidityMigrator) internal view { + ISharedLockbox sharedLockbox = ISharedLockbox(_contracts.SharedLockbox); + + require(ILiquidityMigrator(_liquidityMigrator).SHARED_LOCKBOX() == sharedLockbox, "LM-10"); + } } diff --git a/packages/contracts-bedrock/scripts/deploy/Deploy.s.sol b/packages/contracts-bedrock/scripts/deploy/Deploy.s.sol index b9f86088d4ef..223421aaca64 100644 --- a/packages/contracts-bedrock/scripts/deploy/Deploy.s.sol +++ b/packages/contracts-bedrock/scripts/deploy/Deploy.s.sol @@ -296,6 +296,7 @@ contract Deploy is Deployer { save("ProtocolVersions", address(dso.protocolVersionsImpl())); save("SharedLockboxProxy", address(dso.sharedLockboxProxy())); save("SharedLockbox", address(dso.sharedLockboxImpl())); + save("LiquidityMigrator", address(dso.liquidityMigratorImpl())); // First run assertions for the ProtocolVersions, SuperchainConfig and SharedLockbox proxy contracts. Types.ContractSet memory contracts = _proxies(); @@ -303,6 +304,12 @@ contract Deploy is Deployer { ChainAssertions.checkSuperchainConfig({ _contracts: contracts, _cfg: cfg, _isProxy: true, _isPaused: false }); ChainAssertions.checkSharedLockbox({ _contracts: contracts, _isProxy: true }); + // Test the LiquidityMigrator contract is setup correctly. + ChainAssertions.checkLiquidityMigrator({ + _contracts: contracts, + _liquidityMigrator: mustGetAddress("LiquidityMigrator") + }); + // Then replace the SharedLockbox proxy with the implementation address and run assertions on it. contracts.SharedLockbox = mustGetAddress("SharedLockbox"); ChainAssertions.checkSharedLockbox({ _contracts: contracts, _isProxy: false }); diff --git a/packages/contracts-bedrock/scripts/deploy/DeploySuperchain.s.sol b/packages/contracts-bedrock/scripts/deploy/DeploySuperchain.s.sol index d2f33c034103..fcb2b5005d6a 100644 --- a/packages/contracts-bedrock/scripts/deploy/DeploySuperchain.s.sol +++ b/packages/contracts-bedrock/scripts/deploy/DeploySuperchain.s.sol @@ -9,6 +9,7 @@ import { IProtocolVersions, ProtocolVersion } from "interfaces/L1/IProtocolVersi import { IProxyAdmin } from "interfaces/universal/IProxyAdmin.sol"; import { IProxy } from "interfaces/universal/IProxy.sol"; import { ISharedLockbox } from "interfaces/L1/ISharedLockbox.sol"; +import { ILiquidityMigrator } from "interfaces/L1/ILiquidityMigrator.sol"; import { DeployUtils } from "scripts/libraries/DeployUtils.sol"; import { Solarray } from "scripts/libraries/Solarray.sol"; @@ -165,6 +166,7 @@ contract DeploySuperchainOutput is BaseDeployIO { IProxyAdmin internal _superchainProxyAdmin; ISharedLockbox internal _sharedLockboxImpl; ISharedLockbox internal _sharedLockboxProxy; + ILiquidityMigrator internal _liquidityMigratorImpl; // This method lets each field be set individually. The selector of an output's getter method // is used to determine which field to set. @@ -177,6 +179,7 @@ contract DeploySuperchainOutput is BaseDeployIO { else if (_sel == this.protocolVersionsProxy.selector) _protocolVersionsProxy = IProtocolVersions(_address); else if (_sel == this.sharedLockboxImpl.selector) _sharedLockboxImpl = ISharedLockbox(_address); else if (_sel == this.sharedLockboxProxy.selector) _sharedLockboxProxy = ISharedLockbox(_address); + else if (_sel == this.liquidityMigratorImpl.selector) _liquidityMigratorImpl = ILiquidityMigrator(_address); else revert("DeploySuperchainOutput: unknown selector"); } @@ -190,7 +193,8 @@ contract DeploySuperchainOutput is BaseDeployIO { address(this.protocolVersionsImpl()), address(this.protocolVersionsProxy()), address(this.sharedLockboxImpl()), - address(this.sharedLockboxProxy()) + address(this.sharedLockboxProxy()), + address(this.liquidityMigratorImpl()) ); DeployUtils.assertValidContractAddresses(addrs); @@ -246,12 +250,18 @@ contract DeploySuperchainOutput is BaseDeployIO { return _sharedLockboxProxy; } + function liquidityMigratorImpl() public view returns (ILiquidityMigrator) { + DeployUtils.assertValidContractAddress(address(_liquidityMigratorImpl)); + return _liquidityMigratorImpl; + } + // -------- Deployment Assertions -------- function assertValidDeploy(DeploySuperchainInput _dsi) public { assertValidSuperchainProxyAdmin(_dsi); assertValidSuperchainConfig(_dsi); assertValidProtocolVersions(_dsi); assertValidSharedLockbox(); + assertValidLiquidityMigrator(); } function assertValidSuperchainProxyAdmin(DeploySuperchainInput _dsi) internal view { @@ -322,6 +332,12 @@ contract DeploySuperchainOutput is BaseDeployIO { sl = sharedLockboxImpl(); require(sl.SUPERCHAIN_CONFIG() == superchainConfigProxy(), "SLB-40"); } + + function assertValidLiquidityMigrator() internal view { + // Implementation checks. + ILiquidityMigrator lm = liquidityMigratorImpl(); + require(lm.SHARED_LOCKBOX() == sharedLockboxProxy(), "LM-10"); + } } // For all broadcasts in this script we explicitly specify the deployer as `msg.sender` because for @@ -383,8 +399,8 @@ contract DeploySuperchain is Script { function deploySuperchain(DeploySuperchainInput _dsi, DeploySuperchainOutput _dso) public { // Precalculate the proxies addresses. Needed since there are circular dependencies between them. PrecalculatedAddresses memory precalculatedAddresses; - precalculatedAddresses.superchainConfigProxy = vm.computeCreateAddress(msg.sender, vm.getNonce(msg.sender) + 3); - precalculatedAddresses.sharedLockboxProxy = vm.computeCreateAddress(msg.sender, vm.getNonce(msg.sender) + 7); + precalculatedAddresses.superchainConfigProxy = vm.computeCreateAddress(msg.sender, vm.getNonce(msg.sender) + 4); + precalculatedAddresses.sharedLockboxProxy = vm.computeCreateAddress(msg.sender, vm.getNonce(msg.sender) + 8); // Deploy implementation contracts deploySuperchainImplementationContracts(_dsi, _dso, precalculatedAddresses); @@ -430,15 +446,27 @@ contract DeploySuperchain is Script { }) ); + // Deploy LiquidityMigrator implementation + ILiquidityMigrator liquidityMigratorImpl = ILiquidityMigrator( + DeployUtils.create1({ + _name: "LiquidityMigrator", + _args: DeployUtils.encodeConstructor( + abi.encodeCall(ILiquidityMigrator.__constructor__, (_precalculatedAddresses.sharedLockboxProxy)) + ) + }) + ); + vm.stopBroadcast(); vm.label(address(superchainConfigImpl), "SuperchainConfigImpl"); vm.label(address(protocolVersionsImpl), "ProtocolVersionsImpl"); vm.label(address(sharedLockboxImpl), "SharedLockboxImpl"); + vm.label(address(liquidityMigratorImpl), "LiquidityMigratorImpl"); _dso.set(_dso.superchainConfigImpl.selector, address(superchainConfigImpl)); _dso.set(_dso.protocolVersionsImpl.selector, address(protocolVersionsImpl)); _dso.set(_dso.sharedLockboxImpl.selector, address(sharedLockboxImpl)); + _dso.set(_dso.liquidityMigratorImpl.selector, address(liquidityMigratorImpl)); } function deployAndInitializeSuperchainProxyContracts( diff --git a/packages/contracts-bedrock/snapshots/.gas-snapshot b/packages/contracts-bedrock/snapshots/.gas-snapshot index 165a2cfd60d7..8e8ff71d5952 100644 --- a/packages/contracts-bedrock/snapshots/.gas-snapshot +++ b/packages/contracts-bedrock/snapshots/.gas-snapshot @@ -6,8 +6,8 @@ GasBenchMark_L1Block_SetValuesEcotone:test_setL1BlockValuesEcotone_benchmark() ( GasBenchMark_L1Block_SetValuesEcotone_Warm:test_setL1BlockValuesEcotone_benchmark() (gas: 7619) GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 369297) GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967504) -GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 564475) -GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4076645) +GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 564460) +GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4076630) GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 467064) GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_1() (gas: 3512768) GasBenchMark_L1StandardBridge_Finalize:test_finalizeETHWithdrawal_benchmark() (gas: 72661) diff --git a/packages/contracts-bedrock/snapshots/abi/LiquidityMigrator.json b/packages/contracts-bedrock/snapshots/abi/LiquidityMigrator.json index a96a61f9ea48..c1c723a90262 100644 --- a/packages/contracts-bedrock/snapshots/abi/LiquidityMigrator.json +++ b/packages/contracts-bedrock/snapshots/abi/LiquidityMigrator.json @@ -10,6 +10,19 @@ "stateMutability": "nonpayable", "type": "constructor" }, + { + "inputs": [], + "name": "SHARED_LOCKBOX", + "outputs": [ + { + "internalType": "contract ISharedLockbox", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "migrateETH", @@ -17,6 +30,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "version", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, { "anonymous": false, "inputs": [ diff --git a/packages/contracts-bedrock/snapshots/semver-lock.json b/packages/contracts-bedrock/snapshots/semver-lock.json index 87f3d7e28d94..4606ba37fc16 100644 --- a/packages/contracts-bedrock/snapshots/semver-lock.json +++ b/packages/contracts-bedrock/snapshots/semver-lock.json @@ -19,6 +19,10 @@ "initCodeHash": "0xd992c45b8461b9546fe4e3cecbce15d17ce366a62aab17058aad3b15bf36d21d", "sourceCodeHash": "0xa35478e9e2659a320da725a117b200dea2826175d2b17d881de1196da0cc91eb" }, + "src/L1/LiquidityMigrator.sol": { + "initCodeHash": "0x708f764a2de821caa3d520c93f1951e24128b136a5c41b06e2b1444a1a34e2e8", + "sourceCodeHash": "0x4f719e707583e2b23b9fcbd6e70935df099f45ac0efc50d1156051609bc26f69" + }, "src/L1/OPContractsManager.sol": { "initCodeHash": "0x9b704574a7005dc2aa8d6a3e0d85572493cc4bbd60033a23e437632a5fef7720", "sourceCodeHash": "0x05ed7ad68e4e9bca7334314e794a1f66e5899532bb01cfa3a7716cb2688df9d5" diff --git a/packages/contracts-bedrock/src/L1/LiquidityMigrator.sol b/packages/contracts-bedrock/src/L1/LiquidityMigrator.sol index 48634a460be4..37c3326c7f1c 100644 --- a/packages/contracts-bedrock/src/L1/LiquidityMigrator.sol +++ b/packages/contracts-bedrock/src/L1/LiquidityMigrator.sol @@ -1,19 +1,25 @@ // SPDX-License-Identifier: MIT pragma solidity 0.8.15; +// Interfaces +import { ISemver } from "interfaces/universal/ISemver.sol"; import { ISharedLockbox } from "interfaces/L1/ISharedLockbox.sol"; /// @custom:proxied true /// @title LiquidityMigrator /// @notice A contract to migrate the OptimisPortal's ETH balance to the SharedLockbox. One-time use logic, executed in /// a batch of transactions to enable the SharedLockbox interaction within the OptimismPortal. -contract LiquidityMigrator { +contract LiquidityMigrator is ISemver { /// @notice Emitted when the contract's ETH balance is migrated to the SharedLockbox. /// @param amount The amount corresponding to the contract's ETH balance migrated. event ETHMigrated(uint256 amount); /// @notice The SharedLockbox contract. - ISharedLockbox internal immutable SHARED_LOCKBOX; + ISharedLockbox public immutable SHARED_LOCKBOX; + + /// @notice Semantic version. + /// @custom:semver 1.0.0-beta.1 + string public constant version = "1.0.0-beta.1"; /// @notice Constructs the LiquidityMigrator contract. /// @param _sharedLockbox The address of the SharedLockbox contract. diff --git a/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol b/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol index a793fab462bf..a0d1981e3b41 100644 --- a/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol +++ b/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol @@ -3,38 +3,66 @@ pragma solidity 0.8.15; import { CommonTest } from "test/setup/CommonTest.sol"; import { LiquidityMigrator } from "src/L1/LiquidityMigrator.sol"; +import { IProxyAdmin } from "interfaces/universal/IProxyAdmin.sol"; contract LiquidityMigratorTest is CommonTest { event ETHMigrated(uint256 amount); - LiquidityMigrator public migrator; - function setUp() public virtual override { super.enableInterop(); super.setUp(); - migrator = new LiquidityMigrator(address(sharedLockbox)); } /// @notice Tests the migration of the contract's ETH balance to the SharedLockbox works properly. function test_migrateETH_succeeds(uint256 _ethAmount) public { - vm.deal(address(migrator), _ethAmount); + vm.deal(address(liquidityMigrator), _ethAmount); // Get the balance of the migrator before the migration to compare later on the assertions - uint256 _migratorEthBalance = address(migrator).balance; + uint256 _migratorEthBalance = address(liquidityMigrator).balance; uint256 _lockboxBalanceBefore = address(sharedLockbox).balance; - // Look for the emit of the `ETHMigrated` event - emit ETHMigrated(_migratorEthBalance); - // Set the migrator as an authorized portal so it can lock the ETH while migrating vm.prank(address(superchainConfig)); - sharedLockbox.authorizePortal(address(migrator)); + sharedLockbox.authorizePortal(address(liquidityMigrator)); + + // Look for the emit of the `ETHMigrated` event + vm.expectEmit(address(liquidityMigrator)); + emit ETHMigrated(_migratorEthBalance); // Call the `migrateETH` function with the amount - migrator.migrateETH(); + liquidityMigrator.migrateETH(); // Assert the balances after the migration happened - assert(address(migrator).balance == 0); + assert(address(liquidityMigrator).balance == 0); assert(address(sharedLockbox).balance == _lockboxBalanceBefore + _migratorEthBalance); } + + /// @notice Tests the migration of the portal's ETH balance to the SharedLockbox works properly. + function test_portal_migrateETH_succeeds(uint256 _ethAmount) public { + vm.deal(address(optimismPortal2), _ethAmount); + + // Get the balance of the portal before the migration to compare later on the assertions + uint256 _portalEthBalance = address(optimismPortal2).balance; + uint256 _lockboxBalanceBefore = address(sharedLockbox).balance; + + // Set the portal as an authorized portal so it can lock the ETH while migrating + IProxyAdmin proxyAdmin = IProxyAdmin(deploy.mustGetAddress("ProxyAdmin")); + address proxyAdminOwner = proxyAdmin.owner(); + + // Look for the emit of the `ETHMigrated` event + vm.expectEmit(address(optimismPortal2)); + emit ETHMigrated(_portalEthBalance); + + // Update the portal proxy implementation to the LiquidityMigrator contract + vm.prank(proxyAdminOwner); + proxyAdmin.upgradeAndCall({ + _proxy: payable(optimismPortal2), + _implementation: address(liquidityMigrator), + _data: abi.encodeCall(LiquidityMigrator.migrateETH, ()) + }); + + // Assert the balances after the migration happened + assert(address(optimismPortal2).balance == 0); + assert(address(sharedLockbox).balance == _lockboxBalanceBefore + _portalEthBalance); + } } diff --git a/packages/contracts-bedrock/test/opcm/DeploySuperchain.t.sol b/packages/contracts-bedrock/test/opcm/DeploySuperchain.t.sol index b4904c0199e8..cd1d8d5ebf8d 100644 --- a/packages/contracts-bedrock/test/opcm/DeploySuperchain.t.sol +++ b/packages/contracts-bedrock/test/opcm/DeploySuperchain.t.sol @@ -8,6 +8,7 @@ import { ProxyAdmin } from "src/universal/ProxyAdmin.sol"; import { Proxy } from "src/universal/Proxy.sol"; import { SuperchainConfig } from "src/L1/SuperchainConfig.sol"; import { SharedLockbox } from "src/L1/SharedLockbox.sol"; +import { LiquidityMigrator } from "src/L1/LiquidityMigrator.sol"; import { IProtocolVersions, ProtocolVersion } from "interfaces/L1/IProtocolVersions.sol"; import { DeploySuperchainInput, DeploySuperchain, DeploySuperchainOutput } from "scripts/deploy/DeploySuperchain.s.sol"; @@ -63,6 +64,7 @@ contract DeploySuperchainOutput_Test is Test { IProtocolVersions protocolVersionsProxy = IProtocolVersions(makeAddr("protocolVersionsProxy")); SharedLockbox sharedLockboxImpl = SharedLockbox(makeAddr("sharedLockboxImpl")); SharedLockbox sharedLockboxProxy = SharedLockbox(makeAddr("sharedLockboxProxy")); + LiquidityMigrator liquidityMigratorImpl = LiquidityMigrator(makeAddr("liquidityMigratorImpl")); // Ensure each address has code, since these are expected to be contracts. vm.etch(address(superchainProxyAdmin), hex"01"); @@ -72,6 +74,7 @@ contract DeploySuperchainOutput_Test is Test { vm.etch(address(protocolVersionsProxy), hex"01"); vm.etch(address(sharedLockboxImpl), hex"01"); vm.etch(address(sharedLockboxProxy), hex"01"); + vm.etch(address(liquidityMigratorImpl), hex"01"); // Set the output data. dso.set(dso.superchainProxyAdmin.selector, address(superchainProxyAdmin)); @@ -81,6 +84,7 @@ contract DeploySuperchainOutput_Test is Test { dso.set(dso.protocolVersionsProxy.selector, address(protocolVersionsProxy)); dso.set(dso.sharedLockboxImpl.selector, address(sharedLockboxImpl)); dso.set(dso.sharedLockboxProxy.selector, address(sharedLockboxProxy)); + dso.set(dso.liquidityMigratorImpl.selector, address(liquidityMigratorImpl)); // Compare the test data to the getter methods. assertEq(address(superchainProxyAdmin), address(dso.superchainProxyAdmin()), "100"); @@ -90,6 +94,7 @@ contract DeploySuperchainOutput_Test is Test { assertEq(address(protocolVersionsProxy), address(dso.protocolVersionsProxy()), "500"); assertEq(address(sharedLockboxImpl), address(dso.sharedLockboxImpl()), "600"); assertEq(address(sharedLockboxProxy), address(dso.sharedLockboxProxy()), "700"); + assertEq(address(liquidityMigratorImpl), address(dso.liquidityMigratorImpl()), "800"); } function test_getters_whenNotSet_reverts() public { @@ -110,6 +115,9 @@ contract DeploySuperchainOutput_Test is Test { vm.expectRevert("DeployUtils: zero address"); dso.sharedLockboxProxy(); + + vm.expectRevert("DeployUtils: zero address"); + dso.liquidityMigratorImpl(); } function test_getters_whenAddrHasNoCode_reverts() public { @@ -139,6 +147,10 @@ contract DeploySuperchainOutput_Test is Test { dso.set(dso.sharedLockboxProxy.selector, emptyAddr); vm.expectRevert(expectedErr); dso.sharedLockboxProxy(); + + dso.set(dso.liquidityMigratorImpl.selector, emptyAddr); + vm.expectRevert(expectedErr); + dso.liquidityMigratorImpl(); } } diff --git a/packages/contracts-bedrock/test/setup/Setup.sol b/packages/contracts-bedrock/test/setup/Setup.sol index 2b52e8c4c858..9aa97b3458d1 100644 --- a/packages/contracts-bedrock/test/setup/Setup.sol +++ b/packages/contracts-bedrock/test/setup/Setup.sol @@ -26,6 +26,7 @@ import { IL2OutputOracle } from "interfaces/L1/IL2OutputOracle.sol"; import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol"; import { ISuperchainConfig } from "interfaces/L1/ISuperchainConfig.sol"; import { ISharedLockbox } from "interfaces/L1/ISharedLockbox.sol"; +import { ILiquidityMigrator } from "interfaces/L1/ILiquidityMigrator.sol"; import { IDataAvailabilityChallenge } from "interfaces/L1/IDataAvailabilityChallenge.sol"; import { IL1StandardBridge } from "interfaces/L1/IL1StandardBridge.sol"; import { IProtocolVersions } from "interfaces/L1/IProtocolVersions.sol"; @@ -94,6 +95,7 @@ contract Setup { ISuperchainConfig superchainConfig; IDataAvailabilityChallenge dataAvailabilityChallenge; ISharedLockbox sharedLockbox; + ILiquidityMigrator liquidityMigrator; // L2 contracts IL2CrossDomainMessenger l2CrossDomainMessenger = @@ -209,6 +211,7 @@ contract Setup { superchainConfig = ISuperchainConfig(deploy.mustGetAddress("SuperchainConfigProxy")); anchorStateRegistry = IAnchorStateRegistry(deploy.mustGetAddress("AnchorStateRegistryProxy")); sharedLockbox = ISharedLockbox(deploy.mustGetAddress("SharedLockboxProxy")); + liquidityMigrator = ILiquidityMigrator(deploy.mustGetAddress("LiquidityMigrator")); vm.label(address(optimismPortal), "OptimismPortal"); vm.label(deploy.mustGetAddress("OptimismPortalProxy"), "OptimismPortalProxy"); @@ -233,6 +236,7 @@ contract Setup { vm.label(deploy.mustGetAddress("SuperchainConfigProxy"), "SuperchainConfigProxy"); vm.label(address(sharedLockbox), "SharedLockbox"); vm.label(deploy.mustGetAddress("SharedLockboxProxy"), "SharedLockboxProxy"); + vm.label(address(liquidityMigrator), "LiquidtyMigrator"); vm.label(address(anchorStateRegistry), "AnchorStateRegistryProxy"); vm.label(AddressAliasHelper.applyL1ToL2Alias(address(l1CrossDomainMessenger)), "L1CrossDomainMessenger_aliased"); diff --git a/packages/contracts-bedrock/test/universal/Specs.t.sol b/packages/contracts-bedrock/test/universal/Specs.t.sol index 9c642561dd05..ba7cea19fbd0 100644 --- a/packages/contracts-bedrock/test/universal/Specs.t.sol +++ b/packages/contracts-bedrock/test/universal/Specs.t.sol @@ -934,6 +934,8 @@ contract Specification_Test is CommonTest { // LiquidityMigrator _addSpec({ _name: "LiquidityMigrator", _sel: _getSel("migrateETH()") }); + _addSpec({ _name: "LiquidityMigrator", _sel: _getSel("SHARED_LOCKBOX()") }); + _addSpec({ _name: "LiquidityMigrator", _sel: _getSel("version()") }); } /// @dev Computes the selector from a function signature. From 073713a2fd19101bb7a8003ef3b7cdc39ca228ed Mon Sep 17 00:00:00 2001 From: agusduha Date: Tue, 24 Dec 2024 11:19:55 -0300 Subject: [PATCH 2/3] test: fix comment --- packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol b/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol index a0d1981e3b41..32174034814f 100644 --- a/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol +++ b/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol @@ -45,7 +45,7 @@ contract LiquidityMigratorTest is CommonTest { uint256 _portalEthBalance = address(optimismPortal2).balance; uint256 _lockboxBalanceBefore = address(sharedLockbox).balance; - // Set the portal as an authorized portal so it can lock the ETH while migrating + // Get the proxy admin address and it's owner IProxyAdmin proxyAdmin = IProxyAdmin(deploy.mustGetAddress("ProxyAdmin")); address proxyAdminOwner = proxyAdmin.owner(); From 9e1cc42ae39f8d150e229bc48706402ad9dd3688 Mon Sep 17 00:00:00 2001 From: agusduha Date: Tue, 24 Dec 2024 16:01:22 -0300 Subject: [PATCH 3/3] test: fix internal variables names --- .../test/L1/LiquidityMigrator.t.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol b/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol index 32174034814f..44d2d7ea8051 100644 --- a/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol +++ b/packages/contracts-bedrock/test/L1/LiquidityMigrator.t.sol @@ -18,8 +18,8 @@ contract LiquidityMigratorTest is CommonTest { vm.deal(address(liquidityMigrator), _ethAmount); // Get the balance of the migrator before the migration to compare later on the assertions - uint256 _migratorEthBalance = address(liquidityMigrator).balance; - uint256 _lockboxBalanceBefore = address(sharedLockbox).balance; + uint256 migratorEthBalance = address(liquidityMigrator).balance; + uint256 lockboxBalanceBefore = address(sharedLockbox).balance; // Set the migrator as an authorized portal so it can lock the ETH while migrating vm.prank(address(superchainConfig)); @@ -27,14 +27,14 @@ contract LiquidityMigratorTest is CommonTest { // Look for the emit of the `ETHMigrated` event vm.expectEmit(address(liquidityMigrator)); - emit ETHMigrated(_migratorEthBalance); + emit ETHMigrated(migratorEthBalance); // Call the `migrateETH` function with the amount liquidityMigrator.migrateETH(); // Assert the balances after the migration happened assert(address(liquidityMigrator).balance == 0); - assert(address(sharedLockbox).balance == _lockboxBalanceBefore + _migratorEthBalance); + assert(address(sharedLockbox).balance == lockboxBalanceBefore + migratorEthBalance); } /// @notice Tests the migration of the portal's ETH balance to the SharedLockbox works properly. @@ -42,8 +42,8 @@ contract LiquidityMigratorTest is CommonTest { vm.deal(address(optimismPortal2), _ethAmount); // Get the balance of the portal before the migration to compare later on the assertions - uint256 _portalEthBalance = address(optimismPortal2).balance; - uint256 _lockboxBalanceBefore = address(sharedLockbox).balance; + uint256 portalEthBalance = address(optimismPortal2).balance; + uint256 lockboxBalanceBefore = address(sharedLockbox).balance; // Get the proxy admin address and it's owner IProxyAdmin proxyAdmin = IProxyAdmin(deploy.mustGetAddress("ProxyAdmin")); @@ -51,7 +51,7 @@ contract LiquidityMigratorTest is CommonTest { // Look for the emit of the `ETHMigrated` event vm.expectEmit(address(optimismPortal2)); - emit ETHMigrated(_portalEthBalance); + emit ETHMigrated(portalEthBalance); // Update the portal proxy implementation to the LiquidityMigrator contract vm.prank(proxyAdminOwner); @@ -63,6 +63,6 @@ contract LiquidityMigratorTest is CommonTest { // Assert the balances after the migration happened assert(address(optimismPortal2).balance == 0); - assert(address(sharedLockbox).balance == _lockboxBalanceBefore + _portalEthBalance); + assert(address(sharedLockbox).balance == lockboxBalanceBefore + portalEthBalance); } }