Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect event type inferrence #777

Closed
kinsyudev opened this issue Apr 5, 2024 · 3 comments
Closed

Incorrect event type inferrence #777

kinsyudev opened this issue Apr 5, 2024 · 3 comments

Comments

@kinsyudev
Copy link

Hey, I'm working on indexing a certain event where part of the data is marked as indexed and some isn't. Here's the event's ABI.

{
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: "address",
        name: "token0",
        type: "address",
      },
      {
        indexed: true,
        internalType: "address",
        name: "token1",
        type: "address",
      },
      { indexed: false, internalType: "bool", name: "stable", type: "bool" },
      {
        indexed: false,
        internalType: "address",
        name: "pair",
        type: "address",
      },
      { indexed: false, internalType: "uint256", name: "", type: "uint256" },
    ],
    name: "PairCreated",
    type: "event",
  },

When I look at event.args, it infers that the types will be

(property) args: readonly [`0x${string}`, `0x${string}`, boolean, `0x${string}`, bigint]

But instead, at runtime, event.args includes the following

{
  name: 'PairCreated',
  args: [ false, '0x783A3Fb9F88dF5A89fB3a5e595254Fa8f7b97b48', 7n ],
  log: {
    address: '0xc6366EFD0AF1d09171fe0EBF32c7943BB310832a',
    blockHash: '0x00029b7a00000793ea07845a2d6d1a81b016bdee433acf70e28687fde676aa52',
    blockNumber: 50805967n,
    data: '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000783a3fb9f88df5a89fb3a5e595254fa8f7b97b480000000000000000000000000000000000000000000000000000000000000007',
    id: '0x00029b7a00000793ea07845a2d6d1a81b016bdee433acf70e28687fde676aa52-0x2',
    logIndex: 2,
    removed: false,
    topics: [
      '0xc4805696c66d7cf352fc1d6bb633ad5ee82f6cb577c453024b6e0eb8306c6fc9',
      '0x000000000000000000000000049d68029688eabf473097a2fc38ef61633a3c7a',
      '0x00000000000000000000000021be370d5312f44cb42ce377bc9b8a0cef1a4c83'
    ],
    transactionHash: '0x908abe1c16f8c62979187eb0f5b570328a2b85a8a019f2e942511d01b2372b10',
    transactionIndex: 0
  },
...
}

You can see that args are only the non-indexed args of the event, and the args marked as indexed, are part of log.topics.

Versions:

dependencies:
  '@ponder/core':
    specifier: ^0.3.9
    version: 0.3.9(@types/node@20.9.0)(typescript@5.2.2)(viem@1.19.3)(zod@3.22.4)
  '@t3-oss/env-core':
    specifier: ^0.9.2
    version: 0.9.2(typescript@5.2.2)(zod@3.22.4)
  viem:
    specifier: ^1.19.3
    version: 1.19.3(typescript@5.2.2)(zod@3.22.4)
  zod:
    specifier: ^3.22.4
    version: 3.22.4

devDependencies:
  '@types/node':
    specifier: ^20.9.0
    version: 20.9.0
  eslint:
    specifier: ^8.53.0
    version: 8.53.0
  eslint-config-ponder:
    specifier: ^0.3.9
    version: 0.3.9(@typescript-eslint/eslint-plugin@6.21.0)(@typescript-eslint/parser@6.21.0)(eslint@8.53.0)
  typescript:
    specifier: ^5.2.2
    version: 5.2.2
@0xOlias
Copy link
Collaborator

0xOlias commented Apr 5, 2024

Hi @kinsyudev, thanks for reporting. I think this might be a viem bug, reported here. As a workaround, you should be able to solve this by adding a name for the 5th parameter in the ABI item.

@kinsyudev
Copy link
Author

Thanks @0xOlias that solved it, a lot cleaner than this workaround I made....

  const [stable, pairAddress] = event.args as unknown as [
    boolean,
    `0x${string}`
  ];
  const token0 = bytes32ToAddress(event.log.topics[1] ?? "");
  const token1 = bytes32ToAddress(event.log.topics[2] ?? "");

@0xOlias
Copy link
Collaborator

0xOlias commented Apr 8, 2024

The fix was merged into Viem and should be released in 2.9.13.

To get the fix in your Ponder app, just upgrade Viem (it's a peer dep).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants