Query editor
-- This query computes prices for use in slippage on CoW Protocol---- It gives hourly prices for all tokens transferred to or from the protocol.---- Parameters:-- {{start_time}} - the timestamp for which the analysis should start (inclusively)-- {{end_time}} - the timestamp for which the analysis should end (exclusively)-- {{blockchain}} - network to run the analysis on---- The columns of the result are-- - hour: hour for which a price is valid-- - token_address: address of token with a price. contract address for erc20 tokens,-- 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee for native token-- - decimals: decimals of the token, can be null-- - price_unit: USD price of one unit (i.e. pow(10, decimals) atoms) of a token-- - price_atom: USD price of one atom (i.e. 1. / pow(10, decimals) units) of a token-- Fetch a list of token addresses and times we need prices for. We use hourly prices only.with token_times as (selecttoken_address,date_trunc('hour', block_time) as hour --noqa: RF04from "query_4021257(blockchain='{{blockchain}}',start_time='{{start_time}}',end_time='{{end_time}}')"where token_address != 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeegroup by 1, 2),aave_tokens_mapping as (select distinctchain as blockchain,atoken as atoken_address,asset as underlying_addressfrom aave_v3_multichain.poolconfigurator_evt_reserveinitializedunion distinctselect distinct'ethereum' as blockchain,atoken as atoken_address,asset as underlying_addressfrom aave_v3_lido_ethereum.poolconfigurator_evt_reserveinitializedunion distinctselect distinct'ethereum' as blockchain,atoken as atoken_address,asset as underlying_addressfrom aave_v3_ethereum.etherfipoolconfiguratorinstance_evt_reserveinitialized),token_times_enriched as (-- All tokens are associated with a proxy address which is used for finding a price feed instead of the original contract addressselecttt.token_address,coalesce(atm.underlying_address, tt.token_address) as proxy_address,tt.hourfrom token_times as tt left join aave_tokens_mapping as atmon tt.token_address = atm.atoken_address and atm.blockchain = '{{blockchain}}'),-- Precise prices are prices from the Dune price feed.precise_prices as (select