The service fetches the L1 ETH balances of sequencer, proposer, relayer and fast relayer in each polling interval. Based on the ETH balances, we can calculate the costs of maintaining the Layer 2.
L1ETHBalance: The ETH balances of all accounts
L1ETHCostFee: The ETH fees that we pay to maintain the Layer 2 since the gas oracle service starts
The service also fetches the L2 gas fees collected by us based on the gasUsage * gasPrice and increased L2 block numbers in each polling interval. We also calculate the average gas usage per block, so we can estimate the gas price.
L2ETHCollectFee: The ETH fees that we collect from the Layer 2 transactions.
avgL2GasLimitPerBlock : The average gas limit per block in each polling interval
numberOfBlocksInterval: The increased number of blocks in each pooling interval
When the estimated L2 gas price is lower than the GAS_PRICE_ORACLE_FLOOR_PRICE, we set the gas price as the GAS_PRICE_ORACLE_FLOOR_PRICE.
When the estimated L2 gas price is larger than the GAS_PRICE_ORACLE_ROOF_PRICE, we set the gas price as the GAS_PRICE_ORACLE_ROOF_PRICE.
When the new estimated L2 gas price is not in the range of (1 + GAS_PRICE_ORACLE_MIN_PERCENT_CHANGE) * latestGasPriceInContract and (1 - GAS_PRICE_ORACLE_MIN_PERCENT_CHANGE) * latestGasPriceInContract, we update the gas price.
numberOfBlocksInterval can affect the gas price significantly. The possible solution is to increase the POLLING_INTERVAL to 30 mins.
When the service starts, the gas price will be restored to the GAS_PRICE_ORACLE_FLOOR_PRICE.
The GAS_PRICE_ORACLE_FLOOR_PRICE and GAS_PRICE_ORACLE_ROOF_PRICE are not easy to be determined in the test environment.