ddx-python 1.0.5__cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. ddx/.gitignore +1 -0
  2. ddx/__init__.py +58 -0
  3. ddx/_rust/__init__.pyi +2009 -0
  4. ddx/_rust/common/__init__.pyi +17 -0
  5. ddx/_rust/common/accounting.pyi +6 -0
  6. ddx/_rust/common/enums.pyi +3 -0
  7. ddx/_rust/common/requests/__init__.pyi +21 -0
  8. ddx/_rust/common/requests/intents.pyi +19 -0
  9. ddx/_rust/common/specs.pyi +17 -0
  10. ddx/_rust/common/state/__init__.pyi +41 -0
  11. ddx/_rust/common/state/keys.pyi +29 -0
  12. ddx/_rust/common/transactions.pyi +7 -0
  13. ddx/_rust/decimal.pyi +3 -0
  14. ddx/_rust/h256.pyi +3 -0
  15. ddx/_rust.abi3.so +0 -0
  16. ddx/app_config/ethereum/addresses.json +541 -0
  17. ddx/auditor/README.md +32 -0
  18. ddx/auditor/__init__.py +0 -0
  19. ddx/auditor/auditor_driver.py +1034 -0
  20. ddx/auditor/websocket_message.py +54 -0
  21. ddx/common/__init__.py +0 -0
  22. ddx/common/epoch_params.py +28 -0
  23. ddx/common/fill_context.py +144 -0
  24. ddx/common/item_utils.py +38 -0
  25. ddx/common/logging.py +184 -0
  26. ddx/common/market_specs.py +64 -0
  27. ddx/common/trade_mining_params.py +19 -0
  28. ddx/common/transaction_utils.py +85 -0
  29. ddx/common/transactions/__init__.py +0 -0
  30. ddx/common/transactions/advance_epoch.py +91 -0
  31. ddx/common/transactions/advance_settlement_epoch.py +63 -0
  32. ddx/common/transactions/all_price_checkpoints.py +84 -0
  33. ddx/common/transactions/cancel.py +76 -0
  34. ddx/common/transactions/cancel_all.py +88 -0
  35. ddx/common/transactions/complete_fill.py +103 -0
  36. ddx/common/transactions/disaster_recovery.py +97 -0
  37. ddx/common/transactions/event.py +48 -0
  38. ddx/common/transactions/fee_distribution.py +119 -0
  39. ddx/common/transactions/funding.py +294 -0
  40. ddx/common/transactions/futures_expiry.py +123 -0
  41. ddx/common/transactions/genesis.py +108 -0
  42. ddx/common/transactions/inner/__init__.py +0 -0
  43. ddx/common/transactions/inner/adl_outcome.py +25 -0
  44. ddx/common/transactions/inner/fill.py +227 -0
  45. ddx/common/transactions/inner/liquidated_position.py +41 -0
  46. ddx/common/transactions/inner/liquidation_entry.py +41 -0
  47. ddx/common/transactions/inner/liquidation_fill.py +118 -0
  48. ddx/common/transactions/inner/outcome.py +32 -0
  49. ddx/common/transactions/inner/trade_fill.py +125 -0
  50. ddx/common/transactions/insurance_fund_update.py +142 -0
  51. ddx/common/transactions/insurance_fund_withdraw.py +99 -0
  52. ddx/common/transactions/liquidation.py +357 -0
  53. ddx/common/transactions/partial_fill.py +125 -0
  54. ddx/common/transactions/pnl_realization.py +122 -0
  55. ddx/common/transactions/post.py +72 -0
  56. ddx/common/transactions/post_order.py +95 -0
  57. ddx/common/transactions/price_checkpoint.py +96 -0
  58. ddx/common/transactions/signer_registered.py +62 -0
  59. ddx/common/transactions/specs_update.py +61 -0
  60. ddx/common/transactions/strategy_update.py +156 -0
  61. ddx/common/transactions/tradable_product_update.py +98 -0
  62. ddx/common/transactions/trade_mining.py +147 -0
  63. ddx/common/transactions/trader_update.py +105 -0
  64. ddx/common/transactions/withdraw.py +91 -0
  65. ddx/common/transactions/withdraw_ddx.py +74 -0
  66. ddx/common/utils.py +176 -0
  67. ddx/config.py +17 -0
  68. ddx/derivadex_client.py +254 -0
  69. ddx/py.typed +0 -0
  70. ddx/realtime_client/__init__.py +2 -0
  71. ddx/realtime_client/config.py +2 -0
  72. ddx/realtime_client/logs/pytest.log +0 -0
  73. ddx/realtime_client/models/__init__.py +683 -0
  74. ddx/realtime_client/realtime_client.py +567 -0
  75. ddx/rest_client/__init__.py +0 -0
  76. ddx/rest_client/clients/__init__.py +0 -0
  77. ddx/rest_client/clients/base_client.py +60 -0
  78. ddx/rest_client/clients/market_client.py +1241 -0
  79. ddx/rest_client/clients/on_chain_client.py +432 -0
  80. ddx/rest_client/clients/signed_client.py +301 -0
  81. ddx/rest_client/clients/system_client.py +843 -0
  82. ddx/rest_client/clients/trade_client.py +335 -0
  83. ddx/rest_client/constants/__init__.py +0 -0
  84. ddx/rest_client/constants/endpoints.py +67 -0
  85. ddx/rest_client/contracts/__init__.py +0 -0
  86. ddx/rest_client/contracts/checkpoint/__init__.py +560 -0
  87. ddx/rest_client/contracts/ddx/__init__.py +1949 -0
  88. ddx/rest_client/contracts/dummy_token/__init__.py +1014 -0
  89. ddx/rest_client/contracts/i_collateral/__init__.py +1414 -0
  90. ddx/rest_client/contracts/i_stake/__init__.py +696 -0
  91. ddx/rest_client/exceptions/__init__.py +0 -0
  92. ddx/rest_client/exceptions/exceptions.py +32 -0
  93. ddx/rest_client/http/__init__.py +0 -0
  94. ddx/rest_client/http/http_client.py +305 -0
  95. ddx/rest_client/models/__init__.py +0 -0
  96. ddx/rest_client/models/market.py +683 -0
  97. ddx/rest_client/models/signed.py +60 -0
  98. ddx/rest_client/models/system.py +390 -0
  99. ddx/rest_client/models/trade.py +140 -0
  100. ddx/rest_client/utils/__init__.py +0 -0
  101. ddx/rest_client/utils/encryption_utils.py +26 -0
  102. ddx_python-1.0.5.dist-info/METADATA +63 -0
  103. ddx_python-1.0.5.dist-info/RECORD +104 -0
  104. ddx_python-1.0.5.dist-info/WHEEL +4 -0
