1
1
pub mod types;
2
2
3
+ use async_trait:: async_trait;
3
4
use reqwest:: { Client , Error } ;
4
5
use types:: {
5
6
AddWalletResponse , CreateCrossOrderBody , CreateLimitOrderBody , CreateMarketOrderTxBody ,
@@ -15,12 +16,108 @@ use url::Url;
15
16
16
17
const DEFAULT_BASE_URL : & str = "https://api.pumpx.ai" ;
17
18
18
- pub struct PumpxApi {
19
+ #[ async_trait]
20
+ pub trait PumpxApi : Send + Sync {
21
+ async fn user_connect (
22
+ & self ,
23
+ access_token : & str ,
24
+ user_id : String ,
25
+ email : String ,
26
+ invite_code : Option < String > ,
27
+ google_code : String ,
28
+ language : Option < String > ,
29
+ ) -> Result < UserConnectResponse , Error > ;
30
+
31
+ async fn verify_google_code (
32
+ & self ,
33
+ access_token : & str ,
34
+ google_code : String ,
35
+ language : Option < String > ,
36
+ ) -> Result < VerifyGoogleCodeResponse , Error > ;
37
+
38
+ async fn add_wallet (
39
+ & self ,
40
+ access_token : & str ,
41
+ language : Option < String > ,
42
+ ) -> Result < AddWalletResponse , Error > ;
43
+
44
+ async fn get_user_trade_info ( & self , access_token : & str )
45
+ -> Result < UserTradeInfoResponse , Error > ;
46
+
47
+ async fn create_market_order_unsigned_tx (
48
+ & self ,
49
+ access_token : & str ,
50
+ body : CreateMarketOrderUnsignedTxBody ,
51
+ ) -> Result < CreateMarketOrderUnsignedTxResponse , Error > ;
52
+
53
+ async fn send_order_tx (
54
+ & self ,
55
+ access_token : & str ,
56
+ body : SendOrderTxBody ,
57
+ ) -> Result < SendOrderTxResponse , Error > ;
58
+
59
+ async fn create_limit_order (
60
+ & self ,
61
+ access_token : & str ,
62
+ body : CreateLimitOrderBody ,
63
+ ) -> Result < OrderInfoResponse , Error > ;
64
+
65
+ async fn create_cross_order (
66
+ & self ,
67
+ access_token : & str ,
68
+ data : CreateCrossOrderBody ,
69
+ ) -> Result < OrderInfoResponse , Error > ;
70
+
71
+ async fn cross_fail (
72
+ & self ,
73
+ access_token : & str ,
74
+ data : CrossFailBody ,
75
+ ) -> Result < OrderInfoResponse , Error > ;
76
+
77
+ #[ allow( clippy:: too_many_arguments) ]
78
+ async fn create_transfer_unsigned_tx (
79
+ & self ,
80
+ access_token : & str ,
81
+ body : CreateTransferUnsignedTxBody ,
82
+ language : Option < String > ,
83
+ ) -> Result < CreateTransferUnsignedTxResponse , Error > ;
84
+
85
+ async fn send_transfer_tx (
86
+ & self ,
87
+ access_token : & str ,
88
+ body : SendTransferTxBody ,
89
+ language : Option < String > ,
90
+ ) -> Result < SendTransferTxResponse , Error > ;
91
+
92
+ async fn create_market_order_tx (
93
+ & self ,
94
+ access_token : & str ,
95
+ body : CreateMarketOrderTxBody ,
96
+ ) -> Result < CreateMarketOrderTxResponse , Error > ;
97
+
98
+ #[ allow( clippy:: too_many_arguments) ]
99
+ async fn create_transfer_tx (
100
+ & self ,
101
+ access_token : & str ,
102
+ body : CreateTransferTxBody ,
103
+ language : Option < String > ,
104
+ ) -> Result < CreateTransferTxResponse , Error > ;
105
+
106
+ async fn get_gas_info (
107
+ & self ,
108
+ access_token : & str ,
109
+ chain_id : u32 ,
110
+ ) -> Result < GetGasInfoResponse , Error > ;
111
+
112
+ async fn get_account_user_id ( & self , email : String ) -> Result < GetAccountUserIdResponse , Error > ;
113
+ }
114
+
115
+ pub struct PumpxApiClient {
19
116
http_client : Client ,
20
117
base_url : Url ,
21
118
}
22
119
23
- impl PumpxApi {
120
+ impl PumpxApiClient {
24
121
pub fn new ( base_url : Option < String > ) -> Self {
25
122
let base_url = match base_url {
26
123
Some ( url) => Url :: parse ( & url) . expect ( "Invalid base URL" ) ,
@@ -32,10 +129,13 @@ impl PumpxApi {
32
129
. default_headers ( default_headers)
33
130
. build ( )
34
131
. expect ( "Failed to build HTTP client" ) ;
35
- PumpxApi { http_client, base_url }
132
+ PumpxApiClient { http_client, base_url }
36
133
}
134
+ }
37
135
38
- pub async fn user_connect (
136
+ #[ async_trait]
137
+ impl PumpxApi for PumpxApiClient {
138
+ async fn user_connect (
39
139
& self ,
40
140
access_token : & str ,
41
141
user_id : String ,
@@ -72,7 +172,7 @@ impl PumpxApi {
72
172
} )
73
173
}
74
174
75
- pub async fn verify_google_code (
175
+ async fn verify_google_code (
76
176
& self ,
77
177
access_token : & str ,
78
178
google_code : String ,
@@ -102,7 +202,7 @@ impl PumpxApi {
102
202
} )
103
203
}
104
204
105
- pub async fn add_wallet (
205
+ async fn add_wallet (
106
206
& self ,
107
207
access_token : & str ,
108
208
language : Option < String > ,
@@ -131,7 +231,7 @@ impl PumpxApi {
131
231
} )
132
232
}
133
233
134
- pub async fn get_user_trade_info (
234
+ async fn get_user_trade_info (
135
235
& self ,
136
236
access_token : & str ,
137
237
) -> Result < UserTradeInfoResponse , Error > {
@@ -145,7 +245,7 @@ impl PumpxApi {
145
245
. await
146
246
}
147
247
148
- pub async fn create_market_order_unsigned_tx (
248
+ async fn create_market_order_unsigned_tx (
149
249
& self ,
150
250
access_token : & str ,
151
251
body : CreateMarketOrderUnsignedTxBody ,
@@ -179,7 +279,7 @@ impl PumpxApi {
179
279
} )
180
280
}
181
281
182
- pub async fn send_order_tx (
282
+ async fn send_order_tx (
183
283
& self ,
184
284
access_token : & str ,
185
285
body : SendOrderTxBody ,
@@ -209,7 +309,7 @@ impl PumpxApi {
209
309
} )
210
310
}
211
311
212
- pub async fn create_limit_order (
312
+ async fn create_limit_order (
213
313
& self ,
214
314
access_token : & str ,
215
315
body : CreateLimitOrderBody ,
@@ -225,7 +325,7 @@ impl PumpxApi {
225
325
. await
226
326
}
227
327
228
- pub async fn create_cross_order (
328
+ async fn create_cross_order (
229
329
& self ,
230
330
access_token : & str ,
231
331
data : CreateCrossOrderBody ,
@@ -251,7 +351,7 @@ impl PumpxApi {
251
351
} )
252
352
}
253
353
254
- pub async fn cross_fail (
354
+ async fn cross_fail (
255
355
& self ,
256
356
access_token : & str ,
257
357
data : CrossFailBody ,
@@ -278,7 +378,7 @@ impl PumpxApi {
278
378
}
279
379
280
380
#[ allow( clippy:: too_many_arguments) ]
281
- pub async fn create_transfer_unsigned_tx (
381
+ async fn create_transfer_unsigned_tx (
282
382
& self ,
283
383
access_token : & str ,
284
384
body : CreateTransferUnsignedTxBody ,
@@ -314,7 +414,7 @@ impl PumpxApi {
314
414
} )
315
415
}
316
416
317
- pub async fn send_transfer_tx (
417
+ async fn send_transfer_tx (
318
418
& self ,
319
419
access_token : & str ,
320
420
body : SendTransferTxBody ,
@@ -346,7 +446,7 @@ impl PumpxApi {
346
446
} )
347
447
}
348
448
349
- pub async fn create_market_order_tx (
449
+ async fn create_market_order_tx (
350
450
& self ,
351
451
access_token : & str ,
352
452
body : CreateMarketOrderTxBody ,
@@ -377,7 +477,7 @@ impl PumpxApi {
377
477
}
378
478
379
479
#[ allow( clippy:: too_many_arguments) ]
380
- pub async fn create_transfer_tx (
480
+ async fn create_transfer_tx (
381
481
& self ,
382
482
access_token : & str ,
383
483
body : CreateTransferTxBody ,
@@ -413,7 +513,7 @@ impl PumpxApi {
413
513
} )
414
514
}
415
515
416
- pub async fn get_gas_info (
516
+ async fn get_gas_info (
417
517
& self ,
418
518
access_token : & str ,
419
519
chain_id : u32 ,
@@ -430,10 +530,7 @@ impl PumpxApi {
430
530
. await
431
531
}
432
532
433
- pub async fn get_account_user_id (
434
- & self ,
435
- email : String ,
436
- ) -> Result < GetAccountUserIdResponse , Error > {
533
+ async fn get_account_user_id ( & self , email : String ) -> Result < GetAccountUserIdResponse , Error > {
437
534
let endpoint = self . base_url . join ( "v3/account/get_account_user_id" ) . unwrap ( ) ;
438
535
let params = GetAccountUserIdParams { email } ;
439
536
self . http_client . get ( endpoint) . query ( & params) . send ( ) . await ?. json ( ) . await
0 commit comments