Query editor
with snap as (select current_date - interval '1' day as dunion allselect current_date - interval '2' day),docks as (select strategyHash as strategy_hash, min(evt_block_time) as docked_atfrom oneinch_multichain.aquarouter_evt_docked where chain='ethereum' group by 1),flows as (select maker, strategyHash as strategy_hash, token, evt_block_time as ts, cast(amount as int256) as amtfrom oneinch_multichain.aquarouter_evt_pushed where chain='ethereum'union allselect maker, strategyHash, token, evt_block_time, -cast(amount as int256)from oneinch_multichain.aquarouter_evt_pulled where chain='ethereum'),bal as ( -- per-strategy balance as of each snapshot day, only if still openselect s.d, f.maker, f.strategy_hash, f.token, sum(f.amt) as bal_rawfrom snap sjoin flows f on f.ts < s.d + interval '1' dayleft join docks dk on dk.strategy_hash = f.strategy_hashwhere dk.docked_at is null or dk.docked_at >= s.d + interval '1' daygroup by 1,2,3,4having sum(f.amt) > 0),dedup as ( -- reuse stripped: max commitment per token that dayselect d, maker, token, max(bal_raw) as dedup_rawfrom bal group by 1,2,3),tok as (select contract_address, max(decimals) as decimals from tokens.erc20 where blockchain='ethereum' group by 1),px as (select date(minute) as day, contract_address, avg(price) as pricefrom prices.usd where blockchain='ethereum' and minute >= current_date - interval '3' day group by 1,2),leg_usd as (select dd.d, dd.maker, cast(dd.dedup_raw as double)/power(10,coalesce(t.decimals,18))*p.price as usdfrom dedup ddleft join tok t on t.contract_address=dd.tokenleft join px p on p.day=dd.d and p.contract_address=dd.token),backed_day as (select d, maker, sum(usd) as backed_usd from leg_usd where usd is not null and usd < 10000000 group by 1,2),backed as (select maker, avg(backed_usd) as avg_capital_usd from backed_day group by 1),maker_yield as ( -- yield from the last 2 days' cohort, off the published baseselect maker,count(*) as positions,sum(volume_usd) as vol, sum(spread_yield_usd) as spread,sum(est_incentive_usd) as inc, sum(total_yield_usd) as yield,approx_percentile(range_width_pct,0.5) as mr,approx_percentile(fee_pct,0.5) as mffrom query_8308889where not unbounded and capital_days > 0 and shipped_at >= current_date - interval '2' daygroup by 1)selecty.maker as provider,y.positions,round(b.avg_capital_usd, 0) as capital_usd,round(y.vol, 0) as volume_2d_usd,round(y.spread, 0) as spread_2d_usd,round(y.inc, 0) as incentive_2d_usd,round(y.yield, 0) as total_yield_2d_usd,round(100.0 * y.yield / nullif(b.avg_capital_usd,0) * 365.0/2, 0) as est_apy_pct,round(y.mr, 3) as median_range_pct,round(y.mf, 4) as median_fee_pct