Skip to content

Commit 4010d57

Browse files
authored
reduce number of request-wallet calls (#3474)
1 parent 2d7432f commit 4010d57

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl<
2626
from_address: String,
2727
from_wallet: Vec<u8>,
2828
pumpx_config: &PumpxConfig,
29+
to_address: String,
2930
) -> Result<(String, String, Option<InstantFlowDetails>), ()> {
3031
debug!("executing cross chain swap");
3132

@@ -34,11 +35,6 @@ impl<
3435
return Err(());
3536
}
3637

37-
let Some(to_chain_type) = ChainType::from_pumpx_chain_id(pumpx_config.to_chain_id) else {
38-
error!("Unsupported to_chain_id: {}", pumpx_config.to_chain_id);
39-
return Err(());
40-
};
41-
4238
let from_asset_binance_coin_name =
4339
BinanceAsset::from_chain_asset(&swap_order.from_asset)?.coin.name();
4440

@@ -84,14 +80,6 @@ impl<
8480
)?;
8581
}
8682

87-
let to_wallet = self
88-
.pumpx_signer_client
89-
.request_wallet(to_chain_type, pumpx_config.wallet_index, omni_account)
90-
.await
91-
.map_err(|e| error!("Could not get to_wallet from pumpx-signer: {:?}", e))?;
92-
93-
let to_address = pubkey_to_address(to_chain_type, &to_wallet)?;
94-
9583
self.pumpx_create_cross_order(
9684
intent_id,
9785
pumpx_config.from_token_ca.clone(),

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async fn simple_cross_chain_swap_sol_to_bsc() {
113113
mockall::predicate::eq(pumpx_wallet_index),
114114
mockall::predicate::eq(pumpx_wallet_omni_account),
115115
)
116-
.times(2)
116+
.times(1)
117117
.returning(|_, _, _| {
118118
Ok(hex::decode("0365db18229197e1ff835e0faaec9a9a9900b0aeb5f18e3faa5a4ca60c80213d7c")
119119
.unwrap()
@@ -415,7 +415,7 @@ async fn simple_cross_chain_swap_bsc_to_sol() {
415415
mockall::predicate::eq(pumpx_wallet_index),
416416
mockall::predicate::eq(pumpx_wallet_omni_account),
417417
)
418-
.times(2)
418+
.times(1)
419419
.returning(|_, _, _| {
420420
Ok([
421421
150, 221, 47, 78, 207, 124, 147, 48, 228, 240, 229, 138, 142, 98, 114, 103, 47,
@@ -719,7 +719,7 @@ async fn instant_payout_cross_chain_swap() {
719719
116, 52, 128, 14, 245, 109, 68, 26, 222, 183, 80, 165, 126, 31,
720720
]),
721721
)
722-
.times(2)
722+
.times(1)
723723
.returning(|_, _, _| {
724724
Ok(hex::decode("0365db18229197e1ff835e0faaec9a9a9900b0aeb5f18e3faa5a4ca60c80213d7c")
725725
.unwrap()
@@ -840,6 +840,7 @@ async fn instant_payout_cross_chain_swap() {
840840
mockall::predicate::eq(None),
841841
mockall::predicate::eq(None),
842842
)
843+
// second call is done in separate thread when doing deposit asynchronously in case of instant swap
843844
.times(2)
844845
.returning(|_, _, _, _| {
845846
Ok(vec![prepare_coin_info(solana_coin_ticker, solana_coin_name, "SOL")])
@@ -853,6 +854,7 @@ async fn instant_payout_cross_chain_swap() {
853854
mockall::predicate::always(),
854855
mockall::predicate::eq(None),
855856
)
857+
// second call is done in separate thread when doing deposit asynchronously in case of instant swap
856858
.times(2)
857859
.returning(|_, _, _, _| {
858860
Ok(DepositAddress {
@@ -882,6 +884,7 @@ async fn instant_payout_cross_chain_swap() {
882884
mockall::predicate::eq("/api/v3/ticker/price"),
883885
mockall::predicate::eq(Some(sol_bnb_price_params)),
884886
)
887+
// second call is done in separate thread when doing deposit asynchronously in case of instant swap
885888
.times(2)
886889
.returning(|_, _| Ok(SymbolPrice { price: "10".to_string() }));
887890

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ impl<
197197

198198
let mut from_address = pubkey_to_address(from_chain_type, &from_wallet)?;
199199

200+
let Some(to_chain_type) = ChainType::from_pumpx_chain_id(pumpx_config.to_chain_id)
201+
else {
202+
error!("Unsupported to_chain_id: {}", pumpx_config.to_chain_id);
203+
return Err(());
204+
};
205+
206+
let to_wallet = self
207+
.pumpx_signer_client
208+
.request_wallet(to_chain_type, pumpx_config.wallet_index, *account_id.as_ref())
209+
.await
210+
.map_err(|e| error!("Could not get to_wallet from pumpx-signer: {:?}", e))?;
211+
212+
let to_address = pubkey_to_address(to_chain_type, &to_wallet)?;
213+
200214
let storage = PumpxJwtStorage::new(self.storage_db.clone());
201215
let Ok(Some(access_token)) =
202216
storage.get(&(account_id.clone(), AUTH_TOKEN_ACCESS_TYPE))
@@ -221,6 +235,7 @@ impl<
221235
from_address,
222236
from_wallet,
223237
&pumpx_config,
238+
to_address.clone(),
224239
)
225240
.await
226241
{
@@ -250,6 +265,7 @@ impl<
250265
amount,
251266
&pumpx_config,
252267
from_address,
268+
to_address,
253269
)
254270
.await?;
255271

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ impl<
1818
amount: String,
1919
pumpx_config: &PumpxConfig,
2020
from_address: String,
21+
to_address: String,
2122
) -> Result<Vec<u8>, ()> {
2223
debug!("executing single chain swap");
2324

@@ -26,14 +27,6 @@ impl<
2627
return Err(());
2728
};
2829

29-
let to_wallet = self
30-
.pumpx_signer_client
31-
.request_wallet(to_chain_type, pumpx_config.wallet_index, omni_account)
32-
.await
33-
.map_err(|e| error!("Could not get to_wallet from pumpx-signer: {:?}", e))?;
34-
35-
let to_address = pubkey_to_address(to_chain_type, &to_wallet)?;
36-
3730
// always use `to_token_ca` from RPC
3831
let token_ca = pumpx_config.to_token_ca.clone();
3932

0 commit comments

Comments
 (0)