Skip to content

Implement cross chain swaps #3364

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 39 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
489bc9d
feat(binance): add wallet API functionality
silva-fj Apr 10, 2025
dec6936
feat(cross-chain): integrate Binance API dependency in the cross-chai…
silva-fj Apr 11, 2025
debd3bb
feat(cross-chain): integrate BinanceApi in executor
silva-fj Apr 11, 2025
213ee4d
feat(cross-chain): add initial Binance integration
silva-fj Apr 11, 2025
007cb0e
Merge branch 'dev' into p-1395-intent-processing-cross-chain-swap
silva-fj Apr 11, 2025
ab7b623
Merge branch 'dev' into p-1395-intent-processing-cross-chain-swap
silva-fj Apr 11, 2025
abb38fa
cross-order should only be all for cross chain swaps
silva-fj Apr 11, 2025
2699d7b
feat(solana): implement RemoteSigner for transactions
silva-fj Apr 11, 2025
23debe3
refactor(solana): inject runtime Handle to RemoteSigner
silva-fj Apr 11, 2025
0daaf5a
feat(solana): create independent module for SDK
silva-fj Apr 11, 2025
18fe716
feat(solana): implement client for transactions
silva-fj Apr 11, 2025
10c5637
fixing solana exports
silva-fj Apr 11, 2025
ec57d99
refactoring solana client, injecting it to the cross chain intent
silva-fj Apr 11, 2025
0dd4907
feat(solana): add SPL token mapping for cross-chain swaps
silva-fj Apr 11, 2025
bdf14fa
feat(cross-chain): implement Solana token transfers
silva-fj Apr 11, 2025
ce009c4
Merge branch 'dev' into p-1395-intent-processing-cross-chain-swap
silva-fj Apr 11, 2025
8a560c7
Merge remote-tracking branch 'origin/dev' into p-1395-intent-processi…
silva-fj Apr 11, 2025
699563e
feat(cross-chain): implement Binance trading for swaps
silva-fj Apr 11, 2025
7db5210
fixing fmt issue
silva-fj Apr 11, 2025
27d179e
feat(cross-chain): integrate accounting contract client
silva-fj Apr 11, 2025
d8e9d99
initial setup accounting contract call
silva-fj Apr 11, 2025
1163176
fixing fmt issue
silva-fj Apr 11, 2025
1e22eff
adding more TODO's
silva-fj Apr 11, 2025
7e1b156
determine cross chain payout address
kziemianek Apr 11, 2025
e4d47c9
taplo fmt
kziemianek Apr 11, 2025
bc336ae
Merge branch 'dev' into p-1395-intent-processing-cross-chain-swap
kziemianek Apr 12, 2025
a8d7641
taplo fmt
kziemianek Apr 12, 2025
5f36ac7
remove address
kziemianek Apr 12, 2025
f8b0b95
create pumpx market order
kziemianek Apr 12, 2025
739686e
calculate binance traded amount
kziemianek Apr 12, 2025
9beea18
add debug info
kziemianek Apr 12, 2025
82feb91
fix clippy
Kailai-Wang Apr 12, 2025
8161663
Merge branch 'dev' into p-1395-intent-processing-cross-chain-swap
Kailai-Wang Apr 12, 2025
3adaf1c
use new api
Kailai-Wang Apr 12, 2025
9ec55a0
to_address
kziemianek Apr 13, 2025
2d35896
binance fills with decimals
kziemianek Apr 13, 2025
39b82a1
binance bnb amount received to bnb jagers
kziemianek Apr 13, 2025
9f8a4d8
Merge branch 'dev' into p-1395-intent-processing-cross-chain-swap
kziemianek Apr 13, 2025
e4a5991
add contract adress
kziemianek Apr 13, 2025
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
531 changes: 494 additions & 37 deletions tee-worker/omni-executor/Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tee-worker/omni-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"parentchain/signer",
"pumpx",
"rpc-server",
"solana",
]

resolver = "2"
Expand Down Expand Up @@ -59,6 +60,7 @@ regex = "1.7"
reqwest = { version = "0.12", features = ["json"] }
ring = "0.16.20"
rsa = "0.9.7"
rust_decimal = "1.37.1"
scale-encode = "0.10.0"
scale-info = "2.11.6"
secp256k1 = "=0.29.1"
Expand All @@ -71,6 +73,7 @@ solana-client = "2.1.5"
solana-sdk = "2.1.5"
sp-core = "35.0.0"
sp-state-machine = { version = "0.44.0", features = ["std"] }
spl-associated-token-account = "6.0.0"
spl-token = "7.0.0"
subxt = "0.38.0"
subxt-core = "0.38.0"
Expand Down Expand Up @@ -105,6 +108,7 @@ parentchain-rpc-client = { path = "parentchain/rpc-client" }
parentchain-signer = { path = "parentchain/signer" }
pumpx = { path = "pumpx" }
rpc-server = { path = "rpc-server" }
solana = { path = "solana" }
solana-intent-executor = { path = "intent/executors/solana" }

