Tony_Intel2023-05-20 06:30 PM
    Updated 2023-05-21
    select
    case when len(input_data) = 970 then 'Borrow'
    when len(input_data) = 1034 then 'Withdraw' end as action,
    symbol,
    date_trunc('day', y.block_timestamp) as date,
    sum(raw_amount/pow(10, decimals)) as amount
    from avalanche.core.fact_token_transfers y
    join avalanche.core.fact_transactions x
    on x.tx_hash = y.tx_hash
    join avalanche.core.dim_contracts t
    on y.contract_address = t.address
    where y.origin_function_signature = '0x49160658' and y.ORIGIN_TO_ADDRESS = '0x0cd070285380cabfc3be55176928dc8a55e6d2a7'
    group by 1, 2, 3

    union all

    select
    case when origin_function_signature = '0x3bc1f1ed' then 'Deposit'
    when origin_function_signature = '0x0020311b' then 'Repay' end as action,
    symbol,
    date_trunc('day', x.block_timestamp) as date,
    sum(raw_amount/pow(10, decimals)) as amount
    from avalanche.core.fact_token_transfers x
    join avalanche.core.dim_contracts t
    on x.contract_address = t.address
    where origin_to_address = lower('0x1f9bD6986D0cDCde9fbBe87D142f3Dc4DdcA1Fd9') and origin_function_signature in ('0x3bc1f1ed', '0x0020311b')
    group by 1, 2, 3

    union all

    select
    'Deposit' as action,
    symbol,
    date_trunc('day', x.block_timestamp) as date,
    sum(raw_amount/pow(10, decimals)) as amount
    from avalanche.core.fact_token_transfers x
    Run a query to Download Data