forked from scroll-tech/scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL1MessageQueueWithGasPriceOracle.sol
More file actions
110 lines (89 loc) · 3.66 KB
/
L1MessageQueueWithGasPriceOracle.sol
File metadata and controls
110 lines (89 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: MIT
pragma solidity =0.8.24;
import {IWhitelist} from "../../libraries/common/IWhitelist.sol";
import {IL1MessageQueue} from "./IL1MessageQueue.sol";
import {IL1MessageQueueWithGasPriceOracle} from "./IL1MessageQueueWithGasPriceOracle.sol";
import {IL2GasPriceOracle} from "./IL2GasPriceOracle.sol";
import {L1MessageQueue} from "./L1MessageQueue.sol";
contract L1MessageQueueWithGasPriceOracle is L1MessageQueue, IL1MessageQueueWithGasPriceOracle {
/*************
* Constants *
*************/
/// @notice The intrinsic gas for transaction.
uint256 private constant INTRINSIC_GAS_TX = 21000;
/// @notice The appropriate intrinsic gas for each byte.
uint256 private constant APPROPRIATE_INTRINSIC_GAS_PER_BYTE = 16;
/*************
* Variables *
*************/
/// @inheritdoc IL1MessageQueueWithGasPriceOracle
uint256 public override l2BaseFee;
/// @inheritdoc IL1MessageQueueWithGasPriceOracle
address public override whitelistChecker;
/***************
* Constructor *
***************/
/// @notice Constructor for `L1MessageQueueWithGasPriceOracle` implementation contract.
///
/// @param _messenger The address of `L1ScrollMessenger` contract.
/// @param _scrollChain The address of `ScrollChain` contract.
/// @param _enforcedTxGateway The address of `EnforcedTxGateway` contract.
constructor(
address _messenger,
address _scrollChain,
address _enforcedTxGateway
) L1MessageQueue(_messenger, _scrollChain, _enforcedTxGateway) {}
/// @notice Initialize the storage of L1MessageQueueWithGasPriceOracle.
function initializeV2() external reinitializer(2) {
l2BaseFee = IL2GasPriceOracle(gasOracle).l2BaseFee();
whitelistChecker = IL2GasPriceOracle(gasOracle).whitelist();
}
/*************************
* Public View Functions *
*************************/
/// @inheritdoc IL1MessageQueue
function estimateCrossDomainMessageFee(uint256 _gasLimit)
external
view
override(IL1MessageQueue, L1MessageQueue)
returns (uint256)
{
return _gasLimit * l2BaseFee;
}
/// @inheritdoc IL1MessageQueue
function calculateIntrinsicGasFee(bytes calldata _calldata)
public
pure
override(IL1MessageQueue, L1MessageQueue)
returns (uint256)
{
// no way this can overflow `uint256`
unchecked {
return INTRINSIC_GAS_TX + _calldata.length * APPROPRIATE_INTRINSIC_GAS_PER_BYTE;
}
}
/*****************************
* Public Mutating Functions *
*****************************/
/// @notice Allows whitelistCheckered caller to modify the l2 base fee.
/// @param _newL2BaseFee The new l2 base fee.
function setL2BaseFee(uint256 _newL2BaseFee) external {
if (!IWhitelist(whitelistChecker).isSenderAllowed(_msgSender())) {
revert ErrorNotWhitelistedSender();
}
uint256 _oldL2BaseFee = l2BaseFee;
l2BaseFee = _newL2BaseFee;
emit UpdateL2BaseFee(_oldL2BaseFee, _newL2BaseFee);
}
/************************
* Restricted Functions *
************************/
/// @notice Update whitelist checker contract.
/// @dev This function can only called by contract owner.
/// @param _newWhitelistChecker The address of new whitelist checker contract.
function updateWhitelistChecker(address _newWhitelistChecker) external onlyOwner {
address _oldWhitelistChecker = whitelistChecker;
whitelistChecker = _newWhitelistChecker;
emit UpdateWhitelistChecker(_oldWhitelistChecker, _newWhitelistChecker);
}
}