Query editor
-- Widget: Counter | Title: "APY" (suffix: "%", decimals: 2)---- "Time-weighted yield rate" methodology — robust to lumpy distribution.---- For each RewardsReceived event in the last 7 days:-- gap_days = (this reward's time) − (previous reward's time) in days-- balance_before = wiTRY contract iTRY balance JUST before this reward-- yield_added = amount / balance_before-- implied_daily = yield_added / gap_days---- Aggregated:-- avg_daily_yield = Σ(yield_added) / Σ(gap_days)-- APY = (1 + avg_daily_yield)^365 − 1---- Why this works for weekend gaps & delayed distributions:-- Mon (1d gap, R reward) → R/B/1 daily rate-- Tue (1d gap, R reward) → R/B/1-- ...-- Mon catch-up (3d gap, 3R) → 3R/B/3 = R/B/1 (same rate, weekend folded in)-- Delayed by 1 day (2d gap, 2R) → 2R/B/2 = R/B/1 (same rate)---- All these scenarios produce the same daily yield contribution. Average-- stays stable regardless of when you query.WITH-- Every RewardsReceived event with its gap from the previous onerewards AS (SELECTblock_time AS t,CAST(bytearray_to_uint256(bytearray_substring(data, 1, 32)) AS DOUBLE) / 1e18 AS amount,LAG(block_time) OVER (ORDER BY block_time) AS prev_tFROM ethereum.logsWHERE contract_address = 0xE346C29b5B60Ef870b9724c57ccfbBc631e47DEEAND topic0 = 0xbb28dd7cd6be6f61828ea9158a04c5182c716a946a6d2f31f4864edb87471aa6),-- Recent rewards (last 7 days, with a previous one to compute gap)recent_rewards AS (SELECTCAST(t AS TIMESTAMP) AS t,amount,CAST(date_diff('second', prev_t, t) AS DOUBLE) / 86400.0 AS gap_daysFROM rewardsWHERE prev_t IS NOT NULLAND CAST(t AS TIMESTAMP) >= CAST(NOW() AS TIMESTAMP) - INTERVAL '7' DAY),-- All iTRY transfers in/out of wiTRY contract (signed)itry_transfers AS (SELECTCAST(evt_block_time AS TIMESTAMP) AS t,CASE WHEN "to" = 0xE346C29b5B60Ef870b9724c57ccfbBc631e47DEE THEN CAST(value AS DOUBLE)WHEN "from" = 0xE346C29b5B60Ef870b9724c57ccfbBc631e47DEE THEN -CAST(value AS DOUBLE)ELSE 0 END AS deltaFROM erc20_ethereum.evt_TransferWHERE contract_address = 0xb492B4aFD9658093694CF9452D5C272e8230F3B0AND ("to" = 0xE346C29b5B60Ef870b9724c57ccfbBc631e47DEEOR "from" = 0xE346C29b5B60Ef870b9724c57ccfbBc631e47DEE)),