Query editor
WITH borrow_and_repay AS (SELECTusers AS user,SUM(CASE WHEN action = 'Borrow' THEN amount ELSE 0 END) AS total_borrowed,SUM(CASE WHEN action = 'Repay' THEN amount ELSE 0 END) AS total_repaidFROM (-- EthereumSELECT onBehalfOf AS users, 'Borrow' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_ethereum.Pool_evt_BorrowLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'ethereum'UNION ALLSELECT user AS users, 'Repay' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_ethereum.Pool_evt_RepayLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'ethereum'-- ArbitrumUNION ALLSELECT onBehalfOf AS users, 'Borrow' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_arbitrum.L2Pool_evt_BorrowLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'arbitrum'UNION ALLSELECT user AS users, 'Repay' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_arbitrum.L2Pool_evt_RepayLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'arbitrum'-- BaseUNION ALLSELECT onBehalfOf AS users, 'Borrow' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_base.L2Pool_evt_BorrowLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'base'UNION ALLSELECT user AS users, 'Repay' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_base.L2Pool_evt_RepayLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'base'-- OptimismUNION ALLSELECT onBehalfOf AS users, 'Borrow' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_optimism.Pool_evt_BorrowLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'optimism'UNION ALLSELECT user AS users, 'Repay' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_optimism.Pool_evt_RepayLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'optimism'-- PolygonUNION ALLSELECT onBehalfOf AS users, 'Borrow' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_polygon.Pool_evt_BorrowLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'polygon'UNION ALLSELECT user AS users, 'Repay' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_polygon.Pool_evt_RepayLEFT JOIN tokens.erc20 t ON reserve = t.contract_address AND blockchain = 'polygon'-- AvalancheUNION ALLSELECT onBehalfOf AS users, 'Borrow' AS action, amount / POW(10, decimals) AS amountFROM aave_v3_avalanche_c.Pool_evt_Borrow