Skip to content

Commit a5c701c

Browse files
authored
Cross chain swap instant payout (#3443)
* instant payout
1 parent 30bc4dd commit a5c701c

File tree

22 files changed

+1457
-529
lines changed

22 files changed

+1457
-529
lines changed

tee-worker/omni-executor/Cargo.lock

Lines changed: 52 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tee-worker/omni-executor/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ regex = "1.7"
6464
reqwest = { version = "0.12", features = ["json"] }
6565
ring = "0.16.20"
6666
rsa = "0.9.7"
67+
ruint = "1.13.1"
6768
rust_decimal = "1.37.1"
6869
scale-encode = "0.10.0"
6970
scale-info = "2.11.6"
@@ -83,12 +84,14 @@ subxt = "0.40.0"
8384
subxt-core = "0.40.0"
8485
subxt-signer = { version = "0.40.0", features = ["subxt"] }
8586
tempfile = "3.19.1"
87+
test-log = { version = "0.2.17", features = ["trace"] }
8688
tokio = "1.43.0"
8789
tracing = "0.1.41"
8890
tracing-subscriber = "0.3.19"
8991
url = "2.5.4"
9092
uuid = "1.16.0"
9193

94+
9295
# Local dependencies
9396
accounting-contract = { path = "accounting-contract/solana/programs/accounting-contract", features = ["no-entrypoint"] }
9497
accounting-contract-client = { path = "accounting-contract-client" }

tee-worker/omni-executor/accounting-contract-client/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub trait AccountingContractApi: Send + Sync {
2929
async fn get_nonce(&self, user: Address) -> Result<U256, ()>;
3030

3131
async fn get_balance(&self) -> Result<U256, ()>;
32+
33+
async fn get_address(&self) -> Address;
34+
35+
async fn get_signer_address(&self) -> Address;
3236
}
3337

3438
pub struct AccountingContractClient<P: RpcProvider<Transaction = TransactionRequest> + Send + Sync>
@@ -93,6 +97,14 @@ impl<P: RpcProvider<Transaction = TransactionRequest> + Send + Sync> AccountingC
9397
Ok(balance)
9498
})
9599
}
100+
101+
async fn get_address(&self) -> Address {
102+
self.contract_address
103+
}
104+
105+
async fn get_signer_address(&self) -> Address {
106+
self.provider.get_wallet_address().await.expect("No signer address")
107+
}
96108
}
97109

98110
#[cfg(feature = "mocks")]
@@ -120,6 +132,14 @@ pub mod mocks {
120132
async fn get_nonce(&self, user: Address) -> Result<U256, ()>;
121133

122134
async fn get_balance(&self) -> Result<U256, ()>;
135+
136+
async fn get_address(&self) -> Address {
137+
Address::default();
138+
}
139+
140+
async fn get_signer_address(&self) -> Address {
141+
Address::default();
142+
}
123143
}
124144
}
125145
}

tee-worker/omni-executor/ethereum-rpc/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub mod signer;
1919

2020
use std::str::FromStr;
2121

22+
use alloy::network::Ethereum;
2223
use alloy::network::EthereumWallet;
24+
use alloy::network::NetworkWallet;
2325
use alloy::primitives::Address;
2426
use alloy::primitives::U256;
2527
use alloy::providers::Provider;
@@ -65,6 +67,7 @@ pub trait RpcProvider: Send + Sync {
6567
async fn estimate_gas(&self, tx: Self::Transaction) -> Result<u64, ()>;
6668
async fn get_gas_price(&self) -> Result<u128, ()>;
6769
async fn call(&self, tx: Self::Transaction) -> Result<Vec<u8>, ()>;
70+
async fn get_wallet_address(&self) -> Result<Address, ()>;
6871
}
6972

7073
pub struct AlloyRpcProvider {
@@ -180,6 +183,14 @@ impl RpcProvider for AlloyRpcProvider {
180183

181184
Ok(result.to_vec())
182185
}
186+
187+
async fn get_wallet_address(&self) -> Result<Address, ()> {
188+
if let Some(ref wallet) = self.wallet {
189+
Ok(<EthereumWallet as NetworkWallet<Ethereum>>::default_signer_address(wallet))
190+
} else {
191+
Err(())
192+
}
193+
}
183194
}
184195

185196
#[async_trait]
@@ -227,6 +238,7 @@ pub mod mocks {
227238
async fn estimate_gas(&self, tx: TransactionRequest) -> Result<u64, ()>;
228239
async fn get_gas_price(&self) -> Result<u128, ()>;
229240
async fn call(&self, tx: TransactionRequest) -> Result<Vec<u8>, ()>;
241+
async fn get_wallet_address(&self) -> Result<Address, ()>;
230242
}
231243

232244

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::Storage;
2+
use executor_primitives::AccountId;
3+
use executor_primitives::ChainAsset;
4+
use parity_scale_codec::Encode;
5+
use rocksdb::DB;
6+
use std::sync::Arc;
7+
8+
const STORAGE_NAME: &str = "asset_lock_storage";
9+
10+
#[derive(Encode)]
11+
pub struct Key {
12+
pub account_id: AccountId,
13+
pub asset_id: ChainAsset,
14+
}
15+
16+
pub struct AssetLockStorage {
17+
db: Arc<DB>,
18+
}
19+
20+
impl AssetLockStorage {
21+
pub fn new(db: Arc<DB>) -> Self {
22+
Self { db }
23+
}
24+
}
25+
26+
impl Storage<Key, Vec<u8>> for AssetLockStorage {
27+
fn db(&self) -> Arc<crate::StorageDB> {
28+
self.db.clone()
29+
}
30+
31+
fn name(&self) -> &'static str {
32+
STORAGE_NAME
33+
}
34+
}

tee-worker/omni-executor/executor-storage/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ mod pumpx_jwt;
2424
pub use pumpx_jwt::PumpxJwtStorage;
2525
mod intent_id;
2626
pub use intent_id::IntentIdStorage;
27+
mod asset_lock;
28+
pub use asset_lock::AssetLockStorage;
29+
pub use asset_lock::Key as AssetLockStorageKey;
2730
use tracing::error;
2831

2932
const STORAGE_DB_PATH: &str = "storage_db";

tee-worker/omni-executor/executor-worker/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ alloy = { workspace = true, features = ["signer-local"] }
99
clap = { workspace = true, features = ["derive"] }
1010
hex = { workspace = true }
1111
metrics-exporter-prometheus = { workspace = true }
12+
rust_decimal = { workspace = true }
1213
scale-encode = { workspace = true }
1314
serde_json = { workspace = true }
1415
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }
@@ -26,6 +27,7 @@ executor-core = { workspace = true }
2627
executor-crypto = { workspace = true }
2728
executor-primitives = { workspace = true }
2829
executor-storage = { workspace = true }
30+
intent-asset-lock = { workspace = true }
2931
native-task-handler = { workspace = true }
3032
parentchain-attestation = { workspace = true }
3133
parentchain-listener = { workspace = true }

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ use executor_crypto::rsa::{traits::PublicKeyParts, Rsa3072PubKey};
3939
use executor_crypto::{ecdsa, ed25519, PairTrait};
4040
use executor_primitives::AccountId;
4141
use executor_storage::{init_storage, StorageDB};
42+
use intent_asset_lock::precise::PreciseAssetsLock;
43+
use intent_asset_lock::AccountAssetLocks;
4244
use metrics_exporter_prometheus::PrometheusBuilder;
4345
use native_task_handler::{
4446
run_native_task_handler, Aes256KeyStore, TaskHandlerContext, MAX_CONCURRENT_TASKS,
@@ -53,6 +55,7 @@ use parentchain_signer::{key_store::SubstrateKeyStore, TxSigner};
5355
use pumpx::{pubkey_to_evm_address, pubkey_to_solana_address};
5456
use pumpx::{PumpxApi, PumpxApiClient};
5557
use rpc_server::{start_server as start_rpc_server, AuthTokenKeyStore};
58+
use rust_decimal::Decimal;
5659
use solana::SolanaRpcClient;
5760
use solana_intent_executor::SolanaIntentExecutor;
5861
use std::collections::HashMap;
@@ -286,7 +289,11 @@ async fn main() -> Result<(), ()> {
286289
let join = start_wallet_metrics(Handle::current(), wallet_metrics);
287290
// wallet monitoring setup end
288291

292+
let account_assets_lock: Arc<AccountAssetLocks<PreciseAssetsLock>> =
293+
Arc::new(AccountAssetLocks::new(storage_db.clone()));
294+
289295
let cross_chain_intent_executor = CrossChainIntentExecutor::new(
296+
account_assets_lock,
290297
rpc_endpoint_registry,
291298
pumpx_signer_client.clone(),
292299
pumpx_api.clone(),
@@ -296,6 +303,7 @@ async fn main() -> Result<(), ()> {
296303
solana_client,
297304
Arc::new(Box::new(evm_accounting_contract_client)),
298305
Arc::new(Box::new(solana_accounting_contract_client)),
306+
Decimal::from_str("200").unwrap(),
299307
)?;
300308

301309
let task_handler_context = TaskHandlerContext::new(

tee-worker/omni-executor/intent/asset-lock/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ authors = ['Trust Computing GmbH <info@litentry.com>']
55
edition.workspace = true
66

77
[dependencies]
8-
ruint = "1.13.1"
8+
parity-scale-codec = { workspace = true }
9+
ruint = { workspace = true, features = ["parity-scale-codec"] }
10+
tracing = { workspace = true }
911

1012
# Local dependencies
1113
executor-core = { workspace = true }
1214
executor-primitives = { workspace = true }
15+
executor-storage = { workspace = true }
1316
heima-primitives = { workspace = true }
1417

18+
19+
[dev-dependencies]
20+
tempfile = { workspace = true }
21+
1522
[lints]
1623
workspace = true

0 commit comments

Comments
 (0)