connorhCompound Borrower Summary
    Updated 2023-01-30
    -- 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,
    borrows_contract_symbol AS underlying_symbol,
    sum(loan_amount) AS token_loan_amount,
    sum(loan_amount_usd) AS loan_amount_usd
    FROM compound.borrows
    WHERE block_timestamp >= CURRENT_DATE - 60
    GROUP BY 1,2
    ), repays AS (

    SELECT
    borrower,
    repay_contract_symbol AS underlying_symbol,
    sum(repayed_amount) AS token_repay_amount,
    sum(repayed_amount_usd) AS loan_repay_amount_usd
    FROM compound.repayments
    WHERE block_timestamp >= CURRENT_DATE - 60
    GROUP BY 1,2


    ), liquidations AS (
    SELECT
    borrower,
    liquidation_contract_symbol AS underlying_symbol,
    SUM(liquidation_amount) AS amount_seized,
    SUM(liquidation_amount_usd) AS amount_seized_usd,
    COUNT(DISTINCT liquidator) AS liquidators
    FROM
    compound.liquidations
    WHERE block_timestamp >= CURRENT_DATE - 60
    Run a query to Download Data