File size: 17,257 Bytes
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
 
 
 
 
 
 
281bada
858826c
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
CREATE TABLE IF NOT EXISTS trades
(
    timestamp           DateTime('UTC'),
    signature           String,

    slot                UInt64,
    transaction_index   UInt32,
    instruction_index   UInt16,
    success             Boolean,              
    error               Nullable(String),

    -- Fee Structure
    priority_fee        Float64,
    bribe_fee           Float64,
    coin_creator_fee    Float64,
    mev_protection      UInt8,

    -- Parties
    maker               String,

    -- Balances (Pre & Post)
    base_balance    Float64,

    
    quote_balance   Float64,


    -- Trade Semantics
    trade_type          UInt8,
    protocol            UInt8,
    platform            UInt8,

    -- Asset Info
    pool_address        String,
    base_address        String,
    quote_address       String,

    -- Trade Details
    slippage            Float32,
    price_impact        Float32,

    base_amount         UInt64,
    quote_amount        UInt64,

    price               Float64,
    price_usd           Float64,

    total               Float64,
    total_usd           Float64

)
ENGINE = MergeTree()
ORDER BY (base_address, timestamp, maker, signature);

--- mint
CREATE TABLE IF NOT EXISTS mints
(
    -- === Transaction Details ===
    -- Solana signature is usually 88 characters, but we use String for flexibility.
    signature String,
    -- Converted to DateTime for easier time-based operations in ClickHouse.
    timestamp DateTime('UTC'),
    slot UInt64,
    success Boolean,
    error Nullable(String),
    priority_fee Float64,

    -- === Protocol & Platform ===
    -- Protocol codes: 0=Unknown, 1=PumpFunLaunchpad, 2=RaydiumLaunchpad,
    -- 3=PumpFunAMM, 4=RaydiumCPMM, 5=MeteoraBonding
    protocol UInt8,

    -- === Mint & Pool Details ===
    mint_address String,
    creator_address String,
    pool_address String,

    -- === Liquidity Details ===
    initial_base_liquidity UInt64,
    initial_quote_liquidity UInt64,

    -- === Token Metadata ===
    token_name Nullable(String),
    token_symbol Nullable(String),
    token_uri Nullable(String),
    token_decimals UInt8,
    total_supply UInt64,

    is_mutable                              Boolean,
    update_authority                        Nullable(String),
    mint_authority                          Nullable(String),
    freeze_authority                        Nullable(String),

)
ENGINE = MergeTree() 
ORDER BY (timestamp, creator_address, mint_address);

CREATE TABLE IF NOT EXISTS migrations
(
    -- Transaction Details
    timestamp           DateTime('UTC'),
 
    signature String,
    slot UInt64,
    success Boolean,
    error Nullable(String),
    priority_fee Float64,

    -- Protocol & Platform
    protocol UInt8,

    -- Migration Details
    mint_address String,
    virtual_pool_address String,
    pool_address String,
    
    -- Liquidity Details
    migrated_base_liquidity Nullable(UInt64),
    migrated_quote_liquidity Nullable(UInt64)
)
ENGINE = MergeTree()
ORDER BY (mint_address, virtual_pool_address, pool_address, timestamp);

CREATE TABLE IF NOT EXISTS fee_collections
(
    -- Transaction Details
    timestamp           DateTime('UTC'),
    
    signature String,
    slot UInt64,
    success Boolean,
    error Nullable(String),
    priority_fee Float64,

    -- Protocol & Platform
    protocol UInt8,

    -- Fee Details
    vault_address String,
    recipient_address String,

    -- Collected Amounts
    token_0_mint_address String,
    token_0_amount  Float64,
    token_1_mint_address Nullable(String),
    token_1_amount Nullable(Float64)
)
ENGINE = MergeTree()
ORDER BY (vault_address, recipient_address, timestamp);

CREATE TABLE IF NOT EXISTS liquidity
(
      -- Transaction Details --
    signature String,
    timestamp DateTime('UTC'),
    slot UInt64,
    success Boolean,
    error Nullable(String),
    priority_fee Float64,

    -- Protocol Info --
    protocol UInt8,

    -- LP Action Details --
    change_type UInt8,
    lp_provider String,
    pool_address String,

    -- Token Amounts --
    base_amount UInt64,
    quote_amount UInt64
)
ENGINE = MergeTree()
ORDER BY (timestamp, pool_address, lp_provider);

