SwapMath
Functions
_amountToBinNetOfProtocolFee
Internal function to calculate the amount after deducting the protocol fee.
Parameters
Name | Type | Description |
---|---|---|
|
| Input delta in ERC token. |
|
| Fee basis for calculating the fee amount. |
|
| Proportion of the fee that goes to the protocol in three-decimal format. e.g. fee of 100 is 10% protocol fee rate. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount after deducting the protocol fee. |
_remainingBinInputSpaceGivenOutput
Internal function to calculate the remaining input space given the output.
Parameters
Name | Type | Description |
---|---|---|
|
| The current liquidity in the bin. |
|
| The desired output amount. |
|
| The current square root price. |
|
| True if the swap input is token A. |
Returns
Name | Type | Description |
---|---|---|
|
| The input amount that can be accommodated in the bin. |
computeEndPrice
Compute end price of a swap as well as the approximate end price in the tick domain. The resulting output fraction tick part is written to the input newDelta object.
Ain: endSqrtP = in / L + sqrtP
Bin: endSqrtP = 1 / (in / L + 1 / sqrtP) = L / (in + L / sqrtP)
fractional Tick: (endSqrtP - lowerSqrtP) / (upperSqrtP - lowerSqrtP)
computeSwapExactIn
Calculate swap data for an exact input swap.
Parameters
Name | Type | Description |
---|---|---|
|
| Current price. |
|
| Reserve and liquidity values of the bin. |
|
| Desired input amount. |
|
| True if the swap input is token A. |
|
| Ratio that the swapper pays in D18 format. |
|
| Proportion of the fee that goes to the protocol. |
Returns
Name | Type | Description |
---|---|---|
|
| Swap data delta for the exact input swap. |
computeSwapExactOut
Calculate swap data for an exact output swap.
Parameters
Name | Type | Description |
---|---|---|
|
| Current price. |
|
| Reserve and liquidity values of the bin. |
|
| Desired output amount. |
|
| True if the swap input is token A. |
|
| Ratio that the swapper pays in D18 format. |
|
| Proportion of the fee that goes to the protocol. |
Returns
Name | Type | Description |
---|---|---|
|
| Swap data delta for the exact output swap. |
Last updated