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.multicall()
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.multicall()
30//! .add_typed(usdc, IERC20::transferCall { to: recipient, amount: U256::from(1000) })
31//! .execute().await?;
32//! ```
33//!
34//! ## Builder API
35//!
36//! The `MulticallBuilder` provides a fluent API for constructing transactions:
37//!
38//! ```rust,ignore
39//! // Build and simulate
40//! let builder = safe.multicall()
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 chain;
54pub mod contracts;
55pub mod encoding;
56pub mod eoa;
57pub mod error;
58pub mod safe;
59pub mod signing;
60pub mod simulation;
61pub mod types;
62
63// Re-export main types at crate root
64pub use chain::{ChainAddresses, ChainConfig};
65pub use contracts::{IERC20, IMultiSend, IMultiSendCallOnly, ISafe, ISafeProxyFactory, ISafeSetup};
66pub use encoding::SafeTxParams;
67pub use eoa::{Eoa, EoaBatchResult, EoaBuilder, EoaTxResult};
68pub use error::{Error, Result};
69pub use safe::{ExecutionResult, MulticallBuilder, Safe};
70pub use simulation::{AccountState, DiffMode, ForkSimulator, SimulationResult};
71pub use types::{Call, Operation, SafeCall, TypedCall};
72
73// Re-export alloy types that are commonly used
74pub use alloy::network::AnyNetwork;
75pub use alloy::primitives::{Address, Bytes, U256};
76pub use alloy::providers::Provider;