MultiHop Swap
Explanation of the MultiHopSwap transaction
Overview
Multihop swap provides a swapping mechanism to achieve better prices by routing through a series of pools.Rather than swapping directly from TokenA to TokenB a user may be able to get a better price if they swap from TokenA to TokenC to TokenD to TokenB. When performing a multohop swap the user provides an array of Denoms that they would like to swap through. For example if the user supplied the following array of Denoms [“TokenA”, “TokenC”, “TokenD”, “TokenB”
], the following swaps would be performed: Swap TokenA for TokenC; Swap TokenC for TokenD; Swap TokenD for TokenB.
The underlying swaps (hops) within a Multihop Swap are performed using the same mechanism as the basic Swap function. Unlike the the basic swap however, the complete amount of specified by AmountIn
will always be used. If there is insufficient liquidity in a route to swap 100% of the AmountIn
the route will fail. Additionally, rather than supply an explicit argument for TokenIn
the first denom in each Routes
array is used as the TokenIn.
MultihopSwap also allows users to set an ExitLimitPrice.
For a route to succeed the final conversion rate for the entry token and ExitToken must be less than the ExitLimitPrice. For a Multihop swap to succeed the following test must be satisfied:
Multihop swap also allows users to supply multiple different routes. By default, the first route that does not run out of liquidity, hit the ExitLimitPrice
or return an error will be used. Multihop swap also provides a PickBestRoute
option. When PickBestRoute
is true all routes will be run and the route that results in the greatest amount of the resulting TokenOut for at final hop will be used. This option to dynamically pick the best route at runtime significantly reduces the risk of front running.
Multihop Swap Message
MsgMultiHopSwap
Creator
string (sdk.AccAddress)
Account from which TokenIn is debited
Receiver
string (sdk.AccAddress)
Account to which TokenOut is credited
Routes
[]MultiHopRoute
Array of possible routes
AmountIn
sdk.Int
Amount of TokenIn to swap
ExitLimitPrice
sdk.Dec
Minimum price that that must be satisfied for a route to succeed
PickBestRoute
bool
If true all routes are run and the route with the best price is used
Multihop Route
Hops
[]String
Array of denoms to route through
Last updated