robinhood-chain 0.7.0

Robinhood Chain API SDK (EVM, chain id 4663) — KOL trade intelligence, token discovery & launch-bundle detection, deployer reputation, the DEX trade tape, and the four push rule engines (copy-trade, price alerts, KOL coordination, first touches). Same msk_ key, bundled into every MadeOnSol tier at https://madeonsol.com/pricing
Documentation
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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
//! Request and response types for every Robinhood Chain endpoint.
//!
//! Robinhood Chain is an EVM chain (id 4663), so every wire field is EVM-native:
//! `token_address` (lowercase `0x…`), `eth_amount`, `tx_hash`, `block_number`,
//! `net_flow_eth`. Field names mirror the JSON wire format exactly so you can paste
//! API examples straight from the docs at <https://madeonsol.com/api-docs>.

use std::collections::HashMap;

use serde::{Deserialize, Serialize};

// ─── Shared enums ────────────────────────────────────────────────────────────

/// Trade side.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum TradeAction {
    Buy,
    Sell,
}

impl TradeAction {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Buy => "buy",
            Self::Sell => "sell",
        }
    }
}

/// Rolling window for the KOL leaderboard.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum KolLeaderboardPeriod {
    #[serde(rename = "24h")]
    H24,
    #[serde(rename = "7d")]
    D7,
    #[serde(rename = "30d")]
    D30,
}

impl KolLeaderboardPeriod {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::H24 => "24h",
            Self::D7 => "7d",
            Self::D30 => "30d",
        }
    }
}

/// Rolling consensus window for hot tokens.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum HotTokensWindow {
    #[serde(rename = "5m")]
    M5,
    #[serde(rename = "15m")]
    M15,
    #[serde(rename = "1h")]
    H1,
    #[serde(rename = "6h")]
    H6,
    #[serde(rename = "24h")]
    H24,
}

impl HotTokensWindow {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::M5 => "5m",
            Self::M15 => "15m",
            Self::H1 => "1h",
            Self::H6 => "6h",
            Self::H24 => "24h",
        }
    }
}

/// Uniswap DEX version filter for the trade tape.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum TradeDex {
    #[serde(rename = "uniswap-v2")]
    UniswapV2,
    #[serde(rename = "uniswap-v3")]
    UniswapV3,
    #[serde(rename = "uniswap-v4")]
    UniswapV4,
}

impl TradeDex {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::UniswapV2 => "uniswap-v2",
            Self::UniswapV3 => "uniswap-v3",
            Self::UniswapV4 => "uniswap-v4",
        }
    }
}

/// Ordering for token discovery (all descending).
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum TokensSort {
    LastTrade,
    MarketCap,
    Liquidity,
    PeakMc,
}

impl TokensSort {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::LastTrade => "last_trade",
            Self::MarketCap => "market_cap",
            Self::Liquidity => "liquidity",
            Self::PeakMc => "peak_mc",
        }
    }
}

/// Deployer reputation tier (filter + response value).
///
/// ⚠️ Tier semantics (migrations 267 + 269): `Elite` and `Good` are earned on the
/// $100K `runner_rate` and require 24h of deployer history — the $40K
/// graduation bar proved farmable by operators mass-relaunching one ticker
/// across rotating wallets. `graduation_rate` is still returned and still means
/// the $40K bar, but it NO LONGER sets the tier; `Spammer` is the one exception
/// that still keys off it. Call
/// [`DeployerHunter::stats`](crate::api::deployer_hunter::DeployerHunter::stats)
/// for the live thresholds.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum DeployerTier {
    Elite,
    Good,
    Neutral,
    Spammer,
}

impl DeployerTier {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Elite => "elite",
            Self::Good => "good",
            Self::Neutral => "neutral",
            Self::Spammer => "spammer",
        }
    }
}

/// Ordering for the deployer-hunter leaderboard (all descending, NULLs last).
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum DeployerLeaderboardSort {
    GraduationRate,
    RunnerRate,
    TokensDeployed,
    BestPeakMcUsd,
    LastDeployAt,
}

impl DeployerLeaderboardSort {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::GraduationRate => "graduation_rate",
            Self::RunnerRate => "runner_rate",
            Self::TokensDeployed => "tokens_deployed",
            Self::BestPeakMcUsd => "best_peak_mc_usd",
            Self::LastDeployAt => "last_deploy_at",
        }
    }
}

/// Behavioural classification filter for alpha-wallet ranking.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AlphaClassification {
    All,
    Human,
    Bot,
    SmartMoney,
}

impl AlphaClassification {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::All => "all",
            Self::Human => "human",
            Self::Bot => "bot",
            Self::SmartMoney => "smart_money",
        }
    }
}

/// Identity filter for alpha-wallet ranking.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AlphaIdentity {
    All,
    KnownKol,
    Unknown,
}

impl AlphaIdentity {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::All => "all",
            Self::KnownKol => "known_kol",
            Self::Unknown => "unknown",
        }
    }
}

/// Ordering for alpha-wallet ranking.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AlphaSort {
    NetEth,
    WinRate,
    Trades,
    Tokens,
    BuyEth,
    MemecoinShare,
    LastTradeAt,
}

impl AlphaSort {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::NetEth => "net_eth",
            Self::WinRate => "win_rate",
            Self::Trades => "trades",
            Self::Tokens => "tokens",
            Self::BuyEth => "buy_eth",
            Self::MemecoinShare => "memecoin_share",
            Self::LastTradeAt => "last_trade_at",
        }
    }
}

/// Sort direction.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum SortOrder {
    Desc,
    Asc,
}

impl SortOrder {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Desc => "desc",
            Self::Asc => "asc",
        }
    }
}

/// Confidence band on a buyer-quality read.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Confidence {
    Low,
    Medium,
    High,
}

/// Directional signal on a buyer-quality read.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum QualitySignal {
    Positive,
    Neutral,
    Negative,
}

/// Launch-bundle kind. Robinhood Chain is an Arbitrum Orbit L2 with no atomic
/// multi-signer transaction, so there is no `atomic_tx` kind — a detected bundle
/// is `same_block`, else `none`.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum BundleKind {
    SameBlock,
    None,
}

/// Window for the reputable-deployer best-tokens ranking.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum BestTokensPeriod {
    #[serde(rename = "24h")]
    H24,
    #[serde(rename = "7d")]
    D7,
    #[serde(rename = "30d")]
    D30,
    #[serde(rename = "all")]
    All,
}

impl BestTokensPeriod {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::H24 => "24h",
            Self::D7 => "7d",
            Self::D30 => "30d",
            Self::All => "all",
        }
    }
}

/// Ordering for one deployer's paginated launch history.
///
/// `PeakMcUsd` is a **page-scoped** sort — peak MC lives in another table and is
/// applied after enrichment of the requested page only, so it is not a global
/// "top tokens by peak MC" ranking. Use
/// [`DeployerHunter::best_tokens`](crate::api::deployer_hunter::DeployerHunter::best_tokens)
/// for a real ranking.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum DeployerTokensSort {
    FirstSeenAt,
    PeakMcUsd,
}

impl DeployerTokensSort {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::FirstSeenAt => "first_seen_at",
            Self::PeakMcUsd => "peak_mc_usd",
        }
    }
}

/// Rolling window for KOL coordination.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
pub enum CoordinationPeriod {
    #[serde(rename = "1h")]
    H1,
    #[serde(rename = "6h")]
    H6,
    #[serde(rename = "24h")]
    H24,
    #[serde(rename = "7d")]
    D7,
}

impl CoordinationPeriod {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::H1 => "1h",
            Self::H6 => "6h",
            Self::H24 => "24h",
            Self::D7 => "7d",
        }
    }
}

/// Deployer-alert kind. Robinhood Chain has no `bonded`/`kol_buy` alerts — most
/// launchpads are direct-to-DEX and alerts carry no KOL join.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum DeployerAlertType {
    NewDeploy,
    Graduated,
}

impl DeployerAlertType {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::NewDeploy => "new_deploy",
            Self::Graduated => "graduated",
        }
    }
}

/// Deployer-alert priority. Robinhood Chain has no `low` priority.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum DeployerAlertPriority {
    High,
    Medium,
}

impl DeployerAlertPriority {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::High => "high",
            Self::Medium => "medium",
        }
    }
}

/// Direction of a KOL cohort's in-window flow on a coordination row.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum CoordinationSignal {
    Accumulating,
    Distributing,
}

/// Direction of a deployer's launch quality over time.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum TrajectoryTrend {
    Improving,
    Declining,
    Stable,
}

// ─── KOL: feed ───────────────────────────────────────────────────────────────

/// Query parameters for [`Kol::feed`](crate::api::kol::Kol::feed).
#[derive(Debug, Clone, Default, Serialize)]
pub struct KolFeedParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Cursor — return trades strictly older than this ISO 8601 timestamp.
    /// Pass `next_before` from the previous response to page backwards.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub action: Option<TradeAction>,
    /// Filter to a single KOL by their EVM wallet address (0x, 40 hex).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kol: Option<String>,
    /// Minimum trade size in ETH.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_eth: Option<f64>,
}

/// A single KOL trade on Robinhood Chain.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcKolTrade {
    /// The KOL's Robinhood-Chain wallet (0x).
    pub evm_address: String,
    #[serde(default)]
    pub kol_name: Option<String>,
    #[serde(default)]
    pub kol_twitter: Option<String>,
    pub token_address: String,
    #[serde(default)]
    pub token_symbol: Option<String>,
    #[serde(default)]
    pub token_name: Option<String>,
    /// `pons` | `flap` | `clanker` | `hood.fun` | `virtuals` | null.
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    /// Reputation tier of the token's deployer (`elite`/`good`/`neutral`/`spammer`).
    #[serde(default)]
    pub deployer_tier: Option<String>,
    /// Token age at request time (first-seen → now), in minutes.
    #[serde(default)]
    pub token_age_minutes: Option<i64>,
    pub action: TradeAction,
    /// Trade size in ETH.
    #[serde(default)]
    pub eth_amount: Option<f64>,
    #[serde(default)]
    pub token_amount: Option<f64>,
    #[serde(default)]
    pub price_usd_at_trade: Option<f64>,
    /// Token market cap when the KOL traded.
    #[serde(default)]
    pub market_cap_usd_at_trade: Option<f64>,
    /// Token market cap now.
    #[serde(default)]
    pub current_mc_usd: Option<f64>,
    /// All-time-high market cap observed since ingestion.
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub liquidity_usd: Option<f64>,
    /// `current_mc_usd ÷ market_cap_usd_at_trade` — how far the token ran after the trade.
    #[serde(default)]
    pub mc_multiple_since_trade: Option<f64>,
    /// `uniswap-v2/v3/v4` or the launchpad name for curve trades.
    pub dex: String,
    #[serde(default)]
    pub pool: Option<String>,
    pub tx_hash: String,
    pub block_number: i64,
    pub traded_at: String,
}

/// Response of [`Kol::feed`](crate::api::kol::Kol::feed).
#[derive(Debug, Clone, Deserialize)]
pub struct KolFeedResponse {
    /// Always `"robinhood"`.
    pub chain: String,
    pub trades: Vec<RhcKolTrade>,
    pub count: u32,
    /// Age of the newest row, in seconds.
    #[serde(default)]
    pub data_age_seconds: Option<i64>,
    /// Cursor for the next page — pass as `before` to fetch older trades.
    #[serde(default)]
    pub next_before: Option<String>,
}

// ─── KOL: leaderboard ────────────────────────────────────────────────────────

/// Query parameters for [`Kol::leaderboard`](crate::api::kol::Kol::leaderboard).
#[derive(Debug, Clone, Default, Serialize)]
pub struct KolLeaderboardParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub period: Option<KolLeaderboardPeriod>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
}

/// A single row of the KOL activity leaderboard.
#[derive(Debug, Clone, Deserialize)]
pub struct KolLeaderboardEntry {
    #[serde(default)]
    pub kol_name: Option<String>,
    #[serde(default)]
    pub kol_twitter: Option<String>,
    pub trades: i64,
    pub buys: i64,
    pub sells: i64,
    /// Total ETH bought in the window.
    pub buy_eth: f64,
    /// Total ETH sold in the window.
    pub sell_eth: f64,
    /// `buy_eth − sell_eth` (flow, not realized PnL).
    pub net_eth: f64,
    /// Distinct tokens traded in the window.
    pub tokens_traded: i64,
    pub last_trade_at: String,
}

/// Response of [`Kol::leaderboard`](crate::api::kol::Kol::leaderboard).
#[derive(Debug, Clone, Deserialize)]
pub struct KolLeaderboardResponse {
    pub chain: String,
    pub period: String,
    pub leaderboard: Vec<KolLeaderboardEntry>,
    pub count: u32,
}

// ─── KOL: hot tokens ─────────────────────────────────────────────────────────

/// Query parameters for [`Kol::hot_tokens`](crate::api::kol::Kol::hot_tokens).
#[derive(Debug, Clone, Default, Serialize)]
pub struct HotTokensParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub window: Option<HotTokensWindow>,
}

/// A consensus token — bought by 2+ distinct KOLs in the window.
#[derive(Debug, Clone, Deserialize)]
pub struct HotToken {
    pub token_address: String,
    #[serde(default)]
    pub token_symbol: Option<String>,
    #[serde(default)]
    pub token_name: Option<String>,
    /// `noxa | flap | pons | hood.fun | clanker | null`.
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    /// `elite | good | neutral | spammer | null`.
    #[serde(default)]
    pub deployer_tier: Option<String>,
    /// Distinct KOL buyers in the window (>= 2).
    pub kols_buying: i64,
    pub buys: i64,
    pub sells: i64,
    pub buy_eth: f64,
    /// `buy_eth − sell_eth`.
    pub net_eth: f64,
    /// Current market cap.
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    pub last_trade_at: String,
}

/// Response of [`Kol::hot_tokens`](crate::api::kol::Kol::hot_tokens).
#[derive(Debug, Clone, Deserialize)]
pub struct HotTokensResponse {
    pub chain: String,
    pub window: String,
    pub tokens: Vec<HotToken>,
    pub count: u32,
}

// ─── KOL: profile ────────────────────────────────────────────────────────────

/// Aggregate stats over a KOL's last 200 RHC trades.
#[derive(Debug, Clone, Deserialize)]
pub struct KolProfileStats {
    pub trades: i64,
    pub buys: i64,
    pub sells: i64,
    pub buy_eth: f64,
    pub sell_eth: f64,
    pub net_eth: f64,
    pub tokens_traded: i64,
    /// e.g. `"last 200 trades"`.
    pub window: String,
}

/// Response of [`Kol::wallet`](crate::api::kol::Kol::wallet).
#[derive(Debug, Clone, Deserialize)]
pub struct KolProfileResponse {
    pub chain: String,
    pub evm_address: String,
    #[serde(default)]
    pub kol_name: Option<String>,
    #[serde(default)]
    pub kol_twitter: Option<String>,
    pub stats: KolProfileStats,
    /// 50 most recent trades (token, action, eth_amount, price/MC at trade, dex,
    /// tx_hash, traded_at). Left as raw JSON — shape is not schema-pinned upstream.
    #[serde(default)]
    pub trades: Vec<serde_json::Value>,
}

// ─── KOL: coordination ───────────────────────────────────────────────────────

/// Query parameters for
/// [`Kol::coordination`](crate::api::kol::Kol::coordination).
#[derive(Debug, Clone, Default, Serialize)]
pub struct CoordinationParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub period: Option<CoordinationPeriod>,
    /// Minimum distinct KOL buyers for a token to qualify (2..=50, default 2).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_kols: Option<u32>,
    /// Max tokens (1..=50, default 20).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Minimum market cap at the FIRST KOL buy (USD). Tokens with an unknown
    /// entry MC are excluded whenever a band is set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_mc_usd: Option<f64>,
    /// Maximum market cap at the first KOL buy (USD).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_mc_usd: Option<f64>,
}

/// One KOL's leg of a coordination cohort.
#[derive(Debug, Clone, Deserialize)]
pub struct CoordinationKol {
    pub evm_address: String,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub twitter_url: Option<String>,
    pub buy_eth: f64,
    pub sell_eth: f64,
    /// True when this KOL sold more ETH than it bought in the window.
    pub exited: bool,
}

/// A token bought by N+ distinct KOLs in the window, with cohort composition.
#[derive(Debug, Clone, Deserialize)]
pub struct CoordinationToken {
    pub token_address: String,
    #[serde(default)]
    pub token_symbol: Option<String>,
    #[serde(default)]
    pub token_name: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub deployer_tier: Option<String>,
    #[serde(default)]
    pub token_age_minutes: Option<i64>,
    /// Distinct KOL buyers in the window.
    pub kol_count: i64,
    pub total_buys: i64,
    pub buy_eth: f64,
    pub sell_eth: f64,
    /// `buy_eth − sell_eth` over the window.
    pub net_eth: f64,
    pub signal: CoordinationSignal,
    /// KOLs that sold more than they bought.
    pub exited_count: i64,
    pub holders_count: i64,
    pub first_buy_at: String,
    pub last_buy_at: String,
    /// How fast the cohort piled in, first → last buy.
    pub time_to_consensus_sec: i64,
    #[serde(default)]
    pub market_cap_usd_at_first_buy: Option<f64>,
    #[serde(default)]
    pub current_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub liquidity_usd: Option<f64>,
    /// Per-KOL breakdown, largest buyer first.
    #[serde(default)]
    pub kols: Vec<CoordinationKol>,
}

/// Response of [`Kol::coordination`](crate::api::kol::Kol::coordination).
#[derive(Debug, Clone, Deserialize)]
pub struct CoordinationResponse {
    pub chain: String,
    pub coordination: Vec<CoordinationToken>,
    pub count: u32,
    pub period: String,
    pub min_kols: i64,
}

// ─── KOL: first touches ──────────────────────────────────────────────────────

/// Query parameters for
/// [`Kol::first_touches`](crate::api::kol::Kol::first_touches).
#[derive(Debug, Clone, Default, Serialize)]
pub struct FirstTouchesParams {
    /// Max events (1..=100, default 50). Clamped to 20 below PRO.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// ISO 8601 — only first-touches strictly newer. The polling idiom: pass back
    /// the newest timestamp you saw.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since: Option<String>,
    /// ISO 8601 cursor — only first-touches strictly older. Pass `next_before`
    /// from the previous response to page back.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Minimum first-buy size in ETH (0..=100000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_eth: Option<f64>,
    /// Only tokens younger than N minutes at first touch (1..=43200).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub token_age_max_min: Option<u32>,
    /// Filter by launchpad: pons, flap, clanker, hood.fun, noxa, virtuals.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub launchpad: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_mc_usd: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_mc_usd: Option<f64>,
}

/// The KOL behind a first touch. `evm_address` is ULTRA/BUSINESS only.
#[derive(Debug, Clone, Deserialize)]
pub struct FirstTouchKol {
    /// ULTRA/BUSINESS only — omitted on lower tiers.
    #[serde(default)]
    pub evm_address: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub twitter_url: Option<String>,
}

/// The first time ANY tracked KOL bought a given token.
#[derive(Debug, Clone, Deserialize)]
pub struct FirstTouchEvent {
    pub token_address: String,
    #[serde(default)]
    pub token_symbol: Option<String>,
    #[serde(default)]
    pub token_name: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    pub first_buy_at: String,
    #[serde(default)]
    pub eth_amount: Option<f64>,
    #[serde(default)]
    pub token_amount: Option<f64>,
    pub tx_hash: String,
    /// Token age at the first KOL buy, in minutes.
    #[serde(default)]
    pub token_age_minutes: Option<i64>,
    #[serde(default)]
    pub market_cap_usd_at_first_buy: Option<f64>,
    #[serde(default)]
    pub price_usd_at_first_buy: Option<f64>,
    #[serde(default)]
    pub current_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    pub first_kol: FirstTouchKol,
}

/// Response of [`Kol::first_touches`](crate::api::kol::Kol::first_touches).
#[derive(Debug, Clone, Deserialize)]
pub struct FirstTouchesResponse {
    pub chain: String,
    pub events: Vec<FirstTouchEvent>,
    pub count: u32,
    /// Cursor for the next page — pass as `before` to fetch older events.
    #[serde(default)]
    pub next_before: Option<String>,
    #[serde(default)]
    pub data_age_seconds: Option<i64>,
}

// ─── Trades: DEX tape ────────────────────────────────────────────────────────

/// Query parameters for [`Trades::list`](crate::api::trades::Trades::list).
#[derive(Debug, Clone, Default, Serialize)]
pub struct TradesParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Filter to one token address (0x, 40 hex).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub token: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dex: Option<TradeDex>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub action: Option<TradeAction>,
    /// Minimum trade size in ETH.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_eth: Option<f64>,
    /// Cursor: trades strictly older than this `block_time`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
}

/// A single Uniswap swap on Robinhood Chain.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcTrade {
    pub block_number: i64,
    pub block_time: String,
    pub tx_hash: String,
    pub log_index: i64,
    pub dex: String,
    pub pool: String,
    /// Swap-log recipient — the ROUTER for aggregated swaps. Use `trader_eoa`
    /// for wallet analytics.
    #[serde(default)]
    pub trader: Option<String>,
    /// The effective trading account — `tx.from` on an ordinary transaction, or
    /// the ERC-4337 userOp sender when the trade was bundled. Never the router
    /// or the bundler. An EOA either way: userOp senders on this chain carry an
    /// EIP-7702 delegation rather than being contract accounts.
    #[serde(default)]
    pub trader_eoa: Option<String>,
    /// Router/aggregator contract (tx.to).
    #[serde(default)]
    pub router: Option<String>,
    #[serde(default)]
    pub token_address: Option<String>,
    #[serde(default)]
    pub action: Option<TradeAction>,
    #[serde(default)]
    pub eth_amount: Option<f64>,
    #[serde(default)]
    pub price_native: Option<f64>,
    #[serde(default)]
    pub price_usd: Option<f64>,
    #[serde(default)]
    pub mc_usd_at_trade: Option<f64>,
    /// Effective gas price, gwei.
    #[serde(default)]
    pub gas_price: Option<f64>,
    /// Transaction position within the block (ordering / sandwich detection).
    #[serde(default)]
    pub tx_index: Option<i64>,
    /// 4-byte calldata selector.
    #[serde(default)]
    pub method_selector: Option<String>,
    /// v3/v4 in-range liquidity at the trade.
    #[serde(default)]
    pub liquidity: Option<f64>,
    #[serde(default)]
    pub launchpad: Option<String>,
    /// True if `trader_eoa` is a tracked KOL wallet.
    #[serde(default)]
    pub is_kol: bool,
    #[serde(default)]
    pub kol_name: Option<String>,
    /// Set if `trader_eoa` is a known deployer.
    #[serde(default)]
    pub deployer_tier: Option<String>,
}

/// Response of [`Trades::list`](crate::api::trades::Trades::list).
#[derive(Debug, Clone, Deserialize)]
pub struct TradesResponse {
    pub chain: String,
    pub trades: Vec<RhcTrade>,
    pub count: u32,
    /// Pagination cursor (last row's `block_time`).
    #[serde(default)]
    pub next_before: Option<String>,
}

// ─── Tokens: discovery ───────────────────────────────────────────────────────

/// Query parameters for [`Tokens::list`](crate::api::tokens::Tokens::list).
#[derive(Debug, Clone, Default, Serialize)]
pub struct TokensListParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<TokensSort>,
    /// Minimum current market cap (USD).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_mc_usd: Option<f64>,
    /// Minimum current liquidity (USD).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_liquidity_usd: Option<f64>,
    /// Filter by launchpad: pons, flap, clanker, hood.fun, noxa, virtuals.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub launchpad: Option<String>,
}

/// A single token in the discovery list.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcTokenSummary {
    pub token_address: String,
    #[serde(default)]
    pub symbol: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub deployer_address: Option<String>,
    #[serde(default)]
    pub deployer_tier: Option<String>,
    #[serde(default)]
    pub price_usd: Option<f64>,
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    #[serde(default)]
    pub fdv_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_at: Option<String>,
    /// Percent below all-time-high MC.
    #[serde(default)]
    pub drawdown_from_peak_pct: Option<i64>,
    #[serde(default)]
    pub liquidity_usd: Option<f64>,
    #[serde(default)]
    pub primary_dex: Option<String>,
    #[serde(default)]
    pub primary_pool: Option<String>,
    #[serde(default)]
    pub last_trade_time: Option<String>,
}

/// Response of [`Tokens::list`](crate::api::tokens::Tokens::list).
#[derive(Debug, Clone, Deserialize)]
pub struct TokensListResponse {
    pub chain: String,
    pub tokens: Vec<RhcTokenSummary>,
    pub count: u32,
    pub sort: String,
}

// ─── Tokens: single-token bundle snapshot ────────────────────────────────────

/// Deployer reputation block on a token snapshot.
#[derive(Debug, Clone, Deserialize)]
pub struct TokenDeployer {
    pub address: String,
    pub tier: String,
    pub tokens_deployed: i64,
    #[serde(default)]
    pub graduation_rate: Option<f64>,
    #[serde(default)]
    pub runner_rate: Option<f64>,
    pub runners: i64,
    #[serde(default)]
    pub best_peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub launchpads: Vec<String>,
}

/// KOL activity summary on a token snapshot.
#[derive(Debug, Clone, Deserialize)]
pub struct TokenKolActivity {
    pub distinct_kols: i64,
    #[serde(default)]
    pub names: Vec<String>,
    pub buys: i64,
    pub sells: i64,
    pub net_eth: f64,
}

