-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filters ERC20 Transfer Events to only 0x transactions.
- Loading branch information
Andrés Elizondo
committed
Jul 19, 2024
1 parent
0f9e99c
commit dc2ff3d
Showing
3 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |