nado-protocol 0.1.6__py3-none-any.whl → 0.2.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.
@@ -17,6 +17,19 @@ def to_pow_10(x: int, pow: int) -> int:
17
17
  return x * 10**pow
18
18
 
19
19
 
20
+ def to_x6(x: float) -> int:
21
+ """
22
+ Converts a float to a fixed point of 1e6.
23
+
24
+ Args:
25
+ x (float): Float value to convert.
26
+
27
+ Returns:
28
+ int: Fixed point value represented as an integer.
29
+ """
30
+ return int(Decimal(str(x)) * Decimal(10**6))
31
+
32
+
20
33
  def to_x18(x: float) -> int:
21
34
  """
22
35
  Converts a float to a fixed point of 1e18.
@@ -45,6 +58,19 @@ def from_pow_10(x: int, pow: int) -> float:
45
58
  return float(x) / 10**pow
46
59
 
47
60
 
61
+ def from_x6(x: int) -> float:
62
+ """
63
+ Reverts integer from power of 10^6 format.
64
+
65
+ Args:
66
+ x (int): Converted value.
67
+
68
+ Returns:
69
+ float: Original value.
70
+ """
71
+ return from_pow_10(x, 6)
72
+
73
+
48
74
  def from_x18(x: int) -> float:
49
75
  """
50
76
  Reverts integer from power of 10^18 format.
@@ -4,13 +4,13 @@ from nado_protocol.utils.expiration import OrderType
4
4
 
5
5
 
6
6
  # Order appendix version
7
- APPENDIX_VERSION = 0
7
+ APPENDIX_VERSION = 1
8
8
 
9
9
 
10
10
  class AppendixBitFields:
11
11
  # | value | reserved | trigger | reduce only | order type| isolated | version |
12
- # | 96 bits | 18 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
13
- # | 127..32 | 31..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
12
+ # | 64 bits | 50 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
13
+ # | 127..64 | 63..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
14
14
 
15
15
  # Bit positions (from LSB to MSB)
16
16
  VERSION_BITS = 8 # bits 7..0
@@ -18,8 +18,8 @@ class AppendixBitFields:
18
18
  ORDER_TYPE_BITS = 2 # bits 10..9
19
19
  REDUCE_ONLY_BITS = 1 # bit 11
20
20
  TRIGGER_TYPE_BITS = 2 # bits 13..12
21
- RESERVED_BITS = 18 # bits 31..14
22
- VALUE_BITS = 96 # bits 127..32 (for isolated margin or TWAP data)
21
+ RESERVED_BITS = 50 # bits 63..14
22
+ VALUE_BITS = 64 # bits 127..64 (for isolated margin or TWAP data)
23
23
 
24
24
  # Bit masks
25
25
  VERSION_MASK = (1 << VERSION_BITS) - 1
@@ -37,7 +37,7 @@ class AppendixBitFields:
37
37
  REDUCE_ONLY_SHIFT = 11
38
38
  TRIGGER_TYPE_SHIFT = 12
39
39
  RESERVED_SHIFT = 14
40
- VALUE_SHIFT = 32
40
+ VALUE_SHIFT = 64
41
41
 
42
42
 
43
43
  class OrderAppendixTriggerType(IntEnum):
@@ -51,22 +51,19 @@ class OrderAppendixTriggerType(IntEnum):
51
51
 
52
52
 
53
53
  class TWAPBitFields:
54
- """Bit field definitions for TWAP value packing within the 96-bit value field."""
54
+ """Bit field definitions for TWAP value packing within the 64-bit value field."""
55
55
 
56
- # Bit layout (MSB → LSB): | times (32 bits) | slippage_x6 (32 bits) | reserved (32 bits) |
56
+ # Bit layout (MSB → LSB): | times (32 bits) | slippage_x6 (32 bits) |
57
57
  TIMES_BITS = 32
58
58
  SLIPPAGE_BITS = 32
59
- RESERVED_BITS = 32
60
59
 
61
60
  # Bit masks
62
61
  TIMES_MASK = (1 << TIMES_BITS) - 1
63
62
  SLIPPAGE_MASK = (1 << SLIPPAGE_BITS) - 1
