Query editor
WITH extracted AS (SELECTt.block_time AS block_time,t.tx_hash AS transaction_hash,t."from" AS buyer,t.input AS input_data,-- Extract the function selectorVARBINARY_SUBSTRING(t.input, 1, 4) AS function_selector,-- Common parameters for the functionVARBINARY_TO_UINT256(VARBINARY_SUBSTRING(t.input, 5, 32)) AS offset_tierId,VARBINARY_TO_UINT256(VARBINARY_SUBSTRING(t.input, 37, 32)) AS nodes_purchased,-- Extract code address from position 101 (bytes 101-132)VARBINARY_SUBSTRING(t.input, 101, 32) AS code_address_rawFROM arbitrum.traces AS tJOIN arbitrum.transactions AS tx ON t.tx_hash = tx.hashWHEREtx.success = true -- Include only successful transactionsAND t."to" = 0x23d73C47AddC85dcDCE321736b12078fafD88640 -- Contract address for ArbitrumAND VARBINARY_STARTS_WITH(t.input, 0x38b05423) -- Only `whitelistedPurchaseInTierWithWalletCode`),tierid_extracted AS (SELECT*,-- Safely extract `tierID`CASEWHEN offset_tierId IS NOT NULLAND CAST(offset_tierId + 37 AS BIGINT) <= LENGTH(input_data)THEN FROM_UTF8(VARBINARY_SUBSTRING(input_data,CAST(offset_tierId + 37 AS BIGINT),LEAST(CAST(VARBINARY_TO_UINT256(VARBINARY_SUBSTRING(input_data,CAST(offset_tierId + 5 AS BIGINT),32)) AS BIGINT),LENGTH(input_data) - (CAST(offset_tierId + 37 AS BIGINT) - 1))))ELSE NULLEND AS tierIDFROM extracted),code_extracted AS (SELECT*,-- Extract the code (wallet address) from `code_address_raw`'0x' || LOWER(TO_HEX(VARBINARY_SUBSTRING(code_address_raw, 13, 20))) AS with_code,-- Determine if a promo code was usedCASEWHEN code_address_raw IS NOT NULL THEN 'yes'ELSE 'no'END AS use_codeFROM tierid_extracted