-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSqrtPriceMathTest.sol
86 lines (77 loc) · 2.64 KB
/
SqrtPriceMathTest.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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();
}
}