osmosis icon indicating copy to clipboard operation
osmosis copied to clipboard

CL: Iterates till out of gas when there is not sufficient liquidity

Open czarcas7ic opened this issue 2 years ago • 0 comments

Background

Quasar made the following comment in our Slack:

Hey! We're currently experiencing out-of-gas issues when attempting large swap amounts over pool 1081 axl.USDC/USDT. We've noticed that smaller liquidity swaps work without any hitches, leading us to believe that the problem might be due to an iterative process on the chain side. From our understanding, Osmosis seems to calculate a swap as:

while (stillNeededLiquidityForSwap > 0) {
    tickspacingindex -= 1;
    // Deduct available liquidity in the current tick spacing from stillNeededLiquidityForSwap
}

If there's a need to check a considerable number of ticks to meet the liquidity requirements, it appears that a NOT_ENOUGH_LIQUIDITY error is being obscured by an OUT_OF_GAS error. Could you kindly look into this? Thanks in advance!

Txs failed: https://www.mintscan.io/osmosis/tx/F207ABD16DA18B0A0C0826F2F0CD37FB1ED991D7BC0EE13586F441C1DD50B0BD https://www.mintscan.io/osmosis/tx/231FCC6DDC98F3CAC1A89A0A65B7268792E3CA6CB2FDCF010ECDBAFEE5771399

Txs that went trough with lower amounts: https://www.mintscan.io/osmosis/tx/1B2D4C37DEC4B93F97722D8AF1344C221A1DF0303B8A5DD5AC19BE3591BCFACC https://www.mintscan.io/osmosis/tx/DFE12C8AC46F5769E30386F4283D3BC253621FCB88435A534ADC992D19CEDDCF?height=11803880

Suggested Design

This can probably be fixed fairly simply by checking the total balance of the pool, and if the input corresponds to an estimated output that will exceed this, we error.

It may be necessary to check the total amount out during each iteration though if we cant make the estimation up front, and then once we hit an iteration that exceeds the liquidity of the pool, we error.

Acceptance Criteria

If we swap with an amount that is greater than the liquidity of the pool, we error with this message rather than iterating till out of gas.

czarcas7ic avatar Oct 17 '23 18:10 czarcas7ic