Skip to content

Commit f204758

Browse files
committed
Added execute call
1 parent 1cd3130 commit f204758

File tree

15 files changed

+762
-87
lines changed

15 files changed

+762
-87
lines changed

crates/yttrium/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ rust-version.workspace = true
66
license.workspace = true
77

88
[lib]
9-
# name = "yttrium_dart"
9+
name = "yttrium_dart"
1010
crate-type = ["lib", "cdylib", "staticlib"]
1111

1212
[features]

crates/yttrium/src/chain_abstraction/dart_compat.rs

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#[cfg(feature = "chain_abstraction_client")]
22
use {
33
alloy::{
4-
providers::Provider,
4+
network::Ethereum,
5+
primitives::PrimitiveSignature,
6+
providers::{Provider, RootProvider},
57
// sol,
68
// sol_types::SolCall,
79
},
@@ -12,7 +14,7 @@ use {
1214
prepare::PrepareResponseAvailable,
1315
status::{StatusResponse, StatusResponseCompleted},
1416
},
15-
client::Client,
17+
client::{Client,ExecuteDetails},
1618
currency::Currency,
1719
error::PrepareDetailedResponse,
1820
ui_fields::UiFields,
@@ -34,6 +36,26 @@ pub enum FFIError {
3436
General(String),
3537
}
3638

39+
#[cfg(feature = "chain_abstraction_client")]
40+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
41+
pub struct FFIPrimitiveSignature {
42+
pub y_parity: bool,
43+
pub r: String,
44+
pub s: String,
45+
}
46+
47+
impl From<FFIPrimitiveSignature> for PrimitiveSignature {
48+
49+
fn from(ffi_signature: FFIPrimitiveSignature) -> Self {
50+
type U256 = alloy::primitives::U256;
51+
PrimitiveSignature::new(
52+
U256::from_str(&ffi_signature.r).unwrap(),
53+
U256::from_str(&ffi_signature.s).unwrap(),
54+
ffi_signature.y_parity,
55+
)
56+
}
57+
}
58+
3759
// ----------------
3860

3961
#[cfg(feature = "chain_abstraction_client")]
@@ -141,12 +163,8 @@ pub struct LocalAmountAccCompat {
141163
pub fees: Vec<FeeCompat>,
142164
}
143165

144-
impl From<crate::chain_abstraction::local_fee_acc::LocalAmountAcc>
145-
for LocalAmountAccCompat
146-
{
147-
fn from(
148-
original: crate::chain_abstraction::local_fee_acc::LocalAmountAcc,
149-
) -> Self {
166+
impl From<crate::chain_abstraction::local_fee_acc::LocalAmountAcc> for LocalAmountAccCompat {
167+
fn from(original: crate::chain_abstraction::local_fee_acc::LocalAmountAcc) -> Self {
150168
Self { fees: original.get_fees_compat() }
151169
}
152170
}
@@ -164,8 +182,7 @@ impl ChainAbstractionClient {
164182

165183
pub fn new(project_id: String, pulse_metadata: FFIPulseMetadata) -> Self {
166184
let ffi_pulse_metadata = PulseMetadata::try_from(pulse_metadata).unwrap();
167-
let ffi_project_id = ProjectId::from(project_id.clone());
168-
let client = Client::new(ffi_project_id, ffi_pulse_metadata);
185+
let client = Client::new(ProjectId::from(project_id.clone()), ffi_pulse_metadata);
169186
Self { project_id, client }
170187
}
171188

@@ -239,28 +256,52 @@ impl ChainAbstractionClient {
239256
.map_err(|e| FFIError::General(e.to_string()))
240257
}
241258

242-
// pub async fn execute(
259+
pub async fn execute(
260+
&self,
261+
ui_fields: UiFields,
262+
route_txn_sigs: Vec<FFIPrimitiveSignature>,
263+
initial_txn_sig: FFIPrimitiveSignature,
264+
) -> Result<ExecuteDetails, FFIError> {
265+
266+
let ffi_route_txn_sigs = route_txn_sigs
267+
.into_iter()
268+
.map(|sig| PrimitiveSignature::from(sig))
269+
.collect();
270+
271+
let ffi_initial_txn_sig = PrimitiveSignature::from(initial_txn_sig);
272+
273+
self.client
274+
.execute(ui_fields, ffi_route_txn_sigs, ffi_initial_txn_sig)
275+
.await
276+
// TODO wanted to return ExecuteError directly here, but can't because Swift keeps the UniFFI lifer private to the yttrium crate and not available to kotlin-ffi crate
277+
// This will be fixed when we merge these crates
278+
.map_err(|e| FFIError::General(e.to_string()))
279+
}
280+
281+
// pub async fn estimate_fees(
243282
// &self,
244-
// ui_fields: UiFields,
245-
// route_txn_sigs: Vec<FFIPrimitiveSignature>,
246-
// initial_txn_sig: FFIPrimitiveSignature,
247-
// ) -> Result<ExecuteDetails, FFIError> {
283+
// chain_id: String,
284+
// ) -> Result<Eip1559Estimation, FFIError> {
248285
// self.client
249-
// .execute(ui_fields, route_txn_sigs, initial_txn_sig)
286+
// .provider_pool
287+
// .get_provider(&chain_id)
288+
// .await
289+
// .estimate_eip1559_fees(None)
250290
// .await
251-
// // TODO wanted to return ExecuteError directly here, but can't because Swift keeps the UniFFI lifer private to the yttrium crate and not available to kotlin-ffi crate
252-
// // This will be fixed when we merge these crates
291+
// .map(Into::into)
253292
// .map_err(|e| FFIError::General(e.to_string()))
254293
// }
255294

256295
pub async fn estimate_fees(
257296
&self,
258297
chain_id: String,
259298
) -> Result<Eip1559Estimation, FFIError> {
260-
self.client
261-
.provider_pool
262-
.get_provider(&chain_id)
263-
.await
299+
let url = format!("https://rpc.walletconnect.org/v1?chainId={chain_id}&projectId={}", self.project_id)
300+
.parse()
301+
.expect("Invalid RPC URL");
302+
303+
let provider = RootProvider::<Ethereum>::new_http(url);
304+
provider
264305
.estimate_eip1559_fees(None)
265306
.await
266307
.map(Into::into)

0 commit comments

Comments
 (0)