infrastructure-upgrade/lib/v3-core/contracts/test/SqrtPriceMathTest.sol
T-Hax 735546619e
init
Signed-off-by: T-Hax <>
2023-04-08 18:46:18 +00:00

87 lines
2.6 KiB
Solidity

// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;
import '../libraries/SqrtPriceMath.sol';
contract SqrtPriceMathTest {
function getNextSqrtPriceFromInput(
uint160 sqrtP,
uint128 liquidity,
uint256 amountIn,
bool zeroForOne
) external pure returns (uint160 sqrtQ) {
return SqrtPriceMath.getNextSqrtPriceFromInput(sqrtP, liquidity, amountIn, zeroForOne);
}
function getGasCostOfGetNextSqrtPriceFromInput(
uint160 sqrtP,
uint128 liquidity,
uint256 amountIn,
bool zeroForOne
) external view returns (uint256) {
uint256 gasBefore = gasleft();
SqrtPriceMath.getNextSqrtPriceFromInput(sqrtP, liquidity, amountIn, zeroForOne);
return gasBefore - gasleft();
}
function getNextSqrtPriceFromOutput(
uint160 sqrtP,
uint128 liquidity,
uint256 amountOut,
bool zeroForOne
) external pure returns (uint160 sqrtQ) {
return SqrtPriceMath.getNextSqrtPriceFromOutput(sqrtP, liquidity, amountOut, zeroForOne);
}
function getGasCostOfGetNextSqrtPriceFromOutput(
uint160 sqrtP,
uint128 liquidity,
uint256 amountOut,
bool zeroForOne
) external view returns (uint256) {
uint256 gasBefore = gasleft();
SqrtPriceMath.getNextSqrtPriceFromOutput(sqrtP, liquidity, amountOut, zeroForOne);
return gasBefore - gasleft();
}
function getAmount0Delta(
uint160 sqrtLower,
uint160 sqrtUpper,
uint128 liquidity,
bool roundUp
) external pure returns (uint256 amount0) {
return SqrtPriceMath.getAmount0Delta(sqrtLower, sqrtUpper, liquidity, roundUp);
}
function getAmount1Delta(
uint160 sqrtLower,
uint160 sqrtUpper,
uint128 liquidity,
bool roundUp
) external pure returns (uint256 amount1) {
return SqrtPriceMath.getAmount1Delta(sqrtLower, sqrtUpper, liquidity, roundUp);
}
function getGasCostOfGetAmount0Delta(
uint160 sqrtLower,
uint160 sqrtUpper,
uint128 liquidity,
bool roundUp
) external view returns (uint256) {
uint256 gasBefore = gasleft();
SqrtPriceMath.getAmount0Delta(sqrtLower, sqrtUpper, liquidity, roundUp);
return gasBefore - gasleft();
}
function getGasCostOfGetAmount1Delta(
uint160 sqrtLower,
uint160 sqrtUpper,
uint128 liquidity,
bool roundUp
) external view returns (uint256) {
uint256 gasBefore = gasleft();
SqrtPriceMath.getAmount1Delta(sqrtLower, sqrtUpper, liquidity, roundUp);
return gasBefore - gasleft();
}
}