Query editor
-- @title Coinbase tokenized-stock markets (Base) — daily borrow APY-- @description Daily borrow APY for the five Coinbase tokenized-stock / USDC Morpho Blue markets on Base that-- Steakhouse High Yield USDC allocates to (AAPLc 62.5%, GOOGLc 77%, NVDAc 62.5%, METAc 62.5%, SPCXc 62.5%),-- from market creation on 7 Sep 2026. Daily version of query 8798663. Long format: one row per (day, market).-- @author Romana (Steakhouse Financial)-- @notes Rate from Morpho Blue AccrueInterest.prevBorrowRate (per-second, WAD). Each event's rate is weighted by-- the seconds it was in force (until the next accrual on that market), clipped to the day boundary, then-- averaged per day. Days with no accrual carry the previous day's last rate. APY = exp(rate × 365 × 86400) − 1.-- @version 1.0with markets as (select *from (values(0xae1a30486234bf7e7ac166c7c03d9bc5f2cd8a39be2c48e73c665ac7148c3c28, 'AAPLc/USDC 62.5%'), (0xa3913d896b7e9c0e0a84f1be27d376cf2065616101cb7c44674af8a154e684cc, 'GOOGLc/USDC 77%'), (0xb4b42dd66cef25614b94510a910d54b2c148e7621d22b4271566724beda63d13, 'NVDAc/USDC 62.5%'), (0x44b343b5087c0bd34207cb5c199f12030777bf6b8c0a128438246f1212f37ca5, 'METAc/USDC 62.5%'), (0xce983b9ee6344e16ebbcc66812f23caafc63ae83fcc14fa29b66c7e69e9cecf6, 'SPCXc/USDC 62.5%')) as t(market_id, market)), events as (select m.market, a.evt_block_time as t, cast(a.prevBorrowRate as double) / 1e18 as rate_per_sec, lead(a.evt_block_time) over (partition by m.market order by a.evt_block_time, a.evt_index) as t_nextfrom morpho_blue_base.morphoblue_evt_accrueinterest ainner join markets m on m.market_id = a.idwhere a.evt_block_time >= timestamp '2026-09-07')-- the rate set at each accrual is in force until the next accrual; split that interval by day, segments as (select e.market, e.rate_per_sec, cast(d.day as date) as day, greatest(e.t, cast(d.day as timestamp)) as seg_start, least(coalesce(e.t_next, now()), cast(d.day as timestamp) + interval '1' day) as seg_endfrom events ecross join unnest(sequence(cast(date_trunc('day', e.t) as date), cast(date_trunc('day', coalesce(e.t_next, now())) as date), interval '1' day)) as d(day)), daily as (select market, day, sum(rate_per_sec * date_diff('second', seg_start, seg_end)) / nullif(sum(date_diff('second', seg_start, seg_end)), 0) as rate_per_secfrom segmentswhere seg_end > seg_startgroup by 1, 2)select day, market, rate_per_sec * 365 * 86400 as borrow_apr, exp(rate_per_sec * 365 * 86400) - 1 as borrow_apyfrom dailywhere rate_per_sec is not nullorder by day desc, market