Query editor
-- native-core-dex-asset-volume · GENERATED by lib/core/dexShareQuery.ts-- Editing here is safe but pointless: /api/cron/dex_refresh rewrites the query from that-- file whenever the two differ, so a hand edit survives only until the next manual run.---- Every asset traded against a major quote on Uniswap or PancakeSwap, any chain, that-- cleared $3,000 over the window. One row per (week, asset, project). NO Core asset-- list: the dashboard names the assets it wants through the results API's own filter, so-- a market listed after this query last ran is already covered by the next run.WITH t AS (SELECT project, block_time, token_bought_symbol AS tb, token_sold_symbol AS ts, amount_usdFROM dex.trades-- From the Monday before the window, so the oldest week is whole. Core → Growth sets-- each week against Core's whole week, and a week cut mid-way understated it.WHERE block_date >= date_trunc('week', current_date - interval '30' day)AND project IN ('uniswap','pancakeswap') AND amount_usd IS NOT NULL-- The quote filter is the only pushdown left, and it is a big one: it drops every-- trade that is not against a dollar or a major, which is also every trade this-- comparison could not have assigned an asset side to.AND (upper(token_bought_symbol) IN ('USDT','USDC','DAI','USD1','FDUSD','BUSD','USDE','USDG','WETH','ETH','WBNB','BNB','WBTC','CBBTC','BTCB') OR upper(token_sold_symbol) IN ('USDT','USDC','DAI','USD1','FDUSD','BUSD','USDE','USDG','WETH','ETH','WBNB','BNB','WBTC','CBBTC','BTCB'))),r AS (SELECT project, block_time, amount_usd, tb, ts,CASE WHEN upper(tb) IN ('USDT','USDC','DAI','USD1','FDUSD','BUSD','USDE','USDG') THEN 1WHEN upper(tb) IN ('WETH','ETH','WBNB','BNB','WBTC','CBBTC','BTCB') THEN 2 ELSE 3 END AS rb,CASE WHEN upper(ts) IN ('USDT','USDC','DAI','USD1','FDUSD','BUSD','USDE','USDG') THEN 1WHEN upper(ts) IN ('WETH','ETH','WBNB','BNB','WBTC','CBBTC','BTCB') THEN 2 ELSE 3 END AS rsFROM t),d AS (SELECT project, block_time, amount_usd,CASE WHEN rb >= rs THEN tb ELSE ts END AS rawaFROM r WHERE rb <> rs),n AS (SELECT project, block_time, amount_usd,-- WETH→ETH, WBNB→BNB, and the xStocks wrapper wNVDAx→NVDAx. The wrapper rule-- tests the ORIGINAL casing because the convention IS the casing: lowercase w,-- lowercase x, uppercase ticker between. Upper-casing first would fire it on any-- symbol starting with W and ending in X. The hand-written list this replaced-- carried the wrapper as 'wNVDAxx', a typo that matched nothing and hid $18.3M-- of NVDAx and $25.6M of SPCXx a week, all of it on X Layer and Ink.upper(CASE WHEN upper(rawa) = 'WETH' THEN 'ETH'WHEN upper(rawa) = 'WBNB' THEN 'BNB'WHEN regexp_like(rawa, '^w[A-Z]+x$') THEN substr(rawa, 2)ELSE rawa END) AS assetFROM d),-- FOUR MEASURES PER ROW, and the three rolling ones are not derivable from the weekly-- one. Core → Markets compares against a rolling 24h/7d/30d served by the gateway;-- summing calendar periods to approximate that is worst at 24h. So the rolling windows-- are computed here from block_time, and the weekly column stays for Core → Growth.g AS (SELECT CAST(date_trunc('week', block_time) AS date) AS wk,asset, project,sum(amount_usd) AS vol,sum(CASE WHEN block_time >= now() - interval '1' day THEN amount_usd ELSE 0 END) AS r1,sum(CASE WHEN block_time >= now() - interval '7' day THEN amount_usd ELSE 0 END) AS r7,sum(CASE WHEN block_time >= now() - interval '30' day THEN amount_usd ELSE 0 END) AS r30FROM nGROUP BY 1,2,3