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,1014 @@
1
+ """Generated wrapper for DummyToken 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 DummyToken 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
+ DummyTokenValidator,
33
+ )
34
+ except ImportError:
35
+
36
+ class DummyTokenValidator( # 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
+
49
+
50
+
51
+ class AllowanceMethod(ContractMethod): # pylint: disable=invalid-name
52
+ """Various interfaces to the allowance method."""
53
+
54
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
55
+ """Persist instance data."""
56
+ super().__init__(web3_or_provider, contract_address, validator)
57
+ self._underlying_method = contract_function
58
+
59
+ def validate_and_normalize_inputs(self, owner: str, spender: str):
60
+ """Validate the inputs to the allowance method."""
61
+ self.validator.assert_valid(
62
+ method_name='allowance',
63
+ parameter_name='owner',
64
+ argument_value=owner,
65
+ )
66
+ owner = self.validate_and_checksum_address(owner)
67
+ self.validator.assert_valid(
68
+ method_name='allowance',
69
+ parameter_name='spender',
70
+ argument_value=spender,
71
+ )
72
+ spender = self.validate_and_checksum_address(spender)
73
+ return (owner, spender)
74
+
75
+ def call(self, owner: str, spender: str, tx_params: Optional[TxParams] = None) -> int:
76
+ """Execute underlying contract method via eth_call.
77
+
78
+ See {IERC20-allowance}.
79
+
80
+ :param tx_params: transaction parameters
81
+ :returns: the return value of the underlying method.
82
+ """
83
+ (owner, spender) = self.validate_and_normalize_inputs(owner, spender)
84
+ tx_params = super().normalize_tx_params(tx_params)
85
+ returned = self._underlying_method(owner, spender).call(tx_params.as_dict())
86
+ return int(returned)
87
+
88
+ def send_transaction(self, owner: str, spender: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
89
+ """Execute underlying contract method via eth_sendTransaction.
90
+
91
+ See {IERC20-allowance}.
92
+
93
+ :param tx_params: transaction parameters
94
+ """
95
+ (owner, spender) = self.validate_and_normalize_inputs(owner, spender)
96
+ tx_params = super().normalize_tx_params(tx_params)
97
+ return self._underlying_method(owner, spender).transact(tx_params.as_dict())
98
+
99
+ def build_transaction(self, owner: str, spender: str, tx_params: Optional[TxParams] = None) -> dict:
100
+ """Construct calldata to be used as input to the method."""
101
+ (owner, spender) = self.validate_and_normalize_inputs(owner, spender)
102
+ tx_params = super().normalize_tx_params(tx_params)
103
+ return self._underlying_method(owner, spender).build_transaction(tx_params.as_dict())
104
+
105
+ def estimate_gas(self, owner: str, spender: str, tx_params: Optional[TxParams] = None) -> int:
106
+ """Estimate gas consumption of method call."""
107
+ (owner, spender) = self.validate_and_normalize_inputs(owner, spender)
108
+ tx_params = super().normalize_tx_params(tx_params)
109
+ return self._underlying_method(owner, spender).estimate_gas(tx_params.as_dict())
110
+
111
+ class ApproveMethod(ContractMethod): # pylint: disable=invalid-name
112
+ """Various interfaces to the approve method."""
113
+
114
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
115
+ """Persist instance data."""
116
+ super().__init__(web3_or_provider, contract_address, validator)
117
+ self._underlying_method = contract_function
118
+
119
+ def validate_and_normalize_inputs(self, spender: str, amount: int):
120
+ """Validate the inputs to the approve method."""
121
+ self.validator.assert_valid(
122
+ method_name='approve',
123
+ parameter_name='spender',
124
+ argument_value=spender,
125
+ )
126
+ spender = self.validate_and_checksum_address(spender)
127
+ self.validator.assert_valid(
128
+ method_name='approve',
129
+ parameter_name='amount',
130
+ argument_value=amount,
131
+ )
132
+ # safeguard against fractional inputs
133
+ amount = int(amount)
134
+ return (spender, amount)
135
+
136
+ def call(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> bool:
137
+ """Execute underlying contract method via eth_call.
138
+
139
+ See {IERC20-approve}. NOTE: If `amount` is the maximum `uint256`, the
140
+ allowance is not updated on `transferFrom`. This is semantically
141
+ equivalent to an infinite approval. Requirements: - `spender` cannot be
142
+ the zero address.
143
+
144
+ :param tx_params: transaction parameters
145
+ :returns: the return value of the underlying method.
146
+ """
147
+ (spender, amount) = self.validate_and_normalize_inputs(spender, amount)
148
+ tx_params = super().normalize_tx_params(tx_params)
149
+ returned = self._underlying_method(spender, amount).call(tx_params.as_dict())
150
+ return bool(returned)
151
+
152
+ def send_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
153
+ """Execute underlying contract method via eth_sendTransaction.
154
+
155
+ See {IERC20-approve}. NOTE: If `amount` is the maximum `uint256`, the
156
+ allowance is not updated on `transferFrom`. This is semantically
157
+ equivalent to an infinite approval. Requirements: - `spender` cannot be
158
+ the zero address.
159
+
160
+ :param tx_params: transaction parameters
161
+ """
162
+ (spender, amount) = self.validate_and_normalize_inputs(spender, amount)
163
+ tx_params = super().normalize_tx_params(tx_params)
164
+ return self._underlying_method(spender, amount).transact(tx_params.as_dict())
165
+
166
+ def build_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
167
+ """Construct calldata to be used as input to the method."""
168
+ (spender, amount) = self.validate_and_normalize_inputs(spender, amount)
169
+ tx_params = super().normalize_tx_params(tx_params)
170
+ return self._underlying_method(spender, amount).build_transaction(tx_params.as_dict())
171
+
172
+ def estimate_gas(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
173
+ """Estimate gas consumption of method call."""
174
+ (spender, amount) = self.validate_and_normalize_inputs(spender, amount)
175
+ tx_params = super().normalize_tx_params(tx_params)
176
+ return self._underlying_method(spender, amount).estimate_gas(tx_params.as_dict())
177
+
178
+ class BalanceOfMethod(ContractMethod): # pylint: disable=invalid-name
179
+ """Various interfaces to the balanceOf method."""
180
+
181
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
182
+ """Persist instance data."""
183
+ super().__init__(web3_or_provider, contract_address, validator)
184
+ self._underlying_method = contract_function
185
+
186
+ def validate_and_normalize_inputs(self, account: str):
187
+ """Validate the inputs to the balanceOf method."""
188
+ self.validator.assert_valid(
189
+ method_name='balanceOf',
190
+ parameter_name='account',
191
+ argument_value=account,
192
+ )
193
+ account = self.validate_and_checksum_address(account)
194
+ return (account)
195
+
196
+ def call(self, account: str, tx_params: Optional[TxParams] = None) -> int:
197
+ """Execute underlying contract method via eth_call.
198
+
199
+ See {IERC20-balanceOf}.
200
+
201
+ :param tx_params: transaction parameters
202
+ :returns: the return value of the underlying method.
203
+ """
204
+ (account) = self.validate_and_normalize_inputs(account)
205
+ tx_params = super().normalize_tx_params(tx_params)
206
+ returned = self._underlying_method(account).call(tx_params.as_dict())
207
+ return int(returned)
208
+
209
+ def send_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
210
+ """Execute underlying contract method via eth_sendTransaction.
211
+
212
+ See {IERC20-balanceOf}.
213
+
214
+ :param tx_params: transaction parameters
215
+ """
216
+ (account) = self.validate_and_normalize_inputs(account)
217
+ tx_params = super().normalize_tx_params(tx_params)
218
+ return self._underlying_method(account).transact(tx_params.as_dict())
219
+
220
+ def build_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> dict:
221
+ """Construct calldata to be used as input to the method."""
222
+ (account) = self.validate_and_normalize_inputs(account)
223
+ tx_params = super().normalize_tx_params(tx_params)
224
+ return self._underlying_method(account).build_transaction(tx_params.as_dict())
225
+
226
+ def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int:
227
+ """Estimate gas consumption of method call."""
228
+ (account) = self.validate_and_normalize_inputs(account)
229
+ tx_params = super().normalize_tx_params(tx_params)
230
+ return self._underlying_method(account).estimate_gas(tx_params.as_dict())
231
+
232
+ class BurnMethod(ContractMethod): # pylint: disable=invalid-name
233
+ """Various interfaces to the burn method."""
234
+
235
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
236
+ """Persist instance data."""
237
+ super().__init__(web3_or_provider, contract_address, validator)
238
+ self._underlying_method = contract_function
239
+
240
+ def validate_and_normalize_inputs(self, account: str, amount: int):
241
+ """Validate the inputs to the burn method."""
242
+ self.validator.assert_valid(
243
+ method_name='burn',
244
+ parameter_name='account',
245
+ argument_value=account,
246
+ )
247
+ account = self.validate_and_checksum_address(account)
248
+ self.validator.assert_valid(
249
+ method_name='burn',
250
+ parameter_name='amount',
251
+ argument_value=amount,
252
+ )
253
+ # safeguard against fractional inputs
254
+ amount = int(amount)
255
+ return (account, amount)
256
+
257
+ def call(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> None:
258
+ """Execute underlying contract method via eth_call.
259
+
260
+ :param tx_params: transaction parameters
261
+ :returns: the return value of the underlying method.
262
+ """
263
+ (account, amount) = self.validate_and_normalize_inputs(account, amount)
264
+ tx_params = super().normalize_tx_params(tx_params)
265
+ self._underlying_method(account, amount).call(tx_params.as_dict())
266
+
267
+ def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
268
+ """Execute underlying contract method via eth_sendTransaction.
269
+
270
+ :param tx_params: transaction parameters
271
+ """
272
+ (account, amount) = self.validate_and_normalize_inputs(account, amount)
273
+ tx_params = super().normalize_tx_params(tx_params)
274
+ return self._underlying_method(account, amount).transact(tx_params.as_dict())
275
+
276
+ def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
277
+ """Construct calldata to be used as input to the method."""
278
+ (account, amount) = self.validate_and_normalize_inputs(account, amount)
279
+ tx_params = super().normalize_tx_params(tx_params)
280
+ return self._underlying_method(account, amount).build_transaction(tx_params.as_dict())
281
+
282
+ def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
283
+ """Estimate gas consumption of method call."""
284
+ (account, amount) = self.validate_and_normalize_inputs(account, amount)
285
+ tx_params = super().normalize_tx_params(tx_params)
286
+ return self._underlying_method(account, amount).estimate_gas(tx_params.as_dict())
287
+
288
+ class DecimalsMethod(ContractMethod): # pylint: disable=invalid-name
289
+ """Various interfaces to the decimals method."""
290
+
291
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
292
+ """Persist instance data."""
293
+ super().__init__(web3_or_provider, contract_address)
294
+ self._underlying_method = contract_function
295
+
296
+ def call(self, tx_params: Optional[TxParams] = None) -> int:
297
+ """Execute underlying contract method via eth_call.
298
+
299
+ Returns the number of decimals used to get its user representation. For
300
+ example, if `decimals` equals `2`, a balance of `505` tokens should be
301
+ displayed to a user as `5.05` (`505 / 10 ** 2`). Tokens usually opt for
302
+ a value of 18, imitating the relationship between Ether and Wei. This
303
+ is the default value returned by this function, unless it's overridden.
304
+ NOTE: This information is only used for _display_ purposes: it in no
305
+ way affects any of the arithmetic of the contract, including {IERC20-
306
+ balanceOf} and {IERC20-transfer}.
307
+
308
+ :param tx_params: transaction parameters
309
+ :returns: the return value of the underlying method.
310
+ """
311
+ tx_params = super().normalize_tx_params(tx_params)
312
+ returned = self._underlying_method().call(tx_params.as_dict())
313
+ return int(returned)
314
+
315
+ def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
316
+ """Execute underlying contract method via eth_sendTransaction.
317
+
318
+ Returns the number of decimals used to get its user representation. For
319
+ example, if `decimals` equals `2`, a balance of `505` tokens should be
320
+ displayed to a user as `5.05` (`505 / 10 ** 2`). Tokens usually opt for
321
+ a value of 18, imitating the relationship between Ether and Wei. This
322
+ is the default value returned by this function, unless it's overridden.
323
+ NOTE: This information is only used for _display_ purposes: it in no
324
+ way affects any of the arithmetic of the contract, including {IERC20-
325
+ balanceOf} and {IERC20-transfer}.
326
+
327
+ :param tx_params: transaction parameters
328
+ """
329
+ tx_params = super().normalize_tx_params(tx_params)
330
+ return self._underlying_method().transact(tx_params.as_dict())
331
+
332
+ def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
333
+ """Construct calldata to be used as input to the method."""
334
+ tx_params = super().normalize_tx_params(tx_params)
335
+ return self._underlying_method().build_transaction(tx_params.as_dict())
336
+
337
+ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
338
+ """Estimate gas consumption of method call."""
339
+ tx_params = super().normalize_tx_params(tx_params)
340
+ return self._underlying_method().estimate_gas(tx_params.as_dict())
341
+
342
+ class DecreaseAllowanceMethod(ContractMethod): # pylint: disable=invalid-name
343
+ """Various interfaces to the decreaseAllowance method."""
344
+
345
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
346
+ """Persist instance data."""
347
+ super().__init__(web3_or_provider, contract_address, validator)
348
+ self._underlying_method = contract_function
349
+
350
+ def validate_and_normalize_inputs(self, spender: str, subtracted_value: int):
351
+ """Validate the inputs to the decreaseAllowance method."""
352
+ self.validator.assert_valid(
353
+ method_name='decreaseAllowance',
354
+ parameter_name='spender',
355
+ argument_value=spender,
356
+ )
357
+ spender = self.validate_and_checksum_address(spender)
358
+ self.validator.assert_valid(
359
+ method_name='decreaseAllowance',
360
+ parameter_name='subtractedValue',
361
+ argument_value=subtracted_value,
362
+ )
363
+ # safeguard against fractional inputs
364
+ subtracted_value = int(subtracted_value)
365
+ return (spender, subtracted_value)
366
+
367
+ def call(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> bool:
368
+ """Execute underlying contract method via eth_call.
369
+
370
+ Atomically decreases the allowance granted to `spender` by the caller.
371
+ This is an alternative to {approve} that can be used as a mitigation
372
+ for problems described in {IERC20-approve}. Emits an {Approval} event
373
+ indicating the updated allowance. Requirements: - `spender` cannot be
374
+ the zero address. - `spender` must have allowance for the caller of at
375
+ least `subtractedValue`.
376
+
377
+ :param tx_params: transaction parameters
378
+ :returns: the return value of the underlying method.
379
+ """
380
+ (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
381
+ tx_params = super().normalize_tx_params(tx_params)
382
+ returned = self._underlying_method(spender, subtracted_value).call(tx_params.as_dict())
383
+ return bool(returned)
384
+
385
+ def send_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
386
+ """Execute underlying contract method via eth_sendTransaction.
387
+
388
+ Atomically decreases the allowance granted to `spender` by the caller.
389
+ This is an alternative to {approve} that can be used as a mitigation
390
+ for problems described in {IERC20-approve}. Emits an {Approval} event
391
+ indicating the updated allowance. Requirements: - `spender` cannot be
392
+ the zero address. - `spender` must have allowance for the caller of at
393
+ least `subtractedValue`.
394
+
395
+ :param tx_params: transaction parameters
396
+ """
397
+ (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
398
+ tx_params = super().normalize_tx_params(tx_params)
399
+ return self._underlying_method(spender, subtracted_value).transact(tx_params.as_dict())
400
+
401
+ def build_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> dict:
402
+ """Construct calldata to be used as input to the method."""
403
+ (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
404
+ tx_params = super().normalize_tx_params(tx_params)
405
+ return self._underlying_method(spender, subtracted_value).build_transaction(tx_params.as_dict())
406
+
407
+ def estimate_gas(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> int:
408
+ """Estimate gas consumption of method call."""
409
+ (spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
410
+ tx_params = super().normalize_tx_params(tx_params)
411
+ return self._underlying_method(spender, subtracted_value).estimate_gas(tx_params.as_dict())
412
+
413
+ class IncreaseAllowanceMethod(ContractMethod): # pylint: disable=invalid-name
414
+ """Various interfaces to the increaseAllowance method."""
415
+
416
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
417
+ """Persist instance data."""
418
+ super().__init__(web3_or_provider, contract_address, validator)
419
+ self._underlying_method = contract_function
420
+
421
+ def validate_and_normalize_inputs(self, spender: str, added_value: int):
422
+ """Validate the inputs to the increaseAllowance method."""
423
+ self.validator.assert_valid(
424
+ method_name='increaseAllowance',
425
+ parameter_name='spender',
426
+ argument_value=spender,
427
+ )
428
+ spender = self.validate_and_checksum_address(spender)
429
+ self.validator.assert_valid(
430
+ method_name='increaseAllowance',
431
+ parameter_name='addedValue',
432
+ argument_value=added_value,
433
+ )
434
+ # safeguard against fractional inputs
435
+ added_value = int(added_value)
436
+ return (spender, added_value)
437
+
438
+ def call(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> bool:
439
+ """Execute underlying contract method via eth_call.
440
+
441
+ Atomically increases the allowance granted to `spender` by the caller.
442
+ This is an alternative to {approve} that can be used as a mitigation
443
+ for problems described in {IERC20-approve}. Emits an {Approval} event
444
+ indicating the updated allowance. Requirements: - `spender` cannot be
445
+ the zero address.
446
+
447
+ :param tx_params: transaction parameters
448
+ :returns: the return value of the underlying method.
449
+ """
450
+ (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
451
+ tx_params = super().normalize_tx_params(tx_params)
452
+ returned = self._underlying_method(spender, added_value).call(tx_params.as_dict())
453
+ return bool(returned)
454
+
455
+ def send_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
456
+ """Execute underlying contract method via eth_sendTransaction.
457
+
458
+ Atomically increases the allowance granted to `spender` by the caller.
459
+ This is an alternative to {approve} that can be used as a mitigation
460
+ for problems described in {IERC20-approve}. Emits an {Approval} event
461
+ indicating the updated allowance. Requirements: - `spender` cannot be
462
+ the zero address.
463
+
464
+ :param tx_params: transaction parameters
465
+ """
466
+ (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
467
+ tx_params = super().normalize_tx_params(tx_params)
468
+ return self._underlying_method(spender, added_value).transact(tx_params.as_dict())
469
+
470
+ def build_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> dict:
471
+ """Construct calldata to be used as input to the method."""
472
+ (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
473
+ tx_params = super().normalize_tx_params(tx_params)
474
+ return self._underlying_method(spender, added_value).build_transaction(tx_params.as_dict())
475
+
476
+ def estimate_gas(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> int:
477
+ """Estimate gas consumption of method call."""
478
+ (spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
479
+ tx_params = super().normalize_tx_params(tx_params)
480
+ return self._underlying_method(spender, added_value).estimate_gas(tx_params.as_dict())
481
+
482
+ class InitialSupplyMethod(ContractMethod): # pylint: disable=invalid-name
483
+ """Various interfaces to the initialSupply method."""
484
+
485
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
486
+ """Persist instance data."""
487
+ super().__init__(web3_or_provider, contract_address)
488
+ self._underlying_method = contract_function
489
+
490
+ def call(self, tx_params: Optional[TxParams] = None) -> int:
491
+ """Execute underlying contract method via eth_call.
492
+
493
+ :param tx_params: transaction parameters
494
+ :returns: the return value of the underlying method.
495
+ """
496
+ tx_params = super().normalize_tx_params(tx_params)
497
+ returned = self._underlying_method().call(tx_params.as_dict())
498
+ return int(returned)
499
+
500
+ def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
501
+ """Execute underlying contract method via eth_sendTransaction.
502
+
503
+ :param tx_params: transaction parameters
504
+ """
505
+ tx_params = super().normalize_tx_params(tx_params)
506
+ return self._underlying_method().transact(tx_params.as_dict())
507
+
508
+ def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
509
+ """Construct calldata to be used as input to the method."""
510
+ tx_params = super().normalize_tx_params(tx_params)
511
+ return self._underlying_method().build_transaction(tx_params.as_dict())
512
+
513
+ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
514
+ """Estimate gas consumption of method call."""
515
+ tx_params = super().normalize_tx_params(tx_params)
516
+ return self._underlying_method().estimate_gas(tx_params.as_dict())
517
+
518
+ class MintMethod(ContractMethod): # pylint: disable=invalid-name
519
+ """Various interfaces to the mint method."""
520
+
521
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
522
+ """Persist instance data."""
523
+ super().__init__(web3_or_provider, contract_address, validator)
524
+ self._underlying_method = contract_function
525
+
526
+ def validate_and_normalize_inputs(self, account: str, amount: int):
527
+ """Validate the inputs to the mint method."""
528
+ self.validator.assert_valid(
529
+ method_name='mint',
530
+ parameter_name='account',
531
+ argument_value=account,
532
+ )
533
+ account = self.validate_and_checksum_address(account)
534
+ self.validator.assert_valid(
535
+ method_name='mint',
536
+ parameter_name='amount',
537
+ argument_value=amount,
538
+ )
539
+ # safeguard against fractional inputs
540
+ amount = int(amount)
541
+ return (account, amount)
542
+
543
+ def call(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> None:
544
+ """Execute underlying contract method via eth_call.
545
+
546
+ :param tx_params: transaction parameters
547
+ :returns: the return value of the underlying method.
548
+ """
549
+ (account, amount) = self.validate_and_normalize_inputs(account, amount)
550
+ tx_params = super().normalize_tx_params(tx_params)
551
+ self._underlying_method(account, amount).call(tx_params.as_dict())
552
+
553
+ def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
554
+ """Execute underlying contract method via eth_sendTransaction.
555
+
556
+ :param tx_params: transaction parameters
557
+ """
558
+ (account, amount) = self.validate_and_normalize_inputs(account, amount)
559
+ tx_params = super().normalize_tx_params(tx_params)
560
+ return self._underlying_method(account, amount).transact(tx_params.as_dict())
561
+
562
+ def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
563
+ """Construct calldata to be used as input to the method."""
564
+ (account, amount) = self.validate_and_normalize_inputs(account, amount)
565
+ tx_params = super().normalize_tx_params(tx_params)
566
+ return self._underlying_method(account, amount).build_transaction(tx_params.as_dict())
567
+
568
+ def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
569
+ """Estimate gas consumption of method call."""
570
+ (account, amount) = self.validate_and_normalize_inputs(account, amount)
571
+ tx_params = super().normalize_tx_params(tx_params)
572
+ return self._underlying_method(account, amount).estimate_gas(tx_params.as_dict())
573
+
574
+ class NameMethod(ContractMethod): # pylint: disable=invalid-name
575
+ """Various interfaces to the name method."""
576
+
577
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
578
+ """Persist instance data."""
579
+ super().__init__(web3_or_provider, contract_address)
580
+ self._underlying_method = contract_function
581
+
582
+ def call(self, tx_params: Optional[TxParams] = None) -> str:
583
+ """Execute underlying contract method via eth_call.
584
+
585
+ Returns the name of the token.
586
+
587
+ :param tx_params: transaction parameters
588
+ :returns: the return value of the underlying method.
589
+ """
590
+ tx_params = super().normalize_tx_params(tx_params)
591
+ returned = self._underlying_method().call(tx_params.as_dict())
592
+ return str(returned)
593
+
594
+ def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
595
+ """Execute underlying contract method via eth_sendTransaction.
596
+
597
+ Returns the name of the token.
598
+
599
+ :param tx_params: transaction parameters
600
+ """
601
+ tx_params = super().normalize_tx_params(tx_params)
602
+ return self._underlying_method().transact(tx_params.as_dict())
603
+
604
+ def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
605
+ """Construct calldata to be used as input to the method."""
606
+ tx_params = super().normalize_tx_params(tx_params)
607
+ return self._underlying_method().build_transaction(tx_params.as_dict())
608
+
609
+ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
610
+ """Estimate gas consumption of method call."""
611
+ tx_params = super().normalize_tx_params(tx_params)
612
+ return self._underlying_method().estimate_gas(tx_params.as_dict())
613
+
614
+ class SymbolMethod(ContractMethod): # pylint: disable=invalid-name
615
+ """Various interfaces to the symbol method."""
616
+
617
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
618
+ """Persist instance data."""
619
+ super().__init__(web3_or_provider, contract_address)
620
+ self._underlying_method = contract_function
621
+
622
+ def call(self, tx_params: Optional[TxParams] = None) -> str:
623
+ """Execute underlying contract method via eth_call.
624
+
625
+ Returns the symbol of the token, usually a shorter version of the name.
626
+
627
+ :param tx_params: transaction parameters
628
+ :returns: the return value of the underlying method.
629
+ """
630
+ tx_params = super().normalize_tx_params(tx_params)
631
+ returned = self._underlying_method().call(tx_params.as_dict())
632
+ return str(returned)
633
+
634
+ def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
635
+ """Execute underlying contract method via eth_sendTransaction.
636
+
637
+ Returns the symbol of the token, usually a shorter version of the name.
638
+
639
+ :param tx_params: transaction parameters
640
+ """
641
+ tx_params = super().normalize_tx_params(tx_params)
642
+ return self._underlying_method().transact(tx_params.as_dict())
643
+
644
+ def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
645
+ """Construct calldata to be used as input to the method."""
646
+ tx_params = super().normalize_tx_params(tx_params)
647
+ return self._underlying_method().build_transaction(tx_params.as_dict())
648
+
649
+ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
650
+ """Estimate gas consumption of method call."""
651
+ tx_params = super().normalize_tx_params(tx_params)
652
+ return self._underlying_method().estimate_gas(tx_params.as_dict())
653
+
654
+ class TotalSupplyMethod(ContractMethod): # pylint: disable=invalid-name
655
+ """Various interfaces to the totalSupply method."""
656
+
657
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
658
+ """Persist instance data."""
659
+ super().__init__(web3_or_provider, contract_address)
660
+ self._underlying_method = contract_function
661
+
662
+ def call(self, tx_params: Optional[TxParams] = None) -> int:
663
+ """Execute underlying contract method via eth_call.
664
+
665
+ See {IERC20-totalSupply}.
666
+
667
+ :param tx_params: transaction parameters
668
+ :returns: the return value of the underlying method.
669
+ """
670
+ tx_params = super().normalize_tx_params(tx_params)
671
+ returned = self._underlying_method().call(tx_params.as_dict())
672
+ return int(returned)
673
+
674
+ def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
675
+ """Execute underlying contract method via eth_sendTransaction.
676
+
677
+ See {IERC20-totalSupply}.
678
+
679
+ :param tx_params: transaction parameters
680
+ """
681
+ tx_params = super().normalize_tx_params(tx_params)
682
+ return self._underlying_method().transact(tx_params.as_dict())
683
+
684
+ def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
685
+ """Construct calldata to be used as input to the method."""
686
+ tx_params = super().normalize_tx_params(tx_params)
687
+ return self._underlying_method().build_transaction(tx_params.as_dict())
688
+
689
+ def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
690
+ """Estimate gas consumption of method call."""
691
+ tx_params = super().normalize_tx_params(tx_params)
692
+ return self._underlying_method().estimate_gas(tx_params.as_dict())
693
+
694
+ class TransferMethod(ContractMethod): # pylint: disable=invalid-name
695
+ """Various interfaces to the transfer method."""
696
+
697
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
698
+ """Persist instance data."""
699
+ super().__init__(web3_or_provider, contract_address, validator)
700
+ self._underlying_method = contract_function
701
+
702
+ def validate_and_normalize_inputs(self, to: str, amount: int):
703
+ """Validate the inputs to the transfer method."""
704
+ self.validator.assert_valid(
705
+ method_name='transfer',
706
+ parameter_name='to',
707
+ argument_value=to,
708
+ )
709
+ to = self.validate_and_checksum_address(to)
710
+ self.validator.assert_valid(
711
+ method_name='transfer',
712
+ parameter_name='amount',
713
+ argument_value=amount,
714
+ )
715
+ # safeguard against fractional inputs
716
+ amount = int(amount)
717
+ return (to, amount)
718
+
719
+ def call(self, to: str, amount: int, tx_params: Optional[TxParams] = None) -> bool:
720
+ """Execute underlying contract method via eth_call.
721
+
722
+ See {IERC20-transfer}. Requirements: - `to` cannot be the zero address.
723
+ - the caller must have a balance of at least `amount`.
724
+
725
+ :param tx_params: transaction parameters
726
+ :returns: the return value of the underlying method.
727
+ """
728
+ (to, amount) = self.validate_and_normalize_inputs(to, amount)
729
+ tx_params = super().normalize_tx_params(tx_params)
730
+ returned = self._underlying_method(to, amount).call(tx_params.as_dict())
731
+ return bool(returned)
732
+
733
+ def send_transaction(self, to: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
734
+ """Execute underlying contract method via eth_sendTransaction.
735
+
736
+ See {IERC20-transfer}. Requirements: - `to` cannot be the zero address.
737
+ - the caller must have a balance of at least `amount`.
738
+
739
+ :param tx_params: transaction parameters
740
+ """
741
+ (to, amount) = self.validate_and_normalize_inputs(to, amount)
742
+ tx_params = super().normalize_tx_params(tx_params)
743
+ return self._underlying_method(to, amount).transact(tx_params.as_dict())
744
+
745
+ def build_transaction(self, to: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
746
+ """Construct calldata to be used as input to the method."""
747
+ (to, amount) = self.validate_and_normalize_inputs(to, amount)
748
+ tx_params = super().normalize_tx_params(tx_params)
749
+ return self._underlying_method(to, amount).build_transaction(tx_params.as_dict())
750
+
751
+ def estimate_gas(self, to: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
752
+ """Estimate gas consumption of method call."""
753
+ (to, amount) = self.validate_and_normalize_inputs(to, amount)
754
+ tx_params = super().normalize_tx_params(tx_params)
755
+ return self._underlying_method(to, amount).estimate_gas(tx_params.as_dict())
756
+
757
+ class TransferFromMethod(ContractMethod): # pylint: disable=invalid-name
758
+ """Various interfaces to the transferFrom method."""
759
+
760
+ def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
761
+ """Persist instance data."""
762
+ super().__init__(web3_or_provider, contract_address, validator)
763
+ self._underlying_method = contract_function
764
+
765
+ def validate_and_normalize_inputs(self, _from: str, to: str, amount: int):
766
+ """Validate the inputs to the transferFrom method."""
767
+ self.validator.assert_valid(
768
+ method_name='transferFrom',
769
+ parameter_name='from',
770
+ argument_value=_from,
771
+ )
772
+ _from = self.validate_and_checksum_address(_from)
773
+ self.validator.assert_valid(
774
+ method_name='transferFrom',
775
+ parameter_name='to',
776
+ argument_value=to,
777
+ )
778
+ to = self.validate_and_checksum_address(to)
779
+ self.validator.assert_valid(
780
+ method_name='transferFrom',
781
+ parameter_name='amount',
782
+ argument_value=amount,
783
+ )
784
+ # safeguard against fractional inputs
785
+ amount = int(amount)
786
+ return (_from, to, amount)
787
+
788
+ def call(self, _from: str, to: str, amount: int, tx_params: Optional[TxParams] = None) -> bool:
789
+ """Execute underlying contract method via eth_call.
790
+
791
+ See {IERC20-transferFrom}. Emits an {Approval} event indicating the
792
+ updated allowance. This is not required by the EIP. See the note at the
793
+ beginning of {ERC20}. NOTE: Does not update the allowance if the
794
+ current allowance is the maximum `uint256`. Requirements: - `from` and
795
+ `to` cannot be the zero address. - `from` must have a balance of at
796
+ least `amount`. - the caller must have allowance for ``from``'s tokens
797
+ of at least `amount`.
798
+
799
+ :param tx_params: transaction parameters
800
+ :returns: the return value of the underlying method.
801
+ """
802
+ (_from, to, amount) = self.validate_and_normalize_inputs(_from, to, amount)
803
+ tx_params = super().normalize_tx_params(tx_params)
804
+ returned = self._underlying_method(_from, to, amount).call(tx_params.as_dict())
805
+ return bool(returned)
806
+
807
+ def send_transaction(self, _from: str, to: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
808
+ """Execute underlying contract method via eth_sendTransaction.
809
+
810
+ See {IERC20-transferFrom}. Emits an {Approval} event indicating the
811
+ updated allowance. This is not required by the EIP. See the note at the
812
+ beginning of {ERC20}. NOTE: Does not update the allowance if the
813
+ current allowance is the maximum `uint256`. Requirements: - `from` and
814
+ `to` cannot be the zero address. - `from` must have a balance of at
815
+ least `amount`. - the caller must have allowance for ``from``'s tokens
816
+ of at least `amount`.
817
+
818
+ :param tx_params: transaction parameters
819
+ """
820
+ (_from, to, amount) = self.validate_and_normalize_inputs(_from, to, amount)
821
+ tx_params = super().normalize_tx_params(tx_params)
822
+ return self._underlying_method(_from, to, amount).transact(tx_params.as_dict())
823
+
824
+ def build_transaction(self, _from: str, to: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
825
+ """Construct calldata to be used as input to the method."""
826
+ (_from, to, amount) = self.validate_and_normalize_inputs(_from, to, amount)
827
+ tx_params = super().normalize_tx_params(tx_params)
828
+ return self._underlying_method(_from, to, amount).build_transaction(tx_params.as_dict())
829
+
830
+ def estimate_gas(self, _from: str, to: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
831
+ """Estimate gas consumption of method call."""
832
+ (_from, to, amount) = self.validate_and_normalize_inputs(_from, to, amount)
833
+ tx_params = super().normalize_tx_params(tx_params)
834
+ return self._underlying_method(_from, to, amount).estimate_gas(tx_params.as_dict())
835
+
836
+ # pylint: disable=too-many-public-methods,too-many-instance-attributes
837
+ class DummyToken:
838
+ """Wrapper class for DummyToken Solidity contract."""
839
+ allowance: AllowanceMethod
840
+ """Constructor-initialized instance of
841
+ :class:`AllowanceMethod`.
842
+ """
843
+
844
+ approve: ApproveMethod
845
+ """Constructor-initialized instance of
846
+ :class:`ApproveMethod`.
847
+ """
848
+
849
+ balance_of: BalanceOfMethod
850
+ """Constructor-initialized instance of
851
+ :class:`BalanceOfMethod`.
852
+ """
853
+
854
+ burn: BurnMethod
855
+ """Constructor-initialized instance of
856
+ :class:`BurnMethod`.
857
+ """
858
+
859
+ decimals: DecimalsMethod
860
+ """Constructor-initialized instance of
861
+ :class:`DecimalsMethod`.
862
+ """
863
+
864
+ decrease_allowance: DecreaseAllowanceMethod
865
+ """Constructor-initialized instance of
866
+ :class:`DecreaseAllowanceMethod`.
867
+ """
868
+
869
+ increase_allowance: IncreaseAllowanceMethod
870
+ """Constructor-initialized instance of
871
+ :class:`IncreaseAllowanceMethod`.
872
+ """
873
+
874
+ initial_supply: InitialSupplyMethod
875
+ """Constructor-initialized instance of
876
+ :class:`InitialSupplyMethod`.
877
+ """
878
+
879
+ mint: MintMethod
880
+ """Constructor-initialized instance of
881
+ :class:`MintMethod`.
882
+ """
883
+
884
+ name: NameMethod
885
+ """Constructor-initialized instance of
886
+ :class:`NameMethod`.
887
+ """
888
+
889
+ symbol: SymbolMethod
890
+ """Constructor-initialized instance of
891
+ :class:`SymbolMethod`.
892
+ """
893
+
894
+ total_supply: TotalSupplyMethod
895
+ """Constructor-initialized instance of
896
+ :class:`TotalSupplyMethod`.
897
+ """
898
+
899
+ transfer: TransferMethod
900
+ """Constructor-initialized instance of
901
+ :class:`TransferMethod`.
902
+ """
903
+
904
+ transfer_from: TransferFromMethod
905
+ """Constructor-initialized instance of
906
+ :class:`TransferFromMethod`.
907
+ """
908
+
909
+
910
+ def __init__(
911
+ self,
912
+ web3_or_provider: Union[Web3, BaseProvider],
913
+ contract_address: str,
914
+ validator: DummyTokenValidator = None,
915
+ ):
916
+ """Get an instance of wrapper for smart contract.
917
+
918
+ :param web3_or_provider: Either an instance of `web3.Web3`:code: or
919
+ `web3.providers.base.BaseProvider`:code:
920
+ :param contract_address: where the contract has been deployed
921
+ :param validator: for validation of method inputs.
922
+ """
923
+ # pylint: disable=too-many-statements
924
+
925
+ self.contract_address = contract_address
926
+
927
+ if not validator:
928
+ validator = DummyTokenValidator(web3_or_provider, contract_address)
929
+
930
+ web3 = None
931
+ if isinstance(web3_or_provider, BaseProvider):
932
+ web3 = Web3(web3_or_provider)
933
+ elif isinstance(web3_or_provider, Web3):
934
+ web3 = web3_or_provider
935
+ else:
936
+ raise TypeError(
937
+ "Expected parameter 'web3_or_provider' to be an instance of either"
938
+ + " Web3 or BaseProvider"
939
+ )
940
+
941
+ # if any middleware was imported, inject it
942
+ try:
943
+ MIDDLEWARE
944
+ except NameError:
945
+ pass
946
+ else:
947
+ try:
948
+ for middleware in MIDDLEWARE:
949
+ web3.middleware_onion.inject(
950
+ middleware['function'], layer=middleware['layer'],
951
+ )
952
+ except ValueError as value_error:
953
+ if value_error.args == ("You can't add the same un-named instance twice",):
954
+ pass
955
+
956
+ self._web3_eth = web3.eth
957
+
958
+ functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=DummyToken.abi()).functions
959
+
960
+ self.allowance = AllowanceMethod(web3_or_provider, contract_address, functions.allowance, validator)
961
+
962
+ self.approve = ApproveMethod(web3_or_provider, contract_address, functions.approve, validator)
963
+
964
+ self.balance_of = BalanceOfMethod(web3_or_provider, contract_address, functions.balanceOf, validator)
965
+
966
+ self.burn = BurnMethod(web3_or_provider, contract_address, functions.burn, validator)
967
+
968
+ self.decimals = DecimalsMethod(web3_or_provider, contract_address, functions.decimals)
969
+
970
+ self.decrease_allowance = DecreaseAllowanceMethod(web3_or_provider, contract_address, functions.decreaseAllowance, validator)
971
+
972
+ self.increase_allowance = IncreaseAllowanceMethod(web3_or_provider, contract_address, functions.increaseAllowance, validator)
973
+
974
+ self.initial_supply = InitialSupplyMethod(web3_or_provider, contract_address, functions.initialSupply)
975
+
976
+ self.mint = MintMethod(web3_or_provider, contract_address, functions.mint, validator)
977
+
978
+ self.name = NameMethod(web3_or_provider, contract_address, functions.name)
979
+
980
+ self.symbol = SymbolMethod(web3_or_provider, contract_address, functions.symbol)
981
+
982
+ self.total_supply = TotalSupplyMethod(web3_or_provider, contract_address, functions.totalSupply)
983
+
984
+ self.transfer = TransferMethod(web3_or_provider, contract_address, functions.transfer, validator)
985
+
986
+ self.transfer_from = TransferFromMethod(web3_or_provider, contract_address, functions.transferFrom, validator)
987
+
988
+ def get_approval_event(
989
+ self, tx_hash: Union[HexBytes, bytes]
990
+ ) -> Tuple[AttributeDict]:
991
+ """Get log entry for Approval event.
992
+
993
+ :param tx_hash: hash of transaction emitting Approval event
994
+ """
995
+ tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
996
+ return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=DummyToken.abi()).events.Approval().process_receipt(tx_receipt)
997
+ def get_transfer_event(
998
+ self, tx_hash: Union[HexBytes, bytes]
999
+ ) -> Tuple[AttributeDict]:
1000
+ """Get log entry for Transfer event.
1001
+
1002
+ :param tx_hash: hash of transaction emitting Transfer event
1003
+ """
1004
+ tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
1005
+ return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=DummyToken.abi()).events.Transfer().process_receipt(tx_receipt)
1006
+
1007
+ @staticmethod
1008
+ def abi():
1009
+ """Return the ABI to the underlying contract."""
1010
+ return json.loads(
1011
+ '[{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint8","name":"decimals","type":"uint8"}],"stateMutability":"payable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]' # noqa: E501 (line-too-long)
1012
+ )
1013
+
1014
+ # pylint: disable=too-many-lines