Skip to main content

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 create2;
56pub mod encoding;
57pub mod eoa;
58pub mod error;
59pub mod safe;
60pub mod signing;
61pub mod simulation;
62pub mod types;
63pub mod wallet;
64
65// Re-export main types at crate root
66pub use chain::{ChainAddresses, ChainConfig};
67pub use contracts::{IERC20, IMultiSend, IMultiSendCallOnly, ISafe, ISafeProxyFactory, ISafeSetup};
68pub use create2::{compute_create2_address, encode_setup_call};
69pub use encoding::SafeTxParams;
70pub use eoa::{Eoa, EoaBatchResult, EoaBuilder, EoaTxResult};
71pub use error::{Error, Result};
72pub use safe::{is_safe, ExecutionResult, MulticallBuilder, Safe, SAFE_SINGLETON_SLOT};
73pub use simulation::{AccountState, DiffMode, ForkSimulator, SimulationResult};
74pub use types::{BatchResult, BatchSimulationResult, Call, Operation, SafeCall, TypedCall};
75pub use wallet::{BatchBuilder, SimulatedBatchBuilder, Wallet, WalletConfig};
76
77// Re-export alloy types that are commonly used
78pub use alloy::network::AnyNetwork;
79pub use alloy::primitives::{Address, Bytes, U256};
80pub use alloy::providers::Provider;