From ae7981c68b36193191f4e6e3f0511577cb093733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Elizondo?= Date: Wed, 29 May 2024 14:40:07 -0500 Subject: [PATCH] Adds support for multiple ABIs for ERC20 Transfer events. --- src/abis.ts | 2 +- src/parsers/events/erc20_transfer_events.ts | 26 +++++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/abis.ts b/src/abis.ts index 2d40966d..9e6a2321 100644 --- a/src/abis.ts +++ b/src/abis.ts @@ -1427,7 +1427,7 @@ export const STAKING_REWARDS_PAID_ABI = { type: 'event', }; -export const ERC20_TRANSFER_ABI = { +export const STANDARD_ERC20_TRANSFER_ABI = { anonymous: false, inputs: [ { diff --git a/src/parsers/events/erc20_transfer_events.ts b/src/parsers/events/erc20_transfer_events.ts index b5f69626..e79bfecc 100644 --- a/src/parsers/events/erc20_transfer_events.ts +++ b/src/parsers/events/erc20_transfer_events.ts @@ -1,4 +1,4 @@ -import { ERC20_TRANSFER_ABI } from '../../constants'; +import { STANDARD_ERC20_TRANSFER_ABI } from '../../constants'; import { ERC20TransferEvent } from '../../entities'; import { parseEvent } from './parse_event'; import { BigNumber } from '@0x/utils'; @@ -13,17 +13,23 @@ export function parseERC20TransferEvent(eventLog: LogEntry): ERC20TransferEvent parseEvent(eventLog, eRC20TransferEvent); - // ERC20 Transfers have 3 topics and 32 bytes of data - // ERC721 Transfers have 4 topics and no data - if (eventLog.topics.length !== 3) { + if (eventLog.topics.length === 4 && eventLog.data === '0x') { + // ERC721 Transfer - 4 topics, no data + return null; + } else if (eventLog.topics.length === 3 && eventLog.data !== '0x') { + // Standard ERC20 Transfer - 3 topics, 32 bytes of data + const decodedLog = abiCoder.decodeLog( + STANDARD_ERC20_TRANSFER_ABI.inputs, + eventLog.data, + eventLog.topics.slice(1), + ); + + eRC20TransferEvent.from = decodedLog.from.toLowerCase(); + eRC20TransferEvent.to = decodedLog.to.toLowerCase(); + eRC20TransferEvent.value = new BigNumber(decodedLog.value); + } else { return null; } - const decodedLog = abiCoder.decodeLog(ERC20_TRANSFER_ABI.inputs, eventLog.data, eventLog.topics.slice(1)); - - eRC20TransferEvent.from = decodedLog.from.toLowerCase(); - eRC20TransferEvent.to = decodedLog.to.toLowerCase(); - eRC20TransferEvent.value = new BigNumber(decodedLog.value); - return eRC20TransferEvent; }