/// Response of [`Tokens::get`](crate::api::tokens::Tokens::get).
#[derive(Debug, Clone, Deserialize)]
pub struct TokenDetailResponse {
    pub chain: String,
    pub token_address: String,
    #[serde(default)]
    pub symbol: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub decimals: Option<i64>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub graduated_pool: Option<String>,
    #[serde(default)]
    pub graduated_at: Option<String>,
    #[serde(default)]
    pub deployer_address: Option<String>,
    #[serde(default)]
    pub first_seen_at: Option<String>,
    #[serde(default)]
    pub token_age_minutes: Option<i64>,
    #[serde(default)]
    pub price_usd: Option<f64>,
    #[serde(default)]
    pub price_native: Option<f64>,
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    #[serde(default)]
    pub fdv_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_at: Option<String>,
    #[serde(default)]
    pub drawdown_from_peak_pct: Option<i64>,
    #[serde(default)]
    pub total_supply_raw: Option<String>,
    #[serde(default)]
    pub liquidity_usd: Option<f64>,
    #[serde(default)]
    pub primary_dex: Option<String>,
    #[serde(default)]
    pub primary_pool: Option<String>,
    #[serde(default)]
    pub last_trade_time: Option<String>,
    /// Deployer reputation.
    #[serde(default)]
    pub deployer: Option<TokenDeployer>,
    /// Up to 10 other tokens by the same deployer (symbol or address).
    #[serde(default)]
    pub deployer_other_tokens: Vec<String>,
    #[serde(default)]
    pub kol_activity: Option<TokenKolActivity>,
    /// Up to 20 pools with reserves/liquidity/sqrt_price. Raw JSON — shape is
    /// not schema-pinned upstream.
    #[serde(default)]
    pub pools: Vec<serde_json::Value>,
}

// ─── Tokens: token intel (top-traders / flow / peak-history / holders) ───────

/// Query parameters for [`Tokens::top_traders`](crate::api::tokens::Tokens::top_traders).
#[derive(Debug, Clone, Default, Serialize)]
pub struct TopTradersParams {
    /// Rows to return. Capped at 50 on PRO, 200 on ULTRA/BUSINESS. Default 50.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Page offset (0..=10000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u32>,
}

/// Query parameters for [`Tokens::flow`](crate::api::tokens::Tokens::flow).
#[derive(Debug, Clone, Default, Serialize)]
pub struct FlowParams {
    /// Lookback window: `1h`, `6h`, `24h` or `7d`. Default `24h`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub window: Option<String>,
}

/// Query parameters for [`Tokens::peak_history`](crate::api::tokens::Tokens::peak_history).
#[derive(Debug, Clone, Default, Serialize)]
pub struct PeakHistoryParams {
    /// Curve window: `24h`, `7d`, `30d` or `all`. Default `7d`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub window: Option<String>,
    /// `"false"` to skip the series and return only the peak summary.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub curve: Option<String>,
}

/// Query parameters for [`Tokens::holders`](crate::api::tokens::Tokens::holders).
#[derive(Debug, Clone, Default, Serialize)]
pub struct HoldersParams {
    /// Rows to return. Capped at 50 on PRO, 200 on ULTRA/BUSINESS. Default 50.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Page offset (0..=10000).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u32>,
}

/// One holder-growth window (`1h` / `24h` / `7d`) inside
/// [`HolderGrowth`] on `GET /rhc/tokens/{address}/holders`.
///
/// Every count is `None` when the window could not be resolved (the chain had
/// no ingested trades in it). Pools and burn addresses are excluded from all
/// counts.
#[derive(Debug, Clone, Deserialize)]
pub struct HolderGrowthWindow {
    /// Lowest block observed at-or-after now()−window (from our trade ingest, ~10 blocks/s).
    #[serde(default)]
    pub cutoff_block: Option<i64>,
    /// Addresses whose FIRST `Transfer` of this token landed at-or-after `cutoff_block` (any current balance).
    #[serde(default)]
    pub entered: Option<i64>,
    /// `entered` ∩ balance > 0.
    #[serde(default)]
    pub entered_still_holding: Option<i64>,
    /// Pre-existing holders whose last `Transfer` in the window left them at zero.
    #[serde(default)]
    pub exited: Option<i64>,
    /// `entered_still_holding − exited` ≈ change in `holder_count` over the window.
    #[serde(default)]
    pub net: Option<i64>,
}

/// The `holder_growth` object on `GET /rhc/tokens/{address}/holders`
/// ([`Tokens::holders`](crate::api::tokens::Tokens::holders)).
///
/// Entered / exited holders per window, read from the `Transfer`-log fold
/// (`first_seen_block` + `last_block`, zero-balance rows retained). The whole
/// object is `null` on the wire only if the growth read failed; a single window
/// is `None` when the chain had no ingested trades in it. Deserialize it from
/// the response with `serde_json::from_value(resp["holder_growth"].clone())`.
#[derive(Debug, Clone, Deserialize)]
pub struct HolderGrowth {
    #[serde(rename = "1h", default)]
    pub h1: Option<HolderGrowthWindow>,
    #[serde(rename = "24h", default)]
    pub h24: Option<HolderGrowthWindow>,
    #[serde(rename = "7d", default)]
    pub d7: Option<HolderGrowthWindow>,
    /// Server-side explanation of the semantics.
    #[serde(default)]
    pub note: Option<String>,
}

// ─── Tokens: candles ─────────────────────────────────────────────────────────

/// Query parameters for [`Tokens::candles`](crate::api::tokens::Tokens::candles).
#[derive(Debug, Clone, Default, Serialize)]
pub struct CandlesParams {
    /// Number of candles (most recent first, returned chronological). 1..=1000, default 240.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Lower bound on `bucket_start` (ISO 8601).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from: Option<String>,
    /// Upper bound on `bucket_start` (ISO 8601).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub to: Option<String>,
}

/// A single 1-minute OHLC candle.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcCandle {
    pub bucket_start: String,
    pub open_price_usd: f64,
    pub high_price_usd: f64,
    pub low_price_usd: f64,
    pub close_price_usd: f64,
    #[serde(default)]
    pub open_mc_usd: Option<f64>,
    #[serde(default)]
    pub high_mc_usd: Option<f64>,
    #[serde(default)]
    pub low_mc_usd: Option<f64>,
    #[serde(default)]
    pub close_mc_usd: Option<f64>,
    #[serde(default)]
    pub close_liquidity_usd: Option<f64>,
    #[serde(default)]
    pub close_supply: Option<f64>,
    pub volume_usd: f64,
    #[serde(default)]
    pub volume_buy_usd: Option<f64>,
    #[serde(default)]
    pub volume_sell_usd: Option<f64>,
    pub trades: i64,
    #[serde(default)]
    pub buy_count: Option<i64>,
    #[serde(default)]
    pub sell_count: Option<i64>,
    #[serde(default)]
    pub dex: Option<String>,
    #[serde(default)]
    pub pool_address: Option<String>,
}

/// Response of [`Tokens::candles`](crate::api::tokens::Tokens::candles).
#[derive(Debug, Clone, Deserialize)]
pub struct CandlesResponse {
    pub chain: String,
    pub token_address: String,
    pub timeframe: String,
    pub candles: Vec<RhcCandle>,
    pub count: u32,
}

// ─── Tokens: KOL consensus ───────────────────────────────────────────────────

/// The KOL cohort's position on a token.
#[derive(Debug, Clone, Deserialize)]
pub struct KolConsensus {
    pub total_kol_buyers: i64,
    pub total_kol_sellers: i64,
    /// Fraction of KOL buyers who also sold (0–1).
    pub kol_exit_rate: f64,
    pub net_flow_eth: f64,
    pub total_buy_eth: f64,
    pub total_sell_eth: f64,
    #[serde(default)]
    pub first_kol_buy_at: Option<String>,
    #[serde(default)]
    pub last_kol_buy_at: Option<String>,
    #[serde(default)]
    pub first_touch_wallet: Option<String>,
    #[serde(default)]
    pub first_touch_at: Option<String>,
    /// Median MC at KOL buy. Null when the RHC pricer withheld MC under its
    /// liquidity gate.
    #[serde(default)]
    pub median_entry_mc_usd: Option<f64>,
    /// Number of buys with a `market_cap_usd_at_trade` — the median's sample size.
    #[serde(default)]
    pub entry_mc_samples: i64,
    pub total_trades: i64,
    /// ULTRA only — distinct KOL buyer wallets.
    #[serde(default)]
    pub buyers: Vec<String>,
    /// ULTRA only — KOL wallets that bought and sold.
    #[serde(default)]
    pub exited: Vec<String>,
}

/// Response of [`Tokens::kol_consensus`](crate::api::tokens::Tokens::kol_consensus).
#[derive(Debug, Clone, Deserialize)]
pub struct KolConsensusResponse {
    pub chain: String,
    pub token_address: String,
    #[serde(default)]
    pub current_mc_usd: Option<f64>,
    #[serde(default)]
    pub current_price_usd: Option<f64>,
    /// Null when no tracked KOL has traded the token.
    #[serde(default)]
    pub consensus: Option<KolConsensus>,
}

// ─── Tokens: buyer quality ───────────────────────────────────────────────────

/// Per-factor breakdown of a buyer-quality read.
#[derive(Debug, Clone, Deserialize)]
pub struct BuyerQualityBreakdown {
    pub early_buyers_analyzed: i64,
    pub alpha_wallet_count: i64,
    pub kol_count: i64,
    /// Early buyers flagged as part of a same-block launch bundle.
    pub bundle_buyer_count: i64,
    /// Early buyers on the rolling dump-cluster list (informational — does not
    /// move the score).
    pub dump_cluster_count: i64,
    /// Early buyers with ≥5 recent early-buyer appearances of any kind.
    pub recycled_early_buyer_count: i64,
    /// Percent (0–100), non-bot buyers with ≥3 tokens of history.
    #[serde(default)]
    pub avg_historical_win_rate: Option<f64>,
    pub bot_dominated: bool,
}

/// The 0–100 buyer-quality read.
#[derive(Debug, Clone, Deserialize)]
pub struct BuyerQuality {
    pub score: i64,
    pub confidence: Confidence,
    pub signal: QualitySignal,
    pub breakdown: BuyerQualityBreakdown,
}

/// Signal-availability block on a buyer-quality response.
#[derive(Debug, Clone, Deserialize)]
pub struct BuyerQualityCoverage {
    #[serde(default)]
    pub bundle_detection: Option<String>,
    #[serde(default)]
    pub dump_cluster_signal: Option<String>,
    #[serde(default)]
    pub note: Option<String>,
}

/// Response of [`Tokens::buyer_quality`](crate::api::tokens::Tokens::buyer_quality).
#[derive(Debug, Clone, Deserialize)]
pub struct BuyerQualityResponse {
    pub chain: String,
    pub token_address: String,
    #[serde(default)]
    pub current_mc_usd: Option<f64>,
    pub quality: BuyerQuality,
    #[serde(default)]
    pub coverage: Option<BuyerQualityCoverage>,
    /// Present only when buyer data is insufficient.
    #[serde(default)]
    pub note: Option<String>,
}

// ─── Tokens: launch-bundle detection ─────────────────────────────────────────

/// The scalar bundle signal.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcBundle {
    /// Bundle-cohort size (0 when none).
    pub wallet_count: i64,
    /// `same_block` = 3+ early buyers first-bought in one block; `none` = no cluster.
    pub bundle_kind: BundleKind,
    /// Net tokens still held ÷ tokens bought, [0,1]. The primary signal.
    #[serde(default)]
    pub held_ratio: Option<f64>,
    /// Net tokens held ÷ total supply, [0,1]; null when supply is unknown.
    #[serde(default)]
    pub held_pct_of_supply: Option<f64>,
    /// True when the cohort holds ≤0.5% of what it bought.
    pub fully_exited: bool,
    /// Cohort cumulative buy-side token volume (human-scaled).
    pub buy_volume: f64,
    /// Cohort net position (Σbuys − Σsells, human-scaled).
    pub tokens_held: f64,
}

/// A single wallet in the bundle cohort. Empty for BASIC; top-10 for PRO;
/// full cohort for ULTRA. ULTRA-only identity fields default when absent.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcBundleWallet {
    /// Early-buyer rank (1 = first buyer).
    pub rank: i64,
    /// Buyer wallet (lowercase 0x).
    pub wallet: String,
    #[serde(default)]
    pub held_ratio: Option<f64>,
    pub has_sold: bool,
    /// Wallet is a tracked RHC KOL.
    #[serde(default)]
    pub is_kol: bool,
    /// ULTRA only — historical win-rate [0,1].
    #[serde(default)]
    pub win_rate: Option<f64>,
    /// ULTRA only — bot heuristic from `mv_rhc_alpha_wallets`.
    #[serde(default)]
    pub likely_bot: Option<bool>,
    /// ULTRA only — net position, human-scaled.
    #[serde(default)]
    pub tokens_held: Option<f64>,
}

/// Response of [`Tokens::bundle`](crate::api::tokens::Tokens::bundle).
#[derive(Debug, Clone, Deserialize)]
pub struct RhcBundleResponse {
    pub chain: String,
    pub token_address: String,
    pub bundle: RhcBundle,
    /// Empty for BASIC; top-10 for PRO; full cohort for ULTRA.
    #[serde(default)]
    pub wallets: Vec<RhcBundleWallet>,
}

// ─── Tokens: batch ───────────────────────────────────────────────────────────

/// JSON body for the two batch POST endpoints: `{"addresses": [...]}`.
///
/// Built for you by [`Tokens::batch`](crate::api::tokens::Tokens::batch) and
/// [`Tokens::batch_buyer_quality`](crate::api::tokens::Tokens::batch_buyer_quality) —
/// exposed so callers can log or reuse the exact wire body.
#[derive(Debug, Clone, Default, Serialize)]
pub struct BatchAddressesRequest {
    pub addresses: Vec<String>,
}

