ethereum / eth-typing

Python types for type hinting commonly used ethereum types
MIT License
31 stars 35 forks source link

ABIEvent should use indexed components #91

Closed LefterisJP closed 2 weeks ago

LefterisJP commented 2 weeks ago

What happened?

Either the ABIEvent type definition seems wrong to me or I am misunderstanding how it should be used.

The current definition is:

class ABIEvent(TypedDict):
    """
    TypedDict to represent the `ABI` for an event.
    """

    name: str
    """Event name identifier."""
    type: Literal["event"]
    """Event ABI type."""
    anonymous: NotRequired[bool]
    """If True, event is anonymous. Cannot filter the event by name."""
    inputs: NotRequired[Sequence["ABIComponent"]]
    """Input components for the event."""```

But this is skipping the `indexed` argument of all event inputs.

Shouldn't it be

```diff
-    inputs: NotRequired[Sequence["ABIComponent"]]
+    inputs: NotRequired[Sequence["ABIComponentIndexed"]]

instead?

Code that produced the error

GRAPH_DELEGATION_TRANSFER_ABI: Final[Sequence[ABIEvent]] = [
    {  # all type ignores are due to inability of typing to see ABIComponentIndexed
        'anonymous': False,
        'inputs': [
            {
                'indexed': True,  # type: ignore
                'name': 'delegator',
                'type': 'address',
            },
            {
                'indexed': True,  # type: ignore
                'name': 'l2Delegator',
                'type': 'address',
            },
            {
                'indexed': True,  # type: ignore
                'name': 'indexer',
                'type': 'address',
            },
            {
                'indexed': False,  # type: ignore
                'name': 'l2Indexer',
                'type': 'address',
            },
            {
                'indexed': False,  # type: ignore
                'name': 'transferredDelegationTokens',
                'type': 'uint256',
            },
        ],
        'name': 'DelegationTransferredToL2',
        'type': 'event',
    },
]

Full error output

rotkehlchen/chain/evm/decoding/thegraph/constants.py:22: error: Extra key "indexed" for TypedDict "ABIComponent"  [typeddict-unknown-key]
rotkehlchen/chain/evm/decoding/thegraph/constants.py:27: error: Extra key "indexed" for TypedDict "ABIComponent"  [typeddict-unknown-key]
rotkehlchen/chain/evm/decoding/thegraph/constants.py:32: error: Extra key "indexed" for TypedDict "ABIComponent"  [typeddict-unknown-key]
rotkehlchen/chain/evm/decoding/thegraph/constants.py:37: error: Extra key "indexed" for TypedDict "ABIComponent"  [typeddict-unknown-key]

Fill this section in if you know how this could or should be fixed

-    inputs: NotRequired[Sequence["ABIComponent"]]
+    inputs: NotRequired[Sequence["ABIComponentIndexed"]]

eth-typing Version

5.0.0

Python Version

3.11.0

Operating System

linux

Output from pip freeze

not relevant
fselmo commented 2 weeks ago

Thanks @LefterisJP. You're correct. We'll get this change in asap.

LefterisJP commented 2 weeks ago

Thanks @LefterisJP. You're correct. We'll get this change in asap.

hahaah thanks. Because of the fix tests failed in CI and not locally and took me some time to figure out what had happened. Need to be pinnign eth-typign again :)