-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[contracts]: enable initiating L2 upgrade via L1 to L2 message (#887
- Loading branch information
1 parent
2f8ae44
commit 422e608
Showing
7 changed files
with
362 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@eth-optimism/contracts': patch | ||
--- | ||
|
||
enables l2 upgrades to be initiated by an l1 to l2 message |
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
114 changes: 114 additions & 0 deletions
114
packages/contracts/contracts/chugsplash/L2ChugSplashOwner.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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >0.5.0 <0.8.0; | ||
|
||
/* Library Imports */ | ||
import { OVM_CrossDomainEnabled } from "../optimistic-ethereum/libraries/bridge/OVM_CrossDomainEnabled.sol"; | ||
|
||
/** | ||
* @title L2ChugSplashOwner | ||
* @dev This contract will be the owner of the L2ChugSplashDeployer contract on deployed networks. | ||
* By separating this from the L2ChugSplashDeployer, we can more easily test the core ChugSplash | ||
* logic. It's effectively just a proxy to the L2ChugSplashDeployer. | ||
*/ | ||
contract L2ChugSplashOwner is OVM_CrossDomainEnabled { | ||
|
||
/********** | ||
* Events * | ||
**********/ | ||
|
||
event OwnershipTransferred( | ||
address indexed previousOwner, | ||
address indexed newOwner | ||
); | ||
|
||
|
||
/************* | ||
* Variables * | ||
*************/ | ||
|
||
address public owner; | ||
|
||
|
||
/*************** | ||
* Constructor * | ||
***************/ | ||
|
||
/** | ||
* @param _owner Address that will initially own the L2ChugSplashOwner. | ||
*/ | ||
constructor( | ||
address _owner | ||
) | ||
public | ||
OVM_CrossDomainEnabled(0x4200000000000000000000000000000000000007) | ||
{ | ||
// Need to replicate the code from transferOwnership because transferOwnership can only be | ||
// called via an L1 => L2 message. | ||
require( | ||
_owner != address(0), | ||
"L2ChugSplashOwner: new owner is the zero address" | ||
); | ||
|
||
emit OwnershipTransferred(owner, _owner); | ||
owner = _owner; | ||
} | ||
|
||
|
||
/******************** | ||
* Public Functions * | ||
********************/ | ||
|
||
/** | ||
* Leaves the contract without owner. | ||
*/ | ||
function renounceOwnership() | ||
public | ||
onlyFromCrossDomainAccount(owner) | ||
{ | ||
emit OwnershipTransferred(owner, address(0)); | ||
owner = address(0); | ||
} | ||
|
||
/** | ||
* Transfers ownership to a new address. | ||
* @param _newOwner Address of the new owner. | ||
*/ | ||
function transferOwnership( | ||
address _newOwner | ||
) | ||
public | ||
onlyFromCrossDomainAccount(owner) | ||
{ | ||
require( | ||
_newOwner != address(0), | ||
"L2ChugSplashOwner: new owner is the zero address" | ||
); | ||
|
||
emit OwnershipTransferred(owner, _newOwner); | ||
owner = _newOwner; | ||
} | ||
|
||
|
||
/********************* | ||
* Fallback Function * | ||
*********************/ | ||
|
||
fallback() | ||
external | ||
onlyFromCrossDomainAccount(owner) | ||
{ | ||
(bool success, bytes memory returndata) = address( | ||
0x420000000000000000000000000000000000000D | ||
).call(msg.data); | ||
|
||
if (success) { | ||
assembly { | ||
return(add(returndata, 0x20), mload(returndata)) | ||
} | ||
} else { | ||
assembly { | ||
revert(add(returndata, 0x20), mload(returndata)) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.