Circles Types
Core type definitions for the Circles protocol ecosystem.
This crate provides fundamental data structures used throughout the Circles protocol implementation, including flow matrices, transfer steps, and address handling.
Overview
The circles-types crate serves as the foundation for all Circles protocol operations, providing type-safe representations of:
- Network addresses and transaction data
- Flow graph structures for pathfinding
- Transfer operations and routing information
- Matrix representations for smart contract interactions
Features
- Type Safety: Leverages Rust's type system with
alloy-primitivesfor Ethereum compatibility - Serialization: Full
serdesupport for JSON serialization/deserialization - Zero-Copy Operations: Efficient memory usage with borrowed data where possible
- Protocol Compatibility: Types designed to match Circles smart contract interfaces
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use ;
use U256;
// Create a transfer step
let transfer = TransferStep ;
// Create flow edges for routing
let edge = FlowEdge ;
// Create streams for flow organization
let stream = Stream ;
Working with Flow Matrices
use ;
let matrix = FlowMatrix ;
// Flow matrices are ready for use with pathfinding algorithms
// and smart contract interactions
Type Reference
Core Types
Address: Ethereum address type (re-exported fromalloy-primitives)TransferStep: Represents a single transfer operation in a multi-hop pathFlowEdge: Directed edge in the flow graph with amount and routing informationStream: Collection of flow edges representing a complete transfer routeFlowMatrix: Complete flow representation ready for smart contract execution
Transfer Operations
The TransferStep struct captures all information needed for a single transfer:
Flow Graph Structures
Flow edges represent the routing information:
Streams organize related flow edges:
Serialization
All types implement Serialize and Deserialize for easy JSON handling:
use TransferStep;
let transfer = TransferStep ;
let json = to_string?;
let parsed: TransferStep = from_str?;
Compatibility
This crate is designed to work seamlessly with:
circles-pathfinder: Pathfinding and flow matrix calculation- Smart Contracts: Types match Solidity struct layouts
alloy: Full compatibility with the Alloy crate ecosystem- JSON-RPC: Direct serialization support for protocol communication
Contributing
Contributions are welcome! Please ensure that:
- All public types implement
Clone,Debug, and serde traits where appropriate - New types include comprehensive documentation
- Changes maintain backward compatibility where possible
- Tests cover both serialization and basic usage patterns
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.