forked from Uniswap/v3-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TickBitmapTest.sol
40 lines (32 loc) · 1.25 KB
/
TickBitmapTest.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
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;
import '../libraries/TickBitmap.sol';
contract TickBitmapTest {
using TickBitmap for mapping(int16 => uint256);
mapping(int16 => uint256) public bitmap;
function flipTick(int24 tick) external {
bitmap.flipTick(tick, 1);
}
function getGasCostOfFlipTick(int24 tick) external returns (uint256) {
uint256 gasBefore = gasleft();
bitmap.flipTick(tick, 1);
return gasBefore - gasleft();
}
function nextInitializedTickWithinOneWord(int24 tick, bool lte)
external
view
returns (int24 next, bool initialized)
{
return bitmap.nextInitializedTickWithinOneWord(tick, 1, lte);
}
function getGasCostOfNextInitializedTickWithinOneWord(int24 tick, bool lte) external view returns (uint256) {
uint256 gasBefore = gasleft();
bitmap.nextInitializedTickWithinOneWord(tick, 1, lte);
return gasBefore - gasleft();
}
// returns whether the given tick is initialized
function isInitialized(int24 tick) external view returns (bool) {
(int24 next, bool initialized) = bitmap.nextInitializedTickWithinOneWord(tick, 1, true);
return next == tick ? initialized : false;
}
}