-
Notifications
You must be signed in to change notification settings - Fork 18
/
L2TxFeeVault.sol
167 lines (131 loc) · 6.1 KB
/
L2TxFeeVault.sol
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// SPDX-License-Identifier: MIT
// MIT License
// Copyright (c) 2022 Optimism
// Copyright (c) 2022 Scroll
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
pragma solidity =0.8.24;
import {IL2ScrollMessenger} from "../IL2ScrollMessenger.sol";
import {OwnableBase} from "../../libraries/common/OwnableBase.sol";
// solhint-disable no-empty-blocks
// solhint-disable reason-string
/// @title L2TxFeeVault
/// @notice The L2TxFeeVault contract contains the logic for the vault contracts
/// used to hold fee revenue generated by the L2 system.
contract L2TxFeeVault is OwnableBase {
/**********
* Events *
**********/
/// @notice Emits each time that a withdrawal occurs.
///
/// @param value Amount that was withdrawn (in wei).
/// @param to Address that the funds were sent to.
/// @param from Address that triggered the withdrawal.
event Withdrawal(uint256 value, address to, address from);
/// @notice Emits each time the owner updates the address of `messenger`.
/// @param oldMessenger The address of old messenger.
/// @param newMessenger The address of new messenger.
event UpdateMessenger(address indexed oldMessenger, address indexed newMessenger);
/// @notice Emits each time the owner updates the address of `recipient`.
/// @param oldRecipient The address of old recipient.
/// @param newRecipient The address of new recipient.
event UpdateRecipient(address indexed oldRecipient, address indexed newRecipient);
/// @notice Emits each time the owner updates the value of `minWithdrawAmount`.
/// @param oldMinWithdrawAmount The value of old `minWithdrawAmount`.
/// @param newMinWithdrawAmount The value of new `minWithdrawAmount`.
event UpdateMinWithdrawAmount(uint256 oldMinWithdrawAmount, uint256 newMinWithdrawAmount);
/*************
* Variables *
*************/
/// @notice Minimum balance before a withdrawal can be triggered.
uint256 public minWithdrawAmount;
/// @notice Scroll L2 messenger address.
address public messenger;
/// @notice Wallet that will receive the fees on L1.
address public recipient;
/// @notice Total amount of wei processed by the contract.
uint256 public totalProcessed;
/***************
* Constructor *
***************/
/// @param _owner The owner of the contract.
/// @param _recipient Wallet that will receive the fees on L1.
/// @param _minWithdrawalAmount Minimum balance before a withdrawal can be triggered.
constructor(
address _owner,
address _recipient,
uint256 _minWithdrawalAmount
) {
_transferOwnership(_owner);
minWithdrawAmount = _minWithdrawalAmount;
recipient = _recipient;
}
/*****************************
* Public Mutating Functions *
*****************************/
/// @notice Allow the contract to receive ETH.
receive() external payable {}
/// @notice Triggers a withdrawal of funds to the L1 fee wallet.
/// @param _value The amount of ETH to withdraw.
function withdraw(uint256 _value) public {
require(
_value >= minWithdrawAmount,
"FeeVault: withdrawal amount must be greater than minimum withdrawal amount"
);
uint256 _balance = address(this).balance;
require(_value <= _balance, "FeeVault: insufficient balance to withdraw");
unchecked {
totalProcessed += _value;
}
emit Withdrawal(_value, recipient, msg.sender);
// no fee provided
IL2ScrollMessenger(messenger).sendMessage{value: _value}(
recipient,
_value,
bytes(""), // no message (simple eth transfer)
0 // _gasLimit can be zero for fee vault.
);
}
/// @notice Triggers a withdrawal of all available funds to the L1 fee wallet.
function withdraw() external {
uint256 value = address(this).balance;
withdraw(value);
}
/************************
* Restricted Functions *
************************/
/// @notice Update the address of messenger.
/// @param _newMessenger The address of messenger to update.
function updateMessenger(address _newMessenger) external onlyOwner {
address _oldMessenger = messenger;
messenger = _newMessenger;
emit UpdateMessenger(_oldMessenger, _newMessenger);
}
/// @notice Update the address of recipient.
/// @param _newRecipient The address of recipient to update.
function updateRecipient(address _newRecipient) external onlyOwner {
address _oldRecipient = recipient;
recipient = _newRecipient;
emit UpdateRecipient(_oldRecipient, _newRecipient);
}
/// @notice Update the minimum withdraw amount.
/// @param _newMinWithdrawAmount The minimum withdraw amount to update.
function updateMinWithdrawAmount(uint256 _newMinWithdrawAmount) external onlyOwner {
uint256 _oldMinWithdrawAmount = minWithdrawAmount;
minWithdrawAmount = _newMinWithdrawAmount;
emit UpdateMinWithdrawAmount(_oldMinWithdrawAmount, _newMinWithdrawAmount);
}
}