denze-e7j2NUCreator Fees Paid by {{nft_contract_address}}
    Updated 2023-03-31
    WITH

    input_contracts AS (
    SELECT
    *
    FROM VALUES
    (lower('{{nft_contract_address}}'))
    AS data(nft_contract_address)
    WHERE data.nft_contract_address regexp '^0x[0-9a-fA-F]{40}$' -- check address is a valid format, i.e. starts with 0x and has 42 characters total
    )

    , input_time AS (
    SELECT
    CASE
    WHEN to_timestamp_ntz(data.snapshot_time) > date_trunc('minute', current_timestamp) THEN date_trunc('minute', current_timestamp)
    ELSE date_trunc('minute', to_timestamp_ntz(data.snapshot_time))
    END AS snapshot_time
    FROM VALUES
    ('{{snapshot_time}}')
    AS data(snapshot_time)
    )

    , input_creator_fee_perc AS (
    SELECT
    *
    FROM VALUES
    ({{creator_fee_perc}})
    AS data(creator_fee_perc)
    )

    -- get the time of the latest data for reference in the output
    -- to ensure that the actual snapshot time is the expected snapshot time
    , snapshot_time_check AS (
    SELECT
    CASE
    WHEN MIN(block_time) >= (SELECT snapshot_time FROM input_time) THEN (SELECT snapshot_time FROM input_time)
    Run a query to Download Data