Swaps
An overview on what Swaps on Duality are
Swap provides the most basic mechanism for exchanging one denom for another. It is a core building block of Multihop Swaps and Taker limit order. The swap operation operates by trading a TokenIn
through the liquidity pools that are provided by LPs and outputs a specified TokenOut
When performing a swap we iterate through liquidity (PoolReserves
& LimitOrderTranche
s) from best to worst price. As we iterate through each instance of TickLiqudity
we fully exhaust it before moving to the next TickLiquidity
instance. This iteration continues until ONE of the following conditions is met:
All available liquidity has been exhausted.
If there is no available tokenOut liquidity for the given pair at the beginning of the swap it will fail and return an
ErrInsufficientLiquidity
.If swap is called through a
IMMEDIATE_OR_CANCEL
limit order it will still succeed if liquidity is exhausted and only a portion of theAmountIn
has been used. In all other cases a partial fill of a swap will result in a failure.
The
AmountIn
has been hit (ie. the user has swapped through 100% of the suppliedTokenIn
).MaxAmountOut
has been set and theTokenOut
amount is equal toMaxAmountOut
.In cases where only a portion of the maxAmountIn is used only the used portion of
TokenIn
will be debited from the user's account.
Last updated