Skip to content

Commit 78a4f7e

Browse files
committed
chain/ethereum: use effective gas price instead of gas_price
1 parent 50ad26b commit 78a4f7e

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

chain/ethereum/src/trigger.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use graph::data::subgraph::API_VERSION_0_0_2;
55
use graph::data::subgraph::API_VERSION_0_0_6;
66
use graph::data::subgraph::API_VERSION_0_0_7;
77
use graph::data_source::common::DeclaredCall;
8-
use graph::prelude::alloy::consensus::Transaction as TransactioTrait;
8+
use graph::prelude::alloy::consensus::Transaction as TransactionTrait;
99
use graph::prelude::alloy::primitives::{Address, B256, U256};
1010
use graph::prelude::alloy::rpc::types::Log;
1111
use graph::prelude::alloy::rpc::types::Transaction;
@@ -483,13 +483,17 @@ impl<'a> EthereumBlockData<'a> {
483483
#[derive(Clone, Debug)]
484484
pub struct EthereumTransactionData<'a> {
485485
tx: &'a Transaction,
486+
base_fee_per_gas: Option<u64>,
486487
}
487488

488489
impl<'a> EthereumTransactionData<'a> {
489490
// We don't implement `From` because it causes confusion with the `from`
490491
// accessor method
491-
fn new(tx: &'a Transaction) -> EthereumTransactionData<'a> {
492-
EthereumTransactionData { tx }
492+
fn new(tx: &'a Transaction, base_fee_per_gas: Option<u64>) -> EthereumTransactionData<'a> {
493+
EthereumTransactionData {
494+
tx,
495+
base_fee_per_gas,
496+
}
493497
}
494498

495499
pub fn hash(&self) -> &B256 {
@@ -517,8 +521,7 @@ impl<'a> EthereumTransactionData<'a> {
517521
}
518522

519523
pub fn gas_price(&self) -> u128 {
520-
// EIP-1559 made this optional.
521-
self.tx.inner.gas_price().unwrap_or(0)
524+
self.tx.effective_gas_price(self.base_fee_per_gas)
522525
}
523526

524527
pub fn input(&self) -> &[u8] {
@@ -548,7 +551,7 @@ impl<'a> EthereumEventData<'a> {
548551
) -> Self {
549552
EthereumEventData {
550553
block: EthereumBlockData::from(block),
551-
transaction: EthereumTransactionData::new(tx),
554+
transaction: EthereumTransactionData::new(tx, block.base_fee_per_gas()),
552555
log,
553556
params,
554557
}
@@ -598,7 +601,7 @@ impl<'a> EthereumCallData<'a> {
598601
) -> EthereumCallData<'a> {
599602
EthereumCallData {
600603
block: EthereumBlockData::from(block),
601-
transaction: EthereumTransactionData::new(transaction),
604+
transaction: EthereumTransactionData::new(transaction, block.base_fee_per_gas()),
602605
inputs,
603606
outputs,
604607
call,

graph/src/components/ethereum/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ impl BlockWrapper {
4141
pub fn inner(&self) -> &AlloyBlock {
4242
&self.0
4343
}
44+
45+
pub fn base_fee_per_gas(&self) -> Option<u64> {
46+
self.0.header.base_fee_per_gas
47+
}
4448
}
4549

4650
pub type LightEthereumBlock = BlockWrapper;

0 commit comments

Comments
 (0)