(client: PublicClient, blockNumber?: bigint)
| 50 | } |
| 51 | |
| 52 | export const getNextBaseFee = async (client: PublicClient, blockNumber?: bigint) => { |
| 53 | const block = await client.getBlock({ blockNumber, includeTransactions: false }) |
| 54 | const isArc = isArcNetwork() |
| 55 | |
| 56 | const feeParams = await (async () => { |
| 57 | try { |
| 58 | return await ProtocolConfig.attach(client).read.feeParams({ blockNumber: block.number }) |
| 59 | } catch (_err) { |
| 60 | return undefined |
| 61 | } |
| 62 | })() |
| 63 | |
| 64 | const nextEIP1559BaseFee = calc1559BaseFee(block.gasUsed, block.gasLimit, block.baseFeePerGas ?? 0n, feeParams) |
| 65 | const { gasUsed, gasUsedSmoothed, nextBaseFee } = isArc |
| 66 | ? await SystemAccounting.getGasValues(client, block.number) |
| 67 | : { gasUsed: 0n, gasUsedSmoothed: 0n, nextBaseFee: 0n } |
| 68 | const nextEMABaseFee = isArc |
| 69 | ? feeParams |
| 70 | ? clampBaseFee(calc1559BaseFee(gasUsedSmoothed, block.gasLimit, block.baseFeePerGas ?? 0n, feeParams), feeParams) |
| 71 | : nextEIP1559BaseFee |
| 72 | : nextEIP1559BaseFee |
| 73 | |
| 74 | return { |
| 75 | block, |
| 76 | gasValues: { gasUsed, gasUsedSmoothed, nextBaseFee }, |
| 77 | feeParams, |
| 78 | next: { |
| 79 | baseFeePerGas: isArc ? nextEMABaseFee : nextEIP1559BaseFee, |
| 80 | emaBaseFee: nextEMABaseFee, |
| 81 | eip1559BaseFee: nextEIP1559BaseFee, |
| 82 | }, |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | type BaseFeeParams = { |
| 87 | inverseElasticityMultiplier: bigint |
no test coverage detected