# SwapMath

Private constructor that cannot be constructed.

Returns the price and token amounts resulting from an Elastic swap.

Params | Type | Description |
---|---|---|

sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |

sqrtRatioTargetX96 | The target square root price of the pool following the swap denominated in Q notation. Direction of the swap is inferred by comparing the target price against the current pool price. | |

liquidity | The amount of usable liquidity. | |

amountRemaining | Remaining amount of tokens that needs to be swapped in or out. | |

feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |

exactIn | boolean | `true` = Swap logic is based on exact in.
`false` = Swap logic is based on exact out. |

zeroForOne | boolean | `true` = Swap is from token0 to token1.
`false` = Swap is from token1 to token0. |

Returns the amount of tokens used in the swap in order to reach the target price.

Params | Type | Description |
---|---|---|

sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |

sqrtRatioTargetX96 | The target square root price of the pool following the swap denominated in Q notation. Direction of the swap is inferred by comparing the target price against the current pool price. | |

liquidity | The amount of usable liquidity. | |

feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |

exactIn | boolean | `true` = Swap logic is based on exact in.
`false` = Swap logic is based on exact out. |

zeroForOne | boolean | `true` = Swap is from token0 to token1.
`false` = Swap is from token1 to token0. |

Type | Description |
---|---|

The amount of tokens used in the swap in order to reach the target price. |

Returns the output token amount from the swap.

Params | Type | Description |
---|---|---|

sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |

sqrtRatioTargetX96 | The target square root price of the pool following the swap denominated in Q notation. Direction of the swap is inferred by comparing the target price against the current pool price. | |

liquidity | The amount of usable liquidity. | |

deltaL | The liquidity delta due to the swap. | |

feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |

exactIn | boolean | `true` = Swap logic is based on exact in.
`false` = Swap logic is based on exact out. |

zeroForOne | boolean | `true` = Swap is from token0 to token1.
`false` = Swap is from token1 to token0. |

Type | Description |
---|---|

Swap output token amount. |

Returns the incremental liquidity in the case where the resulting pool price after the swap is non-zero (i.e. target price was reached within the pool).

Params | Type | Description |
---|---|---|

sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |

sqrtRatioTargetX96 | ||

liquidity | The amount of usable liquidity. | |

absAmount | The absolute amount of tokens used for the swap. | |

exactIn | boolean | `true` = Swap logic is based on exact in.
`false` = Swap logic is based on exact out. |

zeroForOne | boolean | `true` = Swap is from token0 to token1.
`false` = Swap is from token1 to token0. |

Type | Description |
---|---|

The incremental liquidity amount following a swap. |

Returns the estimated incremental liquidity in the case where the resulting pool price after the swap is zero (i.e. target price is outside the pool).

Params | Type | Description |
---|---|---|

absAmount | The absolute amount of tokens used for the swap. | |

liquidity | The amount of usable liquidity. | |

sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |

feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |

exactIn | boolean | `true` = Swap logic is based on exact in.
`false` = Swap logic is based on exact out. |

zeroForOne | boolean | `true` = Swap is from token0 to token1.
`false` = Swap is from token1 to token0. |

Type | Description |
---|---|

The estimated incremental liquidity amount following a swap. |

Returns the final price following the swap.

Params | Type | Description |
---|---|---|

absAmount | The absolute amount of tokens used for the swap. | |

liquidity | The amount of usable liquidity. | |

deltaL | The liquidity delta due to the swap. | |

sqrtRatioCurrentX96 | The current square root price of the pool denominated in Q notation. | |

feePips | The swap fee taken from the input amount, denominated in hundredths of bips. | |

exactIn | boolean | `true` = Swap logic is based on exact in.
`false` = Swap logic is based on exact out. |

zeroForOne | boolean | `true` = Swap is from token0 to token1.
`false` = Swap is from token1 to token0. |

Type | Description |
---|---|

The final price following the swap. |

Last modified 4mo ago