circles_types/
lib.rs

1//! # Circles Types
2//!
3//! Complete type definitions for the Circles protocol ecosystem in Rust.
4//!
5//! This crate provides comprehensive data structures for all aspects of the Circles
6//! protocol, including avatar management, trust relations, token operations, pathfinding,
7//! event handling, RPC communication, and contract interactions. All types support
8//! full `serde` serialization and are compatible with the TypeScript Circles SDK.
9//!
10//! ## Features
11//!
12//! - **Complete Protocol Coverage**: Types for avatars, trust, tokens, groups, events
13//! - **Alloy Integration**: Built on `alloy-primitives` for Ethereum compatibility
14//! - **API Compatible**: Matches TypeScript SDK structure exactly
15//! - **Type Safety**: Leverages Rust's type system while maintaining flexibility
16//! - **Async Ready**: Traits for contract runners and batch operations
17//! - **Query DSL**: Complete query builder for `circles_query` RPC method
18//!
19//! ## Usage Examples
20//!
21//! ```rust,ignore
22//! use circles_types::{
23//!     // Core types
24//!     Address, U256, TxHash,
25//!     // Avatar and profile types
26//!     AvatarInfo, Profile, AvatarType,
27//!     // Pathfinding
28//!     FindPathParams, PathfindingResult,
29//!     // Trust relations
30//!     TrustRelation, TrustRelationType,
31//!     // Configuration
32//!     CirclesConfig,
33//! };
34//!
35//! // Create avatar information
36//! let avatar = AvatarInfo {
37//!     block_number: 12345,
38//!     timestamp: Some(1234567890),
39//!     transaction_index: 1,
40//!     log_index: 0,
41//!     transaction_hash: "0xabc123...".parse()?,
42//!     version: 2,
43//!     avatar_type: AvatarType::CrcV2RegisterHuman,
44//!     avatar: "0x123...".parse()?,
45//!     token_id: Some(U256::from(1)),
46//!     has_v1: false,
47//!     v1_token: None,
48//!     cid_v0_digest: None,
49//!     cid_v0: None,
50//!     v1_stopped: None,
51//!     is_human: true,
52//!     name: None,
53//!     symbol: None,
54//! };
55//!
56//! // Create pathfinding parameters
57//! let params = FindPathParams {
58//!     from: "0xabc...".parse()?,
59//!     to: "0xdef...".parse()?,
60//!     target_flow: U256::from(1000u64),
61//!     use_wrapped_balances: Some(true),
62//!     from_tokens: None,
63//!     to_tokens: None,
64//!     exclude_from_tokens: None,
65//!     exclude_to_tokens: None,
66//!     simulated_balances: None,
67//!     max_transfers: Some(10),
68//! };
69//!
70//! // Serialize to JSON
71//! let json = serde_json::to_string(&avatar)?;
72//! # Ok::<(), Box<dyn std::error::Error>>(())
73//! ```
74//!
75//! ## Type Categories
76//!
77//! ### Core Blockchain Types
78//! - [`Address`] - Ethereum address (re-exported from alloy-primitives)
79//! - [`TxHash`], [`BlockHash`] - Transaction and block hashes
80//! - [`U256`], [`U192`] - Large unsigned integers
81//! - [`TransactionRequest`] - Transaction request data
82//!
83//! ### Avatar & Profile Management
84//! - [`AvatarInfo`] - Complete avatar information and metadata
85//! - [`Profile`] - User profile with name, description, images
86//! - [`GroupProfile`] - Group profile extending Profile with symbol
87//! - [`AvatarType`] - Registration event types (Human, Group, Organization)
88//!
89//! ### Trust & Social Graph
90//! - [`TrustRelation`] - Individual trust relationship
91//! - [`AggregatedTrustRelation`] - Processed trust relationships
92//! - [`TrustRelationType`] - Trust relationship types
93//!
94//! ### Token Operations
95//! - [`TokenBalance`] - Token balance with metadata
96//! - [`TokenInfo`] - Token creation and type information
97//! - [`TokenHolder`] - Account token holdings
98//! - [`Balance`] - Flexible balance type (raw or formatted)
99//!
100//! ### Group Management
101//! - [`GroupRow`] - Group registration and metadata
102//! - [`GroupMembershipRow`] - Group membership records
103//! - [`GroupQueryParams`] - Parameters for group queries
104//!
105//! ### Pathfinding & Transfers
106//! - [`FindPathParams`] - Parameters for path computation
107//! - [`PathfindingResult`] - Computed transfer path
108//! - [`TransferStep`] - Individual transfer in a path
109//! - [`FlowMatrix`] - Complete flow representation for contracts
110//! - [`SimulatedBalance`] - Balance simulation for pathfinding
111//!
112//! ### Event System
113//! - [`CirclesEvent`] - Universal event structure
114//! - [`CirclesEventType`] - All supported event types (25+ variants)
115//! - [`CirclesBaseEvent`] - Common event metadata
116//!
117//! ### RPC & Communication
118//! - [`JsonRpcRequest`], [`JsonRpcResponse`] - Standard JSON-RPC types
119//! - [`CirclesQueryResponse`] - Response format for queries
120//! - [`TokenBalanceResponse`] - Token balance from RPC calls
121//!
122//! ### Query System
123//! - [`QueryParams`] - Parameters for `circles_query` RPC method
124//! - [`FilterPredicate`], [`Conjunction`] - Query filtering DSL
125//! - [`PagedResult`] - Paginated query results
126//! - [`SortOrder`], [`OrderBy`] - Result sorting
127//!
128//! ### Contract Execution
129//! - [`ContractRunner`] - Async trait for contract interactions
130//! - [`BatchRun`] - Trait for batched transaction execution
131//! - [`RunnerConfig`] - Configuration for contract runners
132//!
133//! ### Protocol Configuration
134//! - [`CirclesConfig`] - Complete protocol configuration
135//! - [`EscrowedAmountAndDays`] - Contract-specific response types
136//! - [`DecodedContractError`] - Contract error information
137//!
138//! ### Network State
139//! - [`NetworkSnapshot`] - Complete network state at a block
140//! - [`EventRow`] - Base structure for event pagination
141//! - [`Cursor`] - Pagination cursor for efficient queries
142
143// =============================================================================
144// External re-exports
145// =============================================================================
146
147// Alloy primitive types
148pub use alloy_primitives::aliases::{BlockHash, TxHash};
149pub use alloy_primitives::Address;
150pub use alloy_primitives::Bytes;
151pub use alloy_primitives::{aliases::U192, U256};
152
153// Alloy RPC types
154pub use alloy_provider::transport::TransportResult;
155pub use alloy_rpc_types::TransactionRequest;
156
157// =============================================================================
158// Internal modules with explicit re-exports
159// =============================================================================
160
161mod avatar;
162pub use avatar::{AvatarInfo, AvatarType, GeoLocation, GroupProfile, Profile};
163
164mod config;
165pub use config::CirclesConfig;
166
167mod contracts;
168pub use contracts::EscrowedAmountAndDays;
169
170mod errors;
171pub use errors::DecodedContractError;
172
173mod events;
174pub use events::{CirclesBaseEvent, CirclesEvent, CirclesEventType, RpcSubscriptionEvent};
175
176mod group;
177pub use group::{GroupMembershipRow, GroupQueryParams, GroupRow};
178
179mod network;
180pub use network::{EventType, NetworkSnapshot};
181
182mod trust;
183pub use trust::{AggregatedTrustRelation, TrustRelation, TrustRelationType};
184
185mod wrapper;
186pub use wrapper::{CirclesType, WrappedTokenInfo, WrappedTokensRecord};
187
188mod token;
189pub use token::{TokenBalance, TokenHolder, TokenInfo};
190
191mod client;
192pub use client::{AvatarRow, CirclesQuery, GroupType, TokenBalanceRow, TrustRelationRow};
193
194mod runner;
195pub use runner::{BatchRun, ContractRunner, RunnerConfig};
196
197mod rpc;
198pub use rpc::{
199    Balance, CirclesQueryResponse, JsonRpcError, JsonRpcRequest, JsonRpcResponse, QueryResponse,
200    SafeQueryResponse, TokenBalanceResponse,
201};
202
203mod query;
204pub use query::{
205    ColumnInfo, Conjunction, ConjunctionType, Cursor, EventRow, Filter, FilterPredicate,
206    FilterType, OrderBy, PagedQueryParams, PagedResult, QueryParams, SortOrder, TableInfo,
207};
208
209mod pathfinding;
210pub use pathfinding::{
211    AdvancedTransferOptions,
212    FindPathParams,
213    // Original flow types
214    FlowEdge,
215    FlowEdgeStruct,
216    FlowMatrix,
217    PathfindingFlowMatrix,
218    PathfindingResult,
219    PathfindingTransferStep,
220    SimulatedBalance,
221    Stream,
222    StreamStruct,
223    TransferStep,
224};