Skip to content
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: introduce SharedLockbox #141

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bf3278f
feat: add shared lockbox (#126)
0xDiscotech Nov 20, 2024
0324436
Merge pull request #136 from defi-wonderland/chore/sync-develop
agusduha Nov 22, 2024
27a4515
feat: integrate portal to lockbox (#139)
agusduha Nov 26, 2024
9476989
feat: add liquidity migrator contract with its unit test and interfac…
0xDiscotech Nov 27, 2024
b240094
feat: integrate system config with superchain config (#140)
agusduha Nov 27, 2024
3254d14
feat: manage dependency set on superchain config (#138)
0xDiscotech Nov 28, 2024
2c7d996
chore: add zero dependencies check (#142)
0xDiscotech Nov 28, 2024
7111d13
Merge branch 'develop' into fix/merge-conflict-lockbox
agusduha Nov 28, 2024
4a45ed2
fix: pre pr
agusduha Nov 28, 2024
cae605e
Merge pull request #143 from defi-wonderland/fix/merge-conflict-lockbox
agusduha Nov 28, 2024
37dccaf
feat: Add pause check (#145)
agusduha Nov 29, 2024
8bef762
Merge branch 'develop' into fix/merge-conflict-lockbox-2
agusduha Dec 9, 2024
036b1d5
fix: pre pr and interfaces imports
agusduha Dec 9, 2024
9163c9c
Merge pull request #147 from defi-wonderland/fix/merge-conflict-lockb…
agusduha Dec 9, 2024
6f5c86d
feat: add upgrader role to superchain config (#163)
agusduha Dec 19, 2024
85d49dc
feat: use superchain config lockbox in portal (#164)
agusduha Dec 19, 2024
078bb36
Merge branch 'develop' into fix/merge-conflict-lockbox-3
agusduha Dec 19, 2024
657c97b
fix: pre pr
agusduha Dec 19, 2024
36a8897
Merge pull request #165 from defi-wonderland/fix/merge-conflict-lockb…
agusduha Dec 20, 2024
3b9eba9
feat: liquidity migrator deployment (#166)
agusduha Dec 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/contracts-bedrock/interfaces/L1/ILiquidityMigrator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +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);
}
2 changes: 2 additions & 0 deletions packages/contracts-bedrock/interfaces/L1/IOptimismPortal2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { IDisputeGame } from "interfaces/dispute/IDisputeGame.sol";
import { IDisputeGameFactory } from "interfaces/dispute/IDisputeGameFactory.sol";
import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol";
import { ISuperchainConfig } from "interfaces/L1/ISuperchainConfig.sol";
import { ISharedLockbox } from "interfaces/L1/ISharedLockbox.sol";

interface IOptimismPortal2 {
error AlreadyFinalized();
Expand Down Expand Up @@ -69,6 +70,7 @@ interface IOptimismPortal2 {
function disputeGameBlacklist(IDisputeGame) external view returns (bool);
function disputeGameFactory() external view returns (IDisputeGameFactory);
function disputeGameFinalityDelaySeconds() external view returns (uint256);
function sharedLockbox() external view returns (ISharedLockbox);
function donateETH() external payable;
function finalizeWithdrawalTransaction(Types.WithdrawalTransaction memory _tx) external;
function finalizeWithdrawalTransactionExternalProof(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IDisputeGameFactory } from "interfaces/dispute/IDisputeGameFactory.sol"
import { ISystemConfig } from "interfaces/L1/ISystemConfig.sol";
import { ISuperchainConfig } from "interfaces/L1/ISuperchainConfig.sol";
import { ConfigType } from "interfaces/L2/IL1BlockInterop.sol";
import { ISharedLockbox } from "interfaces/L1/ISharedLockbox.sol";

interface IOptimismPortalInterop {
error AlreadyFinalized();
Expand Down Expand Up @@ -70,6 +71,7 @@ interface IOptimismPortalInterop {
function disputeGameBlacklist(IDisputeGame) external view returns (bool);
function disputeGameFactory() external view returns (IDisputeGameFactory);
function disputeGameFinalityDelaySeconds() external view returns (uint256);
function sharedLockbox() external view returns (ISharedLockbox);
function donateETH() external payable;
function finalizeWithdrawalTransaction(Types.WithdrawalTransaction memory _tx) external;
function finalizeWithdrawalTransactionExternalProof(
Expand Down
33 changes: 33 additions & 0 deletions packages/contracts-bedrock/interfaces/L1/ISharedLockbox.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { ISemver } from "interfaces/universal/ISemver.sol";
import { ISuperchainConfig } from "interfaces/L1/ISuperchainConfig.sol";

/// @title ISharedLockbox
/// @notice Interface for the SharedLockbox contract
interface ISharedLockbox is ISemver {
error Unauthorized();

error Paused();

event ETHLocked(address indexed portal, uint256 amount);

event ETHUnlocked(address indexed portal, uint256 amount);

event PortalAuthorized(address indexed portal);

function SUPERCHAIN_CONFIG() external view returns (ISuperchainConfig);

function authorizedPortals(address) external view returns (bool);

function __constructor__(address _superchainConfig) external;

function paused() external view returns (bool);

function unlockETH(uint256 _value) external;

function lockETH() external payable;

function authorizePortal(address _portal) external;
}
20 changes: 17 additions & 3 deletions packages/contracts-bedrock/interfaces/L1/ISuperchainConfig.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ISuperchainConfig {
import { IDependencySet } from "interfaces/L2/IDependencySet.sol";
import { ISharedLockbox } from "interfaces/L1/ISharedLockbox.sol";

interface ISuperchainConfig is IDependencySet {
enum UpdateType {
GUARDIAN
}
Expand All @@ -10,15 +13,26 @@ interface ISuperchainConfig {
event Initialized(uint8 version);
event Paused(string identifier);
event Unpaused();
event ChainAdded(uint256 indexed chainId, address indexed systemConfig, address indexed portal);

error Unauthorized();
error ChainAlreadyHasDependencies();
error ChainAlreadyAdded();

function GUARDIAN_SLOT() external view returns (bytes32);
function PAUSED_SLOT() external view returns (bytes32);
function UPGRADER_SLOT() external view returns (bytes32);
function SHARED_LOCKBOX() external view returns (ISharedLockbox);
function guardian() external view returns (address guardian_);
function initialize(address _guardian, bool _paused) external;
function systemConfigs(uint256) external view returns (address);
function upgrader() external view returns (address upgrader_);
function initialize(address _guardian, address _upgrader, bool _paused) external;
function pause(string memory _identifier) external;
function paused() external view returns (bool paused_);
function unpause() external;
function version() external view returns (string memory);
function addChain(uint256 _chainId, address _systemConfig) external;
function dependencySet() external view returns (uint256[] memory);

function __constructor__() external;
function __constructor__(address _sharedLockbox) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface ISystemConfigInterop {

function addDependency(uint256 _chainId) external;
function removeDependency(uint256 _chainId) external;
function dependencyManager() external view returns (address);
function dependencyCounter() external view returns (uint256);
function initialize(
address _owner,
uint32 _basefeeScalar,
Expand All @@ -65,11 +65,11 @@ interface ISystemConfigInterop {
address _unsafeBlockSigner,
IResourceMetering.ResourceConfig memory _config,
address _batchInbox,
ISystemConfig.Addresses memory _addresses,
address _dependencyManager
ISystemConfig.Addresses memory _addresses
)
external;
function version() external pure returns (string memory);
function SUPERCHAIN_CONFIG() external view returns (address);

function __constructor__() external;
function __constructor__(address _superchainConfig) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var excludeContracts = []string{

// TODO: Interfaces that need to be fixed
"IInitializable", "IOptimismMintableERC20", "ILegacyMintableERC20",
"KontrolCheatsBase", "ISystemConfigInterop", "IResolvedDelegateProxy",
"KontrolCheatsBase", "IResolvedDelegateProxy",
}

type ContractDefinition struct {
Expand Down
37 changes: 30 additions & 7 deletions packages/contracts-bedrock/scripts/deploy/ChainAssertions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { IResourceMetering } from "interfaces/L1/IResourceMetering.sol";
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";
Expand Down Expand Up @@ -142,27 +144,26 @@ library ChainAssertions {
/// @notice Asserts that the SystemConfigInterop is setup correctly
function checkSystemConfigInterop(
Types.ContractSet memory _contracts,
Types.ContractSet memory _proxies,
DeployConfig _cfg,
bool _isProxy
)
internal
view
{
ISystemConfigInterop config = ISystemConfigInterop(_contracts.SystemConfig);
ISuperchainConfig superchainConfig = ISuperchainConfig(_proxies.SuperchainConfig);

console.log(
"Running chain assertions on the SystemConfigInterop %s at %s",
_isProxy ? "proxy" : "implementation",
address(config)
);

checkSystemConfig(_contracts, _cfg, _isProxy);
if (_isProxy) {
// TODO: this is not being set in the deployment, nor is a config value.
// Update this when it has an entry in hardhat.json
require(config.dependencyManager() == address(0), "CHECK-SCFGI-10");
} else {
require(config.dependencyManager() == address(0), "CHECK-SCFGI-20");
}

require(config.dependencyCounter() == 0, "CHECK-SCFGI-10");
require(config.SUPERCHAIN_CONFIG() == address(superchainConfig), "CHECK-SCFGI-20");
}

/// @notice Asserts that the L1CrossDomainMessenger is setup correctly
Expand Down Expand Up @@ -586,4 +587,26 @@ library ChainAssertions {

// TODO: Add assertions for blueprints and setters?
}

/// @notice Asserts that the SharedLockbox is setup correctly
function checkSharedLockbox(Types.ContractSet memory _contracts, bool _isProxy) internal view {
ISharedLockbox sharedLockbox = ISharedLockbox(_contracts.SharedLockbox);
ISuperchainConfig superchainConfig = ISuperchainConfig(_contracts.SuperchainConfig);

console.log(
"Running chain assertions on the SharedLockbox %s at %s",
_isProxy ? "proxy" : "implementation",
address(sharedLockbox)
);

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");
}
}
48 changes: 42 additions & 6 deletions packages/contracts-bedrock/scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ contract Deploy is Deployer {
L1ERC721Bridge: getAddress("L1ERC721BridgeProxy"),
ProtocolVersions: getAddress("ProtocolVersionsProxy"),
SuperchainConfig: getAddress("SuperchainConfigProxy"),
OPContractsManager: getAddress("OPContractsManager")
OPContractsManager: getAddress("OPContractsManager"),
SharedLockbox: getAddress("SharedLockboxProxy")
});
}

Expand All @@ -150,7 +151,8 @@ contract Deploy is Deployer {
L1ERC721Bridge: getAddress("L1ERC721Bridge"),
ProtocolVersions: getAddress("ProtocolVersions"),
SuperchainConfig: getAddress("SuperchainConfig"),
OPContractsManager: getAddress("OPContractsManager")
OPContractsManager: getAddress("OPContractsManager"),
SharedLockbox: getAddress("SharedLockbox")
});
}

Expand All @@ -167,9 +169,17 @@ contract Deploy is Deployer {
/// @notice Deploy a new OP Chain using an existing SuperchainConfig and ProtocolVersions
/// @param _superchainConfigProxy Address of the existing SuperchainConfig proxy
/// @param _protocolVersionsProxy Address of the existing ProtocolVersions proxy
function runWithSuperchain(address payable _superchainConfigProxy, address payable _protocolVersionsProxy) public {
/// @param _sharedLockboxProxy Address of the existing SharedLockbox proxy
function runWithSuperchain(
address payable _superchainConfigProxy,
address payable _protocolVersionsProxy,
address payable _sharedLockboxProxy
)
public
{
require(_superchainConfigProxy != address(0), "Deploy: must specify address for superchain config proxy");
require(_protocolVersionsProxy != address(0), "Deploy: must specify address for protocol versions proxy");
require(_sharedLockboxProxy != address(0), "Deploy: must specify address for shared lockbox proxy");

vm.chainId(cfg.l1ChainID());

Expand All @@ -183,6 +193,10 @@ contract Deploy is Deployer {
save("ProtocolVersions", pvProxy.implementation());
save("ProtocolVersionsProxy", _protocolVersionsProxy);

IProxy slProxy = IProxy(_sharedLockboxProxy);
save("SharedLockbox", slProxy.implementation());
save("SharedLockboxProxy", _sharedLockboxProxy);

_run({ _needsSuperchain: false });
}

Expand Down Expand Up @@ -255,9 +269,10 @@ contract Deploy is Deployer {
////////////////////////////////////////////////////////////////

/// @notice Deploy a full system with a new SuperchainConfig
/// The Superchain system has 2 singleton contracts which lie outside of an OP Chain:
/// The Superchain system has 3 singleton contracts which lie outside of an OP Chain:
/// 1. The SuperchainConfig contract
/// 2. The ProtocolVersions contract
/// 3. The SharedLockbox contract
function deploySuperchain() public {
console.log("Setting up Superchain");
DeploySuperchain ds = new DeploySuperchain();
Expand All @@ -279,11 +294,25 @@ contract Deploy is Deployer {
save("SuperchainConfig", address(dso.superchainConfigImpl()));
save("ProtocolVersionsProxy", address(dso.protocolVersionsProxy()));
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 and SuperchainConfig proxy contracts.
// First run assertions for the ProtocolVersions, SuperchainConfig and SharedLockbox proxy contracts.
Types.ContractSet memory contracts = _proxies();
ChainAssertions.checkProtocolVersions({ _contracts: contracts, _cfg: cfg, _isProxy: true });
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 });

// Then replace the ProtocolVersions proxy with the implementation address and run assertions on it.
contracts.ProtocolVersions = mustGetAddress("ProtocolVersions");
Expand Down Expand Up @@ -315,6 +344,7 @@ contract Deploy is Deployer {
);
dii.set(dii.superchainConfigProxy.selector, mustGetAddress("SuperchainConfigProxy"));
dii.set(dii.protocolVersionsProxy.selector, mustGetAddress("ProtocolVersionsProxy"));
dii.set(dii.sharedLockboxProxy.selector, mustGetAddress("SharedLockboxProxy"));
dii.set(dii.salt.selector, _implSalt());

if (_isInterop) {
Expand Down Expand Up @@ -364,7 +394,13 @@ contract Deploy is Deployer {
_oracle: IPreimageOracle(address(dio.preimageOracleSingleton()))
});
if (_isInterop) {
ChainAssertions.checkSystemConfigInterop({ _contracts: contracts, _cfg: cfg, _isProxy: false });
Types.ContractSet memory proxies = _proxies();
ChainAssertions.checkSystemConfigInterop({
_contracts: contracts,
_proxies: proxies,
_cfg: cfg,
_isProxy: false
});
} else {
ChainAssertions.checkSystemConfig({ _contracts: contracts, _cfg: cfg, _isProxy: false });
}
Expand Down
Loading