From 29d8ac1139d0b6c3718e91cdd618972355029cfb Mon Sep 17 00:00:00 2001 From: ponyjackal Date: Fri, 26 Jul 2024 09:36:36 -0700 Subject: [PATCH] feat: add grabLogsFromTransaction --- .../bridges/acrossProtocol/destination.ts | 6 +-- .../bridges/acrossProtocol/source.ts | 6 +-- .../bridges/hopTransferToL1/destination.ts | 6 +-- .../bridges/hopTransferToL1/source.ts | 6 +-- .../bridges/hopTransferToL2/destination.ts | 6 +-- .../bridges/hopTransferToL2/source.ts | 6 +-- src/contextualizers/bridges/opStack/source.ts | 6 +-- .../bridges/starGate/destination.ts | 6 +-- .../bridges/starGate/source.ts | 6 +-- .../heuristics/ethTransfer/ethTransfer.ts | 4 +- .../protocol/boombox/boombox.ts | 10 ++--- .../protocol/cryptopunks/cryptopunks.ts | 8 +++- src/contextualizers/protocol/eas/eas.ts | 9 ++++- .../protocol/eas/schemaRegistry.ts | 10 ++++- src/contextualizers/protocol/ens/registrar.ts | 16 +++++--- .../protocol/farcaster/bundler.ts | 9 ++++- .../protocol/farcaster/idGateway.ts | 10 ++++- .../protocol/frenpet/gameplay.ts | 38 +++++++++++-------- .../protocol/friendTech/detect.ts | 4 +- .../protocol/friendTech/friendTech.ts | 15 +++++--- .../protocol/highlight/highlight.ts | 4 +- .../protocol/nouns/auctionHouse.ts | 10 ++++- .../protocol/nouns/daoLogic.ts | 13 +++++-- .../protocol/nounsBuilder/auction.ts | 9 ++++- .../protocol/nounsBuilder/governor.ts | 11 ++++-- src/contextualizers/protocol/rodeo/rodeo.ts | 8 ++-- .../protocol/skyoneer/destination.ts | 11 ++++-- .../protocol/skyoneer/plotAction.ts | 16 +++++--- .../protocol/skyoneer/source.ts | 12 +++--- .../protocol/uniswapV3/uniswapV3Pair.ts | 11 +++--- .../protocol/zoraCreator/zoraCreator.ts | 8 ++-- src/helpers/utils.ts | 21 ++++++++++ 32 files changed, 209 insertions(+), 112 deletions(-) diff --git a/src/contextualizers/bridges/acrossProtocol/destination.ts b/src/contextualizers/bridges/acrossProtocol/destination.ts index 404b18f0..c7e4df75 100644 --- a/src/contextualizers/bridges/acrossProtocol/destination.ts +++ b/src/contextualizers/bridges/acrossProtocol/destination.ts @@ -10,7 +10,7 @@ import { ACROSS_PROTOCOL_RELAYER_ABI, ACROSS_PROTOCOL_RELAYERS, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isAcrossProtocol = detect(transaction); @@ -28,7 +28,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const filledRelayLog = logs.find((log: Log) => { if (log.address !== ACROSS_PROTOCOL_RELAYERS[originChainId]) return false; @@ -50,7 +50,7 @@ export function detect(transaction: Transaction): boolean { export function generate(transaction: Transaction): Transaction { const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let filledRelayEvent; const filledRelayLog = logs.find((log: Log) => { if (log.address !== ACROSS_PROTOCOL_RELAYERS[originChainId]) return false; diff --git a/src/contextualizers/bridges/acrossProtocol/source.ts b/src/contextualizers/bridges/acrossProtocol/source.ts index 17e38f9d..4924eed6 100644 --- a/src/contextualizers/bridges/acrossProtocol/source.ts +++ b/src/contextualizers/bridges/acrossProtocol/source.ts @@ -10,7 +10,7 @@ import { ACROSS_PROTOCOL_RELAYER_ABI, ACROSS_PROTOCOL_RELAYERS, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isAcrossProtocol = detect(transaction); @@ -28,7 +28,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const fundsDepositedLog = logs.find((log: Log) => { if (log.address !== ACROSS_PROTOCOL_RELAYERS[originChainId]) return false; @@ -51,7 +51,7 @@ export function detect(transaction: Transaction): boolean { export function generate(transaction: Transaction): Transaction { const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let fundsDepositedEvent; const fundsDepositedLog = logs.find((log: Log) => { if (log.address !== ACROSS_PROTOCOL_RELAYERS[originChainId]) return false; diff --git a/src/contextualizers/bridges/hopTransferToL1/destination.ts b/src/contextualizers/bridges/hopTransferToL1/destination.ts index ed025493..dbd7d128 100644 --- a/src/contextualizers/bridges/hopTransferToL1/destination.ts +++ b/src/contextualizers/bridges/hopTransferToL1/destination.ts @@ -6,7 +6,7 @@ import { Transaction, } from '../../../types'; import { HOP_WITHDRAWAL_BONDED_EVENT_ABI, HOP_RELAYERS } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isHopTransferToL1 = detect(transaction); @@ -24,7 +24,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const withdrawalBondedLog = logs.find((log: any) => { if (log.address !== HOP_RELAYERS[originChainId]) return false; @@ -49,7 +49,7 @@ export function generate(transaction: Transaction): Transaction { const chainId = transaction.chainId; if (!chainId) return transaction; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let decodedWithdrawalBondedLog; for (const log of logs) { if (log.address !== HOP_RELAYERS[originChainId]) continue; diff --git a/src/contextualizers/bridges/hopTransferToL1/source.ts b/src/contextualizers/bridges/hopTransferToL1/source.ts index 25e280cb..2c9c0ddf 100644 --- a/src/contextualizers/bridges/hopTransferToL1/source.ts +++ b/src/contextualizers/bridges/hopTransferToL1/source.ts @@ -6,7 +6,7 @@ import { Transaction, } from '../../../types'; import { HOP_TRANSFER_SENT_EVENT_ABI, HOP_RELAYERS } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isHopTransferToL1 = detect(transaction); @@ -24,7 +24,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const transferSentLog = logs.find((log: any) => { if (log.address !== HOP_RELAYERS[originChainId]) return false; @@ -46,7 +46,7 @@ export function detect(transaction: Transaction): boolean { export function generate(transaction: Transaction): Transaction { const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let decodedTransferSentLog; for (const log of logs) { if (log.address !== HOP_RELAYERS[originChainId]) continue; diff --git a/src/contextualizers/bridges/hopTransferToL2/destination.ts b/src/contextualizers/bridges/hopTransferToL2/destination.ts index b85c0c2f..22f7a76c 100644 --- a/src/contextualizers/bridges/hopTransferToL2/destination.ts +++ b/src/contextualizers/bridges/hopTransferToL2/destination.ts @@ -9,7 +9,7 @@ import { HOP_TRANSFER_FROM_L1_COMPLETED_EVENT_ABI, HOP_RELAYERS, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isHopTransferToL1 = detect(transaction); @@ -27,7 +27,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const transferFromL1CompletedLog = logs.find((log: any) => { if (log.address !== HOP_RELAYERS[originChainId]) return false; @@ -51,7 +51,7 @@ export function generate(transaction: Transaction): Transaction { const chainId = transaction.chainId; if (!chainId) return transaction; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let decodedTransferFromL1CompletedLog; for (const log of logs) { if (log.address !== HOP_RELAYERS[chainId]) continue; diff --git a/src/contextualizers/bridges/hopTransferToL2/source.ts b/src/contextualizers/bridges/hopTransferToL2/source.ts index 41bc4668..492ec45e 100644 --- a/src/contextualizers/bridges/hopTransferToL2/source.ts +++ b/src/contextualizers/bridges/hopTransferToL2/source.ts @@ -6,7 +6,7 @@ import { Transaction, } from '../../../types'; import { HOP_TRANSFER_SENT_TO_L2_EVENT_ABI, HOP_RELAYERS } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isHopTransferToL1 = detect(transaction); @@ -24,7 +24,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const transferSentToL2Log = logs.find((log: any) => { if (log.address !== HOP_RELAYERS[originChainId]) return false; @@ -46,7 +46,7 @@ export function detect(transaction: Transaction): boolean { export function generate(transaction: Transaction): Transaction { const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let decodedTransferSentToL2Log; for (const log of logs) { if (log.address !== HOP_RELAYERS[originChainId]) continue; diff --git a/src/contextualizers/bridges/opStack/source.ts b/src/contextualizers/bridges/opStack/source.ts index 7fdb6f6d..8cdfbfad 100644 --- a/src/contextualizers/bridges/opStack/source.ts +++ b/src/contextualizers/bridges/opStack/source.ts @@ -18,7 +18,7 @@ import { TRANSACTION_DEPOSITED_EVENT_ABI, TRANSACTION_DEPOSITED_EVENT_HASH, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isOpStack = detect(transaction); @@ -36,7 +36,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ if (transaction.chainId === 1) { - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const transactionDepositedLog = logs.find((log: any) => { return log.topic0 === TRANSACTION_DEPOSITED_EVENT_HASH; }); @@ -58,7 +58,7 @@ export function generate(transaction: Transaction): Transaction { } const assetTransfer: Asset = assetSent[0]; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const transactionDepositedLog = logs.find((log: any) => { return log.topic0 === TRANSACTION_DEPOSITED_EVENT_HASH; }); diff --git a/src/contextualizers/bridges/starGate/destination.ts b/src/contextualizers/bridges/starGate/destination.ts index af5239ad..694ce1e9 100644 --- a/src/contextualizers/bridges/starGate/destination.ts +++ b/src/contextualizers/bridges/starGate/destination.ts @@ -16,7 +16,7 @@ import { STAR_GATE_PACKET_RECEIVED_EVENT_ABI, STAR_GATE_CHAIN_IDS, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isStarGate = detect(transaction); @@ -34,7 +34,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const packetReceivedLog = logs.find((log: Log) => { if (log.address !== STAR_GATE_RELAYERS[originChainId]) return false; @@ -58,7 +58,7 @@ export function detect(transaction: Transaction): boolean { export function generate(transaction: Transaction): Transaction { const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let decodedPacketReceivedLog; for (const log of logs) { diff --git a/src/contextualizers/bridges/starGate/source.ts b/src/contextualizers/bridges/starGate/source.ts index 1a9d6b3f..7b4c3f17 100644 --- a/src/contextualizers/bridges/starGate/source.ts +++ b/src/contextualizers/bridges/starGate/source.ts @@ -15,7 +15,7 @@ import { STAR_GATE_PACKET_EVENT_ABI, STAR_GATE_CHAIN_IDS, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isStarGate = detect(transaction); @@ -33,7 +33,7 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); const sendMsgLog = logs.find((log: Log) => { if (log.address !== STAR_GATE_BRIDGES[originChainId]) return false; const decoded = decodeLog( @@ -79,7 +79,7 @@ export function detect(transaction: Transaction): boolean { export function generate(transaction: Transaction): Transaction { const originChainId = transaction.chainId ?? 1; - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let decodedSwapLog; for (const log of logs) { diff --git a/src/contextualizers/heuristics/ethTransfer/ethTransfer.ts b/src/contextualizers/heuristics/ethTransfer/ethTransfer.ts index 008efe68..911a3b3c 100644 --- a/src/contextualizers/heuristics/ethTransfer/ethTransfer.ts +++ b/src/contextualizers/heuristics/ethTransfer/ethTransfer.ts @@ -1,3 +1,4 @@ +import { grabLogsFromTransaction } from '../../../helpers/utils'; import { AssetType, HeuristicContextActionEnum, @@ -12,12 +13,13 @@ export function contextualize(transaction: Transaction): Transaction { } export function detect(transaction: Transaction): boolean { + const logs = grabLogsFromTransaction(transaction); // TODO; check logs from transaction if ( transaction.to && transaction.input === '0x' && transaction.value !== BigInt(0) && - transaction.logs?.length === 0 + logs.length === 0 ) { return true; } diff --git a/src/contextualizers/protocol/boombox/boombox.ts b/src/contextualizers/protocol/boombox/boombox.ts index f1097c95..00a68287 100644 --- a/src/contextualizers/protocol/boombox/boombox.ts +++ b/src/contextualizers/protocol/boombox/boombox.ts @@ -8,6 +8,7 @@ import { import { decodeEVMAddress, decodeTransactionInput, + grabLogsFromTransaction, } from '../../../helpers/utils'; import { CHAIN_IDS } from '../../../helpers/constants'; @@ -123,12 +124,11 @@ export const generate = (transaction: Transaction): Transaction => { case 'distribute': const distributeArtistId = decoded.args && decoded.args.length > 0 ? decoded.args[0] : ''; + const logs = grabLogsFromTransaction(transaction); // decode logs - const distributeLogs = transaction.logs - ? transaction.logs.filter( - (log) => log.topic0 === EVENT_DISTRIBUTE_TOPIC, - ) - : []; + const distributeLogs = logs.filter( + (log) => log.topic0 === EVENT_DISTRIBUTE_TOPIC, + ); const recipients = distributeLogs.map((log) => decodeEVMAddress(log.topic2), ); diff --git a/src/contextualizers/protocol/cryptopunks/cryptopunks.ts b/src/contextualizers/protocol/cryptopunks/cryptopunks.ts index c1012b2a..063df263 100644 --- a/src/contextualizers/protocol/cryptopunks/cryptopunks.ts +++ b/src/contextualizers/protocol/cryptopunks/cryptopunks.ts @@ -7,7 +7,10 @@ import { Transaction, } from '../../../types'; import { CryptopunksContracts, CRYPTOPUNK_ABIS } from './constants'; -import { decodeTransactionInput } from '../../../helpers/utils'; +import { + decodeTransactionInput, + grabLogsFromTransaction, +} from '../../../helpers/utils'; export const contextualize = (transaction: Transaction): Transaction => { const isENS = detect(transaction); @@ -357,7 +360,8 @@ export const generate = (transaction: Transaction): Transaction => { unit: 'wei', }; if (transaction.receipt?.status) { - const transferTopic = transaction.logs?.filter( + const logs = grabLogsFromTransaction(transaction); + const transferTopic = logs.filter( (log) => log.topic0 === '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', diff --git a/src/contextualizers/protocol/eas/eas.ts b/src/contextualizers/protocol/eas/eas.ts index d9c0f71c..d497addd 100644 --- a/src/contextualizers/protocol/eas/eas.ts +++ b/src/contextualizers/protocol/eas/eas.ts @@ -5,7 +5,11 @@ import { EventLogTopics, EASContextActionEnum, } from '../../../types'; -import { decodeTransactionInput, decodeLog } from '../../../helpers/utils'; +import { + decodeTransactionInput, + decodeLog, + grabLogsFromTransaction, +} from '../../../helpers/utils'; import { ABIs, EAS_LINKS } from './constants'; export const contextualize = (transaction: Transaction): Transaction => { @@ -70,7 +74,8 @@ const getAttestationID = (transaction: Transaction): string | null => { return null; } // TODO: Confirm that the event matches the expected name - const transactionLog = transaction?.logs?.[0]; + const logs = grabLogsFromTransaction(transaction); + const transactionLog = logs?.[0]; const decoded = decodeLog( ABIs.EAS, transactionLog?.data as Hex, diff --git a/src/contextualizers/protocol/eas/schemaRegistry.ts b/src/contextualizers/protocol/eas/schemaRegistry.ts index 6135d1ba..0ff0224e 100644 --- a/src/contextualizers/protocol/eas/schemaRegistry.ts +++ b/src/contextualizers/protocol/eas/schemaRegistry.ts @@ -4,7 +4,11 @@ import { EventLogTopics, Transaction, } from '../../../types'; -import { decodeTransactionInput, decodeLog } from '../../../helpers/utils'; +import { + decodeTransactionInput, + decodeLog, + grabLogsFromTransaction, +} from '../../../helpers/utils'; import { ABIs, EAS_LINKS } from './constants'; export const contextualize = (transaction: Transaction): Transaction => { @@ -54,11 +58,13 @@ export const generate = (transaction: Transaction): Transaction => { } if (!transaction.chainId) return transaction; + const logs = grabLogsFromTransaction(transaction); + switch (decoded.functionName) { case 'register': { let id = ''; if (transaction.receipt?.status) { - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { const decoded = decodeLog( ABIs.SchemaRegistry, log.data as Hex, diff --git a/src/contextualizers/protocol/ens/registrar.ts b/src/contextualizers/protocol/ens/registrar.ts index 5471594d..74711866 100644 --- a/src/contextualizers/protocol/ens/registrar.ts +++ b/src/contextualizers/protocol/ens/registrar.ts @@ -5,7 +5,11 @@ import { Transaction, } from '../../../types'; import { ENS_CONTRACTS, ENS_ADDRESSES } from './constants'; -import { convertDate, decodeLog } from '../../../helpers/utils'; +import { + convertDate, + decodeLog, + grabLogsFromTransaction, +} from '../../../helpers/utils'; export const contextualize = (transaction: Transaction): Transaction => { const isENS = detect(transaction); @@ -15,12 +19,13 @@ export const contextualize = (transaction: Transaction): Transaction => { }; export const detect = (transaction: Transaction): boolean => { + const logs = grabLogsFromTransaction(transaction); // detect logs - if (!transaction.logs) { + if (logs.length === 0) { return false; } - for (const log of transaction.logs) { + for (const log of logs) { if ( log.address !== ENS_ADDRESSES.registrarV2 && log.address !== ENS_ADDRESSES.registrarV3 @@ -49,9 +54,10 @@ export const detect = (transaction: Transaction): boolean => { // Contextualize for mined txs export const generate = (transaction: Transaction): Transaction => { - if (!transaction.logs) return transaction; + const logs = grabLogsFromTransaction(transaction); + if (logs.length === 0) return transaction; - for (const log of transaction.logs) { + for (const log of logs) { if ( log.address !== ENS_ADDRESSES.registrarV2 && log.address !== ENS_ADDRESSES.registrarV3 diff --git a/src/contextualizers/protocol/farcaster/bundler.ts b/src/contextualizers/protocol/farcaster/bundler.ts index fd4e85b2..60fcda9a 100644 --- a/src/contextualizers/protocol/farcaster/bundler.ts +++ b/src/contextualizers/protocol/farcaster/bundler.ts @@ -7,7 +7,11 @@ import { Transaction, } from '../../../types'; import { FarcasterContracts } from './constants'; -import { decodeTransactionInput, decodeLog } from '../../../helpers/utils'; +import { + decodeTransactionInput, + decodeLog, + grabLogsFromTransaction, +} from '../../../helpers/utils'; // Contextualizer for the Bundler contract: // https://github.com/farcasterxyz/contracts/blob/main/src/interfaces/IBundler.sol @@ -43,6 +47,7 @@ export const generate = (transaction: Transaction): Transaction => { ); if (!decoded) return transaction; + const logs = grabLogsFromTransaction(transaction); const caller = transaction.from; switch (decoded.functionName) { @@ -59,7 +64,7 @@ export const generate = (transaction: Transaction): Transaction => { // Capture FID let fid = ''; if (transaction.receipt?.status) { - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { return log.address === FarcasterContracts.IdRegistry.address; }); if (registerLog) { diff --git a/src/contextualizers/protocol/farcaster/idGateway.ts b/src/contextualizers/protocol/farcaster/idGateway.ts index 21d926d6..a859aea2 100644 --- a/src/contextualizers/protocol/farcaster/idGateway.ts +++ b/src/contextualizers/protocol/farcaster/idGateway.ts @@ -5,7 +5,11 @@ import { Transaction, } from '../../../types'; import { FarcasterContracts } from './constants'; -import { decodeLog, decodeTransactionInput } from '../../../helpers/utils'; +import { + decodeLog, + decodeTransactionInput, + grabLogsFromTransaction, +} from '../../../helpers/utils'; // Contextualizer for the IdGateway contract: // https://github.com/farcasterxyz/contracts/blob/main/src/interfaces/IIdGateway.sol @@ -39,10 +43,12 @@ export const generate = (transaction: Transaction): Transaction => { ); if (!decoded) return transaction; + const logs = grabLogsFromTransaction(transaction); + // Capture FID let fid = ''; if (transaction.receipt?.status) { - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { return log.address === FarcasterContracts.IdRegistry.address; }); if (registerLog) { diff --git a/src/contextualizers/protocol/frenpet/gameplay.ts b/src/contextualizers/protocol/frenpet/gameplay.ts index 304d2889..9950da42 100644 --- a/src/contextualizers/protocol/frenpet/gameplay.ts +++ b/src/contextualizers/protocol/frenpet/gameplay.ts @@ -11,7 +11,11 @@ import { ERC721Asset, FrenpetContextActionEnum, } from '../../../types'; -import { decodeFunction, decodeLog } from '../../../helpers/utils'; +import { + decodeFunction, + decodeLog, + grabLogsFromTransaction, +} from '../../../helpers/utils'; export const contextualize = (transaction: Transaction): Transaction => { const isFrenPet = detect(transaction); @@ -33,6 +37,8 @@ export const detect = (transaction: Transaction): boolean => { // Contextualize for mined txs export const generate = (transaction: Transaction): Transaction => { + const logs = grabLogsFromTransaction(transaction); + switch (transaction.sigHash) { case '0x715488b0': { // buyAccessory(uint256,uint256) @@ -122,18 +128,18 @@ export const generate = (transaction: Transaction): Transaction => { tokenId: (parsed.args[1] as bigint).toString(), }; if (transaction.receipt?.status) { - if (!transaction.logs || transaction.logs?.length) { + if (logs.length === 0) { return transaction; } const parsedLog = decodeLog( parseAbi(abi), - transaction.logs[0]?.data as Hex, + logs[0]?.data as Hex, [ - transaction.logs[0]?.topic0, - transaction.logs[0]?.topic1, - transaction.logs[0]?.topic2, - transaction.logs[0]?.topic3, + logs[0]?.topic0, + logs[0]?.topic1, + logs[0]?.topic2, + logs[0]?.topic3, ] as EventLogTopics, ); if (!parsedLog) return transaction; @@ -359,17 +365,17 @@ export const generate = (transaction: Transaction): Transaction => { }, }; } else { - if (!transaction || !transaction.logs?.length) { + if (!transaction || logs.length === 0) { return transaction; } const parsedLog = decodeLog( parseAbi(abi), - transaction.logs[0]?.data as Hex, + logs[0]?.data as Hex, [ - transaction.logs[0]?.topic0, - transaction.logs[0]?.topic1, - transaction.logs[0]?.topic2, - transaction.logs[0]?.topic3, + logs[0]?.topic0, + logs[0]?.topic1, + logs[0]?.topic2, + logs[0]?.topic3, ] as EventLogTopics, ); if (!parsedLog) return transaction; @@ -468,8 +474,8 @@ export const generate = (transaction: Transaction): Transaction => { }; if (transaction.receipt?.status) { if ( - transaction.logs && - transaction.logs?.filter( + logs && + logs.filter( (log) => log.topic0 === '0x8d02746aaac19768ccd257b3b666918a78b779c9f3d243bf3720313655a28004', @@ -494,7 +500,7 @@ export const generate = (transaction: Transaction): Transaction => { }, }; } else { - const attackLogs = transaction.logs?.filter( + const attackLogs = logs.filter( (log) => log.topic0 === '0xcf2d586a11b0df2dc974a66369ad4e68566a0635fd2448e810592eac3d3bedae', // Attack(uint256 attacker, uint256 winner, uint256 loser, uint256 scoresWon) diff --git a/src/contextualizers/protocol/friendTech/detect.ts b/src/contextualizers/protocol/friendTech/detect.ts index e72866f2..0437331b 100644 --- a/src/contextualizers/protocol/friendTech/detect.ts +++ b/src/contextualizers/protocol/friendTech/detect.ts @@ -1,9 +1,11 @@ +import { grabLogsFromTransaction } from '../../../helpers/utils'; import { Transaction } from '../../../types'; import { FRIEND_TECH_ADDRESSES } from './constants'; export const detect = (transaction: Transaction): boolean => { + const logs = grabLogsFromTransaction(transaction); /** implement your detection logic */ - if (transaction.to !== FRIEND_TECH_ADDRESSES || !transaction.logs) { + if (transaction.to !== FRIEND_TECH_ADDRESSES || logs.length === 0) { return false; } // buyShares(address sharesSubject, uint256 amount) diff --git a/src/contextualizers/protocol/friendTech/friendTech.ts b/src/contextualizers/protocol/friendTech/friendTech.ts index 23e121c6..cd9ef576 100644 --- a/src/contextualizers/protocol/friendTech/friendTech.ts +++ b/src/contextualizers/protocol/friendTech/friendTech.ts @@ -6,7 +6,11 @@ import { Transaction, } from '../../../types'; import { ABIs } from './constants'; -import { decodeTransactionInput, decodeLog } from '../../../helpers/utils'; +import { + decodeTransactionInput, + decodeLog, + grabLogsFromTransaction, +} from '../../../helpers/utils'; import { detect } from './detect'; export const contextualize = (transaction: Transaction): Transaction => { @@ -18,6 +22,7 @@ export const contextualize = (transaction: Transaction): Transaction => { // Contextualize for txs export const generate = (transaction: Transaction): Transaction => { + const logs = grabLogsFromTransaction(transaction); // Failed transaction if (!transaction.receipt?.status) { // buyShares(address sharesSubject, uint256 amount) @@ -71,9 +76,9 @@ export const generate = (transaction: Transaction): Transaction => { // buyShares(address sharesSubject, uint256 amount) if (transaction.sigHash === '0x6945b123') { try { - if (!transaction.logs) return transaction; + if (logs.length === 0) return transaction; - const log = transaction.logs[0]; + const log = logs[0]; const parsedLog = decodeLog( ABIs.FriendTech, log.data as Hex, @@ -156,9 +161,9 @@ export const generate = (transaction: Transaction): Transaction => { // sellShares(address sharesSubject, uint256 amount) if (transaction.sigHash === '0xb51d0534') { try { - if (!transaction.logs) return transaction; + if (logs.length === 0) return transaction; - const log = transaction.logs[0]; + const log = logs[0]; const parsedLog = decodeLog( ABIs.FriendTech, log.data as Hex, diff --git a/src/contextualizers/protocol/highlight/highlight.ts b/src/contextualizers/protocol/highlight/highlight.ts index 01019e5c..34731b95 100644 --- a/src/contextualizers/protocol/highlight/highlight.ts +++ b/src/contextualizers/protocol/highlight/highlight.ts @@ -1,7 +1,7 @@ import { Abi, Hex } from 'viem'; import { AssetType, EventLogTopics, Transaction } from '../../../types'; import { MINT_MANAGER_ABI, MINT_MANAGER_CONTRACT } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; import { generate as erc721Generate } from '../../heuristics/erc721Mint/erc721Mint'; import { generate as erc1155Generate } from '../../heuristics/erc1155Mint/erc1155Mint'; @@ -39,7 +39,7 @@ export const generate = (transaction: Transaction): Transaction => { transaction.context.summaries.en.title = 'Highlight'; // check if mint with rewards - const logs = transaction.logs ?? []; + const logs = grabLogsFromTransaction(transaction); let decodedLog; for (const log of logs) { decodedLog = decodeLog( diff --git a/src/contextualizers/protocol/nouns/auctionHouse.ts b/src/contextualizers/protocol/nouns/auctionHouse.ts index bfd2a173..93f58f0a 100644 --- a/src/contextualizers/protocol/nouns/auctionHouse.ts +++ b/src/contextualizers/protocol/nouns/auctionHouse.ts @@ -6,7 +6,11 @@ import { Transaction, } from '../../../types'; import { NounsContracts, ABIs } from './constants'; -import { decodeLog, decodeTransactionInput } from '../../../helpers/utils'; +import { + decodeLog, + decodeTransactionInput, + grabLogsFromTransaction, +} from '../../../helpers/utils'; export const contextualize = (transaction: Transaction): Transaction => { const isNouns = detect(transaction); @@ -58,6 +62,8 @@ export const generate = (transaction: Transaction): Transaction => { if (!decoded) return transaction; + const logs = grabLogsFromTransaction(transaction); + switch (decoded.functionName) { case 'createBid': { transaction.context = { @@ -97,7 +103,7 @@ export const generate = (transaction: Transaction): Transaction => { let nounId = ''; let winner = ''; - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { try { const decoded = decodeLog( ABIs.NounsAuctionHouse, diff --git a/src/contextualizers/protocol/nouns/daoLogic.ts b/src/contextualizers/protocol/nouns/daoLogic.ts index 66187ca3..5f43a0a2 100644 --- a/src/contextualizers/protocol/nouns/daoLogic.ts +++ b/src/contextualizers/protocol/nouns/daoLogic.ts @@ -5,7 +5,11 @@ import { Transaction, } from '../../../types'; import { NounsContracts, ABIs } from './constants'; -import { decodeLog, decodeTransactionInput } from '../../../helpers/utils'; +import { + decodeLog, + decodeTransactionInput, + grabLogsFromTransaction, +} from '../../../helpers/utils'; const translateSupport = (support: number) => { if (support === 0) return NounsGovernorActionEnum.VOTED_AGAINST; @@ -77,6 +81,7 @@ export const generate = (transaction: Transaction): Transaction => { ABIs.NounsDAOLogic, ); if (!decoded) return transaction; + const logs = grabLogsFromTransaction(transaction); switch (decoded.functionName) { case 'propose': { @@ -84,7 +89,7 @@ export const generate = (transaction: Transaction): Transaction => { let proposalId: bigint = BigInt(0); - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { try { const decoded = decodeLog( ABIs.NounsDAOLogic, @@ -155,7 +160,7 @@ export const generate = (transaction: Transaction): Transaction => { let proposalId: bigint = BigInt(0); - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { try { const decoded = decodeLog( ABIs.NounsDAOLogic, @@ -290,7 +295,7 @@ export const generate = (transaction: Transaction): Transaction => { let voter: string = ''; - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { try { const decoded = decodeLog( ABIs.NounsDAOLogic, diff --git a/src/contextualizers/protocol/nounsBuilder/auction.ts b/src/contextualizers/protocol/nounsBuilder/auction.ts index dd08e113..c5015695 100644 --- a/src/contextualizers/protocol/nounsBuilder/auction.ts +++ b/src/contextualizers/protocol/nounsBuilder/auction.ts @@ -8,7 +8,11 @@ import { } from '../../../types'; import { ABIs, NOUNS_BUILDER_INSTANCES } from './constants'; import { NounsContracts } from '../nouns/constants'; -import { decodeLog, decodeTransactionInput } from '../../../helpers/utils'; +import { + decodeLog, + decodeTransactionInput, + grabLogsFromTransaction, +} from '../../../helpers/utils'; const daoByAuctionAuctionHouseContract = (address: string) => { return NOUNS_BUILDER_INSTANCES.find((v) => v.auctionHouse === address); @@ -60,6 +64,7 @@ export const generate = (transaction: Transaction): Transaction => { ); if (!decoded) return transaction; + const logs = grabLogsFromTransaction(transaction); switch (decoded.functionName) { case 'createBid': { @@ -131,7 +136,7 @@ export const generate = (transaction: Transaction): Transaction => { let tokenId = ''; let winner = ''; - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { try { const decoded = decodeLog( ABIs.IAuction, diff --git a/src/contextualizers/protocol/nounsBuilder/governor.ts b/src/contextualizers/protocol/nounsBuilder/governor.ts index 6af7852d..6fb39809 100644 --- a/src/contextualizers/protocol/nounsBuilder/governor.ts +++ b/src/contextualizers/protocol/nounsBuilder/governor.ts @@ -12,7 +12,11 @@ import { NounsBuilderInstance, } from './constants'; import { NounsContracts } from '../nouns/constants'; -import { decodeLog, decodeTransactionInput } from '../../../helpers/utils'; +import { + decodeLog, + decodeTransactionInput, + grabLogsFromTransaction, +} from '../../../helpers/utils'; const translateSupport = (support: bigint) => { if (support === 0n) return NounsGovernorActionEnum.VOTED_AGAINST; @@ -89,6 +93,7 @@ export const generate = (transaction: Transaction): Transaction => { if (!transaction.to) return transaction; const dao = daoByAuctionGovernorContract(transaction.to); + const logs = grabLogsFromTransaction(transaction); const getDynamicVariables = ( proposalId: string, @@ -122,7 +127,7 @@ export const generate = (transaction: Transaction): Transaction => { const description = decoded.args[3]; let proposalId = ''; - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { try { const decoded = decodeLog( ABIs.IGovernor, @@ -271,7 +276,7 @@ export const generate = (transaction: Transaction): Transaction => { case 'execute': { let proposalId = ''; - const registerLog = transaction.logs?.find((log) => { + const registerLog = logs.find((log) => { try { const decoded = decodeLog( ABIs.IGovernor, diff --git a/src/contextualizers/protocol/rodeo/rodeo.ts b/src/contextualizers/protocol/rodeo/rodeo.ts index 4b5081da..5da7a2f6 100644 --- a/src/contextualizers/protocol/rodeo/rodeo.ts +++ b/src/contextualizers/protocol/rodeo/rodeo.ts @@ -4,7 +4,7 @@ import { MULTI_TOKEN_DROP_MARKET_ABI, MULTI_TOKEN_DROP_MARKET_CONTRACT, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; import { generate as erc721Generate } from '../../heuristics/erc721Mint/erc721Mint'; import { generate as erc1155Generate } from '../../heuristics/erc1155Mint/erc1155Mint'; @@ -17,8 +17,7 @@ export const contextualize = (transaction: Transaction): Transaction => { export const detect = (transaction: Transaction): boolean => { // check if there is 'MintFromFixedPriceSale' log emitted - const logs = - transaction.logs && transaction.logs.length > 0 ? transaction.logs : []; + const logs = grabLogsFromTransaction(transaction); const mintFromFixedPriceSaleLog = findMintFromFixedPriceSaleLog(logs); if (!mintFromFixedPriceSaleLog) return false; @@ -40,8 +39,7 @@ export const generate = (transaction: Transaction): Transaction => { transaction.context.summaries.category = 'PROTOCOL_1'; transaction.context.summaries.en.title = 'Rodeo'; - const logs = - transaction.logs && transaction.logs.length > 0 ? transaction.logs : []; + const logs = grabLogsFromTransaction(transaction); const mintFromFixedPriceSaleLog = findMintFromFixedPriceSaleLog(logs); if (!mintFromFixedPriceSaleLog) return transaction; const decodedLog = decodeLog( diff --git a/src/contextualizers/protocol/skyoneer/destination.ts b/src/contextualizers/protocol/skyoneer/destination.ts index 73b56f95..04aff9f0 100644 --- a/src/contextualizers/protocol/skyoneer/destination.ts +++ b/src/contextualizers/protocol/skyoneer/destination.ts @@ -1,6 +1,7 @@ import { decodeLog, decodeTransactionInput, + grabLogsFromTransaction, processAssetTransfers, } from '../../../helpers/utils'; import { CHAIN_IDS } from '../../../helpers/constants'; @@ -35,9 +36,10 @@ export function detect(transaction: Transaction): boolean { return false; } // check logs - if (!transaction.logs) return false; + const logs = grabLogsFromTransaction(transaction); + if (logs.length === 0) return false; - for (const log of transaction.logs) { + for (const log of logs) { if (log.address !== PACK_ACTIVATION_DESTINATION_CONTRACT) continue; const decoded = decodeLog(PACK_ACTIVATION_DESTINATION_ABI, log.data, [ @@ -56,8 +58,9 @@ export function detect(transaction: Transaction): boolean { } export function generate(transaction: Transaction): Transaction { + const logs = grabLogsFromTransaction(transaction); if ( - !transaction.logs || + logs.length === 0 || transaction.chainId !== CHAIN_IDS.gold || !transaction.assetTransfers || !transaction.netAssetTransfers @@ -81,7 +84,7 @@ export function generate(transaction: Transaction): Transaction { // decode ActivatedStarterPackOnDestination event let activatedStarterPackOnDestinationDecoded, mintedPlotPackActivateDecoded; // const gameMintedTokenDecoded: any[] = []; - for (const log of transaction.logs) { + for (const log of logs) { const decoded = decodeLog(PACK_ACTIVATION_DESTINATION_ABI, log.data, [ log.topic0, log.topic1, diff --git a/src/contextualizers/protocol/skyoneer/plotAction.ts b/src/contextualizers/protocol/skyoneer/plotAction.ts index 9bb8f6e0..5644a4cb 100644 --- a/src/contextualizers/protocol/skyoneer/plotAction.ts +++ b/src/contextualizers/protocol/skyoneer/plotAction.ts @@ -5,7 +5,11 @@ import { AssetType, } from '../../../types'; import { PLOT_ACTION_CONTRACT_ADDRESS, PLOT_ACTION_ABI } from './constants'; -import { decodeLog, processAssetTransfers } from '../../../helpers/utils'; +import { + decodeLog, + grabLogsFromTransaction, + processAssetTransfers, +} from '../../../helpers/utils'; import { CHAIN_IDS } from '../../../helpers/constants'; export function contextualize(transaction: Transaction): Transaction { @@ -24,9 +28,10 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ // check logs - if (!transaction.logs) return false; + const logs = grabLogsFromTransaction(transaction); + if (logs.length === 0) return false; - for (const log of transaction.logs) { + for (const log of logs) { if (log.address !== PLOT_ACTION_CONTRACT_ADDRESS) continue; const decoded = decodeLog(PLOT_ACTION_ABI, log.data, [ @@ -51,8 +56,9 @@ export function detect(transaction: Transaction): boolean { } export function generate(transaction: Transaction): Transaction { + const logs = grabLogsFromTransaction(transaction); if ( - !transaction.logs || + logs.length === 0 || transaction.chainId !== CHAIN_IDS.gold || !transaction.assetTransfers || !transaction.netAssetTransfers @@ -65,7 +71,7 @@ export function generate(transaction: Transaction): Transaction { ); let decoded; - for (const log of transaction.logs) { + for (const log of logs) { if (log.address !== PLOT_ACTION_CONTRACT_ADDRESS) continue; decoded = decodeLog(PLOT_ACTION_ABI, log.data, [ diff --git a/src/contextualizers/protocol/skyoneer/source.ts b/src/contextualizers/protocol/skyoneer/source.ts index 466d73e8..b5de11ed 100644 --- a/src/contextualizers/protocol/skyoneer/source.ts +++ b/src/contextualizers/protocol/skyoneer/source.ts @@ -7,7 +7,7 @@ import { PACK_ACTIVATION_SOURCE_CONTRACT, PACK_ACTIVATION_SOURCE_ABI, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export function contextualize(transaction: Transaction): Transaction { const isPackActivationSource = detect(transaction); @@ -25,9 +25,10 @@ export function detect(transaction: Transaction): boolean { * and it also serves to decouple the logic, thereby simplifying the testing process */ // check logs - if (!transaction.logs) return false; + const logs = grabLogsFromTransaction(transaction); + if (logs.length === 0) return false; - for (const log of transaction.logs) { + for (const log of logs) { if (log.address !== PACK_ACTIVATION_SOURCE_CONTRACT) continue; const decoded = decodeLog(PACK_ACTIVATION_SOURCE_ABI, log.data, [ @@ -46,11 +47,12 @@ export function detect(transaction: Transaction): boolean { } export function generate(transaction: Transaction): Transaction { - if (!transaction.logs || !transaction.chainId) return transaction; + const logs = grabLogsFromTransaction(transaction); + if (logs.length === 0 || !transaction.chainId) return transaction; // decode ActivatedStarterPackOnSource event let decoded; - for (const log of transaction.logs) { + for (const log of logs) { if (log.address !== PACK_ACTIVATION_SOURCE_CONTRACT) continue; decoded = decodeLog(PACK_ACTIVATION_SOURCE_ABI, log.data, [ diff --git a/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts b/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts index 31d3f367..c94aedb6 100644 --- a/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts +++ b/src/contextualizers/protocol/uniswapV3/uniswapV3Pair.ts @@ -7,7 +7,7 @@ import { Transaction, } from '../../../types'; import { UNISWAP_V3_PAIR_ABI, UNIVERSAL_ROUTERS } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; export const contextualize = (transaction: Transaction): Transaction => { const isSwap = detect(transaction); @@ -18,8 +18,8 @@ export const contextualize = (transaction: Transaction): Transaction => { export const detect = (transaction: Transaction): boolean => { // check logs - const logs = transaction.logs; - if (!logs) return false; + const logs = grabLogsFromTransaction(transaction); + if (logs.length === 0) return false; for (const log of logs) { const decoded = decodeLog( @@ -35,14 +35,15 @@ export const detect = (transaction: Transaction): boolean => { // Contextualize for mined txs export const generate = (transaction: Transaction): Transaction => { + const logs = grabLogsFromTransaction(transaction); if ( !transaction.netAssetTransfers || - !transaction.logs || + logs.length === 0 || !transaction.chainId ) return transaction; let decoded; - for (const log of transaction.logs) { + for (const log of logs) { decoded = decodeLog( UNISWAP_V3_PAIR_ABI as Abi, log.data as Hex, diff --git a/src/contextualizers/protocol/zoraCreator/zoraCreator.ts b/src/contextualizers/protocol/zoraCreator/zoraCreator.ts index 257cfe3c..c150d9ff 100644 --- a/src/contextualizers/protocol/zoraCreator/zoraCreator.ts +++ b/src/contextualizers/protocol/zoraCreator/zoraCreator.ts @@ -5,7 +5,7 @@ import { PROTOCOL_REWARDS_CONTRACT, REWARDS_DEPOSIT_TOPIC, } from './constants'; -import { decodeLog } from '../../../helpers/utils'; +import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils'; import { generate as erc721Generate } from '../../heuristics/erc721Mint/erc721Mint'; import { generate as erc1155Generate } from '../../heuristics/erc1155Mint/erc1155Mint'; @@ -18,8 +18,7 @@ export const contextualize = (transaction: Transaction): Transaction => { export const detect = (transaction: Transaction): boolean => { // check if there is 'RewardsDeposit' log emitted - const logs = - transaction.logs && transaction.logs.length > 0 ? transaction.logs : []; + const logs = grabLogsFromTransaction(transaction); const rewardsDepositLog = logs.find( (log) => log.topic0 === REWARDS_DEPOSIT_TOPIC && @@ -32,6 +31,7 @@ export const detect = (transaction: Transaction): boolean => { // Contextualize for mined txs export const generate = (transaction: Transaction): Transaction => { + const logs = grabLogsFromTransaction(transaction); // detect as heuristic erc721 or erc1155 mint transaction = erc721Generate(transaction); if (transaction.context?.summaries?.en.title !== 'NFT Mint') { @@ -44,8 +44,6 @@ export const generate = (transaction: Transaction): Transaction => { transaction.context.summaries.category = 'PROTOCOL_1'; transaction.context.summaries.en.title = 'Zora'; - const logs = - transaction.logs && transaction.logs.length > 0 ? transaction.logs : []; const rewardsDepositLog = logs.find( (log) => log.topic0 === REWARDS_DEPOSIT_TOPIC, ); diff --git a/src/helpers/utils.ts b/src/helpers/utils.ts index bfd538b0..f6f71b43 100644 --- a/src/helpers/utils.ts +++ b/src/helpers/utils.ts @@ -23,6 +23,7 @@ import { ETHAssetTransfer, ERC20AssetTransfer, ERC20Asset, + Log, } from '../types'; const VALID_CHARS = @@ -497,3 +498,23 @@ export const addAssetTransfersToContext = ( return transaction; }; + +export const grabLogsFromTransaction = (transaction: Transaction): Log[] => { + if (transaction.logs) return transaction.logs; + + if (transaction.receipt?.logs) { + return transaction.receipt.logs.map((log) => { + return { + address: log.address, + topics: log.topics, + data: log.data, + topic0: log.topics?.[0], + topic1: log.topics?.[1], + topic2: log.topics?.[2], + topic3: log.topics?.[3], + } as Log; + }); + } + + return []; +};