SecondsOutside
Contains methods for working with a mapping from tick to 32 bit timestamp values, specifically seconds spent outside the tick.
The mapping uses int24 for keys since ticks are represented as int24 and there are 8 (2^3) values per word. Note "seconds outside" is always a relative measurement, only consistent for as long as a the lower tick and upper tick have gross liquidity greater than 0.
Functions
initialize
Called the first time a tick is used to set the seconds outside value. Assumes the tick is not initialized.
Parameters:
Name | Type | Description |
---|---|---|
| mapping(int24 => uint256) | the packed mapping of tick to seconds outside |
| int24 | the tick to be initialized |
| int24 | the current tick |
| int24 | the spacing between usable ticks |
| uint32 | the current timestamp |
clear
Called when a tick is no longer used, to clear the seconds outside value of the tick
Parameters:
Name | Type | Description |
---|---|---|
| mapping(int24 => uint256) | the packed mapping of tick to seconds outside |
| int24 | the tick to be cleared |
| int24 | the spacing between usable ticks |
cross
Called when an initialized tick is crossed to update the seconds outside for that tick. Must be called every time an initialized tick is crossed
Parameters:
Name | Type | Description |
---|---|---|
| mapping(int24 => uint256) | the packed mapping of tick to seconds outside |
| int24 | the tick to be crossed |
| int24 | the spacing between usable ticks |
| uint32 | the current block timestamp truncated to 32 bits |
get
Get the seconds outside for an initialized tick. Should be called only on initialized ticks.
Parameters:
Name | Type | Description |
---|---|---|
| mapping(int24 => uint256) | the packed mapping of tick to seconds outside |
| int24 | the tick to get the seconds outside value for |
| int24 | the spacing between usable ticks |
Return Values:
Type | Description |
---|---|
uint32 | seconds outside value for that tick |
secondsInside
Get the seconds inside a tick range, assuming both tickLower and tickUpper are initialized
Parameters:
Name | Type | Description |
---|---|---|
| mapping(int24 => uint256) | the packed mapping of tick to seconds outside |
| int24 | the lower tick for which to get seconds inside |
| int24 | the upper tick for which to get seconds inside |
| int24 | the current tick |
| int24 | the spacing between usable ticks |
Return Values:
Name | Type | Description |
---|---|---|
| uint32 | relative seconds inside value that can be snapshotted and compared to a later snapshot to compute |
time spent between tickLower and tickUpper, i.e. time that a position's liquidity was in use.
Last updated