/// Deployer reputation block on a batch token entry.
#[derive(Debug, Clone, Deserialize)]
pub struct TokenBatchDeployer {
    /// Deployer wallet (lowercase 0x).
    pub address: String,
    /// How the deployer was attributed (e.g. the launchpad event).
    #[serde(default)]
    pub source: Option<String>,
    /// Present only when the deployer has a reputation row.
    #[serde(default)]
    pub tier: Option<String>,
    #[serde(default)]
    pub tokens_deployed: Option<i64>,
    /// Tokens that reached a $40K+ peak MC.
    #[serde(default)]
    pub graduated: Option<i64>,
    /// The $40K bar. Still returned, but it NO LONGER sets the tier.
    #[serde(default)]
    pub graduation_rate: Option<f64>,
    /// Tokens that peaked ≥ $100K MC.
    #[serde(default)]
    pub runners: Option<i64>,
    /// The $100K bar — this is what `tier` now rides on.
    #[serde(default)]
    pub runner_rate: Option<f64>,
}

/// One token in a batch response. Every REQUESTED address is echoed back, so
/// unknown tokens appear as `found: false` with the rest of the fields absent.
#[derive(Debug, Clone, Deserialize)]
pub struct TokenBatchEntry {
    pub address: String,
    pub found: bool,
    #[serde(default)]
    pub symbol: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub decimals: Option<i64>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub graduated_at: Option<String>,
    #[serde(default)]
    pub first_seen_at: Option<String>,
    #[serde(default)]
    pub price_usd: Option<f64>,
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    #[serde(default)]
    pub fdv_usd: Option<f64>,
    #[serde(default)]
    pub liquidity_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_at: Option<String>,
    #[serde(default)]
    pub primary_dex: Option<String>,
    #[serde(default)]
    pub last_trade_time: Option<String>,
    #[serde(default)]
    pub deployer: Option<TokenBatchDeployer>,
}

/// Response of [`Tokens::batch`](crate::api::tokens::Tokens::batch).
#[derive(Debug, Clone, Deserialize)]
pub struct TokenBatchResponse {
    pub chain: String,
    /// One entry per requested address, in the order sent (de-duplicated).
    pub tokens: Vec<TokenBatchEntry>,
    pub requested: i64,
    /// How many of the requested addresses resolved to a known token.
    pub found: i64,
}

/// One token in a batch buyer-quality response.
///
/// Per-token failures degrade to an entry carrying `error` rather than failing
/// the whole batch — one unpriced token never costs you the other 19 results.
#[derive(Debug, Clone, Deserialize)]
pub struct BatchBuyerQualityEntry {
    pub chain: String,
    pub token_address: String,
    #[serde(default)]
    pub current_mc_usd: Option<f64>,
    /// `None` when this token failed to score — see `error`.
    #[serde(default)]
    pub quality: Option<BuyerQuality>,
    /// Present only when buyer data is insufficient.
    #[serde(default)]
    pub note: Option<String>,
    /// Present only when this one token failed to score.
    #[serde(default)]
    pub error: Option<String>,
}

/// Response of
/// [`Tokens::batch_buyer_quality`](crate::api::tokens::Tokens::batch_buyer_quality).
#[derive(Debug, Clone, Deserialize)]
pub struct BatchBuyerQualityResponse {
    pub chain: String,
    pub tokens: Vec<BatchBuyerQualityEntry>,
    pub requested: i64,
    /// Entries that scored (the rest carry `error`).
    pub scored: i64,
    /// The server-side cap — **20**, deliberately lower than the Solana batch
    /// cap of 50 (per-token cohort computation, not one set-based query).
    pub max_addresses: i64,
    #[serde(default)]
    pub coverage: Option<BuyerQualityCoverage>,
}

// ─── Deployer-hunter: leaderboard ────────────────────────────────────────────

/// Query parameters for
/// [`DeployerHunter::leaderboard`](crate::api::deployer_hunter::DeployerHunter::leaderboard).
#[derive(Debug, Clone, Default, Serialize)]
pub struct DeployerLeaderboardParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<DeployerLeaderboardSort>,
    /// Filter to one reputation tier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tier: Option<DeployerTier>,
    /// Minimum tokens deployed (1..=100000, default 3). Note that `elite`/`good`
    /// themselves require ≥5 launches **and** 24h of deployer history.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_tokens: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u32>,
}

/// A single deployer on the reputation leaderboard.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcDeployerRow {
    /// Deployer wallet (lowercase 0x).
    pub deployer_address: String,
    pub tokens_deployed: i64,
    /// Tokens that reached a $40K+ peak MC (the graduation milestone).
    pub graduated: i64,
    /// `graduated ÷ tokens_deployed` — the $40K bar. Still returned, but it no
    /// longer sets `tier` (only `spammer` still keys off it).
    pub graduation_rate: f64,
    /// Tokens that peaked ≥ $100K MC.
    pub runners: i64,
    /// `runners ÷ tokens_deployed` — the $100K bar. This is what `tier` rides
    /// on (migrations 267 + 269).
    pub runner_rate: f64,
    #[serde(default)]
    pub best_peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub launchpads: Vec<String>,
    #[serde(default)]
    pub first_deploy_at: Option<String>,
    #[serde(default)]
    pub last_deploy_at: Option<String>,
    pub tier: String,
}

/// Response of
/// [`DeployerHunter::leaderboard`](crate::api::deployer_hunter::DeployerHunter::leaderboard).
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerLeaderboardResponse {
    pub chain: String,
    pub deployers: Vec<RhcDeployerRow>,
    /// The filtered deployer count; page with limit/offset until `has_more` is false.
    pub total: i64,
    pub limit: i64,
    pub offset: i64,
    pub has_more: bool,
}

// ─── Deployer-hunter: single profile ─────────────────────────────────────────

/// One deployer's full reputation row.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcDeployer {
    pub deployer_address: String,
    pub tokens_deployed: i64,
    pub curve_tokens: i64,
    pub graduated: i64,
    #[serde(default)]
    pub bonding_rate: Option<f64>,
    pub runners: i64,
    /// `runners ÷ tokens_deployed` — the $100K bar that `tier` rides on.
    pub runner_rate: f64,
    #[serde(default)]
    pub best_peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub launchpads: Vec<String>,
    #[serde(default)]
    pub first_deploy_at: Option<String>,
    #[serde(default)]
    pub last_deploy_at: Option<String>,
    pub tier: String,
}

/// One recent token by a deployer.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcDeployerToken {
    pub address: String,
    #[serde(default)]
    pub symbol: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub graduated_at: Option<String>,
    #[serde(default)]
    pub graduated_pool: Option<String>,
    #[serde(default)]
    pub first_seen_at: Option<String>,
    /// Live market cap.
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    /// All-time-high MC observed since ingestion.
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_at: Option<String>,
}

/// Response of
/// [`DeployerHunter::profile`](crate::api::deployer_hunter::DeployerHunter::profile).
///
/// Unknown wallets return 200 with `is_deployer: false` (not a 404).
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerProfileResponse {
    pub chain: String,
    /// False if this wallet has never deployed a tracked token (`deployer` is then null).
    pub is_deployer: bool,
    pub address: String,
    #[serde(default)]
    pub deployer: Option<RhcDeployer>,
    /// Up to 50 most recent tokens by this deployer.
    #[serde(default)]
    pub recent_tokens: Vec<RhcDeployerToken>,
    /// Rows returned (capped at 50) — the true total is `deployer.tokens_deployed`.
    #[serde(default)]
    pub recent_tokens_count: i64,
}

// ─── Deployer-hunter: trajectory ─────────────────────────────────────────────

/// The trailing run at the end of a deployer's (chronological) launch history.
#[derive(Debug, Clone, Deserialize)]
pub struct TrajectoryStreak {
    /// `bond` (a graduation) | `fail` | `none`. Field names keep the Solana
    /// `bond` wording so the two chains stay drop-in compatible.
    #[serde(rename = "type")]
    pub kind: String,
    pub count: i64,
}

/// One rolling 10-launch window.
#[derive(Debug, Clone, Deserialize)]
pub struct TrajectoryWindow {
    /// 1-based index of the launch that closes this window.
    pub window_end: i64,
    /// Share of the window's launches that graduated (0–1).
    pub bond_rate: f64,
}

/// The best or worst rolling 10-launch stretch.
#[derive(Debug, Clone, Deserialize)]
pub struct TrajectoryStretch {
    pub start_index: i64,
    pub end_index: i64,
    pub bond_rate: f64,
}

/// A deployer's launch quality over time.
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerTrajectory {
    pub current_streak: TrajectoryStreak,
    pub longest_bond_streak: i64,
    pub longest_fail_streak: i64,
    /// Rolling 10-launch success rates, oldest window first.
    #[serde(default)]
    pub rolling_bond_rates: Vec<TrajectoryWindow>,
    /// Latest rolling rate vs the lifetime rate, ±0.05.
    pub trend: TrajectoryTrend,
    #[serde(default)]
    pub avg_days_between_deploys: Option<f64>,
    /// Average launches burned between a miss and the next hit.
    #[serde(default)]
    pub avg_recovery_tokens: Option<f64>,
    #[serde(default)]
    pub best_stretch: Option<TrajectoryStretch>,
    #[serde(default)]
    pub worst_stretch: Option<TrajectoryStretch>,
    pub total_tokens_analyzed: i64,
}

/// Response of
/// [`DeployerHunter::trajectory`](crate::api::deployer_hunter::DeployerHunter::trajectory).
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerTrajectoryResponse {
    pub chain: String,
    /// False if this wallet has never deployed a tracked token.
    pub is_deployer: bool,
    pub address: String,
    #[serde(default)]
    pub deployer: Option<RhcDeployerRow>,
    /// What was actually counted per token: the $40K peak-MC graduation
    /// milestone — NOT the $100K runner bar that TIERS ride on.
    #[serde(default)]
    pub success_metric: Option<String>,
    /// `None` for an unknown wallet.
    #[serde(default)]
    pub trajectory: Option<DeployerTrajectory>,
    /// True when the analysis hit the 500-launch cap, so the curve is not the
    /// whole history.
    #[serde(default)]
    pub truncated: bool,
}

// ─── Deployer-hunter: launch history (paginated) ─────────────────────────────

/// Query parameters for
/// [`DeployerHunter::tokens`](crate::api::deployer_hunter::DeployerHunter::tokens).
#[derive(Debug, Clone, Default, Serialize)]
pub struct DeployerTokensParams {
    /// Page size (1..=100, default 50).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Page offset (0..=10000, default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<DeployerTokensSort>,
}

/// One token in a deployer's paginated launch history.
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerTokenRow {
    pub address: String,
    #[serde(default)]
    pub symbol: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    /// How the deployer was attributed for this token.
    #[serde(default)]
    pub deployer_source: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub graduated_at: Option<String>,
    #[serde(default)]
    pub first_seen_at: Option<String>,
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_at: Option<String>,
    #[serde(default)]
    pub liquidity_usd: Option<f64>,
}

/// Response of
/// [`DeployerHunter::tokens`](crate::api::deployer_hunter::DeployerHunter::tokens).
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerTokensResponse {
    pub chain: String,
    pub is_deployer: bool,
    pub address: String,
    #[serde(default)]
    pub deployer: Option<RhcDeployerRow>,
    #[serde(default)]
    pub tokens: Vec<DeployerTokenRow>,
    /// The deployer's lifetime launch count — page until `has_more` is false.
    pub total: i64,
    pub limit: i64,
    pub offset: i64,
    pub has_more: bool,
    #[serde(default)]
    pub sort: Option<String>,
    /// `"page"` when `sort = peak_mc_usd` — the ordering was applied to this page
    /// only, not the whole history.
    #[serde(default)]
    pub sort_scope: Option<String>,
}

// ─── Deployer-hunter: best tokens ────────────────────────────────────────────

/// Query parameters for
/// [`DeployerHunter::best_tokens`](crate::api::deployer_hunter::DeployerHunter::best_tokens).
#[derive(Debug, Clone, Default, Serialize)]
pub struct BestTokensParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub period: Option<BestTokensPeriod>,
    /// Max tokens (1..=50, default 10).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
}

/// Reputation block on a best-tokens row.
#[derive(Debug, Clone, Deserialize)]
pub struct BestTokenDeployer {
    pub address: String,
    /// `elite` or `good` — earned on the $100K `runner_rate`.
    pub tier: String,
    /// The $40K bar. Returned, but it no longer sets the tier.
    #[serde(default)]
    pub graduation_rate: Option<f64>,
    #[serde(default)]
    pub runner_rate: Option<f64>,
    pub tokens_deployed: i64,
}

/// A token launched in the window by a currently-reputable deployer.
#[derive(Debug, Clone, Deserialize)]
pub struct BestToken {
    pub address: String,
    #[serde(default)]
    pub symbol: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub first_seen_at: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_at: Option<String>,
    #[serde(default)]
    pub liquidity_usd: Option<f64>,
    #[serde(default)]
    pub deployer: Option<BestTokenDeployer>,
}