CREATE TABLE IF NOT EXISTS pool_creations (
    -- Transaction Details --
    signature String,
    timestamp Datetime('UTC'),
    slot UInt64,
    success Boolean,
    error Nullable(String),
    priority_fee Float64,

    -- Protocol Info --
    protocol UInt8,

    -- Pool & Token Details --
    creator_address String,
    pool_address String,
    base_address String,
    quote_address String,
    lp_token_address String,

    -- Optional Initial State --
    initial_base_liquidity Nullable(UInt64),
    initial_quote_liquidity Nullable(UInt64),
    base_decimals Nullable(UInt8),
    quote_decimals Nullable(UInt8)
)
ENGINE = MergeTree()
ORDER BY (base_address, creator_address);

CREATE TABLE IF NOT EXISTS transfers
(
    -- Transaction Details
    timestamp           DateTime('UTC'),
    signature String,
    slot UInt64,
    success Boolean,
    error Nullable(String),
    priority_fee Float64,

    -- Transfer Details
    source String,
    destination String,

    -- Amount & Mint Details
    mint_address String, 
    amount UInt64,
    amount_decimal Float64,

    -- Balance Context ===
    source_balance Float64,
    destination_balance Float64
)
ENGINE = MergeTree()
ORDER BY (source, destination, mint_address, timestamp);

CREATE TABLE IF NOT EXISTS supply_locks
(
    -- === Transaction Details ===
    timestamp           DateTime('UTC'),

    signature String,
    slot UInt64,
    success Boolean, 
    error Nullable(String),
    priority_fee Float64,

    -- === Protocol Info ===
    protocol UInt8,

    -- === Vesting Details ===
    contract_address String,
    sender String,
    recipient String,
    mint_address String,
    total_locked_amount     Float64,
    final_unlock_timestamp  UInt64
)
ENGINE = MergeTree()
ORDER BY (timestamp, mint_address, sender, recipient);

CREATE TABLE IF NOT EXISTS supply_lock_actions
(
    -- === Transaction Details ===
 
    signature String,
    timestamp           DateTime('UTC'),
    slot UInt64,
    success     Boolean, 
    error Nullable(String),
    priority_fee Float64,

    -- === Protocol Info ===
    protocol UInt8,

    -- === Action Details ===
    action_type UInt8, -- e.g., 0 for Withdraw, 1 for Topup
    contract_address String,
    user String,
    mint_address String,
    amount Float64
)
ENGINE = MergeTree()
ORDER BY (timestamp, mint_address, user);

CREATE TABLE IF NOT EXISTS burns
(
    -- Transaction Details
    timestamp DateTime('UTC'),
    signature String,
    slot UInt64,
    success Boolean,
    error Nullable(String),
    priority_fee Float64,

    -- Burn Details
    mint_address String,
    source String,
    amount UInt64,
    amount_decimal Float64,

    source_balance Float64
)
ENGINE = MergeTree()
ORDER BY (mint_address, source, timestamp);

-------- Wallet schema

CREATE TABLE IF NOT EXISTS wallet_profiles
(
    updated_at DateTime('UTC'),
    first_seen_ts DateTime('UTC'),
    last_seen_ts DateTime('UTC'),

    wallet_address                  String,
    tags                            Array(String),
    deployed_tokens                 Array(String),

    funded_from                     String,
    funded_timestamp                UInt32,
    funded_signature                String,
    funded_amount                   Float64
)
ENGINE = ReplacingMergeTree(updated_at)
PRIMARY KEY (wallet_address)
ORDER BY (wallet_address);

