Advertisement
Noordle

Untitled

Oct 30th, 2024
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 3.58 KB | None | 0 0
  1. SELECT
  2.     dictGet('d_addresses_2', 'name', coin) AS coin,
  3.     argMax(price, block_number) AS max_price,
  4.     argMin(price, block_number) AS min_price,
  5.     MAX(block_number) AS max_blck,
  6.     MIN(block_number) AS min_blck,
  7.     max_price - min_price AS delta,
  8.     argMin(TRANSACTION, block_number) AS first_trx,
  9.         argMax(TRANSACTION, block_number) AS last_trx
  10.     FROM (
  11.          SELECT any(transaction_hash) AS TRANSACTION,
  12.                 block_number,
  13.                 argMaxIf(address_id, log_index,
  14.                          arrayElement(topics, 1) =
  15.                          '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' AND
  16.                          address_id != 7255236872428775134)              AS coin,
  17.  
  18.                 arrayElement(reserves_0_1, coin_pos) / arrayElement(reserves_0_1, eth_pos)      AS price,
  19.  
  20.                 IF(arrayElement(swap_arr_decoded, 1) = last_eth_wad[1] OR
  21.                    arrayElement(swap_arr_decoded, 3) = last_eth_wad[1],
  22.                    1, 2)                                                                       AS eth_pos,
  23.                 eth_pos = 1 ? 2 : 1                                                            AS coin_pos,
  24.  
  25.                 arrayMap(x -> reinterpretAsUInt128(reverse(unhex(x))), sync_arr)               AS reserves_0_1,
  26.                 array(
  27.                         SUBSTRING(SUBSTRING(sync_data, 3), 1, 64),
  28.                         SUBSTRING(SUBSTRING(sync_data, 3), 65, 64)
  29.                 )                                                                              AS sync_arr,
  30.                 argMaxIf(DATA, log_index,
  31.                          arrayElement(topics, 1) =
  32.                          '0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1') AS sync_data,
  33.  
  34.  
  35.                 arrayMap(x -> reinterpretAsUInt128(reverse(unhex(x))), transfer_eth_arr)       AS last_eth_wad,
  36.                 array(
  37.                         SUBSTRING(SUBSTRING(transfer_eth_data, 3), 1, 64)
  38.                 )                                                                              AS transfer_eth_arr,
  39.                 argMaxIf(DATA, log_index,
  40.                          arrayElement(topics, 1) =
  41.                          '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' AND
  42.                          address_id = 7255236872428775134)               AS transfer_eth_data,
  43.  
  44.  
  45.                 arrayMap(x -> reinterpretAsUInt128(reverse(unhex(x))), swap_arr)               AS swap_arr_decoded,
  46.                 array(
  47.                         SUBSTRING(SUBSTRING(swap_data, 3), 1, 64),
  48.                         SUBSTRING(SUBSTRING(swap_data, 3), 65, 64),
  49.                         SUBSTRING(SUBSTRING(swap_data, 3), 129, 64),
  50.                         SUBSTRING(SUBSTRING(swap_data, 3), 193, 64)
  51.                 )                                                                              AS swap_arr,
  52.                 argMaxIf(DATA, log_index,
  53.                          arrayElement(topics, 1) =
  54.                          '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822') AS swap_data
  55.          FROM etherium_logs_new
  56.          prewhere block_number BETWEEN 20406885 AND 20460000
  57.          GROUP BY block_number, transaction_index
  58.          ORDER BY block_number, transaction_index
  59.         ) AS sub
  60. WHERE NOT isNaN(price)
  61. GROUP BY coin
  62. HAVING delta > 0
  63. ORDER BY delta DESC;
  64.  
  65.  
  66. CREATE TABLE trxs_5 engine = Log AS
  67. SELECT DISTINCT block_number, transaction_index FROM etherium_logs_new
  68. WHERE block_number BETWEEN 20406885 AND 20414095 AND address_id = 7255236872428775134;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement