Pathfinding Algorithm
The core intelligence of InfiRouter lies in its on-chain pathfinding algorithm, implemented primarily within the internal _findBestPath function. This recursive algorithm systematically explores potential swap routes to identify the one offering the maximum output amount, potentially adjusted for gas costs. It utilizes a recursive depth-first search strategy.
The algorithm operates recursively as follows:
Base Case - Direct Path Evaluation: The function first considers all possible single-step path. It iterates through every registered adapter.
Recursive Step - Multi-Hop Exploration:
ā The algorithm checks if further exploration is warranted based on the maxSteps constraint. If the current path being built has length ( l ) and ( l < - 1 ), it proceeds to explore two-step (or longer) paths originating from the current state. ā It iterates through each potential intermediary token in the TRUSTED_TOKENS list.
Last updated