Query editor
-- RWA liquidity: the headline numbers-- One row of summary stats for the RWA Liquidity Terminal stat cards.-- Sources: tokens_ethereum.rwa, erc20_ethereum.evt_Transfer, dex.trades, prices.usd_latest-- by @aardashevwith reg as (select contract_address, symbol, decimals from tokens_ethereum.rwa), supply as (selectt.contract_address, sum(casewhen t."from" = 0x0000000000000000000000000000000000000000 then cast(t.value as double)when t.to = 0x0000000000000000000000000000000000000000 then -cast(t.value as double)else 0 end) as raw_supplyfrom erc20_ethereum.evt_Transfer tjoin reg r on r.contract_address = t.contract_addressgroup by 1), oracle_px as (select contract_address, price from prices.usd_latest where blockchain = 'ethereum'), trades as (selectr.contract_address, count(*) as trades_30d, sum(if(d.amount_usd > 0, d.amount_usd, null)) as vol_30d, approx_percentile(if(d.amount_usd > 0, d.amount_usd, null)/ nullif(if(d.token_bought_address = r.contract_address, d.token_bought_amount, d.token_sold_amount), 0), 0.5) as dex_pxfrom dex.trades djoin reg r on r.contract_address in (d.token_bought_address, d.token_sold_address)where d.blockchain = 'ethereum' and d.block_time >= now() - interval '30' daygroup by 1), per_token as (selectr.symbol, s.raw_supply / power(10, r.decimals) * coalesce(o.price, t.dex_px) as aum_usd, coalesce(t.vol_30d, 0) as vol_30d, coalesce(t.trades_30d, 0) as trades_30dfrom reg rleft join supply s on s.contract_address = r.contract_addressleft join oracle_px o on o.contract_address = r.contract_addressleft join trades t on t.contract_address = r.contract_address)selectcount(*) as tokens_tracked, sum(aum_usd) as measurable_aum_usd, sum(vol_30d) as dex_volume_30d, sum(vol_30d) / nullif(sum(aum_usd), 0) as blended_monthly_turnover, count_if(trades_30d = 0) as tokens_with_zero_dex_trades, count_if(aum_usd is null) as tokens_with_no_price, cast(count_if(trades_30d = 0) as double) / count(*) as share_never_traded