TickLiquidity
to fill the swap order. Liquidity is always iterated through in order of best to worst price (from the taker’s perspective.) For each swap, we completely exhaust the available reserves before moving on to the next tick. For TickLiquidity
instances at the same TickIndex
they are iterated through in a deterministic order as follows:
PoolReserves
take priorityLimitOrderTranches
are iterated through when Pool Reserve liquidity is depletedLimitOrderTranches
are iterated through in alphabetical order of their TrancheKey
(LimitOrderTranche.Key.TrancheKey
.)PoolReserves
the proceeds from the swap are added to the reserves on the reciprocal side of the pool. Ie. The output of TokenA swapped through a PoolReserves
will be moved to a PoolReserves
holding TokenB.
ATOM
0 USDC
. Price: 8 USDC
per ATOM
. Tick index .ATOM
0 USDC
. Price: 9 USDC
per ATOM
. Tick index .ATOM
0 USDC
. Price: 10 USDC
per ATOM
. Tick index .ATOM
. Price: USDC
per ATOM
: Tick index USDC
. Price: ATOM
per USDC
: Tick index ATOM
per USDC
spent. it yields ATOM
per USDC
USDC
per ATOM
spent. it yields USDC
per ATOM
Taker Limit Order
. She wants to swap USDC
for ATOM
at the best possible price.
TickLiquidity
holding ATOM
is a LimitOrderTranche
at tick . Since this is a limit order, when swapped through and depleted the liquidity is removed from state and the USDC
Alice paid can be later withdrawn by the limit order Receiver
USDC
using this pool before depleting the reserves. This will net her ATOM
for the swap:USDC
she needs to swap, so we move to the next available tick:
This tick offers ATOM
at a price of USDC
per ATOM
and is of type PoolReserve
. Any USDC Alice pays for this swap will be placed in the corresponding poolReserves of the Pool (USDC @ Tick .) Alice swaps the remainder of her USDC
here, resulting in an additional ATOM
:USDC
for ATOM
with an average price of ATOM
per USDC
.PoolReserves
have a fee of zero. In a real world scenario almost all PoolReserves
will have a fee. In a scenario with fees TokenIn
will be added to ). Learn more about fees in the PoolReserves section.