Skip to content
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

fix: balance transfer & deployed txn #14

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
Comment on lines +63 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you saying this is not correct and shouldn't work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the entry point says to do a staticcall when calling getSenderAddress. Here it's currently doing a regular call I think.

Not sure exactly the difference but it seems to work as-is for now for simple account so I'm leaving it as-is. But something to be aware of if there are issues in the future


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