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

41 lines
1.2 KiB
Solidity

// 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;
}
}