Skip to content

Commit

Permalink
fix: Safe bricking (#33)
Browse files Browse the repository at this point in the history
* chore: refactor 3

* fix: bricked account
  • Loading branch information
chris13524 authored Oct 2, 2024
1 parent 22e90cf commit 6cea557
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 79 deletions.
7 changes: 4 additions & 3 deletions crates/yttrium/src/bundler/models/user_operation_receipt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy::primitives::Address;
use alloy::primitives::{b256, Address, B256};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -19,10 +19,11 @@ pub struct UserOperationReceiptReceipt {
pub effective_gas_price: String,
}

// TODO replace with alloy's UserOperationReceipt
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserOperationReceipt {
pub user_op_hash: String,
pub user_op_hash: B256,
pub entry_point: Address,
pub sender: Address,
pub nonce: String,
Expand All @@ -38,7 +39,7 @@ pub struct UserOperationReceipt {
impl UserOperationReceipt {
pub fn mock() -> Self {
UserOperationReceipt {
user_op_hash: "0x93c06f3f5909cc2b192713ed9bf93e3e1fde4b22fcd2466304fa404f9b80ff90".to_string(),
user_op_hash: b256!("93c06f3f5909cc2b192713ed9bf93e3e1fde4b22fcd2466304fa404f9b80ff90"),
entry_point: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
.parse()
.unwrap(),
Expand Down
24 changes: 4 additions & 20 deletions crates/yttrium/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,58 +73,46 @@ impl fmt::Display for ChainId {
pub struct Chain {
pub id: ChainId,
pub entry_point_version: EntryPointVersion,
pub name: &'static str,
}

impl Chain {
pub fn new(
id: ChainId,
entry_point_version: EntryPointVersion,
name: &'static str,
) -> Self {
Self { id, entry_point_version, name }
pub fn new(id: ChainId, entry_point_version: EntryPointVersion) -> Self {
Self { id, entry_point_version }
}

pub const ETHEREUM_MAINNET_V07: Self = Self {
id: ChainId::ETHEREUM_MAINNET,
entry_point_version: EntryPointVersion::V07,
name: "Ethereum Mainnet",
};

pub const ETHEREUM_MAINNET_V06: Self = Self {
id: ChainId::ETHEREUM_MAINNET,
entry_point_version: EntryPointVersion::V06,
name: "Ethereum Mainnet",
};

pub const ETHEREUM_SEPOLIA_V07: Self = Self {
id: ChainId::ETHEREUM_SEPOLIA,
entry_point_version: EntryPointVersion::V07,
name: "Ethereum Sepolia",
};

pub const BASE_SEPOLIA_V07: Self = Self {
id: ChainId::BASE_SEPOLIA,
entry_point_version: EntryPointVersion::V07,
name: "Base Sepolia",
};

pub const ETHEREUM_SEPOLIA_V06: Self = Self {
id: ChainId::ETHEREUM_SEPOLIA,
entry_point_version: EntryPointVersion::V06,
name: "Ethereum Sepolia",
};

pub const LOCAL_ETHEREUM_SEPOLIA_V07: Self = Self {
id: ChainId::LOCAL_FOUNDRY_ETHEREUM_SEPOLIA,
entry_point_version: EntryPointVersion::V07,
name: "Local Ethereum Sepolia",
};

pub const LOCAL_ETHEREUM_SEPOLIA_V06: Self = Self {
id: ChainId::LOCAL_FOUNDRY_ETHEREUM_SEPOLIA,
entry_point_version: EntryPointVersion::V06,
name: "Local Ethereum Sepolia",
};
}

Expand All @@ -143,16 +131,12 @@ impl Chain {

impl From<ChainId> for Chain {
fn from(chain_id: ChainId) -> Self {
Self {
id: chain_id,
entry_point_version: EntryPointVersion::V07,
name: "",
}
Self { id: chain_id, entry_point_version: EntryPointVersion::V07 }
}
}

impl fmt::Display for Chain {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} ({})", self.name, self.id)
write!(f, "{}", self.id)
}
}
10 changes: 8 additions & 2 deletions crates/yttrium/src/smart_accounts/safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,20 @@ pub async fn get_account_address(
}

pub fn get_call_data(execution_calldata: Vec<Transaction>) -> Bytes {
get_call_data_with_try(execution_calldata, false)
}

pub fn get_call_data_with_try(
execution_calldata: Vec<Transaction>,
exec_type: bool,
) -> Bytes {
let batch = execution_calldata.len() != 1;
let revert_on_error = false;
let selector = [0u8; 4];
let context = [0u8; 22];

let mode = DynSolValue::Tuple(vec![
DynSolValue::Uint(Uint::from(if batch { 0x01 } else { 0x00 }), 8), // DelegateCall is 0xFF
DynSolValue::Uint(Uint::from(revert_on_error as u8), 8),
DynSolValue::Uint(Uint::from(exec_type as u8), 8), // revertOnError in permissionless
DynSolValue::Bytes(vec![0u8; 4]),
DynSolValue::Bytes(selector.to_vec()),
DynSolValue::Bytes(context.to_vec()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn get_sender_address_with_signer(
let rpc_base_url = config.clone().endpoints.rpc.base_url;

let chain_id = ChainId::new_eip155(chain_id);
let chain = crate::chain::Chain::new(chain_id, EntryPointVersion::V07, "");
let chain = crate::chain::Chain::new(chain_id, EntryPointVersion::V07);

let entry_point_config = chain.entry_point_config();

Expand Down
1 change: 1 addition & 0 deletions crates/yttrium/src/transaction/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub async fn send_transaction_with_private_key_signer(
config,
)
.await?
.user_op_hash
} else {
send_transaction_with_signer(transaction, config, chain_id, signer)
.await?
Expand Down
Loading

0 comments on commit 6cea557

Please sign in to comment.