circles-pathfinder
Pathfinding and flow matrix calculation for the Circles protocol. Uses circles-rpc to call circlesV2_findPath and produces contract-ready types for Hub interactions.
Features
- Path discovery through the trust network with optional wrapped-balance usage and simulated balances.
- Flow matrix creation and packing for on-chain
operateFlowMatrix/redeemPayment. - Wrapped token handling helpers: normalize wrappers, unwrap inflationary balances, and rewrite paths to underlying avatars.
- Netted-flow checks: shrink path values, compute/validate netted flow, and cap
U256inputs toU192for contract compatibility. - Contract-ready conversions via
sol!types (FlowEdge/Stream) and coordinate packing helpers.
Quickstart
use ;
use ;
async
Wrapped tokens & netted flow
- Replace wrapped token owners with the underlying avatar for contract-facing flows:
use ;
let info_map = token_info_map_from_path.await?;
let wrapped = wrapped_totals_from_path;
let unwrapped = expected_unwrapped_totals; // uses converter + timestamp hint
let rewritten = replace_wrapped_tokens;
compute_netted_flow;
assert_no_netted_flow_mismatch?;
- Helpers normalize wrapper variants, unwrap inflationary balances with
circles-utils, and ensure flow matrix amounts fit inU192(u256_to_u192).
Examples
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 becomeCrcUnknownEvent.
Notes / status
- Targets Circles v2 RPCs; wrapper conversion logic matches the TypeScript
@pathfinderreference. - Use
circles-utilsdemurrage/inflation converters when inspecting wrapped balances directly. - Subscription reconnect/backoff is not handled here; use the SDK crate if you need retries or catch-up helpers.