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.
- ddx/.gitignore +1 -0
- ddx/__init__.py +58 -0
- ddx/_rust/__init__.pyi +2009 -0
- ddx/_rust/common/__init__.pyi +17 -0
- ddx/_rust/common/accounting.pyi +6 -0
- ddx/_rust/common/enums.pyi +3 -0
- ddx/_rust/common/requests/__init__.pyi +21 -0
- ddx/_rust/common/requests/intents.pyi +19 -0
- ddx/_rust/common/specs.pyi +17 -0
- ddx/_rust/common/state/__init__.pyi +41 -0
- ddx/_rust/common/state/keys.pyi +29 -0
- ddx/_rust/common/transactions.pyi +7 -0
- ddx/_rust/decimal.pyi +3 -0
- ddx/_rust/h256.pyi +3 -0
- ddx/_rust.abi3.so +0 -0
- ddx/app_config/ethereum/addresses.json +541 -0
- ddx/auditor/README.md +32 -0
- ddx/auditor/__init__.py +0 -0
- ddx/auditor/auditor_driver.py +1034 -0
- ddx/auditor/websocket_message.py +54 -0
- ddx/common/__init__.py +0 -0
- ddx/common/epoch_params.py +28 -0
- ddx/common/fill_context.py +144 -0
- ddx/common/item_utils.py +38 -0
- ddx/common/logging.py +184 -0
- ddx/common/market_specs.py +64 -0
- ddx/common/trade_mining_params.py +19 -0
- ddx/common/transaction_utils.py +85 -0
- ddx/common/transactions/__init__.py +0 -0
- ddx/common/transactions/advance_epoch.py +91 -0
- ddx/common/transactions/advance_settlement_epoch.py +63 -0
- ddx/common/transactions/all_price_checkpoints.py +84 -0
- ddx/common/transactions/cancel.py +76 -0
- ddx/common/transactions/cancel_all.py +88 -0
- ddx/common/transactions/complete_fill.py +103 -0
- ddx/common/transactions/disaster_recovery.py +97 -0
- ddx/common/transactions/event.py +48 -0
- ddx/common/transactions/fee_distribution.py +119 -0
- ddx/common/transactions/funding.py +294 -0
- ddx/common/transactions/futures_expiry.py +123 -0
- ddx/common/transactions/genesis.py +108 -0
- ddx/common/transactions/inner/__init__.py +0 -0
- ddx/common/transactions/inner/adl_outcome.py +25 -0
- ddx/common/transactions/inner/fill.py +227 -0
- ddx/common/transactions/inner/liquidated_position.py +41 -0
- ddx/common/transactions/inner/liquidation_entry.py +41 -0
- ddx/common/transactions/inner/liquidation_fill.py +118 -0
- ddx/common/transactions/inner/outcome.py +32 -0
- ddx/common/transactions/inner/trade_fill.py +125 -0
- ddx/common/transactions/insurance_fund_update.py +142 -0
- ddx/common/transactions/insurance_fund_withdraw.py +99 -0
- ddx/common/transactions/liquidation.py +357 -0
- ddx/common/transactions/partial_fill.py +125 -0
- ddx/common/transactions/pnl_realization.py +122 -0
- ddx/common/transactions/post.py +72 -0
- ddx/common/transactions/post_order.py +95 -0
- ddx/common/transactions/price_checkpoint.py +96 -0
- ddx/common/transactions/signer_registered.py +62 -0
- ddx/common/transactions/specs_update.py +61 -0
- ddx/common/transactions/strategy_update.py +156 -0
- ddx/common/transactions/tradable_product_update.py +98 -0
- ddx/common/transactions/trade_mining.py +147 -0
- ddx/common/transactions/trader_update.py +105 -0
- ddx/common/transactions/withdraw.py +91 -0
- ddx/common/transactions/withdraw_ddx.py +74 -0
- ddx/common/utils.py +176 -0
- ddx/config.py +17 -0
- ddx/derivadex_client.py +254 -0
- ddx/py.typed +0 -0
- ddx/realtime_client/__init__.py +2 -0
- ddx/realtime_client/config.py +2 -0
- ddx/realtime_client/logs/pytest.log +0 -0
- ddx/realtime_client/models/__init__.py +683 -0
- ddx/realtime_client/realtime_client.py +567 -0
- ddx/rest_client/__init__.py +0 -0
- ddx/rest_client/clients/__init__.py +0 -0
- ddx/rest_client/clients/base_client.py +60 -0
- ddx/rest_client/clients/market_client.py +1241 -0
- ddx/rest_client/clients/on_chain_client.py +432 -0
- ddx/rest_client/clients/signed_client.py +301 -0
- ddx/rest_client/clients/system_client.py +843 -0
- ddx/rest_client/clients/trade_client.py +335 -0
- ddx/rest_client/constants/__init__.py +0 -0
- ddx/rest_client/constants/endpoints.py +67 -0
- ddx/rest_client/contracts/__init__.py +0 -0
- ddx/rest_client/contracts/checkpoint/__init__.py +560 -0
- ddx/rest_client/contracts/ddx/__init__.py +1949 -0
- ddx/rest_client/contracts/dummy_token/__init__.py +1014 -0
- ddx/rest_client/contracts/i_collateral/__init__.py +1414 -0
- ddx/rest_client/contracts/i_stake/__init__.py +696 -0
- ddx/rest_client/exceptions/__init__.py +0 -0
- ddx/rest_client/exceptions/exceptions.py +32 -0
- ddx/rest_client/http/__init__.py +0 -0
- ddx/rest_client/http/http_client.py +305 -0
- ddx/rest_client/models/__init__.py +0 -0
- ddx/rest_client/models/market.py +683 -0
- ddx/rest_client/models/signed.py +60 -0
- ddx/rest_client/models/system.py +390 -0
- ddx/rest_client/models/trade.py +140 -0
- ddx/rest_client/utils/__init__.py +0 -0
- ddx/rest_client/utils/encryption_utils.py +26 -0
- ddx_python-1.0.5.dist-info/METADATA +63 -0
- ddx_python-1.0.5.dist-info/RECORD +104 -0
- ddx_python-1.0.5.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,1949 @@
|
|
|
1
|
+
"""Generated wrapper for DDX 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 DDX 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
|
+
DDXValidator,
|
|
33
|
+
)
|
|
34
|
+
except ImportError:
|
|
35
|
+
|
|
36
|
+
class DDXValidator( # 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 MaxSupplyMethod(ContractMethod): # pylint: disable=invalid-name
|
|
52
|
+
"""Various interfaces to the MAX_SUPPLY method."""
|
|
53
|
+
|
|
54
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
55
|
+
"""Persist instance data."""
|
|
56
|
+
super().__init__(web3_or_provider, contract_address)
|
|
57
|
+
self._underlying_method = contract_function
|
|
58
|
+
|
|
59
|
+
def call(self, tx_params: Optional[TxParams] = None) -> int:
|
|
60
|
+
"""Execute underlying contract method via eth_call.
|
|
61
|
+
|
|
62
|
+
:param tx_params: transaction parameters
|
|
63
|
+
:returns: the return value of the underlying method.
|
|
64
|
+
"""
|
|
65
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
66
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
67
|
+
return int(returned)
|
|
68
|
+
|
|
69
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
70
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
71
|
+
|
|
72
|
+
:param tx_params: transaction parameters
|
|
73
|
+
"""
|
|
74
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
75
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
76
|
+
|
|
77
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
78
|
+
"""Construct calldata to be used as input to the method."""
|
|
79
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
80
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
81
|
+
|
|
82
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
83
|
+
"""Estimate gas consumption of method call."""
|
|
84
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
85
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
86
|
+
|
|
87
|
+
class PreMineSupplyMethod(ContractMethod): # pylint: disable=invalid-name
|
|
88
|
+
"""Various interfaces to the PRE_MINE_SUPPLY method."""
|
|
89
|
+
|
|
90
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
91
|
+
"""Persist instance data."""
|
|
92
|
+
super().__init__(web3_or_provider, contract_address)
|
|
93
|
+
self._underlying_method = contract_function
|
|
94
|
+
|
|
95
|
+
def call(self, tx_params: Optional[TxParams] = None) -> int:
|
|
96
|
+
"""Execute underlying contract method via eth_call.
|
|
97
|
+
|
|
98
|
+
:param tx_params: transaction parameters
|
|
99
|
+
:returns: the return value of the underlying method.
|
|
100
|
+
"""
|
|
101
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
102
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
103
|
+
return int(returned)
|
|
104
|
+
|
|
105
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
106
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
107
|
+
|
|
108
|
+
:param tx_params: transaction parameters
|
|
109
|
+
"""
|
|
110
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
111
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
112
|
+
|
|
113
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
114
|
+
"""Construct calldata to be used as input to the method."""
|
|
115
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
116
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
117
|
+
|
|
118
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
119
|
+
"""Estimate gas consumption of method call."""
|
|
120
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
121
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
122
|
+
|
|
123
|
+
class AllowanceMethod(ContractMethod): # pylint: disable=invalid-name
|
|
124
|
+
"""Various interfaces to the allowance method."""
|
|
125
|
+
|
|
126
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
127
|
+
"""Persist instance data."""
|
|
128
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
129
|
+
self._underlying_method = contract_function
|
|
130
|
+
|
|
131
|
+
def validate_and_normalize_inputs(self, account: str, spender: str):
|
|
132
|
+
"""Validate the inputs to the allowance method."""
|
|
133
|
+
self.validator.assert_valid(
|
|
134
|
+
method_name='allowance',
|
|
135
|
+
parameter_name='_account',
|
|
136
|
+
argument_value=account,
|
|
137
|
+
)
|
|
138
|
+
account = self.validate_and_checksum_address(account)
|
|
139
|
+
self.validator.assert_valid(
|
|
140
|
+
method_name='allowance',
|
|
141
|
+
parameter_name='_spender',
|
|
142
|
+
argument_value=spender,
|
|
143
|
+
)
|
|
144
|
+
spender = self.validate_and_checksum_address(spender)
|
|
145
|
+
return (account, spender)
|
|
146
|
+
|
|
147
|
+
def call(self, account: str, spender: str, tx_params: Optional[TxParams] = None) -> int:
|
|
148
|
+
"""Execute underlying contract method via eth_call.
|
|
149
|
+
|
|
150
|
+
:param _account: The address of the account holding the funds
|
|
151
|
+
:param _spender: The address of the account spending the funds
|
|
152
|
+
:param tx_params: transaction parameters
|
|
153
|
+
:returns: the return value of the underlying method.
|
|
154
|
+
"""
|
|
155
|
+
(account, spender) = self.validate_and_normalize_inputs(account, spender)
|
|
156
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
157
|
+
returned = self._underlying_method(account, spender).call(tx_params.as_dict())
|
|
158
|
+
return int(returned)
|
|
159
|
+
|
|
160
|
+
def send_transaction(self, account: str, spender: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
161
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
162
|
+
|
|
163
|
+
:param _account: The address of the account holding the funds
|
|
164
|
+
:param _spender: The address of the account spending the funds
|
|
165
|
+
:param tx_params: transaction parameters
|
|
166
|
+
"""
|
|
167
|
+
(account, spender) = self.validate_and_normalize_inputs(account, spender)
|
|
168
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
169
|
+
return self._underlying_method(account, spender).transact(tx_params.as_dict())
|
|
170
|
+
|
|
171
|
+
def build_transaction(self, account: str, spender: str, tx_params: Optional[TxParams] = None) -> dict:
|
|
172
|
+
"""Construct calldata to be used as input to the method."""
|
|
173
|
+
(account, spender) = self.validate_and_normalize_inputs(account, spender)
|
|
174
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
175
|
+
return self._underlying_method(account, spender).build_transaction(tx_params.as_dict())
|
|
176
|
+
|
|
177
|
+
def estimate_gas(self, account: str, spender: str, tx_params: Optional[TxParams] = None) -> int:
|
|
178
|
+
"""Estimate gas consumption of method call."""
|
|
179
|
+
(account, spender) = self.validate_and_normalize_inputs(account, spender)
|
|
180
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
181
|
+
return self._underlying_method(account, spender).estimate_gas(tx_params.as_dict())
|
|
182
|
+
|
|
183
|
+
class ApproveMethod(ContractMethod): # pylint: disable=invalid-name
|
|
184
|
+
"""Various interfaces to the approve method."""
|
|
185
|
+
|
|
186
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
187
|
+
"""Persist instance data."""
|
|
188
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
189
|
+
self._underlying_method = contract_function
|
|
190
|
+
|
|
191
|
+
def validate_and_normalize_inputs(self, spender: str, amount: int):
|
|
192
|
+
"""Validate the inputs to the approve method."""
|
|
193
|
+
self.validator.assert_valid(
|
|
194
|
+
method_name='approve',
|
|
195
|
+
parameter_name='_spender',
|
|
196
|
+
argument_value=spender,
|
|
197
|
+
)
|
|
198
|
+
spender = self.validate_and_checksum_address(spender)
|
|
199
|
+
self.validator.assert_valid(
|
|
200
|
+
method_name='approve',
|
|
201
|
+
parameter_name='_amount',
|
|
202
|
+
argument_value=amount,
|
|
203
|
+
)
|
|
204
|
+
# safeguard against fractional inputs
|
|
205
|
+
amount = int(amount)
|
|
206
|
+
return (spender, amount)
|
|
207
|
+
|
|
208
|
+
def call(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> bool:
|
|
209
|
+
"""Execute underlying contract method via eth_call.
|
|
210
|
+
|
|
211
|
+
This will overwrite the approval amount for `spender` and is subject to
|
|
212
|
+
issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
|
|
213
|
+
|
|
214
|
+
:param _amount: The number of tokens that are approved (2^256-1 means
|
|
215
|
+
infinite)
|
|
216
|
+
:param _spender: The address of the account which may transfer tokens
|
|
217
|
+
:param tx_params: transaction parameters
|
|
218
|
+
:returns: the return value of the underlying method.
|
|
219
|
+
"""
|
|
220
|
+
(spender, amount) = self.validate_and_normalize_inputs(spender, amount)
|
|
221
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
222
|
+
returned = self._underlying_method(spender, amount).call(tx_params.as_dict())
|
|
223
|
+
return bool(returned)
|
|
224
|
+
|
|
225
|
+
def send_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
226
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
227
|
+
|
|
228
|
+
This will overwrite the approval amount for `spender` and is subject to
|
|
229
|
+
issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
|
|
230
|
+
|
|
231
|
+
:param _amount: The number of tokens that are approved (2^256-1 means
|
|
232
|
+
infinite)
|
|
233
|
+
:param _spender: The address of the account which may transfer tokens
|
|
234
|
+
:param tx_params: transaction parameters
|
|
235
|
+
"""
|
|
236
|
+
(spender, amount) = self.validate_and_normalize_inputs(spender, amount)
|
|
237
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
238
|
+
return self._underlying_method(spender, amount).transact(tx_params.as_dict())
|
|
239
|
+
|
|
240
|
+
def build_transaction(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
241
|
+
"""Construct calldata to be used as input to the method."""
|
|
242
|
+
(spender, amount) = self.validate_and_normalize_inputs(spender, amount)
|
|
243
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
244
|
+
return self._underlying_method(spender, amount).build_transaction(tx_params.as_dict())
|
|
245
|
+
|
|
246
|
+
def estimate_gas(self, spender: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
|
|
247
|
+
"""Estimate gas consumption of method call."""
|
|
248
|
+
(spender, amount) = self.validate_and_normalize_inputs(spender, amount)
|
|
249
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
250
|
+
return self._underlying_method(spender, amount).estimate_gas(tx_params.as_dict())
|
|
251
|
+
|
|
252
|
+
class BalanceOfMethod(ContractMethod): # pylint: disable=invalid-name
|
|
253
|
+
"""Various interfaces to the balanceOf method."""
|
|
254
|
+
|
|
255
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
256
|
+
"""Persist instance data."""
|
|
257
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
258
|
+
self._underlying_method = contract_function
|
|
259
|
+
|
|
260
|
+
def validate_and_normalize_inputs(self, account: str):
|
|
261
|
+
"""Validate the inputs to the balanceOf method."""
|
|
262
|
+
self.validator.assert_valid(
|
|
263
|
+
method_name='balanceOf',
|
|
264
|
+
parameter_name='_account',
|
|
265
|
+
argument_value=account,
|
|
266
|
+
)
|
|
267
|
+
account = self.validate_and_checksum_address(account)
|
|
268
|
+
return (account)
|
|
269
|
+
|
|
270
|
+
def call(self, account: str, tx_params: Optional[TxParams] = None) -> int:
|
|
271
|
+
"""Execute underlying contract method via eth_call.
|
|
272
|
+
|
|
273
|
+
:param _account: The address of the account to get the balance of
|
|
274
|
+
:param tx_params: transaction parameters
|
|
275
|
+
:returns: the return value of the underlying method.
|
|
276
|
+
"""
|
|
277
|
+
(account) = self.validate_and_normalize_inputs(account)
|
|
278
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
279
|
+
returned = self._underlying_method(account).call(tx_params.as_dict())
|
|
280
|
+
return int(returned)
|
|
281
|
+
|
|
282
|
+
def send_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
283
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
284
|
+
|
|
285
|
+
:param _account: The address of the account to get the balance of
|
|
286
|
+
:param tx_params: transaction parameters
|
|
287
|
+
"""
|
|
288
|
+
(account) = self.validate_and_normalize_inputs(account)
|
|
289
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
290
|
+
return self._underlying_method(account).transact(tx_params.as_dict())
|
|
291
|
+
|
|
292
|
+
def build_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> dict:
|
|
293
|
+
"""Construct calldata to be used as input to the method."""
|
|
294
|
+
(account) = self.validate_and_normalize_inputs(account)
|
|
295
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
296
|
+
return self._underlying_method(account).build_transaction(tx_params.as_dict())
|
|
297
|
+
|
|
298
|
+
def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int:
|
|
299
|
+
"""Estimate gas consumption of method call."""
|
|
300
|
+
(account) = self.validate_and_normalize_inputs(account)
|
|
301
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
302
|
+
return self._underlying_method(account).estimate_gas(tx_params.as_dict())
|
|
303
|
+
|
|
304
|
+
class BurnMethod(ContractMethod): # pylint: disable=invalid-name
|
|
305
|
+
"""Various interfaces to the burn method."""
|
|
306
|
+
|
|
307
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
308
|
+
"""Persist instance data."""
|
|
309
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
310
|
+
self._underlying_method = contract_function
|
|
311
|
+
|
|
312
|
+
def validate_and_normalize_inputs(self, amount: int):
|
|
313
|
+
"""Validate the inputs to the burn method."""
|
|
314
|
+
self.validator.assert_valid(
|
|
315
|
+
method_name='burn',
|
|
316
|
+
parameter_name='_amount',
|
|
317
|
+
argument_value=amount,
|
|
318
|
+
)
|
|
319
|
+
# safeguard against fractional inputs
|
|
320
|
+
amount = int(amount)
|
|
321
|
+
return (amount)
|
|
322
|
+
|
|
323
|
+
def call(self, amount: int, tx_params: Optional[TxParams] = None) -> None:
|
|
324
|
+
"""Execute underlying contract method via eth_call.
|
|
325
|
+
|
|
326
|
+
Creates `amount` tokens and assigns them to `account`, decreasing the
|
|
327
|
+
total supply. Emits a {Transfer} event with `from` set to the zero
|
|
328
|
+
address. Requirements - `to` cannot be the zero address.
|
|
329
|
+
|
|
330
|
+
:param tx_params: transaction parameters
|
|
331
|
+
:returns: the return value of the underlying method.
|
|
332
|
+
"""
|
|
333
|
+
(amount) = self.validate_and_normalize_inputs(amount)
|
|
334
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
335
|
+
self._underlying_method(amount).call(tx_params.as_dict())
|
|
336
|
+
|
|
337
|
+
def send_transaction(self, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
338
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
339
|
+
|
|
340
|
+
Creates `amount` tokens and assigns them to `account`, decreasing the
|
|
341
|
+
total supply. Emits a {Transfer} event with `from` set to the zero
|
|
342
|
+
address. Requirements - `to` cannot be the zero address.
|
|
343
|
+
|
|
344
|
+
:param tx_params: transaction parameters
|
|
345
|
+
"""
|
|
346
|
+
(amount) = self.validate_and_normalize_inputs(amount)
|
|
347
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
348
|
+
return self._underlying_method(amount).transact(tx_params.as_dict())
|
|
349
|
+
|
|
350
|
+
def build_transaction(self, amount: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
351
|
+
"""Construct calldata to be used as input to the method."""
|
|
352
|
+
(amount) = self.validate_and_normalize_inputs(amount)
|
|
353
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
354
|
+
return self._underlying_method(amount).build_transaction(tx_params.as_dict())
|
|
355
|
+
|
|
356
|
+
def estimate_gas(self, amount: int, tx_params: Optional[TxParams] = None) -> int:
|
|
357
|
+
"""Estimate gas consumption of method call."""
|
|
358
|
+
(amount) = self.validate_and_normalize_inputs(amount)
|
|
359
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
360
|
+
return self._underlying_method(amount).estimate_gas(tx_params.as_dict())
|
|
361
|
+
|
|
362
|
+
class BurnFromMethod(ContractMethod): # pylint: disable=invalid-name
|
|
363
|
+
"""Various interfaces to the burnFrom method."""
|
|
364
|
+
|
|
365
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
366
|
+
"""Persist instance data."""
|
|
367
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
368
|
+
self._underlying_method = contract_function
|
|
369
|
+
|
|
370
|
+
def validate_and_normalize_inputs(self, account: str, amount: int):
|
|
371
|
+
"""Validate the inputs to the burnFrom method."""
|
|
372
|
+
self.validator.assert_valid(
|
|
373
|
+
method_name='burnFrom',
|
|
374
|
+
parameter_name='_account',
|
|
375
|
+
argument_value=account,
|
|
376
|
+
)
|
|
377
|
+
account = self.validate_and_checksum_address(account)
|
|
378
|
+
self.validator.assert_valid(
|
|
379
|
+
method_name='burnFrom',
|
|
380
|
+
parameter_name='_amount',
|
|
381
|
+
argument_value=amount,
|
|
382
|
+
)
|
|
383
|
+
# safeguard against fractional inputs
|
|
384
|
+
amount = int(amount)
|
|
385
|
+
return (account, amount)
|
|
386
|
+
|
|
387
|
+
def call(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> None:
|
|
388
|
+
"""Execute underlying contract method via eth_call.
|
|
389
|
+
|
|
390
|
+
Creates `amount` tokens and assigns them to `account`, increasing the
|
|
391
|
+
total supply. Emits a {Transfer} event with `from` set to the zero
|
|
392
|
+
address. Requirements - `to` cannot be the zero address.
|
|
393
|
+
|
|
394
|
+
:param tx_params: transaction parameters
|
|
395
|
+
:returns: the return value of the underlying method.
|
|
396
|
+
"""
|
|
397
|
+
(account, amount) = self.validate_and_normalize_inputs(account, amount)
|
|
398
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
399
|
+
self._underlying_method(account, amount).call(tx_params.as_dict())
|
|
400
|
+
|
|
401
|
+
def send_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
402
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
403
|
+
|
|
404
|
+
Creates `amount` tokens and assigns them to `account`, increasing the
|
|
405
|
+
total supply. Emits a {Transfer} event with `from` set to the zero
|
|
406
|
+
address. Requirements - `to` cannot be the zero address.
|
|
407
|
+
|
|
408
|
+
:param tx_params: transaction parameters
|
|
409
|
+
"""
|
|
410
|
+
(account, amount) = self.validate_and_normalize_inputs(account, amount)
|
|
411
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
412
|
+
return self._underlying_method(account, amount).transact(tx_params.as_dict())
|
|
413
|
+
|
|
414
|
+
def build_transaction(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
415
|
+
"""Construct calldata to be used as input to the method."""
|
|
416
|
+
(account, amount) = self.validate_and_normalize_inputs(account, amount)
|
|
417
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
418
|
+
return self._underlying_method(account, amount).build_transaction(tx_params.as_dict())
|
|
419
|
+
|
|
420
|
+
def estimate_gas(self, account: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
|
|
421
|
+
"""Estimate gas consumption of method call."""
|
|
422
|
+
(account, amount) = self.validate_and_normalize_inputs(account, amount)
|
|
423
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
424
|
+
return self._underlying_method(account, amount).estimate_gas(tx_params.as_dict())
|
|
425
|
+
|
|
426
|
+
class CheckpointsMethod(ContractMethod): # pylint: disable=invalid-name
|
|
427
|
+
"""Various interfaces to the checkpoints method."""
|
|
428
|
+
|
|
429
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
430
|
+
"""Persist instance data."""
|
|
431
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
432
|
+
self._underlying_method = contract_function
|
|
433
|
+
|
|
434
|
+
def validate_and_normalize_inputs(self, index_0: str, index_1: int):
|
|
435
|
+
"""Validate the inputs to the checkpoints method."""
|
|
436
|
+
self.validator.assert_valid(
|
|
437
|
+
method_name='checkpoints',
|
|
438
|
+
parameter_name='index_0',
|
|
439
|
+
argument_value=index_0,
|
|
440
|
+
)
|
|
441
|
+
index_0 = self.validate_and_checksum_address(index_0)
|
|
442
|
+
self.validator.assert_valid(
|
|
443
|
+
method_name='checkpoints',
|
|
444
|
+
parameter_name='index_1',
|
|
445
|
+
argument_value=index_1,
|
|
446
|
+
)
|
|
447
|
+
# safeguard against fractional inputs
|
|
448
|
+
index_1 = int(index_1)
|
|
449
|
+
return (index_0, index_1)
|
|
450
|
+
|
|
451
|
+
def call(self, index_0: str, index_1: int, tx_params: Optional[TxParams] = None) -> Tuple[int, int]:
|
|
452
|
+
"""Execute underlying contract method via eth_call.
|
|
453
|
+
|
|
454
|
+
:param tx_params: transaction parameters
|
|
455
|
+
:returns: the return value of the underlying method.
|
|
456
|
+
"""
|
|
457
|
+
(index_0, index_1) = self.validate_and_normalize_inputs(index_0, index_1)
|
|
458
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
459
|
+
returned = self._underlying_method(index_0, index_1).call(tx_params.as_dict())
|
|
460
|
+
return (returned[0],returned[1],)
|
|
461
|
+
|
|
462
|
+
def send_transaction(self, index_0: str, index_1: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
463
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
464
|
+
|
|
465
|
+
:param tx_params: transaction parameters
|
|
466
|
+
"""
|
|
467
|
+
(index_0, index_1) = self.validate_and_normalize_inputs(index_0, index_1)
|
|
468
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
469
|
+
return self._underlying_method(index_0, index_1).transact(tx_params.as_dict())
|
|
470
|
+
|
|
471
|
+
def build_transaction(self, index_0: str, index_1: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
472
|
+
"""Construct calldata to be used as input to the method."""
|
|
473
|
+
(index_0, index_1) = self.validate_and_normalize_inputs(index_0, index_1)
|
|
474
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
475
|
+
return self._underlying_method(index_0, index_1).build_transaction(tx_params.as_dict())
|
|
476
|
+
|
|
477
|
+
def estimate_gas(self, index_0: str, index_1: int, tx_params: Optional[TxParams] = None) -> int:
|
|
478
|
+
"""Estimate gas consumption of method call."""
|
|
479
|
+
(index_0, index_1) = self.validate_and_normalize_inputs(index_0, index_1)
|
|
480
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
481
|
+
return self._underlying_method(index_0, index_1).estimate_gas(tx_params.as_dict())
|
|
482
|
+
|
|
483
|
+
class DecimalsMethod(ContractMethod): # pylint: disable=invalid-name
|
|
484
|
+
"""Various interfaces to the decimals method."""
|
|
485
|
+
|
|
486
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
487
|
+
"""Persist instance data."""
|
|
488
|
+
super().__init__(web3_or_provider, contract_address)
|
|
489
|
+
self._underlying_method = contract_function
|
|
490
|
+
|
|
491
|
+
def call(self, tx_params: Optional[TxParams] = None) -> int:
|
|
492
|
+
"""Execute underlying contract method via eth_call.
|
|
493
|
+
|
|
494
|
+
:param tx_params: transaction parameters
|
|
495
|
+
:returns: the return value of the underlying method.
|
|
496
|
+
"""
|
|
497
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
498
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
499
|
+
return int(returned)
|
|
500
|
+
|
|
501
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
502
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
503
|
+
|
|
504
|
+
:param tx_params: transaction parameters
|
|
505
|
+
"""
|
|
506
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
507
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
508
|
+
|
|
509
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
510
|
+
"""Construct calldata to be used as input to the method."""
|
|
511
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
512
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
513
|
+
|
|
514
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
515
|
+
"""Estimate gas consumption of method call."""
|
|
516
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
517
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
518
|
+
|
|
519
|
+
class DecreaseAllowanceMethod(ContractMethod): # pylint: disable=invalid-name
|
|
520
|
+
"""Various interfaces to the decreaseAllowance method."""
|
|
521
|
+
|
|
522
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
523
|
+
"""Persist instance data."""
|
|
524
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
525
|
+
self._underlying_method = contract_function
|
|
526
|
+
|
|
527
|
+
def validate_and_normalize_inputs(self, spender: str, subtracted_value: int):
|
|
528
|
+
"""Validate the inputs to the decreaseAllowance method."""
|
|
529
|
+
self.validator.assert_valid(
|
|
530
|
+
method_name='decreaseAllowance',
|
|
531
|
+
parameter_name='_spender',
|
|
532
|
+
argument_value=spender,
|
|
533
|
+
)
|
|
534
|
+
spender = self.validate_and_checksum_address(spender)
|
|
535
|
+
self.validator.assert_valid(
|
|
536
|
+
method_name='decreaseAllowance',
|
|
537
|
+
parameter_name='_subtractedValue',
|
|
538
|
+
argument_value=subtracted_value,
|
|
539
|
+
)
|
|
540
|
+
# safeguard against fractional inputs
|
|
541
|
+
subtracted_value = int(subtracted_value)
|
|
542
|
+
return (spender, subtracted_value)
|
|
543
|
+
|
|
544
|
+
def call(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> bool:
|
|
545
|
+
"""Execute underlying contract method via eth_call.
|
|
546
|
+
|
|
547
|
+
Atomically decreases the allowance granted to `spender` by the caller.
|
|
548
|
+
This is an alternative to {approve} that can be used as a mitigation
|
|
549
|
+
for problems described in {IERC20-approve}. Emits an {Approval} event
|
|
550
|
+
indicating the updated allowance. Requirements: - `spender` cannot be
|
|
551
|
+
the zero address. - `spender` must have allowance for the caller of at
|
|
552
|
+
least `subtractedValue`.
|
|
553
|
+
|
|
554
|
+
:param tx_params: transaction parameters
|
|
555
|
+
:returns: the return value of the underlying method.
|
|
556
|
+
"""
|
|
557
|
+
(spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
|
|
558
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
559
|
+
returned = self._underlying_method(spender, subtracted_value).call(tx_params.as_dict())
|
|
560
|
+
return bool(returned)
|
|
561
|
+
|
|
562
|
+
def send_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
563
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
564
|
+
|
|
565
|
+
Atomically decreases the allowance granted to `spender` by the caller.
|
|
566
|
+
This is an alternative to {approve} that can be used as a mitigation
|
|
567
|
+
for problems described in {IERC20-approve}. Emits an {Approval} event
|
|
568
|
+
indicating the updated allowance. Requirements: - `spender` cannot be
|
|
569
|
+
the zero address. - `spender` must have allowance for the caller of at
|
|
570
|
+
least `subtractedValue`.
|
|
571
|
+
|
|
572
|
+
:param tx_params: transaction parameters
|
|
573
|
+
"""
|
|
574
|
+
(spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
|
|
575
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
576
|
+
return self._underlying_method(spender, subtracted_value).transact(tx_params.as_dict())
|
|
577
|
+
|
|
578
|
+
def build_transaction(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
579
|
+
"""Construct calldata to be used as input to the method."""
|
|
580
|
+
(spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
|
|
581
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
582
|
+
return self._underlying_method(spender, subtracted_value).build_transaction(tx_params.as_dict())
|
|
583
|
+
|
|
584
|
+
def estimate_gas(self, spender: str, subtracted_value: int, tx_params: Optional[TxParams] = None) -> int:
|
|
585
|
+
"""Estimate gas consumption of method call."""
|
|
586
|
+
(spender, subtracted_value) = self.validate_and_normalize_inputs(spender, subtracted_value)
|
|
587
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
588
|
+
return self._underlying_method(spender, subtracted_value).estimate_gas(tx_params.as_dict())
|
|
589
|
+
|
|
590
|
+
class DelegateMethod(ContractMethod): # pylint: disable=invalid-name
|
|
591
|
+
"""Various interfaces to the delegate method."""
|
|
592
|
+
|
|
593
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
594
|
+
"""Persist instance data."""
|
|
595
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
596
|
+
self._underlying_method = contract_function
|
|
597
|
+
|
|
598
|
+
def validate_and_normalize_inputs(self, delegatee: str):
|
|
599
|
+
"""Validate the inputs to the delegate method."""
|
|
600
|
+
self.validator.assert_valid(
|
|
601
|
+
method_name='delegate',
|
|
602
|
+
parameter_name='_delegatee',
|
|
603
|
+
argument_value=delegatee,
|
|
604
|
+
)
|
|
605
|
+
delegatee = self.validate_and_checksum_address(delegatee)
|
|
606
|
+
return (delegatee)
|
|
607
|
+
|
|
608
|
+
def call(self, delegatee: str, tx_params: Optional[TxParams] = None) -> None:
|
|
609
|
+
"""Execute underlying contract method via eth_call.
|
|
610
|
+
|
|
611
|
+
:param _delegatee: The address to delegate votes to
|
|
612
|
+
:param tx_params: transaction parameters
|
|
613
|
+
:returns: the return value of the underlying method.
|
|
614
|
+
"""
|
|
615
|
+
(delegatee) = self.validate_and_normalize_inputs(delegatee)
|
|
616
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
617
|
+
self._underlying_method(delegatee).call(tx_params.as_dict())
|
|
618
|
+
|
|
619
|
+
def send_transaction(self, delegatee: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
620
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
621
|
+
|
|
622
|
+
:param _delegatee: The address to delegate votes to
|
|
623
|
+
:param tx_params: transaction parameters
|
|
624
|
+
"""
|
|
625
|
+
(delegatee) = self.validate_and_normalize_inputs(delegatee)
|
|
626
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
627
|
+
return self._underlying_method(delegatee).transact(tx_params.as_dict())
|
|
628
|
+
|
|
629
|
+
def build_transaction(self, delegatee: str, tx_params: Optional[TxParams] = None) -> dict:
|
|
630
|
+
"""Construct calldata to be used as input to the method."""
|
|
631
|
+
(delegatee) = self.validate_and_normalize_inputs(delegatee)
|
|
632
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
633
|
+
return self._underlying_method(delegatee).build_transaction(tx_params.as_dict())
|
|
634
|
+
|
|
635
|
+
def estimate_gas(self, delegatee: str, tx_params: Optional[TxParams] = None) -> int:
|
|
636
|
+
"""Estimate gas consumption of method call."""
|
|
637
|
+
(delegatee) = self.validate_and_normalize_inputs(delegatee)
|
|
638
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
639
|
+
return self._underlying_method(delegatee).estimate_gas(tx_params.as_dict())
|
|
640
|
+
|
|
641
|
+
class DelegateBySigMethod(ContractMethod): # pylint: disable=invalid-name
|
|
642
|
+
"""Various interfaces to the delegateBySig method."""
|
|
643
|
+
|
|
644
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
645
|
+
"""Persist instance data."""
|
|
646
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
647
|
+
self._underlying_method = contract_function
|
|
648
|
+
|
|
649
|
+
def validate_and_normalize_inputs(self, delegatee: str, nonce: int, expiry: int, signature: Union[bytes, str]):
|
|
650
|
+
"""Validate the inputs to the delegateBySig method."""
|
|
651
|
+
self.validator.assert_valid(
|
|
652
|
+
method_name='delegateBySig',
|
|
653
|
+
parameter_name='_delegatee',
|
|
654
|
+
argument_value=delegatee,
|
|
655
|
+
)
|
|
656
|
+
delegatee = self.validate_and_checksum_address(delegatee)
|
|
657
|
+
self.validator.assert_valid(
|
|
658
|
+
method_name='delegateBySig',
|
|
659
|
+
parameter_name='_nonce',
|
|
660
|
+
argument_value=nonce,
|
|
661
|
+
)
|
|
662
|
+
# safeguard against fractional inputs
|
|
663
|
+
nonce = int(nonce)
|
|
664
|
+
self.validator.assert_valid(
|
|
665
|
+
method_name='delegateBySig',
|
|
666
|
+
parameter_name='_expiry',
|
|
667
|
+
argument_value=expiry,
|
|
668
|
+
)
|
|
669
|
+
# safeguard against fractional inputs
|
|
670
|
+
expiry = int(expiry)
|
|
671
|
+
self.validator.assert_valid(
|
|
672
|
+
method_name='delegateBySig',
|
|
673
|
+
parameter_name='_signature',
|
|
674
|
+
argument_value=signature,
|
|
675
|
+
)
|
|
676
|
+
return (delegatee, nonce, expiry, signature)
|
|
677
|
+
|
|
678
|
+
def call(self, delegatee: str, nonce: int, expiry: int, signature: Union[bytes, str], tx_params: Optional[TxParams] = None) -> None:
|
|
679
|
+
"""Execute underlying contract method via eth_call.
|
|
680
|
+
|
|
681
|
+
:param _delegatee: The address to delegate votes to
|
|
682
|
+
:param _expiry: The time at which to expire the signature
|
|
683
|
+
:param _nonce: The contract state required to match the signature
|
|
684
|
+
:param _signature: Signature
|
|
685
|
+
:param tx_params: transaction parameters
|
|
686
|
+
:returns: the return value of the underlying method.
|
|
687
|
+
"""
|
|
688
|
+
(delegatee, nonce, expiry, signature) = self.validate_and_normalize_inputs(delegatee, nonce, expiry, signature)
|
|
689
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
690
|
+
self._underlying_method(delegatee, nonce, expiry, signature).call(tx_params.as_dict())
|
|
691
|
+
|
|
692
|
+
def send_transaction(self, delegatee: str, nonce: int, expiry: int, signature: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
693
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
694
|
+
|
|
695
|
+
:param _delegatee: The address to delegate votes to
|
|
696
|
+
:param _expiry: The time at which to expire the signature
|
|
697
|
+
:param _nonce: The contract state required to match the signature
|
|
698
|
+
:param _signature: Signature
|
|
699
|
+
:param tx_params: transaction parameters
|
|
700
|
+
"""
|
|
701
|
+
(delegatee, nonce, expiry, signature) = self.validate_and_normalize_inputs(delegatee, nonce, expiry, signature)
|
|
702
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
703
|
+
return self._underlying_method(delegatee, nonce, expiry, signature).transact(tx_params.as_dict())
|
|
704
|
+
|
|
705
|
+
def build_transaction(self, delegatee: str, nonce: int, expiry: int, signature: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict:
|
|
706
|
+
"""Construct calldata to be used as input to the method."""
|
|
707
|
+
(delegatee, nonce, expiry, signature) = self.validate_and_normalize_inputs(delegatee, nonce, expiry, signature)
|
|
708
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
709
|
+
return self._underlying_method(delegatee, nonce, expiry, signature).build_transaction(tx_params.as_dict())
|
|
710
|
+
|
|
711
|
+
def estimate_gas(self, delegatee: str, nonce: int, expiry: int, signature: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int:
|
|
712
|
+
"""Estimate gas consumption of method call."""
|
|
713
|
+
(delegatee, nonce, expiry, signature) = self.validate_and_normalize_inputs(delegatee, nonce, expiry, signature)
|
|
714
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
715
|
+
return self._underlying_method(delegatee, nonce, expiry, signature).estimate_gas(tx_params.as_dict())
|
|
716
|
+
|
|
717
|
+
class DelegatesMethod(ContractMethod): # pylint: disable=invalid-name
|
|
718
|
+
"""Various interfaces to the delegates method."""
|
|
719
|
+
|
|
720
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
721
|
+
"""Persist instance data."""
|
|
722
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
723
|
+
self._underlying_method = contract_function
|
|
724
|
+
|
|
725
|
+
def validate_and_normalize_inputs(self, index_0: str):
|
|
726
|
+
"""Validate the inputs to the delegates method."""
|
|
727
|
+
self.validator.assert_valid(
|
|
728
|
+
method_name='delegates',
|
|
729
|
+
parameter_name='index_0',
|
|
730
|
+
argument_value=index_0,
|
|
731
|
+
)
|
|
732
|
+
index_0 = self.validate_and_checksum_address(index_0)
|
|
733
|
+
return (index_0)
|
|
734
|
+
|
|
735
|
+
def call(self, index_0: str, tx_params: Optional[TxParams] = None) -> str:
|
|
736
|
+
"""Execute underlying contract method via eth_call.
|
|
737
|
+
|
|
738
|
+
:param tx_params: transaction parameters
|
|
739
|
+
:returns: the return value of the underlying method.
|
|
740
|
+
"""
|
|
741
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
742
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
743
|
+
returned = self._underlying_method(index_0).call(tx_params.as_dict())
|
|
744
|
+
return str(returned)
|
|
745
|
+
|
|
746
|
+
def send_transaction(self, index_0: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
747
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
748
|
+
|
|
749
|
+
:param tx_params: transaction parameters
|
|
750
|
+
"""
|
|
751
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
752
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
753
|
+
return self._underlying_method(index_0).transact(tx_params.as_dict())
|
|
754
|
+
|
|
755
|
+
def build_transaction(self, index_0: str, tx_params: Optional[TxParams] = None) -> dict:
|
|
756
|
+
"""Construct calldata to be used as input to the method."""
|
|
757
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
758
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
759
|
+
return self._underlying_method(index_0).build_transaction(tx_params.as_dict())
|
|
760
|
+
|
|
761
|
+
def estimate_gas(self, index_0: str, tx_params: Optional[TxParams] = None) -> int:
|
|
762
|
+
"""Estimate gas consumption of method call."""
|
|
763
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
764
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
765
|
+
return self._underlying_method(index_0).estimate_gas(tx_params.as_dict())
|
|
766
|
+
|
|
767
|
+
class GetCurrentVotesMethod(ContractMethod): # pylint: disable=invalid-name
|
|
768
|
+
"""Various interfaces to the getCurrentVotes method."""
|
|
769
|
+
|
|
770
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
771
|
+
"""Persist instance data."""
|
|
772
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
773
|
+
self._underlying_method = contract_function
|
|
774
|
+
|
|
775
|
+
def validate_and_normalize_inputs(self, account: str):
|
|
776
|
+
"""Validate the inputs to the getCurrentVotes method."""
|
|
777
|
+
self.validator.assert_valid(
|
|
778
|
+
method_name='getCurrentVotes',
|
|
779
|
+
parameter_name='_account',
|
|
780
|
+
argument_value=account,
|
|
781
|
+
)
|
|
782
|
+
account = self.validate_and_checksum_address(account)
|
|
783
|
+
return (account)
|
|
784
|
+
|
|
785
|
+
def call(self, account: str, tx_params: Optional[TxParams] = None) -> int:
|
|
786
|
+
"""Execute underlying contract method via eth_call.
|
|
787
|
+
|
|
788
|
+
:param _account: The address to get votes balance.
|
|
789
|
+
:param tx_params: transaction parameters
|
|
790
|
+
:returns: the return value of the underlying method.
|
|
791
|
+
"""
|
|
792
|
+
(account) = self.validate_and_normalize_inputs(account)
|
|
793
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
794
|
+
returned = self._underlying_method(account).call(tx_params.as_dict())
|
|
795
|
+
return int(returned)
|
|
796
|
+
|
|
797
|
+
def send_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
798
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
799
|
+
|
|
800
|
+
:param _account: The address to get votes balance.
|
|
801
|
+
:param tx_params: transaction parameters
|
|
802
|
+
"""
|
|
803
|
+
(account) = self.validate_and_normalize_inputs(account)
|
|
804
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
805
|
+
return self._underlying_method(account).transact(tx_params.as_dict())
|
|
806
|
+
|
|
807
|
+
def build_transaction(self, account: str, tx_params: Optional[TxParams] = None) -> dict:
|
|
808
|
+
"""Construct calldata to be used as input to the method."""
|
|
809
|
+
(account) = self.validate_and_normalize_inputs(account)
|
|
810
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
811
|
+
return self._underlying_method(account).build_transaction(tx_params.as_dict())
|
|
812
|
+
|
|
813
|
+
def estimate_gas(self, account: str, tx_params: Optional[TxParams] = None) -> int:
|
|
814
|
+
"""Estimate gas consumption of method call."""
|
|
815
|
+
(account) = self.validate_and_normalize_inputs(account)
|
|
816
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
817
|
+
return self._underlying_method(account).estimate_gas(tx_params.as_dict())
|
|
818
|
+
|
|
819
|
+
class GetPriorVotesMethod(ContractMethod): # pylint: disable=invalid-name
|
|
820
|
+
"""Various interfaces to the getPriorVotes method."""
|
|
821
|
+
|
|
822
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
823
|
+
"""Persist instance data."""
|
|
824
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
825
|
+
self._underlying_method = contract_function
|
|
826
|
+
|
|
827
|
+
def validate_and_normalize_inputs(self, account: str, block_number: int):
|
|
828
|
+
"""Validate the inputs to the getPriorVotes method."""
|
|
829
|
+
self.validator.assert_valid(
|
|
830
|
+
method_name='getPriorVotes',
|
|
831
|
+
parameter_name='_account',
|
|
832
|
+
argument_value=account,
|
|
833
|
+
)
|
|
834
|
+
account = self.validate_and_checksum_address(account)
|
|
835
|
+
self.validator.assert_valid(
|
|
836
|
+
method_name='getPriorVotes',
|
|
837
|
+
parameter_name='_blockNumber',
|
|
838
|
+
argument_value=block_number,
|
|
839
|
+
)
|
|
840
|
+
# safeguard against fractional inputs
|
|
841
|
+
block_number = int(block_number)
|
|
842
|
+
return (account, block_number)
|
|
843
|
+
|
|
844
|
+
def call(self, account: str, block_number: int, tx_params: Optional[TxParams] = None) -> int:
|
|
845
|
+
"""Execute underlying contract method via eth_call.
|
|
846
|
+
|
|
847
|
+
Block number must be a finalized block or else this function will
|
|
848
|
+
revert to prevent misinformation.
|
|
849
|
+
|
|
850
|
+
:param _account: The address of the account to check
|
|
851
|
+
:param _blockNumber: The block number to get the vote balance at
|
|
852
|
+
:param tx_params: transaction parameters
|
|
853
|
+
:returns: the return value of the underlying method.
|
|
854
|
+
"""
|
|
855
|
+
(account, block_number) = self.validate_and_normalize_inputs(account, block_number)
|
|
856
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
857
|
+
returned = self._underlying_method(account, block_number).call(tx_params.as_dict())
|
|
858
|
+
return int(returned)
|
|
859
|
+
|
|
860
|
+
def send_transaction(self, account: str, block_number: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
861
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
862
|
+
|
|
863
|
+
Block number must be a finalized block or else this function will
|
|
864
|
+
revert to prevent misinformation.
|
|
865
|
+
|
|
866
|
+
:param _account: The address of the account to check
|
|
867
|
+
:param _blockNumber: The block number to get the vote balance at
|
|
868
|
+
:param tx_params: transaction parameters
|
|
869
|
+
"""
|
|
870
|
+
(account, block_number) = self.validate_and_normalize_inputs(account, block_number)
|
|
871
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
872
|
+
return self._underlying_method(account, block_number).transact(tx_params.as_dict())
|
|
873
|
+
|
|
874
|
+
def build_transaction(self, account: str, block_number: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
875
|
+
"""Construct calldata to be used as input to the method."""
|
|
876
|
+
(account, block_number) = self.validate_and_normalize_inputs(account, block_number)
|
|
877
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
878
|
+
return self._underlying_method(account, block_number).build_transaction(tx_params.as_dict())
|
|
879
|
+
|
|
880
|
+
def estimate_gas(self, account: str, block_number: int, tx_params: Optional[TxParams] = None) -> int:
|
|
881
|
+
"""Estimate gas consumption of method call."""
|
|
882
|
+
(account, block_number) = self.validate_and_normalize_inputs(account, block_number)
|
|
883
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
884
|
+
return self._underlying_method(account, block_number).estimate_gas(tx_params.as_dict())
|
|
885
|
+
|
|
886
|
+
class IncreaseAllowanceMethod(ContractMethod): # pylint: disable=invalid-name
|
|
887
|
+
"""Various interfaces to the increaseAllowance method."""
|
|
888
|
+
|
|
889
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
890
|
+
"""Persist instance data."""
|
|
891
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
892
|
+
self._underlying_method = contract_function
|
|
893
|
+
|
|
894
|
+
def validate_and_normalize_inputs(self, spender: str, added_value: int):
|
|
895
|
+
"""Validate the inputs to the increaseAllowance method."""
|
|
896
|
+
self.validator.assert_valid(
|
|
897
|
+
method_name='increaseAllowance',
|
|
898
|
+
parameter_name='_spender',
|
|
899
|
+
argument_value=spender,
|
|
900
|
+
)
|
|
901
|
+
spender = self.validate_and_checksum_address(spender)
|
|
902
|
+
self.validator.assert_valid(
|
|
903
|
+
method_name='increaseAllowance',
|
|
904
|
+
parameter_name='_addedValue',
|
|
905
|
+
argument_value=added_value,
|
|
906
|
+
)
|
|
907
|
+
# safeguard against fractional inputs
|
|
908
|
+
added_value = int(added_value)
|
|
909
|
+
return (spender, added_value)
|
|
910
|
+
|
|
911
|
+
def call(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> bool:
|
|
912
|
+
"""Execute underlying contract method via eth_call.
|
|
913
|
+
|
|
914
|
+
Atomically increases the allowance granted to `spender` by the caller.
|
|
915
|
+
This is an alternative to {approve} that can be used as a mitigation
|
|
916
|
+
for problems described in {IERC20-approve}. Emits an {Approval} event
|
|
917
|
+
indicating the updated allowance. Requirements: - `spender` cannot be
|
|
918
|
+
the zero address.
|
|
919
|
+
|
|
920
|
+
:param tx_params: transaction parameters
|
|
921
|
+
:returns: the return value of the underlying method.
|
|
922
|
+
"""
|
|
923
|
+
(spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
|
|
924
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
925
|
+
returned = self._underlying_method(spender, added_value).call(tx_params.as_dict())
|
|
926
|
+
return bool(returned)
|
|
927
|
+
|
|
928
|
+
def send_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
929
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
930
|
+
|
|
931
|
+
Atomically increases the allowance granted to `spender` by the caller.
|
|
932
|
+
This is an alternative to {approve} that can be used as a mitigation
|
|
933
|
+
for problems described in {IERC20-approve}. Emits an {Approval} event
|
|
934
|
+
indicating the updated allowance. Requirements: - `spender` cannot be
|
|
935
|
+
the zero address.
|
|
936
|
+
|
|
937
|
+
:param tx_params: transaction parameters
|
|
938
|
+
"""
|
|
939
|
+
(spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
|
|
940
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
941
|
+
return self._underlying_method(spender, added_value).transact(tx_params.as_dict())
|
|
942
|
+
|
|
943
|
+
def build_transaction(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
944
|
+
"""Construct calldata to be used as input to the method."""
|
|
945
|
+
(spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
|
|
946
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
947
|
+
return self._underlying_method(spender, added_value).build_transaction(tx_params.as_dict())
|
|
948
|
+
|
|
949
|
+
def estimate_gas(self, spender: str, added_value: int, tx_params: Optional[TxParams] = None) -> int:
|
|
950
|
+
"""Estimate gas consumption of method call."""
|
|
951
|
+
(spender, added_value) = self.validate_and_normalize_inputs(spender, added_value)
|
|
952
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
953
|
+
return self._underlying_method(spender, added_value).estimate_gas(tx_params.as_dict())
|
|
954
|
+
|
|
955
|
+
class IssuedSupplyMethod(ContractMethod): # pylint: disable=invalid-name
|
|
956
|
+
"""Various interfaces to the issuedSupply method."""
|
|
957
|
+
|
|
958
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
959
|
+
"""Persist instance data."""
|
|
960
|
+
super().__init__(web3_or_provider, contract_address)
|
|
961
|
+
self._underlying_method = contract_function
|
|
962
|
+
|
|
963
|
+
def call(self, tx_params: Optional[TxParams] = None) -> int:
|
|
964
|
+
"""Execute underlying contract method via eth_call.
|
|
965
|
+
|
|
966
|
+
:param tx_params: transaction parameters
|
|
967
|
+
:returns: the return value of the underlying method.
|
|
968
|
+
"""
|
|
969
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
970
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
971
|
+
return int(returned)
|
|
972
|
+
|
|
973
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
974
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
975
|
+
|
|
976
|
+
:param tx_params: transaction parameters
|
|
977
|
+
"""
|
|
978
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
979
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
980
|
+
|
|
981
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
982
|
+
"""Construct calldata to be used as input to the method."""
|
|
983
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
984
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
985
|
+
|
|
986
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
987
|
+
"""Estimate gas consumption of method call."""
|
|
988
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
989
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
990
|
+
|
|
991
|
+
class IssuerMethod(ContractMethod): # pylint: disable=invalid-name
|
|
992
|
+
"""Various interfaces to the issuer method."""
|
|
993
|
+
|
|
994
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
995
|
+
"""Persist instance data."""
|
|
996
|
+
super().__init__(web3_or_provider, contract_address)
|
|
997
|
+
self._underlying_method = contract_function
|
|
998
|
+
|
|
999
|
+
def call(self, tx_params: Optional[TxParams] = None) -> str:
|
|
1000
|
+
"""Execute underlying contract method via eth_call.
|
|
1001
|
+
|
|
1002
|
+
:param tx_params: transaction parameters
|
|
1003
|
+
:returns: the return value of the underlying method.
|
|
1004
|
+
"""
|
|
1005
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1006
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
1007
|
+
return str(returned)
|
|
1008
|
+
|
|
1009
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1010
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1011
|
+
|
|
1012
|
+
:param tx_params: transaction parameters
|
|
1013
|
+
"""
|
|
1014
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1015
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
1016
|
+
|
|
1017
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
1018
|
+
"""Construct calldata to be used as input to the method."""
|
|
1019
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1020
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
1021
|
+
|
|
1022
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
1023
|
+
"""Estimate gas consumption of method call."""
|
|
1024
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1025
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
1026
|
+
|
|
1027
|
+
class MintMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1028
|
+
"""Various interfaces to the mint method."""
|
|
1029
|
+
|
|
1030
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
1031
|
+
"""Persist instance data."""
|
|
1032
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
1033
|
+
self._underlying_method = contract_function
|
|
1034
|
+
|
|
1035
|
+
def validate_and_normalize_inputs(self, recipient: str, amount: int):
|
|
1036
|
+
"""Validate the inputs to the mint method."""
|
|
1037
|
+
self.validator.assert_valid(
|
|
1038
|
+
method_name='mint',
|
|
1039
|
+
parameter_name='_recipient',
|
|
1040
|
+
argument_value=recipient,
|
|
1041
|
+
)
|
|
1042
|
+
recipient = self.validate_and_checksum_address(recipient)
|
|
1043
|
+
self.validator.assert_valid(
|
|
1044
|
+
method_name='mint',
|
|
1045
|
+
parameter_name='_amount',
|
|
1046
|
+
argument_value=amount,
|
|
1047
|
+
)
|
|
1048
|
+
# safeguard against fractional inputs
|
|
1049
|
+
amount = int(amount)
|
|
1050
|
+
return (recipient, amount)
|
|
1051
|
+
|
|
1052
|
+
def call(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> None:
|
|
1053
|
+
"""Execute underlying contract method via eth_call.
|
|
1054
|
+
|
|
1055
|
+
Creates `amount` tokens and assigns them to `account`, increasing the
|
|
1056
|
+
total supply. Emits a {Transfer} event with `from` set to the zero
|
|
1057
|
+
address. Requirements - `to` cannot be the zero address.
|
|
1058
|
+
|
|
1059
|
+
:param tx_params: transaction parameters
|
|
1060
|
+
:returns: the return value of the underlying method.
|
|
1061
|
+
"""
|
|
1062
|
+
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
|
|
1063
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1064
|
+
self._underlying_method(recipient, amount).call(tx_params.as_dict())
|
|
1065
|
+
|
|
1066
|
+
def send_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1067
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1068
|
+
|
|
1069
|
+
Creates `amount` tokens and assigns them to `account`, increasing the
|
|
1070
|
+
total supply. Emits a {Transfer} event with `from` set to the zero
|
|
1071
|
+
address. Requirements - `to` cannot be the zero address.
|
|
1072
|
+
|
|
1073
|
+
:param tx_params: transaction parameters
|
|
1074
|
+
"""
|
|
1075
|
+
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
|
|
1076
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1077
|
+
return self._underlying_method(recipient, amount).transact(tx_params.as_dict())
|
|
1078
|
+
|
|
1079
|
+
def build_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
1080
|
+
"""Construct calldata to be used as input to the method."""
|
|
1081
|
+
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
|
|
1082
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1083
|
+
return self._underlying_method(recipient, amount).build_transaction(tx_params.as_dict())
|
|
1084
|
+
|
|
1085
|
+
def estimate_gas(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
|
|
1086
|
+
"""Estimate gas consumption of method call."""
|
|
1087
|
+
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
|
|
1088
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1089
|
+
return self._underlying_method(recipient, amount).estimate_gas(tx_params.as_dict())
|
|
1090
|
+
|
|
1091
|
+
class NameMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1092
|
+
"""Various interfaces to the name method."""
|
|
1093
|
+
|
|
1094
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
1095
|
+
"""Persist instance data."""
|
|
1096
|
+
super().__init__(web3_or_provider, contract_address)
|
|
1097
|
+
self._underlying_method = contract_function
|
|
1098
|
+
|
|
1099
|
+
def call(self, tx_params: Optional[TxParams] = None) -> str:
|
|
1100
|
+
"""Execute underlying contract method via eth_call.
|
|
1101
|
+
|
|
1102
|
+
:param tx_params: transaction parameters
|
|
1103
|
+
:returns: the return value of the underlying method.
|
|
1104
|
+
"""
|
|
1105
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1106
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
1107
|
+
return str(returned)
|
|
1108
|
+
|
|
1109
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1110
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1111
|
+
|
|
1112
|
+
:param tx_params: transaction parameters
|
|
1113
|
+
"""
|
|
1114
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1115
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
1116
|
+
|
|
1117
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
1118
|
+
"""Construct calldata to be used as input to the method."""
|
|
1119
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1120
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
1121
|
+
|
|
1122
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
1123
|
+
"""Estimate gas consumption of method call."""
|
|
1124
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1125
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
1126
|
+
|
|
1127
|
+
class NoncesMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1128
|
+
"""Various interfaces to the nonces method."""
|
|
1129
|
+
|
|
1130
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
1131
|
+
"""Persist instance data."""
|
|
1132
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
1133
|
+
self._underlying_method = contract_function
|
|
1134
|
+
|
|
1135
|
+
def validate_and_normalize_inputs(self, index_0: str):
|
|
1136
|
+
"""Validate the inputs to the nonces method."""
|
|
1137
|
+
self.validator.assert_valid(
|
|
1138
|
+
method_name='nonces',
|
|
1139
|
+
parameter_name='index_0',
|
|
1140
|
+
argument_value=index_0,
|
|
1141
|
+
)
|
|
1142
|
+
index_0 = self.validate_and_checksum_address(index_0)
|
|
1143
|
+
return (index_0)
|
|
1144
|
+
|
|
1145
|
+
def call(self, index_0: str, tx_params: Optional[TxParams] = None) -> int:
|
|
1146
|
+
"""Execute underlying contract method via eth_call.
|
|
1147
|
+
|
|
1148
|
+
:param tx_params: transaction parameters
|
|
1149
|
+
:returns: the return value of the underlying method.
|
|
1150
|
+
"""
|
|
1151
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
1152
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1153
|
+
returned = self._underlying_method(index_0).call(tx_params.as_dict())
|
|
1154
|
+
return int(returned)
|
|
1155
|
+
|
|
1156
|
+
def send_transaction(self, index_0: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1157
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1158
|
+
|
|
1159
|
+
:param tx_params: transaction parameters
|
|
1160
|
+
"""
|
|
1161
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
1162
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1163
|
+
return self._underlying_method(index_0).transact(tx_params.as_dict())
|
|
1164
|
+
|
|
1165
|
+
def build_transaction(self, index_0: str, tx_params: Optional[TxParams] = None) -> dict:
|
|
1166
|
+
"""Construct calldata to be used as input to the method."""
|
|
1167
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
1168
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1169
|
+
return self._underlying_method(index_0).build_transaction(tx_params.as_dict())
|
|
1170
|
+
|
|
1171
|
+
def estimate_gas(self, index_0: str, tx_params: Optional[TxParams] = None) -> int:
|
|
1172
|
+
"""Estimate gas consumption of method call."""
|
|
1173
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
1174
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1175
|
+
return self._underlying_method(index_0).estimate_gas(tx_params.as_dict())
|
|
1176
|
+
|
|
1177
|
+
class NumCheckpointsMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1178
|
+
"""Various interfaces to the numCheckpoints method."""
|
|
1179
|
+
|
|
1180
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
1181
|
+
"""Persist instance data."""
|
|
1182
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
1183
|
+
self._underlying_method = contract_function
|
|
1184
|
+
|
|
1185
|
+
def validate_and_normalize_inputs(self, index_0: str):
|
|
1186
|
+
"""Validate the inputs to the numCheckpoints method."""
|
|
1187
|
+
self.validator.assert_valid(
|
|
1188
|
+
method_name='numCheckpoints',
|
|
1189
|
+
parameter_name='index_0',
|
|
1190
|
+
argument_value=index_0,
|
|
1191
|
+
)
|
|
1192
|
+
index_0 = self.validate_and_checksum_address(index_0)
|
|
1193
|
+
return (index_0)
|
|
1194
|
+
|
|
1195
|
+
def call(self, index_0: str, tx_params: Optional[TxParams] = None) -> int:
|
|
1196
|
+
"""Execute underlying contract method via eth_call.
|
|
1197
|
+
|
|
1198
|
+
:param tx_params: transaction parameters
|
|
1199
|
+
:returns: the return value of the underlying method.
|
|
1200
|
+
"""
|
|
1201
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
1202
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1203
|
+
returned = self._underlying_method(index_0).call(tx_params.as_dict())
|
|
1204
|
+
return int(returned)
|
|
1205
|
+
|
|
1206
|
+
def send_transaction(self, index_0: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1207
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1208
|
+
|
|
1209
|
+
:param tx_params: transaction parameters
|
|
1210
|
+
"""
|
|
1211
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
1212
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1213
|
+
return self._underlying_method(index_0).transact(tx_params.as_dict())
|
|
1214
|
+
|
|
1215
|
+
def build_transaction(self, index_0: str, tx_params: Optional[TxParams] = None) -> dict:
|
|
1216
|
+
"""Construct calldata to be used as input to the method."""
|
|
1217
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
1218
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1219
|
+
return self._underlying_method(index_0).build_transaction(tx_params.as_dict())
|
|
1220
|
+
|
|
1221
|
+
def estimate_gas(self, index_0: str, tx_params: Optional[TxParams] = None) -> int:
|
|
1222
|
+
"""Estimate gas consumption of method call."""
|
|
1223
|
+
(index_0) = self.validate_and_normalize_inputs(index_0)
|
|
1224
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1225
|
+
return self._underlying_method(index_0).estimate_gas(tx_params.as_dict())
|
|
1226
|
+
|
|
1227
|
+
class OwnershipTransferredMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1228
|
+
"""Various interfaces to the ownershipTransferred method."""
|
|
1229
|
+
|
|
1230
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
1231
|
+
"""Persist instance data."""
|
|
1232
|
+
super().__init__(web3_or_provider, contract_address)
|
|
1233
|
+
self._underlying_method = contract_function
|
|
1234
|
+
|
|
1235
|
+
def call(self, tx_params: Optional[TxParams] = None) -> bool:
|
|
1236
|
+
"""Execute underlying contract method via eth_call.
|
|
1237
|
+
|
|
1238
|
+
:param tx_params: transaction parameters
|
|
1239
|
+
:returns: the return value of the underlying method.
|
|
1240
|
+
"""
|
|
1241
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1242
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
1243
|
+
return bool(returned)
|
|
1244
|
+
|
|
1245
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1246
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1247
|
+
|
|
1248
|
+
:param tx_params: transaction parameters
|
|
1249
|
+
"""
|
|
1250
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1251
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
1252
|
+
|
|
1253
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
1254
|
+
"""Construct calldata to be used as input to the method."""
|
|
1255
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1256
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
1257
|
+
|
|
1258
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
1259
|
+
"""Estimate gas consumption of method call."""
|
|
1260
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1261
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
1262
|
+
|
|
1263
|
+
class PermitMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1264
|
+
"""Various interfaces to the permit method."""
|
|
1265
|
+
|
|
1266
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
1267
|
+
"""Persist instance data."""
|
|
1268
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
1269
|
+
self._underlying_method = contract_function
|
|
1270
|
+
|
|
1271
|
+
def validate_and_normalize_inputs(self, spender: str, value: int, nonce: int, expiry: int, signature: Union[bytes, str]):
|
|
1272
|
+
"""Validate the inputs to the permit method."""
|
|
1273
|
+
self.validator.assert_valid(
|
|
1274
|
+
method_name='permit',
|
|
1275
|
+
parameter_name='_spender',
|
|
1276
|
+
argument_value=spender,
|
|
1277
|
+
)
|
|
1278
|
+
spender = self.validate_and_checksum_address(spender)
|
|
1279
|
+
self.validator.assert_valid(
|
|
1280
|
+
method_name='permit',
|
|
1281
|
+
parameter_name='_value',
|
|
1282
|
+
argument_value=value,
|
|
1283
|
+
)
|
|
1284
|
+
# safeguard against fractional inputs
|
|
1285
|
+
value = int(value)
|
|
1286
|
+
self.validator.assert_valid(
|
|
1287
|
+
method_name='permit',
|
|
1288
|
+
parameter_name='_nonce',
|
|
1289
|
+
argument_value=nonce,
|
|
1290
|
+
)
|
|
1291
|
+
# safeguard against fractional inputs
|
|
1292
|
+
nonce = int(nonce)
|
|
1293
|
+
self.validator.assert_valid(
|
|
1294
|
+
method_name='permit',
|
|
1295
|
+
parameter_name='_expiry',
|
|
1296
|
+
argument_value=expiry,
|
|
1297
|
+
)
|
|
1298
|
+
# safeguard against fractional inputs
|
|
1299
|
+
expiry = int(expiry)
|
|
1300
|
+
self.validator.assert_valid(
|
|
1301
|
+
method_name='permit',
|
|
1302
|
+
parameter_name='_signature',
|
|
1303
|
+
argument_value=signature,
|
|
1304
|
+
)
|
|
1305
|
+
return (spender, value, nonce, expiry, signature)
|
|
1306
|
+
|
|
1307
|
+
def call(self, spender: str, value: int, nonce: int, expiry: int, signature: Union[bytes, str], tx_params: Optional[TxParams] = None) -> None:
|
|
1308
|
+
"""Execute underlying contract method via eth_call.
|
|
1309
|
+
|
|
1310
|
+
:param _expiry: The time at which to expire the signature
|
|
1311
|
+
:param _nonce: The contract state required to match the signature
|
|
1312
|
+
:param _signature: Signature
|
|
1313
|
+
:param _spender: The spender being approved
|
|
1314
|
+
:param _value: The value being approved
|
|
1315
|
+
:param tx_params: transaction parameters
|
|
1316
|
+
:returns: the return value of the underlying method.
|
|
1317
|
+
"""
|
|
1318
|
+
(spender, value, nonce, expiry, signature) = self.validate_and_normalize_inputs(spender, value, nonce, expiry, signature)
|
|
1319
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1320
|
+
self._underlying_method(spender, value, nonce, expiry, signature).call(tx_params.as_dict())
|
|
1321
|
+
|
|
1322
|
+
def send_transaction(self, spender: str, value: int, nonce: int, expiry: int, signature: Union[bytes, str], tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1323
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1324
|
+
|
|
1325
|
+
:param _expiry: The time at which to expire the signature
|
|
1326
|
+
:param _nonce: The contract state required to match the signature
|
|
1327
|
+
:param _signature: Signature
|
|
1328
|
+
:param _spender: The spender being approved
|
|
1329
|
+
:param _value: The value being approved
|
|
1330
|
+
:param tx_params: transaction parameters
|
|
1331
|
+
"""
|
|
1332
|
+
(spender, value, nonce, expiry, signature) = self.validate_and_normalize_inputs(spender, value, nonce, expiry, signature)
|
|
1333
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1334
|
+
return self._underlying_method(spender, value, nonce, expiry, signature).transact(tx_params.as_dict())
|
|
1335
|
+
|
|
1336
|
+
def build_transaction(self, spender: str, value: int, nonce: int, expiry: int, signature: Union[bytes, str], tx_params: Optional[TxParams] = None) -> dict:
|
|
1337
|
+
"""Construct calldata to be used as input to the method."""
|
|
1338
|
+
(spender, value, nonce, expiry, signature) = self.validate_and_normalize_inputs(spender, value, nonce, expiry, signature)
|
|
1339
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1340
|
+
return self._underlying_method(spender, value, nonce, expiry, signature).build_transaction(tx_params.as_dict())
|
|
1341
|
+
|
|
1342
|
+
def estimate_gas(self, spender: str, value: int, nonce: int, expiry: int, signature: Union[bytes, str], tx_params: Optional[TxParams] = None) -> int:
|
|
1343
|
+
"""Estimate gas consumption of method call."""
|
|
1344
|
+
(spender, value, nonce, expiry, signature) = self.validate_and_normalize_inputs(spender, value, nonce, expiry, signature)
|
|
1345
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1346
|
+
return self._underlying_method(spender, value, nonce, expiry, signature).estimate_gas(tx_params.as_dict())
|
|
1347
|
+
|
|
1348
|
+
class SymbolMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1349
|
+
"""Various interfaces to the symbol method."""
|
|
1350
|
+
|
|
1351
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
1352
|
+
"""Persist instance data."""
|
|
1353
|
+
super().__init__(web3_or_provider, contract_address)
|
|
1354
|
+
self._underlying_method = contract_function
|
|
1355
|
+
|
|
1356
|
+
def call(self, tx_params: Optional[TxParams] = None) -> str:
|
|
1357
|
+
"""Execute underlying contract method via eth_call.
|
|
1358
|
+
|
|
1359
|
+
:param tx_params: transaction parameters
|
|
1360
|
+
:returns: the return value of the underlying method.
|
|
1361
|
+
"""
|
|
1362
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1363
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
1364
|
+
return str(returned)
|
|
1365
|
+
|
|
1366
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1367
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1368
|
+
|
|
1369
|
+
:param tx_params: transaction parameters
|
|
1370
|
+
"""
|
|
1371
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1372
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
1373
|
+
|
|
1374
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
1375
|
+
"""Construct calldata to be used as input to the method."""
|
|
1376
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1377
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
1378
|
+
|
|
1379
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
1380
|
+
"""Estimate gas consumption of method call."""
|
|
1381
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1382
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
1383
|
+
|
|
1384
|
+
class TotalSupplyMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1385
|
+
"""Various interfaces to the totalSupply method."""
|
|
1386
|
+
|
|
1387
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
1388
|
+
"""Persist instance data."""
|
|
1389
|
+
super().__init__(web3_or_provider, contract_address)
|
|
1390
|
+
self._underlying_method = contract_function
|
|
1391
|
+
|
|
1392
|
+
def call(self, tx_params: Optional[TxParams] = None) -> int:
|
|
1393
|
+
"""Execute underlying contract method via eth_call.
|
|
1394
|
+
|
|
1395
|
+
:param tx_params: transaction parameters
|
|
1396
|
+
:returns: the return value of the underlying method.
|
|
1397
|
+
"""
|
|
1398
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1399
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
1400
|
+
return int(returned)
|
|
1401
|
+
|
|
1402
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1403
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1404
|
+
|
|
1405
|
+
:param tx_params: transaction parameters
|
|
1406
|
+
"""
|
|
1407
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1408
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
1409
|
+
|
|
1410
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
1411
|
+
"""Construct calldata to be used as input to the method."""
|
|
1412
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1413
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
1414
|
+
|
|
1415
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
1416
|
+
"""Estimate gas consumption of method call."""
|
|
1417
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1418
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
1419
|
+
|
|
1420
|
+
class TransferMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1421
|
+
"""Various interfaces to the transfer method."""
|
|
1422
|
+
|
|
1423
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
1424
|
+
"""Persist instance data."""
|
|
1425
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
1426
|
+
self._underlying_method = contract_function
|
|
1427
|
+
|
|
1428
|
+
def validate_and_normalize_inputs(self, recipient: str, amount: int):
|
|
1429
|
+
"""Validate the inputs to the transfer method."""
|
|
1430
|
+
self.validator.assert_valid(
|
|
1431
|
+
method_name='transfer',
|
|
1432
|
+
parameter_name='_recipient',
|
|
1433
|
+
argument_value=recipient,
|
|
1434
|
+
)
|
|
1435
|
+
recipient = self.validate_and_checksum_address(recipient)
|
|
1436
|
+
self.validator.assert_valid(
|
|
1437
|
+
method_name='transfer',
|
|
1438
|
+
parameter_name='_amount',
|
|
1439
|
+
argument_value=amount,
|
|
1440
|
+
)
|
|
1441
|
+
# safeguard against fractional inputs
|
|
1442
|
+
amount = int(amount)
|
|
1443
|
+
return (recipient, amount)
|
|
1444
|
+
|
|
1445
|
+
def call(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> bool:
|
|
1446
|
+
"""Execute underlying contract method via eth_call.
|
|
1447
|
+
|
|
1448
|
+
:param _amount: The number of tokens to transfer
|
|
1449
|
+
:param _recipient: The address of the destination account
|
|
1450
|
+
:param tx_params: transaction parameters
|
|
1451
|
+
:returns: the return value of the underlying method.
|
|
1452
|
+
"""
|
|
1453
|
+
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
|
|
1454
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1455
|
+
returned = self._underlying_method(recipient, amount).call(tx_params.as_dict())
|
|
1456
|
+
return bool(returned)
|
|
1457
|
+
|
|
1458
|
+
def send_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1459
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1460
|
+
|
|
1461
|
+
:param _amount: The number of tokens to transfer
|
|
1462
|
+
:param _recipient: The address of the destination account
|
|
1463
|
+
:param tx_params: transaction parameters
|
|
1464
|
+
"""
|
|
1465
|
+
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
|
|
1466
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1467
|
+
return self._underlying_method(recipient, amount).transact(tx_params.as_dict())
|
|
1468
|
+
|
|
1469
|
+
def build_transaction(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
1470
|
+
"""Construct calldata to be used as input to the method."""
|
|
1471
|
+
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
|
|
1472
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1473
|
+
return self._underlying_method(recipient, amount).build_transaction(tx_params.as_dict())
|
|
1474
|
+
|
|
1475
|
+
def estimate_gas(self, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
|
|
1476
|
+
"""Estimate gas consumption of method call."""
|
|
1477
|
+
(recipient, amount) = self.validate_and_normalize_inputs(recipient, amount)
|
|
1478
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1479
|
+
return self._underlying_method(recipient, amount).estimate_gas(tx_params.as_dict())
|
|
1480
|
+
|
|
1481
|
+
class TransferFromMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1482
|
+
"""Various interfaces to the transferFrom method."""
|
|
1483
|
+
|
|
1484
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
1485
|
+
"""Persist instance data."""
|
|
1486
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
1487
|
+
self._underlying_method = contract_function
|
|
1488
|
+
|
|
1489
|
+
def validate_and_normalize_inputs(self, _from: str, recipient: str, amount: int):
|
|
1490
|
+
"""Validate the inputs to the transferFrom method."""
|
|
1491
|
+
self.validator.assert_valid(
|
|
1492
|
+
method_name='transferFrom',
|
|
1493
|
+
parameter_name='_from',
|
|
1494
|
+
argument_value=_from,
|
|
1495
|
+
)
|
|
1496
|
+
_from = self.validate_and_checksum_address(_from)
|
|
1497
|
+
self.validator.assert_valid(
|
|
1498
|
+
method_name='transferFrom',
|
|
1499
|
+
parameter_name='_recipient',
|
|
1500
|
+
argument_value=recipient,
|
|
1501
|
+
)
|
|
1502
|
+
recipient = self.validate_and_checksum_address(recipient)
|
|
1503
|
+
self.validator.assert_valid(
|
|
1504
|
+
method_name='transferFrom',
|
|
1505
|
+
parameter_name='_amount',
|
|
1506
|
+
argument_value=amount,
|
|
1507
|
+
)
|
|
1508
|
+
# safeguard against fractional inputs
|
|
1509
|
+
amount = int(amount)
|
|
1510
|
+
return (_from, recipient, amount)
|
|
1511
|
+
|
|
1512
|
+
def call(self, _from: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> bool:
|
|
1513
|
+
"""Execute underlying contract method via eth_call.
|
|
1514
|
+
|
|
1515
|
+
:param _amount: The number of tokens to transfer
|
|
1516
|
+
:param _from: The address of the source account
|
|
1517
|
+
:param _recipient: The address of the destination account
|
|
1518
|
+
:param tx_params: transaction parameters
|
|
1519
|
+
:returns: the return value of the underlying method.
|
|
1520
|
+
"""
|
|
1521
|
+
(_from, recipient, amount) = self.validate_and_normalize_inputs(_from, recipient, amount)
|
|
1522
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1523
|
+
returned = self._underlying_method(_from, recipient, amount).call(tx_params.as_dict())
|
|
1524
|
+
return bool(returned)
|
|
1525
|
+
|
|
1526
|
+
def send_transaction(self, _from: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1527
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1528
|
+
|
|
1529
|
+
:param _amount: The number of tokens to transfer
|
|
1530
|
+
:param _from: The address of the source account
|
|
1531
|
+
:param _recipient: The address of the destination account
|
|
1532
|
+
:param tx_params: transaction parameters
|
|
1533
|
+
"""
|
|
1534
|
+
(_from, recipient, amount) = self.validate_and_normalize_inputs(_from, recipient, amount)
|
|
1535
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1536
|
+
return self._underlying_method(_from, recipient, amount).transact(tx_params.as_dict())
|
|
1537
|
+
|
|
1538
|
+
def build_transaction(self, _from: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> dict:
|
|
1539
|
+
"""Construct calldata to be used as input to the method."""
|
|
1540
|
+
(_from, recipient, amount) = self.validate_and_normalize_inputs(_from, recipient, amount)
|
|
1541
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1542
|
+
return self._underlying_method(_from, recipient, amount).build_transaction(tx_params.as_dict())
|
|
1543
|
+
|
|
1544
|
+
def estimate_gas(self, _from: str, recipient: str, amount: int, tx_params: Optional[TxParams] = None) -> int:
|
|
1545
|
+
"""Estimate gas consumption of method call."""
|
|
1546
|
+
(_from, recipient, amount) = self.validate_and_normalize_inputs(_from, recipient, amount)
|
|
1547
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1548
|
+
return self._underlying_method(_from, recipient, amount).estimate_gas(tx_params.as_dict())
|
|
1549
|
+
|
|
1550
|
+
class TransferOwnershipToDerivaDexProxyMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1551
|
+
"""Various interfaces to the transferOwnershipToDerivaDEXProxy method."""
|
|
1552
|
+
|
|
1553
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function, validator: Validator=None):
|
|
1554
|
+
"""Persist instance data."""
|
|
1555
|
+
super().__init__(web3_or_provider, contract_address, validator)
|
|
1556
|
+
self._underlying_method = contract_function
|
|
1557
|
+
|
|
1558
|
+
def validate_and_normalize_inputs(self, deriva_dex_proxy: str):
|
|
1559
|
+
"""Validate the inputs to the transferOwnershipToDerivaDEXProxy method."""
|
|
1560
|
+
self.validator.assert_valid(
|
|
1561
|
+
method_name='transferOwnershipToDerivaDEXProxy',
|
|
1562
|
+
parameter_name='_derivaDEXProxy',
|
|
1563
|
+
argument_value=deriva_dex_proxy,
|
|
1564
|
+
)
|
|
1565
|
+
deriva_dex_proxy = self.validate_and_checksum_address(deriva_dex_proxy)
|
|
1566
|
+
return (deriva_dex_proxy)
|
|
1567
|
+
|
|
1568
|
+
def call(self, deriva_dex_proxy: str, tx_params: Optional[TxParams] = None) -> None:
|
|
1569
|
+
"""Execute underlying contract method via eth_call.
|
|
1570
|
+
|
|
1571
|
+
:param _derivaDEXProxy: DerivaDEX Proxy address
|
|
1572
|
+
:param tx_params: transaction parameters
|
|
1573
|
+
:returns: the return value of the underlying method.
|
|
1574
|
+
"""
|
|
1575
|
+
(deriva_dex_proxy) = self.validate_and_normalize_inputs(deriva_dex_proxy)
|
|
1576
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1577
|
+
self._underlying_method(deriva_dex_proxy).call(tx_params.as_dict())
|
|
1578
|
+
|
|
1579
|
+
def send_transaction(self, deriva_dex_proxy: str, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1580
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1581
|
+
|
|
1582
|
+
:param _derivaDEXProxy: DerivaDEX Proxy address
|
|
1583
|
+
:param tx_params: transaction parameters
|
|
1584
|
+
"""
|
|
1585
|
+
(deriva_dex_proxy) = self.validate_and_normalize_inputs(deriva_dex_proxy)
|
|
1586
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1587
|
+
return self._underlying_method(deriva_dex_proxy).transact(tx_params.as_dict())
|
|
1588
|
+
|
|
1589
|
+
def build_transaction(self, deriva_dex_proxy: str, tx_params: Optional[TxParams] = None) -> dict:
|
|
1590
|
+
"""Construct calldata to be used as input to the method."""
|
|
1591
|
+
(deriva_dex_proxy) = self.validate_and_normalize_inputs(deriva_dex_proxy)
|
|
1592
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1593
|
+
return self._underlying_method(deriva_dex_proxy).build_transaction(tx_params.as_dict())
|
|
1594
|
+
|
|
1595
|
+
def estimate_gas(self, deriva_dex_proxy: str, tx_params: Optional[TxParams] = None) -> int:
|
|
1596
|
+
"""Estimate gas consumption of method call."""
|
|
1597
|
+
(deriva_dex_proxy) = self.validate_and_normalize_inputs(deriva_dex_proxy)
|
|
1598
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1599
|
+
return self._underlying_method(deriva_dex_proxy).estimate_gas(tx_params.as_dict())
|
|
1600
|
+
|
|
1601
|
+
class VersionMethod(ContractMethod): # pylint: disable=invalid-name
|
|
1602
|
+
"""Various interfaces to the version method."""
|
|
1603
|
+
|
|
1604
|
+
def __init__(self, web3_or_provider: Union[Web3, BaseProvider], contract_address: str, contract_function):
|
|
1605
|
+
"""Persist instance data."""
|
|
1606
|
+
super().__init__(web3_or_provider, contract_address)
|
|
1607
|
+
self._underlying_method = contract_function
|
|
1608
|
+
|
|
1609
|
+
def call(self, tx_params: Optional[TxParams] = None) -> str:
|
|
1610
|
+
"""Execute underlying contract method via eth_call.
|
|
1611
|
+
|
|
1612
|
+
:param tx_params: transaction parameters
|
|
1613
|
+
:returns: the return value of the underlying method.
|
|
1614
|
+
"""
|
|
1615
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1616
|
+
returned = self._underlying_method().call(tx_params.as_dict())
|
|
1617
|
+
return str(returned)
|
|
1618
|
+
|
|
1619
|
+
def send_transaction(self, tx_params: Optional[TxParams] = None) -> Union[HexBytes, bytes]:
|
|
1620
|
+
"""Execute underlying contract method via eth_sendTransaction.
|
|
1621
|
+
|
|
1622
|
+
:param tx_params: transaction parameters
|
|
1623
|
+
"""
|
|
1624
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1625
|
+
return self._underlying_method().transact(tx_params.as_dict())
|
|
1626
|
+
|
|
1627
|
+
def build_transaction(self, tx_params: Optional[TxParams] = None) -> dict:
|
|
1628
|
+
"""Construct calldata to be used as input to the method."""
|
|
1629
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1630
|
+
return self._underlying_method().build_transaction(tx_params.as_dict())
|
|
1631
|
+
|
|
1632
|
+
def estimate_gas(self, tx_params: Optional[TxParams] = None) -> int:
|
|
1633
|
+
"""Estimate gas consumption of method call."""
|
|
1634
|
+
tx_params = super().normalize_tx_params(tx_params)
|
|
1635
|
+
return self._underlying_method().estimate_gas(tx_params.as_dict())
|
|
1636
|
+
|
|
1637
|
+
# pylint: disable=too-many-public-methods,too-many-instance-attributes
|
|
1638
|
+
class DDX:
|
|
1639
|
+
"""Wrapper class for DDX Solidity contract.
|
|
1640
|
+
|
|
1641
|
+
All method parameters of type `bytes`:code: should be encoded as UTF-8,
|
|
1642
|
+
which can be accomplished via `str.encode("utf_8")`:code:.
|
|
1643
|
+
"""
|
|
1644
|
+
max_supply: MaxSupplyMethod
|
|
1645
|
+
"""Constructor-initialized instance of
|
|
1646
|
+
:class:`MaxSupplyMethod`.
|
|
1647
|
+
"""
|
|
1648
|
+
|
|
1649
|
+
pre_mine_supply: PreMineSupplyMethod
|
|
1650
|
+
"""Constructor-initialized instance of
|
|
1651
|
+
:class:`PreMineSupplyMethod`.
|
|
1652
|
+
"""
|
|
1653
|
+
|
|
1654
|
+
allowance: AllowanceMethod
|
|
1655
|
+
"""Constructor-initialized instance of
|
|
1656
|
+
:class:`AllowanceMethod`.
|
|
1657
|
+
"""
|
|
1658
|
+
|
|
1659
|
+
approve: ApproveMethod
|
|
1660
|
+
"""Constructor-initialized instance of
|
|
1661
|
+
:class:`ApproveMethod`.
|
|
1662
|
+
"""
|
|
1663
|
+
|
|
1664
|
+
balance_of: BalanceOfMethod
|
|
1665
|
+
"""Constructor-initialized instance of
|
|
1666
|
+
:class:`BalanceOfMethod`.
|
|
1667
|
+
"""
|
|
1668
|
+
|
|
1669
|
+
burn: BurnMethod
|
|
1670
|
+
"""Constructor-initialized instance of
|
|
1671
|
+
:class:`BurnMethod`.
|
|
1672
|
+
"""
|
|
1673
|
+
|
|
1674
|
+
burn_from: BurnFromMethod
|
|
1675
|
+
"""Constructor-initialized instance of
|
|
1676
|
+
:class:`BurnFromMethod`.
|
|
1677
|
+
"""
|
|
1678
|
+
|
|
1679
|
+
checkpoints: CheckpointsMethod
|
|
1680
|
+
"""Constructor-initialized instance of
|
|
1681
|
+
:class:`CheckpointsMethod`.
|
|
1682
|
+
"""
|
|
1683
|
+
|
|
1684
|
+
decimals: DecimalsMethod
|
|
1685
|
+
"""Constructor-initialized instance of
|
|
1686
|
+
:class:`DecimalsMethod`.
|
|
1687
|
+
"""
|
|
1688
|
+
|
|
1689
|
+
decrease_allowance: DecreaseAllowanceMethod
|
|
1690
|
+
"""Constructor-initialized instance of
|
|
1691
|
+
:class:`DecreaseAllowanceMethod`.
|
|
1692
|
+
"""
|
|
1693
|
+
|
|
1694
|
+
delegate: DelegateMethod
|
|
1695
|
+
"""Constructor-initialized instance of
|
|
1696
|
+
:class:`DelegateMethod`.
|
|
1697
|
+
"""
|
|
1698
|
+
|
|
1699
|
+
delegate_by_sig: DelegateBySigMethod
|
|
1700
|
+
"""Constructor-initialized instance of
|
|
1701
|
+
:class:`DelegateBySigMethod`.
|
|
1702
|
+
"""
|
|
1703
|
+
|
|
1704
|
+
delegates: DelegatesMethod
|
|
1705
|
+
"""Constructor-initialized instance of
|
|
1706
|
+
:class:`DelegatesMethod`.
|
|
1707
|
+
"""
|
|
1708
|
+
|
|
1709
|
+
get_current_votes: GetCurrentVotesMethod
|
|
1710
|
+
"""Constructor-initialized instance of
|
|
1711
|
+
:class:`GetCurrentVotesMethod`.
|
|
1712
|
+
"""
|
|
1713
|
+
|
|
1714
|
+
get_prior_votes: GetPriorVotesMethod
|
|
1715
|
+
"""Constructor-initialized instance of
|
|
1716
|
+
:class:`GetPriorVotesMethod`.
|
|
1717
|
+
"""
|
|
1718
|
+
|
|
1719
|
+
increase_allowance: IncreaseAllowanceMethod
|
|
1720
|
+
"""Constructor-initialized instance of
|
|
1721
|
+
:class:`IncreaseAllowanceMethod`.
|
|
1722
|
+
"""
|
|
1723
|
+
|
|
1724
|
+
issued_supply: IssuedSupplyMethod
|
|
1725
|
+
"""Constructor-initialized instance of
|
|
1726
|
+
:class:`IssuedSupplyMethod`.
|
|
1727
|
+
"""
|
|
1728
|
+
|
|
1729
|
+
issuer: IssuerMethod
|
|
1730
|
+
"""Constructor-initialized instance of
|
|
1731
|
+
:class:`IssuerMethod`.
|
|
1732
|
+
"""
|
|
1733
|
+
|
|
1734
|
+
mint: MintMethod
|
|
1735
|
+
"""Constructor-initialized instance of
|
|
1736
|
+
:class:`MintMethod`.
|
|
1737
|
+
"""
|
|
1738
|
+
|
|
1739
|
+
name: NameMethod
|
|
1740
|
+
"""Constructor-initialized instance of
|
|
1741
|
+
:class:`NameMethod`.
|
|
1742
|
+
"""
|
|
1743
|
+
|
|
1744
|
+
nonces: NoncesMethod
|
|
1745
|
+
"""Constructor-initialized instance of
|
|
1746
|
+
:class:`NoncesMethod`.
|
|
1747
|
+
"""
|
|
1748
|
+
|
|
1749
|
+
num_checkpoints: NumCheckpointsMethod
|
|
1750
|
+
"""Constructor-initialized instance of
|
|
1751
|
+
:class:`NumCheckpointsMethod`.
|
|
1752
|
+
"""
|
|
1753
|
+
|
|
1754
|
+
ownership_transferred: OwnershipTransferredMethod
|
|
1755
|
+
"""Constructor-initialized instance of
|
|
1756
|
+
:class:`OwnershipTransferredMethod`.
|
|
1757
|
+
"""
|
|
1758
|
+
|
|
1759
|
+
permit: PermitMethod
|
|
1760
|
+
"""Constructor-initialized instance of
|
|
1761
|
+
:class:`PermitMethod`.
|
|
1762
|
+
"""
|
|
1763
|
+
|
|
1764
|
+
symbol: SymbolMethod
|
|
1765
|
+
"""Constructor-initialized instance of
|
|
1766
|
+
:class:`SymbolMethod`.
|
|
1767
|
+
"""
|
|
1768
|
+
|
|
1769
|
+
total_supply: TotalSupplyMethod
|
|
1770
|
+
"""Constructor-initialized instance of
|
|
1771
|
+
:class:`TotalSupplyMethod`.
|
|
1772
|
+
"""
|
|
1773
|
+
|
|
1774
|
+
transfer: TransferMethod
|
|
1775
|
+
"""Constructor-initialized instance of
|
|
1776
|
+
:class:`TransferMethod`.
|
|
1777
|
+
"""
|
|
1778
|
+
|
|
1779
|
+
transfer_from: TransferFromMethod
|
|
1780
|
+
"""Constructor-initialized instance of
|
|
1781
|
+
:class:`TransferFromMethod`.
|
|
1782
|
+
"""
|
|
1783
|
+
|
|
1784
|
+
transfer_ownership_to_deriva_dex_proxy: TransferOwnershipToDerivaDexProxyMethod
|
|
1785
|
+
"""Constructor-initialized instance of
|
|
1786
|
+
:class:`TransferOwnershipToDerivaDexProxyMethod`.
|
|
1787
|
+
"""
|
|
1788
|
+
|
|
1789
|
+
version: VersionMethod
|
|
1790
|
+
"""Constructor-initialized instance of
|
|
1791
|
+
:class:`VersionMethod`.
|
|
1792
|
+
"""
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
def __init__(
|
|
1796
|
+
self,
|
|
1797
|
+
web3_or_provider: Union[Web3, BaseProvider],
|
|
1798
|
+
contract_address: str,
|
|
1799
|
+
validator: DDXValidator = None,
|
|
1800
|
+
):
|
|
1801
|
+
"""Get an instance of wrapper for smart contract.
|
|
1802
|
+
|
|
1803
|
+
:param web3_or_provider: Either an instance of `web3.Web3`:code: or
|
|
1804
|
+
`web3.providers.base.BaseProvider`:code:
|
|
1805
|
+
:param contract_address: where the contract has been deployed
|
|
1806
|
+
:param validator: for validation of method inputs.
|
|
1807
|
+
"""
|
|
1808
|
+
# pylint: disable=too-many-statements
|
|
1809
|
+
|
|
1810
|
+
self.contract_address = contract_address
|
|
1811
|
+
|
|
1812
|
+
if not validator:
|
|
1813
|
+
validator = DDXValidator(web3_or_provider, contract_address)
|
|
1814
|
+
|
|
1815
|
+
web3 = None
|
|
1816
|
+
if isinstance(web3_or_provider, BaseProvider):
|
|
1817
|
+
web3 = Web3(web3_or_provider)
|
|
1818
|
+
elif isinstance(web3_or_provider, Web3):
|
|
1819
|
+
web3 = web3_or_provider
|
|
1820
|
+
else:
|
|
1821
|
+
raise TypeError(
|
|
1822
|
+
"Expected parameter 'web3_or_provider' to be an instance of either"
|
|
1823
|
+
+ " Web3 or BaseProvider"
|
|
1824
|
+
)
|
|
1825
|
+
|
|
1826
|
+
# if any middleware was imported, inject it
|
|
1827
|
+
try:
|
|
1828
|
+
MIDDLEWARE
|
|
1829
|
+
except NameError:
|
|
1830
|
+
pass
|
|
1831
|
+
else:
|
|
1832
|
+
try:
|
|
1833
|
+
for middleware in MIDDLEWARE:
|
|
1834
|
+
web3.middleware_onion.inject(
|
|
1835
|
+
middleware['function'], layer=middleware['layer'],
|
|
1836
|
+
)
|
|
1837
|
+
except ValueError as value_error:
|
|
1838
|
+
if value_error.args == ("You can't add the same un-named instance twice",):
|
|
1839
|
+
pass
|
|
1840
|
+
|
|
1841
|
+
self._web3_eth = web3.eth
|
|
1842
|
+
|
|
1843
|
+
functions = self._web3_eth.contract(address=to_checksum_address(contract_address), abi=DDX.abi()).functions
|
|
1844
|
+
|
|
1845
|
+
self.max_supply = MaxSupplyMethod(web3_or_provider, contract_address, functions.MAX_SUPPLY)
|
|
1846
|
+
|
|
1847
|
+
self.pre_mine_supply = PreMineSupplyMethod(web3_or_provider, contract_address, functions.PRE_MINE_SUPPLY)
|
|
1848
|
+
|
|
1849
|
+
self.allowance = AllowanceMethod(web3_or_provider, contract_address, functions.allowance, validator)
|
|
1850
|
+
|
|
1851
|
+
self.approve = ApproveMethod(web3_or_provider, contract_address, functions.approve, validator)
|
|
1852
|
+
|
|
1853
|
+
self.balance_of = BalanceOfMethod(web3_or_provider, contract_address, functions.balanceOf, validator)
|
|
1854
|
+
|
|
1855
|
+
self.burn = BurnMethod(web3_or_provider, contract_address, functions.burn, validator)
|
|
1856
|
+
|
|
1857
|
+
self.burn_from = BurnFromMethod(web3_or_provider, contract_address, functions.burnFrom, validator)
|
|
1858
|
+
|
|
1859
|
+
self.checkpoints = CheckpointsMethod(web3_or_provider, contract_address, functions.checkpoints, validator)
|
|
1860
|
+
|
|
1861
|
+
self.decimals = DecimalsMethod(web3_or_provider, contract_address, functions.decimals)
|
|
1862
|
+
|
|
1863
|
+
self.decrease_allowance = DecreaseAllowanceMethod(web3_or_provider, contract_address, functions.decreaseAllowance, validator)
|
|
1864
|
+
|
|
1865
|
+
self.delegate = DelegateMethod(web3_or_provider, contract_address, functions.delegate, validator)
|
|
1866
|
+
|
|
1867
|
+
self.delegate_by_sig = DelegateBySigMethod(web3_or_provider, contract_address, functions.delegateBySig, validator)
|
|
1868
|
+
|
|
1869
|
+
self.delegates = DelegatesMethod(web3_or_provider, contract_address, functions.delegates, validator)
|
|
1870
|
+
|
|
1871
|
+
self.get_current_votes = GetCurrentVotesMethod(web3_or_provider, contract_address, functions.getCurrentVotes, validator)
|
|
1872
|
+
|
|
1873
|
+
self.get_prior_votes = GetPriorVotesMethod(web3_or_provider, contract_address, functions.getPriorVotes, validator)
|
|
1874
|
+
|
|
1875
|
+
self.increase_allowance = IncreaseAllowanceMethod(web3_or_provider, contract_address, functions.increaseAllowance, validator)
|
|
1876
|
+
|
|
1877
|
+
self.issued_supply = IssuedSupplyMethod(web3_or_provider, contract_address, functions.issuedSupply)
|
|
1878
|
+
|
|
1879
|
+
self.issuer = IssuerMethod(web3_or_provider, contract_address, functions.issuer)
|
|
1880
|
+
|
|
1881
|
+
self.mint = MintMethod(web3_or_provider, contract_address, functions.mint, validator)
|
|
1882
|
+
|
|
1883
|
+
self.name = NameMethod(web3_or_provider, contract_address, functions.name)
|
|
1884
|
+
|
|
1885
|
+
self.nonces = NoncesMethod(web3_or_provider, contract_address, functions.nonces, validator)
|
|
1886
|
+
|
|
1887
|
+
self.num_checkpoints = NumCheckpointsMethod(web3_or_provider, contract_address, functions.numCheckpoints, validator)
|
|
1888
|
+
|
|
1889
|
+
self.ownership_transferred = OwnershipTransferredMethod(web3_or_provider, contract_address, functions.ownershipTransferred)
|
|
1890
|
+
|
|
1891
|
+
self.permit = PermitMethod(web3_or_provider, contract_address, functions.permit, validator)
|
|
1892
|
+
|
|
1893
|
+
self.symbol = SymbolMethod(web3_or_provider, contract_address, functions.symbol)
|
|
1894
|
+
|
|
1895
|
+
self.total_supply = TotalSupplyMethod(web3_or_provider, contract_address, functions.totalSupply)
|
|
1896
|
+
|
|
1897
|
+
self.transfer = TransferMethod(web3_or_provider, contract_address, functions.transfer, validator)
|
|
1898
|
+
|
|
1899
|
+
self.transfer_from = TransferFromMethod(web3_or_provider, contract_address, functions.transferFrom, validator)
|
|
1900
|
+
|
|
1901
|
+
self.transfer_ownership_to_deriva_dex_proxy = TransferOwnershipToDerivaDexProxyMethod(web3_or_provider, contract_address, functions.transferOwnershipToDerivaDEXProxy, validator)
|
|
1902
|
+
|
|
1903
|
+
self.version = VersionMethod(web3_or_provider, contract_address, functions.version)
|
|
1904
|
+
|
|
1905
|
+
def get_approval_event(
|
|
1906
|
+
self, tx_hash: Union[HexBytes, bytes]
|
|
1907
|
+
) -> Tuple[AttributeDict]:
|
|
1908
|
+
"""Get log entry for Approval event.
|
|
1909
|
+
|
|
1910
|
+
:param tx_hash: hash of transaction emitting Approval event
|
|
1911
|
+
"""
|
|
1912
|
+
tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
|
|
1913
|
+
return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=DDX.abi()).events.Approval().process_receipt(tx_receipt)
|
|
1914
|
+
def get_delegate_changed_event(
|
|
1915
|
+
self, tx_hash: Union[HexBytes, bytes]
|
|
1916
|
+
) -> Tuple[AttributeDict]:
|
|
1917
|
+
"""Get log entry for DelegateChanged event.
|
|
1918
|
+
|
|
1919
|
+
:param tx_hash: hash of transaction emitting DelegateChanged event
|
|
1920
|
+
"""
|
|
1921
|
+
tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
|
|
1922
|
+
return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=DDX.abi()).events.DelegateChanged().process_receipt(tx_receipt)
|
|
1923
|
+
def get_delegate_votes_changed_event(
|
|
1924
|
+
self, tx_hash: Union[HexBytes, bytes]
|
|
1925
|
+
) -> Tuple[AttributeDict]:
|
|
1926
|
+
"""Get log entry for DelegateVotesChanged event.
|
|
1927
|
+
|
|
1928
|
+
:param tx_hash: hash of transaction emitting DelegateVotesChanged event
|
|
1929
|
+
"""
|
|
1930
|
+
tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
|
|
1931
|
+
return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=DDX.abi()).events.DelegateVotesChanged().process_receipt(tx_receipt)
|
|
1932
|
+
def get_transfer_event(
|
|
1933
|
+
self, tx_hash: Union[HexBytes, bytes]
|
|
1934
|
+
) -> Tuple[AttributeDict]:
|
|
1935
|
+
"""Get log entry for Transfer event.
|
|
1936
|
+
|
|
1937
|
+
:param tx_hash: hash of transaction emitting Transfer event
|
|
1938
|
+
"""
|
|
1939
|
+
tx_receipt = self._web3_eth.get_transaction_receipt(tx_hash)
|
|
1940
|
+
return self._web3_eth.contract(address=to_checksum_address(self.contract_address), abi=DDX.abi()).events.Transfer().process_receipt(tx_receipt)
|
|
1941
|
+
|
|
1942
|
+
@staticmethod
|
|
1943
|
+
def abi():
|
|
1944
|
+
"""Return the ABI to the underlying contract."""
|
|
1945
|
+
return json.loads(
|
|
1946
|
+
'[{"inputs":[],"stateMutability":"nonpayable","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":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"address","name":"fromDelegate","type":"address"},{"indexed":true,"internalType":"address","name":"toDelegate","type":"address"}],"name":"DelegateChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegate","type":"address"},{"indexed":false,"internalType":"uint96","name":"previousBalance","type":"uint96"},{"indexed":false,"internalType":"uint96","name":"newBalance","type":"uint96"}],"name":"DelegateVotesChanged","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":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRE_MINE_SUPPLY","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","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":"uint256","name":"_amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"burnFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"},{"internalType":"uint256","name":"index_1","type":"uint256"}],"name":"checkpoints","outputs":[{"internalType":"uint32","name":"id","type":"uint32"},{"internalType":"uint96","name":"votes","type":"uint96"}],"stateMutability":"view","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":"_delegatee","type":"address"}],"name":"delegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegatee","type":"address"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"uint256","name":"_expiry","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"delegateBySig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"}],"name":"delegates","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"getCurrentVotes","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"uint256","name":"_blockNumber","type":"uint256"}],"name":"getPriorVotes","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","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":"issuedSupply","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"issuer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","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":[{"internalType":"address","name":"index_0","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"index_0","type":"address"}],"name":"numCheckpoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ownershipTransferred","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"uint256","name":"_expiry","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","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":"_recipient","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_derivaDEXProxy","type":"address"}],"name":"transferOwnershipToDerivaDEXProxy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]' # noqa: E501 (line-too-long)
|
|
1947
|
+
)
|
|
1948
|
+
|
|
1949
|
+
# pylint: disable=too-many-lines
|