CREATE TABLE IF NOT EXISTS wallet_profile_metrics
(
    updated_at DateTime('UTC'),
    wallet_address                  String,
    balance                         Float64,

    transfers_in_count              UInt32,
    transfers_out_count             UInt32,
    spl_transfers_in_count          UInt32,
    spl_transfers_out_count         UInt32,

    total_buys_count                UInt32,
    total_sells_count               UInt32,
    total_winrate                   Float32,

    stats_1d_realized_profit_sol    Float64,
    stats_1d_realized_profit_usd    Float64,
    stats_1d_realized_profit_pnl    Float32,
    stats_1d_buy_count              UInt32,
    stats_1d_sell_count             UInt32,
    stats_1d_transfer_in_count      UInt32,
    stats_1d_transfer_out_count     UInt32,
    stats_1d_avg_holding_period     Float32,
    stats_1d_total_bought_cost_sol  Float64,
    stats_1d_total_bought_cost_usd  Float64,
    stats_1d_total_sold_income_sol  Float64,
    stats_1d_total_sold_income_usd  Float64,
    stats_1d_total_fee              Float64,
    stats_1d_winrate                Float32,
    stats_1d_tokens_traded          UInt32,

    stats_7d_realized_profit_sol    Float64,
    stats_7d_realized_profit_usd    Float64,
    stats_7d_realized_profit_pnl    Float32,
    stats_7d_buy_count              UInt32,
    stats_7d_sell_count             UInt32,
    stats_7d_transfer_in_count      UInt32,
    stats_7d_transfer_out_count     UInt32,
    stats_7d_avg_holding_period     Float32,
    stats_7d_total_bought_cost_sol  Float64,
    stats_7d_total_bought_cost_usd  Float64,
    stats_7d_total_sold_income_sol  Float64,
    stats_7d_total_sold_income_usd  Float64,
    stats_7d_total_fee              Float64,
    stats_7d_winrate                Float32,
    stats_7d_tokens_traded          UInt32,

    stats_30d_realized_profit_sol   Float64,
    stats_30d_realized_profit_usd   Float64,
    stats_30d_realized_profit_pnl   Float32,
    stats_30d_buy_count             UInt32,
    stats_30d_sell_count            UInt32,
    stats_30d_transfer_in_count     UInt32,
    stats_30d_transfer_out_count    UInt32,
    stats_30d_avg_holding_period    Float32,
    stats_30d_total_bought_cost_sol Float64,
    stats_30d_total_bought_cost_usd Float64,
    stats_30d_total_sold_income_sol Float64,
    stats_30d_total_sold_income_usd Float64,
    stats_30d_total_fee             Float64,
    stats_30d_winrate               Float32,
    stats_30d_tokens_traded         UInt32
)
ENGINE = MergeTree
ORDER BY (wallet_address, updated_at);

CREATE TABLE IF NOT EXISTS wallet_holdings
(
    updated_at DateTime('UTC'),
    start_holding_at DateTime('UTC'),

    wallet_address                  String,
    mint_address                    String,
    current_balance                 Float64,

    realized_profit_pnl             Float32,
    realized_profit_sol             Float64,
    realized_profit_usd             Float64,

    history_transfer_in             UInt32,
    history_transfer_out            UInt32,

    history_bought_amount           Float64,
    history_bought_cost_sol         Float64,
    history_sold_amount             Float64,
    history_sold_income_sol         Float64
)
ENGINE = MergeTree
ORDER BY (wallet_address, mint_address, updated_at);

CREATE TABLE IF NOT EXISTS tokens (
    updated_at DateTime('UTC'),
    created_at DateTime('UTC'),

    -- Core Identifiers
    token_address           String,
    name                    String,
    symbol                  String,
    token_uri               String,

    -- Token Metadata
    decimals                UInt8,
    creator_address         String,
    pool_addresses          Array(String), -- Map Vec<String> to Array(String)

    -- Protocol/Launchpad
    launchpad               UInt8,
    protocol                UInt8,
    total_supply            UInt64,

    -- Authorities/Flags
    is_mutable              Boolean, -- Alias for UInt8, but Boolean is clearer/modern
    update_authority        Nullable(String), -- Map Option<String> to Nullable(String)
    mint_authority          Nullable(String),
    freeze_authority        Nullable(String)
)
ENGINE = ReplacingMergeTree(updated_at)
PRIMARY KEY (token_address)
ORDER BY (token_address, updated_at);

-- Latest tokens (one row per token_address)
CREATE TABLE IF NOT EXISTS tokens_latest
(
    updated_at DateTime('UTC'),
    created_at DateTime('UTC'),

    token_address           String,
    name                    String,
    symbol                  String,
    token_uri               String,

    decimals                UInt8,
    creator_address         String,
    pool_addresses          Array(String),

    launchpad               UInt8,
    protocol                UInt8,
    total_supply            UInt64,

    is_mutable              Boolean,
    update_authority        Nullable(String),
    mint_authority          Nullable(String),
    freeze_authority        Nullable(String)
)
ENGINE = ReplacingMergeTree(updated_at)
ORDER BY (token_address);

CREATE TABLE IF NOT EXISTS token_metrics (
    updated_at DateTime('UTC'),
    token_address           String,
    total_volume_usd        Float64,
    total_buys              UInt32,
    total_sells             UInt32,
    unique_holders          UInt32,
    ath_price_usd           Float64
)
ENGINE = MergeTree
ORDER BY (token_address, updated_at);



-- ========= Latest snapshot helper tables =========
-- Keep full history in the base tables above, but read fast from these ReplacingMergeTree snapshots.

