Query editor
WITH positions AS (SELECT position, collateral FROM query_8336020),latest AS (SELECT l.contract_address AS position,bytearray_to_uint256(bytearray_substring(l.data, 65, 32)) / 1e18 AS minted_zchf,ROW_NUMBER() OVER (PARTITION BY l.contract_address ORDER BY l.block_number DESC, l.index DESC) AS rnFROM ethereum.logs lJOIN positions p ON l.contract_address = p.positionWHERE l.topic0 = 0x9483a26ad376f30b5199a79e75df3bb05158c4ee32a348f53e83245a5e50c86e)SELECT COALESCE(tk.symbol, CAST(p.collateral AS varchar)) AS symbol,COUNT(*) AS n_positions,SUM(lu.minted_zchf) AS minted_zchf,100.0 * SUM(lu.minted_zchf) / SUM(SUM(lu.minted_zchf)) OVER () AS pct_of_debtFROM latest luJOIN positions p ON p.position = lu.positionLEFT JOIN tokens.erc20 tk ON tk.contract_address = p.collateral AND tk.blockchain = 'ethereum'WHERE lu.rn = 1 AND lu.minted_zchf > 0GROUP BY 1ORDER BY minted_zchf DESC