forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add superchain erc20 factory implementation (#23)
* feat: add superchain erc20 factory implementation * fix: remove createX comments
- Loading branch information
Showing
8 changed files
with
235 additions
and
2 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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"name": "implementation", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "pure", | ||
"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)" | ||
} | ||
] |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import { IBeacon } from "@openzeppelin/contracts-v5/proxy/beacon/IBeacon.sol"; | ||
import { ISemver } from "src/universal/ISemver.sol"; | ||
|
||
/// @custom:proxied | ||
/// @custom:predeployed 0x4200000000000000000000000000000000000027 | ||
/// @title OptimismSuperchainERC20Beacon | ||
/// @notice OptimismSuperchainERC20Beacon is the beacon proxy for the OptimismSuperchainERC20 implementation. | ||
contract OptimismSuperchainERC20Beacon is IBeacon, ISemver { | ||
/// TODO: Replace with real implementation address | ||
/// @notice Address of the OptimismSuperchainERC20 implementation. | ||
address internal constant IMPLEMENTATION_ADDRESS = 0x0000000000000000000000000000000000000000; | ||
|
||
/// @notice Semantic version. | ||
/// @custom:semver 1.0.0-beta.1 | ||
string public constant version = "1.0.0-beta.1"; | ||
|
||
/// @inheritdoc IBeacon | ||
function implementation() external pure override returns (address) { | ||
return IMPLEMENTATION_ADDRESS; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import { IOptimismERC20Factory } from "src/L2/IOptimismERC20Factory.sol"; | ||
import { ISemver } from "src/universal/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 a 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) | ||
{ | ||
// Encode the `initialize` call data for the OptimismSuperchainERC20. | ||
bytes memory initCallData = | ||
abi.encodeCall(OptimismSuperchainERC20.initialize, (_remoteToken, _name, _symbol, _decimals)); | ||
|
||
// Encode the BeaconProxy creation code with the beacon contract address and the `initialize` call data. | ||
bytes memory creationCode = bytes.concat( | ||
type(BeaconProxy).creationCode, abi.encode(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_BEACON, initCallData) | ||
); | ||
|
||
// Use CREATE3 for deterministic deployment. | ||
bytes32 salt = keccak256(abi.encode(_remoteToken, _name, _symbol, _decimals)); | ||
_superchainERC20 = CREATE3.deploy({ salt: salt, creationCode: creationCode, value: 0 }); | ||
|
||
// Store OptimismSuperchainERC20 and remote token addresses | ||
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