adriaparcerisasfees on kashi 2.0
    Updated 2022-07-13
    -- How much fees each Kashi market has generated and which are the top markets in terms of fees generated?

    WITH
    lendings as (
    select
    block_timestamp,
    --trunc(block_timestamp,'month') as date,
    lending_pool as kashi_pair,
    tx_hash
    from flipside_prod_db.crosschain.ez_lending
    where platform ='sushi' --and symbol in ('DAI','USDT','USDC','USDN') and action='Deposit'
    --group by 1,2
    ),
    collaterals as (
    SELECT
    block_timestamp,
    --trunc(block_timestamp,'month') as date,
    lending_pool as kashi_pair,
    tx_hash
    from flipside_prod_db.crosschain.ez_borrowing
    where platform='sushi' --and block_chain --and collateral_symbol in ('DAI','USDT','USDC','USDN') and action='Borrow'
    --group by 1,2
    ),
    lending_fees as (
    SELECT
    y.kashi_pair,
    sum(tx_fee) as monthly_eth_fees_generated
    from polygon.core.fact_transactions x
    join lendings y on x.tx_hash=y.tx_hash
    group by 1
    order by 2 desc
    ),
    collateral_fees as (
    SELECT
    y.kashi_pair,
    sum(tx_fee) as monthly_eth_fees_generated
    Run a query to Download Data