SwapMath
Contains methods for computing the result of a swap within a single tick price range, i.e., a single tick.
Functions
computeSwapStep
Computes the result of swapping some amount in, or amount out, given the parameters of the swap
The fee, plus the amount in, will never exceed the amount remaining if the swap's amountSpecified
is positive
Parameters:
Name | Type | Description |
---|---|---|
| uint160 | The current sqrt price of the pool |
| uint160 | The price that cannot be exceeded, from which the direction of the swap is inferred |
| uint128 | The usable liquidity |
| int256 | How much input or output amount is remaining to be swapped in/out |
| uint24 | The fee taken from the input amount, expressed in hundredths of a bip |
Return Values:
Name | Type | Description |
---|---|---|
| uint160 | The price after swapping the amount in/out, not to exceed the price target |
| uint256 | The amount to be swapped in, of either token0 or token1, based on the direction of the swap |
| uint256 | The amount to be received, of either token0 or token1, based on the direction of the swap |
| uint256 | The amount of input that will be taken as a fee |
Last updated