Skip to main content
Helpful?

TickBitmap

Git Source | Generated with forge doc

Stores a packed mapping of tick index to its initialized state

The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word.

Functions

compress

round towards negative infinity

function compress(int24 tick, int24 tickSpacing) internal pure returns (int24 compressed);

position

Computes the position in the mapping where the initialized bit for a tick lives

function position(int24 tick) internal pure returns (int16 wordPos, uint8 bitPos);

Parameters

NameTypeDescription
tickint24The tick for which to compute the position

Returns

NameTypeDescription
wordPosint16The key in the mapping containing the word in which the bit is stored
bitPosuint8The bit position in the word where the flag is stored

flipTick

Flips the initialized state for a given tick from false to true, or vice versa

function flipTick(mapping(int16 => uint256) storage self, int24 tick, int24 tickSpacing) internal;

Parameters

NameTypeDescription
selfmapping(int16 => uint256)The mapping in which to flip the tick
tickint24The tick to flip
tickSpacingint24The spacing between usable ticks

nextInitializedTickWithinOneWord

Returns the next initialized tick contained in the same word (or adjacent word) as the tick that is either to the left (less than or equal to) or right (greater than) of the given tick

function nextInitializedTickWithinOneWord(
mapping(int16 => uint256) storage self,
int24 tick,
int24 tickSpacing,
bool lte
) internal view returns (int24 next, bool initialized);

Parameters

NameTypeDescription
selfmapping(int16 => uint256)The mapping in which to compute the next initialized tick
tickint24The starting tick
tickSpacingint24The spacing between usable ticks
lteboolWhether to search for the next initialized tick to the left (less than or equal to the starting tick)

Returns

NameTypeDescription
nextint24The next initialized or uninitialized tick up to 256 ticks away from the current tick
initializedboolWhether the next tick is initialized, as the function only searches within up to 256 ticks

Errors

TickMisaligned

Thrown when the tick is not enumerated by the tick spacing

error TickMisaligned(int24 tick, int24 tickSpacing);

Parameters

NameTypeDescription
tickint24the invalid tick
tickSpacingint24The tick spacing of the pool
Helpful?