Skip to content

Update params/types/structs based on API spec #3370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions common/primitives/core/src/omni/intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ pub enum SingleChainSwapProvider {
pub struct PumpxConfig {
pub order_type: PumpxOrderType,
pub swap_type: u32, // 1:buy 2:sell
pub chain_id: u32, // to align with pumpx: sol:10000 eth:1 bsc:56 base:8453
pub token_ca: BoundedVec<u8, IntentStringLen>,
pub from_chain_id: u32,
pub from_token_ca: BoundedVec<u8, IntentStringLen>,
pub to_chain_id: u32,
pub to_token_ca: BoundedVec<u8, IntentStringLen>,
pub from_amount: BoundedVec<u8, IntentStringLen>,
pub double_out: bool,
pub is_one_click: bool,
pub is_anti_mev: bool,
Expand Down
3 changes: 3 additions & 0 deletions tee-worker/omni-executor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tee-worker/omni-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ hex-literal = "0.4"
hmac = "0.12.1"
jsonrpsee = { version = "0.24", features = ["server"] }
jsonwebtoken = "9.3.0"
libsecp256k1 = "0.7.1"
log = "0.4.22"
mockall = "0.13.1"
parity-scale-codec = "3.6.12"
Expand Down
1 change: 1 addition & 0 deletions tee-worker/omni-executor/executor-core/src/native_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub enum NativeTask {
#[codec(index = 24)]
PumpxTransferWidthdraw(
Identity,
Option<u32>, // request_id
u32, // chain_id
u32, // wallet_index
String, // recipient_address
Expand Down
4 changes: 2 additions & 2 deletions tee-worker/omni-executor/executor-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub use auth::*;
pub mod signature;
pub mod utils;
pub use heima_primitives::{
omni::*, teebag::DcapQuote, AccountId, BlockNumber, Hash, Identity, MrEnclave, Nonce,
ShardIdentifier, Web2IdentityType,
omni::*, teebag::DcapQuote, AccountId, BlockNumber, ChainAsset, Hash, Identity, MrEnclave,
Nonce, ShardIdentifier, Web2IdentityType,
};
use std::fmt::Debug;

Expand Down
190 changes: 127 additions & 63 deletions tee-worker/omni-executor/intent/executors/cross-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use async_trait::async_trait;
use executor_core::intent_executor::IntentExecutor;
use executor_primitives::utils::hex::ToHexPrefixed;
use executor_primitives::ChainAsset;
use executor_primitives::Intent;
use executor_primitives::IntentId;
use executor_primitives::PumpxOrderType;
Expand All @@ -34,7 +33,6 @@ use heima_authentication::auth_token::AUTH_TOKEN_ACCESS_TYPE;
use parity_scale_codec::Encode;
use pumpx::signer_client::ChainType;
use pumpx::signer_client::SignerClient;
use pumpx::types::ChainId;
use pumpx::types::CreateCrossOrderData;
use pumpx::types::CrossOrderInfo;
use pumpx::types::GasType;
Expand All @@ -43,6 +41,7 @@ use pumpx::types::NewLimitOrder;
use pumpx::types::NewMarketOrder;
use pumpx::types::SwapType;
use pumpx::PumpxApi;
use pumpx::{pubkey_to_evm_address, pubkey_to_solana_address};
use std::collections::HashMap;
use std::marker::PhantomData;
use std::sync::Arc;
Expand Down Expand Up @@ -136,7 +135,7 @@ impl<
intent: Intent,
) -> Result<Option<Vec<u8>>, ()> {
match intent {
Intent::Swap(ref swap_order, ref _ccsp, ref scsp) => {
Intent::Swap(ref _swap_order, ref _ccsp, ref scsp) => {
let Ok(mut rpc_client) = self.parentchain_rpc_client_factory.new_client().await
else {
log::error!("Failed to create rpc client");
Expand Down Expand Up @@ -188,12 +187,6 @@ impl<
// )?;
//

let from_amount_string = std::str::from_utf8(&swap_order.from_amount)
.map_err(|_| {
log::error!("Failed to parse from_amount_string");
})
.map(|v| v.to_string())?;

let intent_accepted_event_emit_call = parentchain_api_interface::tx()
.omni_account()
.intent_accepted(account_id.to_subxt_type(), intent_id, intent.to_subxt_type());
Expand All @@ -211,31 +204,29 @@ impl<
// TODO: update this when we have more providers
let SingleChainSwapProvider::Pumpx(pumpx_config) = scsp;

let chain_id = match swap_order.to_asset {
ChainAsset::Ethereum(..) => ChainId::EVM,
ChainAsset::Solana(_) => ChainId::Solana,
};
let usd_worth = std::str::from_utf8(&pumpx_config.usd_worth)
.map_err(|_| {
log::error!("Failed to parse usd_worth");
})
.map(|v| v.to_string())?;
let token_ca = std::str::from_utf8(&pumpx_config.token_ca)

let from_token_ca = std::str::from_utf8(&pumpx_config.from_token_ca)
.map_err(|_| {
log::error!("Failed to parse token_ca");
log::error!("Failed to parse from_token_ca");
})
.map(|v| v.to_string())?;

let to_token_ca = std::str::from_utf8(&pumpx_config.to_token_ca)
.map_err(|_| {
log::error!("Failed to parse to_token_ca");
})
.map(|v| v.to_string())?;
let Some(chain_type) = ChainType::from_pumpx_chain_id(chain_id.to_number() as u32)
else {
log::error!("Unsupported chain id: {:?}", chain_id);
return Err(());
};

let wallet_address = self
.pumpx_signer_client
.request_wallet(chain_type, pumpx_config.wallet_index, *account_id.as_ref())
.await
.map_err(|e| log::error!("Could not get wallet from pumpx-signer: {:?}", e))?;
let from_amount = std::str::from_utf8(&pumpx_config.from_amount)
.map_err(|_| {
log::error!("Failed to parse from_amount");
})
.map(|v| v.to_string())?;

let storage = PumpxJwtStorage::new(self.storage_db.clone());
let Some(access_token) = storage.get(&(account_id.clone(), AUTH_TOKEN_ACCESS_TYPE))
Expand All @@ -246,18 +237,27 @@ impl<

let pumpx_order_response: Option<Vec<u8>>;

if swap_order.from_asset.is_same_chain(&swap_order.to_asset) {
let user_trade_info =
self.pumpx_api.get_user_trade_info(&access_token).await.map_err(|_| {
log::error!("Failed to get user trade info");
if pumpx_config.from_chain_id == pumpx_config.to_chain_id {
let Some(chain_type) = ChainType::from_pumpx_chain_id(pumpx_config.to_chain_id)
else {
log::error!("Unsupported to_chain_id: {}", pumpx_config.to_chain_id);
return Err(());
};

let wallet_address = self
.pumpx_signer_client
.request_wallet(chain_type, pumpx_config.wallet_index, *account_id.as_ref())
.await
.map_err(|e| {
log::error!("Could not get wallet from pumpx-signer: {:?}", e)
})?;

let order_response = match pumpx_config.order_type {
PumpxOrderType::Market => {
let new_market_order = NewMarketOrder {
request_id: intent_id,
chain_id: chain_id.clone(),
token_ca,
chain_id: pumpx_config.to_chain_id,
token_ca: to_token_ca.clone(),
swap_type: match pumpx_config.swap_type {
1 => SwapType::Buy,
2 => SwapType::Sell,
Expand All @@ -269,12 +269,19 @@ impl<
return Err(());
},
},
amount_in: from_amount_string.clone(),
amount_in: from_amount.clone(),
double_out: pumpx_config.double_out,
is_one_click: pumpx_config.is_one_click,
address: wallet_address.to_hex(),
is_anti_mev: user_trade_info.data.is_anti_mev,
is_auto_slippage: user_trade_info.data.is_auto_slippage,
address: match chain_type {
ChainType::Evm => pubkey_to_evm_address(&wallet_address)?,
ChainType::Solana => pubkey_to_solana_address(&wallet_address)?,
_ => {
log::error!("Unsupported {:?} wallet address", chain_type);
return Err(());
},
},
is_anti_mev: pumpx_config.is_anti_mev,
is_auto_slippage: pumpx_config.is_auto_slippage,
gas_type: match pumpx_config.gas_type {
1 => GasType::Slow,
2 => GasType::Medium,
Expand All @@ -287,18 +294,18 @@ impl<
return Err(());
},
},
slippage: user_trade_info.data.slippage,
slippage: pumpx_config.slippage,
wallet_index: pumpx_config.wallet_index,
};
let market_order_unsigned_tx = self
let market_order_unsigned_tx_res = self
.pumpx_api
.create_market_order_unsigned_tx(&access_token, new_market_order)
.await
.map_err(|_| {
log::error!("Failed to create market order unsigned tx");
})?;

let tx_data = market_order_unsigned_tx.data.tx_data;
let tx_data = market_order_unsigned_tx_res.data.tx_data;
let mut messages_to_sign = Vec::new();
for tx in tx_data {
let tx_cleaned = tx.strip_prefix("0x").unwrap_or(&tx);
Expand All @@ -312,13 +319,6 @@ impl<
messages_to_sign.push(tx_bytes);
}

let Some(chain_type) =
ChainType::from_pumpx_chain_id(chain_id.to_number() as u32)
else {
log::error!("Unsupported chain id: {:?}", chain_id);
return Err(());
};

let signatures = match self
.pumpx_signer_client
.request_signatures(
Expand All @@ -344,13 +344,13 @@ impl<
.collect();

let market_order_tx = MarketOrderTx {
order_id: market_order_unsigned_tx.data.order_id,
order_id: market_order_unsigned_tx_res.data.order_id,
chain_id: market_order_unsigned_tx_res.data.chain_id,
tx_data: signed_tx_data,
chain_id: chain_id.clone(),
};
let market_order_tx_res = self
.pumpx_api
.send_market_order_tx(&access_token, market_order_tx)
.send_order_tx(&access_token, market_order_tx)
.await
.map_err(|_| {
log::error!("Failed to send market order tx");
Expand Down Expand Up @@ -381,9 +381,9 @@ impl<

let new_limit_order = NewLimitOrder {
request_id: intent_id,
chain_id: chain_id.clone(),
token_ca,
amount: from_amount_string.clone(),
chain_id: pumpx_config.to_chain_id,
token_ca: to_token_ca,
amount: from_amount,
swap_type: match pumpx_config.swap_type {
1 => SwapType::Buy,
2 => SwapType::Sell,
Expand All @@ -401,9 +401,16 @@ impl<
trailing_percent: pumpx_config
.trailing_percent
.map(|v| v.to_string()),
address: wallet_address.to_hex(),
is_anti_mev: user_trade_info.data.is_anti_mev,
is_auto_slippage: user_trade_info.data.is_auto_slippage,
address: match chain_type {
ChainType::Evm => pubkey_to_evm_address(&wallet_address)?,
ChainType::Solana => pubkey_to_solana_address(&wallet_address)?,
_ => {
log::error!("Unsupported {:?} wallet address", chain_type);
return Err(());
},
},
is_anti_mev: pumpx_config.is_anti_mev,
is_auto_slippage: pumpx_config.is_auto_slippage,
gas_type: match pumpx_config.gas_type {
1 => GasType::Slow,
2 => GasType::Medium,
Expand All @@ -416,33 +423,90 @@ impl<
return Err(());
},
},
slippage: user_trade_info.data.slippage,
slippage: pumpx_config.slippage,
wallet_index: pumpx_config.wallet_index,
};
let limit_order_response = self
let limit_order_res = self
.pumpx_api
.create_limit_order(&access_token, new_limit_order)
.await
.map_err(|_| {
log::error!("Failed to create limit order");
})?;

limit_order_response.encode()
limit_order_res.encode()
},
};
pumpx_order_response = Some(order_response);
} else {
// notify backend about it
let Some(from_chain_type) =
ChainType::from_pumpx_chain_id(pumpx_config.from_chain_id)
else {
log::error!("Unsupported from_chain_id: {}", pumpx_config.from_chain_id);
return Err(());
};

let Some(to_chain_type) =
ChainType::from_pumpx_chain_id(pumpx_config.to_chain_id)
else {
log::error!("Unsupported to_chain_id: {}", pumpx_config.to_chain_id);
return Err(());
};

let from_wallet_address = self
.pumpx_signer_client
.request_wallet(
from_chain_type,
pumpx_config.wallet_index,
*account_id.as_ref(),
)
.await
.map_err(|e| {
log::error!("Could not get from_wallet from pumpx-signer: {:?}", e)
})?;

let _to_wallet_address = self
.pumpx_signer_client
.request_wallet(
to_chain_type,
pumpx_config.wallet_index,
*account_id.as_ref(),
)
.await
.map_err(|e| {
log::error!("Could not get to_wallet from pumpx-signer: {:?}", e)
})?;

let cross_order_data = CreateCrossOrderData {
request_id: intent_id,
chain_id: chain_id.clone(),
info: vec![CrossOrderInfo {
chain_id: chain_id.clone(),
chain_id: pumpx_config.to_chain_id,
token_ca: to_token_ca,
swap_type: match pumpx_config.swap_type {
1 => SwapType::Buy,
2 => SwapType::Sell,
_ => {
log::error!("Unsupported swap type: {}", pumpx_config.swap_type);
return Err(());
},
},
is_one_click: pumpx_config.is_one_click,
cross_info: vec![CrossOrderInfo {
chain_id: pumpx_config.from_chain_id,
wallet_index: pumpx_config.wallet_index,
address: wallet_address.to_hex(),
amount: from_amount_string.clone(),
address: match from_chain_type {
ChainType::Evm => pubkey_to_evm_address(&from_wallet_address)?,
ChainType::Solana => {
pubkey_to_solana_address(&from_wallet_address)?
},
_ => {
log::error!("Unsupported {:?} wallet address", from_chain_type);
return Err(());
},
},
amount: from_amount,
usd: usd_worth,
token_ca: token_ca.clone(),
token_ca: from_token_ca,
}],
};
self.pumpx_api
Expand Down
Loading
Loading