Hessishzink fees tbl
    Updated 8 days ago
    with all_txs as (SELECT VALUE as cost,
    TO_ADDRESS as receiver ,
    case when
    TO_ADDRESS = '0xd00c70f9b78c63a36519c488f862df95b7a73d90' then 'Mint fee'
    else 'Referral' end as reason,
    tx_hash,
    BLOCK_TIMESTAMP
    from ink.core.fact_traces
    where --tx_hash = '0x6b764622974863ec8809d96ec45f92d38c6c3353f3e7566581da0de41effd56c' and
    TYPE = 'CALL'
    and TRACE_ADDRESS != 'ORIGIN'
    and TX_SUCCEEDED = 'TRUE'
    and FROM_ADDRESS = lower('0xFb2Cd41a8aeC89EFBb19575C6c48d872cE97A0A5')),

    price as (
    SELECT HOUR::date as time, avg(close) as pr
    from crosschain.price.fact_prices_ohlc_hourly
    where PROVIDER = 'coingecko'
    and ASSET_ID = 'ethereum'
    group by all),


    final_ref as (
    select
    round(sum(cost)*avg(pr),3) as "Referral earnings",
    'All time' as period
    from
    all_txs
    join price
    on time = BLOCK_TIMESTAMP::date
    where
    reason = 'Mint fee'
    union
    -- select
    -- round(sum(cost)*avg(pr),3) as "Referral earnings",
    -- 'Last 30 days' as period
    Last run: 8 days ago
    PERIOD
    Total fees
    1
    All time201440.01
    2
    Last 7 days802.97
    3
    Last 24 hours37.476
    4
    Last 6 hours5.242
    4
    95B
    50s