nado-protocol 0.1.0__py3-none-any.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 (78) hide show
  1. nado_protocol/__init__.py +0 -0
  2. nado_protocol/client/__init__.py +200 -0
  3. nado_protocol/client/apis/__init__.py +26 -0
  4. nado_protocol/client/apis/base.py +42 -0
  5. nado_protocol/client/apis/market/__init__.py +23 -0
  6. nado_protocol/client/apis/market/execute.py +192 -0
  7. nado_protocol/client/apis/market/query.py +310 -0
  8. nado_protocol/client/apis/perp/__init__.py +18 -0
  9. nado_protocol/client/apis/perp/query.py +30 -0
  10. nado_protocol/client/apis/rewards/__init__.py +6 -0
  11. nado_protocol/client/apis/rewards/execute.py +131 -0
  12. nado_protocol/client/apis/rewards/query.py +12 -0
  13. nado_protocol/client/apis/spot/__init__.py +23 -0
  14. nado_protocol/client/apis/spot/base.py +32 -0
  15. nado_protocol/client/apis/spot/execute.py +117 -0
  16. nado_protocol/client/apis/spot/query.py +79 -0
  17. nado_protocol/client/apis/subaccount/__init__.py +24 -0
  18. nado_protocol/client/apis/subaccount/execute.py +54 -0
  19. nado_protocol/client/apis/subaccount/query.py +145 -0
  20. nado_protocol/client/context.py +90 -0
  21. nado_protocol/contracts/__init__.py +377 -0
  22. nado_protocol/contracts/abis/Endpoint.json +636 -0
  23. nado_protocol/contracts/abis/FQuerier.json +1909 -0
  24. nado_protocol/contracts/abis/IClearinghouse.json +876 -0
  25. nado_protocol/contracts/abis/IERC20.json +185 -0
  26. nado_protocol/contracts/abis/IEndpoint.json +250 -0
  27. nado_protocol/contracts/abis/IFoundationRewardsAirdrop.json +76 -0
  28. nado_protocol/contracts/abis/IOffchainBook.json +536 -0
  29. nado_protocol/contracts/abis/IPerpEngine.json +931 -0
  30. nado_protocol/contracts/abis/IProductEngine.json +352 -0
  31. nado_protocol/contracts/abis/ISpotEngine.json +813 -0
  32. nado_protocol/contracts/abis/IStaking.json +288 -0
  33. nado_protocol/contracts/abis/IVrtxAirdrop.json +138 -0
  34. nado_protocol/contracts/abis/MockERC20.json +311 -0
  35. nado_protocol/contracts/deployments/deployment.test.json +18 -0
  36. nado_protocol/contracts/eip712/__init__.py +16 -0
  37. nado_protocol/contracts/eip712/domain.py +36 -0
  38. nado_protocol/contracts/eip712/sign.py +79 -0
  39. nado_protocol/contracts/eip712/types.py +154 -0
  40. nado_protocol/contracts/loader.py +55 -0
  41. nado_protocol/contracts/types.py +141 -0
  42. nado_protocol/engine_client/__init__.py +35 -0
  43. nado_protocol/engine_client/execute.py +416 -0
  44. nado_protocol/engine_client/query.py +481 -0
  45. nado_protocol/engine_client/types/__init__.py +113 -0
  46. nado_protocol/engine_client/types/execute.py +680 -0
  47. nado_protocol/engine_client/types/models.py +247 -0
  48. nado_protocol/engine_client/types/query.py +516 -0
  49. nado_protocol/engine_client/types/stream.py +6 -0
  50. nado_protocol/indexer_client/__init__.py +28 -0
  51. nado_protocol/indexer_client/query.py +466 -0
  52. nado_protocol/indexer_client/types/__init__.py +122 -0
  53. nado_protocol/indexer_client/types/models.py +364 -0
  54. nado_protocol/indexer_client/types/query.py +819 -0
  55. nado_protocol/trigger_client/__init__.py +17 -0
  56. nado_protocol/trigger_client/execute.py +118 -0
  57. nado_protocol/trigger_client/query.py +61 -0
  58. nado_protocol/trigger_client/types/__init__.py +7 -0
  59. nado_protocol/trigger_client/types/execute.py +89 -0
  60. nado_protocol/trigger_client/types/models.py +44 -0
  61. nado_protocol/trigger_client/types/query.py +77 -0
  62. nado_protocol/utils/__init__.py +37 -0
  63. nado_protocol/utils/backend.py +111 -0
  64. nado_protocol/utils/bytes32.py +159 -0
  65. nado_protocol/utils/enum.py +6 -0
  66. nado_protocol/utils/exceptions.py +58 -0
  67. nado_protocol/utils/execute.py +403 -0
  68. nado_protocol/utils/expiration.py +45 -0
  69. nado_protocol/utils/interest.py +66 -0
  70. nado_protocol/utils/math.py +67 -0
  71. nado_protocol/utils/model.py +79 -0
  72. nado_protocol/utils/nonce.py +33 -0
  73. nado_protocol/utils/subaccount.py +18 -0
  74. nado_protocol/utils/time.py +21 -0
  75. nado_protocol-0.1.0.dist-info/METADATA +157 -0
  76. nado_protocol-0.1.0.dist-info/RECORD +78 -0
  77. nado_protocol-0.1.0.dist-info/WHEEL +4 -0
  78. nado_protocol-0.1.0.dist-info/entry_points.txt +11 -0