/// Response of
/// [`DeployerHunter::best_tokens`](crate::api::deployer_hunter::DeployerHunter::best_tokens).
#[derive(Debug, Clone, Deserialize)]
pub struct BestTokensResponse {
    pub chain: String,
    /// Ranked by peak MC, descending.
    pub tokens: Vec<BestToken>,
    pub period: String,
    pub limit: i64,
    /// Size of the elite/good deployer population the window was drawn from.
    pub reputable_deployers: i64,
    /// Launches considered before ranking. Absent when the population was empty.
    #[serde(default)]
    pub candidates_scanned: Option<i64>,
    /// True when the top-N was drawn from the 1000 most RECENT launches in the
    /// period rather than the whole period.
    #[serde(default)]
    pub truncated: bool,
}

// ─── Deployer-hunter: chain-wide stats ───────────────────────────────────────

/// Population of one reputation tier.
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerTierCount {
    pub deployers: i64,
    pub tokens: i64,
}

/// The ACTIVE tier thresholds, so you can see what `elite` currently means
/// instead of guessing from the label.
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerTierRules {
    /// Earned on the $100K `runner_rate` (migrations 267 + 269).
    #[serde(default)]
    pub elite: Option<String>,
    #[serde(default)]
    pub good: Option<String>,
    /// The one tier still keyed off `graduation_rate` — detecting trash is a
    /// different question from detecting quality.
    #[serde(default)]
    pub spammer: Option<String>,
    #[serde(default)]
    pub neutral: Option<String>,
}

/// Response of
/// [`DeployerHunter::stats`](crate::api::deployer_hunter::DeployerHunter::stats).
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerStatsResponse {
    pub chain: String,
    pub total_deployers: i64,
    pub total_tokens: i64,
    /// `elite` + `good` deployers.
    pub reputable_deployers: i64,
    /// Tier name → population.
    #[serde(default)]
    pub by_tier: HashMap<String, DeployerTierCount>,
    /// Share of all indexed tokens deployed by `spammer`-tier wallets.
    #[serde(default)]
    pub spam_token_share: Option<f64>,
    pub alerts_24h: i64,
    pub alerts_7d: i64,
    pub tier_rules: DeployerTierRules,
    /// `"peak market cap >= $40,000"`.
    pub graduation_definition: String,
    /// `"peak market cap >= $100,000"`.
    pub runner_definition: String,
}

// ─── Deployer-hunter: alerts ─────────────────────────────────────────────────

/// Query parameters for
/// [`DeployerHunter::alerts`](crate::api::deployer_hunter::DeployerHunter::alerts).
#[derive(Debug, Clone, Default, Serialize)]
pub struct DeployerAlertsParams {
    /// Matched against the READ-TIME `tier`, not the snapshot, so the filter and
    /// the payload always agree.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deployer_tier: Option<DeployerTier>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub priority: Option<DeployerAlertPriority>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alert_type: Option<DeployerAlertType>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub launchpad: Option<String>,
    /// Minimum market cap at alert time (USD).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_mc: Option<f64>,
    /// `true` disables the default $100 liquidity floor and returns the raw tape.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_untradeable: Option<bool>,
    /// ISO 8601 — only alerts with `event_at` strictly newer. The
    /// incremental-polling idiom: pass back `next_event_at`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since: Option<String>,
    /// ISO 8601 cursor — only alerts strictly older. Takes precedence over
    /// `offset`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Max alerts (1..=500, default 50). BASIC/PRO are capped at 50; only ULTRA
    /// gets the full requested limit.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Page offset (0..=10000, default 0). Ignored when `before` is set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u32>,
}

/// A single deployer alert.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcDeployerAlert {
    pub id: String,
    pub deployer_address: String,
    #[serde(default)]
    pub token_address: Option<String>,
    #[serde(default)]
    pub token_symbol: Option<String>,
    #[serde(default)]
    pub token_name: Option<String>,
    pub alert_type: DeployerAlertType,
    #[serde(default)]
    pub title: Option<String>,
    /// Restated at read time in terms of the $100K runner rate for elite/good
    /// deployers, replacing snapshot copy that quoted the $40K graduation rate.
    #[serde(default)]
    pub message: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    /// The deployer's CURRENT tier, resolved at read time — not the snapshot.
    #[serde(default)]
    pub tier: Option<String>,
    /// The snapshot written when the alert fired.
    #[serde(default)]
    pub tier_at_alert: Option<String>,
    /// True when `tier` and `tier_at_alert` disagree.
    #[serde(default)]
    pub tier_is_stale: bool,
    #[serde(default)]
    pub mc_at_alert: Option<f64>,
    #[serde(default)]
    pub current_mc_usd: Option<f64>,
    /// Live liquidity — what the tradability filter gates on.
    #[serde(default)]
    pub liquidity_usd: Option<f64>,
    pub priority: DeployerAlertPriority,
    pub is_active: bool,
    pub created_at: String,
    /// When the on-chain event actually happened. This is the ordering key.
    #[serde(default)]
    pub event_at: Option<String>,
}

/// Response of
/// [`DeployerHunter::alerts`](crate::api::deployer_hunter::DeployerHunter::alerts).
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerAlertsResponse {
    pub chain: String,
    pub alerts: Vec<RhcDeployerAlert>,
    pub limit: i64,
    pub offset: i64,
    /// The active setting, echoed back — `"liquidity_usd >= $100"` or
    /// `"off (include_untradeable=true)"`.
    pub tradability_filter: String,
    /// Newest `event_at` on this page — pass as `since` to poll forward.
    #[serde(default)]
    pub next_event_at: Option<String>,
    /// Oldest `event_at` on this page — pass as `before` to page backwards.
    #[serde(default)]
    pub next_before: Option<String>,
    #[serde(default)]
    pub data_age_seconds: Option<i64>,
}

// ─── Deployer-hunter: deploy history (PRO+) ──────────────────────────────────

/// Query parameters for
/// [`DeployerHunter::history`](crate::api::deployer_hunter::DeployerHunter::history).
#[derive(Debug, Clone, Default, Serialize)]
pub struct DeployerHistoryParams {
    /// Page size (1..=1000, default 100).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Page offset (0..=100000, default 0).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u32>,
}

/// One token in a deployer's deploy history.
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerHistoryToken {
    pub address: String,
    #[serde(default)]
    pub symbol: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub graduated_at: Option<String>,
    #[serde(default)]
    pub graduated_pool: Option<String>,
    #[serde(default)]
    pub first_seen_at: Option<String>,
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_at: Option<String>,
}

/// Response of
/// [`DeployerHunter::history`](crate::api::deployer_hunter::DeployerHunter::history).
#[derive(Debug, Clone, Deserialize)]
pub struct DeployerHistoryResponse {
    pub chain: String,
    pub is_deployer: bool,
    pub address: String,
    #[serde(default)]
    pub deployer: Option<RhcDeployerRow>,
    /// Newest first, with a stable tiebreaker so pages never overlap or skip.
    #[serde(default)]
    pub tokens: Vec<DeployerHistoryToken>,
    /// Exact count.
    pub total: i64,
    pub limit: i64,
    pub offset: i64,
    pub has_more: bool,
}

// ─── Deployer-hunter: recent graduations ─────────────────────────────────────

/// Query parameters for
/// [`DeployerHunter::recent_bonds`](crate::api::deployer_hunter::DeployerHunter::recent_bonds).
#[derive(Debug, Clone, Default, Serialize)]
pub struct RecentBondsParams {
    /// Filter by the deployer's tier. Tiers ride the $100K runner rate, not the
    /// $40K graduation bar this feed is keyed on.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deployer_tier: Option<DeployerTier>,
    /// Raise the peak-MC floor (USD). Never lowers it below $40K.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_peak: Option<f64>,
    /// Max tokens (1..=200, default 50).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
}

/// A token that crossed the $40K peak-MC graduation milestone.
#[derive(Debug, Clone, Deserialize)]
pub struct RecentBondToken {
    pub address: String,
    #[serde(default)]
    pub symbol: Option<String>,
    #[serde(default)]
    pub name: Option<String>,
    #[serde(default)]
    pub launchpad: Option<String>,
    #[serde(default)]
    pub is_graduated: Option<bool>,
    #[serde(default)]
    pub deployer_address: Option<String>,
    #[serde(default)]
    pub deployer_tier: Option<String>,
    #[serde(default)]
    pub first_seen_at: Option<String>,
    #[serde(default)]
    pub market_cap_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_usd: Option<f64>,
    #[serde(default)]
    pub peak_mc_at: Option<String>,
}

/// Response of
/// [`DeployerHunter::recent_bonds`](crate::api::deployer_hunter::DeployerHunter::recent_bonds).
#[derive(Debug, Clone, Deserialize)]
pub struct RecentBondsResponse {
    pub chain: String,
    /// The graduation milestone in USD — 40000.
    pub graduation_mc: i64,
    /// Newest peak first.
    pub tokens: Vec<RecentBondToken>,
    pub limit: i64,
    /// Newest peak timestamp on this page (informational).
    #[serde(default)]
    pub next_peak_mc_at: Option<String>,
}

// ─── Alpha wallets ───────────────────────────────────────────────────────────

/// Query parameters for
/// [`AlphaWallets::list`](crate::api::alpha_wallets::AlphaWallets::list).
#[derive(Debug, Clone, Default, Serialize)]
pub struct AlphaWalletsParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub classification: Option<AlphaClassification>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub identity: Option<AlphaIdentity>,
    /// Minimum share of trades in launchpad memecoins (0–1).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_memecoin_share: Option<f64>,
    /// Maximum average market cap traded — filter to low-cap degens.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_avg_mc_usd: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_net_eth: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_win_rate: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_win_rate: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_trades: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_tokens: Option<u32>,
    /// Minimum ETH deployed (whale/size filter).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_buy_eth: Option<f64>,
    /// Only wallets that traded within the last N hours (1..=720).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active_hours: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort: Option<AlphaSort>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<SortOrder>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub offset: Option<u32>,
}

/// A single smart-money wallet on Robinhood Chain.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcAlphaWallet {
    /// Trader EOA (lowercase 0x).
    pub wallet: String,
    /// `bot` | `smart_money` | `trader`.
    pub classification: String,
    pub is_known_kol: bool,
    pub trades: i64,
    pub tokens: i64,
    pub buy_eth: f64,
    pub sell_eth: f64,
    /// Realized net flow (sell − buy).
    pub net_eth: f64,
    #[serde(default)]
    pub win_rate: Option<f64>,
    /// Share of trades in launchpad memecoins (vs tokenized stocks/stables).
    #[serde(default)]
    pub memecoin_share: Option<f64>,
    #[serde(default)]
    pub avg_trade_mc_usd: Option<f64>,
    #[serde(default)]
    pub last_trade_at: Option<String>,
}

/// Response of
/// [`AlphaWallets::list`](crate::api::alpha_wallets::AlphaWallets::list).
#[derive(Debug, Clone, Deserialize)]
pub struct AlphaWalletsResponse {
    pub chain: String,
    pub wallets: Vec<RhcAlphaWallet>,
    pub total: i64,
    pub limit: i64,
    pub offset: i64,
    pub has_more: bool,
}

// ─── Streaming ───────────────────────────────────────────────────────────────

/// A 24-hour WebSocket streaming token, as returned by
/// [`Stream::get_token`](crate::api::stream::Stream::get_token).
///
/// Subscribe to the Robinhood Chain channels [`RHC_KOL_TRADES`](crate::api::stream::RHC_KOL_TRADES),
/// [`RHC_DEX_TRADES`](crate::api::stream::RHC_DEX_TRADES) (ULTRA+), or the four
/// rule-engine channels after connecting to `ws_url`.
#[derive(Debug, Clone, Deserialize)]
pub struct StreamToken {
    pub token: String,
    pub expires_at: String,
    #[serde(default)]
    pub next_refresh_at: Option<String>,
    pub ws_url: String,
    /// Only present for ULTRA-tier subscribers.
    #[serde(default)]
    pub dex_ws_url: Option<String>,
    #[serde(default)]
    pub usage: Option<String>,
    #[serde(default, rename = "_rid")]
    pub _rid: Option<String>,
}

/// A single live WebSocket session for your account.
#[derive(Debug, Clone, Deserialize)]
pub struct StreamSession {
    /// Numeric session id (serialized as a string). Pass to
    /// [`Stream::kill_session`](crate::api::stream::Stream::kill_session).
    pub id: String,
    /// Originating service: `"ws-streaming"` or `"dex-stream"`.
    pub service: String,
    pub tier: String,
    pub channels: Vec<String>,
    pub connected_at: String,
    #[serde(default)]
    pub remote_ip: Option<String>,
    /// Messages pushed to this socket so far.
    pub messages_sent: u64,
}

/// Response of [`Stream::sessions`](crate::api::stream::Stream::sessions).
#[derive(Debug, Clone, Deserialize)]
pub struct StreamSessionsResponse {
    pub sessions: Vec<StreamSession>,
    pub count: u32,
    #[serde(default, rename = "_rid")]
    pub _rid: Option<String>,
}

/// Response of [`Stream::kill_session`](crate::api::stream::Stream::kill_session).
#[derive(Debug, Clone, Deserialize)]
pub struct StreamSessionEvicted {
    pub evicted: bool,
    pub id: String,
    #[serde(default, rename = "_rid")]
    pub _rid: Option<String>,
}

// ─── Rule engines: shared ────────────────────────────────────────────────────

