forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: liquidity migrator deployment #166
Merged
agusduha
merged 3 commits into
sc-feat/add-shared-lockbox
from
feat/liquidity-migrator-deployment
Dec 24, 2024
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/contracts-bedrock/interfaces/L1/ILiquidityMigrator.sol
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
// 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 { | ||
event ETHMigrated(uint256 amount); | ||
|
||
function __constructor__(address _sharedLockbox) external; | ||
|
||
function SHARED_LOCKBOX() external view returns (ISharedLockbox); | ||
|
||
function migrateETH() external; | ||
|
||
function version() external view returns (string memory); | ||
} |
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
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
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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT
Suggested change
|
||||||||||
|
||||||||||
// Get the proxy admin address and it's owner | ||||||||||
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); | ||||||||||
} | ||||||||||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also remove the underscores from the stack vars introduced on previous PRs