dannerHierarchical Badger Network - Simple
    Updated 2023-01-22
    with
    ----------------------------------------------------------------------------------------------------
    ---------------------- Org Name Lookups ------------------------------------------------------------
    ----------------------------------------------------------------------------------------------------
    org_names as
    (
    select
    to_address as org_addr,
    try_hex_decode_string(regexp_substr_all(SUBSTR(input, 11, len(input)), '.{64}')[14]::string) AS org_name
    from
    polygon.core.fact_traces
    where block_timestamp :: DATE > '2022-10-16' :: DATE
    and type = 'CALL'
    and from_address = LOWER('0x218b3c623ffb9c5e4dbb9142e6ca6f6559f1c2d6') -- deployer
    and substr(input, 0, 10) = '0xb6dbcae5'
    ),
    ----------------------------------------------------------------------------------------------------
    ---------------------- _Base_Table: Token Definion & Actions ----------------------------------------
    ----------------------------------------------------------------------------------------------------
    -- base table for token actions
    _base_table AS
    (
    SELECT
    block_timestamp,
    block_number,
    event_index,
    contract_address AS org_addr,
    CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS from_address,
    CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS to_address,
    CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS OPERATOR,
    regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
    ethereum.public.udf_hex_to_int(segmented_data [0] :: STRING) AS id,
    ethereum.public.udf_hex_to_int(segmented_data [1] :: STRING) AS value_erc1155
    FROM
    polygon.core.fact_event_logs
    WHERE block_timestamp :: DATE > '2022-10-16' :: DATE
    Run a query to Download Data