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

AMMs LP history #142

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

AMMs LP history #142

wants to merge 21 commits into from

Conversation

PoloX2021
Copy link
Contributor

The goal of the PR is to create one materialized view which stores the historical state of CoW AMMs and competitors.
This will speed up the queries on each pool.

This first version only gets the data for CoW AMM, uniswap, pancakeswap and sushiswap. It'll be possible to add other pools later on, using the same methodology and aggregating it in the final materialized view (e.g. Balancer & Curve).

This new version also adds the weights of the pools

@PoloX2021 PoloX2021 requested a review from fleupold February 28, 2025 14:18
@harisang
Copy link
Contributor

harisang commented Mar 4, 2025

@PoloX2021 Could you fix the linting issues?

@PoloX2021
Copy link
Contributor Author

@PoloX2021 Could you fix the linting issues?

Done. I'm not sure how to fix the linting for amm_lp_table_4781568.sql because of a parsing error related to dune sql specificities.

Co-authored-by: Haris Angelidakis <64154020+harisang@users.noreply.github.com>
select varbinary_substring(topic1, 1 + 12, 20) as address
from {{blockchain}}.logs
where (
contract_address in ( --the factory contracts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slightly cleaner way of doing this would be to define a factory_contracts table where each row has an address and blockchain column. But i guess this is a bit of an overkill.

PoloX2021 and others added 4 commits March 6, 2025 11:54
Co-authored-by: Haris Angelidakis <64154020+harisang@users.noreply.github.com>
Co-authored-by: Haris Angelidakis <64154020+harisang@users.noreply.github.com>
0xe0e2ba143ee5268da87d529949a2521115987302, --arbitrum
0x03362f847B4fAbC12e1Ce98b6b59F94401E4588e --base
)
and topic0 = 0x0d03834d0d86c7f57e877af40e26f176dc31bd637535d4ba153d1ac9de88a7ea
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have: some reference that confirms this is the topic we are looking for

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a link to an example of bind events & cow amm created events, but I've never really found the documentation about it.

(price0.blockchain = '{{blockchain}}' or price0.blockchain is null)
and (price1.blockchain = '{{blockchain}}' or price0.blockchain is null)
and d.day >= date_trunc('day', p.created_at)
from (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit strange. I don't think the "select * from (select ....) this is needed, and you should instead simply have

"select...."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure about how to do it efficiently. Basically, I want to filter by the final condition (where latest_first = 1) AFTER doing all the other operations. If you add the filtering in the where statement, then it happens before which gives a different result.
If there's another way to do it I'd be glad to learn about it.

where latest_first = 1
)

select *
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

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

Successfully merging this pull request may close these issues.

2 participants