safe_rs/lib.rs
1//! # safe-rs
2//!
3//! A Rust library for interacting with Safe v1.4.1 smart accounts.
4//!
5//! ## Features
6//!
7//! - Fluent builder API for multicall transactions
8//! - Local fork simulation using foundry-fork-db + revm
9//! - Seamless integration with alloy's `sol!` macro ecosystem
10//! - Single-owner (1/1 threshold) Safe support
11//!
12//! ## Quick Start
13//!
14//! ```rust,ignore
15//! use safe_rs::{Safe, contracts::IERC20};
16//! use alloy::primitives::{address, U256};
17//!
18//! // Connect to a Safe
19//! let safe = Safe::connect(provider, signer, safe_address).await?;
20//!
21//! // Execute a multicall with typed calls (with simulation)
22//! safe.batch()
23//! .add_typed(usdc, IERC20::transferCall { to: recipient, amount: U256::from(1000) })
24//! .add_typed(usdc, IERC20::approveCall { spender, amount: U256::MAX })
25//! .simulate().await?
26//! .execute().await?;
27//!
28//! // Or execute without simulation (gas estimated via RPC)
29//! safe.batch()
30//! .add_typed(usdc, IERC20::transferCall { to: recipient, amount: U256::from(1000) })
31//! .execute().await?;
32//! ```
33//!
34//! ## Builder API
35//!
36//! The `SafeBuilder` provides a fluent API for constructing transactions:
37//!
38//! ```rust,ignore
39//! // Build and simulate
40//! let builder = safe.batch()
41//! .add_typed(token, call)
42//! .simulate().await?;
43//!
44//! // Inspect simulation results
45//! if let Some(result) = builder.simulation_result() {
46//! println!("Gas used: {}", result.gas_used);
47//! }
48//!
49//! // Execute the transaction
50//! let result = builder.execute().await?;
51//! ```
52
53pub mod account;
54pub mod chain;
55pub mod contracts;
56pub mod create2;
57pub mod encoding;
58pub mod eoa;
59pub mod error;
60pub mod safe;
61pub mod signing;
62pub mod simulation;
63pub mod types;
64pub mod wallet;
65
66// Re-export main types at crate root
67pub use account::Account;
68pub use chain::{ChainAddresses, ChainConfig};
69pub use contracts::{IERC20, IMultiSend, IMultiSendCallOnly, ISafe, ISafeProxyFactory, ISafeSetup};
70pub use create2::{compute_create2_address, encode_setup_call};
71pub use encoding::SafeTxParams;
72pub use eoa::{Eoa, EoaBatchResult, EoaBuilder, EoaTxResult};
73pub use error::{Error, Result};
74pub use safe::{is_safe, ExecutionResult, SafeBuilder, Safe, SAFE_SINGLETON_SLOT};
75pub use simulation::{AccountState, CallTraceArena, DiffMode, ForkSimulator, SimulationResult};
76pub use types::{BatchResult, BatchSimulationResult, Call, CallBuilder, Operation, SafeCall, TypedCall};
77pub use wallet::{Wallet, WalletBuilder, WalletConfig};
78
79/// Type alias for a Safe wallet
80pub type SafeWallet<P> = Wallet<Safe<P>>;
81
82/// Type alias for an EOA wallet
83pub type EoaWallet<P> = Wallet<Eoa<P>>;
84
85// Re-export alloy types that are commonly used
86pub use alloy::network::AnyNetwork;
87pub use alloy::primitives::{Address, Bytes, U256};
88pub use alloy::providers::Provider;