Kruys-Collinsyawning-ivory
    Updated 2024-10-15

    WITH APTIN AS (
    SELECT
    date_trunc('day',t1.block_timestamp) as block_timestamp, t1.event_address, t1.event_data, t1.account_address,
    t1.payload_function, t1.success, t1.tx_hash, t1.event_data:amount::float AS amount_unadjusted,
    t2.address,
    t2.address_name,
    t2.label,
    t3.token_address,
    t3.decimals,
    t3.symbol
    FROM
    aptos.core.fact_events t1
    LEFT JOIN aptos.core.dim_labels t2 ON t1.event_address = t2.address
    LEFT JOIN aptos.core.dim_tokens t3 ON t1.event_data:coin_name = t3.token_address
    WHERE t1.block_timestamp >= '2024-01-01'
    AND initcap(t2.label) = 'Aptin Finance'
    AND t1.payload_function IN (
    '0x3c1d4a86594d681ff7e5d5a233965daeabdc6a15fe5672ceeda5260038857183::lend::borrow',
    '0x3c1d4a86594d681ff7e5d5a233965daeabdc6a15fe5672ceeda5260038857183::lend::supply',
    '0x3c1d4a86594d681ff7e5d5a233965daeabdc6a15fe5672ceeda5260038857183::lend::repay',
    '0x3c1d4a86594d681ff7e5d5a233965daeabdc6a15fe5672ceeda5260038857183::lend::withdraw'
    )
    AND SUCCESS = 'TRUE'
    ),
    PRICE AS (
    SELECT DATE_TRUNC('DAY',HOUR) AS DATE,
    AVG(PRICE) AS PRICE,
    TOKEN_ADDRESS
    FROM
    aptos.price.ez_prices_hourly
    GROUP BY 1,3
    ),
    APTIN_WITH_PRICE AS (
    SELECT
    a.*,
    QueryRunArchived: QueryRun has been archived