Query editor
with ankrBNB_ratio as (select address as bond_token_contract, ((cast(ratio as decimal(38,0)))/1e18) as ratio1, date_trunc('week', call_block_time) as weekfrom ankr_bnb.InternetBondRatioFeed_call_updateRatioBatch cross join unnest(addresses,ratios) as t(address,ratio)where call_success = True and address = 0xfe39985D7eFF914c50A06bA0cFfcCA8361e00C0e -- aBNBb token contractorder by date_trunc('week', call_block_time) desc),daily_metrics as (select week, ratio1, lag(ratio1, 7) over (order by week desc) as ratio2from ankrBNB_ratio),apy_data as (select week, round(avg(((ratio1-ratio2)*(31536000/604800))*100), 3) as apyfrom daily_metricswhere ratio2 is not null--and week >= date('2023-03-11')group by weekorder by week desc)select week, apy, round((apy - lag(apy, 1) ignore nulls over (order by week))) as apy_change_count,round((apy - lag(apy, 1) ignore nulls over (order by week))/lag(apy, 1) ignore nulls over (order by week), 3) as weekly_apy_change_percentfrom apy_dataorder by week desc