ddx/_rust/__init__.pyi ADDED
@@ -0,0 +1,2009 @@
1
+ # This file is automatically generated by pyo3_stub_gen
2
+ # ruff: noqa: E501, F401
3
+
4
+ import builtins
5
+ import datetime
6
+ import typing
7
+ from enum import Enum
8
+
9
+ class AdvanceEpoch:
10
+ time: AdvanceTime
11
+ epoch_id: builtins.int
12
+ json: typing.Any
13
+ def __new__(cls, epoch_id:builtins.int, time:AdvanceTime) -> AdvanceEpoch: ...
14
+ def __repr__(self) -> builtins.str: ...
15
+
16
+ class AdvanceSettlementEpoch:
17
+ time: AdvanceTime
18
+ actions: builtins.list[SettlementAction]
19
+ epoch_id: builtins.int
20
+ json: typing.Any
21
+ def __new__(cls, epoch_id:builtins.int, time:AdvanceTime, actions:typing.Sequence[SettlementAction]) -> AdvanceSettlementEpoch: ...
22
+ def __repr__(self) -> builtins.str: ...
23
+
24
+ class AdvanceTime:
25
+ value: builtins.int
26
+ timestamp: builtins.int
27
+ json: typing.Any
28
+ def __new__(cls, value:builtins.int, timestamp:builtins.int) -> AdvanceTime: ...
29
+ def __repr__(self) -> builtins.str: ...
30
+
31
+ class Balance:
32
+ r"""
33
+ Maps token address to balance amount
34
+ """
35
+ def __new__(cls, amount:Decimal, address:TokenSymbol) -> Balance: ...
36
+ def __repr__(self) -> builtins.str: ...
37
+ def __len__(self) -> builtins.int: ...
38
+ def __getitem__(self, key:TokenSymbol) -> Decimal: ...
39
+ def __setitem__(self, key:TokenSymbol, value:Decimal) -> None: ...
40
+ @classmethod
41
+ def default(cls, _cls:type) -> Balance:
42
+ r"""
43
+ Return an empty `Balance` with zero for every token.
44
+ """
45
+ @classmethod
46
+ def new_from_many(cls, _cls:type, amounts:typing.Mapping[TokenSymbol, Decimal]) -> Balance:
47
+ r"""
48
+ Construct a `Balance` from a mapping (`dict`) of
49
+ `TokenSymbol` → `Decimal` amounts.
50
+ """
51
+ def total_value(self) -> Decimal:
52
+ r"""
53
+ Total value of this balance, obtained by summing
54
+ every token amount. This will be either in USD or DDX, depending on
55
+ its contents.
56
+ """
57
+ def amounts(self) -> builtins.list[Decimal]:
58
+ r"""
59
+ Raw amounts ordered by the canonical token list.
60
+ """
61
+
62
+ class Block:
63
+ r"""
64
+ We use a single `BlockProducer` to sequence blocks along with other requests to ensure that
65
+ all Execution Operators synchronize their state with Ethereum event in the same order.
66
+
67
+ # Notes
68
+
69
+ Some Ethereum events (e.g. Deposits) must only be processed on confirmed blocks.
70
+ Block confirmation count is handled client-side during execution. The block producer's
71
+ responsibility is just to post block numbers into the `RequestQueue`.
72
+ """
73
+ json: typing.Any
74
+ def __new__(cls, number:builtins.int) -> Block: ...
75
+ def __repr__(self) -> builtins.str: ...
76
+
77
+ class BookOrder:
78
+ r"""
79
+ A Bid or Ask in the orderbook (maker order)
80
+ """
81
+ side: OrderSide
82
+ r"""
83
+ Bid = 0, Ask = 1
84
+ """
85
+ amount: Decimal
86
+ r"""
87
+ Order amount
88
+ """
89
+ price: Decimal
90
+ r"""
91
+ Price offered to takers
92
+ """
93
+ trader_address: builtins.str
94
+ r"""
95
+ Maker address
96
+ """
97
+ strategy_id_hash: builtins.str
98
+ r"""
99
+ Maker strategy identifier
100
+ """
101
+ book_ordinal: builtins.int
102
+ r"""
103
+ Per market ordinal sequencing inclusion in the order book
104
+ """
105
+ time_value: builtins.int
106
+ r"""
107
+ Time stamp of the post order transaction
108
+ """
109
+ def __new__(cls, side:OrderSide, amount:Decimal, price:Decimal, trader_address:builtins.str, strategy_id_hash:builtins.str, book_ordinal:builtins.int, time_value:builtins.int) -> BookOrder: ...
110
+ def __repr__(self) -> builtins.str: ...
111
+ def __deepcopy__(self, _memo:dict) -> BookOrder: ...
112
+ def as_item(self) -> Item:
113
+ r"""
114
+ Wrap this concrete structure into the generic [`Item`] enum.
115
+ """
116
+ @classmethod
117
+ def from_item(cls, _cls:type, item:Item) -> BookOrder:
118
+ r"""
119
+ Down-cast a generic [`Item`] into this concrete type.
120
+ """
121
+ def abi_encoded_value(self) -> builtins.bytes:
122
+ r"""
123
+ ABI-encode this value.
124
+ """
125
+ @classmethod
126
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
127
+ r"""
128
+ Decode bytes back into an [`Item`] of this concrete type.
129
+ """
130
+ def is_void(self) -> builtins.bool:
131
+ r"""
132
+ `true` when this value represents the special *void* marker
133
+ used to delete a leaf from the SMT.
134
+ """
135
+
136
+ class BookOrderKey:
137
+ symbol: ProductSymbol
138
+ order_hash: builtins.str
139
+ def __new__(cls, symbol:ProductSymbol, order_hash:builtins.str) -> BookOrderKey: ...
140
+ def __repr__(self) -> builtins.str: ...
141
+ def __deepcopy__(self, _memo:dict) -> BookOrderKey: ...
142
+ def encode_key(self) -> H256:
143
+ r"""
144
+ Encode this state-key into the 32-byte format used on-chain.
145
+ """
146
+ @classmethod
147
+ def decode_key(cls, _cls:type, value:H256) -> BookOrderKey:
148
+ r"""
149
+ Decode a previously-encoded key back into its strongly-typed form.
150
+ """
151
+
152
+ class CancelAllIntent:
153
+ r"""
154
+ Batch cancel all orders for a given strategy
155
+ """
156
+ symbol: ProductSymbol
157
+ strategy: builtins.str
158
+ r"""
159
+ Strategy to cancel orders for
160
+ """
161
+ nonce: builtins.str
162
+ r"""
163
+ A salt for uniqueness of the EIP-712 hash function.
164
+ """
165
+ session_key_signature: typing.Optional[builtins.str]
166
+ r"""
167
+ EIP-191 signature of the 1CT session public key
168
+ """
169
+ signature: builtins.str
170
+ r"""
171
+ EIP-712 signature of the order cancellation intent attributes
172
+ """
173
+ json: typing.Any
174
+ def __new__(cls, symbol:ProductSymbol, strategy:builtins.str, nonce:builtins.str, session_key_signature:typing.Optional[builtins.str], signature:typing.Optional[builtins.str]=None) -> CancelAllIntent: ...
175
+ def __repr__(self) -> builtins.str: ...
176
+ def hash_eip712(self, message_metadata:typing.Optional[tuple[builtins.int, builtins.str]]=None) -> builtins.str:
177
+ r"""
178
+ Compute the EIP-712 digest for this intent.
179
+ Passing `message_metadata=(chain_id, verifying_contract)`
180
+ overrides the default values used in the hash.
181
+ """
182
+ def recover_signer(self) -> tuple[builtins.str, builtins.str]:
183
+ r"""
184
+ Recover the `(eip712_hash, trader_address)` that signed
185
+ this intent.
186
+ """
187
+
188
+ class CancelOrderIntent:
189
+ symbol: ProductSymbol
190
+ order_hash: builtins.str
191
+ r"""
192
+ hash of the corresponding order intent
193
+ """
194
+ nonce: builtins.str
195
+ r"""
196
+ `nonce` specified in the order intent to cancel (to lookup the order without storing its hash)
197
+ A salt for uniqueness of the EIP-712 hash function. May optionally have business meaning to the client.
198
+ """
199
+ session_key_signature: typing.Optional[builtins.str]
200
+ r"""
201
+ EIP-191 signature of the 1CT session public key
202
+ """
203
+ signature: builtins.str
204
+ r"""
205
+ EIP-712 signature of the order cancellation intent attributes
206
+ """
207
+ json: typing.Any
208
+ def __new__(cls, symbol:ProductSymbol, order_hash:builtins.str, nonce:builtins.str, session_key_signature:typing.Optional[builtins.str], signature:typing.Optional[builtins.str]=None) -> CancelOrderIntent: ...
209
+ def __repr__(self) -> builtins.str: ...
210
+ def hash_eip712(self, message_metadata:typing.Optional[tuple[builtins.int, builtins.str]]=None) -> builtins.str:
211
+ r"""
212
+ Compute the EIP-712 digest for this intent.
213
+ Passing `message_metadata=(chain_id, verifying_contract)`
214
+ overrides the default values used in the hash.
215
+ """
216
+ def recover_signer(self) -> tuple[builtins.str, builtins.str]:
217
+ r"""
218
+ Recover the `(eip712_hash, trader_address)` that signed
219
+ this intent.
220
+ """
221
+
222
+ class Decimal:
223
+ r"""
224
+ Wrapped rust_decimal::Decimal. Constructor only supports str, e.g d = Decimal("123.456")
225
+ """
226
+ def __new__(cls, maybe_value:typing.Optional[typing.Any]=None) -> Decimal:
227
+ r"""
228
+ Create a new Decimal In Python:
229
+ let d1 = Decimal("123.456")
230
+ let d2 = Decimal("-987.654")
231
+ let d3 = Decimal("456")
232
+ let d4 = Decimal() # Decimal("0")
233
+ Accepts `None`, another `Decimal`, a string, an `int`, or a `float`.
234
+ When no value (or `None`) is supplied the resulting `Decimal` is zero.
235
+ """
236
+ def recorded_amount(self) -> Decimal:
237
+ r"""
238
+ Returns a value rounded toward zero to `TOKEN_UNIT_SCALE` decimal
239
+ places, matching the precision stored on-chain as `RecordedAmount`.
240
+ """
241
+ def to_usdc_grains(self) -> builtins.int:
242
+ r"""
243
+ Converts the current amount into raw USDC grains
244
+ (`u128`, scaled by `10^TOKEN_UNIT_SCALE`).
245
+ Fails if the result does not fit in `u128`.
246
+ """
247
+ def to_ddx_grains(self) -> builtins.int:
248
+ r"""
249
+ Converts the current amount into raw DDX grains
250
+ (`u128`, scaled by `10^18`).
251
+ Fails if the result does not fit in `u128`.
252
+ """
253
+ @classmethod
254
+ def from_usdc_grains(cls, _cls:type, u:builtins.int) -> Decimal:
255
+ r"""
256
+ Creates a `Decimal` from a `u128` expressed in USDC grains
257
+ (i.e. already scaled by `10^TOKEN_UNIT_SCALE`).
258
+ """
259
+ @classmethod
260
+ def from_ddx_grains(cls, _cls:type, u:builtins.int) -> Decimal:
261
+ r"""
262
+ Creates a `Decimal` from a `u128` expressed in DDX grains
263
+ (i.e. already scaled by `10^18`).
264
+ """
265
+ def quantize(self, precision:builtins.int) -> Decimal:
266
+ r"""
267
+ Returns a copy of this value rounded toward zero to the requested
268
+ number of fractional digits (`precision`).
269
+ """
270
+ def __setstate__(self, state:typing.Any) -> None: ...
271
+ def __getstate__(self) -> typing.Any: ...
272
+ def __repr__(self) -> builtins.str: ...
273
+ def __eq__(self, other:typing.Any) -> builtins.bool: ...
274
+ def __ne__(self, other:typing.Any) -> builtins.bool: ...
275
+ def __lt__(self, other:typing.Any) -> builtins.bool: ...
276
+ def __le__(self, other:typing.Any) -> builtins.bool: ...
277
+ def __gt__(self, other:typing.Any) -> builtins.bool: ...
278
+ def __ge__(self, other:typing.Any) -> builtins.bool: ...
279
+ def __hash__(self) -> builtins.int: ...
280
+ def __add__(self, other:typing.Any) -> Decimal: ...
281
+ def __radd__(self, other:typing.Any) -> Decimal: ...
282
+ def __sub__(self, other:typing.Any) -> Decimal: ...
283
+ def __rsub__(self, other:typing.Any) -> Decimal: ...
284
+ def __mul__(self, other:typing.Any) -> Decimal: ...
285
+ def __rmul__(self, other:typing.Any) -> Decimal: ...
286
+ def __truediv__(self, other:typing.Any) -> Decimal: ...
287
+ def __rtruediv__(self, other:typing.Any) -> Decimal: ...
288
+ def __mod__(self, other:typing.Any) -> Decimal: ...
289
+ def __rmod__(self, other:typing.Any) -> Decimal: ...
290
+ def __pow__(self, exponent:typing.Any, modulo:typing.Any=None) -> Decimal: ...
291
+ def __rpow__(self, base:typing.Any, modulo:typing.Any=None) -> Decimal: ...
292
+ def __neg__(self) -> Decimal: ...
293
+ def __abs__(self) -> Decimal: ...
294
+ def __int__(self) -> builtins.int: ...
295
+ def __float__(self) -> builtins.float: ...
296
+
297
+ class DerivadexSMT:
298
+ r"""
299
+ Wrapped DerivaDEX Sparse Merkle Tree.
300
+ """
301
+ def all_book_orders_for_symbol(self, symbol:ProductSymbol) -> builtins.list[tuple[BookOrderKey, BookOrder]]:
302
+ r"""
303
+ Helper that returns the filtered list described by the method.
304
+ """
305
+ def all_positions_for_symbol(self, symbol:ProductSymbol) -> builtins.list[tuple[PositionKey, Position]]:
306
+ r"""
307
+ Helper that returns the filtered list described by the method.
308
+ """
309
+ def all_prices_for_symbol(self, symbol:ProductSymbol) -> builtins.list[tuple[PriceKey, Price]]:
310
+ r"""
311
+ Helper that returns the filtered list described by the method.
312
+ """
313
+ def all_leaves(self) -> builtins.list[tuple[H256, Item]]:
314
+ r"""
315
+ Helper that returns the filtered list described by the method.
316
+ """
317
+ def epoch_metadata(self, key:EpochMetadataKey) -> typing.Optional[EpochMetadata]:
318
+ r"""
319
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
320
+ """
321
+ def store_epoch_metadata(self, key:EpochMetadataKey, maybe_inner:typing.Optional[EpochMetadata]) -> H256:
322
+ r"""
323
+ Insert (`Some`) or delete (`None`) a leaf and return the new
324
+ SMT root hash.
325
+ """
326
+ def all_epoch_metadatas(self) -> builtins.list[tuple[EpochMetadataKey, EpochMetadata]]:
327
+ r"""
328
+ Return every item of this type currently stored in the tree.
329
+ """
330
+ def insurance_fund_contribution(self, key:InsuranceFundContributionKey) -> typing.Optional[InsuranceFundContribution]:
331
+ r"""
332
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
333
+ """
334
+ def store_insurance_fund_contribution(self, key:InsuranceFundContributionKey, maybe_inner:typing.Optional[InsuranceFundContribution]) -> H256:
335
+ r"""
336
+ Insert (`Some`) or delete (`None`) a leaf and return the new
337
+ SMT root hash.
338
+ """
339
+ def all_insurance_fund_contributions(self) -> builtins.list[tuple[InsuranceFundContributionKey, InsuranceFundContribution]]:
340
+ r"""
341
+ Return every item of this type currently stored in the tree.
342
+ """
343
+ def tradable_product(self, key:TradableProductKey) -> typing.Optional[TradableProduct]:
344
+ r"""
345
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
346
+ """
347
+ def store_tradable_product(self, key:TradableProductKey, maybe_inner:typing.Optional[TradableProduct]) -> H256:
348
+ r"""
349
+ Insert (`Some`) or delete (`None`) a leaf and return the new
350
+ SMT root hash.
351
+ """
352
+ def all_tradable_products(self) -> builtins.list[tuple[TradableProductKey, TradableProduct]]:
353
+ r"""
354
+ Return every item of this type currently stored in the tree.
355
+ """
356
+ def specs(self, key:SpecsKey) -> typing.Optional[Specs]:
357
+ r"""
358
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
359
+ """
360
+ def store_specs(self, key:SpecsKey, maybe_inner:typing.Optional[Specs]) -> H256:
361
+ r"""
362
+ Insert (`Some`) or delete (`None`) a leaf and return the new
363
+ SMT root hash.
364
+ """
365
+ def all_specs(self) -> builtins.list[tuple[SpecsKey, Specs]]:
366
+ r"""
367
+ Return every item of this type currently stored in the tree.
368
+ """
369
+ def signer(self, key:SignerKey) -> typing.Optional[Signer]:
370
+ r"""
371
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
372
+ """
373
+ def store_signer(self, key:SignerKey, maybe_inner:typing.Optional[Signer]) -> H256:
374
+ r"""
375
+ Insert (`Some`) or delete (`None`) a leaf and return the new
376
+ SMT root hash.
377
+ """
378
+ def all_signers(self) -> builtins.list[tuple[SignerKey, Signer]]:
379
+ r"""
380
+ Return every item of this type currently stored in the tree.
381
+ """
382
+ def stats(self, key:StatsKey) -> typing.Optional[Stats]:
383
+ r"""
384
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
385
+ """
386
+ def store_stats(self, key:StatsKey, maybe_inner:typing.Optional[Stats]) -> H256:
387
+ r"""
388
+ Insert (`Some`) or delete (`None`) a leaf and return the new
389
+ SMT root hash.
390
+ """
391
+ def all_stats(self) -> builtins.list[tuple[StatsKey, Stats]]:
392
+ r"""
393
+ Return every item of this type currently stored in the tree.
394
+ """
395
+ def insurance_fund(self, key:InsuranceFundKey) -> typing.Optional[InsuranceFund]:
396
+ r"""
397
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
398
+ """
399
+ def store_insurance_fund(self, key:InsuranceFundKey, maybe_inner:typing.Optional[InsuranceFund]) -> H256:
400
+ r"""
401
+ Insert (`Some`) or delete (`None`) a leaf and return the new
402
+ SMT root hash.
403
+ """
404
+ def all_insurance_funds(self) -> builtins.list[tuple[InsuranceFundKey, InsuranceFund]]:
405
+ r"""
406
+ Return every item of this type currently stored in the tree.
407
+ """
408
+ def price(self, key:PriceKey) -> typing.Optional[Price]:
409
+ r"""
410
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
411
+ """
412
+ def store_price(self, key:PriceKey, maybe_inner:typing.Optional[Price]) -> H256:
413
+ r"""
414
+ Insert (`Some`) or delete (`None`) a leaf and return the new
415
+ SMT root hash.
416
+ """
417
+ def all_prices(self) -> builtins.list[tuple[PriceKey, Price]]:
418
+ r"""
419
+ Return every item of this type currently stored in the tree.
420
+ """
421
+ def book_order(self, key:BookOrderKey) -> typing.Optional[BookOrder]:
422
+ r"""
423
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
424
+ """
425
+ def store_book_order(self, key:BookOrderKey, maybe_inner:typing.Optional[BookOrder]) -> H256:
426
+ r"""
427
+ Insert (`Some`) or delete (`None`) a leaf and return the new
428
+ SMT root hash.
429
+ """
430
+ def all_book_orders(self) -> builtins.list[tuple[BookOrderKey, BookOrder]]:
431
+ r"""
432
+ Return every item of this type currently stored in the tree.
433
+ """
434
+ def position(self, key:PositionKey) -> typing.Optional[Position]:
435
+ r"""
436
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
437
+ """
438
+ def store_position(self, key:PositionKey, maybe_inner:typing.Optional[Position]) -> H256:
439
+ r"""
440
+ Insert (`Some`) or delete (`None`) a leaf and return the new
441
+ SMT root hash.
442
+ """
443
+ def all_positions(self) -> builtins.list[tuple[PositionKey, Position]]:
444
+ r"""
445
+ Return every item of this type currently stored in the tree.
446
+ """
447
+ def strategy(self, key:StrategyKey) -> typing.Optional[Strategy]:
448
+ r"""
449
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
450
+ """
451
+ def store_strategy(self, key:StrategyKey, maybe_inner:typing.Optional[Strategy]) -> H256:
452
+ r"""
453
+ Insert (`Some`) or delete (`None`) a leaf and return the new
454
+ SMT root hash.
455
+ """
456
+ def all_strategies(self) -> builtins.list[tuple[StrategyKey, Strategy]]:
457
+ r"""
458
+ Return every item of this type currently stored in the tree.
459
+ """
460
+ def trader(self, key:TraderKey) -> typing.Optional[Trader]:
461
+ r"""
462
+ Fetch the item stored at `key`, or `None` if the leaf is empty.
463
+ """
464
+ def store_trader(self, key:TraderKey, maybe_inner:typing.Optional[Trader]) -> H256:
465
+ r"""
466
+ Insert (`Some`) or delete (`None`) a leaf and return the new
467
+ SMT root hash.
468
+ """
469
+ def all_traders(self) -> builtins.list[tuple[TraderKey, Trader]]:
470
+ r"""
471
+ Return every item of this type currently stored in the tree.
472
+ """
473
+ def __repr__(self) -> builtins.str: ...
474
+ def __new__(cls) -> DerivadexSMT:
475
+ r"""
476
+ Construct an empty in-memory SMT with a fresh root.
477
+ """
478
+ @classmethod
479
+ def from_genesis(cls, _cls:type, insurance_fund_cap:Balance, ddx_fee_pool:Decimal, specs:typing.Any, current_time:datetime.datetime) -> DerivadexSMT:
480
+ r"""
481
+ Build the genesis SMT, taking `current_time` into account for futures.
482
+ """
483
+ def root(self) -> H256:
484
+ r"""
485
+ Current SMT root hash.
486
+ """
487
+ def merkle_proof(self, keys:typing.Sequence[H256]) -> MerkleProof:
488
+ r"""
489
+ Generate a compiled Merkle proof covering all provided leaf `keys`.
490
+ """
491
+ def store_item_by_key(self, key:H256, maybe_inner:typing.Optional[Item]) -> H256:
492
+ r"""
493
+ Insert (`Some`) or delete (`None`) a leaf at `key` and return the
494
+ updated tree root hash.
495
+ """
496
+ def __deepcopy__(self, _memo:dict) -> DerivadexSMT: ...
497
+
498
+ class EpochMetadata:
499
+ r"""
500
+ Metadata about an epoch that has been transitioned.
501
+ """
502
+ ddx_fee_pool: Decimal
503
+ r"""
504
+ The DDX fee pool. This represents the total DDX fees collected in this epoch and are
505
+ distributed among custodians during a valid checkpoint.
506
+ """
507
+ next_book_ordinals: builtins.dict[ProductSymbol, builtins.int]
508
+ r"""
509
+ The next book ordinals for all of the active markets. This mapping
510
+ allows follower nodes to reliably generate the market index from the
511
+ sparse merkle tree. The ordinals are logged at the end of the epoch and are None if this is
512
+ the current epoch.
513
+ """
514
+ def __new__(cls, ddx_fee_pool:Decimal, next_book_ordinals:typing.Mapping[ProductSymbol, builtins.int]) -> EpochMetadata: ...
515
+ @classmethod
516
+ def default(cls, _cls:type) -> EpochMetadata:
517
+ r"""
518
+ Return empty `EpochMetadata` with zero fee pool and no order ordinals.
519
+ """
520
+ def __repr__(self) -> builtins.str: ...
521
+ def __deepcopy__(self, _memo:dict) -> EpochMetadata: ...
522
+ def as_item(self) -> Item:
523
+ r"""
524
+ Wrap this concrete structure into the generic [`Item`] enum.
525
+ """
526
+ @classmethod
527
+ def from_item(cls, _cls:type, item:Item) -> EpochMetadata:
528
+ r"""
529
+ Down-cast a generic [`Item`] into this concrete type.
530
+ """
531
+ def abi_encoded_value(self) -> builtins.bytes:
532
+ r"""
533
+ ABI-encode this value.
534
+ """
535
+ @classmethod
536
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
537
+ r"""
538
+ Decode bytes back into an [`Item`] of this concrete type.
539
+ """
540
+ def is_void(self) -> builtins.bool:
541
+ r"""
542
+ `true` when this value represents the special *void* marker
543
+ used to delete a leaf from the SMT.
544
+ """
545
+
546
+ class EpochMetadataKey:
547
+ epoch_id: builtins.int
548
+ def __new__(cls, epoch_id:builtins.int) -> EpochMetadataKey: ...
549
+ def __repr__(self) -> builtins.str: ...
550
+ def __deepcopy__(self, _memo:dict) -> EpochMetadataKey: ...
551
+ def encode_key(self) -> H256:
552
+ r"""
553
+ Encode this state-key into the 32-byte format used on-chain.
554
+ """
555
+ @classmethod
556
+ def decode_key(cls, _cls:type, value:H256) -> EpochMetadataKey:
557
+ r"""
558
+ Decode a previously-encoded key back into its strongly-typed form.
559
+ """
560
+
561
+ class H256:
562
+ r"""
563
+ Wrapped sparse_merkle_tree::H256.
564
+ """
565
+ @classmethod
566
+ def from_bytes(cls, _cls:type, b:builtins.bytes) -> H256:
567
+ r"""
568
+ Construct an `H256` from a 32-byte buffer passed from Python.
569
+ Raises `H256Error` when the supplied slice is not exactly 32 bytes long.
570
+ """
571
+ def as_bytes(self) -> builtins.bytes:
572
+ r"""
573
+ Return the underlying 32-byte value as an immutable `bytes`/`memoryview`.
574
+ """
575
+ @staticmethod
576
+ def zero() -> H256:
577
+ r"""
578
+ Return a new zero hash (all bits set to 0).
579
+ """
580
+ def is_zero(self) -> builtins.bool:
581
+ r"""
582
+ `true` if this value equals the zero hash.
583
+ """
584
+ def get_bit(self, i:builtins.int) -> builtins.bool:
585
+ r"""
586
+ Return the bit at position `i` (0 = most-significant bit).
587
+ """
588
+ def set_bit(self, i:builtins.int) -> None:
589
+ r"""
590
+ Set the bit at position `i` to `1`.
591
+ """
592
+ def clear_bit(self, i:builtins.int) -> None:
593
+ r"""
594
+ Clear the bit at position `i` (set it to `0`).
595
+ """
596
+ def fork_height(self, key:H256) -> builtins.int:
597
+ r"""
598
+ Return the length (in bits) of the common prefix between this key and `key`.
599
+ """
600
+ def parent_path(self, height:builtins.int) -> H256:
601
+ r"""
602
+ Return a new key that keeps the first `height` bits of this key
603
+ (i.e. the path of the parent node at that height).
604
+ """
605
+ def copy_bits(self, start:builtins.int) -> H256:
606
+ r"""
607
+ Copy the suffix of this key starting at bit `start` into a new `H256`.
608
+ """
609
+ def __setstate__(self, state:typing.Any) -> None: ...
610
+ def __getstate__(self) -> typing.Any: ...
611
+ def __repr__(self) -> builtins.str: ...
612
+ def __str__(self) -> builtins.str: ...
613
+
614
+ class IndexFundPerpetual:
615
+ allocation: builtins.dict[builtins.str, Decimal]
616
+ rebalance_interval: builtins.int
617
+ initial_index_price: Decimal
618
+ tick_size: Decimal
619
+ max_order_notional: Decimal
620
+ max_taker_price_deviation: Decimal
621
+ min_order_size: Decimal
622
+ def __new__(cls, **kwds) -> IndexFundPerpetual: ...
623
+
624
+ class IndexPrice:
625
+ r"""
626
+ An index price is the price update of an instrument coming from the price feed.
627
+
628
+ It is signed by the price feed's enclave.
629
+ """
630
+ symbol: ProductSymbol
631
+ r"""
632
+ Symbol of the instrument
633
+ """
634
+ price: Decimal
635
+ r"""
636
+ Current market price in the source exchange
637
+ """
638
+ prev_price: Decimal
639
+ r"""
640
+ The previous price update. Useful to prove that no prices were skipped.
641
+ """
642
+ metadata: PriceMetadata
643
+ r"""
644
+ Additional metadata required by the price feed to initialize
645
+ """
646
+ timestamp: builtins.int
647
+ json: typing.Any
648
+ def __new__(cls, symbol:ProductSymbol, price:Decimal, prev_price:Decimal, metadata:PriceMetadata, timestamp:builtins.int) -> IndexPrice: ...
649
+ def hash(self) -> builtins.str:
650
+ r"""
651
+ Compute the hash of this index price request.
652
+ """
653
+ def __repr__(self) -> builtins.str: ...
654
+
655
+ class InsuranceFund:
656
+ def __len__(self) -> builtins.int: ...
657
+ def __getitem__(self, key:TokenSymbol) -> Decimal: ...
658
+ def __setitem__(self, key:TokenSymbol, value:Decimal) -> None: ...
659
+ def __new__(cls, amount:Decimal, symbol:TokenSymbol) -> InsuranceFund:
660
+ r"""
661
+ Construct a balance initialized with `amount` of `symbol`.
662
+ """
663
+ @classmethod
664
+ def default(cls, cls:type) -> InsuranceFund:
665
+ r"""
666
+ Return an empty balance with zero for every token.
667
+ """
668
+ @classmethod
669
+ def new_from_many(cls, cls:type, amounts:typing.Mapping[TokenSymbol, Decimal]) -> InsuranceFund:
670
+ r"""
671
+ Construct a balance from a mapping of token amounts.
672
+ """
673
+ def total_value(self) -> Decimal:
674
+ r"""
675
+ Total value of this balance, obtained by summing
676
+ every token amount. This will be either in USD or DDX, depending on
677
+ its contents.
678
+ """
679
+ def amounts(self) -> builtins.list[Decimal]:
680
+ r"""
681
+ Raw amounts ordered by the canonical token list.
682
+ """
683
+ def __repr__(self) -> builtins.str: ...
684
+ def __deepcopy__(self, _memo:dict) -> InsuranceFund: ...
685
+ def as_item(self) -> Item:
686
+ r"""
687
+ Wrap this concrete structure into the generic [`Item`] enum.
688
+ """
689
+ @classmethod
690
+ def from_item(cls, _cls:type, item:Item) -> InsuranceFund:
691
+ r"""
692
+ Down-cast a generic [`Item`] into this concrete type.
693
+ """
694
+ def abi_encoded_value(self) -> builtins.bytes:
695
+ r"""
696
+ ABI-encode this value.
697
+ """
698
+ @classmethod
699
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
700
+ r"""
701
+ Decode bytes back into an [`Item`] of this concrete type.
702
+ """
703
+ def is_void(self) -> builtins.bool:
704
+ r"""
705
+ `true` when this value represents the special *void* marker
706
+ used to delete a leaf from the SMT.
707
+ """
708
+
709
+ class InsuranceFundContribution:
710
+ r"""
711
+ An insurance fund contribution
712
+ """
713
+ avail_balance: Balance
714
+ r"""
715
+ Total contribution to the insurance fund, minus any withdrawals
716
+ """
717
+ locked_balance: Balance
718
+ r"""
719
+ Balance locked for withdrawal
720
+ """
721
+ def __new__(cls, avail_balance:Balance, locked_balance:Balance) -> InsuranceFundContribution: ...
722
+ @classmethod
723
+ def default(cls, _cls:type) -> InsuranceFundContribution:
724
+ r"""
725
+ Return an empty `InsuranceFundContribution` with zero balances.
726
+ """
727
+ def update_avail_balance(self, symbol:TokenSymbol, amount:Decimal) -> Balance:
728
+ r"""
729
+ Return a copy of `avail_balance` with `symbol` set to `amount`.
730
+ """
731
+ def update_locked_balance(self, symbol:TokenSymbol, amount:Decimal) -> Balance:
732
+ r"""
733
+ Return a copy of `locked_balance` with `symbol` set to `amount`.
734
+ """
735
+ def __repr__(self) -> builtins.str: ...
736
+ def __deepcopy__(self, _memo:dict) -> InsuranceFundContribution: ...
737
+ def as_item(self) -> Item:
738
+ r"""
739
+ Wrap this concrete structure into the generic [`Item`] enum.
740
+ """
741
+ @classmethod
742
+ def from_item(cls, _cls:type, item:Item) -> InsuranceFundContribution:
743
+ r"""
744
+ Down-cast a generic [`Item`] into this concrete type.
745
+ """
746
+ def abi_encoded_value(self) -> builtins.bytes:
747
+ r"""
748
+ ABI-encode this value.
749
+ """
750
+ @classmethod
751
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
752
+ r"""
753
+ Decode bytes back into an [`Item`] of this concrete type.
754
+ """
755
+ def is_void(self) -> builtins.bool:
756
+ r"""
757
+ `true` when this value represents the special *void* marker
758
+ used to delete a leaf from the SMT.
759
+ """
760
+
761
+ class InsuranceFundContributionKey:
762
+ def __repr__(self) -> builtins.str: ...
763
+ def __deepcopy__(self, _memo:dict) -> InsuranceFundContributionKey: ...
764
+ def encode_key(self) -> H256:
765
+ r"""
766
+ Encode this state-key into the 32-byte format used on-chain.
767
+ """
768
+ @classmethod
769
+ def decode_key(cls, _cls:type, value:H256) -> InsuranceFundContributionKey:
770
+ r"""
771
+ Decode a previously-encoded key back into its strongly-typed form.
772
+ """
773
+ def __new__(cls, inner:builtins.str) -> InsuranceFundContributionKey: ...
774
+
775
+ class InsuranceFundKey:
776
+ def __new__(cls) -> InsuranceFundKey: ...
777
+ def __repr__(self) -> builtins.str: ...
778
+ def __deepcopy__(self, _memo:dict) -> InsuranceFundKey: ...
779
+ def encode_key(self) -> H256:
780
+ r"""
781
+ Encode this state-key into the 32-byte format used on-chain.
782
+ """
783
+ @classmethod
784
+ def decode_key(cls, _cls:type, value:H256) -> InsuranceFundKey:
785
+ r"""
786
+ Decode a previously-encoded key back into its strongly-typed form.
787
+ """
788
+
789
+ class Item:
790
+ def __repr__(self) -> builtins.str: ...
791
+ def item_kind(self) -> ItemKind:
792
+ r"""
793
+ Return this item's [`ItemKind`] discriminant.
794
+ """
795
+ def abi_encoded_value(self) -> builtins.bytes:
796
+ r"""
797
+ ABI-encode the wrapped value for hashing / storage.
798
+ """
799
+ @classmethod
800
+ def abi_decode_value_into_item(cls, cls:type, kind:ItemKind, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
801
+ r"""
802
+ Decode the bytes produced by `abi_encoded_value()` back into
803
+ an [`Item`] of the supplied kind.
804
+ """
805
+ @classmethod
806
+ def decode_key(cls, cls:type, kind:ItemKind, encoded_key:H256) -> typing.Any:
807
+ r"""
808
+ Decode a 32-byte SMT key into its strongly-typed form for
809
+ the provided item kind.
810
+ """
811
+
812
+ class MerkleProof:
813
+ def __repr__(self) -> builtins.str: ...
814
+ def as_bytes(self) -> builtins.bytes:
815
+ r"""
816
+ Return the compiled proof as a raw byte slice suitable for
817
+ on-chain verification.
818
+ """
819
+
820
+ class MintPriceCheckpoint:
821
+ time_value: builtins.int
822
+ json: typing.Any
823
+ def __new__(cls, time_value:builtins.int) -> MintPriceCheckpoint: ...
824
+ def __repr__(self) -> builtins.str: ...
825
+
826
+ class ModifyOrderIntent:
827
+ r"""
828
+ Modify order intents are intents that modify the original order details of a specific order
829
+ identified by its order hash.
830
+
831
+ This is identical to a cancel and a re-placing of the new order,
832
+ the only difference from doing them separately being that the execution is atomic when executed
833
+ as a ModifyOrderIntent.
834
+ """
835
+ order_hash: builtins.str
836
+ r"""
837
+ Order hash of the order to modify
838
+ """
839
+ symbol: ProductSymbol
840
+ r"""
841
+ Symbol of the market
842
+ """
843
+ strategy: builtins.str
844
+ r"""
845
+ Strategy Id (label)
846
+ """
847
+ side: OrderSide
848
+ r"""
849
+ Side: 0-Long, 1-Short
850
+ """
851
+ order_type: OrderType
852
+ r"""
853
+ 0-Limit, 1-Market, 2-Stop-Limit
854
+ """
855
+ nonce: builtins.str
856
+ r"""
857
+ A salt for uniqueness of the EIP-712 hash function. May optionally have business meaning to the client.
858
+ """
859
+ amount: Decimal
860
+ r"""
861
+ Order amount
862
+ """
863
+ price: Decimal
864
+ r"""
865
+ Order price. For a limit order, it is the limit price.
866
+ """
867
+ stop_price: Decimal
868
+ r"""
869
+ Stop price. Set to 0 if the order is not a Stop-Limit.
870
+ """
871
+ session_key_signature: typing.Optional[builtins.str]
872
+ r"""
873
+ EIP-191 signature of the 1CT session public key
874
+ """
875
+ signature: builtins.str
876
+ r"""
877
+ EIP-712 signature of the order intent attributes
878
+ """
879
+ json: typing.Any
880
+ def __new__(cls, order_hash:builtins.str, symbol:ProductSymbol, strategy:builtins.str, side:OrderSide, order_type:OrderType, nonce:builtins.str, amount:Decimal, price:Decimal, stop_price:Decimal, session_key_signature:typing.Optional[builtins.str], signature:typing.Optional[builtins.str]=None) -> ModifyOrderIntent: ...
881
+ def hash(self) -> builtins.str:
882
+ r"""
883
+ Compute the hash of this modify order intent.
884
+ """
885
+ def __repr__(self) -> builtins.str: ...
886
+ def hash_eip712(self, message_metadata:typing.Optional[tuple[builtins.int, builtins.str]]=None) -> builtins.str:
887
+ r"""
888
+ Compute the EIP-712 digest for this intent.
889
+ Passing `message_metadata=(chain_id, verifying_contract)`
890
+ overrides the default values used in the hash.
891
+ """
892
+ def recover_signer(self) -> tuple[builtins.str, builtins.str]:
893
+ r"""
894
+ Recover the `(eip712_hash, trader_address)` that signed
895
+ this intent.
896
+ """
897
+
898
+ class OperatorContext:
899
+ r"""
900
+ Holds application-layer environment information
901
+
902
+ Information in here as analogous to something like the operating system locale, but at the application layer.
903
+ In the git application for instance, such context includes name and email.
904
+ Storing this information globally saves us the noise of repeating the same informational arguments
905
+ in multiple functions throughout the application.
906
+
907
+ This does NOT include logic inputs of individual units like configuration parameters (like db credentials),
908
+ business rules (like epoch sizes), etc. We capture these in `TrustedContext` and `NodeContext`, and
909
+ pass them explicitly to individual components (in the name of functional testability).
910
+
911
+ This information does not impact logic routes (testability)
912
+ """
913
+ contract_address: builtins.str
914
+ chain_id: builtins.int
915
+
916
+ class OrderIntent:
917
+ r"""
918
+ Order intents are meta-transactions signed by traders Ethereum wallets and submitted to operators.
919
+
920
+ They come in through the API, signed by their maker. We verify that:
921
+
922
+ a) the signatures recovers the `trader_address`
923
+ b) the maker has enough collateral to be solvent when the order gets filled
924
+
925
+ Following verification, we match an order intent against the order book. This may result in
926
+ fill(s) or posting into the order book depending on the matches found.
927
+ """
928
+ symbol: ProductSymbol
929
+ r"""
930
+ Symbol of the market
931
+ """
932
+ strategy: builtins.str
933
+ r"""
934
+ Strategy Id (label)
935
+ """
936
+ side: OrderSide
937
+ r"""
938
+ Side: 0-Long, 1-Short
939
+ """
940
+ order_type: OrderType
941
+ r"""
942
+ 0-Limit, 1-Market, 2-Stop-Limit
943
+ """
944
+ nonce: builtins.str
945
+ r"""
946
+ A salt for uniqueness of the EIP-712 hash function. May optionally have business meaning to the client.
947
+ """
948
+ amount: Decimal
949
+ r"""
950
+ Order amount
951
+ """
952
+ price: Decimal
953
+ r"""
954
+ Order price. For a limit order, it is the limit price.
955
+ """
956
+ stop_price: Decimal
957
+ r"""
958
+ Stop price. Set to 0 if the order is not a Stop-Limit.
959
+ """
960
+ session_key_signature: typing.Optional[builtins.str]
961
+ r"""
962
+ EIP-191 signature of the 1CT session public key
963
+ """
964
+ signature: builtins.str
965
+ r"""
966
+ EIP-712 signature of the order intent attributes
967
+ """
968
+ json: typing.Any
969
+ def __new__(cls, symbol:ProductSymbol, strategy:builtins.str, side:OrderSide, order_type:OrderType, nonce:builtins.str, amount:Decimal, price:Decimal, stop_price:Decimal, session_key_signature:typing.Optional[builtins.str], signature:typing.Optional[builtins.str]=None) -> OrderIntent: ...
970
+ def hash(self) -> builtins.str:
971
+ r"""
972
+ Compute the hash of this order intent.
973
+ """
974
+ def __repr__(self) -> builtins.str: ...
975
+ def hash_eip712(self, message_metadata:typing.Optional[tuple[builtins.int, builtins.str]]=None) -> builtins.str:
976
+ r"""
977
+ Compute the EIP-712 digest for this intent.
978
+ Passing `message_metadata=(chain_id, verifying_contract)`
979
+ overrides the default values used in the hash.
980
+ """
981
+ def recover_signer(self) -> tuple[builtins.str, builtins.str]:
982
+ r"""
983
+ Recover the `(eip712_hash, trader_address)` that signed
984
+ this intent.
985
+ """
986
+
987
+ class OrderType:
988
+ def __repr__(self) -> builtins.str: ...
989
+
990
+ class Position:
991
+ r"""
992
+ An individual position held in an strategy
993
+ """
994
+ side: PositionSide
995
+ r"""
996
+ The position side: Long = 0, Short = 1
997
+ """
998
+ balance: Decimal
999
+ r"""
1000
+ The position size denominated in the same unit as the underlying
1001
+ """
1002
+ avg_entry_price: Decimal
1003
+ r"""
1004
+ The average entry price (updated when adding to the position)
1005
+ """
1006
+ def __new__(cls, side:PositionSide, balance:Decimal, avg_entry_price:Decimal) -> Position: ...
1007
+ @classmethod
1008
+ def default(cls, _cls:type) -> Position:
1009
+ r"""
1010
+ Return an empty `Position` with zero balance and no entry price.
1011
+ """
1012
+ def bankruptcy_price(self, mark_price:Decimal, account_total_value:Decimal) -> Decimal:
1013
+ r"""
1014
+ Bankruptcy price at which margin would be exhausted.
1015
+ """
1016
+ def unrealized_pnl(self, price:Decimal) -> Decimal:
1017
+ r"""
1018
+ Unrealized profit and loss at the specified `price`.
1019
+ """
1020
+ def avg_pnl(self, price:Decimal) -> Decimal:
1021
+ r"""
1022
+ Average P&L per contract at the specified `price`.
1023
+ """
1024
+ def increase(self, price:Decimal, amount:Decimal) -> tuple[Position, Decimal]:
1025
+ r"""
1026
+ Increase position size by `amount` at `price`; returns the new
1027
+ position together with any realized P&L.
1028
+ """
1029
+ def decrease(self, price:Decimal, amount:Decimal) -> tuple[Position, Decimal]:
1030
+ r"""
1031
+ Decrease position size by `amount` at `price`; returns the new
1032
+ position and realized P&L.
1033
+ """
1034
+ def cross_over(self, price:Decimal, amount:Decimal) -> tuple[Position, Decimal]:
1035
+ r"""
1036
+ Reverse side by `amount` at `price`; returns updated position and P&L.
1037
+ """
1038
+ def __repr__(self) -> builtins.str: ...
1039
+ def __deepcopy__(self, _memo:dict) -> Position: ...
1040
+ def as_item(self) -> Item:
1041
+ r"""
1042
+ Wrap this concrete structure into the generic [`Item`] enum.
1043
+ """
1044
+ @classmethod
1045
+ def from_item(cls, _cls:type, item:Item) -> Position:
1046
+ r"""
1047
+ Down-cast a generic [`Item`] into this concrete type.
1048
+ """
1049
+ def abi_encoded_value(self) -> builtins.bytes:
1050
+ r"""
1051
+ ABI-encode this value.
1052
+ """
1053
+ @classmethod
1054
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
1055
+ r"""
1056
+ Decode bytes back into an [`Item`] of this concrete type.
1057
+ """
1058
+ def is_void(self) -> builtins.bool:
1059
+ r"""
1060
+ `true` when this value represents the special *void* marker
1061
+ used to delete a leaf from the SMT.
1062
+ """
1063
+
1064
+ class PositionKey:
1065
+ trader_address: builtins.str
1066
+ strategy_id_hash: builtins.str
1067
+ symbol: ProductSymbol
1068
+ def __new__(cls, trader_address:builtins.str, strategy_id_hash:builtins.str, symbol:ProductSymbol) -> PositionKey: ...
1069
+ def as_strategy_key(self) -> StrategyKey:
1070
+ r"""
1071
+ Convert this position key into its owner `StrategyKey`.
1072
+ """
1073
+ def __repr__(self) -> builtins.str: ...
1074
+ def __deepcopy__(self, _memo:dict) -> PositionKey: ...
1075
+ def encode_key(self) -> H256:
1076
+ r"""
1077
+ Encode this state-key into the 32-byte format used on-chain.
1078
+ """
1079
+ @classmethod
1080
+ def decode_key(cls, _cls:type, value:H256) -> PositionKey:
1081
+ r"""
1082
+ Decode a previously-encoded key back into its strongly-typed form.
1083
+ """
1084
+
1085
+ class Price:
1086
+ r"""
1087
+ A price value (used for funding and liquidations)
1088
+ """
1089
+ index_price: Decimal
1090
+ r"""
1091
+ The index price number coming from a price feed
1092
+ """
1093
+ mark_price_metadata: MarkPriceMetadata
1094
+ ordinal: builtins.int
1095
+ time_value: builtins.int
1096
+ mark_price: Decimal
1097
+ def __new__(cls, index_price:Decimal, mark_price_metadata:MarkPriceMetadata, ordinal:builtins.int, time_value:builtins.int) -> Price: ...
1098
+ def __repr__(self) -> builtins.str: ...
1099
+ def __deepcopy__(self, _memo:dict) -> Price: ...
1100
+ def as_item(self) -> Item:
1101
+ r"""
1102
+ Wrap this concrete structure into the generic [`Item`] enum.
1103
+ """
1104
+ @classmethod
1105
+ def from_item(cls, _cls:type, item:Item) -> Price:
1106
+ r"""
1107
+ Down-cast a generic [`Item`] into this concrete type.
1108
+ """
1109
+ def abi_encoded_value(self) -> builtins.bytes:
1110
+ r"""
1111
+ ABI-encode this value.
1112
+ """
1113
+ @classmethod
1114
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
1115
+ r"""
1116
+ Decode bytes back into an [`Item`] of this concrete type.
1117
+ """
1118
+ def is_void(self) -> builtins.bool:
1119
+ r"""
1120
+ `true` when this value represents the special *void* marker
1121
+ used to delete a leaf from the SMT.
1122
+ """
1123
+
1124
+ class PriceKey:
1125
+ symbol: ProductSymbol
1126
+ index_price_hash: builtins.str
1127
+ def __new__(cls, symbol:ProductSymbol, index_price_hash:builtins.str) -> PriceKey: ...
1128
+ def __repr__(self) -> builtins.str: ...
1129
+ def __deepcopy__(self, _memo:dict) -> PriceKey: ...
1130
+ def encode_key(self) -> H256:
1131
+ r"""
1132
+ Encode this state-key into the 32-byte format used on-chain.
1133
+ """
1134
+ @classmethod
1135
+ def decode_key(cls, _cls:type, value:H256) -> PriceKey:
1136
+ r"""
1137
+ Decode a previously-encoded key back into its strongly-typed form.
1138
+ """
1139
+
1140
+ class ProductSymbol:
1141
+ def __new__(cls, symbol:builtins.str) -> ProductSymbol:
1142
+ r"""
1143
+ Construct a product symbol from a string representation such as `"ETHP"`.
1144
+ Returns an error if the supplied string cannot be parsed.
1145
+ """
1146
+ def __deepcopy__(self, _memo:dict) -> ProductSymbol: ...
1147
+ def __repr__(self) -> builtins.str: ...
1148
+ def __len__(self) -> builtins.int: ...
1149
+ def is_perpetual(self) -> builtins.bool:
1150
+ r"""
1151
+ Return `true` when this symbol represents a perpetual contract.
1152
+ """
1153
+ def is_future(self) -> builtins.bool:
1154
+ r"""
1155
+ Return `true` when this symbol corresponds to a fixed-expiry future.
1156
+ """
1157
+ def futures_quarter(self) -> typing.Optional[Quarter]:
1158
+ r"""
1159
+ For futures symbols, return the associated `Quarter`; otherwise `None`.
1160
+ """
1161
+ def price_metadata(self) -> PriceMetadata:
1162
+ r"""
1163
+ Construct a `PriceMetadata` value appropriate for this product type.
1164
+ """
1165
+
1166
+ class ProfileUpdateIntent:
1167
+ nonce: builtins.str
1168
+ r"""
1169
+ A salt for uniqueness of the EIP-712 hash function. May optionally have business meaning to the client.
1170
+ """
1171
+ pay_fees_in_ddx: builtins.bool
1172
+ r"""
1173
+ Sets the flag in the trader profile
1174
+ """
1175
+ signature: builtins.str
1176
+ r"""
1177
+ EIP-712 signature of the order intent attributes
1178
+ """
1179
+ json: typing.Any
1180
+ def __new__(cls, nonce:builtins.str, pay_fees_in_ddx:builtins.bool, signature:typing.Optional[builtins.str]=None) -> ProfileUpdateIntent: ...
1181
+ def __repr__(self) -> builtins.str: ...
1182
+ def hash_eip712(self, message_metadata:typing.Optional[tuple[builtins.int, builtins.str]]=None) -> builtins.str:
1183
+ r"""
1184
+ Compute the EIP-712 digest for this intent.
1185
+ Passing `message_metadata=(chain_id, verifying_contract)`
1186
+ overrides the default values used in the hash.
1187
+ """
1188
+ def recover_signer(self) -> tuple[builtins.str, builtins.str]:
1189
+ r"""
1190
+ Recover the `(eip712_hash, trader_address)` that signed
1191
+ this intent.
1192
+ """
1193
+
1194
+ class QuarterlyExpiryFuture:
1195
+ r"""
1196
+ Quarterly expiry futures are contracts that expire at a month 28-day basis.
1197
+
1198
+ This only include attributes common to all quarterly expiry futures.
1199
+ """
1200
+ underlying: builtins.str
1201
+ tick_size: Decimal
1202
+ max_order_notional: Decimal
1203
+ max_taker_price_deviation: Decimal
1204
+ min_order_size: Decimal
1205
+ def __new__(cls, **kwds) -> QuarterlyExpiryFuture: ...
1206
+
1207
+ class SettlementAction:
1208
+ @classmethod
1209
+ def FuturesExpiry(cls, _cls:type, quarter:Quarter) -> SettlementAction:
1210
+ r"""
1211
+ Settlement action representing the expiry of a quarterly future.
1212
+ """
1213
+ def futures_quarter(self) -> typing.Optional[Quarter]:
1214
+ r"""
1215
+ For futures-expiry actions, return the quarter of the quarterly expiry future.
1216
+ """
1217
+ def __repr__(self) -> builtins.str: ...
1218
+
1219
+ class Signer:
1220
+ def __new__(cls, inner:builtins.str) -> Signer:
1221
+ r"""
1222
+ Construct a new `Signer` identified by `inner` release hash.
1223
+ """
1224
+ def __repr__(self) -> builtins.str: ...
1225
+ def __deepcopy__(self, _memo:dict) -> Signer: ...
1226
+ def as_item(self) -> Item:
1227
+ r"""
1228
+ Wrap this concrete structure into the generic [`Item`] enum.
1229
+ """
1230
+ @classmethod
1231
+ def from_item(cls, _cls:type, item:Item) -> Signer:
1232
+ r"""
1233
+ Down-cast a generic [`Item`] into this concrete type.
1234
+ """
1235
+ def abi_encoded_value(self) -> builtins.bytes:
1236
+ r"""
1237
+ ABI-encode this value.
1238
+ """
1239
+ @classmethod
1240
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
1241
+ r"""
1242
+ Decode bytes back into an [`Item`] of this concrete type.
1243
+ """
1244
+ def is_void(self) -> builtins.bool:
1245
+ r"""
1246
+ `true` when this value represents the special *void* marker
1247
+ used to delete a leaf from the SMT.
1248
+ """
1249
+
1250
+ class SignerKey:
1251
+ def __repr__(self) -> builtins.str: ...
1252
+ def __deepcopy__(self, _memo:dict) -> SignerKey: ...
1253
+ def encode_key(self) -> H256:
1254
+ r"""
1255
+ Encode this state-key into the 32-byte format used on-chain.
1256
+ """
1257
+ @classmethod
1258
+ def decode_key(cls, _cls:type, value:H256) -> SignerKey:
1259
+ r"""
1260
+ Decode a previously-encoded key back into its strongly-typed form.
1261
+ """
1262
+ def __new__(cls, inner:builtins.str) -> SignerKey: ...
1263
+
1264
+ class SingleNamePerpetual:
1265
+ r"""
1266
+ A set of specification about each market (aka derivative contracts)
1267
+ """
1268
+ underlying: builtins.str
1269
+ tick_size: Decimal
1270
+ max_order_notional: Decimal
1271
+ max_taker_price_deviation: Decimal
1272
+ min_order_size: Decimal
1273
+ def __new__(cls, **kwds) -> SingleNamePerpetual: ...
1274
+
1275
+ class Specs:
1276
+ def __new__(cls, inner:builtins.str) -> Specs:
1277
+ r"""
1278
+ Wrapped `SpecsExpr`.
1279
+ """
1280
+ def as_product_specs(self, specs_kind:SpecsKind) -> ProductSpecs:
1281
+ r"""
1282
+ Convert this expression into concrete `ProductSpecs` of the requested kind.
1283
+ """
1284
+ def __repr__(self) -> builtins.str: ...
1285
+ def __deepcopy__(self, _memo:dict) -> Specs: ...
1286
+ def as_item(self) -> Item:
1287
+ r"""
1288
+ Wrap this concrete structure into the generic [`Item`] enum.
1289
+ """
1290
+ @classmethod
1291
+ def from_item(cls, _cls:type, item:Item) -> Specs:
1292
+ r"""
1293
+ Down-cast a generic [`Item`] into this concrete type.
1294
+ """
1295
+ def abi_encoded_value(self) -> builtins.bytes:
1296
+ r"""
1297
+ ABI-encode this value.
1298
+ """
1299
+ @classmethod
1300
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
1301
+ r"""
1302
+ Decode bytes back into an [`Item`] of this concrete type.
1303
+ """
1304
+ def is_void(self) -> builtins.bool:
1305
+ r"""
1306
+ `true` when this value represents the special *void* marker
1307
+ used to delete a leaf from the SMT.
1308
+ """
1309
+
1310
+ class SpecsKey:
1311
+ r"""
1312
+ Common key for all specs kind.
1313
+ """
1314
+ kind: SpecsKind
1315
+ name: builtins.str
1316
+ r"""
1317
+ Defined by convention associated with the specs kind.
1318
+ At the time of writing, the naming conventions are:
1319
+
1320
+ - `SingleNamePerpetual`: The product market symbol for the single name perpetuals in our universe (e.g. ETHP, BTCP).
1321
+ - `MarketGateway`: The host name (e.g. api.binance.com, api.exchange.coinbase.com).
1322
+ """
1323
+ def __new__(cls, kind:SpecsKind, name:builtins.str) -> SpecsKey: ...
1324
+ def current_tradable_products(self, current_time:datetime.datetime) -> builtins.list[TradableProductKey]:
1325
+ r"""
1326
+ List the currently tradable products that are live at `current_time`.
1327
+ """
1328
+ def has_lifecycle(self) -> typing.Optional[builtins.bool]:
1329
+ r"""
1330
+ Return whether this specs has a lifecycle constraint.
1331
+ """
1332
+ def __repr__(self) -> builtins.str: ...
1333
+ def __deepcopy__(self, _memo:dict) -> SpecsKey: ...
1334
+ def encode_key(self) -> H256:
1335
+ r"""
1336
+ Encode this state-key into the 32-byte format used on-chain.
1337
+ """
1338
+ @classmethod
1339
+ def decode_key(cls, _cls:type, value:H256) -> SpecsKey:
1340
+ r"""
1341
+ Decode a previously-encoded key back into its strongly-typed form.
1342
+ """
1343
+
1344
+ class Stats:
1345
+ r"""
1346
+ A trader statistics value. This is used to store verified data like trade
1347
+ volume data for trade mining.
1348
+ """
1349
+ maker_volume: Decimal
1350
+ r"""
1351
+ The maker volume of the trader during this trade mining period
1352
+ """
1353
+ taker_volume: Decimal
1354
+ r"""
1355
+ The taker volume of the trader during this trade mining period
1356
+ """
1357
+ def __new__(cls, maker_volume:Decimal, taker_volume:Decimal) -> Stats: ...
1358
+ @classmethod
1359
+ def default(cls, _cls:type) -> Stats:
1360
+ r"""
1361
+ Return a `Stats` structure with all counters set to zero.
1362
+ """
1363
+ def __repr__(self) -> builtins.str: ...
1364
+ def __deepcopy__(self, _memo:dict) -> Stats: ...
1365
+ def as_item(self) -> Item:
1366
+ r"""
1367
+ Wrap this concrete structure into the generic [`Item`] enum.
1368
+ """
1369
+ @classmethod
1370
+ def from_item(cls, _cls:type, item:Item) -> Stats:
1371
+ r"""
1372
+ Down-cast a generic [`Item`] into this concrete type.
1373
+ """
1374
+ def abi_encoded_value(self) -> builtins.bytes:
1375
+ r"""
1376
+ ABI-encode this value.
1377
+ """
1378
+ @classmethod
1379
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
1380
+ r"""
1381
+ Decode bytes back into an [`Item`] of this concrete type.
1382
+ """
1383
+ def is_void(self) -> builtins.bool:
1384
+ r"""
1385
+ `true` when this value represents the special *void* marker
1386
+ used to delete a leaf from the SMT.
1387
+ """
1388
+
1389
+ class StatsKey:
1390
+ trader: builtins.str
1391
+ def __new__(cls, trader:builtins.str) -> StatsKey: ...
1392
+ def as_trader_key(self) -> TraderKey:
1393
+ r"""
1394
+ Convert this stats key into the corresponding `TraderKey`.
1395
+ """
1396
+ def __repr__(self) -> builtins.str: ...
1397
+ def __deepcopy__(self, _memo:dict) -> StatsKey: ...
1398
+ def encode_key(self) -> H256:
1399
+ r"""
1400
+ Encode this state-key into the 32-byte format used on-chain.
1401
+ """
1402
+ @classmethod
1403
+ def decode_key(cls, _cls:type, value:H256) -> StatsKey:
1404
+ r"""
1405
+ Decode a previously-encoded key back into its strongly-typed form.
1406
+ """
1407
+
1408
+ class Strategy:
1409
+ r"""
1410
+ An trading strategy (aka sub-account, formerly known as account)
1411
+ """
1412
+ avail_collateral: Balance
1413
+ r"""
1414
+ Amount of the collateral per token available as margin
1415
+ """
1416
+ locked_collateral: Balance
1417
+ r"""
1418
+ Amount of collateral per token frozen for withdrawal
1419
+ """
1420
+ max_leverage: builtins.int
1421
+ r"""
1422
+ Maximum amount of leverage allowed
1423
+ """
1424
+ frozen: builtins.bool
1425
+ r"""
1426
+ Whether the entire account frozen for strategy tokenization
1427
+ """
1428
+ def __new__(cls, avail_collateral:Balance, locked_collateral:Balance, max_leverage:builtins.int, frozen:builtins.bool) -> Strategy: ...
1429
+ @classmethod
1430
+ def default(cls, _cls:type) -> Strategy:
1431
+ r"""
1432
+ Return an empty `Strategy` with default parameters.
1433
+ """
1434
+ def update_avail_collateral(self, symbol:TokenSymbol, amount:Decimal) -> Balance:
1435
+ r"""
1436
+ Return a new `Balance` obtained by updating this strategy's
1437
+ available collateral for `symbol` to `amount`.
1438
+ """
1439
+ def update_locked_collateral(self, symbol:TokenSymbol, amount:Decimal) -> Balance:
1440
+ r"""
1441
+ Return a new `Balance` obtained by updating this strategy's
1442
+ locked collateral for `symbol` to `amount`.
1443
+ """
1444
+ def __repr__(self) -> builtins.str: ...
1445
+ def __deepcopy__(self, _memo:dict) -> Strategy: ...
1446
+ def as_item(self) -> Item:
1447
+ r"""
1448
+ Wrap this concrete structure into the generic [`Item`] enum.
1449
+ """
1450
+ @classmethod
1451
+ def from_item(cls, _cls:type, item:Item) -> Strategy:
1452
+ r"""
1453
+ Down-cast a generic [`Item`] into this concrete type.
1454
+ """
1455
+ def abi_encoded_value(self) -> builtins.bytes:
1456
+ r"""
1457
+ ABI-encode this value.
1458
+ """
1459
+ @classmethod
1460
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
1461
+ r"""
1462
+ Decode bytes back into an [`Item`] of this concrete type.
1463
+ """
1464
+ def is_void(self) -> builtins.bool:
1465
+ r"""
1466
+ `true` when this value represents the special *void* marker
1467
+ used to delete a leaf from the SMT.
1468
+ """
1469
+
1470
+ class StrategyKey:
1471
+ trader_address: builtins.str
1472
+ strategy_id_hash: builtins.str
1473
+ def __new__(cls, trader_address:builtins.str, strategy_id_hash:builtins.str) -> StrategyKey: ...
1474
+ @staticmethod
1475
+ def generate_strategy_id_hash(strategy_id:builtins.str) -> builtins.str:
1476
+ r"""
1477
+ Deterministically hash `strategy_id` into a `StrategyIdHash`.
1478
+ """
1479
+ def as_position_key(self, symbol:ProductSymbol) -> PositionKey:
1480
+ r"""
1481
+ Derive the `PositionKey` for `symbol` that belongs to this strategy.
1482
+ """
1483
+ def __repr__(self) -> builtins.str: ...
1484
+ def __deepcopy__(self, _memo:dict) -> StrategyKey: ...
1485
+ def encode_key(self) -> H256:
1486
+ r"""
1487
+ Encode this state-key into the 32-byte format used on-chain.
1488
+ """
1489
+ @classmethod
1490
+ def decode_key(cls, _cls:type, value:H256) -> StrategyKey:
1491
+ r"""
1492
+ Decode a previously-encoded key back into its strongly-typed form.
1493
+ """
1494
+
1495
+ class TradableProduct:
1496
+ def __new__(cls) -> TradableProduct: ...
1497
+ def __repr__(self) -> builtins.str: ...
1498
+ def __deepcopy__(self, _memo:dict) -> TradableProduct: ...
1499
+ def as_item(self) -> Item:
1500
+ r"""
1501
+ Wrap this concrete structure into the generic [`Item`] enum.
1502
+ """
1503
+ @classmethod
1504
+ def from_item(cls, _cls:type, item:Item) -> TradableProduct:
1505
+ r"""
1506
+ Down-cast a generic [`Item`] into this concrete type.
1507
+ """
1508
+ def abi_encoded_value(self) -> builtins.bytes:
1509
+ r"""
1510
+ ABI-encode this value.
1511
+ """
1512
+ @classmethod
1513
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
1514
+ r"""
1515
+ Decode bytes back into an [`Item`] of this concrete type.
1516
+ """
1517
+ def is_void(self) -> builtins.bool:
1518
+ r"""
1519
+ `true` when this value represents the special *void* marker
1520
+ used to delete a leaf from the SMT.
1521
+ """
1522
+
1523
+ class TradableProductKey:
1524
+ specs: SpecsKey
1525
+ parameters: typing.Optional[TradableProductParameters]
1526
+ def __new__(cls, specs:SpecsKey, parameters:typing.Optional[TradableProductParameters]) -> TradableProductKey: ...
1527
+ def as_product_symbol(self) -> ProductSymbol:
1528
+ r"""
1529
+ Convert this key into its `ProductSymbol`.
1530
+ """
1531
+ def __repr__(self) -> builtins.str: ...
1532
+ def __deepcopy__(self, _memo:dict) -> TradableProductKey: ...
1533
+ def encode_key(self) -> H256:
1534
+ r"""
1535
+ Encode this state-key into the 32-byte format used on-chain.
1536
+ """
1537
+ @classmethod
1538
+ def decode_key(cls, _cls:type, value:H256) -> TradableProductKey:
1539
+ r"""
1540
+ Decode a previously-encoded key back into its strongly-typed form.
1541
+ """
1542
+
1543
+ class Trader:
1544
+ r"""
1545
+ An individual trader
1546
+ """
1547
+ avail_ddx_balance: Decimal
1548
+ r"""
1549
+ The DDX balance stated / usable for trading
1550
+ """
1551
+ locked_ddx_balance: Decimal
1552
+ r"""
1553
+ The DDX balance locked for withdrawal
1554
+ """
1555
+ pay_fees_in_ddx: builtins.bool
1556
+ r"""
1557
+ Switch to paying fees with DDX
1558
+ """
1559
+ access_denied: builtins.bool
1560
+ r"""
1561
+ Whether the trader is denied access to the platform
1562
+ """
1563
+ referral_address: builtins.str
1564
+ def __new__(cls, avail_ddx_balance:Decimal, locked_ddx_balance:Decimal, pay_fees_in_ddx:builtins.bool) -> Trader: ...
1565
+ def set_referral_address(self, hex:builtins.str) -> None: ...
1566
+ @classmethod
1567
+ def default(cls, _cls:type) -> Trader:
1568
+ r"""
1569
+ Return a zero-initialized `Trader` value.
1570
+ """
1571
+ def __repr__(self) -> builtins.str: ...
1572
+ def __deepcopy__(self, _memo:dict) -> Trader: ...
1573
+ def as_item(self) -> Item:
1574
+ r"""
1575
+ Wrap this concrete structure into the generic [`Item`] enum.
1576
+ """
1577
+ @classmethod
1578
+ def from_item(cls, _cls:type, item:Item) -> Trader:
1579
+ r"""
1580
+ Down-cast a generic [`Item`] into this concrete type.
1581
+ """
1582
+ def abi_encoded_value(self) -> builtins.bytes:
1583
+ r"""
1584
+ ABI-encode this value.
1585
+ """
1586
+ @classmethod
1587
+ def abi_decode_value_into_item(cls, _cls:type, abi_encoded_value:builtins.bytes) -> typing.Optional[Item]:
1588
+ r"""
1589
+ Decode bytes back into an [`Item`] of this concrete type.
1590
+ """
1591
+ def is_void(self) -> builtins.bool:
1592
+ r"""
1593
+ `true` when this value represents the special *void* marker
1594
+ used to delete a leaf from the SMT.
1595
+ """
1596
+
1597
+ class TraderKey:
1598
+ def __repr__(self) -> builtins.str: ...
1599
+ def __deepcopy__(self, _memo:dict) -> TraderKey: ...
1600
+ def encode_key(self) -> H256:
1601
+ r"""
1602
+ Encode this state-key into the 32-byte format used on-chain.
1603
+ """
1604
+ @classmethod
1605
+ def decode_key(cls, _cls:type, value:H256) -> TraderKey:
1606
+ r"""
1607
+ Decode a previously-encoded key back into its strongly-typed form.
1608
+ """
1609
+ def __new__(cls, inner:builtins.str) -> TraderKey: ...
1610
+
1611
+ class UpdateProductListings:
1612
+ r"""
1613
+ A signal to update product listings is sent by the operator clock tick mechanism based on the
1614
+ current wall clock time. It is used to add or remove products from the exchange's product
1615
+ listings.
1616
+
1617
+ Motivating example: there are different futures products all corresponding to the same futures
1618
+ specs class, but each future is listed/available to trade at different times. For example, ETHF{}
1619
+ is a specs class representing futures tracking the price of ETH. ETHFH is a specific tradable
1620
+ product referring to the ETH future expiring in March that is listed at the time of writing one
1621
+ week before the expiry of the preceding September future until its expiry in March. The operator
1622
+ will update the listings to add ETHFH and remove ETHFH at the appropriate times.
1623
+ """
1624
+ additions: builtins.list[TradableProductKey]
1625
+ removals: builtins.list[TradableProductKey]
1626
+ json: typing.Any
1627
+ def __new__(cls, additions:typing.Sequence[TradableProductKey], removals:typing.Sequence[TradableProductKey]) -> UpdateProductListings: ...
1628
+ def __repr__(self) -> builtins.str: ...
1629
+
1630
+ class WithdrawDDXIntent:
1631
+ r"""
1632
+ Traders signal their intent to withdraw ddx which freezes the specified amount
1633
+ in their account.
1634
+
1635
+ Funds may be available on-chain at the next checkpoint the operator is kind enough to
1636
+ "prove" the withdrawals on behalf of traders.
1637
+
1638
+ Otherwise, traders may submit a merkle proof at any time after a `Checkpoint` to collect
1639
+ their funds.
1640
+ """
1641
+ amount: Decimal
1642
+ r"""
1643
+ Amount to withdraw
1644
+ """
1645
+ nonce: builtins.str
1646
+ r"""
1647
+ A salt for uniqueness of the EIP-712 hash function. May optionally have
1648
+ business meaning to the client.
1649
+ """
1650
+ signature: builtins.str
1651
+ r"""
1652
+ EIP-712 signature of the withdraw ddx intent attributes
1653
+ """
1654
+ json: typing.Any
1655
+ def __new__(cls, amount:Decimal, nonce:builtins.str, signature:typing.Optional[builtins.str]=None) -> WithdrawDDXIntent: ...
1656
+ def __repr__(self) -> builtins.str: ...
1657
+ def hash_eip712(self, message_metadata:typing.Optional[tuple[builtins.int, builtins.str]]=None) -> builtins.str:
1658
+ r"""
1659
+ Compute the EIP-712 digest for this intent.
1660
+ Passing `message_metadata=(chain_id, verifying_contract)`
1661
+ overrides the default values used in the hash.
1662
+ """
1663
+ def recover_signer(self) -> tuple[builtins.str, builtins.str]:
1664
+ r"""
1665
+ Recover the `(eip712_hash, trader_address)` that signed
1666
+ this intent.
1667
+ """
1668
+
1669
+ class WithdrawIntent:
1670
+ r"""
1671
+ Traders signal their intent to withdraw which freezes the requested collateral in their account.
1672
+
1673
+ Funds may be available on-chain at the next checkpoint the operator is kind enough to "prove"
1674
+ the withdrawals on behalf of traders. Otherwise, traders may submit a merkle proof
1675
+ at any time after a `Checkpoint` to collect their funds.
1676
+ """
1677
+ strategy_id: builtins.str
1678
+ r"""
1679
+ Strategy Id (label)
1680
+ """
1681
+ currency: builtins.str
1682
+ r"""
1683
+ Ethereum address of the collateral token (ERC-20)
1684
+ """
1685
+ amount: Decimal
1686
+ r"""
1687
+ Amount to withdraw
1688
+ """
1689
+ nonce: builtins.str
1690
+ r"""
1691
+ A salt for uniqueness of the EIP-712 hash function. May optionally have business meaning to the client.
1692
+ """
1693
+ signature: builtins.str
1694
+ r"""
1695
+ EIP-712 signature of the withdraw intent attributes
1696
+ """
1697
+ json: typing.Any
1698
+ def __new__(cls, strategy_id:builtins.str, currency:builtins.str, amount:Decimal, nonce:builtins.str, signature:typing.Optional[builtins.str]=None) -> WithdrawIntent: ...
1699
+ def __repr__(self) -> builtins.str: ...
1700
+ def hash_eip712(self, message_metadata:typing.Optional[tuple[builtins.int, builtins.str]]=None) -> builtins.str:
1701
+ r"""
1702
+ Compute the EIP-712 digest for this intent.
1703
+ Passing `message_metadata=(chain_id, verifying_contract)`
1704
+ overrides the default values used in the hash.
1705
+ """
1706
+ def recover_signer(self) -> tuple[builtins.str, builtins.str]:
1707
+ r"""
1708
+ Recover the `(eip712_hash, trader_address)` that signed
1709
+ this intent.
1710
+ """
1711
+
1712
+ class InsuranceFundUpdateKind(Enum):
1713
+ Unassigned = ...
1714
+ Deposit = ...
1715
+ Withdraw = ...
1716
+
1717
+ def __new__(cls, name:builtins.str) -> InsuranceFundUpdateKind:
1718
+ r"""
1719
+ Parse an `InsuranceFundUpdateKind` from its string discriminant.
1720
+ """
1721
+
1722
+ class ItemKind(Enum):
1723
+ Empty = ...
1724
+ Trader = ...
1725
+ Strategy = ...
1726
+ Position = ...
1727
+ BookOrder = ...
1728
+ Price = ...
1729
+ InsuranceFund = ...
1730
+ Stats = ...
1731
+ Signer = ...
1732
+ Specs = ...
1733
+ TradableProduct = ...
1734
+ InsuranceFundContribution = ...
1735
+ EpochMetadata = ...
1736
+
1737
+ def __new__(cls, value:builtins.int) -> ItemKind:
1738
+ r"""
1739
+ Create an `ItemKind` from its numeric discriminant (`u8`).
1740
+ Returns `PyValueError` if the value does not correspond to a variant.
1741
+ """
1742
+
1743
+ def discriminants(self) -> dict:
1744
+ r"""
1745
+ Return a Python `dict` that maps variant names to their discriminant values.
1746
+ """
1747
+
1748
+ class MarkPriceMetadata(Enum):
1749
+ r"""
1750
+ Metadata for calculating the mark price, along with the current index price
1751
+ """
1752
+ Ema = ...
1753
+ r"""
1754
+ The mark price is calculated using the ema
1755
+ The calculated exponential moving address (input to the mark price and verifiable using orderbook snapshot in the aggregate tree)
1756
+ """
1757
+ Average = ...
1758
+ r"""
1759
+ The mark price is calculated as an average using the sum and amount of previous index prices
1760
+ Mark price = (accum + index_price) / (count + 1)
1761
+ """
1762
+
1763
+ ema: typing.Optional[Decimal]
1764
+
1765
+ @classmethod
1766
+ def from_dict(cls, _cls:type, ob:typing.Any) -> MarkPriceMetadata:
1767
+ r"""
1768
+ Deserialize `MarkPriceMetadata` from the operator serialization.
1769
+ """
1770
+
1771
+ def __repr__(self) -> builtins.str: ...
1772
+
1773
+ def __deepcopy__(self, _memo:dict) -> MarkPriceMetadata: ...
1774
+
1775
+ class OrderSide(Enum):
1776
+ Bid = ...
1777
+ Ask = ...
1778
+
1779
+ def __new__(cls, name:builtins.str) -> OrderSide:
1780
+ r"""
1781
+ Parse an `OrderSide` (`"Bid"` or `"Ask"`) from its string `name`.
1782
+ """
1783
+
1784
+ class PositionSide(Enum):
1785
+ Empty = ...
1786
+ Long = ...
1787
+ Short = ...
1788
+
1789
+ class PriceDirection(Enum):
1790
+ r"""
1791
+ Direction of the price movement compared to the last price update executed.
1792
+ """
1793
+ Up = ...
1794
+ Down = ...
1795
+ Flat = ...
1796
+ Unknown = ...
1797
+ r"""
1798
+ Not enough context to determine the direction
1799
+ """
1800
+
1801
+ class PriceMetadata(Enum):
1802
+ Empty = ...
1803
+ SingleNamePerpetual = ...
1804
+ IndexFundPerpetual = ...
1805
+ QuarterlyExpiryFuture = ...
1806
+
1807
+ weights: typing.Optional[builtins.dict[builtins.str, Decimal]]
1808
+
1809
+ @classmethod
1810
+ def from_dict(cls, _cls:type, ob:typing.Any) -> PriceMetadata:
1811
+ r"""
1812
+ Deserialize `PriceMetadata` from the operator serialization.
1813
+ """
1814
+
1815
+ def __repr__(self) -> builtins.str: ...
1816
+
1817
+ class ProductSpecs(Enum):
1818
+ SingleNamePerpetual = ...
1819
+ IndexFundPerpetual = ...
1820
+ QuarterlyExpiryFuture = ...
1821
+
1822
+ tick_size: Decimal
1823
+
1824
+ max_order_notional: Decimal
1825
+
1826
+ max_taker_price_deviation: Decimal
1827
+
1828
+ min_order_size: Decimal
1829
+
1830
+ def __repr__(self) -> builtins.str: ...
1831
+
1832
+ def underlying_symbols(self) -> builtins.list[builtins.str]:
1833
+ r"""
1834
+ Return the list of underlying symbols referenced by this specification.
1835
+ """
1836
+
1837
+ class Quarter(Enum):
1838
+ March = ...
1839
+ June = ...
1840
+ September = ...
1841
+ December = ...
1842
+
1843
+ def __repr__(self) -> builtins.str: ...
1844
+
1845
+ def __new__(cls, name:builtins.str) -> Quarter:
1846
+ r"""
1847
+ Parse a calendar quarter ("March", "June", …) from `name`.
1848
+ """
1849
+
1850
+ @classmethod
1851
+ def find_quarter(cls, _cls:type, datetime:datetime.datetime) -> Quarter:
1852
+ r"""
1853
+ Determine the quarter in which `datetime` lies.
1854
+ """
1855
+
1856
+ def expiry_date_after(self, datetime:datetime.datetime) -> datetime.datetime:
1857
+ r"""
1858
+ First expiry date for this quarter strictly after `datetime`.
1859
+ """
1860
+
1861
+ @classmethod
1862
+ def upcoming_expiry_date(cls, _cls:type, current_time:datetime.datetime) -> datetime.datetime:
1863
+ r"""
1864
+ Next quarterly-futures expiry date from `current_time`.
1865
+ """
1866
+
1867
+ def next(self) -> Quarter:
1868
+ r"""
1869
+ Return the quarter immediately following this one.
1870
+ """
1871
+
1872
+ class SpecsKind(Enum):
1873
+ SingleNamePerpetual = ...
1874
+ IndexFundPerpetual = ...
1875
+ QuarterlyExpiryFuture = ...
1876
+ MarketGateway = ...
1877
+
1878
+ def __new__(cls, kind:builtins.str) -> SpecsKind:
1879
+ r"""
1880
+ Parse a `SpecsKind` from its string representation.
1881
+ """
1882
+
1883
+ class StrategyUpdateKind(Enum):
1884
+ r"""
1885
+ Differentiates various types of strategy updates.
1886
+
1887
+ Enumerates different scenarios like deposits, withdrawals, and other events
1888
+ that impact a trader's strategy, enabling appropriate response and adjustment in the strategy.
1889
+ """
1890
+ Unassigned = ...
1891
+ r"""
1892
+ Used as placeholder in default events.
1893
+ """
1894
+ Deposit = ...
1895
+ r"""
1896
+ Reacts to contract deposit event.
1897
+ """
1898
+ Withdraw = ...
1899
+ r"""
1900
+ Reacts to contract withdraw event, decreasing the (claimed) locked collateral.
1901
+ """
1902
+ WithdrawIntent = ...
1903
+ r"""
1904
+ A client request to withdraw funds, which moves funds from available collateral to locked collateral.
1905
+ """
1906
+ FundingPayment = ...
1907
+ RealizedPnl = ...
1908
+
1909
+ def __new__(cls, name:builtins.str) -> StrategyUpdateKind:
1910
+ r"""
1911
+ Parse a `StrategyUpdateKind` from its string discriminant.
1912
+ """
1913
+
1914
+ class TokenSymbol(Enum):
1915
+ r"""
1916
+ Well-known ERC20 tokens used in the underpinning of the protocol
1917
+ """
1918
+ USDC = ...
1919
+ DDX = ...
1920
+
1921
+ @classmethod
1922
+ def from_address(cls, _cls:type, address:builtins.str) -> TokenSymbol:
1923
+ r"""
1924
+ Construct a `TokenSymbol` from the on-chain token `address`.
1925
+ """
1926
+
1927
+ def address(self) -> builtins.str:
1928
+ r"""
1929
+ Return the canonical on-chain address for this token.
1930
+ """
1931
+
1932
+ class TradableProductParameters(Enum):
1933
+ QuarterlyExpiryFuture = ...
1934
+
1935
+ quarter: typing.Optional[Quarter]
1936
+
1937
+ @classmethod
1938
+ def from_dict(cls, _cls:type, ob:typing.Any) -> TradableProductParameters:
1939
+ r"""
1940
+ Deserialize `TradableProductParameters` from the operator serialization.
1941
+ """
1942
+
1943
+ def __repr__(self) -> builtins.str: ...
1944
+
1945
+ class TradeSide(Enum):
1946
+ Maker = ...
1947
+ Taker = ...
1948
+
1949
+ def trading_fee(self, amount:Decimal, price:Decimal) -> Decimal:
1950
+ r"""
1951
+ Compute the trading fee for the given `amount` at `price` on this side.
1952
+ """
1953
+
1954
+ class TraderUpdateKind(Enum):
1955
+ r"""
1956
+ Differentiates various types of trader updates.
1957
+ """
1958
+ Unassigned = ...
1959
+ r"""
1960
+ Used as placeholder in default events.
1961
+ """
1962
+ DepositDDX = ...
1963
+ r"""
1964
+ Reacts to contract DDX deposit event.
1965
+ """
1966
+ WithdrawDDX = ...
1967
+ r"""
1968
+ Reacts to contract DDX withdraw event, decreasing the (claimed) locked collateral.
1969
+ """
1970
+ WithdrawDDXIntent = ...
1971
+ TradeMiningReward = ...
1972
+ Profile = ...
1973
+ r"""
1974
+ Trader profile parameter updates sent via a client intention.
1975
+ """
1976
+ FeeDistribution = ...
1977
+ r"""
1978
+ Fee distribution event.
1979
+ """
1980
+ Denial = ...
1981
+ r"""
1982
+ Denial of access to the platform due to KYC blacklist, expiration, or other reasons.
1983
+ """
1984
+ Admission = ...
1985
+ r"""
1986
+ Admission to the platform due to KYC re-approval, unbanned, or other reasons.
1987
+ """
1988
+
1989
+ def __new__(cls, name:builtins.str) -> TraderUpdateKind:
1990
+ r"""
1991
+ Parse a `TraderUpdateKind` from its string discriminant.
1992
+ """
1993
+
1994
+ def get_operator_context() -> OperatorContext:
1995
+ r"""
1996
+ Get the operator application context for this DerivaDEX instance.
1997
+ """
1998
+
1999
+ def reinit_operator_context() -> None:
2000
+ r"""
2001
+ Reinitialize the operator application context for this DerivaDEX instance.
2002
+ """
2003
+
2004
+ class CoreCommonError(Exception): ...
2005
+
2006
+ class DecimalError(Exception): ...
2007
+
2008
+ class H256Error(Exception): ...
2009
+