You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATE MATERIALIZED VIEW IF NOT EXISTS logs_to_token_transfers TO token_transfers
53
+
(
54
+
`chain_id` UInt256,
55
+
`token_address` FixedString(42),
56
+
`from_address` String,
57
+
`to_address` String,
58
+
`token_type` String,
59
+
`block_number` UInt256,
60
+
`block_timestamp` DateTime,
61
+
`transaction_hash` FixedString(66),
62
+
`log_index` UInt64,
63
+
`sign` Int8,
64
+
`insert_timestamp` DateTime,
65
+
`token_id` UInt256,
66
+
`amount` UInt256
67
+
)
68
+
AS WITH
69
+
transfer_logs AS
70
+
(
71
+
SELECT
72
+
chain_id,
73
+
address AS token_address,
74
+
topic_0,
75
+
topic_1,
76
+
topic_2,
77
+
topic_3,
78
+
(topic_0 ='0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef') AND (topic_3 ='') AS is_erc20,
79
+
(topic_0 ='0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef') AND (topic_3 !='') AS is_erc721,
80
+
topic_0 IN ('0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', '0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb') AS is_erc1155,
81
+
multiIf(is_erc20, 'erc20', is_erc721, 'erc721', 'erc1155') AS token_type,
WHERE topic_0 IN ('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', '0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb')
93
+
),
94
+
batch_transfer_metadata AS
95
+
(
96
+
SELECT
97
+
*,
98
+
3+ (2*64) AS ids_length_idx,
99
+
ids_length_idx +64AS ids_values_idx,
100
+
reinterpretAsUInt64(reverse(unhex(substring(data, ids_length_idx, 64)))) AS ids_length,
101
+
(ids_length_idx +64) + (ids_length *64) AS amounts_length_idx,
102
+
reinterpretAsUInt64(reverse(unhex(substring(data, amounts_length_idx, 64)))) AS amounts_length,
103
+
amounts_length_idx +64AS amounts_values_idx
104
+
FROM transfer_logs
105
+
WHERE (topic_0 ='0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb') AND (length(topic_1) =66) AND (length(topic_2) =66) AND (length(topic_3) =66) AND (length(data) != (258+ ((ids_length + amounts_length) *64))) AND (ids_length = amounts_length)
multiIf(is_erc20 AND (length(data) =66), reinterpretAsUInt256(reverse(unhex(substring(data, 3)))), is_erc721, toUInt256(1), is_erc1155, if(length(data) =130, reinterpretAsUInt256(reverse(unhex(substring(data, 67, 64)))), toUInt256(1)), toUInt256(0)) AS amount
129
+
FROM transfer_logs
130
+
WHERE topic_0 IN ('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62')
131
+
UNION ALL
132
+
WITH
133
+
transfer_logs AS
134
+
(
135
+
SELECT
136
+
chain_id,
137
+
address AS token_address,
138
+
topic_0,
139
+
topic_1,
140
+
topic_2,
141
+
topic_3,
142
+
(topic_0 ='0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef') AND (topic_3 ='') AS is_erc20,
143
+
(topic_0 ='0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef') AND (topic_3 !='') AS is_erc721,
144
+
topic_0 IN ('0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', '0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb') AS is_erc1155,
145
+
multiIf(is_erc20, 'erc20', is_erc721, 'erc721', 'erc1155') AS token_type,
WHERE topic_0 IN ('0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef', '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62', '0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb')
157
+
),
158
+
batch_transfer_metadata AS
159
+
(
160
+
SELECT
161
+
*,
162
+
3+ (2*64) AS ids_length_idx,
163
+
ids_length_idx +64AS ids_values_idx,
164
+
reinterpretAsUInt64(reverse(unhex(substring(data, ids_length_idx, 64)))) AS ids_length,
165
+
(ids_length_idx +64) + (ids_length *64) AS amounts_length_idx,
166
+
reinterpretAsUInt64(reverse(unhex(substring(data, amounts_length_idx, 64)))) AS amounts_length,
167
+
amounts_length_idx +64AS amounts_values_idx
168
+
FROM transfer_logs
169
+
WHERE (topic_0 ='0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb') AND (length(topic_1) =66) AND (length(topic_2) =66) AND (length(topic_3) =66) AND (length(data) != (258+ ((ids_length + amounts_length) *64))) AND (ids_length = amounts_length)
0 commit comments