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'], })