Improve Protorev Binary Search Range Bounding For Concentrated Liquidity Pools #5884
Labels
F: concentrated-liquidity
Tracking the development of concentrated liquidity feature to improve filtering on the project board
protorev
All things related to x/protorev
Background
This issue describes the ideal APIs the Concentrated Liquidity (CL) module can provide ProtoRev to perform successful pool rebalancing, without running into spurious out of gas issues related to crossing ticks in CL pool swaps.
The context behind this issue is that after the v16 upgrade, it was discovered that when a CL pool has low liquidity and a sizable number of ticks (at the time of the discovery, that being ~$1k of total liquidity and ~28k ticks), when attempting determine the optimal input size to rebalance pools via a binary search approach in protorev, a single call to
k.poolmanagerKeeper.MultihopEstimateOutGivenExactAmountIn
with a tokenIn that crosses over 10k ticks takes more than 50 million gas to compute.The three main relevant APIs that Protorev uses as part of its rebalancing logic are:
poolmanagerKeeper.MultihopEstimateOutGivenExactAmountIn
swapModule.CalcOutAmtGivenIn
poolmanagerKeeper.RouteExactAmountIn
Currently, none of these methods provide an easy way to bound the number of ticks crossed or gas used.
At the heart of the problem is trying to swap in too large of an amount through a route, causing too many ticks to be crossed. The reason this is the case today is because ProtoRev determines the optimal input amount by performing a binary search process that tests different input amounts to see which one results in the largest profit. For example, the parameters set for the OSMO backrunning opportunities is set to perform a binary search between 1 and 16,384 OSMO (extending up to 131,072 OSMO if an opportunity needs more than ~16k to fully capture the opportunity).
To solve this issue then is to have more intelligent binary search bounds calculations, decreasing the upper bound if it crosses too many ticks on a concentrated liquidity pool(s) based on the acceptable gas usage and compute time of the module.
Suggested Design
Concentrated Liquidity Changes To Improve Situation
ComputeMaxInAmtGivenMaxTicksCrossed
for the CL modulewould be useful so that protorev can determine the max amount that can be put in while still respecting the tick boundaries. This will then be used to decide the protorev binary search upper bound, taking the min of MaxInAmtGivenMaxTicksCrossed from this method and the const 2^14 bound from the module.
ProtoRev Changes To Improve Situation
ComputeMaxInAmtGivenMaxTicksCrossed
(or something similar) is implemented, update theExtendSearchRangeIfNeeded
method inrebalance.go
(osmosis/x/protorev/keeper/rebalance.go
Line 171 in 4aeaaa5
UpdateSearchRangeIfNeeded
method that also can decrease the search range.ComputeMaxInAmtGivenMaxTicksCrossed
and the default upper bound.The text was updated successfully, but these errors were encountered: