diff --git a/src/transformers/ethereum/fees.ts b/src/transformers/ethereum/fees.ts index 4debbd3..4800ef7 100644 --- a/src/transformers/ethereum/fees.ts +++ b/src/transformers/ethereum/fees.ts @@ -4,23 +4,21 @@ export function transform(block: RawBlock): RawBlock { block.transactions = block.transactions.map((tx) => { let totalL2FeeWei = BigInt(0); if (tx.gasPrice) { - const l2GasPrice = BigInt(tx.gasPrice); - const l2GasUsed = BigInt(tx.receipt?.gasUsed ?? 0); + const l2GasPrice = BigInt(tx.gasPrice ?? 0); + const l2GasUsed = BigInt(tx.receipt.gasUsed ?? 0); - const tenToTheEighteenth = BigInt('1000000000000000000'); + const l2Gas = l2GasPrice * l2GasUsed; - const l1FeeContribution = !tx.receipt?.l1GasUsed - ? BigInt(0) - : (BigInt(tx.receipt?.l1GasPrice ?? 0) * - BigInt(tx.receipt.l1GasUsed) * - BigInt( - parseFloat(tx.receipt?.l1FeeScalar ?? '0') * Math.pow(10, 18), - )) / - tenToTheEighteenth; + const l1GasUsed = BigInt(tx.receipt.l1GasUsed ?? 0); + const l1GasPrice = BigInt(tx.receipt.l1GasPrice ?? 0); - const l2FeeContribution = l2GasPrice * l2GasUsed; + const l1GasWithoutScalar = l1GasPrice * l1GasUsed; - totalL2FeeWei = l2FeeContribution + l1FeeContribution; + const scalar = Number(tx.receipt.l1FeeScalar ?? 0); + const l1GasWithoutScalarAsNumber = Number(l1GasWithoutScalar); + const l1GasWithScalar = l1GasWithoutScalarAsNumber * scalar; + + totalL2FeeWei = BigInt(l1GasWithScalar) + l2Gas; } tx.baseFeePerGas = block.baseFeePerGas;