/// Where a fired rule is delivered.
///
/// [`Websocket`](Self::Websocket) needs no `webhook_url`; anything else requires
/// one (HTTPS only, SSRF-checked server-side).
///
/// ⚠️ A `webhook_secret` is minted **once**, at creation, and keys off whether a
/// `webhook_url` was supplied — NOT off `delivery_mode`. Sending
/// `delivery_mode: Websocket` together with a `webhook_url` still mints one.
/// Webhook payloads are signed HMAC-SHA256 over `<timestamp>.<body>` in the
/// `X-MadeOnSol-Signature` header.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum DeliveryMode {
    Webhook,
    Websocket,
    Both,
}

impl DeliveryMode {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Webhook => "webhook",
            Self::Websocket => "websocket",
            Self::Both => "both",
        }
    }
}

/// Response of every rule-engine `DELETE`.
///
/// `deleted` is always `true` — a delete that matched nothing returns a 404
/// [`Error::Api`](crate::Error) instead.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcDeletedResponse {
    /// Always `"robinhood"`.
    pub chain: String,
    pub deleted: bool,
}

// ─── Rule engine: copy-trade subscriptions ───────────────────────────────────

/// Which side of the tape a copy-trade rule reacts to.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum CopyTradeOnlyAction {
    Buy,
    Sell,
    Both,
}

impl CopyTradeOnlyAction {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Buy => "buy",
            Self::Sell => "sell",
            Self::Both => "both",
        }
    }
}

/// How the suggested size is derived from the source trade.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum CopyTradeSizingMode {
    /// `sizing_amount` is a flat ETH size.
    Fixed,
    /// `sizing_amount` multiplies the source trade's ETH size.
    Proportional,
    /// `sizing_amount` is a percentage of the source trade's ETH size.
    PercentSource,
}

impl CopyTradeSizingMode {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Fixed => "fixed",
            Self::Proportional => "proportional",
            Self::PercentSource => "percent_source",
        }
    }
}

/// One Robinhood Chain copy-trade rule.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcCopyTradeSubscription {
    /// Numeric identity primary key (bigint).
    pub id: i64,
    #[serde(default)]
    pub name: Option<String>,
    /// Lowercase `0x` wallets this rule follows — the API lowercases on write.
    /// Never empty.
    pub source_wallets: Vec<String>,
    /// Minimum source-trade size, in ETH, for the rule to fire.
    pub min_trade_eth: f64,
    pub only_action: CopyTradeOnlyAction,
    pub sizing_mode: CopyTradeSizingMode,
    /// ETH when `sizing_mode` is [`Fixed`](CopyTradeSizingMode::Fixed), else the
    /// multiplier / percentage applied to the source trade.
    pub sizing_amount: f64,
    pub delivery_mode: DeliveryMode,
    #[serde(default)]
    pub webhook_url: Option<String>,
    pub is_active: bool,
    pub created_at: String,
    pub updated_at: String,
}

/// Response of [`CopyTrade::list`](crate::api::copytrade::CopyTrade::list).
#[derive(Debug, Clone, Deserialize)]
pub struct CopyTradeListResponse {
    /// Always `"robinhood"`.
    pub chain: String,
    pub subscriptions: Vec<RhcCopyTradeSubscription>,
}

/// Body for [`CopyTrade::create`](crate::api::copytrade::CopyTrade::create).
///
/// `source_wallets` and `sizing_amount` are required; every other field takes a
/// server-side default. Unknown keys are **rejected with a 400**, not ignored.
///
/// There is **no market-cap band** here, unlike the Solana copy-trade rule: the
/// RHC notify payload carries no market cap, so a band could only be a per-event
/// DB lookup in the hot path of a ~3.3M-trades/day chain.
#[derive(Debug, Clone, Default, Serialize)]
pub struct CopyTradeCreateParams {
    /// 1..=64 characters.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Required. 1..=250 EVM addresses (`0x`, 40 hex), lowercased on write. The
    /// per-tier wallet cap is enforced server-side (PRO 5 / ULTRA 50 /
    /// BUSINESS 250) and a breach is a 400.
    pub source_wallets: Vec<String>,
    /// Minimum source-trade size in ETH, `>= 0`. Default 0.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_trade_eth: Option<f64>,
    /// Default [`Buy`](CopyTradeOnlyAction::Buy).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub only_action: Option<CopyTradeOnlyAction>,
    /// Default [`Fixed`](CopyTradeSizingMode::Fixed).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sizing_mode: Option<CopyTradeSizingMode>,
    /// Required, strictly `> 0` — ETH size, or the multiplier / percentage, per
    /// `sizing_mode`.
    pub sizing_amount: f64,
    /// Default [`Webhook`](DeliveryMode::Webhook).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub delivery_mode: Option<DeliveryMode>,
    /// HTTPS only. Required unless `delivery_mode` is
    /// [`Websocket`](DeliveryMode::Websocket).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<String>,
}

/// Response of [`CopyTrade::create`](crate::api::copytrade::CopyTrade::create).
#[derive(Debug, Clone, Deserialize)]
pub struct CopyTradeCreateResponse {
    pub chain: String,
    pub subscription: RhcCopyTradeSubscription,
    /// Shown **once** — store it now, it is never returned again. `None` when no
    /// `webhook_url` was supplied.
    #[serde(default)]
    pub webhook_secret: Option<String>,
    /// Either the "save the secret" note, or the name of the WebSocket channel
    /// to subscribe to (`rhc:copytrade:signals`).
    pub note: String,
}

/// Response of [`CopyTrade::get`](crate::api::copytrade::CopyTrade::get) and
/// [`CopyTrade::update`](crate::api::copytrade::CopyTrade::update).
#[derive(Debug, Clone, Deserialize)]
pub struct CopyTradeGetResponse {
    pub chain: String,
    pub subscription: RhcCopyTradeSubscription,
}

/// Body for [`CopyTrade::update`](crate::api::copytrade::CopyTrade::update).
///
/// Omitted fields are left untouched; an all-empty body is a 400.
///
/// `name` and `webhook_url` are nullable on the wire, so they are
/// `Option<Option<String>>`: `None` omits the key entirely, `Some(None)` sends
/// an explicit `null` (clears the value), `Some(Some(v))` sets it. Clearing
/// `webhook_url` while `delivery_mode` still requires one is rejected by the
/// database, so clear both together.
#[derive(Debug, Clone, Default, Serialize)]
pub struct CopyTradeUpdateParams {
    /// `Some(None)` clears the label. 1..=64 characters otherwise.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<Option<String>>,
    /// The per-tier wallet cap is re-checked, so a PRO rule cannot be PATCHed
    /// past its limit.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source_wallets: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_trade_eth: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub only_action: Option<CopyTradeOnlyAction>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sizing_mode: Option<CopyTradeSizingMode>,
    /// Strictly `> 0`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sizing_amount: Option<f64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub delivery_mode: Option<DeliveryMode>,
    /// `Some(None)` clears the webhook URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<Option<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_active: Option<bool>,
}

// ─── Rule engine: copy-trade signals ─────────────────────────────────────────

/// Query parameters for
/// [`CopyTrade::signals`](crate::api::copytrade::CopyTrade::signals).
#[derive(Debug, Clone, Default, Serialize)]
pub struct CopyTradeSignalsParams {
    /// Scope to one of your rules — 404 if you do not own it.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subscription_id: Option<i64>,
    /// ISO 8601 lower bound on `fired_at`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since: Option<String>,
    /// 1..=500, default 50.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
}

/// One fired copy-trade signal.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcCopyTradeSignal {
    pub id: i64,
    pub subscription_id: i64,
    pub fired_at: String,
    /// The followed wallet whose trade triggered the fire.
    pub source_wallet: String,
    pub action: TradeAction,
    pub token_address: String,
    #[serde(default)]
    pub token_symbol: Option<String>,
    #[serde(default)]
    pub token_name: Option<String>,
    /// Size of the source trade, in ETH.
    #[serde(default)]
    pub source_eth_amount: Option<f64>,
    /// Size your rule's `sizing_mode` implies, in ETH.
    #[serde(default)]
    pub suggested_eth_amount: Option<f64>,
    #[serde(default)]
    pub price_usd: Option<f64>,
    #[serde(default)]
    pub dex: Option<String>,
    pub tx_hash: String,
    pub delivered: bool,
    #[serde(default)]
    pub delivered_at: Option<String>,
}

/// Response of [`CopyTrade::signals`](crate::api::copytrade::CopyTrade::signals).
#[derive(Debug, Clone, Default, Deserialize)]
pub struct CopyTradeSignalsResponse {
    pub chain: String,
    pub signals: Vec<RhcCopyTradeSignal>,
    /// ⚠️ The API **omits** this key when you own no copy-trade rules at all, so
    /// it defaults to 0 rather than failing to parse.
    #[serde(default)]
    pub count: u32,
}

// ─── Rule engine: price alerts ───────────────────────────────────────────────

/// Lifecycle of a price alert. `Recovered` and `Expired` are terminal.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum PriceAlertStatus {
    Watching,
    Dipped,
    Recovered,
    Expired,
}

impl PriceAlertStatus {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Watching => "watching",
            Self::Dipped => "dipped",
            Self::Recovered => "recovered",
            Self::Expired => "expired",
        }
    }
}

/// One Robinhood Chain price alert.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcPriceAlert {
    pub id: i64,
    #[serde(default)]
    pub name: Option<String>,
    pub token_address: String,
    #[serde(default)]
    pub token_symbol: Option<String>,
    /// Market cap captured at creation — the alert is a delta from the moment
    /// you set it, not from the token's all-time anything.
    pub baseline_mc_usd: f64,
    pub drop_pct: f64,
    /// `None` for a dip-only, terminal alert.
    #[serde(default)]
    pub recovery_pct: Option<f64>,
    pub status: PriceAlertStatus,
    /// Lowest market cap seen since the dip fired.
    #[serde(default)]
    pub dip_low_mc_usd: Option<f64>,
    #[serde(default)]
    pub dip_fired_at: Option<String>,
    pub delivery_mode: DeliveryMode,
    #[serde(default)]
    pub webhook_url: Option<String>,
    pub is_active: bool,
    /// Alerts self-expire 30 days after creation.
    pub expires_at: String,
    pub created_at: String,
    pub updated_at: String,
}

/// Response of [`PriceAlerts::list`](crate::api::price_alerts::PriceAlerts::list).
#[derive(Debug, Clone, Deserialize)]
pub struct PriceAlertListResponse {
    pub chain: String,
    pub alerts: Vec<RhcPriceAlert>,
}

/// Body for
/// [`PriceAlerts::create`](crate::api::price_alerts::PriceAlerts::create).
///
/// Unknown keys are **rejected with a 400**, not ignored.
#[derive(Debug, Clone, Default, Serialize)]
pub struct PriceAlertCreateParams {
    /// 1..=64 characters.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Required, EVM address (`0x`, 40 hex). The token must already be tracked
    /// on Robinhood Chain **with a market cap** to baseline against, else 400.
    pub token_address: String,
    /// Required. 0.01..=99.99.
    pub drop_pct: f64,
    /// 0.01..=1000. Omit for a dip-only, terminal alert.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub recovery_pct: Option<f64>,
    /// Default [`Webhook`](DeliveryMode::Webhook).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub delivery_mode: Option<DeliveryMode>,
    /// HTTPS only. Required unless `delivery_mode` is
    /// [`Websocket`](DeliveryMode::Websocket).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<String>,
}

/// How Robinhood Chain price alerts are evaluated.
///
/// ⚠️ **Not parity with Solana.** RHC alerts are POLLED off `rhc_token_prices`
/// (`interval_seconds` ≈ 15) rather than reacting to a live sub-second price
/// loop, because the RHC price writer emits no `pg_notify`. Effective latency is
/// that interval plus the token's own price-update cadence.
#[derive(Debug, Clone, Deserialize)]
pub struct PriceAlertEvaluation {
    /// Always `"polled"`.
    pub mode: String,
    /// Poll interval in seconds (~15).
    pub interval_seconds: i64,
    pub note: String,
}

/// Response of
/// [`PriceAlerts::create`](crate::api::price_alerts::PriceAlerts::create).
#[derive(Debug, Clone, Deserialize)]
pub struct PriceAlertCreateResponse {
    pub chain: String,
    pub alert: RhcPriceAlert,
    /// Shown **once** — `None` when no `webhook_url` was supplied.
    #[serde(default)]
    pub webhook_secret: Option<String>,
    pub evaluation: PriceAlertEvaluation,
    /// Either the "save the secret" note, or the name of the WebSocket channel
    /// to subscribe to (`rhc:price_alert:events`).
    pub note: String,
}

/// Response of [`PriceAlerts::get`](crate::api::price_alerts::PriceAlerts::get)
/// and [`PriceAlerts::update`](crate::api::price_alerts::PriceAlerts::update).
#[derive(Debug, Clone, Deserialize)]
pub struct PriceAlertGetResponse {
    pub chain: String,
    pub alert: RhcPriceAlert,
}

