circles_types/
lib.rs

1//! # Circles Types
2//!
3//! Core type definitions for the Circles protocol ecosystem.
4//!
5//! This crate provides fundamental data structures used throughout the Circles
6//! protocol implementation, including flow matrices, transfer steps, and address
7//! handling with full `serde` serialization support.
8//!
9//! ## Usage
10//!
11//! ```rust,ignore
12//! use circles_types::{TransferStep, FlowEdge, Stream};
13//! use alloy_primitives::U256;
14//!
15//! // Create a transfer step
16//! let transfer = TransferStep {
17//!     from_address: "0x123...".parse()?,
18//!     to_address: "0x456...".parse()?,
19//!     token_owner: "0x789...".parse()?,
20//!     value: U256::from(1000u64),
21//! };
22//!
23//! // Serialize to JSON
24//! let json = serde_json::to_string(&transfer)?;
25//! # Ok::<(), Box<dyn std::error::Error>>(())
26//! ```
27//!
28//! ## Core Types
29//!
30//! - [`TransferStep`] - Single transfer operation in a multi-hop path
31//! - [`FlowEdge`] - Directed edge in flow graph with routing info
32//! - [`Stream`] - Collection of edges representing a transfer route
33//! - [`FlowMatrix`] - Complete flow representation for contracts
34//! - [`Address`] - Ethereum address (re-exported from alloy-primitives)
35use alloy_primitives::aliases::U192;
36use serde::{Deserialize, Serialize};
37
38pub type Address = alloy_primitives::Address;
39
40/// Edge in the flow graph (sinkId 1 == final hop)
41#[derive(Clone, Debug, Serialize, Deserialize)]
42pub struct FlowEdge {
43    pub stream_sink_id: u16,
44    pub amount: U192,
45}
46
47#[derive(Clone, Debug, Serialize, Deserialize)]
48pub struct Stream {
49    pub source_coordinate: u16,
50    pub flow_edge_ids: Vec<u16>,
51    pub data: Vec<u8>,
52}
53
54#[derive(Clone, Debug, Serialize, Deserialize)]
55pub struct TransferStep {
56    pub from_address: Address,
57    pub to_address: Address,
58    pub token_owner: Address,
59    pub value: U192,
60}
61
62/// ABI-ready matrix returned by `create_flow_matrix`
63#[derive(Clone, Debug)]
64pub struct FlowMatrix {
65    pub flow_vertices: Vec<Address>,
66    pub flow_edges: Vec<FlowEdge>,
67    pub streams: Vec<Stream>,
68    pub packed_coordinates: Vec<u8>,
69    pub source_coordinate: u16,
70}