Pathfinder
Circles pathfinder calculates “how much and through which tokens can flow from A to B” based on trust and balances (wrapped and unwrapped). You can use it to:
Preview a route and achievable amount.
Feed
TransferBuilderor customoperateFlowMatrixcalls.
Entry points
High-level SDK:
sdk.rpc.pathfinder.findPath / findMaxFlow(sdk.rpcis a public property — no cast needed)Standalone:
const rpc = new CirclesRpc(config.circlesRpcUrl);
Methods
findPath(params: FindPathParams): Promise<PathfindingResult>findMaxFlow(params: Omit<FindPathParams, 'targetFlow'>): Promise<bigint>
Parameters (FindPathParams)
from(Address, required): Source avatar.to(Address, required): Destination avatar.targetFlow(bigint, required forfindPath): Desired amount.useWrappedBalances(boolean, optional): Allow ERC20 wrappers in the route. Set true if you hold wrapped CRC.fromTokens/toTokens(Address[], optional): Only allow these token owners from sender/recipient sides.excludeFromTokens/excludeToTokens(Address[], optional): Ban specific token owners.simulatedBalances(array, optional): Inject hypothetical balances{ holder, token, amount, isWrapped, isStatic }.simulatedTrusts(array, optional): Inject hypothetical trust edges{ truster, trustee }.simulatedConsentedAvatars(Address[], optional): Treat these addresses as having granted ERC‑1155 operator approval. Affects which intermediate hops count as valid.maxTransfers(number, optional): Hop cap; lower = faster, but may reduce flow.debugShowIntermediateSteps(boolean, optional): PopulatePathfindingResult.debugwith the pipeline transformation stages.
findPath (targeted route)
Computes a path for a requested amount; returns what is actually achievable plus hop-by-hop legs.
PathfindingResult:
maxFlow– achievable flow for this request.transfers– ordered legs;tokenOwneris the ERC1155 owner or wrapper used in that hop.debug– present only whendebugShowIntermediateSteps: truewas passed.
Debugging a route
Setting debugShowIntermediateSteps: true returns each stage of the transformation pipeline, which is useful when a route looks wrong and you need to see where it changed:
Each stage is a TransferStep[]. Leave the flag off in production — it makes the response considerably larger.
If maxFlow < targetFlow, decide to scale down or show an error.
findMaxFlow (ceiling)
Returns the absolute maximum possible flow between two avatars with the same options.
Use for sliders, validation, or deciding if you must unwrap/wrap first.
Advanced usage
Wrapped tokens:
useWrappedBalances: trueenables consuming inflationary/demurraged ERC20 wrappers the sender holds.Token pinning/bans: Use
fromTokens/toTokensto force specific personal or group tokens; use theexclude*variants to forbid costly or undesired wrappers.Simulations:
simulatedBalanceslet you preview flows after an expected mint/wrap without waiting for indexer updates.Hop limit:
maxTransferscurbs route length; helpful for UX responsiveness but may lowermaxFlow.
From path to execution
Easiest: call
TransferBuilder.constructAdvancedTransfer(from, to, amount, options)—it runsfindPath, adds unwrap/rewrap, approvals, and returns an ordered tx array.Manual: convert
PathfindingResulttooperateFlowMatrix:
Pathfinder helper functions (when you build flows yourself)
createFlowMatrix(from, to, maxFlow, transfers)– turns aPathfindingResultintoflowVertices,flowEdges,streams,packedCoordinatesforhubV2.operateFlowMatrix.packCoordinates(flowVertices)/transformToFlowVertices(transfers)– lower-level helpers used bycreateFlowMatrixfor packing vertex coordinates.getTokenInfoMapFromPath(from, rpcUrl, path)– fetches token metadata for all tokens/wrappers in a path; feed into other helpers.getWrappedTokensFromPath(path, tokenInfoMap)– list wrapped tokens present in the path.getExpectedUnwrappedTokenTotals(path, tokenInfoMap)– estimate ERC1155 amounts recovered after unwrapping wrappers used in the path.replaceWrappedTokensWithAvatars(path, tokenInfoMap)– rewrite path legs to underlying avatar addresses (for ERC1155 semantics).replaceWrappedTokens(path, unwrappedMap)– replace wrapped token addresses using a precomputed mapping.shrinkPathValues(path, sink, retainBps)– scale down flows proportionally (e.g., execute only 70% of a path).assertNoNettedFlowMismatch(path)– throw if transfers do not net to zero (consistency check).computeNettedFlow(path)– derive net inflow/outflow per address for diagnostics.
Error handling & tips
maxFlow === 0: check mutual trust or unwrap static/demurraged balances back to ERC1155.Paths needing wrapped balances will fail unless
useWrappedBalancesis true.
Last updated
Was this helpful?