Query editor
-- This query automatically detects issues with inaccurate native prices-- affecting protocol and partner fee calculations and suggests fixes for them.-- The output produced is a csv that is ready to be plugged into dbt as a seed-- to correct flagged prices.-- Parameters:-- blockchain: the chain for which we want to retrieve batch data-- start_time: the timestamp of the first block of the interval we are focusing on-- end_time: the timestamp of the last block of the interval we are focusing on-- protocol_fee_usd_threshold: minimum usd value threshold for protocol fee collected, below which a trade is not flagged-- protocol_fee_relative_threshold: minimum relative fraction (protocol_fee_collected_value_usd / trade_value_usd) below which a trade is not flagged-- The output has the following columns:-- blockchain: varchar-- environment: varchar-- auction_id: integer cast as varchar to be easier to consume in Python apps-- token: varbinary cast as varchar to be easier to consume in Python apps-- price: decimal(38, 0) cast as varchar to be easier to consume in Python appswith block_range as (selectmin("number") as start_block,max("number") as end_blockfrom {{blockchain}}.blockswheretime >= cast('{{start_time}}' as timestamp)andtime < cast('{{end_time}}' as timestamp)),all_trades as (selectt.block_time,date_trunc('hour', t.block_time) as hour, --noqa: RF04rd.auction_id,rd.environment,t.order_uid,t.order_type,t.tx_hash,t.sell_token_address,t.buy_token_address,t.usd_value,rd.protocol_fee_native_price,rd.protocol_fee * rd.protocol_fee_native_price / pow(10,18) as protocol_fee_collected_native_unitsfrom cow_protocol_{{blockchain}}.trades as t inner join "query_4364122(blockchain='{{blockchain}}')" as rdon t.order_uid = rd.order_uid and t.tx_hash = rd.tx_hashwhere t.block_number >= (select start_block from block_range) and t.block_number <= (select end_block from block_range)),prices as (select *from "query_4064601(blockchain='{{blockchain}}', start_time='{{start_time}}',end_time='{{end_time}}')"),trades_with_dune_prices as (selectt.*,sp.price_atom as sell_token_atom_usd_price,bp.price_atom as buy_token_atom_usd_price,np.price_atom as native_token_atom_usd_price,np.price_unit as native_token_unit_usd_price