Skip to content

Commit

Permalink
Support nested tuples in EVM events
Browse files Browse the repository at this point in the history
  • Loading branch information
droserasprout committed Dec 20, 2024
1 parent a45e77a commit 27693e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/dipdup/abi/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ def topic0_from_abi(event: dict[str, Any]) -> str:
if event.get('type') != 'event':
raise FrameworkException(f'`{event["name"]}` is not an event')

signature = f'{event["name"]}({",".join([i["type"] for i in event["inputs"]])})'
types = []
from web3._utils.abi import collapse_if_tuple
for input in event['inputs']:
types.append(collapse_if_tuple(input))

signature = f'{event["name"]}({",".join(types)})'
return '0x' + eth_utils.crypto.keccak(text=signature).hex()


Expand Down
10 changes: 9 additions & 1 deletion src/dipdup/indexes/evm_events/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ def decode_event_data(
indexed_values = iter(decode_indexed_topics(tuple(n for n, i in inputs if i), topics))

non_indexed_bytes = decode_hex(data)
print(inputs)
if non_indexed_bytes:
non_indexed_values = iter(decode_abi(tuple(n for n, i in inputs if not i), non_indexed_bytes))
# from web3._utils.abi import collapse_if_tuple
# non_indexed_values = iter(decode_abi(tuple(n for n, i in inputs if not i), non_indexed_bytes))
non_indexed_values = iter(decode_abi(
types=tuple(n for n, i in inputs if not i),
data=non_indexed_bytes,
strict=False,
))
else:
# NOTE: Node truncates trailing zeros in event data
non_indexed_values = cycle((0,))
Expand Down Expand Up @@ -106,6 +113,7 @@ def match_events(
typename=typename,
name=handler_config.name,
)
print(abi)
if event.topics[0] != abi['topic0']:
continue
if len(event.topics) != abi['topic_count'] + 1:
Expand Down
3 changes: 2 additions & 1 deletion src/dipdup/indexes/evm_transactions/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def prepare_transaction_handler_args(
name=handler_config.method,
signature=handler_config.signature,
)['inputs']
from web3._utils.abi import collapse_if_tuple
data = decode_abi(
types=tuple(input['type'] for input in inputs),
types=tuple(collapse_if_tuple(input) for input in inputs),
data=decode_hex(matched_transaction.input[10:]),
strict=False,
)
Expand Down

0 comments on commit 27693e2

Please sign in to comment.