Skip to content

Commit

Permalink
feat: batch gas abstraction txns, refactor Calls, remove cli crate
Browse files Browse the repository at this point in the history
  • Loading branch information
chris13524 committed Jan 10, 2025
1 parent 519ca40 commit 62b3374
Show file tree
Hide file tree
Showing 18 changed files with 371 additions and 229 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[workspace]
members = [
"crates/cli",
"crates/kotlin-ffi",
"crates/yttrium",
"crates/yttrium_dart/rust",
Expand Down
11 changes: 0 additions & 11 deletions crates/cli/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions crates/cli/src/main.rs

This file was deleted.

23 changes: 12 additions & 11 deletions crates/kotlin-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@ use {
std::time::Duration,
yttrium::{
account_client::AccountClient as YAccountClient,
call::{
send::safe_test::{
self, DoSendTransactionParams, OwnerSignature,
PreparedSendTransaction,
},
Call,
},
chain_abstraction::{
api::{
prepare::{PrepareResponse, PrepareResponseAvailable},
status::{StatusResponse, StatusResponseCompleted},
InitialTransaction,
},
client::Client,
currency::Currency,
ui_fields::UiFields,
},
config::Config,
execution::{
send::safe_test::{
self, DoSendTransactionParams, OwnerSignature,
PreparedSendTransaction,
},
Execution,
},
smart_accounts::{
account_address::AccountAddress as FfiAccountAddress,
safe::{SignOutputEnum, SignStep3Params},
Expand Down Expand Up @@ -127,10 +126,12 @@ impl ChainAbstractionClient {

pub async fn prepare(
&self,
initial_transaction: InitialTransaction,
chain_id: String,
from: FFIAddress,
call: Call,
) -> Result<PrepareResponse, FFIError> {
self.client
.prepare(initial_transaction)
.prepare(chain_id, from, call)
.await
.map_err(|e| FFIError::General(e.to_string()))
}
Expand Down Expand Up @@ -261,7 +262,7 @@ impl FFIAccountClient {

pub async fn prepare_send_transactions(
&self,
transactions: Vec<Execution>,
transactions: Vec<Call>,
) -> Result<PreparedSendTransaction, FFIError> {
self.account_client
.prepare_send_transactions(transactions)
Expand Down
8 changes: 4 additions & 4 deletions crates/yttrium/src/account_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use {
client::BundlerClient, config::BundlerConfig,
pimlico::paymaster::client::PaymasterClient,
},
config::Config,
execution::{
call::{
send::{
do_send_transactions, prepare_send_transaction,
safe_test::{
self, DoSendTransactionParams, OwnerSignature,
PreparedSendTransaction,
},
},
Execution,
Call,
},
config::Config,
smart_accounts::{
account_address::AccountAddress,
safe::{
Expand Down Expand Up @@ -96,7 +96,7 @@ impl AccountClient {

pub async fn prepare_send_transactions(
&self,
transactions: Vec<Execution>,
transactions: Vec<Call>,
) -> eyre::Result<PreparedSendTransaction> {
prepare_send_transaction(
transactions,
Expand Down
31 changes: 16 additions & 15 deletions crates/yttrium/src/execution.rs → crates/yttrium/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,46 @@ pub mod send;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct Execution {
#[serde(rename_all = "camelCase")]
pub struct Call {
pub to: Address,
pub value: U256,
pub data: Bytes,
pub input: Bytes,
}

impl Execution {
pub fn new(to: Address, value: U256, data: Bytes) -> Self {
Self { to, value, data }
impl Call {
pub fn new(to: Address, value: U256, input: Bytes) -> Self {
Self { to, value, input }
}

pub fn new_from_strings(
to: String,
value: String,
data: String,
input: String,
) -> eyre::Result<Self> {
let to = to.parse()?;
let value = value.parse()?;
let data = data.parse()?;
Ok(Self { to, value, data })
let input = input.parse()?;
Ok(Self { to, value, input })
}
}

impl std::fmt::Display for Execution {
impl std::fmt::Display for Call {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Transaction(to: {}, value: {}, data: {})",
self.to, self.value, self.data
"Transaction(to: {}, value: {}, input: {})",
self.to, self.value, self.input
)
}
}

impl Execution {
impl Call {
pub fn mock() -> Self {
Self {
to: address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"),
value: U256::ZERO,
data: "0x68656c6c6f".parse().unwrap(),
input: "0x68656c6c6f".parse().unwrap(),
}
}
}
Expand All @@ -56,9 +57,9 @@ mod tests {

#[test]
fn test_new_from_strings() -> eyre::Result<()> {
let expected_transaction = Execution::mock();
let expected_transaction = Call::mock();

let transaction = Execution::new_from_strings(
let transaction = Call::new_from_strings(
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".to_string(),
"0".to_string(),
"0x68656c6c6f".to_string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::{
config::Config, execution::Execution,
call::Call, config::Config,
smart_accounts::account_address::AccountAddress,
user_operation::UserOperationV07,
},
Expand Down Expand Up @@ -47,7 +47,7 @@ impl fmt::Display for SentUserOperationHash {
}

pub async fn prepare_send_transaction(
transactions: Vec<Execution>,
transactions: Vec<Call>,
owner: AccountAddress,
_chain_id: u64,
config: Config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use {
paymaster::client::PaymasterClient,
},
},
call::Call,
chain::ChainId,
config::Config,
entry_point::{EntryPointVersion, ENTRYPOINT_ADDRESS_V07},
execution::Execution,
smart_accounts::{
account_address::AccountAddress,
nonce::get_nonce,
Expand Down Expand Up @@ -91,7 +91,7 @@ pub async fn get_address(
}

pub async fn send_transactions(
execution_calldata: Vec<Execution>,
execution_calldata: Vec<Call>,
owner: LocalSigner<SigningKey>,
address: Option<AccountAddress>,
authorization_list: Option<Vec<Authorization>>,
Expand Down Expand Up @@ -174,7 +174,7 @@ pub struct DoSendTransactionParams {
}

pub async fn prepare_send_transactions(
execution_calldata: Vec<Execution>,
execution_calldata: Vec<Call>,
owner: Address,
address: Option<AccountAddress>,
authorization_list: Option<Vec<Authorization>>,
Expand Down Expand Up @@ -210,7 +210,7 @@ pub async fn prepare_send_transactions(

#[allow(clippy::too_many_arguments)]
pub async fn prepare_send_transactions_inner<P, T, N>(
execution_calldata: Vec<Execution>,
execution_calldata: Vec<Call>,
owners: Owners,
address: Option<AccountAddress>,
authorization_list: Option<Vec<Authorization>>,
Expand Down Expand Up @@ -449,8 +449,8 @@ mod tests {
use {
super::*,
crate::{
call::Call,
chain::ChainId,
execution::Execution,
smart_accounts::safe::{
prepare_sign, sign, sign_step_3, PreparedSignature,
SignOutputEnum,
Expand Down Expand Up @@ -493,10 +493,10 @@ mod tests {
)
.await;

let transaction = vec![Execution {
let transaction = vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}];

let receipt = send_transactions(
Expand All @@ -512,10 +512,10 @@ mod tests {
let balance = provider.get_balance(destination.address()).await?;
assert_eq!(balance, Uint::from(1));

let transaction = vec![Execution {
let transaction = vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}];

let receipt =
Expand Down Expand Up @@ -589,10 +589,10 @@ mod tests {
)
.await;

let transaction = vec![Execution {
let transaction = vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}];

let receipt = send_transactions(
Expand Down Expand Up @@ -630,10 +630,10 @@ mod tests {
)
.await;

let transaction = vec![Execution {
let transaction = vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}];

let receipt = send_transactions(transaction, owner, None, None, config)
Expand Down Expand Up @@ -673,10 +673,10 @@ mod tests {
)
.await;

let transaction = vec![Execution {
let transaction = vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}];

let receipt = send_transactions(
Expand Down Expand Up @@ -803,15 +803,15 @@ mod tests {
.await;

let transaction = vec![
Execution {
Call {
to: destination1.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
},
Execution {
Call {
to: destination2.address(),
value: Uint::from(2),
data: Bytes::new(),
input: Bytes::new(),
},
];

Expand Down Expand Up @@ -1034,10 +1034,10 @@ mod tests {
provider.get_balance(destination.address()).await.unwrap();
assert_eq!(balance, Uint::from(0));
let receipt = send_transactions(
vec![Execution {
vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}],
owner.clone(),
None,
Expand Down Expand Up @@ -1136,10 +1136,10 @@ mod tests {
)
.await;

let transaction = vec![Execution {
let transaction = vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}];

let receipt = send_transactions(transaction, owner, None, None, config)
Expand Down Expand Up @@ -1228,10 +1228,10 @@ mod tests {
provider.get_code_at(authority.address()).await?
);

let transaction = vec![Execution {
let transaction = vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}];

let receipt = send_transactions(
Expand Down Expand Up @@ -1381,10 +1381,10 @@ mod tests {
provider.get_code_at(authority.address()).await?
);

let transaction: Vec<_> = vec![Execution {
let transaction = vec![Call {
to: destination.address(),
value: Uint::from(1),
data: Bytes::new(),
input: Bytes::new(),
}];

let receipt = send_transactions(
Expand Down
Loading

0 comments on commit 62b3374

Please sign in to comment.