stonfi_api_client 0.9.0

API client for Stonfi
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
//! Raw STON.fi API v1 request variants and query parameters.
//!
//! Names and fields intentionally mirror the upstream wire contract.
#![allow(missing_docs, reason = "raw request models mirror the upstream API contract")]

use derive_more::From;
use derive_setters::Setters;
use serde_derive::{Deserialize, Serialize};

#[derive(Clone, From)]
#[non_exhaustive]
pub enum V1Request {
    #[from(skip)]
    Assets,
    AssetsQuery(AssetsQueryParams),
    AssetsSearch(AssetsSearchParams),
    #[from(skip)]
    Asset(String),
    Farms(FarmsParams),
    #[from(skip)]
    Farm(String),
    FarmByPool(FarmByPoolParams),
    JettonWalletAddress(JettonWalletAddressParams),
    LiquidityProvisionSimulate(LiquidityProvisionSimulateParams),
    Markets(MarketsParams),
    PoolQuery(PoolQueryParams),
    Pools(PoolsParams),
    PoolsByMarket(PoolsByMarketParams),
    #[from(skip)]
    Pool(String),
    ReverseSwapSimulate(ReverseSwapSimulateParams),
    #[from(skip)]
    Router(String),
    Routers(RoutersParams),
    SwapSimulate(SwapSimulateParams),
    SwapStatus(SwapStatusParams),
    StatsDex(StatsDexParams),
    StatsFeeAccruals(StatsFeeAccrualsParams),
    StatsFeeWithdrawals(StatsFeeWithdrawalsParams),
    StatsFees(StatsFeesParams),
    StatsOperations(StatsOperationsParams),
    StatsPool(StatsPoolParams),
    #[from(skip)]
    StatsStaking,
    TransactionQuery(TransactionQueryParams),
    #[from(skip)]
    TransactionActionTree(String),
    WalletAsset(WalletAssetParams),
    WalletAssets(WalletAssetsParams),
    WalletFarm(WalletFarmParams),
    WalletFarms(WalletFarmsParams),
    WalletFeeVaults(WalletFeeVaultsParams),
    WalletOperations(WalletOperationsParams),
    WalletPool(WalletPoolParams),
    WalletPools(WalletPoolsParams),
    WalletStakes(WalletStakesParams),
    WalletTransactionsLast(WalletTransactionsLastParams),
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct AssetsQueryParams {
    pub condition: Option<String>,
    pub unconditional_assets: Vec<String>,
    pub wallet_address: Option<String>,
}

impl AssetsQueryParams {
    pub fn new() -> Self { Self::default() }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct AssetsSearchParams {
    pub search_string: String,
    pub condition: Option<String>,
    #[serde(rename = "unconditional_asset")]
    pub unconditional_assets: Option<Vec<String>>,
    pub limit: Option<u32>,
    pub wallet_address: Option<String>,
}

impl AssetsSearchParams {
    pub fn new(search_string: impl Into<String>) -> Self {
        Self {
            search_string: search_string.into(),
            condition: None,
            unconditional_assets: None,
            limit: None,
            wallet_address: None,
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct SwapSimulateParams {
    pub offer_address: String,
    pub ask_address: String,
    pub units: String,
    pub slippage_tolerance: String,
    pub referral_address: Option<String>,
    pub referral_fee: Option<String>,
    pub dex_v2: Option<bool>,
}

impl SwapSimulateParams {
    pub fn new(
        offer_address: impl Into<String>,
        ask_address: impl Into<String>,
        units: impl Into<String>,
        slippage_tolerance: impl Into<String>,
    ) -> Self {
        Self {
            offer_address: offer_address.into(),
            ask_address: ask_address.into(),
            units: units.into(),
            slippage_tolerance: slippage_tolerance.into(),
            referral_address: None,
            referral_fee: None,
            dex_v2: Some(true),
        }
    }
}

impl Default for SwapSimulateParams {
    fn default() -> Self { Self::new("", "", "", "") }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct ReverseSwapSimulateParams {
    pub offer_address: String,
    pub ask_address: String,
    pub units: String,
    pub slippage_tolerance: String,
    pub pool_address: Option<String>,
    pub referral_address: Option<String>,
    pub referral_fee_bps: Option<String>,
    pub dex_v2: Option<bool>,
    pub dex_version: Option<Vec<String>>,
}

impl ReverseSwapSimulateParams {
    pub fn new(
        offer_address: impl Into<String>,
        ask_address: impl Into<String>,
        units: impl Into<String>,
        slippage_tolerance: impl Into<String>,
    ) -> Self {
        Self {
            offer_address: offer_address.into(),
            ask_address: ask_address.into(),
            units: units.into(),
            slippage_tolerance: slippage_tolerance.into(),
            pool_address: None,
            referral_address: None,
            referral_fee_bps: None,
            dex_v2: Some(true),
            dex_version: None,
        }
    }
}

impl Default for ReverseSwapSimulateParams {
    fn default() -> Self { Self::new("", "", "", "") }
}

#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct PoolsParams {
    pub dex_v2: bool,
}

impl Default for PoolsParams {
    fn default() -> Self { Self { dex_v2: true } }
}

impl PoolsParams {
    pub fn new() -> Self { Self::default() }
}

#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct MarketsParams {
    pub dex_v2: bool,
}

impl Default for MarketsParams {
    fn default() -> Self { Self { dex_v2: true } }
}

impl MarketsParams {
    pub fn new() -> Self { Self::default() }
}

#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct RoutersParams {
    pub dex_v2: bool,
}

impl Default for RoutersParams {
    fn default() -> Self { Self { dex_v2: true } }
}

impl RoutersParams {
    pub fn new() -> Self { Self::default() }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct FarmByPoolParams {
    pub pool_address: String,
}

impl FarmByPoolParams {
    pub fn new(pool_address: impl Into<String>) -> Self {
        Self {
            pool_address: pool_address.into(),
        }
    }
}

#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct FarmsParams {
    pub dex_v2: bool,
}

impl Default for FarmsParams {
    fn default() -> Self { Self { dex_v2: true } }
}

impl FarmsParams {
    pub fn new() -> Self { Self::default() }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct PoolsByMarketParams {
    pub asset0_address: String,
    pub asset1_address: String,
}

impl PoolsByMarketParams {
    pub fn new(asset0_address: impl Into<String>, asset1_address: impl Into<String>) -> Self {
        Self {
            asset0_address: asset0_address.into(),
            asset1_address: asset1_address.into(),
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct PoolQueryParams {
    pub condition: Option<String>,
    pub dex_v2: Option<bool>,
    pub limit: Option<u32>,
    pub search_terms: Vec<String>,
    pub sort_by: Vec<String>,
    pub unconditional_assets: Vec<String>,
    pub wallet_address: Option<String>,
}

impl PoolQueryParams {
    pub fn new() -> Self {
        Self {
            dex_v2: Some(true),
            ..Self::default()
        }
    }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct SwapStatusParams {
    pub router_address: String,
    pub owner_address: String,
    pub query_id: String,
}

impl SwapStatusParams {
    pub fn new(
        router_address: impl Into<String>,
        owner_address: impl Into<String>,
        query_id: impl Into<String>,
    ) -> Self {
        Self {
            router_address: router_address.into(),
            owner_address: owner_address.into(),
            query_id: query_id.into(),
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct StatsDexParams {
    pub since: Option<String>,
    pub until: Option<String>,
}

impl StatsDexParams {
    pub fn new() -> Self { Self::default() }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct StatsFeeAccrualsParams {
    pub referrer_address: String,
    pub since: String,
    pub until: String,
}

impl StatsFeeAccrualsParams {
    pub fn new(referrer_address: impl Into<String>, since: impl Into<String>, until: impl Into<String>) -> Self {
        Self {
            referrer_address: referrer_address.into(),
            since: since.into(),
            until: until.into(),
        }
    }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct StatsFeeWithdrawalsParams {
    pub referrer_address: String,
    pub since: String,
    pub until: String,
}

impl StatsFeeWithdrawalsParams {
    pub fn new(referrer_address: impl Into<String>, since: impl Into<String>, until: impl Into<String>) -> Self {
        Self {
            referrer_address: referrer_address.into(),
            since: since.into(),
            until: until.into(),
        }
    }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct StatsFeesParams {
    pub referrer_address: String,
    pub since: String,
    pub until: String,
}

impl StatsFeesParams {
    pub fn new(referrer_address: impl Into<String>, since: impl Into<String>, until: impl Into<String>) -> Self {
        Self {
            referrer_address: referrer_address.into(),
            since: since.into(),
            until: until.into(),
        }
    }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct JettonWalletAddressParams {
    pub asset_address: String,
    pub owner_address: String,
}

impl JettonWalletAddressParams {
    pub fn new(asset_address: impl Into<String>, owner_address: impl Into<String>) -> Self {
        Self {
            asset_address: asset_address.into(),
            owner_address: owner_address.into(),
        }
    }
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
#[serde(rename_all = "PascalCase")]
#[non_exhaustive]
pub enum LiquidityProvisionType {
    Initial,
    #[default]
    Balanced,
    Arbitrary,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct LiquidityProvisionSimulateParams {
    pub provision_type: LiquidityProvisionType,
    pub pool_address: Option<String>,
    pub wallet_address: Option<String>,
    pub token_a: String,
    pub token_b: String,
    pub token_a_units: Option<String>,
    pub token_b_units: Option<String>,
    pub slippage_tolerance: String,
}

impl LiquidityProvisionSimulateParams {
    pub fn new(
        provision_type: LiquidityProvisionType,
        token_a: impl Into<String>,
        token_b: impl Into<String>,
        slippage_tolerance: impl Into<String>,
    ) -> Self {
        Self {
            provision_type,
            pool_address: None,
            wallet_address: None,
            token_a: token_a.into(),
            token_b: token_b.into(),
            token_a_units: None,
            token_b_units: None,
            slippage_tolerance: slippage_tolerance.into(),
        }
    }
}

impl Default for LiquidityProvisionSimulateParams {
    fn default() -> Self { Self::new(LiquidityProvisionType::Balanced, "", "", "") }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct StatsOperationsParams {
    pub since: String,
    pub until: String,
    pub pool_address: Option<String>,
}

impl StatsOperationsParams {
    pub fn new(since: impl Into<String>, until: impl Into<String>) -> Self {
        Self {
            since: since.into(),
            until: until.into(),
            pool_address: None,
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct StatsPoolParams {
    pub since: String,
    pub until: String,
    pub pool_address: Option<String>,
}

impl StatsPoolParams {
    pub fn new(since: impl Into<String>, until: impl Into<String>) -> Self {
        Self {
            since: since.into(),
            until: until.into(),
            pool_address: None,
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct TransactionQueryParams {
    pub wallet_address: Option<String>,
    pub query_id: Option<u64>,
    pub min_tx_timestamp: Option<String>,
    pub ext_msg_hash: Option<String>,
}

impl TransactionQueryParams {
    pub fn new() -> Self { Self::default() }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct WalletAssetsParams {
    pub wallet_address: String,
}

impl WalletAssetsParams {
    pub fn new(wallet_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
        }
    }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct WalletAssetParams {
    pub wallet_address: String,
    pub asset_address: String,
}

impl WalletAssetParams {
    pub fn new(wallet_address: impl Into<String>, asset_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
            asset_address: asset_address.into(),
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct WalletPoolsParams {
    pub wallet_address: String,
    pub dex_v2: Option<bool>,
}

impl WalletPoolsParams {
    pub fn new(wallet_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
            dex_v2: Some(true),
        }
    }
}

impl Default for WalletPoolsParams {
    fn default() -> Self { Self::new("") }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct WalletPoolParams {
    pub wallet_address: String,
    pub pool_address: String,
}

impl WalletPoolParams {
    pub fn new(wallet_address: impl Into<String>, pool_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
            pool_address: pool_address.into(),
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct WalletFarmsParams {
    pub wallet_address: String,
    pub dex_v2: Option<bool>,
    pub only_active: Option<bool>,
}

impl WalletFarmsParams {
    pub fn new(wallet_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
            dex_v2: Some(true),
            only_active: None,
        }
    }
}

impl Default for WalletFarmsParams {
    fn default() -> Self { Self::new("") }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct WalletFarmParams {
    pub wallet_address: String,
    pub farm_address: String,
}

impl WalletFarmParams {
    pub fn new(wallet_address: impl Into<String>, farm_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
            farm_address: farm_address.into(),
        }
    }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct WalletStakesParams {
    pub wallet_address: String,
}

impl WalletStakesParams {
    pub fn new(wallet_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct WalletOperationsParams {
    pub wallet_address: String,
    pub since: String,
    pub until: String,
    pub op_type: Vec<String>,
    pub dex_v2: Option<bool>,
}

impl WalletOperationsParams {
    pub fn new(wallet_address: impl Into<String>, since: impl Into<String>, until: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
            since: since.into(),
            until: until.into(),
            op_type: Vec::new(),
            dex_v2: Some(true),
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_", strip_option)]
#[non_exhaustive]
pub struct WalletTransactionsLastParams {
    pub wallet_address: String,
    pub limit: Option<u32>,
    pub min_tx_timestamp: Option<String>,
}

impl WalletTransactionsLastParams {
    pub fn new(wallet_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
            limit: None,
            min_tx_timestamp: None,
        }
    }
}

#[derive(Serialize, Clone, Default, Setters)]
#[setters(prefix = "with_")]
#[non_exhaustive]
pub struct WalletFeeVaultsParams {
    pub wallet_address: String,
}

impl WalletFeeVaultsParams {
    pub fn new(wallet_address: impl Into<String>) -> Self {
        Self {
            wallet_address: wallet_address.into(),
        }
    }
}

#[serde_with::skip_serializing_none]
#[derive(Serialize)]
pub(super) struct DexV2Query {
    pub(super) dex_v2: Option<bool>,
}

#[derive(Serialize)]
pub(super) struct JettonWalletAddressQuery<'a> {
    pub(super) owner_address: &'a str,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize)]
pub(super) struct WalletFarmsQuery {
    pub(super) dex_v2: Option<bool>,
    pub(super) only_active: Option<bool>,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize)]
pub(super) struct WalletOperationsQuery<'a> {
    pub(super) since: &'a str,
    pub(super) until: &'a str,
    pub(super) op_type: &'a [String],
    pub(super) dex_v2: Option<bool>,
}

#[serde_with::skip_serializing_none]
#[derive(Serialize)]
pub(super) struct WalletTransactionsLastQuery<'a> {
    pub(super) limit: Option<u32>,
    pub(super) min_tx_timestamp: Option<&'a str>,
}

impl From<&V1Request> for V1Request {
    fn from(request: &V1Request) -> Self { request.clone() }
}