Skip to content

Commit

Permalink
contracts-bedrock: define functions for setting static values
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfuturistic committed May 10, 2024
1 parent 2b22287 commit ac6bf98
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
30 changes: 26 additions & 4 deletions packages/contracts-bedrock/src/L1/OptimismPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver {
_;
}

/// @notice Reverts when the caller is not the SystemConfig contract.
modifier onlySystemConfig() {
if (msg.sender != address(systemConfig)) revert Unauthorized();
_;
}

/// @notice Semantic version.
/// @custom:semver 2.7.0
string public constant version = "2.7.0";
Expand Down Expand Up @@ -556,11 +562,27 @@ contract OptimismPortal is Initializable, ResourceMetering, ISemver {
emit TransactionDeposited(from, _to, DEPOSIT_VERSION, opaqueData);
}

/// @notice Sets static configuration options for the L2 system. Only the SystemConfig contract can call this
/// function.
function setConfig(ConfigType _type, bytes memory _value) external {
if (msg.sender != address(systemConfig)) revert Unauthorized();
/// @notice Sets the gas paying token for the L2 system. This token is used as the
/// L2 native asset. Only the SystemConfig contract can call this function.
function setGasPayingToken(
address _token,
uint8 _decimals,
bytes32 _name,
bytes32 _symbol
)
external
onlySystemConfig
{
setConfig(ConfigType.GAS_PAYING_TOKEN, abi.encode(_token, _decimals, _name, _symbol));
}

/// @notice Sets the batcher hash for the L2 system. Only the SystemConfig contract can call this function.
function setBatcherHash(bytes32 _batcherHash) external onlySystemConfig {
setConfig(ConfigType.BATCHER_HASH, abi.encode(_batcherHash));
}

/// @notice Sets static configuration options for the L2 system.
function _setConfig(ConfigType _type, bytes memory _value) internal {
// Set L2 deposit gas as used without paying burning gas. Ensures that deposits cannot use too much L2 gas.
// This value must be large enough to cover the cost of calling `L1Block.setConfig`.
useGas(SYSTEM_DEPOSIT_GAS_LIMIT);
Expand Down
11 changes: 7 additions & 4 deletions packages/contracts-bedrock/src/L1/SystemConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,12 @@ contract SystemConfig is OwnableUpgradeable, ISemver, IGasToken {

// Set the gas paying token in storage and in the OptimismPortal.
GasPayingToken.set({ _token: _token, _decimals: GAS_PAYING_TOKEN_DECIMALS, _name: name, _symbol: symbol });
OptimismPortal(payable(optimismPortal())).setConfig(
ConfigType.GAS_PAYING_TOKEN, abi.encode(_token, GAS_PAYING_TOKEN_DECIMALS, name, symbol)
);
OptimismPortal(payable(optimismPortal())).setGasPayingToken({
_token: _token,
_decimals: GAS_PAYING_TOKEN_DECIMALS,
_name: name,
_symbol: symbol
});
}
}

Expand Down Expand Up @@ -341,7 +344,7 @@ contract SystemConfig is OwnableUpgradeable, ISemver, IGasToken {

bytes memory data = abi.encode(_batcherHash);

OptimismPortal(payable(optimismPortal())).setConfig(ConfigType.BATCHER_HASH, data);
OptimismPortal(payable(optimismPortal())).setBatcherHash(data);

emit ConfigUpdate(VERSION, UpdateType.BATCHER, data);
}
Expand Down

0 comments on commit ac6bf98

Please sign in to comment.