@@ -80,52 +80,56 @@ WHERE topic_0 = '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0
8080-- ERC1155 (batch)
8181CREATE MATERIALIZED VIEW IF NOT EXISTS token_transfers_erc1155_batch_mv
8282TO token_transfers
83- AS
84- SELECT
85- chain_id,
86- address AS token_address,
87- ' erc1155' AS token_type,
88- reinterpretAsUInt256(reverse(unhex(id_hex))) AS token_id,
89- concat(' 0x' , substring (topic_2, 27 , 40 )) AS from_address,
90- concat(' 0x' , substring (topic_3, 27 , 40 )) AS to_address,
83+ AS
84+ SELECT
85+ chain_id,
86+ address AS token_address,
87+ ' erc1155' AS token_type,
88+ reinterpretAsUInt256(reverse(substring (bin, (ids_base + ((i - 1 ) * 32 )) + 1 , 32 ))) AS token_id,
89+ concat(' 0x' , substring (topic_2, 27 , 40 )) AS from_address,
90+ concat(' 0x' , substring (topic_3, 27 , 40 )) AS to_address,
91+ block_number,
92+ block_timestamp,
93+ transaction_hash,
94+ transaction_index,
95+ reinterpretAsUInt256(reverse(substring (bin, (am_base + ((i - 1 ) * 32 )) + 1 , 32 ))) AS amount,
96+ log_index,
97+ toNullable(toUInt16(i - 1 )) AS batch_index,
98+ insert_timestamp,
99+ is_deleted
100+ FROM (
101+ SELECT
102+ chain_id,
103+ address,
104+ topic_2,
105+ topic_3,
91106 block_number,
92107 block_timestamp,
93108 transaction_hash,
94109 transaction_index,
95- reinterpretAsUInt256(reverse(unhex(amount_hex))) AS amount,
96110 log_index,
97- toNullable(toUInt16(array_index - 1 )) AS batch_index,
98- insert_timestamp,
99- is_deleted
100- FROM (
101- SELECT
102- chain_id,
103- address,
104- topic_2,
105- topic_3,
106- block_number,
107- block_timestamp,
108- transaction_hash,
109- transaction_index,
110- log_index,
111- is_deleted,
112- insert_timestamp,
113- toUInt32(reinterpretAsUInt256(reverse(unhex(substring (data, 3 , 64 ))))) AS ids_offset,
114- toUInt32(reinterpretAsUInt256(reverse(unhex(substring (data, 67 , 64 ))))) AS amounts_offset,
115- toUInt32(reinterpretAsUInt256(reverse(unhex(substring (data, 3 + ids_offset * 2 , 64 ))))) AS ids_length,
116- toUInt32(reinterpretAsUInt256(reverse(unhex(substring (data, 3 + amounts_offset * 2 , 64 ))))) AS amounts_length,
117- arrayMap(i - > substring (data, 3 + ids_offset * 2 + 64 + (i- 1 )* 64 , 64 ), range(1 , least(ids_length, 10000 ) + 1 )) AS ids_array,
118- arrayMap(i - > substring (data, 3 + amounts_offset * 2 + 64 + (i- 1 )* 64 , 64 ), range(1 , least(amounts_length, 10000 ) + 1 )) AS amounts_array
119- FROM logs
120- WHERE topic_0 = ' 0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb'
121- AND length(topic_2) = 66
122- AND length(topic_3) = 66
123- AND ids_length = amounts_length
124- )
125- ARRAY JOIN
126- ids_array AS id_hex,
127- amounts_array AS amount_hex,
128- arrayEnumerate(ids_array) AS array_index;
111+ is_deleted,
112+ insert_timestamp,
113+ unhex(substring (data, 3 )) AS bin,
114+ length(unhex(substring (data, 3 ))) AS bin_len,
115+ toUInt32(reinterpretAsUInt256(reverse(substring (unhex(substring (data, 3 )), 1 , 32 )))) AS ids_off,
116+ toUInt32(reinterpretAsUInt256(reverse(substring (unhex(substring (data, 3 )), 33 , 32 )))) AS am_off,
117+ toUInt32(reinterpretAsUInt256(reverse(substring (unhex(substring (data, 3 )), ids_off + 1 , 32 )))) AS ids_len,
118+ toUInt32(reinterpretAsUInt256(reverse(substring (unhex(substring (data, 3 )), am_off + 1 , 32 )))) AS am_len,
119+ ids_off + 32 AS ids_base,
120+ am_off + 32 AS am_base
121+ FROM default .logs
122+ WHERE (topic_0 = ' 0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb' )
123+ AND (length(topic_2) = 66 )
124+ AND (length(topic_3) = 66 )
125+ AND (ids_len = am_len)
126+ AND (ids_len > 0 )
127+ AND ((ids_off + 32 ) <= bin_len)
128+ AND ((am_off + 32 ) <= bin_len)
129+ AND ((ids_base + (ids_len * 32 )) <= bin_len)
130+ AND ((am_base + (am_len * 32 )) <= bin_len)
131+ ) ARRAY JOIN range(1 , ids_len + 1 ) AS i;
132+
129133
130134-- ERC6909
131135CREATE MATERIALIZED VIEW IF NOT EXISTS token_transfers_erc6909_mv
0 commit comments