Skip to content

Commit

Permalink
Merge pull request #6 from Once-Upon/benguyen0214/ou-1664-include-l2-…
Browse files Browse the repository at this point in the history
…fee-math-in-the-transformations-repo

feat: update transaction fees
  • Loading branch information
pcowgill authored Feb 9, 2024
2 parents 1547ef4 + 3b90d7e commit 7fc38d8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/transformers/ethereum/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7fc38d8

Please sign in to comment.