Query editor
with tvl as (select issuer, sum(amount) as tvlfrom (select a.issuer, case when coalesce(a.inverse_values, false)then -i.valueelse i.valueend as amountfrom bitcoin.outputs as iinner join query_3781856 as a on a.address = i.address and coalesce(a.track_inflow, true)where i.value > 0 and i.block_time > date(try_cast('2019-07-24' as timestamp))union allselect a.issuer, case when coalesce(a.inverse_values, false)then i.valueelse -i.valueend as amountfrom bitcoin.inputs as iinner join query_3781856 as a on a.address = i.address and coalesce(a.track_outflow, true)where i.value > 0 and i.block_time > date(try_cast('2019-07-24' as timestamp))) as flowsgroup by issuer)select bi.plain_issuer, bi.issuer, bi.etf_ticker, t.tvl, t.tvl * pu.price as usd_value,bi.percentage_fee, t.tvl / sum(t.tvl) over() as percentage_of_totalfrom tvl tjoin dune.balancercap.result_bitcoin_etf_issuers bi on t.issuer = bi.issuerleft join (select price from prices.usd_latest where blockchain is null and symbol = 'BTC' limit 1) pu on trueorder by t.tvl desc;