Query editor
withwhirlpools as (withfee_updates as (SELECTip.account_whirlpool as whirlpool_id, ip.call_block_time as update_time, fee.defaultFeeRate as fee_tier --https://docs.orca.so/reference/trading-fees, should track protocol fees too. and rewards.FROM whirlpool_solana.whirlpool_call_initializePool ipLEFT JOIN whirlpool_solana.whirlpool_call_initializeFeeTier fee ON ip.account_feeTier = fee.account_feeTierUNION allSELECTaccount_whirlpool as whirlpool_id, call_block_time as update_time, feeRate as fee_tierFROM whirlpool_solana.whirlpool_call_setFeeRate)SELECTtkA.symbol as tokenA_symbol, tkA.decimals as tokenA_decimals, account_tokenMintA as tokenA, account_tokenVaultA as tokenAVault, tkB.symbol as tokenB_symbol, tkB.decimals as tokenB_decimals, account_tokenMintB as tokenB, account_tokenVaultB as tokenBVault, ip.tickSpacing, ip.account_whirlpool as whirlpool_id, fu.update_time, fu.fee_tier, ip.call_tx_id as init_txFROM whirlpool_solana.whirlpool_call_initializePool ipLEFT JOIN fee_updates fu ON fu.whirlpool_id = ip.account_whirlpoolLEFT JOIN tokens_solana.fungible tkA ON tkA.token_mint_address = ip.account_tokenMintALEFT JOIN tokens_solana.fungible tkB ON tkB.token_mint_address = ip.account_tokenMintBWHERE account_whirlpool = '7qbRF6YsyGuLUVs6Y1q64bdVrfe4ZcUUz1JRdoVNUJnm')SELECTsp.call_block_time, concat(COALESCE(tokenA_symbol, tokenA), '-', COALESCE(tokenB_symbol, tokenB)) as token_pair, case when sp.aToB = true then COALESCE(tokenB_symbol, tokenB)else COALESCE(tokenA_symbol, tokenA)end as token_bought_symbol--token bought is always the second instruction (transfer) in the inner instructions, bytearray_to_bigint(bytearray_reverse(bytearray_substring(frombase58(sp.call_inner_instructions[2].data), 2, 8)))/COALESCE(pow(10,case when sp.aToB = true then wp.tokenB_decimals else tokenA_decimals end),1)as token_bought_amount, case when sp.aToB = true then tokenA_symbolelse tokenB_symbolend as token_sold_symbol, bytearray_to_bigint(