Query editor
WITHdelegation_daily_balance AS (SELECTdt,SUM(amount_raw / POW(10, decimals) * price) AS amount_usdFROM query_6106872 AS bLEFT JOIN prices.day AS p ON p.blockchain = 'ethereum' AND p.contract_address = b.collateral AND p.timestamp = b.dtGROUP BY 1),debt_token_transfer AS (SELECTevt_block_date AS dt,"from","to",value / 1e6 AS amountFROM cap_money_ethereum.debttoken_evt_transfer),debt_mint_burn_events AS (SELECTdt,amountFROM debt_token_transferWHERE "from" = 0x0000000000000000000000000000000000000000UNION ALLSELECTdt,-amount AS amountFROM debt_token_transferWHERE "to" = 0x0000000000000000000000000000000000000000),debt_daily_balance_changes AS (SELECTdt,SUM(amount) AS amountFROM debt_mint_burn_eventsGROUP BY 1),delegated_vs_borrowed AS (SELECTdelegation.dt,delegation.amount_usd AS delegation_amount,SUM(COALESCE(debt.amount, 0)) OVER (ORDER BY delegation.dt) AS debt_amountFROM delegation_daily_balance AS delegationLEFT JOIN debt_daily_balance_changes AS debt ON debt.dt = delegation.dt)SELECTdt,delegation_amount,debt_amount,debt_amount/delegation_amount AS debt_delegation_ratioFROM delegated_vs_borrowedWHERE dt >= TIMESTAMP '2025-08-24'ORDER BY dt DESC