SwapMath
Functions
_amountToBinNetOfProtocolFee
Internal function to calculate the amount after deducting the protocol fee.
Parameters
deltaInErc
uint256
Input delta in ERC token.
feeBasis
uint256
Fee basis for calculating the fee amount.
protocolFeeD3
uint256
Proportion of the fee that goes to the protocol in three-decimal format. e.g. fee of 100 is 10% protocol fee rate.
Returns
amount
uint256
The amount after deducting the protocol fee.
_remainingBinInputSpaceGivenOutput
Internal function to calculate the remaining input space given the output.
Parameters
binLiquidity
uint256
The current liquidity in the bin.
output
uint256
The desired output amount.
sqrtPrice
uint256
The current square root price.
tokenAIn
bool
True if the swap input is token A.
Returns
binAmountIn
uint256
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
sqrtPrice
uint256
Current price.
tickData
IMaverickV2Pool.TickData
Reserve and liquidity values of the bin.
amountIn
uint256
Desired input amount.
tokenAIn
bool
True if the swap input is token A.
fee
uint256
Ratio that the swapper pays in D18 format.
protocolFeeD3
uint256
Proportion of the fee that goes to the protocol.
Returns
delta
Delta.Instance
Swap data delta for the exact input swap.
computeSwapExactOut
Calculate swap data for an exact output swap.
Parameters
sqrtPrice
uint256
Current price.
tickData
IMaverickV2Pool.TickData
Reserve and liquidity values of the bin.
amountOut
uint256
Desired output amount.
tokenAIn
bool
True if the swap input is token A.
fee
uint256
Ratio that the swapper pays in D18 format.
protocolFeeD3
uint256
Proportion of the fee that goes to the protocol.
Returns
delta
Delta.Instance
Swap data delta for the exact output swap.
Last updated