-- Latest wallet profile metrics (one row per wallet_address)
CREATE TABLE IF NOT EXISTS wallet_profile_metrics_latest
(
    updated_at DateTime('UTC'),
    wallet_address                  String,
    balance                         Float64,

    transfers_in_count              UInt32,
    transfers_out_count             UInt32,
    spl_transfers_in_count          UInt32,
    spl_transfers_out_count         UInt32,

    total_buys_count                UInt32,
    total_sells_count               UInt32,
    total_winrate                   Float32,

    stats_1d_realized_profit_sol    Float64,
    stats_1d_realized_profit_usd    Float64,
    stats_1d_realized_profit_pnl    Float32,
    stats_1d_buy_count              UInt32,
    stats_1d_sell_count             UInt32,
    stats_1d_transfer_in_count      UInt32,
    stats_1d_transfer_out_count     UInt32,
    stats_1d_avg_holding_period     Float32,
    stats_1d_total_bought_cost_sol  Float64,
    stats_1d_total_bought_cost_usd  Float64,
    stats_1d_total_sold_income_sol  Float64,
    stats_1d_total_sold_income_usd  Float64,
    stats_1d_total_fee              Float64,
    stats_1d_winrate                Float32,
    stats_1d_tokens_traded          UInt32,

    stats_7d_realized_profit_sol    Float64,
    stats_7d_realized_profit_usd    Float64,
    stats_7d_realized_profit_pnl    Float32,
    stats_7d_buy_count              UInt32,
    stats_7d_sell_count             UInt32,
    stats_7d_transfer_in_count      UInt32,
    stats_7d_transfer_out_count     UInt32,
    stats_7d_avg_holding_period     Float32,
    stats_7d_total_bought_cost_sol  Float64,
    stats_7d_total_bought_cost_usd  Float64,
    stats_7d_total_sold_income_sol  Float64,
    stats_7d_total_sold_income_usd  Float64,
    stats_7d_total_fee              Float64,
    stats_7d_winrate                Float32,
    stats_7d_tokens_traded          UInt32,

    stats_30d_realized_profit_sol   Float64,
    stats_30d_realized_profit_usd   Float64,
    stats_30d_realized_profit_pnl   Float32,
    stats_30d_buy_count             UInt32,
    stats_30d_sell_count            UInt32,
    stats_30d_transfer_in_count     UInt32,
    stats_30d_transfer_out_count    UInt32,
    stats_30d_avg_holding_period    Float32,
    stats_30d_total_bought_cost_sol Float64,
    stats_30d_total_bought_cost_usd Float64,
    stats_30d_total_sold_income_sol Float64,
    stats_30d_total_sold_income_usd Float64,
    stats_30d_total_fee             Float64,
    stats_30d_winrate               Float32,
    stats_30d_tokens_traded         UInt32
)
ENGINE = ReplacingMergeTree(updated_at)
ORDER BY (wallet_address);

-- Latest wallet holdings (one row per wallet_address + mint_address)
CREATE TABLE IF NOT EXISTS wallet_holdings_latest
(
    updated_at DateTime('UTC'),
    start_holding_at DateTime('UTC'),

    wallet_address                  String,
    mint_address                    String,
    current_balance                 Float64,

    realized_profit_pnl             Float32,
    realized_profit_sol             Float64,
    realized_profit_usd             Float64,

    history_transfer_in             UInt32,
    history_transfer_out            UInt32,

    history_bought_amount           Float64,
    history_bought_cost_sol         Float64,
    history_sold_amount             Float64,
    history_sold_income_sol         Float64
)
ENGINE = ReplacingMergeTree(updated_at)
ORDER BY (wallet_address, mint_address);

-- Latest token metrics (one row per token_address)
CREATE TABLE IF NOT EXISTS token_metrics_latest
(
    updated_at DateTime('UTC'),
    token_address           String,
    total_volume_usd        Float64,
    total_buys              UInt32,
    total_sells             UInt32,
    unique_holders          UInt32,
    ath_price_usd           Float64
)
ENGINE = ReplacingMergeTree(updated_at)
ORDER BY (token_address);


CREATE TABLE IF NOT EXISTS known_wallets
(
    `wallet_address` String,
    `name` String, -- e.g., "Pump.fun Fee Vault", "Raydium CPMM Authority V4", "KOL - Ansem"
    `tag` String,  -- e.g., "fee_vault", "dex_authority", "kol", "exchange"
)
ENGINE = ReplacingMergeTree()
ORDER BY (wallet_address);