From 335b8608ae8f5b49439f40c9da9c969f2bacce13 Mon Sep 17 00:00:00 2001 From: anastasiarods Date: Sat, 7 Dec 2024 19:40:56 +0700 Subject: [PATCH] Fix ts error for 0x interpreter (#172) --- .changeset/clean-beans-whisper.md | 5 +++++ packages/transaction-interpreter/interpreters/zeroEx.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/clean-beans-whisper.md diff --git a/.changeset/clean-beans-whisper.md b/.changeset/clean-beans-whisper.md new file mode 100644 index 0000000..f8564b2 --- /dev/null +++ b/.changeset/clean-beans-whisper.md @@ -0,0 +1,5 @@ +--- +'@3loop/transaction-interpreter': patch +--- + +Fix ts error for 0x interpreter diff --git a/packages/transaction-interpreter/interpreters/zeroEx.ts b/packages/transaction-interpreter/interpreters/zeroEx.ts index fee6830..c06776e 100644 --- a/packages/transaction-interpreter/interpreters/zeroEx.ts +++ b/packages/transaction-interpreter/interpreters/zeroEx.ts @@ -8,7 +8,12 @@ export function transformEvent(event: DecodedTransaction): InterpretedTransactio if (!swapEvent || newEvent.type !== 'unknown') return newEvent - const { recipient } = swapEvent.event?.params as { recipient: string } + const params = swapEvent.event?.params as { recipient?: string } | undefined + const recipient = params?.recipient || event.fromAddress + + const buyToken = event.methodCall?.params?.[0]?.components?.find((c) => c.name === 'buyToken') as + | { value: string } + | undefined const netSent = getNetTransfers({ transfers: event.transfers, @@ -17,7 +22,7 @@ export function transformEvent(event: DecodedTransaction): InterpretedTransactio }) const netReceived = getNetTransfers({ - transfers: event.transfers, + transfers: buyToken ? event.transfers.filter((t) => t.address === buyToken.value) : event.transfers, toAddresses: [recipient], type: ['ERC20', 'native'], })