Skip to content

Commit

Permalink
Filters ERC20 Transfer Events to only 0x transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrés Elizondo committed Jul 19, 2024
1 parent 0f9e99c commit dc2ff3d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ import {
filterSocketBridgeEvents,
filterWrapUnwrapEvents,
filterWrapUnwrapEventsGetContext,
filterERC20TransferEvents,
filterERC20TransferEventsGetContext,
} from './filters';
import {
parseBridgeFill,
Expand Down Expand Up @@ -792,7 +794,8 @@ export const eventScrperProps: EventScraperProps[] = [
contractAddress: null,
startBlock: SETTLER_DEPLOYMENT_BLOCK,
parser: parseERC20TransferEvent,
filterFunction: filterNulls,
filterFunction: filterERC20TransferEvents,
filterFunctionGetContext: filterERC20TransferEventsGetContext,
},
{
enabled: FEAT_SETTLER_ERC721_TRANSFER_EVENT,
Expand Down
25 changes: 25 additions & 0 deletions src/filters/erc20_transfer_events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Web3Source } from '../data_sources/events/web3';
import { Event, Transaction } from '../entities';
import { getParseTxsAsync } from '../scripts/utils/web3_utils';

export async function filterERC20TransferEventsGetContext(events: Event[], web3Source: Web3Source): Promise<Event[]> {
if (events.length > 0) {
const txHashes = events.map((log: Event) => log.transactionHash);
const txData = await getParseTxsAsync(web3Source, txHashes);
const filteredTxsHashes = txData.parsedTxs
.filter((tx: Transaction) => tx.quoteId)
.map((tx: Transaction) => tx.transactionHash);

const validTxHashSet = new Set(filteredTxsHashes);
const filteredLogs = events.filter((log: Event) => validTxHashSet.has(log.transactionHash));
return filteredLogs.filter((e) => e !== null);
}
return [];
}

export function filterERC20TransferEvents(events: Event[], transaction: Transaction): Event[] {
if (transaction.quoteId) {
return events.filter((e) => e !== null);
}
return [];
}
1 change: 1 addition & 0 deletions src/filters/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { filterSocketBridgeEventsGetContext, filterSocketBridgeEvents } from './socket_bridge_events';
export { filterWrapUnwrapEvents, filterWrapUnwrapEventsGetContext } from './wrap_unwrap_native_events';
export { filterERC20TransferEvents, filterERC20TransferEventsGetContext } from './erc20_transfer_events';

export const filterNulls = (events: any[], _: any) => events.filter((e) => e !== null);

0 comments on commit dc2ff3d

Please sign in to comment.