avantis-trader-sdk 0.8.2__py3-none-any.whl → 0.8.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. avantis_trader_sdk/__init__.py +5 -5
  2. avantis_trader_sdk/abis/AggregatorV3Interface.json +606 -606
  3. avantis_trader_sdk/abis/IPyth.sol/IPyth.dbg.json +4 -4
  4. avantis_trader_sdk/abis/Referral.sol/ReferralStorage.json +7132 -7132
  5. avantis_trader_sdk/abis/Sanctions.json +190 -190
  6. avantis_trader_sdk/abis/Trading.sol/Trading.json +1 -1
  7. avantis_trader_sdk/abis/USDC.sol/USDC.dbg.json +4 -4
  8. avantis_trader_sdk/abis/interfaces/ICallbacks.sol/ICallbacks.json +2637 -2637
  9. avantis_trader_sdk/abis/interfaces/IExecute.sol/IExecute.json +1628 -1628
  10. avantis_trader_sdk/abis/interfaces/IPairInfos.sol/IPairInfos.json +2781 -2781
  11. avantis_trader_sdk/abis/interfaces/IPairStorage.sol/IPairStorage.json +3729 -3729
  12. avantis_trader_sdk/abis/interfaces/IPriceAggregator.sol/IPriceAggregator.json +2330 -2330
  13. avantis_trader_sdk/abis/interfaces/IReferral.sol/IReferral.json +1890 -1890
  14. avantis_trader_sdk/abis/interfaces/ITradingStorage.sol/ITradingStorage.json +7022 -7022
  15. avantis_trader_sdk/abis/interfaces/ITranche.sol/ITranche.json +1283 -1283
  16. avantis_trader_sdk/abis/interfaces/IVaultManager.sol/IVaultManager.json +2424 -2424
  17. avantis_trader_sdk/abis/interfaces/IVeTranche.sol/IVeTranche.json +855 -855
  18. avantis_trader_sdk/abis/library/PositionMath.sol/PositionMath.dbg.json +4 -4
  19. avantis_trader_sdk/abis/library/PositionMath.sol/PositionMath.json +10 -10
  20. avantis_trader_sdk/abis/testnet/USDC.sol/USDC.dbg.json +4 -4
  21. avantis_trader_sdk/abis/testnet/USDC.sol/USDC.json +320 -320
  22. avantis_trader_sdk/client.py +369 -367
  23. avantis_trader_sdk/config.py +14 -14
  24. avantis_trader_sdk/feed/feed_client.py +263 -261
  25. avantis_trader_sdk/rpc/asset_parameters.py +499 -499
  26. avantis_trader_sdk/rpc/blended.py +71 -71
  27. avantis_trader_sdk/rpc/category_parameters.py +216 -216
  28. avantis_trader_sdk/rpc/fee_parameters.py +237 -237
  29. avantis_trader_sdk/rpc/pairs_cache.py +130 -130
  30. avantis_trader_sdk/rpc/rpc_helpers.py +8 -8
  31. avantis_trader_sdk/rpc/snapshot.py +142 -142
  32. avantis_trader_sdk/rpc/trade.py +701 -710
  33. avantis_trader_sdk/rpc/trading_parameters.py +139 -139
  34. avantis_trader_sdk/types.py +462 -462
  35. avantis_trader_sdk/utils.py +78 -78
  36. {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.4.dist-info}/METADATA +124 -113
  37. {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.4.dist-info}/RECORD +39 -40
  38. {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.4.dist-info}/WHEEL +1 -1
  39. avantis_trader_sdk/feed/feedIds.json +0 -214
  40. {avantis_trader_sdk-0.8.2.dist-info → avantis_trader_sdk-0.8.4.dist-info}/top_level.txt +0 -0
