LibLinkedOrders
State Variables
NULL
NULL is a constant that represents an invalid order id
uint48 internal constant NULL = uint48(0);
Functions
insert
inserts an order at the bottom of a linked list of orders
function insert(LinkedOrders storage self, address maker_, uint256 amount_) internal returns (uint48 orderId_);
Parameters
Name | Type | Description |
---|---|---|
self | LinkedOrders | is the linked list of orders |
maker_ | address | is the address of the order maker |
amount_ | uint256 | is the amount of token to be traded |
remove
removes an order from a linked list of orders
function remove(LinkedOrders storage self, uint48 id_) internal returns (bool, address, uint256);
Parameters
Name | Type | Description |
---|---|---|
self | LinkedOrders | is the linked list of orders |
id_ | uint48 | is the id of the order to be removed |
modify
modifies the amount of an order
function modify(LinkedOrders storage self, uint48 id_, uint256 newAmount_) internal returns (address, uint256);
Parameters
Name | Type | Description |
---|---|---|
self | LinkedOrders | is the linked list of orders |
id_ | uint48 | is the id of the order to be modified |
newAmount_ | uint256 | is the new amount of the order |
removeUntilTarget
removes orders from a linked list of orders until the target amount is reached. Useful to fulfill market orders
deletes orders until the target amount is reached in the while loop. If the target amount is reached after removing the last order, returns. Else, does a partial fulfillment of the last order, if it exists
function removeUntilTarget(
LinkedOrders storage self,
uint256 targetAmount_,
uint128 price_,
function(uint48,uint128, address,uint256) internal _f
) internal returns (uint256, bool);
Parameters
Name | Type | Description |
---|---|---|
self | LinkedOrders | is the linked list of orders |
targetAmount_ | uint256 | is the cummulative amount to be removed |
price_ | uint128 | is the price of the order |
_f | function (uint48, uint128, address, uint256) internal | is the function to be called when an order is removed |
getOrders
returns the orders in a linked list of orders
function getOrders(LinkedOrders storage self) internal view returns (ViewOrder[] memory orders_);
Parameters
Name | Type | Description |
---|---|---|
self | LinkedOrders | is the linked list of orders |
Errors
OrderDoesNotExistError
OrderDoesNotExistError is emitted when an order does not exist
error OrderDoesNotExistError();
Structs
Order
Order is a struct that contains the maker, amount, and price of an order.
struct Order {
address maker;
uint48 prev;
uint48 next;
uint256 amount;
}
ViewOrder
ViewOrder is a struct that contains the id, maker, and amount of an order.
struct ViewOrder {
uint48 id;
address maker;
uint256 amount;
}
LinkedOrders
LinkedOrders is a struct that contains the head, tail, and length of a linked list of orders.
struct LinkedOrders {
uint48 head;
uint48 tail;
uint48 length;
mapping(uint48 => Order) orders;
}