@@ -0,0 +1,680 @@
1
+ from typing import Optional, Type, Union
2
+ from pydantic import validator
3
+ from nado_protocol.contracts.types import NadoExecuteType
4
+ from nado_protocol.engine_client.types.models import ResponseStatus
5
+ from nado_protocol.utils.execute import (
6
+ BaseParamsSigned,
7
+ IsolatedOrderParams,
8
+ MarketOrderParams,
9
+ OrderParams,
10
+ SignatureParams,
11
+ )
12
+ from nado_protocol.utils.model import NadoBaseModel
13
+ from nado_protocol.utils.bytes32 import (
14
+ bytes32_to_hex,
15
+ hex_to_bytes32,
16
+ subaccount_to_bytes32,
17
+ )
18
+ from nado_protocol.utils.subaccount import Subaccount
19
+ from nado_protocol.engine_client.types.query import OrderData
20
+
21
+
22
+ Digest = Union[str, bytes]
23
+
24
+
25
+ class PlaceOrderParams(SignatureParams):
26
+ """
27
+ Class for defining the parameters needed to place an order.
28
+
29
+ Attributes:
30
+ id (Optional[int]): An optional custom order id that is echoed back in subscription events e.g: fill orders, etc.
31
+
32
+ product_id (int): The id of the product for which the order is being placed.
33
+
34
+ order (OrderParams): The parameters of the order.
35
+
36
+ digest (Optional[str]): An optional hash of the order data.
37
+
38
+ spot_leverage (Optional[bool]): An optional flag indicating whether leverage should be used for the order. By default, leverage is assumed.
39
+ """
40
+
41
+ id: Optional[int]
42
+ product_id: int
43
+ order: OrderParams
44
+ digest: Optional[str]
45
+ spot_leverage: Optional[bool]
46
+
47
+
48
+ class PlaceIsolatedOrderParams(SignatureParams):
49
+ """
50
+ Class for defining the parameters needed to place an isolated order.
51
+
52
+ Attributes:
53
+ id (Optional[int]): An optional custom order id that is echoed back in subscription events e.g: fill orders, etc.
54
+
55
+ product_id (int): The id of the product for which the order is being placed.
56
+
57
+ isolated_order (IsolatedOrderParams): The parameters of the isolated order.
58
+
59
+ digest (Optional[str]): An optional hash of the order data.
60
+
61
+ borrow_margin (Optional[bool]): Whether the cross subaccount can borrow quote for the margin transfer into the isolated subaccount. If not provided, it defaults to true.
62
+ """
63
+
64
+ id: Optional[int]
65
+ product_id: int
66
+ isolated_order: IsolatedOrderParams
67
+ digest: Optional[str]
68
+ borrow_margin: Optional[bool]
69
+
70
+
71
+ class PlaceMarketOrderParams(SignatureParams):
72
+ """
73
+ Class for defining the parameters needed to place a market order.
74
+
75
+ Attributes:
76
+ product_id (int): The id of the product for which the order is being placed.
77
+
78
+ slippage (Optional[float]): Optional slippage allowed in market price. Defaults to 0.005 (0.5%)
79
+
80
+ market_order (MarketOrderParams): The parameters of the market order.
81
+
82
+ spot_leverage (Optional[bool]): An optional flag indicating whether leverage should be used for the order. By default, leverage is assumed.
83
+
84
+ reduce_only (Optional[bool]): When True, the order can only reduce the size of an existing position. Works only with IOC & FOK.
85
+ """
86
+
87
+ product_id: int
88
+ market_order: MarketOrderParams
89
+ slippage: Optional[float]
90
+ spot_leverage: Optional[bool]
91
+ reduce_only: Optional[bool]
92
+
93
+
94
+ class CancelOrdersParams(BaseParamsSigned):
95
+ """
96
+ Parameters to cancel specific orders.
97
+
98
+ Args:
99
+ productIds (list[int]): List of product IDs for the orders to be canceled.
100
+
101
+ digests (list[Digest]): List of digests of the orders to be canceled.
102
+
103
+ nonce (Optional[int]): A unique number used to prevent replay attacks.
104
+
105
+ Methods:
106
+ serialize_digests: Validates and converts a list of hex digests to bytes32.
107
+ """
108
+
109
+ productIds: list[int]
110
+ digests: list[Digest]
111
+ nonce: Optional[int]
112
+
113
+ @validator("digests")
114
+ def serialize_digests(cls, v: list[Digest]) -> list[bytes]:
115
+ return [hex_to_bytes32(digest) for digest in v]
116
+
117
+
118
+ class CancelProductOrdersParams(BaseParamsSigned):
119
+ """
120
+ Parameters to cancel all orders for specific products.
121
+
122
+ Args:
123
+ productIds (list[int]): List of product IDs for the orders to be canceled.
124
+
125
+ digest (str, optional): Optional EIP-712 digest of the CancelProductOrder request.
126
+
127
+ nonce (Optional[int]): A unique number used to prevent replay attacks.
128
+ """
129
+
130
+ productIds: list[int]
131
+ digest: Optional[str]
132
+ nonce: Optional[int]
133
+
134
+
135
+ class CancelAndPlaceParams(NadoBaseModel):
136
+ """
137
+ Parameters to perform an order cancellation + order placement in the same request.
138
+
139
+ Args:
140
+ cancel_orders (CancelOrdersParams): Order cancellation object.
141
+ place_order (PlaceOrderParams): Order placement object.
142
+ """
143
+
144
+ cancel_orders: CancelOrdersParams
145
+ place_order: PlaceOrderParams
146
+
147
+
148
+ class WithdrawCollateralParams(BaseParamsSigned):
149
+ """
150
+ Parameters required to withdraw collateral from a specific product.
151
+
152
+ Attributes:
153
+ productId (int): The ID of the product to withdraw collateral from.
154
+
155
+ amount (int): The amount of collateral to be withdrawn.
156
+
157
+ spot_leverage (Optional[bool]): Indicates whether leverage is to be used. Defaults to True.
158
+ If set to False, the transaction fails if it causes a borrow on the subaccount.
159
+ """
160
+
161
+ productId: int
162
+ amount: int
163
+ spot_leverage: Optional[bool]
164
+
165
+
166
+ class LiquidateSubaccountParams(BaseParamsSigned):
167
+ """
168
+ Parameters required to liquidate a subaccount.
169
+
170
+ Attributes:
171
+ liquidatee (Subaccount): The subaccount that is to be liquidated.
172
+
173
+ productId (int): ID of product to liquidate.
174
+
175
+ isEncodedSpread (bool): When set to True, productId is expected to encode a perp and spot product Ids as follows: (perp_id << 16) | spot_id
176
+
177
+ amount (int): The amount to be liquidated.
178
+
179
+ Methods:
180
+ serialize_liquidatee(cls, v: Subaccount) -> bytes: Validates and converts the liquidatee subaccount to bytes32 format.
181
+ """
182
+
183
+ liquidatee: Subaccount
184
+ productId: int
185
+ isEncodedSpread: bool
186
+ amount: int
187
+
188
+ @validator("liquidatee")
189
+ def serialize_liquidatee(cls, v: Subaccount) -> bytes:
190
+ return subaccount_to_bytes32(v)
191
+
192
+
193
+ class MintLpParams(BaseParamsSigned):
194
+ """
195
+ Parameters required for minting a liquidity provider token for a specific product in a subaccount.
196
+
197
+ Attributes:
198
+ productId (int): The ID of the product.
199
+
200
+ amountBase (int): The amount of base to be consumed by minting LPs multiplied by 1e18.
201
+
202
+ quoteAmountLow (int): The minimum amount of quote to be consumed by minting LPs multiplied by 1e18.
203
+
204
+ quoteAmountHigh (int): The maximum amount of quote to be consumed by minting LPs multiplied by 1e18.
205
+
206
+ spot_leverage (Optional[bool]): Indicates whether leverage is to be used. Defaults to True.
207
+ If set to False, the transaction fails if it causes a borrow on the subaccount.
208
+ """
209
+
210
+ productId: int
211
+ amountBase: int
212
+ quoteAmountLow: int
213
+ quoteAmountHigh: int
214
+ spot_leverage: Optional[bool]
215
+
216
+
217
+ class BurnLpParams(BaseParamsSigned):
218
+ """
219
+ This class represents the parameters required to burn a liquidity provider
220
+ token for a specific product in a subaccount.
221
+
222
+ Attributes:
223
+ productId (int): The ID of the product.
224
+
225
+ amount (int): Combined amount of base + quote to burn multiplied by 1e18.
226
+ """
227
+
228
+ productId: int
229
+ amount: int
230
+
231
+
232
+ class LinkSignerParams(BaseParamsSigned):
233
+ """
234
+ This class represents the parameters required to link a signer to a subaccount.
235
+
236
+ Attributes:
237
+ signer (Subaccount): The subaccount to be linked.
238
+
239
+ Methods:
240
+ serialize_signer(cls, v: Subaccount) -> bytes: Validates and converts the subaccount to bytes32 format.
241
+ """
242
+
243
+ signer: Subaccount
244
+
245
+ @validator("signer")
246
+ def serialize_signer(cls, v: Subaccount) -> bytes:
247
+ return subaccount_to_bytes32(v)
248
+
249
+
250
+ ExecuteParams = Union[
251
+ PlaceOrderParams,
252
+ PlaceIsolatedOrderParams,
253
+ CancelOrdersParams,
254
+ CancelProductOrdersParams,
255
+ WithdrawCollateralParams,
256
+ LiquidateSubaccountParams,
257
+ MintLpParams,
258
+ BurnLpParams,
259
+ LinkSignerParams,
260
+ CancelAndPlaceParams,
261
+ ]
262
+
263
+
264
+ class PlaceOrderRequest(NadoBaseModel):
265
+ """
266
+ Parameters for a request to place an order.
267
+
268
+ Attributes:
269
+ place_order (PlaceOrderParams): The parameters for the order to be placed.
270
+
271
+ Methods:
272
+ serialize: Validates and serializes the order parameters.
273
+ """
274
+
275
+ place_order: PlaceOrderParams
276
+
277
+ @validator("place_order")
278
+ def serialize(cls, v: PlaceOrderParams) -> PlaceOrderParams:
279
+ if v.order.nonce is None:
280
+ raise ValueError("Missing order `nonce`")
281
+ if v.signature is None:
282
+ raise ValueError("Missing `signature")
283
+ if isinstance(v.order.sender, bytes):
284
+ v.order.serialize_dict(["sender"], bytes32_to_hex)
285
+ v.order.serialize_dict(["nonce", "priceX18", "amount", "expiration"], str)
286
+ return v
287
+
288
+
289
+ class PlaceIsolatedOrderRequest(NadoBaseModel):
290
+ """
291
+ Parameters for a request to place an isolated order.
292
+
293
+ Attributes:
294
+ place_isolated_order (PlaceIsolatedOrderParams): The parameters for the isolated order to be placed.
295
+
296
+ Methods:
297
+ serialize: Validates and serializes the order parameters.
298
+ """
299
+
300
+ place_isolated_order: PlaceIsolatedOrderParams
301
+
302
+ @validator("place_isolated_order")
303
+ def serialize(cls, v: PlaceIsolatedOrderParams) -> PlaceIsolatedOrderParams:
304
+ if v.isolated_order.nonce is None:
305
+ raise ValueError("Missing order `nonce`")
306
+ if v.signature is None:
307
+ raise ValueError("Missing `signature")
308
+ if isinstance(v.isolated_order.sender, bytes):
309
+ v.isolated_order.serialize_dict(["sender"], bytes32_to_hex)
310
+ v.isolated_order.serialize_dict(
311
+ ["nonce", "priceX18", "amount", "expiration", "margin"], str
312
+ )
313
+ return v
314
+
315
+
316
+ class TxRequest(NadoBaseModel):
317
+ """
318
+ Parameters for a transaction request.
319
+
320
+ Attributes:
321
+ tx (dict): The transaction details.
322
+
323
+ signature (str): The signature for the transaction.
324
+
325
+ spot_leverage (Optional[bool]): Indicates whether leverage should be used. If set to false,
326
+ it denotes no borrowing. Defaults to true.
327
+
328
+ digest (Optional[str]): The digest of the transaction.
329
+
330
+ Methods:
331
+ serialize: Validates and serializes the transaction parameters.
332
+ """
333
+
334
+ tx: dict
335
+ signature: str
336
+ spot_leverage: Optional[bool]
337
+ digest: Optional[str]
338
+
339
+ @validator("tx")
340
+ def serialize(cls, v: dict) -> dict:
341
+ """
342
+ Validates and serializes the transaction parameters.
343
+
344
+ Args:
345
+ v (dict): The transaction parameters to be validated and serialized.
346
+
347
+ Raises:
348
+ ValueError: If the 'nonce' attribute is missing in the transaction parameters.
349
+
350
+ Returns:
351
+ dict: The validated and serialized transaction parameters.
352
+ """
353
+ if v.get("nonce") is None:
354
+ raise ValueError("Missing tx `nonce`")
355
+ v["sender"] = bytes32_to_hex(v["sender"])
356
+ v["nonce"] = str(v["nonce"])
357
+ return v
358
+
359
+
360
+ def to_tx_request(cls: Type[NadoBaseModel], v: BaseParamsSigned) -> TxRequest:
361
+ """
362
+ Converts a BaseParamsSigned object to a TxRequest object.
363
+
364
+ Args:
365
+ cls (Type[NadoBaseModel]): The type of the model to convert.
366
+
367
+ v (BaseParamsSigned): The signed parameters to be converted.
368
+
369
+ Raises:
370
+ ValueError: If the 'signature' attribute is missing in the BaseParamsSigned object.
371
+
372
+ Returns:
373
+ TxRequest: The converted transaction request.
374
+ """
375
+ if v.signature is None:
376
+ raise ValueError("Missing `signature`")
377
+ return TxRequest(
378
+ tx=v.dict(exclude={"signature", "digest", "spot_leverage"}),
379
+ signature=v.signature,
380
+ spot_leverage=v.dict().get("spot_leverage"),
381
+ digest=v.dict().get("digest"),
382
+ )
383
+
384
+
385
+ class CancelOrdersRequest(NadoBaseModel):
386
+ """
387
+ Parameters for a cancel orders request.
388
+
389
+ Attributes:
390
+ cancel_orders (CancelOrdersParams): The parameters of the orders to be cancelled.
391
+
392
+ Methods:
393
+ serialize: Serializes 'digests' in 'cancel_orders' into their hexadecimal representation.
394
+
395
+ to_tx_request: Validates and converts 'cancel_orders' into a transaction request.
396
+ """
397
+
398
+ cancel_orders: CancelOrdersParams
399
+
400
+ @validator("cancel_orders")
401
+ def serialize(cls, v: CancelOrdersParams) -> CancelOrdersParams:
402
+ """
403
+ Serializes 'digests' in 'cancel_orders' into their hexadecimal representation.
404
+
405
+ Args:
406
+ v (CancelOrdersParams): The parameters of the orders to be cancelled.
407
+
408
+ Returns:
409
+ CancelOrdersParams: The 'cancel_orders' with serialized 'digests'.
410
+ """
411
+ v.serialize_dict(["digests"], lambda l: [bytes32_to_hex(x) for x in l])
412
+ return v
413
+
414
+ _validator = validator("cancel_orders", allow_reuse=True)(to_tx_request)
415
+
416
+
417
+ class CancelAndPlaceRequest(NadoBaseModel):
418
+ """
419
+ Parameters for a cancel and place request.
420
+
421
+ Attributes:
422
+ cancel_and_place (CancelAndPlaceParams): Request parameters for engine cancel_and_place execution
423
+ """
424
+
425
+ cancel_and_place: CancelAndPlaceParams
426
+
427
+ @validator("cancel_and_place")
428
+ def serialize(cls, v: CancelAndPlaceParams) -> dict:
429
+ cancel_tx = TxRequest.parse_obj(
430
+ CancelOrdersRequest(cancel_orders=v.cancel_orders).cancel_orders
431
+ )
432
+ return {
433
+ "cancel_tx": cancel_tx.tx,
434
+ "place_order": PlaceOrderRequest(place_order=v.place_order).place_order,
435
+ "cancel_signature": cancel_tx.signature,
436
+ }
437
+
438
+
439
+ class CancelProductOrdersRequest(NadoBaseModel):
440
+ """
441
+ Parameters for a cancel product orders request.
442
+
443
+ Attributes:
444
+ cancel_product_orders (CancelProductOrdersParams): The parameters of the product orders to be cancelled.
445
+
446
+ Methods:
447
+ to_tx_request: Validates and converts 'cancel_product_orders' into a transaction request.
448
+ """
449
+
450
+ cancel_product_orders: CancelProductOrdersParams
451
+
452
+ _validator = validator("cancel_product_orders", allow_reuse=True)(to_tx_request)
453
+
454
+
455
+ class WithdrawCollateralRequest(NadoBaseModel):
456
+ """
457
+ Parameters for a withdraw collateral request.
458
+
459
+ Attributes:
460
+ withdraw_collateral (WithdrawCollateralParams): The parameters of the collateral to be withdrawn.
461
+
462
+ Methods:
463
+ serialize: Validates and converts the 'amount' attribute of 'withdraw_collateral' to string.
464
+
465
+ to_tx_request: Validates and converts 'withdraw_collateral' into a transaction request.
466
+ """
467
+
468
+ withdraw_collateral: WithdrawCollateralParams
469
+
470
+ @validator("withdraw_collateral")
471
+ def serialize(cls, v: WithdrawCollateralParams) -> WithdrawCollateralParams:
472
+ v.serialize_dict(["amount"], str)
473
+ return v
474
+
475
+ _validator = validator("withdraw_collateral", allow_reuse=True)(to_tx_request)
476
+
477
+
478
+ class LiquidateSubaccountRequest(NadoBaseModel):
479
+ """
480
+ Parameters for a liquidate subaccount request.
481
+
482
+ Attributes:
483
+ liquidate_subaccount (LiquidateSubaccountParams): The parameters for the subaccount to be liquidated.
484
+
485
+ Methods:
486
+ serialize: Validates and converts the 'amount' attribute and the 'liquidatee' attribute
487
+ of 'liquidate_subaccount' to their proper serialized forms.
488
+
489
+ to_tx_request: Validates and converts 'liquidate_subaccount' into a transaction request.
490
+ """
491
+
492
+ liquidate_subaccount: LiquidateSubaccountParams
493
+
494
+ @validator("liquidate_subaccount")
495
+ def serialize(cls, v: LiquidateSubaccountParams) -> LiquidateSubaccountParams:
496
+ v.serialize_dict(["amount"], str)
497
+ v.serialize_dict(["liquidatee"], bytes32_to_hex)
498
+ return v
499
+
500
+ _validator = validator("liquidate_subaccount", allow_reuse=True)(to_tx_request)
501
+
502
+
503
+ class MintLpRequest(NadoBaseModel):
504
+ """
505
+ Parameters for a mint LP request.
506
+
507
+ Attributes:
508
+ mint_lp (MintLpParams): The parameters for minting liquidity.
509
+
510
+ Methods:
511
+ serialize: Validates and converts the 'amountBase', 'quoteAmountLow', and 'quoteAmountHigh'
512
+ attributes of 'mint_lp' to their proper serialized forms.
513
+
514
+ to_tx_request: Validates and converts 'mint_lp' into a transaction request.
515
+ """
516
+
517
+ mint_lp: MintLpParams
518
+
519
+ @validator("mint_lp")
520
+ def serialize(cls, v: MintLpParams) -> MintLpParams:
521
+ v.serialize_dict(["amountBase", "quoteAmountLow", "quoteAmountHigh"], str)
522
+ return v
523
+
524
+ _validator = validator("mint_lp", allow_reuse=True)(to_tx_request)
525
+
526
+
527
+ class BurnLpRequest(NadoBaseModel):
528
+ """
529
+ Parameters for a burn LP request.
530
+
531
+ Attributes:
532
+ burn_lp (BurnLpParams): The parameters for burning liquidity.
533
+
534
+ Methods:
535
+ serialize: Validates and converts the 'amount' attribute of 'burn_lp' to its proper serialized form.
536
+
537
+ to_tx_request: Validates and converts 'burn_lp' into a transaction request.
538
+ """
539
+
540
+ burn_lp: BurnLpParams
541
+
542
+ @validator("burn_lp")
543
+ def serialize(cls, v: BurnLpParams) -> BurnLpParams:
544
+ v.serialize_dict(["amount"], str)
545
+ return v
546
+
547
+ _validator = validator("burn_lp", allow_reuse=True)(to_tx_request)
548
+
549
+
550
+ class LinkSignerRequest(NadoBaseModel):
551
+ """
552
+ Parameters for a request to link a signer to a subaccount.
553
+
554
+ Attributes:
555
+ link_signer (LinkSignerParams): Parameters including the subaccount to be linked.
556
+
557
+ Methods:
558
+ serialize: Validates and converts the 'signer' attribute of 'link_signer' into its hexadecimal representation.
559
+
560
+ to_tx_request: Validates and converts 'link_signer' into a transaction request.
561
+ """
562
+
563
+ link_signer: LinkSignerParams
564
+
565
+ @validator("link_signer")
566
+ def serialize(cls, v: LinkSignerParams) -> LinkSignerParams:
567
+ v.serialize_dict(["signer"], bytes32_to_hex)
568
+ return v
569
+
570
+ _validator = validator("link_signer", allow_reuse=True)(to_tx_request)
571
+
572
+
573
+ ExecuteRequest = Union[
574
+ PlaceOrderRequest,
575
+ PlaceIsolatedOrderRequest,
576
+ CancelOrdersRequest,
577
+ CancelProductOrdersRequest,
578
+ CancelAndPlaceRequest,
579
+ WithdrawCollateralRequest,
580
+ LiquidateSubaccountRequest,
581
+ MintLpRequest,
582
+ BurnLpRequest,
583
+ LinkSignerRequest,
584
+ ]
585
+
586
+
587
+ class PlaceOrderResponse(NadoBaseModel):
588
+ """
589
+ Data model for place order response.
590
+ """
591
+
592
+ digest: str
593
+
594
+
595
+ class CancelOrdersResponse(NadoBaseModel):
596
+ """
597
+ Data model for cancelled orders response.
598
+ """
599
+
600
+ cancelled_orders: list[OrderData]
601
+
602
+
603
+ ExecuteResponseData = Union[PlaceOrderResponse, CancelOrdersResponse]
604
+
605
+
606
+ class ExecuteResponse(NadoBaseModel):
607
+ """
608
+ Represents the response returned from executing a request.
609
+
610
+ Attributes:
611
+ status (ResponseStatus): The status of the response.
612
+
613
+ signature (Optional[str]): The signature of the response. Only present if the request was successfully executed.
614
+
615
+ data (Optional[ExecuteResponseData]): Data returned from execute, not all executes currently return data.
616
+
617
+ error_code (Optional[int]): The error code, if any error occurred during the execution of the request.
618
+
619
+ error (Optional[str]): The error message, if any error occurred during the execution of the request.
620
+
621
+ request_type (Optional[str]): Type of the request.
622
+
623
+ req (Optional[dict]): The original request that was executed.
624
+
625
+ id (Optional[id]): An optional client id provided when placing an order
626
+ """
627
+
628
+ status: ResponseStatus
629
+ signature: Optional[str]
630
+ data: Optional[ExecuteResponseData]
631
+ error_code: Optional[int]
632
+ error: Optional[str]
633
+ request_type: Optional[str]
634
+ req: Optional[dict]
635
+ id: Optional[int]
636
+
637
+
638
+ def to_execute_request(params: ExecuteParams) -> ExecuteRequest:
639
+ """
640
+ Maps `ExecuteParams` to its corresponding `ExecuteRequest` object based on the parameter type.
641
+
642
+ Args:
643
+ params (ExecuteParams): The parameters to be executed.
644
+
645
+ Returns:
646
+ ExecuteRequest: The corresponding `ExecuteRequest` object.
647
+ """
648
+ execute_request_mapping = {
649
+ PlaceOrderParams: (PlaceOrderRequest, NadoExecuteType.PLACE_ORDER.value),
650
+ PlaceIsolatedOrderParams: (
651
+ PlaceIsolatedOrderRequest,
652
+ NadoExecuteType.PLACE_ISOLATED_ORDER.value,
653
+ ),
654
+ CancelOrdersParams: (
655
+ CancelOrdersRequest,
656
+ NadoExecuteType.CANCEL_ORDERS.value,
657
+ ),
658
+ CancelProductOrdersParams: (
659
+ CancelProductOrdersRequest,
660
+ NadoExecuteType.CANCEL_PRODUCT_ORDERS.value,
661
+ ),
662
+ WithdrawCollateralParams: (
663
+ WithdrawCollateralRequest,
664
+ NadoExecuteType.WITHDRAW_COLLATERAL.value,
665
+ ),
666
+ LiquidateSubaccountParams: (
667
+ LiquidateSubaccountRequest,
668
+ NadoExecuteType.LIQUIDATE_SUBACCOUNT.value,
669
+ ),
670
+ MintLpParams: (MintLpRequest, NadoExecuteType.MINT_LP.value),
671
+ BurnLpParams: (BurnLpRequest, NadoExecuteType.BURN_LP.value),
672
+ LinkSignerParams: (LinkSignerRequest, NadoExecuteType.LINK_SIGNER.value),
673
+ CancelAndPlaceParams: (
674
+ CancelAndPlaceRequest,
675
+ NadoExecuteType.CANCEL_AND_PLACE.value,
676
+ ),
677
+ }
678
+
679
+ RequestClass, field_name = execute_request_mapping[type(params)]
680
+ return RequestClass(**{field_name: params}) # type: ignore