@@ -1,367 +1,369 @@
1
- import json
2
- from pathlib import Path
3
- from web3 import Web3, AsyncWeb3
4
- from .config import CONTRACT_ADDRESSES
5
- from .rpc.pairs_cache import PairsCache
6
- from .rpc.asset_parameters import AssetParametersRPC
7
- from .rpc.category_parameters import CategoryParametersRPC
8
- from .rpc.blended import BlendedRPC
9
- from .rpc.fee_parameters import FeeParametersRPC
10
- from .rpc.trading_parameters import TradingParametersRPC
11
- from .rpc.snapshot import SnapshotRPC
12
- from .rpc.trade import TradeRPC
13
- from .utils import decoder
14
- from .feed.feed_client import FeedClient
15
-
16
- from .signers.base import BaseSigner
17
- from .signers.local_signer import LocalSigner
18
- from .signers.kms_signer import KMSSigner
19
-
20
-
21
- class TraderClient:
22
- """
23
- This class provides methods to interact with the Avantis smart contracts.
24
- """
25
-
26
- def __init__(
27
- self,
28
- provider_url,
29
- l1_provider_url="https://eth.llamarpc.com",
30
- signer: BaseSigner = None,
31
- ):
32
- """
33
- Constructor for the TraderClient class.
34
-
35
- Args:
36
- provider_url: The URL of the Ethereum node provider.
37
- l1_provider_url (optional): The URL of the L1 Ethereum node provider.
38
- signer (optional): The signer to use for signing transactions.
39
- """
40
- self.web3 = Web3(
41
- Web3.HTTPProvider(provider_url, request_kwargs={"timeout": 60})
42
- )
43
- self.async_web3 = AsyncWeb3(
44
- AsyncWeb3.AsyncHTTPProvider(provider_url, request_kwargs={"timeout": 60})
45
- )
46
-
47
- self.l1_web3 = Web3(
48
- Web3.HTTPProvider(l1_provider_url, request_kwargs={"timeout": 60})
49
- )
50
-
51
- self.l1_async_web3 = AsyncWeb3(
52
- AsyncWeb3.AsyncHTTPProvider(l1_provider_url, request_kwargs={"timeout": 60})
53
- )
54
-
55
- self.contracts = self.load_contracts()
56
- self.chain_id = self.web3.eth.chain_id
57
-
58
- self.utils = {
59
- "decoder": lambda *args, **kwargs: decoder(self.web3, *args, **kwargs)
60
- }
61
-
62
- self.pairs_cache = PairsCache(self)
63
- self.asset_parameters = AssetParametersRPC(self)
64
- self.category_parameters = CategoryParametersRPC(self)
65
- self.blended = BlendedRPC(self)
66
- self.fee_parameters = FeeParametersRPC(self)
67
- self.trading_parameters = TradingParametersRPC(self)
68
- self.snapshot = SnapshotRPC(self)
69
- self.trade = TradeRPC(self, FeedClient)
70
-
71
- self.signer = signer
72
-
73
- def load_contract(self, name):
74
- """
75
- Loads the contract ABI and address from the local filesystem.
76
-
77
- Args:
78
- name: The name of the contract.
79
-
80
- Returns:
81
- A Contract object.
82
- """
83
- abi_path = Path(__file__).parent / "abis" / f"{name}.sol" / f"{name}.json"
84
- with open(abi_path) as abi_file:
85
- abi = json.load(abi_file)
86
- address = CONTRACT_ADDRESSES[name]
87
- return self.async_web3.eth.contract(address=address, abi=abi["abi"])
88
-
89
- def load_contracts(self):
90
- """
91
- Loads all the contracts mentioned in the config from the local filesystem.
92
-
93
- Returns:
94
- A dictionary containing the contract names as keys and the Contract objects as values.
95
- """
96
- return {name: self.load_contract(name) for name in CONTRACT_ADDRESSES.keys()}
97
-
98
- async def read_contract(self, contract_name, function_name, *args, decode=True):
99
- """
100
- Calls a read-only function of a contract.
101
-
102
- Args:
103
- contract_name: The name of the contract.
104
- function_name: The name of the function.
105
- args: The arguments to the function.
106
-
107
- Returns:
108
- The result of the function call.
109
- """
110
- contract = self.contracts.get(contract_name)
111
- if not contract:
112
- raise ValueError(f"Contract {contract_name} not found")
113
-
114
- raw_data = await contract.functions[function_name](*args).call()
115
-
116
- if decode:
117
- return self.utils["decoder"](contract, function_name, raw_data)
118
-
119
- return raw_data
120
-
121
- async def write_contract(self, contract_name, function_name, *args, **kwargs):
122
- """
123
- Calls a write function of a contract.
124
-
125
- Args:
126
- contract_name: The name of the contract.
127
- function_name: The name of the function.
128
- args: The arguments to the function.
129
-
130
- Returns:
131
- The transaction hash or the transaction object if signer is None.
132
- """
133
- contract = self.contracts.get(contract_name)
134
- if not contract:
135
- raise ValueError(f"Contract {contract_name} not found")
136
-
137
- if self.has_signer() and "from" not in kwargs:
138
- kwargs["from"] = self.get_signer().get_ethereum_address()
139
-
140
- if "chainId" not in kwargs:
141
- kwargs["chainId"] = self.chain_id
142
-
143
- if "nonce" not in kwargs:
144
- kwargs["nonce"] = await self.get_transaction_count(kwargs["from"])
145
-
146
- transaction = await contract.functions[function_name](*args).build_transaction(
147
- kwargs
148
- )
149
-
150
- if not self.has_signer():
151
- return transaction
152
-
153
- receipt = await self.sign_and_get_receipt(transaction)
154
- return receipt
155
-
156
- def set_signer(self, signer: BaseSigner):
157
- """
158
- Sets the signer.
159
- """
160
- self.signer = signer
161
-
162
- def get_signer(self):
163
- """
164
- Gets the signer.
165
- """
166
- return self.signer
167
-
168
- def remove_signer(self):
169
- """
170
- Removes the signer.
171
- """
172
- self.signer = None
173
-
174
- def has_signer(self):
175
- """
176
- Checks if the signer is set.
177
- """
178
- return self.signer is not None
179
-
180
- def set_local_signer(self, private_key):
181
- """
182
- Sets the local signer.
183
- """
184
- self.signer = LocalSigner(private_key, self.async_web3)
185
-
186
- def set_aws_kms_signer(self, kms_key_id, region_name="us-east-1"):
187
- """
188
- Sets the AWS KMS signer.
189
- """
190
- self.signer = KMSSigner(self.async_web3, kms_key_id, region_name)
191
-
192
- async def sign_transaction(self, transaction):
193
- """
194
- Signs a transaction.
195
-
196
- Args:
197
- transaction: The transaction object.
198
-
199
- Returns:
200
- The signed transaction object.
201
- """
202
- if not self.has_signer():
203
- raise ValueError(
204
- "No signer is set. Please set a signer using `set_signer`."
205
- )
206
- return await self.signer.sign_transaction(transaction)
207
-
208
- async def send_and_get_transaction_hash(self, signed_txn):
209
- """
210
- Gets the transaction hash.
211
-
212
- Args:
213
- signed_txn: The signed transaction object.
214
-
215
- Returns:
216
- The transaction hash.
217
- """
218
- return await self.async_web3.eth.send_raw_transaction(signed_txn.rawTransaction)
219
-
220
- async def wait_for_transaction_receipt(self, tx_hash):
221
- """
222
- Waits for the transaction to be mined.
223
-
224
- Args:
225
- tx_hash: The transaction hash.
226
-
227
- Returns:
228
- The transaction receipt.
229
- """
230
- return await self.async_web3.eth.wait_for_transaction_receipt(tx_hash)
231
-
232
- async def sign_and_get_receipt(self, transaction):
233
- """
234
- Signs a transaction and waits for it to be mined.
235
-
236
- Args:
237
- transaction: The transaction object.
238
-
239
- Returns:
240
- The transaction receipt.
241
- """
242
- gas_estimate = await self.get_gas_estimate(transaction)
243
- transaction["gas"] = gas_estimate
244
- signed_txn = await self.sign_transaction(transaction)
245
- tx_hash = await self.send_and_get_transaction_hash(signed_txn)
246
- return await self.wait_for_transaction_receipt(tx_hash)
247
-
248
- async def get_transaction_count(self, address=None):
249
- """
250
- Gets the transaction count.
251
-
252
- Args:
253
- address (optional): The address.
254
-
255
- Returns:
256
- The transaction count.
257
- """
258
- if address is None:
259
- address = self.get_signer().get_ethereum_address()
260
- return await self.async_web3.eth.get_transaction_count(address)
261
-
262
- async def get_gas_price(self):
263
- """
264
- Gets the gas price.
265
-
266
- Returns:
267
- The gas price.
268
- """
269
- return await self.async_web3.eth.gas_price
270
-
271
- async def get_chain_id(self):
272
- """
273
- Gets the chain id.
274
-
275
- Returns:
276
- The chain id.
277
- """
278
- return await self.async_web3.eth.chain_id
279
-
280
- async def get_balance(self, address=None):
281
- """
282
- Gets the balance.
283
-
284
- Args:
285
- address (optional): The address.
286
-
287
- Returns:
288
- The balance.
289
- """
290
- if address is None:
291
- address = self.get_signer().get_ethereum_address()
292
- balance = await self.async_web3.eth.get_balance(address)
293
- return balance / 10**18
294
-
295
- async def get_usdc_balance(self, address=None):
296
- """
297
- Gets the USDC balance.
298
-
299
- Args:
300
- address (optional): The address.
301
-
302
- Returns:
303
- The USDC balance.
304
- """
305
- if address is None:
306
- address = self.get_signer().get_ethereum_address()
307
- balance = await self.read_contract("USDC", "balanceOf", address, decode=False)
308
- return balance / 10**6
309
-
310
- async def get_usdc_allowance_for_trading(self, address=None):
311
- """
312
- Gets the USDC allowance for the Trading Storage contract.
313
-
314
- Args:
315
- address (optional): The address.
316
-
317
- Returns:
318
- The USDC allowance.
319
- """
320
- if address is None:
321
- address = self.get_signer().get_ethereum_address()
322
-
323
- trading_storage_address = self.contracts["TradingStorage"].address
324
-
325
- allowance = await self.read_contract(
326
- "USDC", "allowance", address, trading_storage_address, decode=False
327
- )
328
- return allowance / 10**6
329
-
330
- async def approve_usdc_for_trading(self, amount=100000):
331
- """
332
- Approves the USDC amount for the Trading Storage contract.
333
-
334
- Args:
335
- amount (optional): The amount to approve. Defaults to $100,000.
336
-
337
- Returns:
338
- The transaction hash.
339
- """
340
- trading_storage_address = self.contracts["TradingStorage"].address
341
- return await self.write_contract(
342
- "USDC", "approve", trading_storage_address, int(amount * 10**6)
343
- )
344
-
345
- async def get_gas_estimate(self, transaction):
346
- """
347
- Gets the gas estimate.
348
-
349
- Args:
350
- transaction: The transaction object.
351
-
352
- Returns:
353
- The gas estimate.
354
- """
355
- return await self.async_web3.eth.estimate_gas(transaction)
356
-
357
- async def get_transaction_hex(self, transaction):
358
- """
359
- Gets the transaction hex.
360
-
361
- Args:
362
- transaction: The transaction object.
363
-
364
- Returns:
365
- The transaction hex.
366
- """
367
- return transaction.hex()
1
+ import json
2
+ from pathlib import Path
3
+ from web3 import Web3, AsyncWeb3
4
+ from .config import CONTRACT_ADDRESSES
5
+ from .rpc.pairs_cache import PairsCache
6
+ from .rpc.asset_parameters import AssetParametersRPC
7
+ from .rpc.category_parameters import CategoryParametersRPC
8
+ from .rpc.blended import BlendedRPC
9
+ from .rpc.fee_parameters import FeeParametersRPC
10
+ from .rpc.trading_parameters import TradingParametersRPC
11
+ from .rpc.snapshot import SnapshotRPC
12
+ from .rpc.trade import TradeRPC
13
+ from .utils import decoder
14
+ from .feed.feed_client import FeedClient
15
+
16
+ from .signers.base import BaseSigner
17
+ from .signers.local_signer import LocalSigner
18
+ from .signers.kms_signer import KMSSigner
19
+
20
+
21
+ class TraderClient:
22
+ """
23
+ This class provides methods to interact with the Avantis smart contracts.
24
+ """
25
+
26
+ def __init__(
27
+ self,
28
+ provider_url,
29
+ l1_provider_url="https://eth.llamarpc.com",
30
+ signer: BaseSigner = None,
31
+ feed_client: FeedClient = None,
32
+ ):
33
+ """
34
+ Constructor for the TraderClient class.
35
+
36
+ Args:
37
+ provider_url: The URL of the Ethereum node provider.
38
+ l1_provider_url (optional): The URL of the L1 Ethereum node provider.
39
+ signer (optional): The signer to use for signing transactions.
40
+ """
41
+ self.web3 = Web3(
42
+ Web3.HTTPProvider(provider_url, request_kwargs={"timeout": 60})
43
+ )
44
+ self.async_web3 = AsyncWeb3(
45
+ AsyncWeb3.AsyncHTTPProvider(provider_url, request_kwargs={"timeout": 60})
46
+ )
47
+
48
+ self.l1_web3 = Web3(
49
+ Web3.HTTPProvider(l1_provider_url, request_kwargs={"timeout": 60})
50
+ )
51
+
52
+ self.l1_async_web3 = AsyncWeb3(
53
+ AsyncWeb3.AsyncHTTPProvider(l1_provider_url, request_kwargs={"timeout": 60})
54
+ )
55
+
56
+ self.contracts = self.load_contracts()
57
+ self.chain_id = self.web3.eth.chain_id
58
+
59
+ self.utils = {
60
+ "decoder": lambda *args, **kwargs: decoder(self.web3, *args, **kwargs)
61
+ }
62
+
63
+ self.pairs_cache = PairsCache(self)
64
+ self.asset_parameters = AssetParametersRPC(self)
65
+ self.category_parameters = CategoryParametersRPC(self)
66
+ self.blended = BlendedRPC(self)
67
+ self.fee_parameters = FeeParametersRPC(self)
68
+ self.trading_parameters = TradingParametersRPC(self)
69
+ self.snapshot = SnapshotRPC(self)
70
+ self.feed_client = feed_client or FeedClient()
71
+ self.trade = TradeRPC(self, self.feed_client)
72
+
73
+ self.signer = signer
74
+
75
+ def load_contract(self, name):
76
+ """
77
+ Loads the contract ABI and address from the local filesystem.
78
+
79
+ Args:
80
+ name: The name of the contract.
81
+
82
+ Returns:
83
+ A Contract object.
84
+ """
85
+ abi_path = Path(__file__).parent / "abis" / f"{name}.sol" / f"{name}.json"
86
+ with open(abi_path) as abi_file:
87
+ abi = json.load(abi_file)
88
+ address = CONTRACT_ADDRESSES[name]
89
+ return self.async_web3.eth.contract(address=address, abi=abi["abi"])
90
+
91
+ def load_contracts(self):
92
+ """
93
+ Loads all the contracts mentioned in the config from the local filesystem.
94
+
95
+ Returns:
96
+ A dictionary containing the contract names as keys and the Contract objects as values.
97
+ """
98
+ return {name: self.load_contract(name) for name in CONTRACT_ADDRESSES.keys()}
99
+
100
+ async def read_contract(self, contract_name, function_name, *args, decode=True):
101
+ """
102
+ Calls a read-only function of a contract.
103
+
104
+ Args:
105
+ contract_name: The name of the contract.
106
+ function_name: The name of the function.
107
+ args: The arguments to the function.
108
+
109
+ Returns:
110
+ The result of the function call.
111
+ """
112
+ contract = self.contracts.get(contract_name)
113
+ if not contract:
114
+ raise ValueError(f"Contract {contract_name} not found")
115
+
116
+ raw_data = await contract.functions[function_name](*args).call()
117
+
118
+ if decode:
119
+ return self.utils["decoder"](contract, function_name, raw_data)
120
+
121
+ return raw_data
122
+
123
+ async def write_contract(self, contract_name, function_name, *args, **kwargs):
124
+ """
125
+ Calls a write function of a contract.
126
+
127
+ Args:
128
+ contract_name: The name of the contract.
129
+ function_name: The name of the function.
130
+ args: The arguments to the function.
131
+
132
+ Returns:
133
+ The transaction hash or the transaction object if signer is None.
134
+ """
135
+ contract = self.contracts.get(contract_name)
136
+ if not contract:
137
+ raise ValueError(f"Contract {contract_name} not found")
138
+
139
+ if self.has_signer() and "from" not in kwargs:
140
+ kwargs["from"] = self.get_signer().get_ethereum_address()
141
+
142
+ if "chainId" not in kwargs:
143
+ kwargs["chainId"] = self.chain_id
144
+
145
+ if "nonce" not in kwargs:
146
+ kwargs["nonce"] = await self.get_transaction_count(kwargs["from"])
147
+
148
+ transaction = await contract.functions[function_name](*args).build_transaction(
149
+ kwargs
150
+ )
151
+
152
+ if not self.has_signer():
153
+ return transaction
154
+
155
+ receipt = await self.sign_and_get_receipt(transaction)
156
+ return receipt
157
+
158
+ def set_signer(self, signer: BaseSigner):
159
+ """
160
+ Sets the signer.
161
+ """
162
+ self.signer = signer
163
+
164
+ def get_signer(self):
165
+ """
166
+ Gets the signer.
167
+ """
168
+ return self.signer
169
+
170
+ def remove_signer(self):
171
+ """
172
+ Removes the signer.
173
+ """
174
+ self.signer = None
175
+
176
+ def has_signer(self):
177
+ """
178
+ Checks if the signer is set.
179
+ """
180
+ return self.signer is not None
181
+
182
+ def set_local_signer(self, private_key):
183
+ """
184
+ Sets the local signer.
185
+ """
186
+ self.signer = LocalSigner(private_key, self.async_web3)
187
+
188
+ def set_aws_kms_signer(self, kms_key_id, region_name="us-east-1"):
189
+ """
190
+ Sets the AWS KMS signer.
191
+ """
192
+ self.signer = KMSSigner(self.async_web3, kms_key_id, region_name)
193
+
194
+ async def sign_transaction(self, transaction):
195
+ """
196
+ Signs a transaction.
197
+
198
+ Args:
199
+ transaction: The transaction object.
200
+
201
+ Returns:
202
+ The signed transaction object.
203
+ """
204
+ if not self.has_signer():
205
+ raise ValueError(
206
+ "No signer is set. Please set a signer using `set_signer`."
207
+ )
208
+ return await self.signer.sign_transaction(transaction)
209
+
210
+ async def send_and_get_transaction_hash(self, signed_txn):
211
+ """
212
+ Gets the transaction hash.
213
+
214
+ Args:
215
+ signed_txn: The signed transaction object.
216
+
217
+ Returns:
218
+ The transaction hash.
219
+ """
220
+ return await self.async_web3.eth.send_raw_transaction(signed_txn.rawTransaction)
221
+
222
+ async def wait_for_transaction_receipt(self, tx_hash):
223
+ """
224
+ Waits for the transaction to be mined.
225
+
226
+ Args:
227
+ tx_hash: The transaction hash.
228
+
229
+ Returns:
230
+ The transaction receipt.
231
+ """
232
+ return await self.async_web3.eth.wait_for_transaction_receipt(tx_hash)
233
+
234
+ async def sign_and_get_receipt(self, transaction):
235
+ """
236
+ Signs a transaction and waits for it to be mined.
237
+
238
+ Args:
239
+ transaction: The transaction object.
240
+
241
+ Returns:
242
+ The transaction receipt.
243
+ """
244
+ gas_estimate = await self.get_gas_estimate(transaction)
245
+ transaction["gas"] = gas_estimate
246
+ signed_txn = await self.sign_transaction(transaction)
247
+ tx_hash = await self.send_and_get_transaction_hash(signed_txn)
248
+ return await self.wait_for_transaction_receipt(tx_hash)
249
+
250
+ async def get_transaction_count(self, address=None):
251
+ """
252
+ Gets the transaction count.
253
+
254
+ Args:
255
+ address (optional): The address.
256
+
257
+ Returns:
258
+ The transaction count.
259
+ """
260
+ if address is None:
261
+ address = self.get_signer().get_ethereum_address()
262
+ return await self.async_web3.eth.get_transaction_count(address)
263
+
264
+ async def get_gas_price(self):
265
+ """
266
+ Gets the gas price.
267
+
268
+ Returns:
269
+ The gas price.
270
+ """
271
+ return await self.async_web3.eth.gas_price
272
+
273
+ async def get_chain_id(self):
274
+ """
275
+ Gets the chain id.
276
+
277
+ Returns:
278
+ The chain id.
279
+ """
280
+ return await self.async_web3.eth.chain_id
281
+
282
+ async def get_balance(self, address=None):
283
+ """
284
+ Gets the balance.
285
+
286
+ Args:
287
+ address (optional): The address.
288
+
289
+ Returns:
290
+ The balance.
291
+ """
292
+ if address is None:
293
+ address = self.get_signer().get_ethereum_address()
294
+ balance = await self.async_web3.eth.get_balance(address)
295
+ return balance / 10**18
296
+
297
+ async def get_usdc_balance(self, address=None):
298
+ """
299
+ Gets the USDC balance.
300
+
301
+ Args:
302
+ address (optional): The address.
303
+
304
+ Returns:
305
+ The USDC balance.
306
+ """
307
+ if address is None:
308
+ address = self.get_signer().get_ethereum_address()
309
+ balance = await self.read_contract("USDC", "balanceOf", address, decode=False)
310
+ return balance / 10**6
311
+
312
+ async def get_usdc_allowance_for_trading(self, address=None):
313
+ """
314
+ Gets the USDC allowance for the Trading Storage contract.
315
+
316
+ Args:
317
+ address (optional): The address.
318
+
319
+ Returns:
320
+ The USDC allowance.
321
+ """
322
+ if address is None:
323
+ address = self.get_signer().get_ethereum_address()
324
+
325
+ trading_storage_address = self.contracts["TradingStorage"].address
326
+
327
+ allowance = await self.read_contract(
328
+ "USDC", "allowance", address, trading_storage_address, decode=False
329
+ )
330
+ return allowance / 10**6
331
+
332
+ async def approve_usdc_for_trading(self, amount=100000):
333
+ """
334
+ Approves the USDC amount for the Trading Storage contract.
335
+
336
+ Args:
337
+ amount (optional): The amount to approve. Defaults to $100,000.
338
+
339
+ Returns:
340
+ The transaction hash.
341
+ """
342
+ trading_storage_address = self.contracts["TradingStorage"].address
343
+ return await self.write_contract(
344
+ "USDC", "approve", trading_storage_address, int(amount * 10**6)
345
+ )
346
+
347
+ async def get_gas_estimate(self, transaction):
348
+ """
349
+ Gets the gas estimate.
350
+
351
+ Args:
352
+ transaction: The transaction object.
353
+
354
+ Returns:
355
+ The gas estimate.
356
+ """
357
+ return await self.async_web3.eth.estimate_gas(transaction)
358
+
359
+ async def get_transaction_hex(self, transaction):
360
+ """
361
+ Gets the transaction hex.
362
+
363
+ Args:
364
+ transaction: The transaction object.
365
+
366
+ Returns:
367
+ The transaction hex.
368
+ """
369
+ return transaction.hex()