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

[BUG] 1inch-LOP introduces duplicates into dex.trades #7163

Open
0xBoxer opened this issue Nov 20, 2024 · 3 comments
Open

[BUG] 1inch-LOP introduces duplicates into dex.trades #7163

0xBoxer opened this issue Nov 20, 2024 · 3 comments
Labels
bug Something isn't working dbt: dex covers the DEX dbt subproject question Further information is requested

Comments

@0xBoxer
Copy link
Collaborator

0xBoxer commented Nov 20, 2024

Description

1inch-LOP models are introducing duplicates into dex.trades. Swap events that belong to other protocols are decoded as being 1inch LOP swaps with an incorrect evt_index number.

Example queries:

single example: https://dune.com/queries/4306571
multiple examples: https://dune.com/queries/4306524

Expected behavior

1inch-LOP model should not pick up these trades

Impacted model(s)

dex.trades
oneinch.lop

Possible solution

turns out that articifcially creating the event_index here is the problem

, row_number() over(partition by tx_hash order by call_trace_address) as evt_index

@0xBoxer 0xBoxer added the bug Something isn't working label Nov 20, 2024
@jeff-dude
Copy link
Member

@grkhr @max-morrow what do you think of this issue?

@jeff-dude jeff-dude added question Further information is requested dbt: dex covers the DEX dbt subproject labels Nov 20, 2024
@grkhr
Copy link
Contributor

grkhr commented Nov 20, 2024

These are not duplicates. In the first example everything is correct as in this TX a lot of 1inch limit orders have been filled (=our own liquidity).

The issue is in evt_index logic. We don't emit trade params in OrderFilled event, so we take them from traces, and there is no way to properly match subtrace with event index (e.g. join the trade from first example with the corresponding event), so we do row_number() over(partition by tx_hash order by call_trace_address) as evt_index to align with table's unique key.

In my honest opinion, evt_index shouldn't present in dex.trades at all, as it's assuming that the dex project will emit trade event, but generally speaking it doesn't have to. But in current architecture it's all we can do with evt_index.

I can only suggest adding trace_address to dex.trades and unique key

@0xBoxer
Copy link
Collaborator Author

0xBoxer commented Nov 22, 2024

fair assessment, adding trace_address seems logically consistent to me.

@jeff-dude I guess to not run into the null <> null problem we will need to deploy a surrogate key that combines a bunch of different factors together and can't be null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dbt: dex covers the DEX dbt subproject question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants