github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/universal/FeeVault.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { L2StandardBridge } from "src/L2/L2StandardBridge.sol"; 5 import { Predeploys } from "src/libraries/Predeploys.sol"; 6 7 /// @title FeeVault 8 /// @notice The FeeVault contract contains the basic logic for the various different vault contracts 9 /// used to hold fee revenue generated by the L2 system. 10 abstract contract FeeVault { 11 /// @notice Enum representing where the FeeVault withdraws funds to. 12 /// @custom:value L1 FeeVault withdraws funds to L1. 13 /// @custom:value L2 FeeVault withdraws funds to L2. 14 enum WithdrawalNetwork { 15 L1, 16 L2 17 } 18 19 /// @notice Minimum balance before a withdrawal can be triggered. 20 uint256 public immutable MIN_WITHDRAWAL_AMOUNT; 21 22 /// @notice Wallet that will receive the fees. 23 address public immutable RECIPIENT; 24 25 /// @notice Network which the RECIPIENT will receive fees on. 26 WithdrawalNetwork public immutable WITHDRAWAL_NETWORK; 27 28 /// @notice The minimum gas limit for the FeeVault withdrawal transaction. 29 uint32 internal constant WITHDRAWAL_MIN_GAS = 35_000; 30 31 /// @notice Total amount of wei processed by the contract. 32 uint256 public totalProcessed; 33 34 /// @notice Emitted each time a withdrawal occurs. This event will be deprecated 35 /// in favor of the Withdrawal event containing the WithdrawalNetwork parameter. 36 /// @param value Amount that was withdrawn (in wei). 37 /// @param to Address that the funds were sent to. 38 /// @param from Address that triggered the withdrawal. 39 event Withdrawal(uint256 value, address to, address from); 40 41 /// @notice Emitted each time a withdrawal occurs. 42 /// @param value Amount that was withdrawn (in wei). 43 /// @param to Address that the funds were sent to. 44 /// @param from Address that triggered the withdrawal. 45 /// @param withdrawalNetwork Network which the to address will receive funds on. 46 event Withdrawal(uint256 value, address to, address from, WithdrawalNetwork withdrawalNetwork); 47 48 /// @param _recipient Wallet that will receive the fees. 49 /// @param _minWithdrawalAmount Minimum balance for withdrawals. 50 /// @param _withdrawalNetwork Network which the recipient will receive fees on. 51 constructor(address _recipient, uint256 _minWithdrawalAmount, WithdrawalNetwork _withdrawalNetwork) { 52 RECIPIENT = _recipient; 53 MIN_WITHDRAWAL_AMOUNT = _minWithdrawalAmount; 54 WITHDRAWAL_NETWORK = _withdrawalNetwork; 55 } 56 57 /// @notice Allow the contract to receive ETH. 58 receive() external payable { } 59 60 /// @notice Triggers a withdrawal of funds to the fee wallet on L1 or L2. 61 function withdraw() external { 62 require( 63 address(this).balance >= MIN_WITHDRAWAL_AMOUNT, 64 "FeeVault: withdrawal amount must be greater than minimum withdrawal amount" 65 ); 66 67 uint256 value = address(this).balance; 68 totalProcessed += value; 69 70 emit Withdrawal(value, RECIPIENT, msg.sender); 71 emit Withdrawal(value, RECIPIENT, msg.sender, WITHDRAWAL_NETWORK); 72 73 if (WITHDRAWAL_NETWORK == WithdrawalNetwork.L2) { 74 (bool success,) = RECIPIENT.call{ value: value }(hex""); 75 require(success, "FeeVault: failed to send ETH to L2 fee recipient"); 76 } else { 77 L2StandardBridge(payable(Predeploys.L2_STANDARD_BRIDGE)).bridgeETHTo{ value: value }( 78 RECIPIENT, WITHDRAWAL_MIN_GAS, bytes("") 79 ); 80 } 81 } 82 }