Query editor
with pools as (selectaccount_custodyTokenMint,account_custody,account_custodyTokenAccount,case when account_custodyTokenMint = 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB' then 'USDT'when account_custodyTokenMint = 'So11111111111111111111111111111111111111112' then 'SOL'when account_custodyTokenMint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' then 'USDC'when account_custodyTokenMint = '7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs' then 'WETH'when account_custodyTokenMint = '3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh' then 'WBTC'end as symbolfrom jupiter_solana.perpetuals_call_addCustody),bal as (selectblock_date,address,account_custody,token_mint_address,a.symbol,post_token_balance,p.price,post_token_balance*p.price/sum(post_token_balance*p.price) over(partition by block_date) as weightfrom (selectblock_date,address,p.symbol,token_mint_address,account_custody,post_token_balance,row_number() over(partition by address,token_mint_address,block_date order by block_time) as daily_recfrom solana.account_activity ajoin pools p on p.account_custodyTokenAccount = a.address AND p.account_custodyTokenMint = a.token_mint_addresswhere tx_success = trueand token_mint_address is not nulland block_date + interval'30' day >= current_date) aleft join prices.usd p ON p.blockchain = 'solana' and toBase58(p.contract_address) = a.token_mint_address and a.block_date = p.minutewhere daily_rec = 1), interm as (SELECTblock_date, bytearray_to_bigint(bytearray_reverse(bytearray_substring(data,1+16+32,1))) as position_side --1 is long, 2 is short, 'increase' AS position_change, to_base58(bytearray_substring(data,1+227,32)) as owner, to_base58(bytearray_substring(data,1+16,32)) as position_key, to_base58(bytearray_substring(data,1+16+32+1,32)) as custody_position_key --ties to the token mint of long or short token, to_base58(bytearray_substring(data,1+16+32+1+32,32)) as custody_collateral_key --ties to the token mint of the collateral token, bytearray_to_bigint(bytearray_reverse(bytearray_substring(data,1+291,8))) / 1e6 as size_usd --this is the levered size delta (change)FROM solana.instruction_callsWHERE executing_account = 'PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu'AND bytearray_substring(data,1+8,8) = 0xf5715534d6bb9984 -- IncreasePositionAND tx_success = trueUNION ALL