-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
72 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,29 @@ | ||
// SPDX-License-Identifier: Apache-2.0. | ||
pragma solidity ^0.8.0; | ||
|
||
// Estimate cost for L1-L2 message handler. | ||
uint256 constant DEPOSIT_FEE_GAS = 20000; | ||
uint256 constant DEPLOYMENT_FEE_GAS = 100000; | ||
uint256 constant MIN_FEE_MARGIN = 100000; | ||
uint256 constant MAX_FEE_MARGIN = 10**14; | ||
|
||
library Fees { | ||
function estimateDepositFee() internal view returns (uint256) { | ||
return DEPOSIT_FEE_GAS * block.basefee; | ||
} | ||
// We don't have a solid way to gauge block gas price | ||
// (block.basefee cannot be used). | ||
uint256 constant DEFAULT_WEI_PER_GAS = 5 * 10**9; | ||
|
||
function estimateEnrollmentFee() internal view returns (uint256) { | ||
return DEPLOYMENT_FEE_GAS * block.basefee; | ||
} | ||
abstract contract Fees { | ||
// Effectively no minimum fee on testnet. | ||
uint256 immutable MIN_FEE = (block.chainid == 1) ? 10**12 : 1; | ||
uint256 constant MAX_FEE = 10**16; | ||
|
||
function checkDepositFee(uint256 feeWei) internal view { | ||
checkFee(feeWei, estimateDepositFee()); | ||
function estimateDepositFee() internal pure returns (uint256) { | ||
return DEPOSIT_FEE_GAS * DEFAULT_WEI_PER_GAS; | ||
} | ||
|
||
function checkEnrollmentFee(uint256 feeWei) internal view { | ||
checkFee(feeWei, estimateEnrollmentFee()); | ||
function estimateEnrollmentFee() internal pure returns (uint256) { | ||
return DEPLOYMENT_FEE_GAS * DEFAULT_WEI_PER_GAS; | ||
} | ||
|
||
/* | ||
The fee should be within margins from the estimated fee: | ||
max(5, estimate/2 - MIN_FEE_MARGIN) <= fee <= 2*estimate + MAX_FEE_MARGIN. | ||
*/ | ||
function checkFee(uint256 feeWei, uint256 feeEstimate) internal pure { | ||
uint256 minFee = feeEstimate >> 1; | ||
minFee = (minFee < MIN_FEE_MARGIN + 5) ? 5 : (minFee - MIN_FEE_MARGIN); | ||
uint256 maxFee = MAX_FEE_MARGIN + (feeEstimate << 1); | ||
require(feeWei >= minFee, "INSUFFICIENT_FEE_VALUE"); | ||
require(feeWei <= maxFee, "FEE_VALUE_TOO_HIGH"); | ||
function checkFee(uint256 feeWei) internal view { | ||
require(feeWei >= MIN_FEE, "INSUFFICIENT_FEE_VALUE"); | ||
require(feeWei <= MAX_FEE, "FEE_VALUE_TOO_HIGH"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: Apache-2.0. | ||
pragma solidity ^0.8.0; | ||
|
||
import "src/solidity/Fees.sol"; | ||
|
||
contract TestFees is Fees { | ||
function estimateDepositFeeWei() external pure returns (uint256) { | ||
return Fees.estimateDepositFee(); | ||
} | ||
|
||
function estimateEnrollmentFeeWei() external pure returns (uint256) { | ||
return Fees.estimateEnrollmentFee(); | ||
} | ||
|
||
function testCheckFee(uint256 feeWei) external view { | ||
Fees.checkFee(feeWei); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters