Skip to content

Commit

Permalink
feat: update transaction fees
Browse files Browse the repository at this point in the history
  • Loading branch information
ponyjackal committed Feb 7, 2024
1 parent 1547ef4 commit 2bb7080
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/transformers/ethereum/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2bb7080

Please sign in to comment.