[workspace.lints.clippy]
Expand Down
9 changes: 8 additions & 1 deletion tee-worker/omni-executor/binance-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
mod convert_api;
mod error;
mod spot_trading_api;
pub mod spot_trading_api;
mod traits;
mod types;
mod wallet_api;

use convert_api::ConvertApi;
use error::Error;
Expand All @@ -16,6 +17,7 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};
use url::Url;
use wallet_api::WalletApi;

const MAX_RECV_WINDOW: u32 = 60000;

Expand Down Expand Up @@ -47,6 +49,11 @@ impl BinanceApi {
SpotTradingApi::new(self)
}

/// Create a new WalletApi instance
pub fn wallet(&self) -> WalletApi {
WalletApi::new(self)
}

/// Create HMAC SHA256 signature for request parameters
pub fn sign_request(&self, query_string: &str) -> String {
let mut mac = Hmac::<Sha256>::new_from_slice(self.api_secret.as_bytes())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod types;
pub mod types;

use crate::{error::Error, traits::TryIntoParams, BinanceApi, Method};
use std::collections::HashMap;
Expand Down
38 changes: 38 additions & 0 deletions tee-worker/omni-executor/binance-api/src/wallet_api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
mod types;

use types::{CoinInfo, DepositAddress};

use crate::{error::Error, BinanceApi, Method};
use std::collections::HashMap;

/// https://developers.binance.com/docs/wallet/Introduction
const WALLET_API: &str = "/sapi/v1";

pub struct WalletApi<'a> {
base_api: &'a BinanceApi,
}

impl<'a> WalletApi<'a> {
pub fn new(binance_api: &BinanceApi) -> WalletApi {
WalletApi { base_api: binance_api }
}

/// Get information of coins (available for deposit and withdraw).
pub async fn get_all_coins_info(&self) -> Result<Vec<CoinInfo>, Error> {
let endpoint = format!("{}/capital/config/getall", WALLET_API);
self.base_api.make_signed_request(&endpoint, Method::GET, None, None).await
}

/// Get deposit address with network
pub async fn get_deposit_address(&self, coin: &str, network: &str) -> Result<String, Error> {
let endpoint = format!("{}/capital/deposit/address", WALLET_API);
let mut params = HashMap::new();
params.insert("coin".to_string(), coin.to_string());
params.insert("network".to_string(), network.to_string());
let response: DepositAddress = self
.base_api
.make_signed_request(&endpoint, Method::GET, Some(params), None)
.await?;
Ok(response.address)
}
}
62 changes: 62 additions & 0 deletions tee-worker/omni-executor/binance-api/src/wallet_api/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use serde::Deserialize;

