Skip to content

Commit 6723ca1

Browse files
authored
pumpx api trait (#3432)
1 parent b72be60 commit 6723ca1

File tree

7 files changed

+134
-36
lines changed

7 files changed

+134
-36
lines changed

tee-worker/omni-executor/executor-worker/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use parentchain_rpc_client::{
4444
use parentchain_signer::{key_store::SubstrateKeyStore, TxSigner};
4545
use pumpx::pubkey_to_evm_address;
4646
use pumpx::signer_client::SignerClient;
47-
use pumpx::PumpxApi;
47+
use pumpx::{PumpxApi, PumpxApiClient};
4848
use rpc_server::{start_server as start_rpc_server, AuthTokenKeyStore};
4949
use solana::SolanaClient;
5050
use solana_intent_executor::SolanaIntentExecutor;
@@ -192,7 +192,8 @@ async fn main() -> Result<(), ()> {
192192
}
193193

194194
let pumpx_api_base_url = std::env::var("OE_PUMPX_API_BASE_URL").ok();
195-
let pumpx_api = Arc::new(PumpxApi::new(pumpx_api_base_url));
195+
let pumpx_api: Arc<Box<dyn PumpxApi>> =
196+
Arc::new(Box::new(PumpxApiClient::new(pumpx_api_base_url)));
196197

197198
let binance_api_key = env::var("OE_BINANCE_API_KEY").unwrap_or("".to_string());
198199
let binance_api_secret = env::var("OE_BINANCE_API_SECRET").unwrap_or("".to_string());

tee-worker/omni-executor/intent/executors/cross-chain/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub struct CrossChainIntentExecutor<Provider: EthereumRpcProvider<Transaction =
106106
// account_asset_lock: AccountAssetLocks<AlwaysUnlockedAssetsLock>,
107107
// rpc_endpoint_registry: RpcEndpointRegistry,
108108
pumpx_signer_client: Arc<Box<dyn SignerClient>>,
109-
pumpx_api: Arc<PumpxApi>,
109+
pumpx_api: Arc<Box<dyn PumpxApi>>,
110110
storage_db: Arc<StorageDB>,
111111
binance_api: Arc<BinanceApi>,
112112
solana_client: Arc<SolanaClient>,
@@ -120,7 +120,7 @@ impl<Provider: EthereumRpcProvider<Transaction = TransactionRequest>>
120120
pub fn new(
121121
_rpc_endpoint_registry: RpcEndpointRegistry,
122122
pumpx_signer_client: Arc<Box<dyn SignerClient>>,
123-
pumpx_api: Arc<PumpxApi>,
123+
pumpx_api: Arc<Box<dyn PumpxApi>>,
124124
storage_db: Arc<StorageDB>,
125125
binance_api: Arc<BinanceApi>,
126126
solana_client: Arc<SolanaClient>,

tee-worker/omni-executor/native-task-handler/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub struct TaskHandlerContext<
7575
pub ethereum_intent_executor: Arc<EthereumIntentExecutor>,
7676
pub solana_intent_executor: Arc<SolanaIntentExecutor>,
7777
pub cross_chain_intent_executor: Arc<CrossChainIntentExecutor>,
78-
pub pumpx_api: Arc<PumpxApi>,
78+
pub pumpx_api: Arc<Box<dyn PumpxApi>>,
7979
pumpx_signer_client: Arc<Box<dyn SignerClient>>,
8080
phantom_header: PhantomData<Header>,
8181
phantom_rpc_client: PhantomData<RpcClient>,
@@ -108,7 +108,7 @@ impl<
108108
ethereum_intent_executor: Arc<EthereumIntentExecutor>,
109109
solana_intent_executor: Arc<SolanaIntentExecutor>,
110110
cross_chain_intent_executor: Arc<CrossChainIntentExecutor>,
111-
pumpx_api: Arc<PumpxApi>,
111+
pumpx_api: Arc<Box<dyn PumpxApi>>,
112112
pumpx_signer_client: Arc<Box<dyn SignerClient>>,
113113
) -> Self {
114114
Self {

tee-worker/omni-executor/pumpx/src/pumpx_api/mod.rs

Lines changed: 118 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod types;
22

3+
use async_trait::async_trait;
34
use reqwest::{Client, Error};
45
use types::{
56
AddWalletResponse, CreateCrossOrderBody, CreateLimitOrderBody, CreateMarketOrderTxBody,
@@ -15,12 +16,108 @@ use url::Url;
1516

1617
const DEFAULT_BASE_URL: &str = "https://api.pumpx.ai";
1718

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 {
19116
http_client: Client,
20117
base_url: Url,
21118
}
22119

23-
impl PumpxApi {
120+
impl PumpxApiClient {
24121
pub fn new(base_url: Option<String>) -> Self {
25122
let base_url = match base_url {
26123
Some(url) => Url::parse(&url).expect("Invalid base URL"),
@@ -32,10 +129,13 @@ impl PumpxApi {
32129
.default_headers(default_headers)
33130
.build()
34131
.expect("Failed to build HTTP client");
35-
PumpxApi { http_client, base_url }
132+
PumpxApiClient { http_client, base_url }
36133
}
134+
}
37135

38-
pub async fn user_connect(
136+
#[async_trait]
137+
impl PumpxApi for PumpxApiClient {
138+
async fn user_connect(
39139
&self,
40140
access_token: &str,
41141
user_id: String,
@@ -72,7 +172,7 @@ impl PumpxApi {
72172
})
73173
}
74174

75-
pub async fn verify_google_code(
175+
async fn verify_google_code(
76176
&self,
77177
access_token: &str,
78178
google_code: String,
@@ -102,7 +202,7 @@ impl PumpxApi {
102202
})
103203
}
104204

105-
pub async fn add_wallet(
205+
async fn add_wallet(
106206
&self,
107207
access_token: &str,
108208
language: Option<String>,
@@ -131,7 +231,7 @@ impl PumpxApi {
131231
})
132232
}
133233

134-
pub async fn get_user_trade_info(
234+
async fn get_user_trade_info(
135235
&self,
136236
access_token: &str,
137237
) -> Result<UserTradeInfoResponse, Error> {
@@ -145,7 +245,7 @@ impl PumpxApi {
145245
.await
146246
}
147247

148-
pub async fn create_market_order_unsigned_tx(
248+
async fn create_market_order_unsigned_tx(
149249
&self,
150250
access_token: &str,
151251
body: CreateMarketOrderUnsignedTxBody,
@@ -179,7 +279,7 @@ impl PumpxApi {
179279
})
180280
}
181281

182-
pub async fn send_order_tx(
282+
async fn send_order_tx(
183283
&self,
184284
access_token: &str,
185285
body: SendOrderTxBody,
@@ -209,7 +309,7 @@ impl PumpxApi {
209309
})
210310
}
211311

212-
pub async fn create_limit_order(
312+
async fn create_limit_order(
213313
&self,
214314
access_token: &str,
215315
body: CreateLimitOrderBody,
@@ -225,7 +325,7 @@ impl PumpxApi {
225325
.await
226326
}
227327

228-
pub async fn create_cross_order(
328+
async fn create_cross_order(
229329
&self,
230330
access_token: &str,
231331
data: CreateCrossOrderBody,
@@ -251,7 +351,7 @@ impl PumpxApi {
251351
})
252352
}
253353

254-
pub async fn cross_fail(
354+
async fn cross_fail(
255355
&self,
256356
access_token: &str,
257357
data: CrossFailBody,
@@ -278,7 +378,7 @@ impl PumpxApi {
278378
}
279379

280380
#[allow(clippy::too_many_arguments)]
281-
pub async fn create_transfer_unsigned_tx(
381+
async fn create_transfer_unsigned_tx(
282382
&self,
283383
access_token: &str,
284384
body: CreateTransferUnsignedTxBody,
@@ -314,7 +414,7 @@ impl PumpxApi {
314414
})
315415
}
316416

317-
pub async fn send_transfer_tx(
417+
async fn send_transfer_tx(
318418
&self,
319419
access_token: &str,
320420
body: SendTransferTxBody,
@@ -346,7 +446,7 @@ impl PumpxApi {
346446
})
347447
}
348448

349-
pub async fn create_market_order_tx(
449+
async fn create_market_order_tx(
350450
&self,
351451
access_token: &str,
352452
body: CreateMarketOrderTxBody,
@@ -377,7 +477,7 @@ impl PumpxApi {
377477
}
378478

379479
#[allow(clippy::too_many_arguments)]
380-
pub async fn create_transfer_tx(
480+
async fn create_transfer_tx(
381481
&self,
382482
access_token: &str,
383483
body: CreateTransferTxBody,
@@ -413,7 +513,7 @@ impl PumpxApi {
413513
})
414514
}
415515

416-
pub async fn get_gas_info(
516+
async fn get_gas_info(
417517
&self,
418518
access_token: &str,
419519
chain_id: u32,
@@ -430,10 +530,7 @@ impl PumpxApi {
430530
.await
431531
}
432532

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> {
437534
let endpoint = self.base_url.join("v3/account/get_account_user_id").unwrap();
438535
let params = GetAccountUserIdParams { email };
439536
self.http_client.get(endpoint).query(&params).send().await?.json().await

tee-worker/omni-executor/rpc-server/src/methods/omni/get_health.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod test {
3131
use jsonrpsee::rpc_params;
3232
use jsonrpsee::ws_client::WsClientBuilder;
3333
use native_task_handler::NativeTaskChannelType;
34-
use pumpx::PumpxApi;
34+
use pumpx::PumpxApiClient;
3535
use rsa::{pkcs1::EncodeRsaPrivateKey, RsaPrivateKey};
3636
use std::sync::Arc;
3737
use tempfile::tempdir;
@@ -49,13 +49,13 @@ mod test {
4949
let rsa_private_key =
5050
RsaPrivateKey::new(&mut rng, 2048).expect("Failed to generate private key");
5151
let jwt_private_key = rsa_private_key.to_pkcs1_der().unwrap();
52-
let pumpx_api = PumpxApi::new(None);
52+
let pumpx_api = PumpxApiClient::new(None);
5353

5454
start_server(
5555
port,
5656
shielding_key.clone(),
5757
Arc::new(sender),
58-
Arc::new(pumpx_api),
58+
Arc::new(Box::new(pumpx_api)),
5959
Arc::new(db),
6060
[0u8; 32],
6161
jwt_private_key.as_bytes().to_vec(),

tee-worker/omni-executor/rpc-server/src/methods/omni/get_shielding_key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod test {
2424
use jsonrpsee::rpc_params;
2525
use jsonrpsee::ws_client::WsClientBuilder;
2626
use native_task_handler::NativeTaskChannelType;
27-
use pumpx::PumpxApi;
27+
use pumpx::PumpxApiClient;
2828
use rsa::{pkcs1::EncodeRsaPrivateKey, RsaPrivateKey};
2929
use std::sync::Arc;
3030
use tempfile::tempdir;
@@ -41,13 +41,13 @@ mod test {
4141
let rsa_private_key =
4242
RsaPrivateKey::new(&mut rng, 2048).expect("Failed to generate private key");
4343
let jwt_private_key = rsa_private_key.to_pkcs1_der().unwrap();
44-
let pumpx_api = PumpxApi::new(None);
44+
let pumpx_api = PumpxApiClient::new(None);
4545

4646
start_server(
4747
port,
4848
shielding_key.clone(),
4949
Arc::new(sender),
50-
Arc::new(pumpx_api),
50+
Arc::new(Box::new(pumpx_api)),
5151
Arc::new(db),
5252
[0u8; 32],
5353
jwt_private_key.as_bytes().to_vec(),

tee-worker/omni-executor/rpc-server/src/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) struct RpcContext {
1616
pub jwt_rsa_private_key: Vec<u8>,
1717
pub google_client_id: String,
1818
pub google_client_secret: String,
19-
pub pumpx_api: Arc<PumpxApi>,
19+
pub pumpx_api: Arc<Box<dyn PumpxApi>>,
2020
}
2121

2222
impl RpcContext {
@@ -30,7 +30,7 @@ impl RpcContext {
3030
jwt_rsa_private_key: Vec<u8>,
3131
google_client_id: String,
3232
google_client_secret: String,
33-
pumpx_api: Arc<PumpxApi>,
33+
pumpx_api: Arc<Box<dyn PumpxApi>>,
3434
) -> Self {
3535
Self {
3636
shielding_key,
@@ -51,7 +51,7 @@ pub async fn start_server(
5151
port: u16,
5252
shielding_key: ShieldingKey,
5353
native_task_sender: Arc<NativeTaskSender>,
54-
pumpx_api: Arc<PumpxApi>,
54+
pumpx_api: Arc<Box<dyn PumpxApi>>,
5555
storage_db: Arc<StorageDB>,
5656
mrenclave: [u8; 32],
5757
jwt_rsa_private_key: Vec<u8>,

0 commit comments

Comments
 (0)