From 2bb708071734c2e3ad772632babe9f66b8800ada Mon Sep 17 00:00:00 2001 From: ponyjackal Date: Tue, 6 Feb 2024 16:29:04 -0800 Subject: [PATCH 1/2] feat: update transaction fees --- src/transformers/ethereum/fees.ts | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/transformers/ethereum/fees.ts b/src/transformers/ethereum/fees.ts index 4debbd3..bcfc35f 100644 --- a/src/transformers/ethereum/fees.ts +++ b/src/transformers/ethereum/fees.ts @@ -5,22 +5,20 @@ export function transform(block: RawBlock): RawBlock { let totalL2FeeWei = BigInt(0); if (tx.gasPrice) { const l2GasPrice = BigInt(tx.gasPrice); - const l2GasUsed = BigInt(tx.receipt?.gasUsed ?? 0); + const l2GasUsed = BigInt(tx.receipt.gasUsed); - 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); + const l1GasWithoutScalarAsNumber = Number(l1GasWithoutScalar); + const l1GasWithScalar = l1GasWithoutScalarAsNumber * scalar; + + totalL2FeeWei = BigInt(l1GasWithScalar) + l2Gas; } tx.baseFeePerGas = block.baseFeePerGas; From 3b90d7eda60c868254c0b5e2f2385e2919b1dd83 Mon Sep 17 00:00:00 2001 From: ponyjackal Date: Wed, 7 Feb 2024 02:12:51 -0800 Subject: [PATCH 2/2] feat: update l1GasWithScalar --- src/transformers/ethereum/fees.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transformers/ethereum/fees.ts b/src/transformers/ethereum/fees.ts index bcfc35f..4800ef7 100644 --- a/src/transformers/ethereum/fees.ts +++ b/src/transformers/ethereum/fees.ts @@ -4,8 +4,8 @@ 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); + const l2GasPrice = BigInt(tx.gasPrice ?? 0); + const l2GasUsed = BigInt(tx.receipt.gasUsed ?? 0); const l2Gas = l2GasPrice * l2GasUsed; @@ -14,7 +14,7 @@ export function transform(block: RawBlock): RawBlock { const l1GasWithoutScalar = l1GasPrice * l1GasUsed; - const scalar = Number(tx.receipt.l1FeeScalar); + const scalar = Number(tx.receipt.l1FeeScalar ?? 0); const l1GasWithoutScalarAsNumber = Number(l1GasWithoutScalar); const l1GasWithScalar = l1GasWithoutScalarAsNumber * scalar;