Query editor
/* Closed position events don't contain the goARB/ARB amounts, so we find the TX hash of these events and thensearch the ARB contract events that occurred in the same transaction to determine the amount of ARB paid */WITH closed_positions AS (SELECT-- block_time,-- bytearray_substring(topic1, 1 + 12, 20) as user,bytearray_to_uint256(bytearray_substring(data, 1 + 32, 32)) * 1e-18 as grai_collected,tx_hashFROM arbitrum.logsWHEREtopic0 = 0xc8469f8998427d0814b7efed804617bd8c43dfdfb3c6780d28a03ecf361fb698 -- PositionClosedAND contract_address = 0xec0f08bc015a0d0fba1df0b8b11d4779f5a04326 -- goARB management contractAND block_number >= 217745171 -- goARB deployed),/* Collection of all ARB transfers from the Dolomite margin contract, which is where the ARB payments are made from */arb_transfers AS (SELECTevt_tx_hash,value/1e18 AS arb_amountFROM erc20_arbitrum.evt_transferWHEREcontract_address = 0x912CE59144191C1204E64559FE8253a0e49E6548 -- ARB contractAND "from"=0x6Bd780E7fDf01D77e4d475c821f1e7AE05409072 -- DolomiteAND evt_block_number >= 217745171 -- goARB deployed)SELECTSUM(arb_amount) AS total_arb_paid,320_000 - SUM(arb_amount) AS arb_ltipp_remaining,SUM(grai_collected) AS total_grai_collectedFROM closed_positions cLEFT JOIN arb_transfers t ON c.tx_hash=t.evt_tx_hash