Query editor
WITH stake_deposits AS (SELECT sum(CAST(assets AS DOUBLE)) / 1e6 AS total_deposited_usdtFROM aave_v3_ethereum.umbrellastaketoken_evt_depositWHERE contract_address = 0xa484ab92fe32b143aee7019fc1502b1daa522d31),stake_withdrawals AS (SELECT sum(CAST(assets AS DOUBLE)) / 1e6 AS total_withdrawn_usdtFROM aave_v3_ethereum.umbrellastaketoken_evt_withdrawWHERE contract_address = 0xa484ab92fe32b143aee7019fc1502b1daa522d31),deficit_covered AS (SELECT sum(CAST(amount AS DOUBLE)) / 1e6 AS total_covered_usdt, count(*) AS num_cover_events, max(evt_block_time) AS last_cover_eventFROM aave_v3_ethereum.umbrella_evt_reservedeficitcoveredWHERE reserve = 0xdac17f958d2ee523a2206206994597c13d831ec7),totals AS (SELECT sum(amount) AS total_suppliedFROM lending.supplyWHERE blockchain = 'ethereum' AND project = 'aave' AND version = '3' AND symbol = 'USDT')SELECTd.total_deposited_usdt - coalesce(w.total_withdrawn_usdt, 0) AS umbrella_stake_balance_usdt_equiv,coalesce(dc.total_covered_usdt, 0) AS historical_deficit_covered_usdt,coalesce(dc.num_cover_events, 0) AS num_cover_events,dc.last_cover_event,100.0 * (d.total_deposited_usdt - coalesce(w.total_withdrawn_usdt, 0)) / t.total_supplied AS umbrella_coverage_pct_of_suppliedFROM stake_deposits d, stake_withdrawals w, deficit_covered dc, totals t