Expand description
§Circles Pathfinder
Pathfinding and flow matrix calculation for the Circles protocol.
This crate provides efficient pathfinding algorithms and flow matrix generation for the Circles universal basic income protocol, with ready-to-use types for smart contract interactions.
§Quick Start
§High-level API (Recommended)
use circles_pathfinder::{FindPathParams, prepare_flow_for_contract};
use alloy_primitives::{Address, aliases::U192, U256};
let params = FindPathParams {
from: "0x123...".parse()?,
to: "0x456...".parse()?,
target_flow: U256::from(1_000_000_000_000_000_000u64), // 1 CRC
use_wrapped_balances: Some(true),
from_tokens: None,
to_tokens: None,
exclude_from_tokens: None,
exclude_to_tokens: None,
simulated_balances: None,
max_transfers: None,
};
// One function call gets contract-ready data
let path_data = prepare_flow_for_contract("https://rpc.circles.com", params).await?;
// Ready for smart contract calls
let (vertices, edges, streams, coords) = path_data.to_contract_params();
// contract.some_function(vertices, edges, streams, coords)§Low-level API (Advanced)
use circles_pathfinder::{find_path, create_flow_matrix};
use alloy_primitives::{Address, aliases::U192};
// Step 1: Find path
let transfers = find_path(
"https://rpc.circles.com",
"0x123...".parse()?,
"0x456...".parse()?,
U192::from(1000u64),
true
).await?;
// Step 2: Create flow matrix
let matrix = create_flow_matrix(
"0x123...".parse()?,
"0x456...".parse()?,
U192::from(1000u64),
&transfers
)?;§Modules
hub- Circles Hub contract types and conversionsrpc- RPC communication and pathfindingflow- Flow matrix calculationpacking- Coordinate packing utilitiesconvenience- High-level convenience functions
§Features
- Fast pathfinding using Circles RPC endpoints
- Hub contract integration with ready-to-use types
- Type safety with
alloy-primitives - Efficient packing for on-chain storage
- Comprehensive testing with real-world scenarios
Re-exports§
pub use hub::PathData;pub use path::assert_no_netted_flow_mismatch;pub use path::compute_netted_flow;pub use path::expected_unwrapped_totals;pub use path::replace_wrapped_tokens;pub use path::shrink_path_values;pub use path::token_info_map_from_path;pub use path::wrapped_totals_from_path;
Modules§
Structs§
- Find
Path Params - Path finding parameters for
circlesV2_findPath. - Flow
Edge - Standard Circles Hub FlowEdge struct matching the contract ABI
- Flow
Matrix - Stream
- Standard Circles Hub Stream struct matching the contract ABI
- redeem
Call - Function with signature
redeem(bytes32,bytes)and selector0xf7ff7207. - redeem
Return - Container type for the return parameters of the
redeem(bytes32,bytes)function.
Enums§
- Pathfinder
Error - Errors that can occur during pathfinding and flow matrix operations.
Functions§
- create_
flow_ matrix - Create a flow matrix from a sequence of transfer steps.
- encode_
redeem_ flow_ matrix - encode_
redeem_ trusted_ data - find_
path - Find an optimal path between two addresses in the Circles network.
- find_
path_ with_ params - Find a path using structured parameters.
- get_
available_ flow - Get the maximum available flow between two addresses
- pack_
coordinates - Pack coordinate values into a compact byte representation.
- prepare_
flow_ for_ contract - High-level function that combines pathfinding and matrix creation
- prepare_
flow_ for_ contract_ simple - Prepare flow for contract using individual parameters (legacy compatibility)
- transform_
to_ flow_ vertices - Transform transfer steps into sorted vertices and coordinate mapping.