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
@@ -0,0 +1,560 @@
1
+ """Generated wrapper for Checkpoint Solidity contract."""
2
+
3
+ # pylint: disable=too-many-arguments
4
+
5
+ import json
6
+ from typing import ( # pylint: disable=unused-import
7
+ Any,
8
+ List,
9
+ Optional,
10
+ Tuple,
11
+ Union,
12
+ )
13
+
14
+ from eth_utils import to_checksum_address
15
+ from mypy_extensions import TypedDict # pylint: disable=unused-import
16
+ from hexbytes import HexBytes
17
+ from web3 import Web3
18
+ from web3.datastructures import AttributeDict
19
+ from web3.providers.base import BaseProvider
20
+
21
+ from zero_ex.contract_wrappers.bases import ContractMethod, Validator
22
+ from zero_ex.contract_wrappers.tx_params import TxParams
23
+
24
+
25
+ # Try to import a custom validator class definition; if there isn't one,
26
+ # declare one that we can instantiate for the default argument to the
27
+ # constructor for Checkpoint below.
28
+ try:
29
+ # both mypy and pylint complain about what we're doing here, but this
30
+ # works just fine, so their messages have been disabled here.
31
+ from . import ( # type: ignore # pylint: disable=import-self
32
+ CheckpointValidator,
33
+ )
34
+ except ImportError:
35
+
36
+ class CheckpointValidator( # type: ignore
37
+ Validator
38
+ ):
39
+ """No-op input validator."""
40
+
41
+
42
+ try:
43
+ from .middleware import MIDDLEWARE # type: ignore
44
+ except ImportError:
45
+ pass
46
+
47
+
48
+ class CheckpointDefsCheckpointData(TypedDict):
49
+ """Python representation of a tuple or struct.
50
+
51
+ Solidity compiler output does not include the names of structs that appear
52
+ in method definitions. A tuple found in an ABI may have been written in
53
+ Solidity as a literal, anonymous tuple, or it may have been written as a
54
+ named `struct`:code:, but there is no way to tell from the compiler
55
+ output. This class represents a tuple that appeared in a method
56
+ definition. Its name is derived from a hash of that tuple's field names,
57
+ and every method whose ABI refers to a tuple with that same list of field
58
+ names will have a generated wrapper method that refers to this class.
59
+
60
+ Any members of type `bytes`:code: should be encoded as UTF-8, which can be
61
+ accomplished via `str.encode("utf_8")`:code:
62
+ """
63
+
64
+ blockNumber: int
65
+
66
+ blockHash: Union[bytes, str]
67
+
68
+ stateRoot: Union[bytes, str]
69
+
70
+ transactionRoot: Union[bytes, str]
71
+
72
+
73
+ class CheckpointDefsCheckpointSubmission(TypedDict):
74
+ """Python representation of a tuple or struct.
75
+
76
+ Solidity compiler output does not include the names of structs that appear
77
+ in method definitions. A tuple found in an ABI may have been written in
78
+ Solidity as a literal, anonymous tuple, or it may have been written as a
79
+ named `struct`:code:, but there is no way to tell from the compiler
80
+ output. This class represents a tuple that appeared in a method
81
+ definition. Its name is derived from a hash of that tuple's field names,
82
+ and every method whose ABI refers to a tuple with that same list of field
83
+ names will have a generated wrapper method that refers to this class.
84
+
85
+ Any members of type `bytes`:code: should be encoded as UTF-8, which can be
86
+ accomplished via `str.encode("utf_8")`:code:
87
+ """
88
+
89
+ checkpointData: CheckpointDefsCheckpointData
90
+
91
+ signatures: List[Union[bytes, str]]
92
+
93
+
94
+ class CheckpointMethod(ContractMethod): # pylint: disable=invalid-name
95
+ """Various interfaces to the checkpoint method."""
96
+
97
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
98
+ """Persist instance data."""
99
+ super().__init__(web3_or_provider, contract_address, validator)
100
+ self._underlying_method = contract_function
101
+
102
+ def validate_and_normalize_inputs(self, majority_checkpoint_submission: CheckpointDefsCheckpointSubmission, minority_checkpoint_submissions: List[CheckpointDefsCheckpointSubmission], epoch_id: int):
103
+ """Validate the inputs to the checkpoint method."""
104
+ self.validator.assert_valid(
105
+ method_name='checkpoint',
106
+ parameter_name='_majorityCheckpointSubmission',
107
+ argument_value=majority_checkpoint_submission,
108
+ )
109
+ self.validator.assert_valid(
110
+ method_name='checkpoint',
111
+ parameter_name='_minorityCheckpointSubmissions',
112
+ argument_value=minority_checkpoint_submissions,
113
+ )
114
+ self.validator.assert_valid(
115
+ method_name='checkpoint',
116
+ parameter_name='_epochId',
117
+ argument_value=epoch_id,
118
+ )
119
+ return (majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id)
120
+
121
+ def call(self, majority_checkpoint_submission: CheckpointDefsCheckpointSubmission, minority_checkpoint_submissions: List[CheckpointDefsCheckpointSubmission], epoch_id: int, tx_params: Optional[TxParams] = None) -> None:
122
+ """Execute underlying contract method via eth_call.
123
+
124
+ :param _epochId: The epoch id of the checkpoint being submitted. This
125
+ id must monotonically increase, but we permit skips in the
126
+ id.
127
+ :param _majorityCheckpointSubmission: Structured data that contains a
128
+ state root, a transaction root, block data, and signatures of
129
+ signers that have attested to the checkpoint.
130
+ :param _minorityCheckpointSubmissions: Same as the valid checkpoints
131
+ but the hashes don't match that of the majority checkpoint.
132
+ :param tx_params: transaction parameters
133
+ :returns: the return value of the underlying method.
134
+ """
135
+ (majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id) = self.validate_and_normalize_inputs(majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id)
136
+ tx_params = super().normalize_tx_params(tx_params)
137
+ self._underlying_method(majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id).call(tx_params.as_dict())
138
+
139
+ def send_transaction(self, majority_checkpoint_submission: CheckpointDefsCheckpointSubmission, minority_checkpoint_submissions: List[CheckpointDefsCheckpointSubmission], epoch_id: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
140
+ """Execute underlying contract method via eth_sendTransaction.
141
+
142
+ :param _epochId: The epoch id of the checkpoint being submitted. This
143
+ id must monotonically increase, but we permit skips in the
144
+ id.
145
+ :param _majorityCheckpointSubmission: Structured data that contains a
146
+ state root, a transaction root, block data, and signatures of
147
+ signers that have attested to the checkpoint.
148
+ :param _minorityCheckpointSubmissions: Same as the valid checkpoints
149
+ but the hashes don't match that of the majority checkpoint.
150
+ :param tx_params: transaction parameters
151
+ """
152
+ (majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id) = self.validate_and_normalize_inputs(majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id)
153
+ tx_params = super().normalize_tx_params(tx_params)
154
+ return self._underlying_method(majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id).transact(tx_params.as_dict())
155
+
156
+ def build_transaction(self, majority_checkpoint_submission: CheckpointDefsCheckpointSubmission, minority_checkpoint_submissions: List[CheckpointDefsCheckpointSubmission], epoch_id: int, tx_params: Optional[TxParams] = None) -> dict:
157
+ """Construct calldata to be used as input to the method."""
158
+ (majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id) = self.validate_and_normalize_inputs(majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id)
159
+ tx_params = super().normalize_tx_params(tx_params)
160
+ return self._underlying_method(majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id).build_transaction(tx_params.as_dict())
161
+
162
+ def estimate_gas(self, majority_checkpoint_submission: CheckpointDefsCheckpointSubmission, minority_checkpoint_submissions: List[CheckpointDefsCheckpointSubmission], epoch_id: int, tx_params: Optional[TxParams] = None) -> int:
163
+ """Estimate gas consumption of method call."""
164
+ (majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id) = self.validate_and_normalize_inputs(majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id)
165
+ tx_params = super().normalize_tx_params(tx_params)
166
+ return self._underlying_method(majority_checkpoint_submission, minority_checkpoint_submissions, epoch_id).estimate_gas(tx_params.as_dict())
167
+
168
+ class GetCheckpointInfoMethod(ContractMethod): # pylint: disable=invalid-name
169
+ """Various interfaces to the getCheckpointInfo method."""
170
+
171
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
172
+ """Persist instance data."""
173
+ super().__init__(web3_or_provider, contract_address)
174
+ self._underlying_method = contract_function
175
+
176
+ def call(self, tx_params: Optional[TxParams] = None) -> Tuple[int, int]:
177
+ """Execute underlying contract method via eth_call.
178
+
179
+ :param tx_params: transaction parameters
180
+ :returns: the return value of the underlying method.
181
+ """
182
+ tx_params = super().normalize_tx_params(tx_params)
183
+ returned = self._underlying_method().call(tx_params.as_dict())
184
+ return (returned[0],returned[1],)
185
+
186
+ def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
187
+ """Execute underlying contract method via eth_sendTransaction.
188
+
189
+ :param tx_params: transaction parameters
190
+ """
191
+ tx_params = super().normalize_tx_params(tx_params)
192
+ return self._underlying_method().transact(tx_params.as_dict())
193
+
194
+ def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
195
+ """Construct calldata to be used as input to the method."""
196
+ tx_params = super().normalize_tx_params(tx_params)
197
+ return self._underlying_method().build_transaction(tx_params.as_dict())
198
+
199
+ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
200
+ """Estimate gas consumption of method call."""
201
+ tx_params = super().normalize_tx_params(tx_params)
202
+ return self._underlying_method().estimate_gas(tx_params.as_dict())
203
+
204
+ class GetLatestCheckpointMethod(ContractMethod): # pylint: disable=invalid-name
205
+ """Various interfaces to the getLatestCheckpoint method."""
206
+
207
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
208
+ """Persist instance data."""
209
+ super().__init__(web3_or_provider, contract_address)
210
+ self._underlying_method = contract_function
211
+
212
+ def call(self, tx_params: Optional[TxParams] = None) -> Tuple[int, Union[bytes, str], Union[bytes, str], int]:
213
+ """Execute underlying contract method via eth_call.
214
+
215
+ :param tx_params: transaction parameters
216
+ :returns: the return value of the underlying method.
217
+ """
218
+ tx_params = super().normalize_tx_params(tx_params)
219
+ returned = self._underlying_method().call(tx_params.as_dict())
220
+ return (returned[0],returned[1],returned[2],returned[3],)
221
+
222
+ def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
223
+ """Execute underlying contract method via eth_sendTransaction.
224
+
225
+ :param tx_params: transaction parameters
226
+ """
227
+ tx_params = super().normalize_tx_params(tx_params)
228
+ return self._underlying_method().transact(tx_params.as_dict())
229
+
230
+ def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
231
+ """Construct calldata to be used as input to the method."""
232
+ tx_params = super().normalize_tx_params(tx_params)
233
+ return self._underlying_method().build_transaction(tx_params.as_dict())
234
+
235
+ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
236
+ """Estimate gas consumption of method call."""
237
+ tx_params = super().normalize_tx_params(tx_params)
238
+ return self._underlying_method().estimate_gas(tx_params.as_dict())
239
+
240
+ class InitializeMethod(ContractMethod): # pylint: disable=invalid-name
241
+ """Various interfaces to the initialize method."""
242
+
243
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
244
+ """Persist instance data."""
245
+ super().__init__(web3_or_provider, contract_address, validator)
246
+ self._underlying_method = contract_function
247
+
248
+ def validate_and_normalize_inputs(self, consensus_threshold: int, quorum: int):
249
+ """Validate the inputs to the initialize method."""
250
+ self.validator.assert_valid(
251
+ method_name='initialize',
252
+ parameter_name='_consensusThreshold',
253
+ argument_value=consensus_threshold,
254
+ )
255
+ self.validator.assert_valid(
256
+ method_name='initialize',
257
+ parameter_name='_quorum',
258
+ argument_value=quorum,
259
+ )
260
+ return (consensus_threshold, quorum)
261
+
262
+ def call(self, consensus_threshold: int, quorum: int, tx_params: Optional[TxParams] = None) -> None:
263
+ """Execute underlying contract method via eth_call.
264
+
265
+ This function is intended to be the initialization target of the
266
+ diamond cut function. This function is not included in the selectors
267
+ being added to the diamond, meaning it cannot be called again.
268
+
269
+ :param _consensusThreshold: The initial consensus threshold.
270
+ :param _quorum: The quorum that will be enforced as a consensus rule.
271
+ :param tx_params: transaction parameters
272
+ :returns: the return value of the underlying method.
273
+ """
274
+ (consensus_threshold, quorum) = self.validate_and_normalize_inputs(consensus_threshold, quorum)
275
+ tx_params = super().normalize_tx_params(tx_params)
276
+ self._underlying_method(consensus_threshold, quorum).call(tx_params.as_dict())
277
+
278
+ def send_transaction(self, consensus_threshold: int, quorum: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
279
+ """Execute underlying contract method via eth_sendTransaction.
280
+
281
+ This function is intended to be the initialization target of the
282
+ diamond cut function. This function is not included in the selectors
283
+ being added to the diamond, meaning it cannot be called again.
284
+
285
+ :param _consensusThreshold: The initial consensus threshold.
286
+ :param _quorum: The quorum that will be enforced as a consensus rule.
287
+ :param tx_params: transaction parameters
288
+ """
289
+ (consensus_threshold, quorum) = self.validate_and_normalize_inputs(consensus_threshold, quorum)
290
+ tx_params = super().normalize_tx_params(tx_params)
291
+ return self._underlying_method(consensus_threshold, quorum).transact(tx_params.as_dict())
292
+
293
+ def build_transaction(self, consensus_threshold: int, quorum: int, tx_params: Optional[TxParams] = None) -> dict:
294
+ """Construct calldata to be used as input to the method."""
295
+ (consensus_threshold, quorum) = self.validate_and_normalize_inputs(consensus_threshold, quorum)
296
+ tx_params = super().normalize_tx_params(tx_params)
297
+ return self._underlying_method(consensus_threshold, quorum).build_transaction(tx_params.as_dict())
298
+
299
+ def estimate_gas(self, consensus_threshold: int, quorum: int, tx_params: Optional[TxParams] = None) -> int:
300
+ """Estimate gas consumption of method call."""
301
+ (consensus_threshold, quorum) = self.validate_and_normalize_inputs(consensus_threshold, quorum)
302
+ tx_params = super().normalize_tx_params(tx_params)
303
+ return self._underlying_method(consensus_threshold, quorum).estimate_gas(tx_params.as_dict())
304
+
305
+ class SetConsensusThresholdMethod(ContractMethod): # pylint: disable=invalid-name
306
+ """Various interfaces to the setConsensusThreshold method."""
307
+
308
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
309
+ """Persist instance data."""
310
+ super().__init__(web3_or_provider, contract_address, validator)
311
+ self._underlying_method = contract_function
312
+
313
+ def validate_and_normalize_inputs(self, consensus_threshold: int):
314
+ """Validate the inputs to the setConsensusThreshold method."""
315
+ self.validator.assert_valid(
316
+ method_name='setConsensusThreshold',
317
+ parameter_name='_consensusThreshold',
318
+ argument_value=consensus_threshold,
319
+ )
320
+ return (consensus_threshold)
321
+
322
+ def call(self, consensus_threshold: int, tx_params: Optional[TxParams] = None) -> None:
323
+ """Execute underlying contract method via eth_call.
324
+
325
+ :param _consensusThreshold: A number between 50 and 100 that represents
326
+ the percentage of valid signers that have to agree for a
327
+ submission to be considered valid.
328
+ :param tx_params: transaction parameters
329
+ :returns: the return value of the underlying method.
330
+ """
331
+ (consensus_threshold) = self.validate_and_normalize_inputs(consensus_threshold)
332
+ tx_params = super().normalize_tx_params(tx_params)
333
+ self._underlying_method(consensus_threshold).call(tx_params.as_dict())
334
+
335
+ def send_transaction(self, consensus_threshold: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
336
+ """Execute underlying contract method via eth_sendTransaction.
337
+
338
+ :param _consensusThreshold: A number between 50 and 100 that represents
339
+ the percentage of valid signers that have to agree for a
340
+ submission to be considered valid.
341
+ :param tx_params: transaction parameters
342
+ """
343
+ (consensus_threshold) = self.validate_and_normalize_inputs(consensus_threshold)
344
+ tx_params = super().normalize_tx_params(tx_params)
345
+ return self._underlying_method(consensus_threshold).transact(tx_params.as_dict())
346
+
347
+ def build_transaction(self, consensus_threshold: int, tx_params: Optional[TxParams] = None) -> dict:
348
+ """Construct calldata to be used as input to the method."""
349
+ (consensus_threshold) = self.validate_and_normalize_inputs(consensus_threshold)
350
+ tx_params = super().normalize_tx_params(tx_params)
351
+ return self._underlying_method(consensus_threshold).build_transaction(tx_params.as_dict())
352
+
353
+ def estimate_gas(self, consensus_threshold: int, tx_params: Optional[TxParams] = None) -> int:
354
+ """Estimate gas consumption of method call."""
355
+ (consensus_threshold) = self.validate_and_normalize_inputs(consensus_threshold)
356
+ tx_params = super().normalize_tx_params(tx_params)
357
+ return self._underlying_method(consensus_threshold).estimate_gas(tx_params.as_dict())
358
+
359
+ class SetQuorumMethod(ContractMethod): # pylint: disable=invalid-name
360
+ """Various interfaces to the setQuorum method."""
361
+
362
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
363
+ """Persist instance data."""
364
+ super().__init__(web3_or_provider, contract_address, validator)
365
+ self._underlying_method = contract_function
366
+
367
+ def validate_and_normalize_inputs(self, quorum: int):
368
+ """Validate the inputs to the setQuorum method."""
369
+ self.validator.assert_valid(
370
+ method_name='setQuorum',
371
+ parameter_name='_quorum',
372
+ argument_value=quorum,
373
+ )
374
+ return (quorum)
375
+
376
+ def call(self, quorum: int, tx_params: Optional[TxParams] = None) -> None:
377
+ """Execute underlying contract method via eth_call.
378
+
379
+ :param _quorum: The quorum value that will be enforced for consensus.
380
+ :param tx_params: transaction parameters
381
+ :returns: the return value of the underlying method.
382
+ """
383
+ (quorum) = self.validate_and_normalize_inputs(quorum)
384
+ tx_params = super().normalize_tx_params(tx_params)
385
+ self._underlying_method(quorum).call(tx_params.as_dict())
386
+
387
+ def send_transaction(self, quorum: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
388
+ """Execute underlying contract method via eth_sendTransaction.
389
+
390
+ :param _quorum: The quorum value that will be enforced for consensus.
391
+ :param tx_params: transaction parameters
392
+ """
393
+ (quorum) = self.validate_and_normalize_inputs(quorum)
394
+ tx_params = super().normalize_tx_params(tx_params)
395
+ return self._underlying_method(quorum).transact(tx_params.as_dict())
396
+
397
+ def build_transaction(self, quorum: int, tx_params: Optional[TxParams] = None) -> dict:
398
+ """Construct calldata to be used as input to the method."""
399
+ (quorum) = self.validate_and_normalize_inputs(quorum)
400
+ tx_params = super().normalize_tx_params(tx_params)
401
+ return self._underlying_method(quorum).build_transaction(tx_params.as_dict())
402
+
403
+ def estimate_gas(self, quorum: int, tx_params: Optional[TxParams] = None) -> int:
404
+ """Estimate gas consumption of method call."""
405
+ (quorum) = self.validate_and_normalize_inputs(quorum)
406
+ tx_params = super().normalize_tx_params(tx_params)
407
+ return self._underlying_method(quorum).estimate_gas(tx_params.as_dict())
408
+
409
+ # pylint: disable=too-many-public-methods,too-many-instance-attributes
410
+ class Checkpoint:
411
+ """Wrapper class for Checkpoint Solidity contract."""
412
+ checkpoint: CheckpointMethod
413
+ """Constructor-initialized instance of
414
+ :class:`CheckpointMethod`.
415
+ """
416
+
417
+ get_checkpoint_info: GetCheckpointInfoMethod
418
+ """Constructor-initialized instance of
419
+ :class:`GetCheckpointInfoMethod`.
420
+ """
421
+
422
+ get_latest_checkpoint: GetLatestCheckpointMethod
423
+ """Constructor-initialized instance of
424
+ :class:`GetLatestCheckpointMethod`.
425
+ """
426
+
427
+ initialize: InitializeMethod
428
+ """Constructor-initialized instance of
429
+ :class:`InitializeMethod`.
430
+ """
431
+
432
+ set_consensus_threshold: SetConsensusThresholdMethod
433
+ """Constructor-initialized instance of
434
+ :class:`SetConsensusThresholdMethod`.
435
+ """
436
+
437
+ set_quorum: SetQuorumMethod
438
+ """Constructor-initialized instance of
439
+ :class:`SetQuorumMethod`.
440
+ """
441
+
442
+
443
+ def __init__(
444
+ self,
445
+ web3_or_provider: Union[Web3, BaseProvider],
446
+ contract_address: str,
447
+ validator: CheckpointValidator = None,
448
+ ):
449
+ """Get an instance of wrapper for smart contract.
450
+
451
+ :param web3_or_provider: Either an instance of `web3.Web3`:code: or
452
+ `web3.providers.base.BaseProvider`:code:
453
+ :param contract_address: where the contract has been deployed
454
+ :param validator: for validation of method inputs.
455
+ """
456
+ # pylint: disable=too-many-statements
457
+
458
+ self.contract_address = contract_address
459
+
460
+ if not validator:
461
+ validator = CheckpointValidator(web3_or_provider, contract_address)
462
+
463
+ web3 = None
464
+ if isinstance(web3_or_provider, BaseProvider):
465
+ web3 = Web3(web3_or_provider)
466
+ elif isinstance(web3_or_provider, Web3):
467
+ web3 = web3_or_provider
468
+ else:
469
+ raise TypeError(
470
+ "Expected parameter 'web3_or_provider' to be an instance of either"
471
+ + " Web3 or BaseProvider"
472
+ )
473
+
474
+ # if any middleware was imported, inject it
475
+ try:
476
+ MIDDLEWARE
477
+ except NameError:
478
+ pass
479
+ else:
480
+ try:
481
+ for middleware in MIDDLEWARE:
482
+ web3.middleware_onion.inject(
483
+ middleware['function'], layer=middleware['layer'],
484
+ )
485
+ except ValueError as value_error:
486
+ if value_error.args == ("You can't add the same un-named instance twice",):
487
+ pass
488
+
489
+ self._web3_eth = web3.eth
490
+
491
+ functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=Checkpoint.abi()).functions
492
+
493
+ self.checkpoint = CheckpointMethod(web3_or_provider, contract_address, functions.checkpoint, validator)
494
+
495
+ self.get_checkpoint_info = GetCheckpointInfoMethod(web3_or_provider, contract_address, functions.getCheckpointInfo)
496
+
497
+ self.get_latest_checkpoint = GetLatestCheckpointMethod(web3_or_provider, contract_address, functions.getLatestCheckpoint)
498
+
499
+ self.initialize = InitializeMethod(web3_or_provider, contract_address, functions.initialize, validator)
500
+
501
+ self.set_consensus_threshold = SetConsensusThresholdMethod(web3_or_provider, contract_address, functions.setConsensusThreshold, validator)
502
+
503
+ self.set_quorum = SetQuorumMethod(web3_or_provider, contract_address, functions.setQuorum, validator)
504
+
505
+ def get_checkpoint_initialized_event(
506
+ self, tx_hash: Union[HexBytes, bytes]
507
+ ) -> Tuple[AttributeDict]:
508
+ """Get log entry for CheckpointInitialized event.
509
+
510
+ :param tx_hash: hash of transaction emitting CheckpointInitialized
511
+ event
512
+ """
513
+ tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
514
+ return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Checkpoint.abi()).events.CheckpointInitialized().process_receipt(tx_receipt)
515
+ def get_checkpointed_event(
516
+ self, tx_hash: Union[HexBytes, bytes]
517
+ ) -> Tuple[AttributeDict]:
518
+ """Get log entry for Checkpointed event.
519
+
520
+ :param tx_hash: hash of transaction emitting Checkpointed event
521
+ """
522
+ tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
523
+ return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Checkpoint.abi()).events.Checkpointed().process_receipt(tx_receipt)
524
+ def get_consensus_threshold_set_event(
525
+ self, tx_hash: Union[HexBytes, bytes]
526
+ ) -> Tuple[AttributeDict]:
527
+ """Get log entry for ConsensusThresholdSet event.
528
+
529
+ :param tx_hash: hash of transaction emitting ConsensusThresholdSet
530
+ event
531
+ """
532
+ tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
533
+ return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Checkpoint.abi()).events.ConsensusThresholdSet().process_receipt(tx_receipt)
534
+ def get_custodians_jailed_event(
535
+ self, tx_hash: Union[HexBytes, bytes]
536
+ ) -> Tuple[AttributeDict]:
537
+ """Get log entry for CustodiansJailed event.
538
+
539
+ :param tx_hash: hash of transaction emitting CustodiansJailed event
540
+ """
541
+ tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
542
+ return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Checkpoint.abi()).events.CustodiansJailed().process_receipt(tx_receipt)
543
+ def get_quorum_set_event(
544
+ self, tx_hash: Union[HexBytes, bytes]
545
+ ) -> Tuple[AttributeDict]:
546
+ """Get log entry for QuorumSet event.
547
+
548
+ :param tx_hash: hash of transaction emitting QuorumSet event
549
+ """
550
+ tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
551
+ return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=Checkpoint.abi()).events.QuorumSet().process_receipt(tx_receipt)
552
+
553
+ @staticmethod
554
+ def abi():
555
+ """Return the ABI to the underlying contract."""
556
+ return json.loads(
557
+ '[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint128","name":"consensusThreshold","type":"uint128"},{"indexed":true,"internalType":"uint128","name":"quorum","type":"uint128"}],"name":"CheckpointInitialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"stateRoot","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"transactionRoot","type":"bytes32"},{"indexed":true,"internalType":"uint128","name":"epochId","type":"uint128"},{"indexed":false,"internalType":"address[]","name":"custodians","type":"address[]"},{"indexed":false,"internalType":"uint128[]","name":"bonds","type":"uint128[]"},{"indexed":false,"internalType":"address","name":"submitter","type":"address"}],"name":"Checkpointed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"consensusThreshold","type":"uint128"}],"name":"ConsensusThresholdSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address[]","name":"custodians","type":"address[]"}],"name":"CustodiansJailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"quorum","type":"uint128"}],"name":"QuorumSet","type":"event"},{"inputs":[{"components":[{"components":[{"internalType":"uint128","name":"blockNumber","type":"uint128"},{"internalType":"bytes32","name":"blockHash","type":"bytes32"},{"internalType":"bytes32","name":"stateRoot","type":"bytes32"},{"internalType":"bytes32","name":"transactionRoot","type":"bytes32"}],"internalType":"struct CheckpointDefs.CheckpointData","name":"checkpointData","type":"tuple"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"internalType":"struct CheckpointDefs.CheckpointSubmission","name":"_majorityCheckpointSubmission","type":"tuple"},{"components":[{"components":[{"internalType":"uint128","name":"blockNumber","type":"uint128"},{"internalType":"bytes32","name":"blockHash","type":"bytes32"},{"internalType":"bytes32","name":"stateRoot","type":"bytes32"},{"internalType":"bytes32","name":"transactionRoot","type":"bytes32"}],"internalType":"struct CheckpointDefs.CheckpointData","name":"checkpointData","type":"tuple"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"}],"internalType":"struct CheckpointDefs.CheckpointSubmission[]","name":"_minorityCheckpointSubmissions","type":"tuple[]"},{"internalType":"uint128","name":"_epochId","type":"uint128"}],"name":"checkpoint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getCheckpointInfo","outputs":[{"internalType":"uint128","name":"","type":"uint128"},{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLatestCheckpoint","outputs":[{"internalType":"uint128","name":"","type":"uint128"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"_consensusThreshold","type":"uint128"},{"internalType":"uint128","name":"_quorum","type":"uint128"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"_consensusThreshold","type":"uint128"}],"name":"setConsensusThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"_quorum","type":"uint128"}],"name":"setQuorum","outputs":[],"stateMutability":"nonpayable","type":"function"}]' # noqa: E501 (line-too-long)
558
+ )
559
+
560
+ # pylint: disable=too-many-lines