Afonso_Diaz2023-04-10 05:57 PM
    Updated 2023-05-05
    with t1 as (
    select
    timestamp::date as date,
    token_contract,
    symbol,
    avg(price_usd) as price_usd
    from near.core.fact_prices
    where symbol not in ('WOO', 'WBTC')
    group by 1, 2, 3

    union all

    select
    hour::date as date,
    '2260fac5e5542a773aa44fbcfedf7c193bc2c599.factory.bridge.near' as token_contract,
    symbol,
    avg(price) as price_usd
    from ethereum.core.fact_hourly_token_prices
    where symbol = 'WBTC'
    group by 1, 2, 3
    ),

    t2 as (
    select
    block_timestamp,
    tx_hash,
    tx_signer as user,
    case
    when symbol in ('USDC.e', 'WBTC', 'WETH', 'DAI', 'USDT.e', 'USN', 'AURORA') then try_parse_json(try_parse_json(b.args):msg):Execute:actions[0]:Borrow:amount / 1e18
    when symbol in ('LINEAR', 'STNEAR', 'wNEAR', 'NearX') then try_parse_json(try_parse_json(b.args):msg):Execute:actions[0]:Borrow:amount / 1e24
    end as amount,
    amount * t1.price_usd as amount_usd,
    symbol
    from near.core.fact_transactions a
    join near.core.fact_actions_events_function_call b
    using(tx_hash)
    Run a query to Download Data