Skip to content

Commit

Permalink
feat: rollback interop factory, modify legacy one
Browse files Browse the repository at this point in the history
  • Loading branch information
agusduha committed Aug 13, 2024
1 parent 90d1e7d commit 8209d4b
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 139 deletions.
8 changes: 4 additions & 4 deletions packages/contracts-bedrock/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 369380)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967520)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 561992)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4074035)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 369356)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2967496)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_0() (gas: 564483)
GasBenchMark_L1StandardBridge_Deposit:test_depositERC20_benchmark_1() (gas: 4076526)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_0() (gas: 466947)
GasBenchMark_L1StandardBridge_Deposit:test_depositETH_benchmark_1() (gas: 3512629)
GasBenchMark_L1StandardBridge_Finalize:test_finalizeETHWithdrawal_benchmark() (gas: 72624)
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@
"sourceCodeHash": "0x52737b23e99bf79dd2c23196b3298e80aa41f740efc6adc7916e696833eb546a"
},
"src/universal/OptimismMintableERC20Factory.sol": {
"initCodeHash": "0xf6f522681e7ae940cb778db68004f122b25194296a65bba7ad1d792bd593c4a6",
"sourceCodeHash": "0x9b8c73ea139f13028008eedef53a6b07576cd6b08979574e6dde3192656e9268"
"initCodeHash": "0x42291ef554697b24e310c9fcf49b8f13a429a924070cda4244da1d6a64717179",
"sourceCodeHash": "0xfa51d0af52ac01c227e1f291dec74663c81e99fa3594cc052af64641c4337e0f"
},
"src/universal/OptimismMintableERC721.sol": {
"initCodeHash": "0xb400f430acf4d65bee9635e4935a6e1e3a0284fc50aea40ad8b7818dc826f31c",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"outputs": [
{
"internalType": "address",
"name": "",
"name": "_localToken",
"type": "address"
}
],
Expand Down Expand Up @@ -122,6 +122,25 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "deployments",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@
"type": "address"
},
{
"bytes": "1568",
"label": "__gap",
"bytes": "32",
"label": "deployments",
"offset": 0,
"slot": "2",
"type": "uint256[49]"
"type": "mapping(address => address)"
},
{
"bytes": "1536",
"label": "__gap",
"offset": 0,
"slot": "3",
"type": "uint256[48]"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.15;
import { OptimismMintableERC20 } from "src/universal/OptimismMintableERC20.sol";
import { ISemver } from "src/universal/ISemver.sol";
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import { IOptimismERC20Factory } from "src/L2/IOptimismERC20Factory.sol";

/// @custom:proxied
/// @custom:predeployed 0x4200000000000000000000000000000000000012
Expand All @@ -12,7 +13,7 @@ import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable
/// contracts on the network it's deployed to. Simplifies the deployment process for users
/// who may be less familiar with deploying smart contracts. Designed to be backwards
/// compatible with the older StandardL2ERC20Factory contract.
abstract contract OptimismMintableERC20Factory is ISemver, Initializable {
contract OptimismMintableERC20Factory is ISemver, Initializable, IOptimismERC20Factory {
/// @custom:spacer OptimismMintableERC20Factory's initializer slot spacing
/// @notice Spacer to avoid packing into the initializer slot
bytes30 private spacer_0_2_30;
Expand All @@ -21,10 +22,14 @@ abstract contract OptimismMintableERC20Factory is ISemver, Initializable {
/// @custom:network-specific
address public bridge;

/// @notice Mapping of local token address to remote token address.
/// This is used to keep track of the token deployments.
mapping(address => address) public deployments;

/// @notice Reserve extra slots in the storage layout for future upgrades.
/// A gap size of 49 was chosen here, so that the first slot used in a child contract
/// would be 1 plus a multiple of 50.
uint256[49] private __gap;
/// A gap size of 48 was chosen here, so that the first slot used in a child contract
/// would be a multiple of 50.
uint256[48] private __gap;

/// @custom:legacy
/// @notice Emitted whenever a new OptimismMintableERC20 is created. Legacy version of the newer
Expand Down Expand Up @@ -104,33 +109,29 @@ abstract contract OptimismMintableERC20Factory is ISemver, Initializable {
/// @param _name ERC20 name.
/// @param _symbol ERC20 symbol.
/// @param _decimals ERC20 decimals
/// @return Address of the newly created token.
/// @return _localToken Address of the newly created token.
function createOptimismMintableERC20WithDecimals(
address _remoteToken,
string memory _name,
string memory _symbol,
uint8 _decimals
)
public
returns (address)
returns (address _localToken)
{
return createWithCreate3(_remoteToken, _name, _symbol, _decimals);
}
require(_remoteToken != address(0), "OptimismMintableERC20Factory: must provide remote token address");

/// @notice Creates an instance of the OptimismMintableERC20 contract, with specified decimals using CREATE3.
/// To be implemented by the child contract.
/// @param _remoteToken Address of the token on the remote chain.
/// @param _name ERC20 name.
/// @param _symbol ERC20 symbol.
/// @param _decimals ERC20 decimals.
/// @return Address of the newly created token.
function createWithCreate3(
address _remoteToken,
string memory _name,
string memory _symbol,
uint8 _decimals
)
public
virtual
returns (address);
bytes32 salt = keccak256(abi.encode(_remoteToken, _name, _symbol, _decimals));

_localToken = address(new OptimismMintableERC20{ salt: salt }(bridge, _remoteToken, _name, _symbol, _decimals));

deployments[_localToken] = _remoteToken;

// Emit the old event too for legacy support.
emit StandardL2TokenCreated(_remoteToken, _localToken);

// Emit the updated event. The arguments here differ from the legacy event, but
// are consistent with the ordering used in StandardBridge events.
emit OptimismMintableERC20Created(_localToken, _remoteToken, msg.sender);
}
}

This file was deleted.

Loading

0 comments on commit 8209d4b

Please sign in to comment.