Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixFan1992 committed Aug 19, 2024
1 parent bf41b09 commit 873887c
Show file tree
Hide file tree
Showing 7 changed files with 1,407 additions and 80 deletions.
1 change: 1 addition & 0 deletions contracts/scripts/native_solc_compile_all_automation
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ compileContract automation/interfaces/v2_2/IAutomationRegistryMaster.sol
compileContract automation/chains/ArbitrumModule.sol
compileContract automation/chains/ChainModuleBase.sol
compileContract automation/chains/OptimismModule.sol
compileContract automation/chains/OptimismModuleV2.sol
compileContract automation/chains/ScrollModule.sol
compileContract automation/interfaces/IChainModule.sol
compileContract automation/interfaces/IAutomationV21PlusCommon.sol
Expand Down
32 changes: 26 additions & 6 deletions contracts/src/v0.8/automation/chains/ScrollModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ pragma solidity 0.8.19;

import {IScrollL1GasPriceOracle} from "../../vendor/@scroll-tech/contracts/src/L2/predeploys/IScrollL1GasPriceOracle.sol";
import {ChainModuleBase} from "./ChainModuleBase.sol";
import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol";

contract ScrollModule is ChainModuleBase, ConfirmedOwner {
error InvalidL1FeeCoefficient(uint8 coefficient);
event L1FeeCoefficientSet(uint8 coefficient);

contract ScrollModule is ChainModuleBase {
/// @dev SCROLL_L1_FEE_DATA_PADDING includes 140 bytes for L1 data padding for Scroll
/// @dev according to testing, this padding allows automation registry to properly estimates L1 data fee with 3-5% buffer
/// @dev this MAY NOT work for a different product and this may get out of date if transmit function is changed
Expand All @@ -15,17 +19,23 @@ contract ScrollModule is ChainModuleBase {
address private constant SCROLL_ORACLE_ADDR = 0x5300000000000000000000000000000000000002;
IScrollL1GasPriceOracle private constant SCROLL_ORACLE = IScrollL1GasPriceOracle(SCROLL_ORACLE_ADDR);

/// @dev L1 fee coefficient can be applied to reduce possibly inflated gas cost
uint8 public s_l1FeeCoefficient = 100;
uint256 private constant FIXED_GAS_OVERHEAD = 45_000;
// @dev PER_CALLDATA_BYTE_GAS_OVERHEAD is used to calculate the cost of calling the oracle with calldata
uint256 private constant PER_CALLDATA_BYTE_GAS_OVERHEAD = 170;

function getCurrentL1Fee(uint256) external view override returns (uint256) {
return SCROLL_ORACLE.getL1Fee(bytes.concat(msg.data, SCROLL_L1_FEE_DATA_PADDING));
constructor() ConfirmedOwner(msg.sender) {}

function getCurrentL1Fee(uint256 dataSize) external view override returns (uint256) {
return (s_l1FeeCoefficient * _getL1Fee(dataSize)) / 100;
}

function getMaxL1Fee(uint256 dataSize) external view override returns (uint256) {
// fee is 4 per 0 byte, 16 per non-zero byte. Worst case we can have all non zero-bytes.
// Instead of setting bytes to non-zero, we initialize 'new bytes' of length 4*dataSize to cover for zero bytes.
// this is the same as OP.
return _getL1Fee(dataSize);
}

function _getL1Fee(uint256 dataSize) internal view returns (uint256) {
bytes memory txCallData = new bytes(4 * dataSize);
return SCROLL_ORACLE.getL1Fee(bytes.concat(txCallData, SCROLL_L1_FEE_DATA_PADDING));
}
Expand All @@ -38,4 +48,14 @@ contract ScrollModule is ChainModuleBase {
{
return (FIXED_GAS_OVERHEAD, PER_CALLDATA_BYTE_GAS_OVERHEAD);
}

function setL1FeeCalculation(uint8 coefficient) external onlyOwner {
if (coefficient > 100) {
revert InvalidL1FeeCoefficient(coefficient);
}

s_l1FeeCoefficient = coefficient;

emit L1FeeCoefficientSet(coefficient);
}
}
64 changes: 0 additions & 64 deletions contracts/src/v0.8/automation/chains/ScrollModuleV2.sol

This file was deleted.

Loading

0 comments on commit 873887c

Please sign in to comment.