connorhAAVE Borrower Summary
Updated 2023-01-26Copy Reference Fork
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
--- Borrower Summary
-- borrows, repays and liquidations by borrower + asset over the past 60 days
--- this creates a tally of compound borrowers (per asset), with loans taken, repayed, and how much (if any) they were subject to liquidation
WITH borrows AS (
SELECT
borrower_address AS borrower,
aave_market,
sum(borrowed_tokens) AS token_loan_amount,
sum(borrowed_usd) AS loan_amount_usd
FROM aave.borrows
WHERE block_timestamp >= CURRENT_DATE - 60
GROUP BY 1,2
), repays AS (
SELECT
borrower,
aave_market,
sum(repayed_tokens) AS token_repay_amount,
sum(repayed_usd) AS loan_repay_amount_usd
FROM aave.repayments
WHERE block_timestamp >= CURRENT_DATE - 60
GROUP BY 1,2
), liquidations AS (
SELECT
borrower,
collateral_asset AS token_contract,
SUM(liquidated_amount) AS amount_seized,
SUM(liquidated_amount_usd) AS amount_seized_usd,
COUNT(DISTINCT liquidator) AS liquidators
FROM
aave.liquidations
Run a query to Download Data