MCPcopy Create free account
hub / github.com/circlefin/arc-node / getNextBaseFee

Function getNextBaseFee

tests/helpers/SystemAccounting.ts:52–84  ·  view source on GitHub ↗
(client: PublicClient, blockNumber?: bigint)

Source from the content-addressed store, hash-verified

50}
51
52export 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
86type BaseFeeParams = {
87 inverseElasticityMultiplier: bigint

Callers 2

query-fee.tsFile · 0.85

Calls 4

isArcNetworkFunction · 0.90
clampBaseFeeFunction · 0.90
calc1559BaseFeeFunction · 0.85
attachMethod · 0.45

Tested by

no test coverage detected