/// Body for
/// [`PriceAlerts::update`](crate::api::price_alerts::PriceAlerts::update).
///
/// `token_address`, `drop_pct` and `recovery_pct` are **immutable** — retuning a
/// threshold mid-flight would make the alert's already-recorded events
/// uninterpretable. Delete and recreate instead; sending them is a 400.
///
/// `name` and `webhook_url` are nullable on the wire: `None` omits the key,
/// `Some(None)` sends an explicit `null`, `Some(Some(v))` sets it.
#[derive(Debug, Clone, Default, Serialize)]
pub struct PriceAlertUpdateParams {
    /// `Some(None)` clears the label.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<Option<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub delivery_mode: Option<DeliveryMode>,
    /// `Some(None)` clears the webhook URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<Option<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_active: Option<bool>,
}

// ─── Rule engine: price-alert events ─────────────────────────────────────────

/// Which leg of a price alert fired.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum PriceAlertEventType {
    Dip,
    Recovery,
}

impl PriceAlertEventType {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Dip => "dip",
            Self::Recovery => "recovery",
        }
    }
}

/// Query parameters for
/// [`PriceAlerts::events`](crate::api::price_alerts::PriceAlerts::events).
#[derive(Debug, Clone, Default, Serialize)]
pub struct PriceAlertEventsParams {
    /// Scope to one of your alerts — 404 if you do not own it.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alert_id: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_type: Option<PriceAlertEventType>,
    /// ISO 8601 lower bound on `fired_at`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since: Option<String>,
    /// 1..=500, default 50.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
}

/// One fired dip or recovery event.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcPriceAlertEvent {
    pub id: i64,
    pub alert_id: i64,
    pub event_type: PriceAlertEventType,
    pub fired_at: String,
    pub token_address: String,
    pub baseline_mc_usd: f64,
    pub current_mc_usd: f64,
    /// Measured drop at fire time, in percent.
    #[serde(default)]
    pub drop_pct_actual: Option<f64>,
    #[serde(default)]
    pub dip_low_mc_usd: Option<f64>,
    /// Measured bounce off the dip low, in percent — recovery events only.
    #[serde(default)]
    pub recovery_pct_actual: Option<f64>,
    pub delivered: bool,
    #[serde(default)]
    pub delivered_at: Option<String>,
}

/// Response of
/// [`PriceAlerts::events`](crate::api::price_alerts::PriceAlerts::events).
#[derive(Debug, Clone, Default, Deserialize)]
pub struct PriceAlertEventsResponse {
    pub chain: String,
    pub events: Vec<RhcPriceAlertEvent>,
    /// ⚠️ The API **omits** this key when you own no price alerts at all, so it
    /// defaults to 0 rather than failing to parse.
    #[serde(default)]
    pub count: u32,
}

// ─── Rule engine: KOL coordination alerts ────────────────────────────────────

/// One Robinhood Chain coordination rule.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcCoordinationAlertRule {
    /// UUID.
    pub id: String,
    #[serde(default)]
    pub name: Option<String>,
    /// Distinct tracked-KOL buyers needed to fire (2..=50).
    pub min_kols: i64,
    /// Rolling window those buys must land inside, in minutes (1..=60).
    pub window_minutes: i64,
    /// Minimum coordination score to fire (0..=100).
    pub min_score: i64,
    /// Minutes before the same token can fire again (1..=1440).
    pub cooldown_min: i64,
    /// Score jump that breaks the cooldown early (0..=100).
    pub score_jump_break: i64,
    #[serde(default)]
    pub min_mc_usd: Option<f64>,
    #[serde(default)]
    pub max_mc_usd: Option<f64>,
    pub delivery_mode: DeliveryMode,
    #[serde(default)]
    pub webhook_url: Option<String>,
    pub is_active: bool,
    pub created_at: String,
    pub updated_at: String,
}

/// Response of
/// [`Kol::coordination_alerts_list`](crate::api::kol::Kol::coordination_alerts_list).
#[derive(Debug, Clone, Deserialize)]
pub struct CoordinationAlertListResponse {
    pub chain: String,
    pub rules: Vec<RhcCoordinationAlertRule>,
}

/// Body for
/// [`Kol::coordination_alerts_create`](crate::api::kol::Kol::coordination_alerts_create).
///
/// Every field is optional — the server default is noted per field. The five
/// counters must be whole numbers, and `min_mc_usd` must be `<= max_mc_usd` when
/// both are set. Unknown keys are **rejected with a 400**, not ignored.
#[derive(Debug, Clone, Default, Serialize)]
pub struct CoordinationAlertCreateParams {
    /// 1..=64 characters.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// 2..=50, default 3.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_kols: Option<u32>,
    /// 1..=60, default 15.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub window_minutes: Option<u32>,
    /// 0..=100, default 0.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_score: Option<u32>,
    /// 1..=1440, default 30.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cooldown_min: Option<u32>,
    /// 0..=100, default 20.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub score_jump_break: Option<u32>,
    /// 0..=1e12. `Some(None)` sends an explicit `null` (no lower band).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_mc_usd: Option<Option<f64>>,
    /// 0..=1e12. `Some(None)` sends an explicit `null` (no upper band).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_mc_usd: Option<Option<f64>>,
    /// Default [`Websocket`](DeliveryMode::Websocket).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub delivery_mode: Option<DeliveryMode>,
    /// HTTPS only. Required unless `delivery_mode` is
    /// [`Websocket`](DeliveryMode::Websocket).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<String>,
}

/// Which scorer components are real on Robinhood Chain.
///
/// Scores are comparable to the Solana coordination scorer, but `earliness` is
/// defaulted (RHC has no early-entry equivalent) while `quality` is a real KOL
/// win-rate. Every fired signal records the same breakdown in its `score_inputs`.
#[derive(Debug, Clone, Deserialize)]
pub struct CoordinationAlertScoring {
    pub score_version: String,
    pub quality: String,
    pub earliness: String,
    pub note: String,
}

/// Response of
/// [`Kol::coordination_alerts_create`](crate::api::kol::Kol::coordination_alerts_create).
#[derive(Debug, Clone, Deserialize)]
pub struct CoordinationAlertCreateResponse {
    pub chain: String,
    pub rule: RhcCoordinationAlertRule,
    /// Shown **once** — `None` when no `webhook_url` was supplied.
    #[serde(default)]
    pub webhook_secret: Option<String>,
    pub scoring: CoordinationAlertScoring,
    /// Either the "save the secret" note, or the name of the WebSocket channel
    /// to subscribe to (`rhc:kol:coordination`).
    pub note: String,
}

/// Response of
/// [`Kol::coordination_alerts_get`](crate::api::kol::Kol::coordination_alerts_get)
/// and
/// [`Kol::coordination_alerts_update`](crate::api::kol::Kol::coordination_alerts_update).
#[derive(Debug, Clone, Deserialize)]
pub struct CoordinationAlertGetResponse {
    pub chain: String,
    pub rule: RhcCoordinationAlertRule,
}

/// Body for
/// [`Kol::coordination_alerts_update`](crate::api::kol::Kol::coordination_alerts_update).
///
/// Omitted fields are left untouched. `name`, `min_mc_usd`, `max_mc_usd` and
/// `webhook_url` are nullable on the wire: `None` omits the key, `Some(None)`
/// sends an explicit `null`, `Some(Some(v))` sets it.
///
/// ⚠️ The `min_mc_usd <= max_mc_usd` check only runs when **both** bounds are in
/// the same PATCH body; a one-sided PATCH that inverts the band is refused by
/// the database instead. Send both together.
#[derive(Debug, Clone, Default, Serialize)]
pub struct CoordinationAlertUpdateParams {
    /// `Some(None)` clears the label.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<Option<String>>,
    /// 2..=50.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_kols: Option<u32>,
    /// 1..=60.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub window_minutes: Option<u32>,
    /// 0..=100.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_score: Option<u32>,
    /// 1..=1440.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cooldown_min: Option<u32>,
    /// 0..=100.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub score_jump_break: Option<u32>,
    /// `Some(None)` clears the lower market-cap band.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_mc_usd: Option<Option<f64>>,
    /// `Some(None)` clears the upper market-cap band.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_mc_usd: Option<Option<f64>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub delivery_mode: Option<DeliveryMode>,
    /// `Some(None)` clears the webhook URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<Option<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_active: Option<bool>,
}

// ─── Rule engine: KOL first-touch subscriptions ──────────────────────────────

/// Auto-classified trading style of the first-touching KOL.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum FirstTouchStrategy {
    Scalper,
    DayTrader,
    Swing,
    Inactive,
    Unscored,
}

impl FirstTouchStrategy {
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::Scalper => "scalper",
            Self::DayTrader => "day_trader",
            Self::Swing => "swing",
            Self::Inactive => "inactive",
            Self::Unscored => "unscored",
        }
    }
}

/// Push filters on a first-touch subscription.
///
/// ⚠️ Deliberately **not** the Solana filter set: Robinhood Chain has no scout
/// score, so `min_scout_tier` / `min_n_touches` are absent rather than silently
/// matching nothing — [`min_kol_winrate`](Self::min_kol_winrate) and
/// [`strategy`](Self::strategy) are the quality gates. Unknown filter keys are
/// **rejected with a 400**, not ignored, and `min_mc_usd` must be
/// `<= max_mc_usd` when both are set.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct FirstTouchFilters {
    /// Only this KOL's first touches (`0x`, 40 hex) — lowercased on write.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub kol: Option<String>,
    /// Minimum first-buy size in ETH (0..=100000).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub min_first_buy_eth: Option<f64>,
    /// 0..=1. Win-rate on CLOSED positions — a KOL who has never sold is
    /// dropped, not counted as a loser.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub min_kol_winrate: Option<f64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub strategy: Option<FirstTouchStrategy>,
    /// 0..=1e12.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub min_mc_usd: Option<f64>,
    /// 0..=1e12.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max_mc_usd: Option<f64>,
}

/// One Robinhood Chain first-touch subscription.
#[derive(Debug, Clone, Deserialize)]
pub struct RhcFirstTouchSubscription {
    /// UUID.
    pub id: String,
    #[serde(default)]
    pub name: Option<String>,
    /// Never null — an unfiltered subscription carries an empty filter set.
    #[serde(default)]
    pub filters: FirstTouchFilters,
    pub delivery_mode: DeliveryMode,
    #[serde(default)]
    pub webhook_url: Option<String>,
    pub is_active: bool,
    pub created_at: String,
    pub updated_at: String,
}

/// Response of
/// [`Kol::first_touch_subscriptions_list`](crate::api::kol::Kol::first_touch_subscriptions_list).
#[derive(Debug, Clone, Deserialize)]
pub struct FirstTouchSubscriptionListResponse {
    pub chain: String,
    pub subscriptions: Vec<RhcFirstTouchSubscription>,
}

/// Body for
/// [`Kol::first_touch_subscriptions_create`](crate::api::kol::Kol::first_touch_subscriptions_create).
#[derive(Debug, Clone, Default, Serialize)]
pub struct FirstTouchSubscriptionCreateParams {
    /// 1..=64 characters.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Default `{}` — every first touch.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<FirstTouchFilters>,
    /// Default [`Websocket`](DeliveryMode::Websocket).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub delivery_mode: Option<DeliveryMode>,
    /// HTTPS only. Required unless `delivery_mode` is
    /// [`Websocket`](DeliveryMode::Websocket).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<String>,
}

/// Response of
/// [`Kol::first_touch_subscriptions_create`](crate::api::kol::Kol::first_touch_subscriptions_create).
#[derive(Debug, Clone, Deserialize)]
pub struct FirstTouchSubscriptionCreateResponse {
    pub chain: String,
    pub subscription: RhcFirstTouchSubscription,
    /// Shown **once** — `None` when no `webhook_url` was supplied.
    #[serde(default)]
    pub webhook_secret: Option<String>,
    /// Either the "save the secret" note, or the name of the WebSocket channel
    /// to subscribe to (`rhc:kol:first_touches`).
    pub note: String,
}

/// Response of
/// [`Kol::first_touch_subscriptions_get`](crate::api::kol::Kol::first_touch_subscriptions_get)
/// and
/// [`Kol::first_touch_subscriptions_update`](crate::api::kol::Kol::first_touch_subscriptions_update).
#[derive(Debug, Clone, Deserialize)]
pub struct FirstTouchSubscriptionGetResponse {
    pub chain: String,
    pub subscription: RhcFirstTouchSubscription,
}

/// Body for
/// [`Kol::first_touch_subscriptions_update`](crate::api::kol::Kol::first_touch_subscriptions_update).
///
/// `filters` is a whole-object **replace**, not a merge — merging would make
/// "remove this filter" inexpressible. It cannot be set to `null`; send
/// `Some(FirstTouchFilters::default())` to clear every filter.
///
/// `name` and `webhook_url` are nullable on the wire: `None` omits the key,
/// `Some(None)` sends an explicit `null`, `Some(Some(v))` sets it.
#[derive(Debug, Clone, Default, Serialize)]
pub struct FirstTouchSubscriptionUpdateParams {
    /// `Some(None)` clears the label.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<Option<String>>,
    /// Whole-object replace.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filters: Option<FirstTouchFilters>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub delivery_mode: Option<DeliveryMode>,
    /// `Some(None)` clears the webhook URL.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub webhook_url: Option<Option<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_active: Option<bool>,
}

// ── Wallet intelligence ──────────────────────────────────────────────────────
//
// Every figure here is denominated in **ETH**. Cost basis is FIFO over a rolling
// 90-day window, so "open" means FIFO-unmatched buys INSIDE that window — a
// position opened before it reads as a sell with no matching buy. That is what
// `cost_basis_observable_from` and `partial` disclose.

