Query editor
WITH operates AS (SELECTblock_time,tx_id,varbinary_to_int256(bytearray_reverse(bytearray_substring(data, 9, 16))) as supply_raw,varbinary_to_int256(bytearray_reverse(bytearray_substring(data, 25, 16))) as borrow_raw,varbinary_to_bigint(bytearray_substring(bytearray_reverse(bytearray_substring(data, 9, 16)), 1, 1)) >= 128 as supply_neg,varbinary_to_bigint(bytearray_substring(bytearray_reverse(bytearray_substring(data, 25, 16)), 1, 1)) >= 128 as borrow_neg,account_arguments[4] as token_mintFROM solana.instruction_callsWHERE executing_account = 'jupeiUmn818Jg1ekPURTpr4mFo29p46vygyykFJ3wZC'AND bytearray_substring(data, 1, 8) = 0xd96ad06374972a87 -- operateAND tx_success),two128 AS (SELECT varbinary_to_int256(from_hex('0x0100000000000000000000000000000000')) AS two128),amounts AS (SELECTblock_time,token_mint,CAST(CASE WHEN supply_neg THEN supply_raw - two128.two128 ELSE supply_raw END AS DOUBLE) as supply_amount,CAST(CASE WHEN borrow_neg THEN borrow_raw - two128.two128 ELSE borrow_raw END AS DOUBLE) as borrow_amountFROM operates, two128),adjusted AS (SELECTDATE(block_time) as date,token_mint,SUM(supply_amount / POW(10, tf.decimals)) as daily_supply_change,SUM(borrow_amount / POW(10, tf.decimals)) as daily_borrow_changeFROM amounts aJOIN tokens_solana.fungible tf ON a.token_mint = tf.token_mint_addressGROUP BY 1, 2),prices AS (SELECTDATE_TRUNC('day', hour) as date,contract_address,MIN(price) as priceFROM dex_solana.price_hourGROUP BY 1, 2)SELECTa.date,SUM(SUM(daily_supply_change * price)) OVER (ORDER BY a.date) as total_supply_usd,SUM(SUM(daily_borrow_change * price)) OVER (ORDER BY a.date) as active_borrow_usdFROM adjusted aJOIN prices p ON a.date = p.date AND a.token_mint = p.contract_addressGROUP BY 1ORDER BY 1 DESC;