| Crates.io | circles-pathfinder |
| lib.rs | circles-pathfinder |
| version | 0.5.0 |
| created_at | 2025-06-09 13:02:22.125164+00 |
| updated_at | 2025-12-05 12:28:32.041882+00 |
| description | Pathfinding and flow matrix calculation for the Circles protocol |
| homepage | https://circles-rs-book.vercel.app/ |
| repository | https://github.com/deluXtreme/circles-rs |
| max_upload_size | |
| id | 1705893 |
| size | 209,394 |
Pathfinding and flow matrix calculation for the Circles protocol. Uses circles-rpc to call circlesV2_findPath and produces contract-ready types for Hub interactions.
operateFlowMatrix / redeemPayment.U256 inputs to U192 for contract compatibility.sol! types (FlowEdge/Stream) and coordinate packing helpers.use circles_pathfinder::{prepare_flow_for_contract, FindPathParams};
use alloy_primitives::{Address, U256};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let params = FindPathParams {
from: "0x1234567890123456789012345678901234567890".parse()?,
to: "0x0987654321098765432109876543210987654321".parse()?,
target_flow: U256::from(1_000_000_000_000_000_000u64), // 1 CRC (U256 input)
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 call does everything: RPC pathfind + flow matrix ready for contracts
let path_data = prepare_flow_for_contract("https://rpc.aboutcircles.com/", params).await?;
let (vertices, edges, streams, coords) = path_data.into_contract_params();
println!("matrix: {} vertices, {} edges", vertices.len(), edges.len());
}
use circles_pathfinder::{
token_info_map_from_path, wrapped_totals_from_path, expected_unwrapped_totals,
replace_wrapped_tokens, compute_netted_flow, assert_no_netted_flow_mismatch,
};
let info_map = token_info_map_from_path(current_avatar, &rpc, &path).await?;
let wrapped = wrapped_totals_from_path(&path, &info_map);
let unwrapped = expected_unwrapped_totals(&wrapped, &info_map); // uses converter + timestamp hint
let rewritten = replace_wrapped_tokens(&path, &unwrapped);
compute_netted_flow(&rewritten);
assert_no_netted_flow_mismatch(&rewritten, None, None)?;
circles-utils, and ensure flow matrix amounts fit in U192 (u256_to_u192).contract_integration: end-to-end pathfinding and flow matrix creation for contract calls.find_path: basic pathfind against a Circles RPC endpoint.path_and_events: pathfind plus optional WS event subscription (CIRCLES_RPC_URL, CIRCLES_RPC_WS_URL). WS parsing tolerates heartbeats/batches; unknown events become CrcUnknownEvent.@pathfinder reference.circles-utils demurrage/inflation converters when inspecting wrapped balances directly.