From 294462641ef46f60bc6792062d4190aa721d8b36 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Fri, 20 Sep 2024 01:23:26 -0400 Subject: [PATCH] Don't have the ERC20 collapse the top-level transfer ID to the transaction ID Uses the ID of the transfer event associated with the top-level transfer. --- processor/ethereum/erc20/src/lib.rs | 30 +++++++++-------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/processor/ethereum/erc20/src/lib.rs b/processor/ethereum/erc20/src/lib.rs index 400a5baa..ec33989e 100644 --- a/processor/ethereum/erc20/src/lib.rs +++ b/processor/ethereum/erc20/src/lib.rs @@ -30,8 +30,8 @@ pub use abi::IERC20::Transfer; /// A top-level ERC20 transfer #[derive(Clone, Debug)] pub struct TopLevelTransfer { - /// The transaction ID which effected this transfer. - pub id: [u8; 32], + /// The ID of the event for this transfer. + pub id: ([u8; 32], u64), /// The address which made the transfer. pub from: [u8; 20], /// The amount transferred. @@ -40,14 +40,6 @@ pub struct TopLevelTransfer { pub data: Vec, } -/// A transaction with a top-level transfer, matched to the log index of the transfer. -pub struct MatchedTopLevelTransfer { - /// The transfer. - pub transfer: TopLevelTransfer, - /// The log index of the transfer. - pub log_index: u64, -} - /// A view for an ERC20 contract. #[derive(Clone, Debug)] pub struct Erc20(Arc>, Address); @@ -62,7 +54,7 @@ impl Erc20 { provider: impl AsRef>, transaction_id: B256, to: Address, - ) -> Result, RpcError> { + ) -> Result, RpcError> { // Fetch the transaction let transaction = provider.as_ref().get_transaction_by_hash(transaction_id).await?.ok_or_else(|| { @@ -132,15 +124,11 @@ impl Erc20 { let encoded = call.abi_encode(); let data = transaction.input.as_ref()[encoded.len() ..].to_vec(); - return Ok(Some(MatchedTopLevelTransfer { - transfer: TopLevelTransfer { - // Since there's only one top-level transfer per TX, set the ID to the TX ID - id: *transaction_id, - from: *log.from.0, - amount: log.value, - data, - }, - log_index, + return Ok(Some(TopLevelTransfer { + id: (*transaction_id, log_index), + from: *log.from.0, + amount: log.value, + data, })); } } @@ -193,7 +181,7 @@ impl Erc20 { // Panicking on a task panic is desired behavior, and we haven't aborted any tasks match top_level_transfer.unwrap() { // Top-level transfer - Ok(Some(top_level_transfer)) => top_level_transfers.push(top_level_transfer.transfer), + Ok(Some(top_level_transfer)) => top_level_transfers.push(top_level_transfer), // Not a top-level transfer Ok(None) => continue, // Failed to get this transaction's information so abort