cowprotocol/solver-rewards

Cardinality issue in slippage query

Opened this issue · 1 comments

valued_potential_buffered_trades joins potential_buffer_trades with clearing_prices and should not increase the number of rows, but seems to do so (period 01-24 to 01-31, 17223 potential buffer trades, 17331 valued buffer trades).

This is likely due to prices.usd no longer being unique for token/minute pair in Dune v2

-- The following joins require the uniqueness of the prices per join,
-- otherwise duplicated internal trades will be found.
-- For clearing prices, it is given by construction and
-- for prices.usd, one can see that the primary key of the table is
-- (contract, minute) as seen here: https://dune.xyz/queries/510124

Fix may be to create an intermediate table that averages prices of tokens for which we have multiple records per week.

I went back 2 months and not seeing any duplicated prices. So it seems the answer is not so straightforward.