|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity =0.7.6; |
| 3 | + |
| 4 | +import "../libraries/SqrtPriceMath.sol"; |
| 5 | + |
| 6 | +contract SqrtPriceMathTest { |
| 7 | + function getNextSqrtPriceFromInput(uint160 sqrtP, uint128 liquidity, uint256 amountIn, bool zeroForOne) |
| 8 | + external |
| 9 | + pure |
| 10 | + returns (uint160 sqrtQ) |
| 11 | + { |
| 12 | + return SqrtPriceMath.getNextSqrtPriceFromInput(sqrtP, liquidity, amountIn, zeroForOne); |
| 13 | + } |
| 14 | + |
| 15 | + function getGasCostOfGetNextSqrtPriceFromInput(uint160 sqrtP, uint128 liquidity, uint256 amountIn, bool zeroForOne) |
| 16 | + external |
| 17 | + view |
| 18 | + returns (uint256) |
| 19 | + { |
| 20 | + uint256 gasBefore = gasleft(); |
| 21 | + SqrtPriceMath.getNextSqrtPriceFromInput(sqrtP, liquidity, amountIn, zeroForOne); |
| 22 | + return gasBefore - gasleft(); |
| 23 | + } |
| 24 | + |
| 25 | + function getNextSqrtPriceFromOutput(uint160 sqrtP, uint128 liquidity, uint256 amountOut, bool zeroForOne) |
| 26 | + external |
| 27 | + pure |
| 28 | + returns (uint160 sqrtQ) |
| 29 | + { |
| 30 | + return SqrtPriceMath.getNextSqrtPriceFromOutput(sqrtP, liquidity, amountOut, zeroForOne); |
| 31 | + } |
| 32 | + |
| 33 | + function getGasCostOfGetNextSqrtPriceFromOutput(uint160 sqrtP, uint128 liquidity, uint256 amountOut, bool zeroForOne) |
| 34 | + external |
| 35 | + view |
| 36 | + returns (uint256) |
| 37 | + { |
| 38 | + uint256 gasBefore = gasleft(); |
| 39 | + SqrtPriceMath.getNextSqrtPriceFromOutput(sqrtP, liquidity, amountOut, zeroForOne); |
| 40 | + return gasBefore - gasleft(); |
| 41 | + } |
| 42 | + |
| 43 | + function getAmount0Delta(uint160 sqrtLower, uint160 sqrtUpper, uint128 liquidity, bool roundUp) |
| 44 | + external |
| 45 | + pure |
| 46 | + returns (uint256 amount0) |
| 47 | + { |
| 48 | + return SqrtPriceMath.getAmount0Delta(sqrtLower, sqrtUpper, liquidity, roundUp); |
| 49 | + } |
| 50 | + |
| 51 | + function getAmount1Delta(uint160 sqrtLower, uint160 sqrtUpper, uint128 liquidity, bool roundUp) |
| 52 | + external |
| 53 | + pure |
| 54 | + returns (uint256 amount1) |
| 55 | + { |
| 56 | + return SqrtPriceMath.getAmount1Delta(sqrtLower, sqrtUpper, liquidity, roundUp); |
| 57 | + } |
| 58 | + |
| 59 | + function getGasCostOfGetAmount0Delta(uint160 sqrtLower, uint160 sqrtUpper, uint128 liquidity, bool roundUp) |
| 60 | + external |
| 61 | + view |
| 62 | + returns (uint256) |
| 63 | + { |
| 64 | + uint256 gasBefore = gasleft(); |
| 65 | + SqrtPriceMath.getAmount0Delta(sqrtLower, sqrtUpper, liquidity, roundUp); |
| 66 | + return gasBefore - gasleft(); |
| 67 | + } |
| 68 | + |
| 69 | + function getGasCostOfGetAmount1Delta(uint160 sqrtLower, uint160 sqrtUpper, uint128 liquidity, bool roundUp) |
| 70 | + external |
| 71 | + view |
| 72 | + returns (uint256) |
| 73 | + { |
| 74 | + uint256 gasBefore = gasleft(); |
| 75 | + SqrtPriceMath.getAmount1Delta(sqrtLower, sqrtUpper, liquidity, roundUp); |
| 76 | + return gasBefore - gasleft(); |
| 77 | + } |
| 78 | +} |
0 commit comments