Query editor
-- check how/if insuranceCover affects amount/amountQuote once there is an instance-- check how spread liquidations are represented under amountQuote-- *check if the 0.001003886464609938 amountQuote liquidated is an anomaly for the productWITH all_days AS ( SELECT * FROM UNNEST(SEQUENCE(TIMESTAMP '2023-04-26', CAST(NOW() AS TIMESTAMP), INTERVAL '1' DAY)) AS ad("date") ),raw_liqs AS(SELECT block_time,topic1 AS liquidatorSubaccount,topic2 AS liquidateeSubaccount,--BYTEARRAY_TO_UINT256(BYTEARRAY_SUBSTRING(topic3, 1, 32)) AS mode,--BYTEARRAY_TO_UINT256(BYTEARRAY_SUBSTRING(data, 1, 32)) AS healthGroup,--BYTEARRAY_TO_INT256(BYTEARRAY_SUBSTRING(data, 1 + 32, 32)) AS amount,BYTEARRAY_TO_INT256(BYTEARRAY_SUBSTRING(data, 1 + 32 * 2, 32))/1e18 AS amountQuote--BYTEARRAY_TO_INT256(BYTEARRAY_SUBSTRING(data, 1 + 32 * 3, 32)) AS insuranceCoverFROM arbitrum.logsWHERE topic0 = 0xf96988bb67b73fa61d64c48dc2e91ae6b697ebb8c5a496d238309aa20fbf6458 -- evt_Liquidation (pre-Edge)UNION ALLSELECT block_time,topic1 AS liquidatorSubaccount,topic2 AS liquidateeSubaccount,--BYTEARRAY_TO_UINT256(BYTEARRAY_SUBSTRING(data, 1, 32)) AS productId,--BYTEARRAY_SUBSTRING(data, 1 + 32, 32) AS isEncodedSpread,--BYTEARRAY_TO_INT256(BYTEARRAY_SUBSTRING(data, 1 + 32 * 2, 32)) AS amount,BYTEARRAY_TO_INT256(BYTEARRAY_SUBSTRING(data, 1 + 32 * 3, 32))/1e18 AS amountQuoteFROM arbitrum.logsWHERE topic0 = 0x494f937f5cc892f798248aa831acfb4ad7c4bf35edd8498c5fb431ce1e38b035 -- evt_Liquidation (post-Edge)),liq_across_timeframes AS(SELECT SUM(IF(amountQuote < 0, -amountQuote, amountQuote)) FILTER (WHERE block_time > NOW() - INTERVAL '1' DAY) AS past_24hr_liq,SUM(IF(amountQuote < 0, -amountQuote, amountQuote)) FILTER (WHERE block_time > NOW() - INTERVAL '7' DAY) AS past_7d_liq,SUM(IF(amountQuote < 0, -amountQuote, amountQuote)) FILTER (WHERE block_time >= TIMESTAMP '2023-04-26') AS all_time_liqFROM raw_liqs)SELECT *FROM (SELECT ad."date",COALESCE(SUM(rl.amountQuote) FILTER (WHERE rl.amountQuote > 0), 0) AS longs_liq,COALESCE(SUM(rl.amountQuote) FILTER (WHERE rl.amountQuote < 0), 0) AS shorts_liq,COALESCE(SUM(rl.amountQuote), 0) AS sum_liqFROM raw_liqs rlRIGHT JOIN all_days adON date_trunc('day', rl.block_time) = ad."date"GROUP BY 1), liq_across_timeframes latORDER BY 1 DESC/*SELECT block_time,tx_hash,BYTEARRAY_LTRIM(topic3) AS mode, -- the liquidation mode (0 = Spread; 1 = Spot; 2 = Perp)BYTEARRAY_SUBSTRING(data, 1, 32) AS healthGroup, -- specifying the spot/perp pair to target for liquidation (0 = BTC and BTC-PERP; 1 = ETH and ETH-PERP)BYTEARRAY_TO_INT256(BYTEARRAY_SUBSTRING(data, 1 + 32, 32)) AS amount, -- amount that was liquidated (liquidatee --> liquidator), can be +ve or -ve, depending on if the user’s balance is +ve or -veBYTEARRAY_TO_INT256(BYTEARRAY_SUBSTRING(data, 1 + 32 * 2, 32)) AS amountQuote, --this is the amount of product transferred from liquidatee to liquidator; this and the following field will have the same sign. if spread, one unit represents one long spot and one short perp i.e. if amount == -1, it means a short spot and a long perp was liquidatedBYTEARRAY_TO_INT256(BYTEARRAY_SUBSTRING(data, 1 + 32 * 3, 32)) AS insuranceCover, -- whether USDC from the insurance fund is pulled into the insolvent account and used to pay liquidators to take on the underwater positionstopic1 AS liquidatorSubaccount,topic2 AS liquidateeSubaccount