Query editor
WITH usdt_borrowers AS (SELECT borrower AS balance_owner, sum(amount) AS net_debtFROM lending.borrowWHERE blockchain = 'ethereum' AND project = 'aave' AND version = '3' AND symbol = 'USDT'GROUP BY 1HAVING sum(amount) > 100),collateral_positions AS (SELECTCASE WHEN transaction_type = 'withdraw' THEN depositor ELSE coalesce(on_behalf_of, depositor) END AS balance_owner,token_address,max(symbol) AS symbol,sum(amount) AS net_suppliedFROM lending.supplyWHERE blockchain = 'ethereum' AND project = 'aave' AND version = '3'GROUP BY 1, 2HAVING sum(amount) > 0),priced AS (SELECTc.symbol,c.token_address,c.net_supplied,p.priceFROM collateral_positions cINNER JOIN usdt_borrowers b ON c.balance_owner = b.balance_ownerLEFT JOIN prices.latest p ON p.contract_address = c.token_address AND p.blockchain = 'ethereum')SELECTsymbol,sum(net_supplied) AS total_tokens,sum(net_supplied * coalesce(price, 0)) AS total_usd_valueFROM pricedGROUP BY symbolHAVING sum(net_supplied * coalesce(price, 0)) > 100000ORDER BY total_usd_value DESCLIMIT 20