0xHaM-dBorrowed, Repaid or Liquidated
    Updated 2022-09-06
    with borrower as (
    SELECT
    BLOCK_TIMESTAMP,
    'BORROWER' as status,
    TX_HASH,
    BORROWER,
    AMOUNT_LOANED as amount
    FROM ethereum.maker.ez_flash_loans
    WHERE TX_STATUS = 'SUCCESS'
    )
    ,repay as (
    SELECT
    a.BLOCK_TIMESTAMP,
    'PAYER' as status,
    a.TX_HASH,
    PAYER,
    AMOUNT_PAID as amount
    FROM ethereum.maker.ez_repayments a join borrower b on PAYER = BORROWER and a.BLOCK_TIMESTAMP > b.BLOCK_TIMESTAMP
    WHERE TX_STATUS = 'SUCCESS'
    )
    , LIQUIDATED as (
    SELECT
    a.BLOCK_TIMESTAMP,
    'LIQUIDATED WALLET' as status,
    a.TX_HASH,
    LIQUIDATED_WALLET,
    COLLATERAL_BALANCE as amount
    FROM ethereum.maker.ez_liquidations a join borrower b on LIQUIDATED_WALLET = BORROWER and a.BLOCK_TIMESTAMP > b.BLOCK_TIMESTAMP
    WHERE TX_STATUS = 'SUCCESS'
    )
    SELECT
    date_trunc('{{interval}}', block_timestamp) as date,
    status,
    COUNT(DISTINCT TX_HASH) as tx_cnt,
    COUNT(DISTINCT BORROWER) as user_cnt,
    Run a query to Download Data