grahamNEAR Bridge Activity da big project
    Updated 2022-10-26
    with token_prices as (
    select distinct token_contract,
    TRUNC(TIMESTAMP,'hour') as timestamp_h,
    avg(price_usd) as price_usd
    from near.core.fact_prices
    where timestamp >= (current_date - {{metric_days}})
    group by 1,2
    ),
    near_prices as (
    select
    TRUNC(TIMESTAMP,'hour') as timestamp_h,
    avg(price_usd) as price_usd
    from near.core.fact_prices
    where timestamp >= (current_date - 90)
    AND symbol = 'wNEAR'
    group by 1
    ),
    nte_erc20_transactions as (
    select
    a.block_timestamp,
    a.tx_hash,
    b.tx_signer as sender,
    b.tx_receiver as token_id,
    parse_json(a.args):amount::number as amount,
    lower(concat('0x',parse_json(a.args):recipient::string)) as eth_recipient
    from "NEAR"."CORE"."FACT_ACTIONS_EVENTS_FUNCTION_CALL" a
    inner join (select tx_hash, tx_receiver, tx_signer
    from "NEAR"."CORE"."FACT_TRANSACTIONS"
    where tx_receiver ilike ('%.factory.bridge.near')
    and tx_receiver not in ('metadata.factory.bridge.near', 'controller.factory.bridge.near')
    and tx_status = 'Success') b
    on a.tx_hash = b.tx_hash
    where a.method_name = 'withdraw'
    and block_timestamp >= (current_date - {{metric_days}})
    ),
    nte_erc20_totals as (
    Run a query to Download Data