-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add multiple price feeds option #65
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes generally make sense for testing other price feeds.
One issue is that the query is a bit too complicated for me now. (Maybe already was too complicated before.) Since it is essential to the accounting, it has to easy to understand what the query does.
For example, the handling of missing values seems a bit indirect: first, some price feeds are combined and an approximate median is computed. If that is missing, yet another price feed is used. So there seem to be different tiers of price feeds as well. But that is not made explicit anywhere. And only the Dune price feed is used for some things (intrinsic prices, native token prices) that other price feeds could theoretically also be used for.
@@ -43,6 +82,35 @@ precise_prices as ( | |||
group by 1, 2, 3 | |||
), | |||
|
|||
multiple_price_feeds_pre as ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name does not help me understand what this table means. You can just select from a union in the next table. If it is a conceptually important table to you, the name should be changed.
@@ -25,8 +25,47 @@ with token_times as ( | |||
group by 1, 2 | |||
), | |||
|
|||
imported_price_feed as ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some comments on what those tables mean, or on the meaning of some tables in the context of the full query.
@@ -135,5 +187,5 @@ native_token_prices as ( | |||
) | |||
|
|||
select * from prices | |||
union all | |||
union distinct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change required? Before, the entries in the prices table were always distinct from entries in the native_token_prices table since the token address was different. Does this still hold?
If not, there might be additional issues due to a token having multiple prices at the same time, leading to duplicate entries when joining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh i didn't think too much about it and it just looked more correct to me (in the sense that if you provide a prices table where native tokens are included, then you should not use the corresponding native_token_prices entries). In the current state, i don't think it can ever happen that the two table have common entries so i will switch back to union all
Is there a way to test this query? |
5ea81c5
to
1fa83a6
Compare
Are you sure you want to use the legacy Caused by: |
For the median part of the code, i added this "test" |
cowprotocol/accounting/price_feed/raw_price_feed_query_4252674.sql
Outdated
Show resolved
Hide resolved
Do you have a test query on dune for some of the final queries, e.g. raw slippage from query 4059683? I still do not quite get what the final design would be and what the intermediate testing would look |
So, i forked basically all queries that this PR changes as follows:
There are some minor changes in some queries so that their output is more interesting for testing purposes |
My goal would be to eventually use the "new price feed". What this will be is not clear yet. Currently it is the median of some price feeds; we could add more price feeds or take some other function of the existing ones, or average out over longer periods of time, etc etc. But the goal is to replace the Dune price feed eventually. The problem itself is a bit underspecified, that's why i don't have a clear answer to "how does it help with fixing prices". A concrete first goal for me would be to kill outliers, i.e., not have to manually exclude txs from the accounting because slippage is extremely off. |
I think the issue is with using prices per unit instead of prices per atom. E.g. for token |
This PR adds the option to use multiple price feeds as follows:
thethe method for computing the median that is presented in this article is used to compute a price based on these price feeds. This replaces what has been now only the dune price.approx_percentile(0.5)
In case all price feeds return null, we continue to use the fallbacks that have been used up till now