Query editor
with all_data as (selecttx_hash,contract_address as rewarder,block_time,bytearray_to_uint256(bytearray_substring(data, 1, 32)) as rewardPerSecond,bytearray_to_uint256(bytearray_substring(data, 1 + 32, 32)) as startTimestamp,bytearray_to_uint256(bytearray_substring(data, 1 + 2 * 32, 32)) as endTimestampfrom avalanche_c.logswhere topic0 = 0xf0b276e9ee40b3a3d065f636ee656c9bf1c9a0c4060fb212fd0861890c107be5and contract_address in (0xD3BD880FDcA136244Ec6eF2F6474970CCe455Cb1,0xBC1d61C438e87e576e3f3CeA1A2c52099c3eD23e,0x3D4FE3e0E6E0BA31Df39961EAA0d9eA1ecA17396-- 0x77EA2c416E53a203952a2841c6715e698AD1B7d7,)),all_transfers as (selecttx_hash,block_time,"to" as rewarder,amount_rawfrom tokens.transferswhere blockchain = 'avalanche_c'and contract_address = 0x0000000000000000000000000000000000000000and "to" in (0xD3BD880FDcA136244Ec6eF2F6474970CCe455Cb1,0xBC1d61C438e87e576e3f3CeA1A2c52099c3eD23e,0x3D4FE3e0E6E0BA31Df39961EAA0d9eA1ecA17396-- 0x77EA2c416E53a203952a2841c6715e698AD1B7d7,)),with_next as (selecta.*,lead(startTimestamp) over (partition by rewarderorder by startTimestamp) as nextStartTimestampfrom all_data a),with_rewards as (select*,/* edge case: if rewards ended before the next schedule starts, use endTimestamp (gap).otherwise, if nextStart exists and is earlier than endTimestamp, use nextStart (overwrite). */casewhen nextStartTimestamp is null then endTimestampelse least(endTimestamp, nextStartTimestamp)end as effectiveEndTimestamp,greatest(cast((casewhen nextStartTimestamp is null then endTimestampelse least(endTimestamp, nextStartTimestamp)end) - startTimestamp