Files
FrenoCorp/node_modules/viem/linea/chainConfig.ts
Michael Freno 7c684a42cc FRE-600: Fix code review blockers
- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-25 00:08:01 -04:00

54 lines
1.6 KiB
TypeScript

import type { ChainConfig, ChainEstimateFeesPerGasFn } from '../types/chain.js'
import { estimateGas } from './actions/estimateGas.js'
export const chainConfig = {
fees: {
estimateFeesPerGas,
async maxPriorityFeePerGas({ block, client, request }) {
const response = await estimateFeesPerGas({
block,
client,
multiply: (x) => x,
request,
type: 'eip1559',
})
// Returning `null` will trigger the base `estimateMaxPriorityFeePerGas` to perform
// fallback mechanisms to estimate priority fee.
if (!response?.maxPriorityFeePerGas) return null
return response.maxPriorityFeePerGas
},
},
} as const satisfies ChainConfig
///////////////////////////////////////////////////////////////////////////
// Internal
///////////////////////////////////////////////////////////////////////////
async function estimateFeesPerGas({
client,
multiply,
request,
type,
}: Parameters<ChainEstimateFeesPerGasFn>[0]): ReturnType<ChainEstimateFeesPerGasFn> {
try {
const response = await estimateGas(client, {
...request,
account: request?.account!,
})
const { priorityFeePerGas: maxPriorityFeePerGas } = response
const baseFeePerGas = multiply(BigInt(response.baseFeePerGas))
const maxFeePerGas = baseFeePerGas + maxPriorityFeePerGas
if (type === 'legacy') return { gasPrice: maxFeePerGas }
return {
maxFeePerGas,
maxPriorityFeePerGas,
}
} catch {
// Returning `null` will trigger the base `estimateFeesPerGas` to perform
// fallback mechanisms to estimate fees.
return null
}
}