Skip to content

@gala-chain/apiAPI


API > computeSwapStep

Function: computeSwapStep()

computeSwapStep(sqrtPriceCurrent, sqrtPriceTarget, liquidity, amountRemaining, fee): BigNumber[]

Parameters

sqrtPriceCurrent: BigNumber

sqrtPriceTarget: BigNumber

liquidity: BigNumber

The usable liquidity

amountRemaining: BigNumber

How much input or output amount is remaining to be swapped in/out

fee: number

The fee taken from the input amount

Returns

sqrtRatioNext The price after swapping the amount in/out, not to exceed the price target

amountIn The amount to be swapped in, of either token0 or token1, based on the direction of the swap

amountOut The amount to be received, of either token0 or token1, based on the direction of the swap

feeAmount The amount of input that will be taken as a fee

Notice

Computes the result of swapping some amount in, or amount out, given the parameters of the swap

Dev

The fee, plus the amount in, will never exceed the amount remaining if the swap's amountSpecified is positive

Source

chain-api/src/utils/dex/swapMath.helper.ts:39