#[derive(Debug, Deserialize)]
#[allow(dead_code)]
pub struct DepositAddress {
pub address: String,
pub coin: String,
pub tag: String,
pub url: String,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CoinInfo {
pub coin: String,
pub deposit_all_enable: bool,
pub free: String,
pub freeze: String,
pub ipoable: String,
pub ipoing: String,
pub is_legal_money: bool,
pub locked: String,
pub name: String,
pub network_list: Vec<NetworkInfo>,
pub storage: Option<String>,
pub trading: Option<bool>,
pub withdraw_all_enable: Option<bool>,
pub withdrawing: Option<String>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NetworkInfo {
pub address_regex: String,
pub coin: String,
// Optional fields that are only present under certain conditions
pub deposit_desc: Option<String>,
pub deposit_enable: bool,
pub is_default: bool,
pub memo_regex: String,
pub min_confirm: u32,
pub name: String,
pub network: String,
pub special_tips: String,
pub special_withdraw_tips: Option<String>,
pub un_lock_confirm: u32,
pub withdraw_desc: Option<String>,
pub withdraw_enable: bool,
pub withdraw_fee: String,
pub withdraw_integer_multiple: String,
pub withdraw_max: String,
pub withdraw_min: String,
pub withdraw_internal_min: Option<String>,
pub same_address: bool,
pub estimated_arrival_time: u32,
pub busy: bool,
pub contract_address_url: String,
pub contract_address: String,
pub reset_address_status: Option<bool>,
pub deposit_dust: Option<String>,
pub denomination: Option<u64>,
}
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, ChainAsset, Hash, Identity, MrEnclave,
Nonce, ShardIdentifier, Web2IdentityType,
identity::Address32, omni::*, teebag::DcapQuote, AccountId, BlockNumber, ChainAsset, Hash,
Identity, MrEnclave, Nonce, ShardIdentifier, Web2IdentityType,
};
use std::fmt::Debug;

Expand Down
4 changes: 4 additions & 0 deletions tee-worker/omni-executor/executor-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
url = { workspace = true }

# Local dependencies
accounting-contract-client = { workspace = true }
binance-api = { workspace = true }
cross-chain-intent-executor = { workspace = true }
ethereum-intent-executor = { workspace = true }
ethereum-rpc = { workspace = true }
executor-core = { workspace = true }
executor-crypto = { workspace = true }
executor-primitives = { workspace = true }
Expand All @@ -29,6 +32,7 @@ parentchain-rpc-client = { workspace = true }
parentchain-signer = { workspace = true }
pumpx = { workspace = true }
rpc-server = { workspace = true }
solana = { workspace = true }
solana-intent-executor = { workspace = true }

[lints]
Expand Down
35 changes: 30 additions & 5 deletions tee-worker/omni-executor/executor-worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use crate::cli::Cli;
use accounting_contract_client::AccountingContractClient;
use binance_api::BinanceApi;
use clap::Parser;
use cli::*;
use cross_chain_intent_executor::{Chain, CrossChainIntentExecutor, RpcEndpointRegistry};
Expand All @@ -38,8 +40,10 @@ use parentchain_rpc_client::{
ToPrimitiveType,
};
use parentchain_signer::{key_store::SubstrateKeyStore, TxSigner};
use pumpx::signer_client::SignerClient;
use pumpx::PumpxApi;
use rpc_server::{start_server as start_rpc_server, AuthTokenKeyStore};
use solana::SolanaClient;
use solana_intent_executor::SolanaIntentExecutor;
use std::env;
use std::io::Write;
Expand Down Expand Up @@ -72,7 +76,6 @@ async fn main() -> Result<(), ()> {

match cli.cmd {
Commands::Run(args) => {
let _binance_api_key = env::var("OE_BINANCE_API_KEY").unwrap_or("".to_string());
let auth_token_key_store =
AuthTokenKeyStore::new(args.auth_token_key_store_path.clone());
let jwt_rsa_private_key = auth_token_key_store.read().expect("Could not read jwt key");
Expand Down Expand Up @@ -116,10 +119,11 @@ async fn main() -> Result<(), ()> {
let aes256_key_store = Aes256KeyStore::new(args.aes256_key_store_path.clone());
let aes256_key = aes256_key_store.read().expect("Could not read aes256 key");

let pumpx_signer_client = Arc::new(pumpx::signer_client::SignerClient::new(
args.pumpx_signer_url.clone(),
pumpx_signer_pair,
));
let pumpx_signer_client: Arc<Box<dyn SignerClient>> =
Arc::new(Box::new(pumpx::signer_client::PumpxSignerClient::new(
args.pumpx_signer_url.clone(),
pumpx_signer_pair,
)));

let ethereum_intent_executor =
EthereumIntentExecutor::new(&args.ethereum_url, &args.delegation_contract_address)?;
Expand All @@ -139,13 +143,34 @@ async fn main() -> Result<(), ()> {
let pumpx_api_base_url = std::env::var("OE_PUMPX_API_BASE_URL").ok();
let pumpx_api = Arc::new(PumpxApi::new(pumpx_api_base_url));

let binance_api_key = env::var("OE_BINANCE_API_KEY").unwrap_or("".to_string());
let binance_api_secret = env::var("OE_BINANCE_API_SECRET").unwrap_or("".to_string());
let binance_api_base_url = env::var("OE_BINANCE_API_BASE_URL").ok();
let binance_api = Arc::new(BinanceApi::new(
binance_api_key,
binance_api_secret,
binance_api_base_url,
));

let solana_client = Arc::new(SolanaClient::new(&args.solana_url));

let ethereum_rpc_provider = ethereum_rpc::AlloyRpcProvider::new(&args.ethereum_url);
let accounting_contract_client = AccountingContractClient::new(
ethereum_rpc_provider,
//todo: from CLI
"0xb0830ef478a215ed393c20a0c97aa69869a0beea".parse().unwrap(),
);

let cross_chain_intent_executor = CrossChainIntentExecutor::new(
parentchain_rpc_client_factory.clone(),
tx_signer.clone(),
rpc_endpoint_registry,
pumpx_signer_client.clone(),
pumpx_api.clone(),
storage_db.clone(),
binance_api,
solana_client,
Arc::new(accounting_contract_client),
)?;

let intent_id_store: Arc<Box<dyn IntentIdStore>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ async-trait = { workspace = true }
hex = { workspace = true }
log = { workspace = true }
parity-scale-codec = { workspace = true }
rust_decimal = { workspace = true }
tokio = { workspace = true }

# Local dependencies
accounting-contract-client = { workspace = true }
alloy = { workspace = true }
base58 = { workspace = true }
binance-api = { workspace = true }
ethereum-rpc = { workspace = true }
executor-core = { workspace = true }
executor-primitives = { workspace = true }
executor-storage = { workspace = true }
Expand All @@ -21,6 +28,7 @@ parentchain-api-interface = { workspace = true }
parentchain-rpc-client = { workspace = true }
parentchain-signer = { workspace = true }
pumpx = { workspace = true }
solana = { workspace = true }

[lints]
workspace = true
Loading