hyperliquid-sdk-rs 0.1.2

High-performance Rust SDK for Hyperliquid Protocol
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
use alloy::primitives::Address;
use serde::{Deserialize, Serialize};

// ==================== Request Types ====================

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CandleSnapshotRequest {
    pub coin: String,
    pub interval: String,
    pub start_time: u64,
    pub end_time: u64,
}

// ==================== Common Response Types ====================

// Note: AllMids returns HashMap<String, String> directly, not wrapped

// ==================== Position & Margin Types ====================

#[derive(Serialize, Deserialize, Debug)]
pub struct AssetPosition {
    pub position: PositionData,
    #[serde(rename = "type")]
    pub type_string: String,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct BasicOrderInfo {
    pub coin: String,
    pub side: String,
    pub limit_px: String,
    pub sz: String,
    pub oid: u64,
    pub timestamp: u64,
    pub trigger_condition: String,
    pub is_trigger: bool,
    pub trigger_px: String,
    pub is_position_tpsl: bool,
    pub reduce_only: bool,
    pub order_type: String,
    pub orig_sz: String,
    pub tif: String,
    pub cloid: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct CandlesSnapshotResponse {
    #[serde(rename = "t")]
    pub time_open: u64,
    #[serde(rename = "T")]
    pub time_close: u64,
    #[serde(rename = "s")]
    pub coin: String,
    #[serde(rename = "i")]
    pub candle_interval: String,
    #[serde(rename = "o")]
    pub open: String,
    #[serde(rename = "c")]
    pub close: String,
    #[serde(rename = "h")]
    pub high: String,
    #[serde(rename = "l")]
    pub low: String,
    #[serde(rename = "v")]
    pub vlm: String,
    #[serde(rename = "n")]
    pub num_trades: u64,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CumulativeFunding {
    pub all_time: String,
    pub since_open: String,
    pub since_change: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct DailyUserVlm {
    pub date: String,
    pub exchange: String,
    pub user_add: String,
    pub user_cross: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Delta {
    #[serde(rename = "type")]
    pub type_string: String,
    pub coin: String,
    pub usdc: String,
    pub szi: String,
    pub funding_rate: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FeeSchedule {
    pub add: String,
    pub cross: String,
    pub referral_discount: String,
    pub tiers: Tiers,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct FundingHistoryResponse {
    pub coin: String,
    pub funding_rate: String,
    pub premium: String,
    pub time: u64,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct L2SnapshotResponse {
    pub coin: String,
    pub levels: Vec<Vec<Level>>,
    pub time: u64,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Level {
    pub n: u64,
    pub px: String,
    pub sz: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Leverage {
    #[serde(rename = "type")]
    pub type_string: String,
    pub value: u32,
    pub raw_usd: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MarginSummary {
    pub account_value: String,
    pub total_margin_used: String,
    pub total_ntl_pos: String,
    pub total_raw_usd: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Mm {
    pub add: String,
    pub maker_fraction_cutoff: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct OpenOrdersResponse {
    pub coin: String,
    pub limit_px: String,
    pub oid: u64,
    pub side: String,
    pub sz: String,
    pub timestamp: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct OrderInfo {
    pub order: BasicOrderInfo,
    pub status: String,
    pub status_timestamp: u64,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct OrderStatusResponse {
    pub status: String,
    /// `None` if the order is not found
    #[serde(default)]
    pub order: Option<OrderInfo>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct PositionData {
    pub coin: String,
    pub entry_px: Option<String>,
    pub leverage: Leverage,
    pub liquidation_px: Option<String>,
    pub margin_used: String,
    pub position_value: String,
    pub return_on_equity: String,
    pub szi: String,
    pub unrealized_pnl: String,
    pub max_leverage: u32,
    pub cum_funding: CumulativeFunding,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RecentTradesResponse {
    pub coin: String,
    pub side: String,
    pub px: String,
    pub sz: String,
    pub time: u64,
    pub hash: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Referrer {
    pub referrer: Address,
    pub code: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ReferralResponse {
    pub referred_by: Option<Referrer>,
    pub cum_vlm: String,
    pub unclaimed_rewards: String,
    pub claimed_rewards: String,
    pub referrer_state: ReferrerState,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ReferrerData {
    pub required: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ReferrerState {
    pub stage: String,
    pub data: ReferrerData,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Tiers {
    pub mm: Vec<Mm>,
    pub vip: Vec<Vip>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UserFeesResponse {
    pub active_referral_discount: String,
    pub daily_user_vlm: Vec<DailyUserVlm>,
    pub fee_schedule: FeeSchedule,
    pub user_add_rate: String,
    pub user_cross_rate: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UserFillsResponse {
    pub closed_pnl: String,
    pub coin: String,
    pub crossed: bool,
    pub dir: String,
    pub hash: String,
    pub oid: u64,
    pub px: String,
    pub side: String,
    pub start_position: String,
    pub sz: String,
    pub time: u64,
    pub fee: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct UserFundingResponse {
    pub time: u64,
    pub hash: String,
    pub delta: Delta,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UserStateResponse {
    pub asset_positions: Vec<AssetPosition>,
    pub cross_margin_summary: MarginSummary,
    pub margin_summary: MarginSummary,
    pub withdrawable: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UserTokenBalance {
    pub coin: String,
    pub hold: String,
    pub total: String,
    pub entry_ntl: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct UserTokenBalanceResponse {
    pub balances: Vec<UserTokenBalance>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Vip {
    pub add: String,
    pub cross: String,
    pub ntl_cutoff: String,
}

// ==================== Metadata Types ====================

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Meta {
    pub universe: Vec<AssetMeta>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct AssetMeta {
    pub name: String,
    pub sz_decimals: u32,
    pub max_leverage: u32,
    #[serde(default)]
    pub only_isolated: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub initial_margin_ratio: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub maintenance_margin_ratio: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub margin_table_id: Option<u32>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub is_delisted: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpotMeta {
    pub universe: Vec<SpotPairMeta>,
    pub tokens: Vec<TokenMeta>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpotPairMeta {
    pub name: String,
    pub tokens: [u32; 2],
    pub index: u32,
    pub is_canonical: bool,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum EvmContract {
    String(String),
    Object {
        address: String,
        evm_extra_wei_decimals: i32,
    },
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TokenMeta {
    pub name: String,
    pub sz_decimals: u32,
    pub wei_decimals: u32,
    pub index: u32,
    pub token_id: String, // Actually a hex string, not Address
    pub is_canonical: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub full_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evm_contract: Option<EvmContract>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deployer_trading_fee_share: Option<String>,
}

/// Response for spotMetaAndAssetCtxs - a tuple of (SpotMeta, Vec<SpotAssetContext>)
///
/// The API returns `[{universe, tokens}, [...assetCtxs]]` as an array.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(from = "(SpotMeta, Vec<SpotAssetContext>)")]
#[serde(into = "(SpotMeta, Vec<SpotAssetContext>)")]
pub struct SpotMetaAndAssetCtxs {
    /// Spot metadata including universe and tokens
    pub meta: SpotMeta,
    /// Asset contexts for each spot pair
    pub asset_ctxs: Vec<SpotAssetContext>,
}

impl From<(SpotMeta, Vec<SpotAssetContext>)> for SpotMetaAndAssetCtxs {
    fn from((meta, asset_ctxs): (SpotMeta, Vec<SpotAssetContext>)) -> Self {
        Self { meta, asset_ctxs }
    }
}

impl From<SpotMetaAndAssetCtxs> for (SpotMeta, Vec<SpotAssetContext>) {
    fn from(val: SpotMetaAndAssetCtxs) -> Self {
        (val.meta, val.asset_ctxs)
    }
}

/// Asset context for spot pairs (different from perp AssetContext)
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpotAssetContext {
    /// Coin/pair name (e.g., "PURR/USDC")
    pub coin: String,
    /// Previous day price
    pub prev_day_px: String,
    /// Daily notional volume
    pub day_ntl_vlm: String,
    /// Mark price
    pub mark_px: String,
    /// Mid price (can be null)
    #[serde(default)]
    pub mid_px: Option<String>,
    /// Circulating supply
    #[serde(default)]
    pub circulating_supply: Option<String>,
    /// Total supply
    #[serde(default)]
    pub total_supply: Option<String>,
    /// Daily base volume
    #[serde(default)]
    pub day_base_vlm: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct AssetContext {
    pub day_ntl_vlm: String,
    pub funding: String,
    pub impact_pxs: Vec<String>,
    pub mark_px: String,
    pub mid_px: String,
    pub open_interest: String,
    pub oracle_px: String,
    pub premium: String,
    pub prev_day_px: String,
}

// ==================== Phase 1 New Types ====================

/// Response for metaAndAssetCtxs - perp metadata with asset contexts
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MetaAndAssetCtxs {
    pub meta: Meta,
    pub asset_ctxs: Vec<PerpAssetContext>,
}

/// Asset context for perpetuals (different from spot AssetContext)
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct PerpAssetContext {
    pub day_ntl_vlm: String,
    pub funding: String,
    pub impact_pxs: Option<Vec<String>>,
    pub mark_px: String,
    pub mid_px: Option<String>,
    pub open_interest: String,
    pub oracle_px: String,
    pub premium: Option<String>,
    pub prev_day_px: String,
}

/// Response for frontendOpenOrders - open orders with extra frontend metadata
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FrontendOpenOrder {
    pub coin: String,
    pub side: String,
    pub limit_px: String,
    pub sz: String,
    pub oid: u64,
    pub timestamp: u64,
    pub orig_sz: String,
    pub cloid: Option<String>,
    pub reduce_only: bool,
    pub order_type: String,
    pub tif: String,
    pub trigger_condition: String,
    pub is_trigger: bool,
    pub trigger_px: String,
    pub is_position_tpsl: bool,
    #[serde(default)]
    pub children: Option<Vec<FrontendOpenOrder>>,
}

/// Response for userFillsByTime - fills with aggregation options
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UserFillByTime {
    pub closed_pnl: String,
    pub coin: String,
    pub crossed: bool,
    pub dir: String,
    pub hash: String,
    pub oid: u64,
    pub px: String,
    pub side: String,
    pub start_position: String,
    pub sz: String,
    pub time: u64,
    pub fee: String,
    pub fee_token: String,
    pub tid: u64,
    pub cloid: Option<String>,
}

/// Response for historicalOrders
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct HistoricalOrder {
    pub order: BasicOrderInfo,
    pub status: String,
    pub status_timestamp: u64,
}

/// Response for subAccounts
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SubAccount {
    pub sub_account_user: Address,
    pub name: String,
    pub master: Address,
    pub clearinghouse_state: Option<SubAccountClearinghouseState>,
}

/// Clearinghouse state for sub-account
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SubAccountClearinghouseState {
    pub margin_summary: MarginSummary,
    pub cross_margin_summary: MarginSummary,
    pub withdrawable: String,
}

/// Response for userRateLimit
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UserRateLimit {
    pub cum_vlm: String,
    pub n_request_ids: u32,
    pub n_request_weights: u32,
    pub n_request_ids_limit: u32,
    pub n_request_weights_limit: u32,
}

/// Response for userVaultEquities
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct VaultEquity {
    pub vault_address: Address,
    pub equity: String,
}

// ==================== Phase 2 New Types ====================

/// Response for portfolio - comprehensive portfolio performance data
///
/// The API returns an array of tuples `[["day", {...}], ["week", {...}], ...]`
/// where each tuple contains a time period and performance data.
///
/// Available periods: "day", "week", "month", "allTime", "perpDay", "perpWeek", "perpMonth", "perpAllTime"
pub type Portfolio = Vec<(String, PortfolioPeriodData)>;

/// Performance data for a single time period in the portfolio response
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PortfolioPeriodData {
    /// Account value history as array of [timestamp, value] pairs
    pub account_value_history: Vec<(u64, String)>,
    /// PnL history as array of [timestamp, value] pairs
    pub pnl_history: Vec<(u64, String)>,
    /// Total volume for this period
    pub vlm: String,
}

/// Response for userNonFundingLedgerUpdates - ledger activity
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct NonFundingLedgerUpdate {
    pub time: u64,
    pub hash: String,
    pub delta: NonFundingDelta,
}

/// Delta type for non-funding ledger updates
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum NonFundingDelta {
    /// Deposit to account
    Deposit { usdc: String },
    /// Withdrawal from account
    Withdraw {
        usdc: String,
        nonce: u64,
        fee: String,
    },
    /// Internal transfer between accounts
    InternalTransfer {
        usdc: String,
        user: Address,
        destination: Address,
        fee: String,
    },
    /// Sub-account transfer
    SubAccountTransfer {
        usdc: String,
        user: Address,
        destination: Address,
    },
    /// Spot token transfer
    SpotTransfer {
        token: String,
        amount: String,
        user: Address,
        destination: Address,
        fee: String,
    },
    /// Liquidation
    Liquidation {
        liquidated_user: Address,
        #[serde(default)]
        leveraged_ntl: Option<String>,
    },
    /// Account class transfer (perp <-> spot)
    AccountClassTransfer { usdc: String, to_perp: bool },
    /// Spot genesis
    SpotGenesis { token: String, amount: String },
    /// Rewards claim
    RewardsClaim { amount: String },
    /// Vault deposit
    VaultDeposit { vault: Address, usdc: String },
    /// Vault withdrawal
    VaultWithdraw {
        vault: Address,
        usdc: String,
        #[serde(default)]
        fee: Option<String>,
    },
    /// Vault leader commission
    VaultLeaderCommission { usdc: String },
}

/// Response for extraAgents - list of additional authorized agents
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ExtraAgent {
    pub address: Address,
    pub name: Option<String>,
    #[serde(default)]
    pub valid_until: Option<u64>,
}

/// Response for userRole - user role and account type
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UserRole {
    /// Role type (e.g., "user", "vault", "subAccount")
    pub role: String,
    /// Additional role data
    #[serde(default)]
    pub data: Option<UserRoleData>,
}

/// Additional data for user role
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UserRoleData {
    /// Master account for sub-accounts
    #[serde(default)]
    pub master: Option<Address>,
    /// Vault address for vault accounts
    #[serde(default)]
    pub vault: Option<Address>,
}

/// Response for tokenDetails - detailed token information
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TokenDetails {
    /// Token name/symbol
    pub name: String,
    /// Size decimals for trading
    pub sz_decimals: u32,
    /// Wei decimals for on-chain representation
    pub wei_decimals: u32,
    /// Token index
    pub index: u32,
    /// Token ID (hex string)
    pub token_id: String,
    /// Whether this is a canonical token
    pub is_canonical: bool,
    /// Full name of the token
    #[serde(default)]
    pub full_name: Option<String>,
    /// EVM contract information
    #[serde(default)]
    pub evm_contract: Option<EvmContract>,
    /// Deployer trading fee share
    #[serde(default)]
    pub deployer_trading_fee_share: Option<String>,
    /// Total supply
    #[serde(default)]
    pub total_supply: Option<String>,
    /// Circulating supply
    #[serde(default)]
    pub circulating_supply: Option<String>,
    /// Market cap
    #[serde(default)]
    pub market_cap: Option<String>,
}

// ==================== Phase 3 New Types ====================

// --- Staking/Delegation Types ---

/// Response for delegatorSummary - staking summary
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DelegatorSummary {
    /// Total delegated amount in wei
    #[serde(default)]
    pub delegated: Option<String>,
    /// Total undelegating amount in wei
    #[serde(default)]
    pub undelegating: Option<String>,
    /// Total rewards earned
    #[serde(default)]
    pub total_rewards: Option<String>,
    /// Pending rewards to claim
    #[serde(default)]
    pub pending_rewards: Option<String>,
    /// Number of validators delegated to
    #[serde(default)]
    pub n_validators: Option<u32>,
}

/// Response for delegations - list of staking delegations
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Delegation {
    /// Validator address
    pub validator: Address,
    /// Delegated amount in wei
    pub amount: String,
    /// Locked until timestamp (for undelegating)
    #[serde(default)]
    pub locked_until: Option<u64>,
    /// Pending rewards
    #[serde(default)]
    pub pending_rewards: Option<String>,
}

/// Response for delegatorRewards - historic staking rewards
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DelegatorReward {
    /// Timestamp of reward
    pub time: u64,
    /// Validator address
    pub validator: Address,
    /// Reward amount
    pub amount: String,
    /// Transaction hash
    #[serde(default)]
    pub hash: Option<String>,
}

/// Response for delegatorHistory - comprehensive staking history
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DelegatorHistoryEntry {
    /// Timestamp of action
    pub time: u64,
    /// Type of action (delegate, undelegate, claim, etc.)
    #[serde(rename = "type")]
    pub action_type: String,
    /// Validator address
    #[serde(default)]
    pub validator: Option<Address>,
    /// Amount in wei
    #[serde(default)]
    pub amount: Option<String>,
    /// Transaction hash
    #[serde(default)]
    pub hash: Option<String>,
}

// --- Deployment Types ---

/// Response for perpDeployAuctionStatus
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PerpDeployAuctionStatus {
    /// Current auction state
    #[serde(default)]
    pub state: Option<String>,
    /// Auction info
    #[serde(default)]
    pub auction: Option<PerpDeployAuction>,
    /// DEX info
    #[serde(default)]
    pub dexes: Option<Vec<PerpDex>>,
}

/// Perp deployment auction info
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PerpDeployAuction {
    /// Coin being auctioned
    #[serde(default)]
    pub coin: Option<String>,
    /// Starting price
    #[serde(default)]
    pub start_px: Option<String>,
    /// Current bid
    #[serde(default)]
    pub current_bid: Option<String>,
    /// End time
    #[serde(default)]
    pub end_time: Option<u64>,
}

/// Response for spotDeployState
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpotDeployState {
    /// Token deploy state
    #[serde(default)]
    pub tokens: Option<Vec<SpotTokenDeployState>>,
    /// User's deploy state
    #[serde(default)]
    pub user_state: Option<SpotUserDeployState>,
}

/// Spot token deployment state
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpotTokenDeployState {
    /// Token name
    pub token: String,
    /// Deployment state
    pub state: String,
    /// Genesis info
    #[serde(default)]
    pub genesis: Option<SpotGenesisInfo>,
}

/// Spot genesis info
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpotGenesisInfo {
    /// Max supply
    #[serde(default)]
    pub max_supply: Option<String>,
    /// Hyperliquidity enabled
    #[serde(default)]
    pub hyperliquidity: Option<bool>,
}

/// Spot user deployment state
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpotUserDeployState {
    /// Tokens being deployed by user
    #[serde(default)]
    pub deploying: Option<Vec<String>>,
    /// Tokens deployed by user
    #[serde(default)]
    pub deployed: Option<Vec<String>>,
}

/// Response for spotPairDeployAuctionStatus
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SpotPairDeployAuctionStatus {
    /// Base token
    #[serde(default)]
    pub base: Option<String>,
    /// Quote token
    #[serde(default)]
    pub quote: Option<String>,
    /// Auction state
    #[serde(default)]
    pub state: Option<String>,
    /// Current bid
    #[serde(default)]
    pub current_bid: Option<String>,
    /// End time
    #[serde(default)]
    pub end_time: Option<u64>,
}

// --- Other Types ---

/// Response for perpDexs - available perpetual DEXs
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PerpDex {
    /// DEX identifier
    pub dex: u32,
    /// DEX name
    pub name: String,
    /// Coins listed on this DEX
    #[serde(default)]
    pub coins: Option<Vec<String>>,
}

/// Response for userDexAbstraction
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UserDexAbstraction {
    /// Whether DEX abstraction is enabled
    pub enabled: bool,
    /// Agent address
    #[serde(default)]
    pub agent: Option<Address>,
    /// Enabled dexes
    #[serde(default)]
    pub dexes: Option<Vec<u32>>,
}

/// Response for userToMultiSigSigners
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MultiSigSignerInfo {
    /// Signer address
    pub address: Address,
    /// Signer weight
    pub weight: u32,
}

/// Multi-sig user info
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MultiSigUserInfo {
    /// Threshold required for approval
    pub threshold: u32,
    /// List of signers
    pub signers: Vec<MultiSigSignerInfo>,
}

/// Response for userTwapSliceFills - TWAP execution fills
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TwapSliceFill {
    /// TWAP order ID
    pub twap_id: u64,
    /// Asset index
    pub asset: u32,
    /// Coin name
    pub coin: String,
    /// Fill price
    pub px: String,
    /// Fill size
    pub sz: String,
    /// Side (buy/sell)
    pub side: String,
    /// Fill time
    pub time: u64,
    /// Transaction hash
    #[serde(default)]
    pub hash: Option<String>,
}