Sandeshnekodex pendle earn USDC
    Updated 2025-01-20
    -- This query calculates the current token balance and earned amount for a specific set of users on base,
    -- focusing on token transfers associated with a specific contract address.
    -- It retrieves deposit and redemption transactions for the specified users and contract address,
    -- sums the net balances of the users, and compares the balance from the blockchain node with the on-chain balance.
    with nekodex_users as
    (
    SELECT
    distinct to_address as user_address
    FROM
    optimism.core.fact_traces
    WHERE 1 = 1
    AND block_timestamp >= '2024-04-12'
    AND identifier = 'CREATE2_0_0_0_0'
    AND from_address = '0x6723b44abeec4e71ebe3232bd5b455805badd22f' -- contract deployer
    AND TX_STATUS = 'SUCCESS'
    ),

    deposit_transactions AS (
    -- Selects outgoing token transfers (deposits) for specified users
    SELECT
    block_number
    , block_timestamp
    , tx_hash
    , from_address AS user_address -- User making the deposit
    , contract_address
    , symbol
    , -1 * amount AS token_amount -- Negate amount to represent outgoing funds
    , -1 * raw_amount_precise::DOUBLE AS precise_token_amount -- Precise negative amount for outgoing transfer
    , 'deposited' AS transaction_direction -- Label to indicate a deposit transaction
    FROM
    base.core.ez_token_transfers
    WHERE
    1 = 1 -- Placeholder for additional conditions
    AND from_address IN (
    select user_address from nekodex_users
    ) -- Filter to only include transfers from the specified users
    QueryRunArchived: QueryRun has been archived