Skip to content

Commit

Permalink
Add getL1FeeUpperBound to GasPriceOracle
Browse files Browse the repository at this point in the history
  • Loading branch information
yukaitu-cb committed Mar 19, 2024
1 parent 69923a7 commit 0882d75
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
35 changes: 33 additions & 2 deletions op-bindings/bindings/gaspriceoracle.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/gaspriceoracle_more.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/l1block.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion op-bindings/bindings/l1block_more.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/contracts-bedrock/src/L2/GasPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,26 @@ contract GasPriceOracle is ISemver {
return _getL1FeeBedrock(_data);
}

/// @notice returns an upper bound for the L1 fee for a given transaction size.
/// It is provided for callers who wish to estimate L1 transaction costs in the
/// write path, and is much more gas efficient than `getL1Fee`.
/// It assumes the worst case of fastlz upper-bound which covers %99.99 txs.
/// @param _unsignedTxSize Unsigned fully RLP-encoded transaction size to get the L1 fee for.
/// @return L1 estimated upper-bound fee that should be paid for the tx
function getL1FeeUpperBound(uint256 _unsignedTxSize) external view returns (uint256) {
require(isFjord, "GasPriceOracle: getL1FeeUpperBound only supports Fjord");

int256 txSize = int256(_unsignedTxSize) + 68;
uint256 feeScaled = baseFeeScalar() * 16 * l1BaseFee() + blobBaseFeeScalar() * blobBaseFee();
// txSize / 255 + 16 is the pratical fastlz upper-bound covers %99.99 txs.
int256 flzUpperBound = txSize / 255 + 16;
int256 cost = COST_INTERCEPT + COST_FASTLZ_COEF * flzUpperBound + COST_TX_SIZE_COEF * txSize;
if (cost < 0) {
cost = 0;
}
return uint256(cost) * feeScaled / (10 ** (DECIMALS * 2));
}

/// @notice Set chain to be Ecotone chain (callable by depositor account)
function setEcotone() external {
require(
Expand Down

0 comments on commit 0882d75

Please sign in to comment.