Circles-Pathfinder
Pathfinding and flow matrix calculation for the Circles protocol.
Features
- Path Discovery: Find optimal paths between addresses in the Circles network
- Flow Matrix Calculation: Generate flow matrices for smart contract interactions
- Contract Integration: Ready-to-use types for smart contract calls
- High Performance: Efficient coordinate packing and vertex transformation
- Type Safety: Compile-time guarantees with alloy primitives
Quick Start
Basic Usage
use ;
use ;
let params = FindPathParams ;
// One function call does everything!
let path_data = prepare_flow_for_contract.await?;
// Convert to contract types and call
let = path_data.to_contract_params;
contract.some_function.send.await?;
// Or use individual conversion methods:
contract.redeemPayment.send.await?;
Advanced Usage
// For composable workflows
let transfers = find_path.await?;
let path_data = from_transfers?;
// Or use the lower-level API
let matrix = create_flow_matrix?;
// matrix contains the raw FlowMatrix from circles_types
Circles Hub Contract Integration
This crate provides seamless integration with Circles Hub smart contracts. The generated types match the exact ABI expected by the contracts:
use ;
// Types generated by sol! macro - match contract ABI exactly
let edges: = path_data.to_flow_edges;
let streams: = path_data.to_streams;
// FlowEdge and Stream have camelCase fields matching Solidity:
// FlowEdge { streamSinkId: u16, amount: U192 }
// Stream { sourceCoordinate: u16, flowEdgeIds: Vec<u16>, data: Bytes }
Contract ABI Compatibility
struct FlowEdge {
uint16 streamSinkId;
uint192 amount;
}
struct Stream {
uint16 sourceCoordinate;
uint16[] flowEdgeIds;
bytes data;
}
function redeemPayment(
address[] memory flowVertices,
FlowEdge[] memory flowEdges,
Stream[] memory streams,
bytes memory packedCoordinates
) external;
No Manual Conversions Required
The old approach required manual field-by-field conversion:
// OLD WAY
let flow_edges: = contract_matrix.flow_edges
.into_iter
.map
.collect;
// NEW WAY
let flow_edges: = path_data.to_flow_edges;