forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce OptimismSuperchainERC20Factory (ethereum-optimism#11617)
* test: add L2 standard bridge interop unit tests (#13) * test: add L2 standard bridge interop unit tests * fix: add tests natspec * fix: unit tests fixes * fix: super to legacy tests failing * fix: mock and expect mint and burn * fix: add generic factory interface (#14) * test: add L2 standard bridge interop unit tests * fix: add tests natspec * fix: add generic factory interface * feat: modify OptimismMintableERC20Factory for convert (#17) * test: add L2 standard bridge interop unit tests * fix: add tests natspec * fix: add generic factory interface * feat: modify OptimismMintableERC20Factory for convert * fix: use only a public function for create3 * feat: rollback interop factory, modify legacy one * fix: delete local token return variable * fix: PR fixes * feat: add superchain erc20 factory implementation (#23) * feat: add superchain erc20 factory implementation * fix: remove createX comments * test: add superchain erc20 factory tests (#25) * test: add superchain erc20 factory tests * test: add erc20 asserts * test: fix expect emit * fix: remove comments * feat: add constructor to superchain ERC20 beacon (#34) * test: remove factory predeploy etch ---------- Co-authored-by: 0xng <[email protected]> Co-authored-by: 0xParticle <[email protected]> Co-authored-by: gotzenx <[email protected]> * fix: set an arbitrary address for superchain erc20 impl * fix: deploy a proxy for the beacon on genesis (#45) --------- Co-authored-by: 0xng <[email protected]> * fix: conflicts and imports * fix: interfaces * chore: add .testdata * fix: adding back .testdata to gitignore * fix: new conflicts from ci improvements --------- Co-authored-by: 0xng <[email protected]> Co-authored-by: 0xParticle <[email protected]> Co-authored-by: gotzenx <[email protected]> Co-authored-by: Disco <[email protected]>
- Loading branch information
1 parent
97aa08a
commit 232c54d
Showing
17 changed files
with
483 additions
and
58 deletions.
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
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
39 changes: 39 additions & 0 deletions
39
packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20Beacon.json
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,39 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_implementation", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "implementation", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "version", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
93 changes: 93 additions & 0 deletions
93
packages/contracts-bedrock/snapshots/abi/OptimismSuperchainERC20Factory.json
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,93 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_remoteToken", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "string", | ||
"name": "_name", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "string", | ||
"name": "_symbol", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "uint8", | ||
"name": "_decimals", | ||
"type": "uint8" | ||
} | ||
], | ||
"name": "deploy", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_superchainERC20", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "superchainToken", | ||
"type": "address" | ||
} | ||
], | ||
"name": "deployments", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "remoteToken", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "version", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "superchainToken", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "remoteToken", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "deployer", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OptimismSuperchainERC20Created", | ||
"type": "event" | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
packages/contracts-bedrock/snapshots/storageLayout/OptimismSuperchainERC20Beacon.json
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 @@ | ||
[] |
9 changes: 9 additions & 0 deletions
9
packages/contracts-bedrock/snapshots/storageLayout/OptimismSuperchainERC20Factory.json
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,9 @@ | ||
[ | ||
{ | ||
"bytes": "32", | ||
"label": "deployments", | ||
"offset": 0, | ||
"slot": "0", | ||
"type": "mapping(address => address)" | ||
} | ||
] |
27 changes: 27 additions & 0 deletions
27
packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Beacon.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,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.15; | ||
|
||
import { IBeacon } from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; | ||
import { ISemver } from "src/universal/interfaces/ISemver.sol"; | ||
|
||
/// @custom:proxied | ||
/// @custom:predeployed 0x4200000000000000000000000000000000000027 | ||
/// @title OptimismSuperchainERC20Beacon | ||
/// @notice OptimismSuperchainERC20Beacon is the beacon proxy for the OptimismSuperchainERC20 implementation. | ||
contract OptimismSuperchainERC20Beacon is IBeacon, ISemver { | ||
/// @notice Address of the OptimismSuperchainERC20 implementation. | ||
address internal immutable IMPLEMENTATION; | ||
|
||
/// @notice Semantic version. | ||
/// @custom:semver 1.0.0-beta.1 | ||
string public constant version = "1.0.0-beta.1"; | ||
|
||
constructor(address _implementation) { | ||
IMPLEMENTATION = _implementation; | ||
} | ||
|
||
/// @inheritdoc IBeacon | ||
function implementation() external view override returns (address) { | ||
return IMPLEMENTATION; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
packages/contracts-bedrock/src/L2/OptimismSuperchainERC20Factory.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,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import { IOptimismERC20Factory } from "src/L2/interfaces/IOptimismERC20Factory.sol"; | ||
import { ISemver } from "src/universal/interfaces/ISemver.sol"; | ||
import { OptimismSuperchainERC20 } from "src/L2/OptimismSuperchainERC20.sol"; | ||
import { Predeploys } from "src/libraries/Predeploys.sol"; | ||
import { BeaconProxy } from "@openzeppelin/contracts-v5/proxy/beacon/BeaconProxy.sol"; | ||
import { CREATE3 } from "@rari-capital/solmate/src/utils/CREATE3.sol"; | ||
|
||
/// @custom:proxied | ||
/// @custom:predeployed 0x4200000000000000000000000000000000000026 | ||
/// @title OptimismSuperchainERC20Factory | ||
/// @notice OptimismSuperchainERC20Factory is a factory contract that deploys OptimismSuperchainERC20 Beacon Proxies | ||
/// using CREATE3. | ||
contract OptimismSuperchainERC20Factory is IOptimismERC20Factory, ISemver { | ||
/// @notice Mapping of the deployed OptimismSuperchainERC20 to the remote token address. | ||
/// This is used to keep track of the token deployments. | ||
mapping(address superchainToken => address remoteToken) public deployments; | ||
|
||
/// @notice Emitted when an OptimismSuperchainERC20 is deployed. | ||
/// @param superchainToken Address of the SuperchainERC20 deployment. | ||
/// @param remoteToken Address of the corresponding token on the remote chain. | ||
/// @param deployer Address of the account that deployed the token. | ||
event OptimismSuperchainERC20Created( | ||
address indexed superchainToken, address indexed remoteToken, address deployer | ||
); | ||
|
||
/// @notice Semantic version. | ||
/// @custom:semver 1.0.0-beta.1 | ||
string public constant version = "1.0.0-beta.1"; | ||
|
||
/// @notice Deploys a OptimismSuperchainERC20 Beacon Proxy using CREATE3. | ||
/// @param _remoteToken Address of the remote token. | ||
/// @param _name Name of the OptimismSuperchainERC20. | ||
/// @param _symbol Symbol of the OptimismSuperchainERC20. | ||
/// @param _decimals Decimals of the OptimismSuperchainERC20. | ||
/// @return _superchainERC20 Address of the OptimismSuperchainERC20 deployment. | ||
function deploy( | ||
address _remoteToken, | ||
string memory _name, | ||
string memory _symbol, | ||
uint8 _decimals | ||
) | ||
external | ||
returns (address _superchainERC20) | ||
{ | ||
bytes memory initCallData = | ||
abi.encodeCall(OptimismSuperchainERC20.initialize, (_remoteToken, _name, _symbol, _decimals)); | ||
|
||
bytes memory creationCode = bytes.concat( | ||
type(BeaconProxy).creationCode, abi.encode(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON, initCallData) | ||
); | ||
|
||
bytes32 salt = keccak256(abi.encode(_remoteToken, _name, _symbol, _decimals)); | ||
_superchainERC20 = CREATE3.deploy({ salt: salt, creationCode: creationCode, value: 0 }); | ||
|
||
deployments[_superchainERC20] = _remoteToken; | ||
|
||
emit OptimismSuperchainERC20Created(_superchainERC20, _remoteToken, msg.sender); | ||
} | ||
} |
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.