Crate safe_rs

Crate safe_rs 

Source
Expand description

§safe-rs

A Rust library for interacting with Safe v1.4.1 smart accounts.

§Features

  • Fluent builder API for multicall transactions
  • Local fork simulation using foundry-fork-db + revm
  • Seamless integration with alloy’s sol! macro ecosystem
  • Single-owner (1/1 threshold) Safe support

§Quick Start

use safe_rs::{Safe, contracts::IERC20};
use alloy::primitives::{address, U256};

// Connect to a Safe
let safe = Safe::connect(provider, signer, safe_address).await?;

// Execute a multicall with typed calls
safe.multicall()
    .add_typed(usdc, IERC20::transferCall { to: recipient, amount: U256::from(1000) })
    .add_typed(usdc, IERC20::approveCall { spender, amount: U256::MAX })
    .simulate().await?
    .execute().await?;

§Type-State Builder

The library uses a type-state pattern to enforce simulation before execution:

// NotSimulated state - can add calls, cannot execute
let builder = safe.multicall()
    .add_typed(token, call);

// Simulated state - can inspect results, can execute
let simulated = builder.simulate().await?;
println!("Gas used: {}", simulated.gas_used());

// Execute the transaction
let result = simulated.execute().await?;

Re-exports§

pub use chain::ChainAddresses;
pub use chain::ChainConfig;
pub use contracts::IERC20;
pub use contracts::IMultiSend;
pub use contracts::IMultiSendCallOnly;
pub use contracts::ISafe;
pub use contracts::ISafeProxyFactory;
pub use contracts::ISafeSetup;
pub use encoding::SafeTxParams;
pub use eoa::Eoa;
pub use eoa::EoaBatchResult;
pub use eoa::EoaBuilder;
pub use eoa::EoaTxResult;
pub use error::Error;
pub use error::Result;
pub use safe::ExecutionResult;
pub use safe::MulticallBuilder;
pub use safe::NotSimulated;
pub use safe::Safe;
pub use safe::Simulated;
pub use simulation::ForkSimulator;
pub use simulation::SimulationResult;
pub use types::Call;
pub use types::Operation;
pub use types::SafeCall;
pub use types::TypedCall;

Modules§

chain
Chain configuration and contract addresses
contracts
Contract ABI definitions for Safe v1.4.1
encoding
Encoding utilities for Safe transactions
eoa
EOA (Externally Owned Account) fallback mode
error
Error types for safe-rs
safe
Safe client and MulticallBuilder implementation
signing
Signature generation for Safe transactions
simulation
Transaction simulation using fork database and revm
types
Type definitions for Safe transactions

Structs§

Address
An Ethereum address, 20 bytes in length.
AnyNetwork
Types for a catch-all network.
Bytes
Wrapper type around bytes::Bytes to support “0x” prefixed hex strings.

Traits§

Provider
Ethereum JSON-RPC interface.

Type Aliases§

U256
256-bit unsigned integer type, consisting of 4, 64-bit limbs.