MasterChETHTime Series Query
    Updated 2024-06-14
    with base as (
    SELECT
    'Borrows' as action,
    date_trunc('year', block_timestamp) as year,
    date_trunc('quarter', block_timestamp) as quarter,
    date_trunc('month', block_timestamp) as month,
    date_trunc('week', block_timestamp) as week,
    token_symbol,
    event_name,
    platform,
    sum(amount) as amount,
    sum(amount_usd) amount_usd,
    avg(amount_usd) amount_usd_avg,
    count(*) as txn_count,
    count(distinct(origin_from_address)) as distinct_lenders
    from
    {{Chain}}.defi.ez_lending_borrows
    group by
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8
    UNION
    ALL
    SELECT
    'Deposits' as action,
    date_trunc('year', block_timestamp) as year,
    date_trunc('quarter', block_timestamp) as quarter,
    date_trunc('month', block_timestamp) as month,
    date_trunc('week', block_timestamp) as week,
    token_symbol,
    event_name,
    QueryRunArchived: QueryRun has been archived