Query editor
WITH token_decimals as (SELECTraised_token_name, raised_token_decimal, project_token_decimal, lbp_contract, chain, timestamp_start, timestamp_endFROMquery_3351887WHEREproject = '{{Protocol}}'), PRICES AS (SELECT*FROMprices.usd_latestleft join token_decimals on 1=1wherelower(blockchain) = lower(chain)), purchases as (SELECTcasewhen topic0 = 0xbeae048c6d270d9469f86cf6e8fedda3c60ad770f16c24c9fc131c8e9a09101d then 'buy'when topic0 = 0x846c37eef631e0943682d87352ec117c20008eb7f425c9b85ac011a6d4774cc0 then 'sell'else 'unknown'end as label, block_time, bytearray_ltrim (topic1) as user, casewhen topic0 = 0xbeae048c6d270d9469f86cf6e8fedda3c60ad770f16c24c9fc131c8e9a09101d then bytearray_to_uint256 (bytearray_substring (data, 1, 32)) / raised_token_decimalwhen topic0 = 0x846c37eef631e0943682d87352ec117c20008eb7f425c9b85ac011a6d4774cc0 then bytearray_to_uint256 (bytearray_substring (data, 33, 32)) / raised_token_decimalelse 0end as token_amount, casewhen topic0 = 0xbeae048c6d270d9469f86cf6e8fedda3c60ad770f16c24c9fc131c8e9a09101d then bytearray_to_uint256 (bytearray_substring (data, 33, 32)) / project_token_decimalwhen topic0 = 0x846c37eef631e0943682d87352ec117c20008eb7f425c9b85ac011a6d4774cc0 then bytearray_to_uint256 (bytearray_substring (data, 1, 32)) / project_token_decimalelse 0end as shares_amount, bytearray_to_uint256 (bytearray_substring (data, 65, 32)) / raised_token_decimal as fee_amount, tx_hash, raised_token_nameFROMethereum.logsleft join token_decimals td on td.chain = 'ethereum'WHEREcontract_address = lbp_contract -- LiquidityBootstrapPooland block_time > timestamp_startand block_time < timestamp_endand topic0 in (0xbeae048c6d270d9469f86cf6e8fedda3c60ad770f16c24c9fc131c8e9a09101d -- Buy (address buyer, uint256 value, uint256 soldToken, uint256 valueTokenInUsdWei), 0x846c37eef631e0943682d87352ec117c20008eb7f425c9b85ac011a6d4774cc0 -- Sell (address sender, uint256 tokens, uint256 cursETHtoUSD, uint256 costUSD))UNION ALLSELECT