Sbhn_NPcolossal-harlequin
    Updated 4 days ago
    WITH price as (
    select hour::date as datee,
    avg(price) as usdprice
    from stellar.price.ez_prices_hourly
    where symbol = 'XLM'
    group by 1
    ),


    supply as ( SELECT
    SUM(
    CASE
    WHEN COALESCE(details_json:asset_balance_changes[0]:asset_code::STRING, 'XLM') = 'XLM'
    THEN details_json:asset_balance_changes[0]:amount * usdprice
    ELSE details_json:asset_balance_changes[0]:amount
    END
    ) AS usd_deposited
    FROM stellar.core.ez_operations
    JOIN stellar.core.fact_contract_events USING(transaction_hash)
    LEFT JOIN price ON DATE_TRUNC('day', block_timestamp) = datee
    WHERE details_json:asset_balance_changes[0]:to = 'CDVQVKOY2YSXS2IC7KN6MNASSHPAO7UN2UR2ON4OI2SKMFJNVAMDX6DP'
    AND details_json:asset_balance_changes[0]:type = 'transfer'
    AND topics_decoded:topics_decoded[0]:value ='supply_collateral'
    and block_timestamp::date >= '2025-01-01'
    ),


    repay as ( SELECT
    SUM(
    CASE
    WHEN COALESCE(details_json:asset_balance_changes[0]:asset_code::STRING, 'XLM') = 'XLM'
    THEN details_json:asset_balance_changes[0]:amount * usdprice
    ELSE details_json:asset_balance_changes[0]:amount
    END
    ) AS usd_repayed
    FROM stellar.core.ez_operations
    Last run: 4 days ago
    USD_DEPOSITED
    USD_REPAYED
    USD_BORROWED
    USD_WITHDRAWN
    1
    12666110.42421385261452.990666045995628.143227448793004.09648709
    1
    71B
    35s