Skip to content

Commit

Permalink
fix: balance transfer & deployed txn (#14)
Browse files Browse the repository at this point in the history
* chore: revert to original code

* chore: various refactors

* chore: multi-transaction send balance tests

* chore: fix clippy

* chore: upgrade alloy (#16)
  • Loading branch information
chris13524 authored Sep 10, 2024
1 parent c440bf1 commit cf7c229
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 105 deletions.
3 changes: 1 addition & 2 deletions crates/yttrium/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rust-version.workspace = true

[dependencies]
# Ethereum
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "b000e16", features = [
alloy = { git = "https://github.com/alloy-rs/alloy", version = "0.3.2", features = [
"contract",
"network",
"providers",
Expand Down Expand Up @@ -48,5 +48,4 @@ wiremock = "0.6.0"
reqwest.workspace = true

[build-dependencies]
alloy-primitives = { version = "0.7.0" }
serde_json = "1"
2 changes: 2 additions & 0 deletions crates/yttrium/src/bundler/pimlico/paymaster/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use serde::{Deserialize, Serialize};
pub struct UserOperationPreSponsorshipV07 {
pub sender: Address,
pub nonce: U256,
#[serde(skip_serializing_if = "Option::is_none")]
pub factory: Option<Address>,
#[serde(skip_serializing_if = "Option::is_none")]
pub factory_data: Option<Bytes>,
pub call_data: Bytes,
pub call_gas_limit: U256,
Expand Down
14 changes: 14 additions & 0 deletions crates/yttrium/src/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ pub const ENTRYPOINT_ADDRESS_V07: &str =
pub const ENTRYPOINT_V06_TYPE: &str = "v0.6";
pub const ENTRYPOINT_V07_TYPE: &str = "v0.7";

sol! (
struct PackedUserOperation {
address sender;
uint256 nonce;
bytes initCode;
bytes callData;
bytes32 accountGasLimits;
uint256 preVerificationGas;
bytes32 gasFees;
bytes paymasterAndData;
bytes signature;
}
);

sol!(
#[allow(missing_docs)]
#[sol(rpc)]
Expand Down
4 changes: 4 additions & 0 deletions crates/yttrium/src/entry_point/get_sender_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ where

let call_builder = instance.getSenderAddress(init_code);

// Note: you may need to static call getSenderAddress() not call() as per
// the spec. Leaving as-is for now.
// let call = call_builder.call_raw().await;

let call: Result<
crate::entry_point::EntryPoint::getSenderAddressReturn,
ContractError,
Expand Down
4 changes: 2 additions & 2 deletions crates/yttrium/src/smart_accounts/nonce.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy::primitives::U256;
use alloy::primitives::aliases::U192;

pub async fn get_nonce<P, T, N>(
provider: &P,
Expand All @@ -14,7 +14,7 @@ where
entry_point_address.to_address(),
provider,
);
let key = U256::ZERO;
let key = U192::ZERO;

let get_nonce_call =
entry_point_instance.getNonce(address.to_address(), key).call().await?;
Expand Down
36 changes: 35 additions & 1 deletion crates/yttrium/src/smart_accounts/safe.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use alloy::{
dyn_abi::DynSolValue,
primitives::{address, keccak256, Address, Bytes, Uint, U256},
providers::ReqwestProvider,
sol,
sol_types::SolCall,
sol_types::{SolCall, SolValue},
};

sol!(
Expand Down Expand Up @@ -158,3 +159,36 @@ pub fn factory_data(
saltNonce: U256::ZERO,
}
}

pub async fn get_account_address(
provider: ReqwestProvider,
owners: Owners,
) -> Address {
let creation_code =
SafeProxyFactory::new(SAFE_PROXY_FACTORY_ADDRESS, provider.clone())
.proxyCreationCode()
.call()
.await
.unwrap()
._0;
let initializer = get_initializer_code(owners.clone());
let deployment_code = DynSolValue::Tuple(vec![
DynSolValue::Bytes(creation_code.to_vec()),
DynSolValue::FixedBytes(
SAFE_ERC_7579_LAUNCHPAD_ADDRESS.into_word(),
32,
),
])
.abi_encode_packed();
let salt = keccak256(
DynSolValue::Tuple(vec![
DynSolValue::FixedBytes(
keccak256(initializer.abi_encode_packed()),
32,
),
DynSolValue::Uint(Uint::from(0), 256),
])
.abi_encode_packed(),
);
SAFE_PROXY_FACTORY_ADDRESS.create2(salt, keccak256(deployment_code))
}
Loading

0 comments on commit cf7c229

Please sign in to comment.