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
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//!
29//! ## Type-State Builder
30//!
31//! The library uses a type-state pattern to enforce simulation before execution:
32//!
33//! ```rust,ignore
34//! // NotSimulated state - can add calls, cannot execute
35//! let builder = safe.multicall()
36//!     .add_typed(token, call);
37//!
38//! // Simulated state - can inspect results, can execute
39//! let simulated = builder.simulate().await?;
40//! println!("Gas used: {}", simulated.gas_used());
41//!
42//! // Execute the transaction
43//! let result = simulated.execute().await?;
44//! ```
45
46pub mod chain;
47pub mod contracts;
48pub mod encoding;
49pub mod eoa;
50pub mod error;
51pub mod safe;
52pub mod signing;
53pub mod simulation;
54pub mod types;
55
56// Re-export main types at crate root
57pub use chain::{ChainAddresses, ChainConfig};
58pub use contracts::{IERC20, IMultiSend, IMultiSendCallOnly, ISafe, ISafeProxyFactory, ISafeSetup};
59pub use encoding::SafeTxParams;
60pub use eoa::{Eoa, EoaBatchResult, EoaBuilder, EoaTxResult};
61pub use error::{Error, Result};
62pub use safe::{ExecutionResult, MulticallBuilder, NotSimulated, Safe, Simulated};
63pub use simulation::{ForkSimulator, SimulationResult};
64pub use types::{Call, Operation, SafeCall, TypedCall};
65
66// Re-export alloy types that are commonly used
67pub use alloy::network::AnyNetwork;
68pub use alloy::primitives::{Address, Bytes, U256};
69pub use alloy::providers::Provider;