/// 90-day trade statistics for one wallet.
#[derive(Debug, Clone, Deserialize)]
pub struct WalletStats {
    pub first_seen: Option<String>,
    pub last_seen: Option<String>,
    pub total_trades: u64,
    /// Denominator for every PnL figure below.
    pub analyzed_trades: u64,
    /// Pre-2026-07-18 rows with a NULL `trader_eoa` — unattributable by design.
    pub unattributed_trades: u64,
    pub unsized_trades: u64,
    pub buys: u64,
    pub sells: u64,
    pub bought_eth: f64,
    pub sold_eth: f64,
    pub realized_pnl_eth: f64,
    pub unrealized_pnl_eth: f64,
    pub total_pnl_eth: f64,
    pub held_value_eth: f64,
    pub unique_tokens: u64,
    pub open_positions: u64,
    pub window_days: u32,
    /// Hit the per-wallet trade cap — figures cover part of the window only.
    pub partial: bool,
}

/// Reputation flags, resolved independently of the PnL snapshot.
#[derive(Debug, Clone, Deserialize)]
pub struct WalletFlags {
    pub is_kol: bool,
    pub kol_name: Option<String>,
    pub is_deployer: bool,
    pub deployer_tier: Option<String>,
    pub deployer_tokens: Option<u64>,
    pub deployer_runner_rate: Option<f64>,
    pub is_alpha_tracked: bool,
    pub alpha_win_rate: Option<f64>,
    pub alpha_net_eth: Option<f64>,
    pub alpha_tokens_traded: Option<u64>,
    pub likely_bot: Option<bool>,
    pub is_dumper: bool,
    #[serde(default)]
    pub dump_cluster: serde_json::Value,
    pub early_buyer_tokens: u64,
}

/// Convenience aggregates computed from [`WalletStats`].
#[derive(Debug, Clone, Deserialize)]
pub struct WalletDerived {
    pub win_rate: Option<f64>,
    pub wins: u64,
    pub losses: u64,
    pub avg_trade_size_eth: Option<f64>,
    pub is_active: bool,
}

/// Response for [`Wallet::profile`](crate::api::wallet::Wallet::profile).
#[derive(Debug, Clone, Deserialize)]
pub struct WalletProfileResponse {
    pub chain: String,
    pub address: String,
    pub stats: WalletStats,
    pub flags: WalletFlags,
    #[serde(default)]
    pub top_tokens: Vec<serde_json::Value>,
    #[serde(default)]
    pub recent_trades: Vec<serde_json::Value>,
    pub derived: WalletDerived,
    /// Snapshot timed out — `flags` still resolve.
    #[serde(default)]
    pub stats_unavailable: bool,
    /// The profile/pnl/positions trio shares one snapshot cache.
    #[serde(default)]
    pub cache_hit: bool,
}

/// One FIFO-unmatched buy position, marked to the current price.
#[derive(Debug, Clone, Deserialize)]
pub struct OpenPosition {
    pub token_address: String,
    pub token_symbol: Option<String>,
    pub token_name: Option<String>,
    pub launchpad: Option<String>,
    pub is_graduated: Option<bool>,
    pub token_amount: f64,
    pub cost_basis_eth: f64,
    pub avg_entry_price_eth: f64,
    pub current_price_eth: Option<f64>,
    pub current_value_eth: Option<f64>,
    pub unrealized_eth: Option<f64>,
    pub unrealized_pct: Option<f64>,
    pub current_mc_usd: Option<f64>,
    pub liquidity_usd: Option<f64>,
    /// `v4_virtual_ceiling` = bonding-curve ceiling, NOT withdrawable TVL —
    /// never size an exit against it. `measured` = real pool reserves.
    pub liquidity_basis: String,
    pub buys_in_position: u64,
    pub realized_so_far_eth: f64,
    pub first_buy_at: Option<String>,
    pub last_buy_at: Option<String>,
}

/// One fully-closed FIFO position.
#[derive(Debug, Clone, Deserialize)]
pub struct ClosedPosition {
    pub token_address: String,
    pub token_symbol: Option<String>,
    pub buy_count: u64,
    pub sell_count: u64,
    pub bought_eth: f64,
    pub sold_eth: f64,
    pub pnl_eth: f64,
    pub roi_pct: Option<f64>,
    pub hold_minutes: Option<i64>,
    /// `win` | `loss` | `breakeven`.
    pub result: String,
    pub first_trade: Option<String>,
    pub last_trade: Option<String>,
}

/// One day on the realized-PnL curve.
#[derive(Debug, Clone, Deserialize)]
pub struct PnlCurvePoint {
    pub date: String,
    pub day_pnl: f64,
    pub cumulative_pnl: f64,
    pub trades: u64,
}

/// Headline PnL aggregates.
#[derive(Debug, Clone, Deserialize)]
pub struct WalletPnlSummary {
    pub realized_eth: f64,
    pub unrealized_eth: f64,
    pub total_pnl_eth: f64,
    pub total_bought_eth: f64,
    pub total_sold_eth: f64,
    pub wins: u64,
    pub losses: u64,
    pub win_rate: Option<f64>,
    pub profit_factor: Option<f64>,
    pub avg_hold_minutes: Option<i64>,
    pub median_hold_minutes: Option<i64>,
    pub max_drawdown_eth: f64,
    pub open_positions_count: u64,
    pub closed_positions_count: u64,
    pub total_tokens_traded: u64,
    #[serde(default)]
    pub best_realized: serde_json::Value,
    #[serde(default)]
    pub worst_realized: serde_json::Value,
}

/// Disclosure block — read this before quoting any PnL total.
#[derive(Debug, Clone, Deserialize)]
pub struct WalletPnlNotes {
    /// Always `ETH`.
    pub denomination: String,
    /// Buys before this date are invisible to cost basis.
    pub cost_basis_observable_from: String,
    pub data_through: Option<String>,
    pub trades_seen: u64,
    pub trades_analyzed: u64,
    pub trades_unattributed: u64,
    pub trades_unsized: u64,
    pub partial: bool,
    #[serde(default)]
    pub partial_reason: String,
}

/// Response for [`Wallet::pnl`](crate::api::wallet::Wallet::pnl).
#[derive(Debug, Clone, Deserialize)]
pub struct WalletPnlResponse {
    pub chain: String,
    pub address: String,
    pub window_days: u32,
    pub summary: WalletPnlSummary,
    #[serde(default)]
    pub pnl_curve: Vec<PnlCurvePoint>,
    #[serde(default)]
    pub closed_positions: Vec<ClosedPosition>,
    #[serde(default)]
    pub open_positions: Vec<OpenPosition>,
    pub notes: WalletPnlNotes,
    #[serde(default)]
    pub cache_hit: bool,
}

/// Totals across the open book.
#[derive(Debug, Clone, Deserialize)]
pub struct WalletPositionsSummary {
    pub open_positions: u64,
    pub total_cost_basis_eth: f64,
    pub total_current_value_eth: f64,
    pub total_unrealized_eth: f64,
    /// Excluded from the value and unrealized totals.
    pub unpriced_positions: u64,
}

/// Response for [`Wallet::positions`](crate::api::wallet::Wallet::positions).
#[derive(Debug, Clone, Deserialize)]
pub struct WalletPositionsResponse {
    pub chain: String,
    pub address: String,
    pub window_days: u32,
    pub summary: WalletPositionsSummary,
    #[serde(default)]
    pub positions: Vec<OpenPosition>,
    #[serde(default)]
    pub notes: serde_json::Value,
}

/// Query parameters for [`Wallet::trades`](crate::api::wallet::Wallet::trades).
#[derive(Debug, Clone, Default, Serialize)]
pub struct WalletTradesParams {
    /// 1..=200, default 50.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    /// Opaque keyset cursor — the previous response's `next_before`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// ISO-8601 with offset.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub action: Option<TradeAction>,
    /// Restrict to one token address (0x, 40 hex).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub token: Option<String>,
}

/// One swap on a wallet's tape.
#[derive(Debug, Clone, Deserialize)]
pub struct WalletTrade {
    pub token_address: Option<String>,
    pub token_symbol: Option<String>,
    pub token_name: Option<String>,
    pub launchpad: Option<String>,
    pub action: Option<TradeAction>,
    pub eth_amount: Option<f64>,
    pub token_amount: Option<f64>,
    pub price_native: Option<f64>,
    pub price_usd: Option<f64>,
    pub mc_usd_at_trade: Option<f64>,
    pub dex: Option<String>,
    pub pool: Option<String>,
    pub router: Option<String>,
    pub method_selector: Option<String>,
    pub tx_hash: String,
    pub log_index: i64,
    pub block_number: u64,
    pub block_time: String,
}

/// Response for [`Wallet::trades`](crate::api::wallet::Wallet::trades).
#[derive(Debug, Clone, Deserialize)]
pub struct WalletTradesResponse {
    pub chain: String,
    pub address: String,
    #[serde(default)]
    pub trades: Vec<WalletTrade>,
    pub count: u64,
    pub has_more: bool,
    /// Opaque cursor for the next page — `None` when the tape is exhausted.
    pub next_before: Option<String>,
}

// ── Wallet tracker (watchlist) ───────────────────────────────────────────────
//
// Quotas are PER CHAIN: PRO 50 / ULTRA 100 / BUSINESS 500 RHC wallets,
// independent of the Solana watchlist. Addresses are lowercased on write so they
// match `rhc_trades.trader_eoa`.

/// One wallet on your watchlist.
#[derive(Debug, Clone, Deserialize)]
pub struct TrackedWallet {
    pub wallet_address: String,
    pub label: Option<String>,
    pub added_at: String,
}

/// Response for [`Wallet::watchlist`](crate::api::wallet::Wallet::watchlist).
#[derive(Debug, Clone, Deserialize)]
pub struct WalletTrackerListResponse {
    pub chain: String,
    #[serde(default)]
    pub wallets: Vec<TrackedWallet>,
    pub count: u64,
    /// Per-tier cap for this chain.
    pub limit: u64,
    pub remaining: u64,
}

/// Body for [`Wallet::track`](crate::api::wallet::Wallet::track).
#[derive(Debug, Clone, Serialize)]
pub struct WalletTrackerAddParams {
    pub wallet_address: String,
    /// 1–64 chars. Omit to leave unlabelled — `null` is rejected on add.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
}

/// Response carrying a single tracked wallet.
#[derive(Debug, Clone, Deserialize)]
pub struct WalletTrackerWalletResponse {
    pub chain: String,
    pub wallet: TrackedWallet,
}

/// Response for [`Wallet::untrack`](crate::api::wallet::Wallet::untrack).
#[derive(Debug, Clone, Deserialize)]
pub struct WalletTrackerRemovedResponse {
    pub chain: String,
    /// The lowercased address that was removed.
    pub removed: String,
}

/// Query parameters for the merged tracked-wallet tape.
#[derive(Debug, Clone, Default, Serialize)]
pub struct WalletTrackerTradesParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// Must already be on the watchlist.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub wallet: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub action: Option<TradeAction>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub token: Option<String>,
}

/// One swap on the merged tracked-wallet tape, tagged with its watchlist label.
#[derive(Debug, Clone, Deserialize)]
pub struct TrackedWalletTrade {
    #[serde(flatten)]
    pub trade: WalletTrade,
    /// Which tracked wallet made the trade.
    pub trader_eoa: Option<String>,
    /// Your watchlist label for that wallet.
    pub label: Option<String>,
}

/// Response for [`Wallet::tracked_trades`](crate::api::wallet::Wallet::tracked_trades).
#[derive(Debug, Clone, Deserialize)]
pub struct WalletTrackerTradesResponse {
    pub chain: String,
    #[serde(default)]
    pub trades: Vec<TrackedWalletTrade>,
    pub count: u64,
    pub has_more: bool,
    pub next_before: Option<String>,
}

/// Query parameters for the tracked-wallet rollup.
#[derive(Debug, Clone, Default, Serialize)]
pub struct WalletTrackerSummaryParams {
    /// Lookback window, default `7d`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub period: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub wallet: Option<String>,
}

/// Per-wallet activity over the chosen period.
#[derive(Debug, Clone, Deserialize)]
pub struct TrackedWalletStats {
    pub trades: u64,
    pub buys: u64,
    pub sells: u64,
    pub buy_eth: f64,
    pub sell_eth: f64,
    pub net_eth: f64,
    pub tokens_traded: u64,
    pub last_trade_at: Option<String>,
}

/// One row of the tracked-wallet rollup.
#[derive(Debug, Clone, Deserialize)]
pub struct TrackedWalletSummary {
    pub wallet_address: String,
    pub label: Option<String>,
    pub added_at: String,
    pub stats: TrackedWalletStats,
}

/// Response for [`Wallet::tracked_summary`](crate::api::wallet::Wallet::tracked_summary).
#[derive(Debug, Clone, Deserialize)]
pub struct WalletTrackerSummaryResponse {
    pub chain: String,
    pub period: String,
    pub interval: String,
    /// Rollup timed out — per-wallet stats are zeroed, not absent.
    #[serde(default)]
    pub stats_unavailable: bool,
    #[serde(default)]
    pub wallets: Vec<TrackedWalletSummary>,
}