flyingfishb1 - Stats Totals by Wallet
    Updated 2024-01-16
    -- forked from b - Stats by Wallet @ https://flipsidecrypto.xyz/edit/queries/1259b517-e7fe-498b-9753-a15858791d0d

    -- forked from a Base Query For Pairs Traded @ https://flipsidecrypto.xyz/edit/queries/2cf751c5-e596-48a6-b857-db02672f8fc5

    with raw_data AS (
    SELECT
    block_timestamp
    , origin_from_address AS wallet
    , decoded_log:indexToken AS index_token
    , name
    , symbol
    , decoded_log:amountIn / pow(10, 6) AS pos_size
    , decoded_log:sizeDelta / pow(10, 30) AS open_size
    , open_size / pos_size AS leverage
    , decoded_log:isLong::boolean AS is_long
    , decoded_log:executionFee / pow(10, 18) AS execution_fee
    , tx_hash
    FROM arbitrum.core.ez_decoded_event_logs
    LEFT JOIN arbitrum.core.dim_contracts on index_token = address
    -- WHERE block_timestamp::date > current_date - 2
    WHERE block_timestamp > '2023-08-30'
    AND origin_to_address = '0x75f688604a58c720e7e4496139765498a2563c78' -- Pear Contract Address
    AND event_name = 'CreateIncreasePosition'
    AND tx_status = 'SUCCESS'
    ORDER BY event_index
    )
    SELECT
    count(DISTINCT wallet) AS pear_users
    , count(DISTINCT tx_hash) AS pear_trades
    , count(DISTINCT symbol) AS pear_tokens
    --, name
    --, symbol
    --, sum(iff(is_long, 1, 0)) AS long_pos
    --, sum(iff(is_long, 0, 1)) AS short_pos
    , sum(pos_size) AS total_collateral
    -- , avg(leverage)
    QueryRunArchived: QueryRun has been archived