pyaver.layouts
1from enum import IntEnum 2from construct import Switch, Bytes, Int8ul, Int32ul, Int64ul, Padding, Int64sl 3from construct import Struct as cStruct 4 5PUBLIC_KEY_LAYOUT = Bytes(32) 6 7KEY_LAYOUT = Bytes(16) 8 9STRING_LAYOUT = cStruct( 10 "string_length" / Int8ul, 11 Padding(3), 12 "content" / Bytes(lambda this: this.string_length) 13) 14 15STRING_VECTOR_LAYOUT = cStruct( 16 "vec_length" / Int8ul, 17 Padding(3), 18 "strings" / STRING_LAYOUT[lambda this: this.vec_length] 19) 20 21OUTCOME_AOB_INSTANCE_LAYOUT = cStruct( 22 "orderbook" / PUBLIC_KEY_LAYOUT, 23 "event_queue" / PUBLIC_KEY_LAYOUT, 24 "bids" / PUBLIC_KEY_LAYOUT, 25 "asks" / PUBLIC_KEY_LAYOUT, 26) 27 28 29SLAB_HEADER_LAYOUT = cStruct( 30 "account_tag" / Int8ul, 31 "bump_index" / Int64ul, 32 "free_list_len" / Int64ul, 33 "free_list_head" / Int32ul, 34 35 "callback_memory_offset" / Int64ul, 36 "callback_free_list_len" / Int64ul, 37 "callback_free_list_head" / Int64ul, 38 "callback_bump_index" / Int64ul, 39 40 "root_node" / Int32ul, 41 "leaf_count" / Int64ul, 42 "market_address" / PUBLIC_KEY_LAYOUT, 43 Padding(7) 44) 45 46 47class NodeType(IntEnum): 48 UNINTIALIZED = 0 49 INNER_NODE = 1 50 LEAF_NODE = 2 51 FREE_NODE = 3 52 LAST_FREE_NODE = 4 53 54# Node size = 32 (+ tag size = 8) => SLOT_SIZE = 40 55 56 57UNINTIALIZED_LAYOUT = cStruct( 58 Padding(32) 59) 60 61INNER_NODE_LAYOUT = cStruct( 62 "prefix_len" / Int64ul, # 8 63 "key" / KEY_LAYOUT, # 16 64 "children" / Int32ul[2], # 8 65) 66 67LEAF_NODE_LAYOUT = cStruct( 68 "key" / KEY_LAYOUT, # 16 69 "callback_info_pt" / Int64ul, # 8 70 "base_quantity" / Int64ul, # 8 71) 72 73FREE_NODE_LAYOUT = cStruct( 74 "next" / Int32ul, # 4 75 Padding(28) # -> 32 76) 77 78LAST_FREE_NODE_LAYOUT = cStruct( 79 Padding(32) 80) 81 82SLAB_NODE_LAYOUT = cStruct( 83 "tag" / Int64ul, 84 "node" 85 / Switch( 86 lambda this: this.tag, 87 { 88 NodeType.UNINTIALIZED: UNINTIALIZED_LAYOUT, 89 NodeType.INNER_NODE: INNER_NODE_LAYOUT, 90 NodeType.LEAF_NODE: LEAF_NODE_LAYOUT, 91 NodeType.FREE_NODE: FREE_NODE_LAYOUT, 92 NodeType.LAST_FREE_NODE: LAST_FREE_NODE_LAYOUT, 93 }, 94 ), 95) 96 97CALLBACK_INFO_LAYOUT = cStruct( 98 "user_market" / PUBLIC_KEY_LAYOUT, 99 "fee_tier" / Int8ul, 100) 101CALLBACK_INFO_LEN = 33 102 103SLOT_SIZE = 40 104SLAB_HEADER_SIZE = 97 105PADDED_LEN = SLAB_HEADER_SIZE + 7 106 107SLAB_LAYOUT = cStruct( 108 "header" / SLAB_HEADER_LAYOUT, 109 "nodes" / SLAB_NODE_LAYOUT[lambda this: this.header.bump_index], 110) 111 112 113USER_MARKET_OUTCOME_POSITION_LAYOUT = cStruct( 114 "free" / Int64ul, 115 "locked" / Int64ul, 116) 117 118USER_MARKET_ORDER_LAYOUT = cStruct( 119 "order_id" / KEY_LAYOUT, 120 "outcome_id" / Int8ul, 121 "base_qty" / Int64ul, 122) 123 124CLOCK_STRUCT = cStruct( 125 "slot" / Int64ul, 126 "epoch_start_timestamp" / Int64sl, 127 "epoch" / Int64ul, 128 "leader_schedule_epoch" / Int64ul, 129 "unix_timestamp" / Int64sl, 130) 131 132def USER_MARKET_STATE_LEN(number_of_outcomes: int, max_number_of_orders: int): 133 return 8 + 32*4 + 3*1 +2*4 + 6*8 + 4+(number_of_outcomes * 2*8) + 4+(max_number_of_orders * (16+1+8)) 134 135#### 136#Event Queue 137 138class EventType(IntEnum): 139 FILL = 0 140 OUT = 1 141 142STRING_LAYOUT = cStruct( 143 "string_length" / Int8ul, 144 Padding(3), 145 "content" / Bytes(lambda this: this.string_length) 146) 147 148EVENT_QUEUE_HEADER_LAYOUT = cStruct( 149 "account_tag" / Int8ul, 150 "head" / Int64ul, 151 "count" / Int64ul, 152 "event_size" / Int64ul, 153 "seq_num" / Int64ul, 154) 155EVENT_QUEUE_HEADER_LEN = 33 156 157CALLBACK_INFO_LAYOUT = cStruct( 158 "user_market" / PUBLIC_KEY_LAYOUT, 159 "fee_tier" / Int8ul, 160) 161CALLBACK_INFO_LEN = 33 162 163ORDER_SUMMARY_SIZE = 41 164 165REGISTER_SIZE = ORDER_SUMMARY_SIZE + 1 166 167EVENT_SLOT_SIZE = 1 + 33 + 2*CALLBACK_INFO_LEN 168 169FILL_LAYOUT = cStruct( 170 "taker_side" / Int8ul, 171 "maker_order_id" / KEY_LAYOUT, 172 "quote_size" / Int64ul, 173 "base_size" / Int64ul, 174 "maker_callback_info" / CALLBACK_INFO_LAYOUT, 175 "taker_callback_info" / CALLBACK_INFO_LAYOUT, 176) 177 178OUT_LAYOUT = cStruct( 179 "side" / Int8ul, 180 "order_id" / KEY_LAYOUT, 181 "base_size" / Int64ul, 182 "delete" / Int8ul, 183 "callback_info" / CALLBACK_INFO_LAYOUT, 184 # Padding(EVENT_SLOT_SIZE-59) 185) 186 187EVENT_LAYOUT = cStruct( 188 "tag" / Int8ul, 189 "node" 190 / Switch( 191 lambda this: this.tag, 192 { 193 EventType.FILL: FILL_LAYOUT, 194 EventType.OUT: OUT_LAYOUT, 195 }, 196 ), 197)
class
NodeType(enum.IntEnum):
48class NodeType(IntEnum): 49 UNINTIALIZED = 0 50 INNER_NODE = 1 51 LEAF_NODE = 2 52 FREE_NODE = 3 53 LAST_FREE_NODE = 4
An enumeration.
UNINTIALIZED = <NodeType.UNINTIALIZED: 0>
INNER_NODE = <NodeType.INNER_NODE: 1>
LEAF_NODE = <NodeType.LEAF_NODE: 2>
FREE_NODE = <NodeType.FREE_NODE: 3>
LAST_FREE_NODE = <NodeType.LAST_FREE_NODE: 4>
Inherited Members
- enum.Enum
- name
- value
- builtins.int
- conjugate
- bit_length
- to_bytes
- from_bytes
- as_integer_ratio
- real
- imag
- numerator
- denominator
def
USER_MARKET_STATE_LEN(number_of_outcomes: int, max_number_of_orders: int)
class
EventType(enum.IntEnum):
An enumeration.
FILL = <EventType.FILL: 0>
OUT = <EventType.OUT: 1>
Inherited Members
- enum.Enum
- name
- value
- builtins.int
- conjugate
- bit_length
- to_bytes
- from_bytes
- as_integer_ratio
- real
- imag
- numerator
- denominator