@@ -4,102 +4,28 @@ import type { ViemPublicClient } from '@aztec/ethereum/types';
44import { BlockNumber , SlotNumber } from '@aztec/foundation/branded-types' ;
55import { Fr } from '@aztec/foundation/curves/bn254' ;
66import type { EthAddress } from '@aztec/foundation/eth-address' ;
7- import { createLogger } from '@aztec/foundation/log' ;
87import type { DateProvider } from '@aztec/foundation/timer' ;
98import type { AztecAddress } from '@aztec/stdlib/aztec-address' ;
109import { type L1RollupConstants , getNextL1SlotTimestamp , getTimestampForSlot } from '@aztec/stdlib/epoch-helpers' ;
11- import { GasFees , ManaUsageEstimate } from '@aztec/stdlib/gas' ;
10+ import { GasFees } from '@aztec/stdlib/gas' ;
1211import type {
1312 BuildCheckpointGlobalVariablesOpts ,
1413 CheckpointGlobalVariables ,
15- FeeProvider ,
1614 GlobalVariableBuilder as GlobalVariableBuilderInterface ,
1715} from '@aztec/stdlib/tx' ;
1816import { GlobalVariables } from '@aztec/stdlib/tx' ;
1917
20- import { FeePredictor } from './fee_predictor.js' ;
21-
2218/** Configuration for the GlobalVariableBuilder (excludes L1 client config). */
2319export type GlobalVariableBuilderConfig = {
2420 l1Contracts : Pick < L1ContractAddresses , 'rollupAddress' > ;
2521 ethereumSlotDuration : number ;
2622 rollupVersion : bigint ;
2723} & Pick < L1RollupConstants , 'slotDuration' | 'l1GenesisTime' > ;
2824
29- /** Provides current and predicted fee information based on on-chain state. */
30- export class FeeProviderImpl implements FeeProvider {
31- private currentMinFees : Promise < GasFees > = Promise . resolve ( new GasFees ( 0 , 0 ) ) ;
32- private currentL1BlockNumber : bigint | undefined = undefined ;
33-
34- private readonly rollupContract : RollupContract ;
35- private readonly feePredictor : FeePredictor ;
36- private readonly ethereumSlotDuration : number ;
37- private readonly l1GenesisTime : bigint ;
38-
39- constructor (
40- private readonly dateProvider : DateProvider ,
41- private readonly publicClient : ViemPublicClient ,
42- config : GlobalVariableBuilderConfig ,
43- ) {
44- this . ethereumSlotDuration = config . ethereumSlotDuration ;
45- this . l1GenesisTime = config . l1GenesisTime ;
46-
47- this . rollupContract = new RollupContract ( this . publicClient , config . l1Contracts . rollupAddress ) ;
48- this . feePredictor = new FeePredictor (
49- this . rollupContract ,
50- this . publicClient ,
51- this . dateProvider ,
52- config . slotDuration ,
53- config . l1GenesisTime ,
54- config . ethereumSlotDuration ,
55- ) ;
56- }
57-
58- /**
59- * Computes the "current" min fees, e.g., the price that you currently should pay to get include in the next block
60- * @returns Min fees for the next block
61- */
62- private async computeCurrentMinFees ( ) : Promise < GasFees > {
63- // Since this might be called in the middle of a slot where a block might have been published,
64- // we need to fetch the last block written, and estimate the earliest timestamp for the next block.
65- // The timestamp of that last block will act as a lower bound for the next block.
66-
67- const lastCheckpoint = await this . rollupContract . getPendingCheckpoint ( ) ;
68- const earliestTimestamp = await this . rollupContract . getTimestampForSlot (
69- SlotNumber . fromBigInt ( BigInt ( lastCheckpoint . slotNumber ) + 1n ) ,
70- ) ;
71- const nextEthTimestamp = getNextL1SlotTimestamp ( this . dateProvider . nowInSeconds ( ) , {
72- l1GenesisTime : this . l1GenesisTime ,
73- ethereumSlotDuration : this . ethereumSlotDuration ,
74- } ) ;
75- const timestamp = earliestTimestamp > nextEthTimestamp ? earliestTimestamp : nextEthTimestamp ;
76-
77- return new GasFees ( 0 , await this . rollupContract . getManaMinFeeAt ( timestamp , true ) ) ;
78- }
79-
80- public async getCurrentMinFees ( ) : Promise < GasFees > {
81- // Get the current block number
82- const blockNumber = await this . publicClient . getBlockNumber ( ) ;
83-
84- // If the L1 block number has changed then chain a new promise to get the current min fees
85- if ( this . currentL1BlockNumber === undefined || blockNumber > this . currentL1BlockNumber ) {
86- this . currentL1BlockNumber = blockNumber ;
87- this . currentMinFees = this . currentMinFees . then ( ( ) => this . computeCurrentMinFees ( ) ) ;
88- }
89- return this . currentMinFees ;
90- }
91-
92- public getPredictedMinFees ( manaUsage ?: ManaUsageEstimate ) : Promise < GasFees [ ] > {
93- return this . feePredictor . getPredictedMinFees ( manaUsage ?? ManaUsageEstimate . Target ) ;
94- }
95- }
96-
9725/**
9826 * Simple global variables builder.
9927 */
10028export class GlobalVariableBuilder implements GlobalVariableBuilderInterface {
101- private log = createLogger ( 'sequencer:global_variable_builder' ) ;
102-
10329 private readonly rollupContract : RollupContract ;
10430 private readonly ethereumSlotDuration : number ;
10531 private readonly aztecSlotDuration : number ;
0 commit comments