Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update transaction fees #6

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jordanmessina @ponyjackal This would be a great function to unit test to make sure it can't underflow, overflow, etc. with realistic values for various L2s

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
Loading