|
1 | 1 | // SPDX-License-Identifier: Apache-2.0. |
2 | 2 | pragma solidity ^0.8.0; |
3 | 3 |
|
| 4 | +// Estimate cost for L1-L2 message handler. |
4 | 5 | uint256 constant DEPOSIT_FEE_GAS = 20000; |
5 | 6 | uint256 constant DEPLOYMENT_FEE_GAS = 100000; |
6 | | -uint256 constant MIN_FEE_MARGIN = 100000; |
7 | | -uint256 constant MAX_FEE_MARGIN = 10**14; |
8 | 7 |
|
9 | | -library Fees { |
10 | | - function estimateDepositFee() internal view returns (uint256) { |
11 | | - return DEPOSIT_FEE_GAS * block.basefee; |
12 | | - } |
| 8 | +// We don't have a solid way to gauge block gas price |
| 9 | +// (block.basefee cannot be used). |
| 10 | +uint256 constant DEFAULT_WEI_PER_GAS = 5 * 10**9; |
13 | 11 |
|
14 | | - function estimateEnrollmentFee() internal view returns (uint256) { |
15 | | - return DEPLOYMENT_FEE_GAS * block.basefee; |
16 | | - } |
| 12 | +abstract contract Fees { |
| 13 | + // Effectively no minimum fee on testnet. |
| 14 | + uint256 immutable MIN_FEE = (block.chainid == 1) ? 10**12 : 1; |
| 15 | + uint256 constant MAX_FEE = 10**16; |
17 | 16 |
|
18 | | - function checkDepositFee(uint256 feeWei) internal view { |
19 | | - checkFee(feeWei, estimateDepositFee()); |
| 17 | + function estimateDepositFee() internal pure returns (uint256) { |
| 18 | + return DEPOSIT_FEE_GAS * DEFAULT_WEI_PER_GAS; |
20 | 19 | } |
21 | 20 |
|
22 | | - function checkEnrollmentFee(uint256 feeWei) internal view { |
23 | | - checkFee(feeWei, estimateEnrollmentFee()); |
| 21 | + function estimateEnrollmentFee() internal pure returns (uint256) { |
| 22 | + return DEPLOYMENT_FEE_GAS * DEFAULT_WEI_PER_GAS; |
24 | 23 | } |
25 | 24 |
|
26 | | - /* |
27 | | - The fee should be within margins from the estimated fee: |
28 | | - max(5, estimate/2 - MIN_FEE_MARGIN) <= fee <= 2*estimate + MAX_FEE_MARGIN. |
29 | | - */ |
30 | | - function checkFee(uint256 feeWei, uint256 feeEstimate) internal pure { |
31 | | - uint256 minFee = feeEstimate >> 1; |
32 | | - minFee = (minFee < MIN_FEE_MARGIN + 5) ? 5 : (minFee - MIN_FEE_MARGIN); |
33 | | - uint256 maxFee = MAX_FEE_MARGIN + (feeEstimate << 1); |
34 | | - require(feeWei >= minFee, "INSUFFICIENT_FEE_VALUE"); |
35 | | - require(feeWei <= maxFee, "FEE_VALUE_TOO_HIGH"); |
| 25 | + function checkFee(uint256 feeWei) internal view { |
| 26 | + require(feeWei >= MIN_FEE, "INSUFFICIENT_FEE_VALUE"); |
| 27 | + require(feeWei <= MAX_FEE, "FEE_VALUE_TOO_HIGH"); |
36 | 28 | } |
37 | 29 | } |
0 commit comments