64
- RESERVED_MASK = (1 << RESERVED_BITS) - 1
65
63
 
66
- # Bit shift positions (within the 96-bit value field)
67
- RESERVED_SHIFT = 0
68
- SLIPPAGE_SHIFT = 32
69
- TIMES_SHIFT = 64
64
+ # Bit shift positions (within the 64-bit value field)
65
+ SLIPPAGE_SHIFT = 0
66
+ TIMES_SHIFT = 32
70
67
 
71
68
  # Slippage scaling factor (6 decimal places)
72
69
  SLIPPAGE_SCALE = 1_000_000
@@ -74,30 +71,27 @@ class TWAPBitFields:
74
71
 
75
72
  def pack_twap_appendix_value(times: int, slippage_frac: float) -> int:
76
73
  """
77
- Packs TWAP order fields into a 96-bit integer for the appendix.
74
+ Packs TWAP order fields into a 64-bit integer for the appendix.
78
75
 
79
76
  Bit layout (MSB → LSB):
80
- | times | slippage_x6 | reserved |
81
- |-----------|-------------|----------|
82
- | 95..64 | 63..32 | 31..0 |
83
- | 32 bits | 32 bits | 32 bits |
77
+ | times | slippage_x6 |
78
+ |-----------|-------------|
79
+ | 63..32 | 31..0 |
80
+ | 32 bits | 32 bits |
84
81
  """
85
82
  slippage_x6 = int(slippage_frac * TWAPBitFields.SLIPPAGE_SCALE)
86
- reserved = 0 # reserved 32-bit field (currently unused)
87
83
 
88
- return (
89
- ((times & TWAPBitFields.TIMES_MASK) << TWAPBitFields.TIMES_SHIFT)
90
- | ((slippage_x6 & TWAPBitFields.SLIPPAGE_MASK) << TWAPBitFields.SLIPPAGE_SHIFT)
91
- | ((reserved & TWAPBitFields.RESERVED_MASK) << TWAPBitFields.RESERVED_SHIFT)
84
+ return ((times & TWAPBitFields.TIMES_MASK) << TWAPBitFields.TIMES_SHIFT) | (
85
+ (slippage_x6 & TWAPBitFields.SLIPPAGE_MASK) << TWAPBitFields.SLIPPAGE_SHIFT
92
86
  )
93
87
 
94
88
 
95
89
  def unpack_twap_appendix_value(value: int) -> tuple[int, float]:
96
90
  """
97
- Unpacks a 96-bit integer into TWAP order fields.
91
+ Unpacks a 64-bit integer into TWAP order fields.
98
92
 
99
93
  Args:
100
- value (int): The 96-bit value to unpack.
94
+ value (int): The 64-bit value to unpack.
101
95
 
102
96
  Returns:
103
97
  tuple[int, float]: Number of TWAP executions and slippage fraction.
@@ -185,9 +179,9 @@ def build_appendix(
185
179
  trigger_value & AppendixBitFields.TRIGGER_TYPE_MASK
186
180
  ) << AppendixBitFields.TRIGGER_TYPE_SHIFT
187
181
 
188
- # Handle upper bits (127..32) based on order type
182
+ # Handle upper bits (127..64) based on order type
189
183
  if isolated and isolated_margin is not None:
190
- # Isolated margin (bits 127..32)
184
+ # Isolated margin (bits 127..64)
191
185
  appendix |= (
192
186
  isolated_margin & AppendixBitFields.VALUE_MASK
193
187
  ) << AppendixBitFields.VALUE_SHIFT
@@ -195,7 +189,7 @@ def build_appendix(
195
189
  OrderAppendixTriggerType.TWAP,
196
190
  OrderAppendixTriggerType.TWAP_CUSTOM_AMOUNTS,
197
191
  ]:
198
- # TWAP value (bits 127..32) - 96 bits
192
+ # TWAP value (bits 127..64) - 64 bits
199
193
  # These are guaranteed to be non-None due to validation above
200
194
  assert twap_times is not None
201
195
  assert twap_slippage_frac is not None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nado-protocol
3
- Version: 0.1.6
3
+ Version: 0.2.0
4
4
  Summary: Nado Protocol SDK
5
5
  Keywords: nado protocol,nado sdk,nado protocol api
6
6
  Author: Jeury Mejia
@@ -47,10 +47,10 @@ nado_protocol/engine_client/types/models.py,sha256=hf9HD8rct2XZIqPznfydBq7jqKiJ3
47
47
  nado_protocol/engine_client/types/query.py,sha256=N6kPuWSUowMeZnUKpxF9NnMKZBKKe-0Q_B9ccFZkjQA,12185
48
48
  nado_protocol/engine_client/types/stream.py,sha256=F_AKqU4pClzUcM6D9Dc79f6RmraahJzj2-hQSXtQ0vQ,159
49
49
  nado_protocol/indexer_client/__init__.py,sha256=ea2exePtguCxJsBlisOQPtnFk8hRmFugeQAuSAaPhoc,922
50
- nado_protocol/indexer_client/query.py,sha256=onhEAoKtBIB_fPJcNLKJg8PnEiQ5qLtTGDwHRryLXhE,16124
50
+ nado_protocol/indexer_client/query.py,sha256=Tm4IYmU0T_9ayFTce8SMRPi_NN8QgyHDr4rFC3h7hSw,17102
51
51
  nado_protocol/indexer_client/types/__init__.py,sha256=r3-jxMjrFNbA1nMRSGZjsE3qypmyWab6k20_gasdwL4,3548
52
- nado_protocol/indexer_client/types/models.py,sha256=sh65JwaOeV8r2lENaVHopnoyP3-9VeqUa0qF4k84Tes,7527
53
- nado_protocol/indexer_client/types/query.py,sha256=WX7CzVzh239wbv4tQdPBKVal5wH6JPOEN0Bd_DPvzdI,18939
52
+ nado_protocol/indexer_client/types/models.py,sha256=vD1YHHeK15hcU5_O4al7001Fi-gTl6EARMuR-Y8stOc,7533
53
+ nado_protocol/indexer_client/types/query.py,sha256=JlI2TXjezTSgvaP8zzb3bO9GADzeQkay1CScO954RAw,19857
54
54
  nado_protocol/trigger_client/__init__.py,sha256=kD_WJWGOCDwX7GvGF5VGZibWR2uPYRcWpIWht31PYR4,545
55
55
  nado_protocol/trigger_client/execute.py,sha256=VkVla3SF6MX-ZJC_wZG72em41MPAKX-jv1_Lh4ydezU,15089
56
56
  nado_protocol/trigger_client/query.py,sha256=7M7opYEddNo0Wf9VQ7rha-WaoFQVv5F5OI-YLSRWrpk,2705
@@ -58,22 +58,24 @@ nado_protocol/trigger_client/types/__init__.py,sha256=Rj953ymGSNnVdOpDrwRuXmC_jh
58
58
  nado_protocol/trigger_client/types/execute.py,sha256=Ij_gCl3ZzhouWF7JxEY_U6hUbe9teOYp1ZfN0PDcOpM,2896
59
59
  nado_protocol/trigger_client/types/models.py,sha256=ZVDF3MFWoR39JBaTmSOTl1WnRnw46hjX-WN_a-g6zKk,1638
60
60
  nado_protocol/trigger_client/types/query.py,sha256=O6qhFLL2IREHc_mf-jFMyuVSzH1RuwjM-8noolLmEaQ,5288
61
- nado_protocol/utils/__init__.py,sha256=_nsvXmdiO3YmjSk7UG7df9qDoC8bd1H8_Au0lF-TwTA,1418
61
+ nado_protocol/utils/__init__.py,sha256=heFEgVHHce8nAqQcmEMR69aZ8aaJAYXukJ2-W_KTFwY,1446
62
62
  nado_protocol/utils/backend.py,sha256=UqmHN_jmTAOnRiUQcUTZUyTGeM7FwjauwSH5h8UxiLQ,3781
63
+ nado_protocol/utils/balance.py,sha256=Pf6tdcxZSn2Ou8M3XJnBIhsMB85-E7VkZDUIaMuEIbg,7435
63
64
  nado_protocol/utils/bytes32.py,sha256=FHeHs9Sf-S7GdFTF6ikuz_sEkM-fpRW-g3kbZawlMd4,5299
64
65
  nado_protocol/utils/enum.py,sha256=_Ij7Ai1H_Bj0OPBjmLhGvQjATXYyqD0DLqpUC-br99s,99
65
66
  nado_protocol/utils/exceptions.py,sha256=j5U-7JEQRnMTe_nFOrF2x-9kaYKgTrPBG9XkwXVm0cI,1644
66
67
  nado_protocol/utils/execute.py,sha256=zK3j2oTzFQlm-075thB_53iePjXpBnKF02RMEAqzl8I,11794
67
68
  nado_protocol/utils/expiration.py,sha256=8g0KI8v-Vnoj8rr-8ik3RxmGp9fXdiVbCVGof_2CDm4,532
68
69
  nado_protocol/utils/interest.py,sha256=pl5N2s7sux9Z0orPthdmFkldljIPwFTpLx1XC9k1oQk,2498
69
- nado_protocol/utils/math.py,sha256=hGbClWHRY5D0fIo5tHyT3_riWvf8WfsXJtqMs8pIQTs,1290
70
+ nado_protocol/utils/margin_manager.py,sha256=9U7gfLzhUUKwsHD3z1BahMAPNpMzYQNKkcQvpZ3IPo0,31767
71
+ nado_protocol/utils/math.py,sha256=TyuMb9ZpwfjLh5fMrNnr_QQWSl3bVZnjODglcxT_XTI,1771
70
72
  nado_protocol/utils/model.py,sha256=feU7cp0mSgNp-Z0dmC6VSFA6Mkjv3rNfoXdqsoZ7uGU,2087
71
73
  nado_protocol/utils/nonce.py,sha256=DHNn5mzXdJRope8QLcDCMFe7Bk4PXLoR9VaFopfse7I,886
72
- nado_protocol/utils/order.py,sha256=7Tul8pxg1Soxj9tI3HEgZV4bz-bW_b3CGARJKqu3_NM,11251
74
+ nado_protocol/utils/order.py,sha256=Q9TlcotvnB395dPhaKpn0EeN1WNTkpYBTUovlirr1_Y,10938
73
75
  nado_protocol/utils/subaccount.py,sha256=WJ7lgU2RekuzJAZH-hhCTbIBlRsl2oHozBm7OEMRV74,495
74
76
  nado_protocol/utils/time.py,sha256=tEwmrkc5VdzKLlgkJIAq2ce-nhrduJZNtVPydrrnTHs,360
75
77
  nado_protocol/utils/twap.py,sha256=hfBVK0CBa8m4uBArxTnNRoJr3o1rJucyopR_8_9gkOo,6197
76
- nado_protocol-0.1.6.dist-info/METADATA,sha256=-6aOZgk4baWDEyXErPbGPBxBareZZ6X571RiZBuA9i0,9558
77
- nado_protocol-0.1.6.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
78
- nado_protocol-0.1.6.dist-info/entry_points.txt,sha256=7xMbwQYtf2zfvzWdBaw5d5hp5TTv5Xia5WPsqxkvKuU,300
79
- nado_protocol-0.1.6.dist-info/RECORD,,
78
+ nado_protocol-0.2.0.dist-info/METADATA,sha256=wb87CI4zUkoaBhltwTo3WmXEWvCpPxEp5iRuYFrkKgw,9558
79
+ nado_protocol-0.2.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
80
+ nado_protocol-0.2.0.dist-info/entry_points.txt,sha256=Df0O9lFc-m0SyOh6_d9FHeG1OT-esxGm-p_z7rTT9h0,340
81
+ nado_protocol-0.2.0.dist-info/RECORD,,
@@ -3,6 +3,7 @@ client-sanity=sanity.nado_client:run
3
3
  contracts-sanity=sanity.contracts:run
4
4
  engine-sanity=sanity.engine_client:run
5
5
  indexer-sanity=sanity.indexer_client:run
6
+ margin-sanity=sanity.margin_manager:run
6
7
  rewards-sanity=sanity.rewards:run
7
8
  signing-sanity=sanity.signing:run
8
9
  test=pytest:main