0-MIDDAI Borrowed Distribution to DAI Borrowers
    Updated 2023-04-13
    with act1 as(
    with tab1 as (
    select tx_hash
    from ethereum.maker.ez_vault_creation),
    tab2 as (
    select tx_hash
    from ethereum.maker.ez_deposits
    where TOKEN_DEPOSITED='0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
    )
    select tab2.tx_hash
    from tab1
    left join tab2
    on tab1.tx_hash=tab2.tx_hash),
    act2 as (
    select BLOCK_TIMESTAMP::date as date,tx_hash,AMOUNT_USD,ORIGIN_FROM_ADDRESS
    from ethereum.core.ez_token_transfers
    where CONTRACT_ADDRESS='0x6b175474e89094c44da98b954eedeac495271d0f'
    and FROM_ADDRESS='0x0000000000000000000000000000000000000000'
    )
    select distinct ORIGIN_FROM_ADDRESS as unique_borrowers,sum(AMOUNT_USD)as dai_borrowed
    ,count(distinct ORIGIN_FROM_ADDRESS)as dai_borrowers,case
    when dai_borrowed>=10 and dai_borrowed<100 then '10 to 100'
    when dai_borrowed>=100 and dai_borrowed<1000 then '100 to 1K'
    when dai_borrowed>=1000 and dai_borrowed<10000 then '1K to 10K'
    when dai_borrowed>=10000 and dai_borrowed<100000 then '10K to 100K'
    when dai_borrowed>=100000 and dai_borrowed<1000000 then '100K to 1M'
    when dai_borrowed>=1000000 and dai_borrowed<10000000 then '1M to 10M'
    when dai_borrowed>=10000000 then 'up to 10M' end as loan_amount
    from act1
    left join act2
    on act1.tx_hash=act2.tx_hash
    where AMOUNT_USD > 0
    group by 1



    Run a query to Download Data