If two currencies are not paired directly, and do not have a common pair between them, they can still be swapped as long as a path between them exists. Router feature can be used to optimize between direct and multi-step swaps.
Solution
I propose to store and update the graph of token pair relations off-chain each time new exchange pair added to runtime.
Afterwards we can utilize Depth First Traversal algorithm to find the shortest path.
It can be quite costly to perform Depth First Traversal in terms of look-ups amount.
The only purpose of having this feature consists in improving user experience, no security risks involved, so there is no need to have this on-chain.
Motivation
If two currencies are not paired directly, and do not have a common pair between them, they can still be swapped as long as a path between them exists. Router feature can be used to optimize between direct and multi-step swaps.
Solution
I propose to store and update the graph of token pair relations off-chain each time new exchange pair added to runtime. Afterwards we can utilize Depth First Traversal algorithm to find the shortest path.
It can be quite costly to perform Depth First Traversal in terms of look-ups amount. The only purpose of having this feature consists in improving user experience, no security risks involved, so there is no need to have this on-chain.