NewOrderLinkedList
This library implements a linked list data structure for managing orderbook prices.
Variables
PriceLinkedList
(struct)
PriceLinkedList
(struct)a storage struct type for storing price linked lists
bidPrices
mapping(uint256 => uint256)
Hashmap-style linked list of bid prices, where key is the price and value is the next_price (next_price < price).
askPrices
mapping(uint256 => uint256)
Hashmap-style linked list of ask prices, where key is the price and value is the next_price (next_price > price).
bidHead
uint256
Head of the bid price linked list (i.e., the highest bid price).
askHead
uint256
Head of the ask price linked list (i.e., the lowest ask price).
lmp
uint256
Last matched price.
Internal Functions
_setLmp
_setLmp
Sets the last matched price in the PriceLinkedList.
Parameters
self
PriceLinkedList storage
The storage reference to the PriceLinkedList struct.
lmp_
uint256
The last matched price to set.
_heads
_heads
Returns the heads of the ask and bid price linked lists.
Parameters
self
PriceLinkedList storage
The storage reference to the PriceLinkedList struct.
Returns
askHead
uint256
The head of the ask price linked list.
bidHead
uint256
The head of the bid price linked list.
_askHead
_askHead
Returns the head of the ask price linked list.
Parameters
self
PriceLinkedList storage
The storage reference to the PriceLinkedList struct.
Returns
askHead
uint256
The head of the ask price linked list.
_bidHead
_bidHead
Returns the head of the bid price linked list.
Parameters
self
PriceLinkedList storage
The storage reference to the PriceLinkedList struct.
Returns
bidHead
uint256
The head of the bid price linked list.
_mktPrice
_mktPrice
Returns the last matched price.
Parameters
self
PriceLinkedList
The storage reference to the PriceLinkedList struct.
Returns
mktPrice
uint256
Returns the last matched price.
_next
_next
Returns the next price in the linked list based on the current price and whether it is a bid or ask price.
Parameters
self
PriceLinkedList storage
The storage reference to the PriceLinkedList struct.
isBid
bool
A flag indicating whether the current price is a bid price.
price
uint256
The current price.
Returns
next
uint256
The next price in the linked list.
_insert
_insert
Inserts a new price into the linked list based on whether it is a bid or ask price. The new price is inserted in the correct position, maintaining the order of the linked list.
Parameters
self
PriceLinkedList
The storage reference to the PriceLinkedList struct.
isBid
bool
A flag indicating whether the price is a bid price.
price
uint256
The price to insert.
_getPrices
_getPrices
Retrieves an array of prices from the linked list, starting from the head and moving to the next price in the specified direction (bid or ask). The number of prices returned is limited by the n
parameter.
Parameters
self
PriceLinkedList
The storage reference to the PriceLinkedList struct.
isBid
bool
A flag indicating the direction of the prices to retrieve.
n
uint256
The maximum number of prices to retrieve.
Returns
prices
uint256[] memory
An array of prices retrieved from the linked list.
Last updated