mech-client 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mech_client/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Mech client."""
2
2
 
3
- __version__ = "0.3.0"
3
+ __version__ = "0.4.0"
@@ -0,0 +1,660 @@
1
+ [
2
+ {
3
+ "inputs": [
4
+ {
5
+ "internalType": "address",
6
+ "name": "_mechMarketplace",
7
+ "type": "address"
8
+ },
9
+ {
10
+ "internalType": "address",
11
+ "name": "_drainer",
12
+ "type": "address"
13
+ },
14
+ {
15
+ "internalType": "address",
16
+ "name": "_token",
17
+ "type": "address"
18
+ }
19
+ ],
20
+ "stateMutability": "nonpayable",
21
+ "type": "constructor"
22
+ },
23
+ {
24
+ "inputs": [
25
+ {
26
+ "internalType": "uint256",
27
+ "name": "current",
28
+ "type": "uint256"
29
+ },
30
+ {
31
+ "internalType": "uint256",
32
+ "name": "required",
33
+ "type": "uint256"
34
+ }
35
+ ],
36
+ "name": "InsufficientBalance",
37
+ "type": "error"
38
+ },
39
+ {
40
+ "inputs": [
41
+ {
42
+ "internalType": "address",
43
+ "name": "sender",
44
+ "type": "address"
45
+ },
46
+ {
47
+ "internalType": "address",
48
+ "name": "marketplace",
49
+ "type": "address"
50
+ }
51
+ ],
52
+ "name": "MarketplaceOnly",
53
+ "type": "error"
54
+ },
55
+ {
56
+ "inputs": [
57
+ {
58
+ "internalType": "uint256",
59
+ "name": "amount",
60
+ "type": "uint256"
61
+ }
62
+ ],
63
+ "name": "NoDepositAllowed",
64
+ "type": "error"
65
+ },
66
+ {
67
+ "inputs": [
68
+ {
69
+ "internalType": "uint256",
70
+ "name": "provided",
71
+ "type": "uint256"
72
+ },
73
+ {
74
+ "internalType": "uint256",
75
+ "name": "max",
76
+ "type": "uint256"
77
+ }
78
+ ],
79
+ "name": "Overflow",
80
+ "type": "error"
81
+ },
82
+ {
83
+ "inputs": [
84
+ {
85
+ "internalType": "address",
86
+ "name": "sender",
87
+ "type": "address"
88
+ },
89
+ {
90
+ "internalType": "address",
91
+ "name": "owner",
92
+ "type": "address"
93
+ }
94
+ ],
95
+ "name": "OwnerOnly",
96
+ "type": "error"
97
+ },
98
+ {
99
+ "inputs": [],
100
+ "name": "ReentrancyGuard",
101
+ "type": "error"
102
+ },
103
+ {
104
+ "inputs": [
105
+ {
106
+ "internalType": "address",
107
+ "name": "account",
108
+ "type": "address"
109
+ }
110
+ ],
111
+ "name": "UnauthorizedAccount",
112
+ "type": "error"
113
+ },
114
+ {
115
+ "inputs": [],
116
+ "name": "ZeroAddress",
117
+ "type": "error"
118
+ },
119
+ {
120
+ "inputs": [],
121
+ "name": "ZeroValue",
122
+ "type": "error"
123
+ },
124
+ {
125
+ "anonymous": false,
126
+ "inputs": [
127
+ {
128
+ "indexed": true,
129
+ "internalType": "address",
130
+ "name": "account",
131
+ "type": "address"
132
+ },
133
+ {
134
+ "indexed": true,
135
+ "internalType": "address",
136
+ "name": "token",
137
+ "type": "address"
138
+ },
139
+ {
140
+ "indexed": false,
141
+ "internalType": "uint256",
142
+ "name": "amount",
143
+ "type": "uint256"
144
+ }
145
+ ],
146
+ "name": "Deposit",
147
+ "type": "event"
148
+ },
149
+ {
150
+ "anonymous": false,
151
+ "inputs": [
152
+ {
153
+ "indexed": true,
154
+ "internalType": "address",
155
+ "name": "token",
156
+ "type": "address"
157
+ },
158
+ {
159
+ "indexed": false,
160
+ "internalType": "uint256",
161
+ "name": "collectedFees",
162
+ "type": "uint256"
163
+ }
164
+ ],
165
+ "name": "Drained",
166
+ "type": "event"
167
+ },
168
+ {
169
+ "anonymous": false,
170
+ "inputs": [
171
+ {
172
+ "indexed": true,
173
+ "internalType": "address",
174
+ "name": "mech",
175
+ "type": "address"
176
+ },
177
+ {
178
+ "indexed": false,
179
+ "internalType": "uint256",
180
+ "name": "deliveryRate",
181
+ "type": "uint256"
182
+ },
183
+ {
184
+ "indexed": false,
185
+ "internalType": "uint256",
186
+ "name": "balance",
187
+ "type": "uint256"
188
+ },
189
+ {
190
+ "indexed": false,
191
+ "internalType": "uint256",
192
+ "name": "rateDiff",
193
+ "type": "uint256"
194
+ }
195
+ ],
196
+ "name": "MechBalanceAdjusted",
197
+ "type": "event"
198
+ },
199
+ {
200
+ "anonymous": false,
201
+ "inputs": [
202
+ {
203
+ "indexed": true,
204
+ "internalType": "address",
205
+ "name": "requester",
206
+ "type": "address"
207
+ },
208
+ {
209
+ "indexed": false,
210
+ "internalType": "uint256",
211
+ "name": "deliveryRate",
212
+ "type": "uint256"
213
+ },
214
+ {
215
+ "indexed": false,
216
+ "internalType": "uint256",
217
+ "name": "balance",
218
+ "type": "uint256"
219
+ }
220
+ ],
221
+ "name": "RequesterBalanceAdjusted",
222
+ "type": "event"
223
+ },
224
+ {
225
+ "anonymous": false,
226
+ "inputs": [
227
+ {
228
+ "indexed": true,
229
+ "internalType": "address",
230
+ "name": "account",
231
+ "type": "address"
232
+ },
233
+ {
234
+ "indexed": false,
235
+ "internalType": "uint256",
236
+ "name": "amount",
237
+ "type": "uint256"
238
+ }
239
+ ],
240
+ "name": "RequesterCreditsRedeemed",
241
+ "type": "event"
242
+ },
243
+ {
244
+ "anonymous": false,
245
+ "inputs": [
246
+ {
247
+ "indexed": true,
248
+ "internalType": "address",
249
+ "name": "token",
250
+ "type": "address"
251
+ },
252
+ {
253
+ "indexed": true,
254
+ "internalType": "uint256",
255
+ "name": "tokenId",
256
+ "type": "uint256"
257
+ }
258
+ ],
259
+ "name": "SubscriptionSet",
260
+ "type": "event"
261
+ },
262
+ {
263
+ "anonymous": false,
264
+ "inputs": [
265
+ {
266
+ "indexed": true,
267
+ "internalType": "address",
268
+ "name": "account",
269
+ "type": "address"
270
+ },
271
+ {
272
+ "indexed": true,
273
+ "internalType": "address",
274
+ "name": "token",
275
+ "type": "address"
276
+ },
277
+ {
278
+ "indexed": false,
279
+ "internalType": "uint256",
280
+ "name": "amount",
281
+ "type": "uint256"
282
+ }
283
+ ],
284
+ "name": "Withdraw",
285
+ "type": "event"
286
+ },
287
+ {
288
+ "inputs": [],
289
+ "name": "MAX_FEE_FACTOR",
290
+ "outputs": [
291
+ {
292
+ "internalType": "uint256",
293
+ "name": "",
294
+ "type": "uint256"
295
+ }
296
+ ],
297
+ "stateMutability": "view",
298
+ "type": "function"
299
+ },
300
+ {
301
+ "inputs": [],
302
+ "name": "MIN_MECH_BALANCE",
303
+ "outputs": [
304
+ {
305
+ "internalType": "uint256",
306
+ "name": "",
307
+ "type": "uint256"
308
+ }
309
+ ],
310
+ "stateMutability": "view",
311
+ "type": "function"
312
+ },
313
+ {
314
+ "inputs": [
315
+ {
316
+ "internalType": "address",
317
+ "name": "mech",
318
+ "type": "address"
319
+ },
320
+ {
321
+ "internalType": "address",
322
+ "name": "requester",
323
+ "type": "address"
324
+ },
325
+ {
326
+ "internalType": "uint256[]",
327
+ "name": "mechDeliveryRates",
328
+ "type": "uint256[]"
329
+ },
330
+ {
331
+ "internalType": "bytes",
332
+ "name": "paymentData",
333
+ "type": "bytes"
334
+ }
335
+ ],
336
+ "name": "adjustMechRequesterBalances",
337
+ "outputs": [],
338
+ "stateMutability": "nonpayable",
339
+ "type": "function"
340
+ },
341
+ {
342
+ "inputs": [
343
+ {
344
+ "internalType": "address",
345
+ "name": "requester",
346
+ "type": "address"
347
+ },
348
+ {
349
+ "internalType": "uint256",
350
+ "name": "numRequests",
351
+ "type": "uint256"
352
+ },
353
+ {
354
+ "internalType": "uint256",
355
+ "name": "deliveryRate",
356
+ "type": "uint256"
357
+ },
358
+ {
359
+ "internalType": "bytes",
360
+ "name": "paymentData",
361
+ "type": "bytes"
362
+ }
363
+ ],
364
+ "name": "checkAndRecordDeliveryRates",
365
+ "outputs": [],
366
+ "stateMutability": "payable",
367
+ "type": "function"
368
+ },
369
+ {
370
+ "inputs": [],
371
+ "name": "collectedFees",
372
+ "outputs": [
373
+ {
374
+ "internalType": "uint256",
375
+ "name": "",
376
+ "type": "uint256"
377
+ }
378
+ ],
379
+ "stateMutability": "view",
380
+ "type": "function"
381
+ },
382
+ {
383
+ "inputs": [
384
+ {
385
+ "internalType": "uint256",
386
+ "name": "amount",
387
+ "type": "uint256"
388
+ }
389
+ ],
390
+ "name": "deposit",
391
+ "outputs": [],
392
+ "stateMutability": "pure",
393
+ "type": "function"
394
+ },
395
+ {
396
+ "inputs": [
397
+ {
398
+ "internalType": "address",
399
+ "name": "",
400
+ "type": "address"
401
+ },
402
+ {
403
+ "internalType": "uint256",
404
+ "name": "amount",
405
+ "type": "uint256"
406
+ }
407
+ ],
408
+ "name": "depositFor",
409
+ "outputs": [],
410
+ "stateMutability": "pure",
411
+ "type": "function"
412
+ },
413
+ {
414
+ "inputs": [],
415
+ "name": "drain",
416
+ "outputs": [],
417
+ "stateMutability": "nonpayable",
418
+ "type": "function"
419
+ },
420
+ {
421
+ "inputs": [],
422
+ "name": "drainer",
423
+ "outputs": [
424
+ {
425
+ "internalType": "address",
426
+ "name": "",
427
+ "type": "address"
428
+ }
429
+ ],
430
+ "stateMutability": "view",
431
+ "type": "function"
432
+ },
433
+ {
434
+ "inputs": [
435
+ {
436
+ "internalType": "address",
437
+ "name": "mech",
438
+ "type": "address"
439
+ },
440
+ {
441
+ "internalType": "address[]",
442
+ "name": "requesters",
443
+ "type": "address[]"
444
+ },
445
+ {
446
+ "internalType": "bool[]",
447
+ "name": "deliveredRequests",
448
+ "type": "bool[]"
449
+ },
450
+ {
451
+ "internalType": "uint256[]",
452
+ "name": "mechDeliveryRates",
453
+ "type": "uint256[]"
454
+ },
455
+ {
456
+ "internalType": "uint256[]",
457
+ "name": "requesterDeliveryRates",
458
+ "type": "uint256[]"
459
+ }
460
+ ],
461
+ "name": "finalizeDeliveryRates",
462
+ "outputs": [],
463
+ "stateMutability": "nonpayable",
464
+ "type": "function"
465
+ },
466
+ {
467
+ "inputs": [
468
+ {
469
+ "internalType": "address",
470
+ "name": "",
471
+ "type": "address"
472
+ }
473
+ ],
474
+ "name": "mapMechBalances",
475
+ "outputs": [
476
+ {
477
+ "internalType": "uint256",
478
+ "name": "",
479
+ "type": "uint256"
480
+ }
481
+ ],
482
+ "stateMutability": "view",
483
+ "type": "function"
484
+ },
485
+ {
486
+ "inputs": [
487
+ {
488
+ "internalType": "address",
489
+ "name": "",
490
+ "type": "address"
491
+ }
492
+ ],
493
+ "name": "mapRequesterBalances",
494
+ "outputs": [
495
+ {
496
+ "internalType": "uint256",
497
+ "name": "",
498
+ "type": "uint256"
499
+ }
500
+ ],
501
+ "stateMutability": "view",
502
+ "type": "function"
503
+ },
504
+ {
505
+ "inputs": [],
506
+ "name": "mechMarketplace",
507
+ "outputs": [
508
+ {
509
+ "internalType": "address",
510
+ "name": "",
511
+ "type": "address"
512
+ }
513
+ ],
514
+ "stateMutability": "view",
515
+ "type": "function"
516
+ },
517
+ {
518
+ "inputs": [],
519
+ "name": "owner",
520
+ "outputs": [
521
+ {
522
+ "internalType": "address",
523
+ "name": "",
524
+ "type": "address"
525
+ }
526
+ ],
527
+ "stateMutability": "view",
528
+ "type": "function"
529
+ },
530
+ {
531
+ "inputs": [],
532
+ "name": "processPayment",
533
+ "outputs": [
534
+ {
535
+ "internalType": "uint256",
536
+ "name": "mechPayment",
537
+ "type": "uint256"
538
+ },
539
+ {
540
+ "internalType": "uint256",
541
+ "name": "marketplaceFee",
542
+ "type": "uint256"
543
+ }
544
+ ],
545
+ "stateMutability": "nonpayable",
546
+ "type": "function"
547
+ },
548
+ {
549
+ "inputs": [
550
+ {
551
+ "internalType": "address",
552
+ "name": "mech",
553
+ "type": "address"
554
+ }
555
+ ],
556
+ "name": "processPaymentByMultisig",
557
+ "outputs": [
558
+ {
559
+ "internalType": "uint256",
560
+ "name": "mechPayment",
561
+ "type": "uint256"
562
+ },
563
+ {
564
+ "internalType": "uint256",
565
+ "name": "marketplaceFee",
566
+ "type": "uint256"
567
+ }
568
+ ],
569
+ "stateMutability": "nonpayable",
570
+ "type": "function"
571
+ },
572
+ {
573
+ "inputs": [
574
+ {
575
+ "internalType": "address",
576
+ "name": "_subscriptionNFT",
577
+ "type": "address"
578
+ },
579
+ {
580
+ "internalType": "uint256",
581
+ "name": "_subscriptionTokenId",
582
+ "type": "uint256"
583
+ },
584
+ {
585
+ "internalType": "uint256",
586
+ "name": "_tokenCreditRatio",
587
+ "type": "uint256"
588
+ }
589
+ ],
590
+ "name": "setSubscription",
591
+ "outputs": [],
592
+ "stateMutability": "nonpayable",
593
+ "type": "function"
594
+ },
595
+ {
596
+ "inputs": [],
597
+ "name": "subscriptionNFT",
598
+ "outputs": [
599
+ {
600
+ "internalType": "address",
601
+ "name": "",
602
+ "type": "address"
603
+ }
604
+ ],
605
+ "stateMutability": "view",
606
+ "type": "function"
607
+ },
608
+ {
609
+ "inputs": [],
610
+ "name": "subscriptionTokenId",
611
+ "outputs": [
612
+ {
613
+ "internalType": "uint256",
614
+ "name": "",
615
+ "type": "uint256"
616
+ }
617
+ ],
618
+ "stateMutability": "view",
619
+ "type": "function"
620
+ },
621
+ {
622
+ "inputs": [],
623
+ "name": "token",
624
+ "outputs": [
625
+ {
626
+ "internalType": "address",
627
+ "name": "",
628
+ "type": "address"
629
+ }
630
+ ],
631
+ "stateMutability": "view",
632
+ "type": "function"
633
+ },
634
+ {
635
+ "inputs": [],
636
+ "name": "tokenCreditRatio",
637
+ "outputs": [
638
+ {
639
+ "internalType": "uint256",
640
+ "name": "",
641
+ "type": "uint256"
642
+ }
643
+ ],
644
+ "stateMutability": "view",
645
+ "type": "function"
646
+ },
647
+ {
648
+ "inputs": [],
649
+ "name": "trackerBalance",
650
+ "outputs": [
651
+ {
652
+ "internalType": "uint256",
653
+ "name": "",
654
+ "type": "uint256"
655
+ }
656
+ ],
657
+ "stateMutability": "view",
658
+ "type": "function"
659
+ }
660
+ ]
@@ -59,7 +59,7 @@
59
59
  "base": {
60
60
  "agent_registry_contract": "0x88DE734655184a09B70700aE4F72364d1ad23728",
61
61
  "service_registry_contract": "0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE",
62
- "mech_marketplace_contract": "0x0000000000000000000000000000000000000000",
62
+ "mech_marketplace_contract": "0xf24eE42edA0fc9b33B7D41B06Ee8ccD2Ef7C5020",
63
63
  "rpc_url": "https://base.llamarpc.com",
64
64
  "wss_endpoint": "wss://base.gateway.tenderly.co",
65
65
  "ledger_config": {
@@ -69,7 +69,7 @@
69
69
  "default_gas_price_strategy": "eip1559",
70
70
  "is_gas_estimation_enabled": false
71
71
  },
72
- "gas_limit": 250000,
72
+ "gas_limit": 500000,
73
73
  "price": 3000000000000,
74
74
  "contract_abi_url": "https://api.basescan.org/api?module=contract&action=getabi&address={contract_address}&apikey={api_key}",
75
75
  "transaction_url": "https://basescan.org/tx/{transaction_digest}",
@@ -26,8 +26,9 @@ import sys
26
26
  import time
27
27
  from dataclasses import asdict, make_dataclass
28
28
  from datetime import datetime
29
+ from enum import Enum
29
30
  from pathlib import Path
30
- from typing import Any, Dict, List, Optional, Tuple, cast
31
+ from typing import Any, Dict, Optional, Tuple, cast
31
32
 
32
33
  import requests
33
34
  import websocket
@@ -45,8 +46,8 @@ from mech_client.interact import (
45
46
  PRIVATE_KEY_FILE_PATH,
46
47
  TIMEOUT,
47
48
  WAIT_SLEEP,
48
- calculate_topic_id,
49
49
  get_contract,
50
+ get_event_signatures,
50
51
  get_mech_config,
51
52
  )
52
53
  from mech_client.prompt_to_ipfs import push_metadata_to_ipfs
@@ -59,16 +60,42 @@ from mech_client.wss import (
59
60
 
60
61
 
61
62
  # false positives for [B105:hardcoded_password_string] Possible hardcoded password
62
- PAYMENT_TYPE_NATIVE = (
63
- "ba699a34be8fe0e7725e93dcbce1701b0211a8ca61330aaeb8a05bf2ec7abed1" # nosec
64
- )
65
- PAYMENT_TYPE_TOKEN = (
66
- "3679d66ef546e66ce9057c4a052f317b135bc8e8c509638f7966edfd4fcf45e9" # nosec
63
+ class PaymentType(Enum):
64
+ """Payment type."""
65
+
66
+ NATIVE = "ba699a34be8fe0e7725e93dcbce1701b0211a8ca61330aaeb8a05bf2ec7abed1" # nosec
67
+ TOKEN = "3679d66ef546e66ce9057c4a052f317b135bc8e8c509638f7966edfd4fcf45e9" # nosec
68
+ NATIVE_NVM = (
69
+ "803dd08fe79d91027fc9024e254a0942372b92f3ccabc1bd19f4a5c2b251c316" # nosec
70
+ )
71
+ TOKEN_NVM = (
72
+ "0d6fd99afa9c4c580fab5e341922c2a5c4b61d880da60506193d7bf88944dd14" # nosec
73
+ )
74
+
75
+
76
+ ABI_DIR_PATH = Path(__file__).parent / "abis"
77
+ IMECH_ABI_PATH = ABI_DIR_PATH / "IMech.json"
78
+ ITOKEN_ABI_PATH = ABI_DIR_PATH / "IToken.json"
79
+ IERC1155_ABI_PATH = ABI_DIR_PATH / "IERC1155.json"
80
+ MARKETPLACE_ABI_PATH = ABI_DIR_PATH / "MechMarketplace.json"
81
+
82
+ BALANCE_TRACKER_NATIVE_ABI_PATH = ABI_DIR_PATH / "BalanceTrackerFixedPriceNative.json"
83
+ BALANCE_TRACKER_TOKEN_ABI_PATH = ABI_DIR_PATH / "BalanceTrackerFixedPriceToken.json"
84
+ BALANCE_TRACKER_NVM_NATIVE_ABI_PATH = (
85
+ ABI_DIR_PATH / "BalanceTrackerNvmSubscriptionNative.json"
67
86
  )
68
- PAYMENT_TYPE_NVM = (
69
- "803dd08fe79d91027fc9024e254a0942372b92f3ccabc1bd19f4a5c2b251c316" # nosec
87
+ BALANCE_TRACKER_NVM_TOKEN_ABI_PATH = (
88
+ ABI_DIR_PATH / "BalanceTrackerNvmSubscriptionToken.json"
70
89
  )
71
90
 
91
+
92
+ PAYMENT_TYPE_TO_ABI_PATH: Dict[str, Path] = {
93
+ PaymentType.NATIVE.value: BALANCE_TRACKER_NATIVE_ABI_PATH,
94
+ PaymentType.TOKEN.value: BALANCE_TRACKER_TOKEN_ABI_PATH,
95
+ PaymentType.NATIVE_NVM.value: BALANCE_TRACKER_NVM_NATIVE_ABI_PATH,
96
+ PaymentType.TOKEN_NVM.value: BALANCE_TRACKER_NVM_TOKEN_ABI_PATH,
97
+ }
98
+
72
99
  CHAIN_TO_WRAPPED_TOKEN = {
73
100
  1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
74
101
  10: "0x4200000000000000000000000000000000000006",
@@ -85,23 +112,16 @@ CHAIN_TO_DEFAULT_MECH_MARKETPLACE_REQUEST_CONFIG = {
85
112
  "priority_mech_address": "0x478ad20eD958dCC5AD4ABa6F4E4cc51e07a840E4",
86
113
  "response_timeout": 300,
87
114
  "payment_data": "0x",
88
- }
115
+ },
116
+ 8453: {
117
+ "mech_marketplace_contract": "0xf24eE42edA0fc9b33B7D41B06Ee8ccD2Ef7C5020",
118
+ "priority_mech_address": "0xE183610A420dBD8825fed49C589Fe2d5BFd5b17a",
119
+ "response_timeout": 300,
120
+ "payment_data": "0x",
121
+ },
89
122
  }
90
123
 
91
124
 
92
- def get_event_signatures(abi: List) -> Tuple[str, str]:
93
- """Calculate `Marketplace Request` and `Marketplace Deliver` event topics"""
94
- marketplace_request, marketplace_deliver = "", ""
95
- for obj in abi:
96
- if obj["type"] != "event":
97
- continue
98
- if obj["name"] == "MarketplaceDeliver":
99
- marketplace_deliver = calculate_topic_id(event=obj)
100
- if obj["name"] == "MarketplaceRequest":
101
- marketplace_request = calculate_topic_id(event=obj)
102
- return marketplace_request, marketplace_deliver
103
-
104
-
105
125
  def fetch_mech_info(
106
126
  ledger_api: EthereumApi,
107
127
  mech_marketplace_contract: Web3Contract,
@@ -120,7 +140,7 @@ def fetch_mech_info(
120
140
  :rtype: Tuple[str, int, int, str, Contract]
121
141
  """
122
142
 
123
- with open(Path(__file__).parent / "abis" / "IMech.json", encoding="utf-8") as f:
143
+ with open(IMECH_ABI_PATH, encoding="utf-8") as f:
124
144
  abi = json.load(f)
125
145
 
126
146
  mech_contract = get_contract(
@@ -137,7 +157,7 @@ def fetch_mech_info(
137
157
  ).call()
138
158
  )
139
159
 
140
- if payment_type not in [PAYMENT_TYPE_NATIVE, PAYMENT_TYPE_TOKEN, PAYMENT_TYPE_NVM]:
160
+ if payment_type not in PaymentType._value2member_map_: # pylint: disable=W0212
141
161
  print(" - Invalid mech type detected.")
142
162
  sys.exit(1)
143
163
 
@@ -175,7 +195,7 @@ def approve_price_tokens(
175
195
  """
176
196
  sender = crypto.address
177
197
 
178
- with open(Path(__file__).parent / "abis" / "IToken.json", encoding="utf-8") as f:
198
+ with open(ITOKEN_ABI_PATH, encoding="utf-8") as f:
179
199
  abi = json.load(f)
180
200
 
181
201
  token_contract = get_contract(
@@ -210,6 +230,7 @@ def fetch_requester_nvm_subscription_balance(
210
230
  requester: str,
211
231
  ledger_api: EthereumApi,
212
232
  mech_payment_balance_tracker: str,
233
+ payment_type: str,
213
234
  ) -> int:
214
235
  """
215
236
  Fetches the requester nvm subscription balance.
@@ -220,11 +241,13 @@ def fetch_requester_nvm_subscription_balance(
220
241
  :type ledger_api: EthereumApi
221
242
  :param mech_payment_balance_tracker: Requested mech's balance tracker contract address
222
243
  :type mech_payment_balance_tracker: str
244
+ :param payment_type: Requested mech's payment type
245
+ :type payment_type: str
223
246
  :return: The requester balance.
224
247
  :rtype: int
225
248
  """
226
249
  with open(
227
- Path(__file__).parent / "abis" / "BalanceTrackerNvmSubscriptionNative.json",
250
+ PAYMENT_TYPE_TO_ABI_PATH[payment_type],
228
251
  encoding="utf-8",
229
252
  ) as f:
230
253
  abi = json.load(f)
@@ -239,10 +262,7 @@ def fetch_requester_nvm_subscription_balance(
239
262
  nvm_balance_tracker_contract.functions.subscriptionTokenId().call()
240
263
  )
241
264
 
242
- with open(
243
- Path(__file__).parent / "abis" / "IERC1155.json",
244
- encoding="utf-8",
245
- ) as f:
265
+ with open(IERC1155_ABI_PATH, encoding="utf-8") as f:
246
266
  abi = json.load(f)
247
267
 
248
268
  subscription_nft_contract = get_contract(
@@ -568,34 +588,12 @@ def check_prepaid_balances(
568
588
  :type max_delivery_rate: int
569
589
  """
570
590
  requester = crypto.address
571
- if payment_type == PAYMENT_TYPE_NATIVE:
572
- with open(
573
- Path(__file__).parent / "abis" / "BalanceTrackerFixedPriceNative.json",
574
- encoding="utf-8",
575
- ) as f:
576
- abi = json.load(f)
577
591
 
578
- balance_tracker_contract = get_contract(
579
- contract_address=mech_payment_balance_tracker,
580
- abi=abi,
581
- ledger_api=ledger_api,
582
- )
583
- requester_balance = balance_tracker_contract.functions.mapRequesterBalances(
584
- requester
585
- ).call()
586
- if requester_balance < max_delivery_rate:
587
- print(
588
- f" - Sender Native deposited balance low. Needed: {max_delivery_rate}, Actual: {requester_balance}"
589
- )
590
- print(f" - Sender Address: {requester}")
591
- print(" - Please use scripts/deposit_native.py to add balance")
592
- sys.exit(1)
592
+ if payment_type in [PaymentType.NATIVE.value, PaymentType.TOKEN.value]:
593
+ payment_type_name = PaymentType(payment_type).name.lower()
594
+ payment_type_abi_path = PAYMENT_TYPE_TO_ABI_PATH[payment_type]
593
595
 
594
- if payment_type == PAYMENT_TYPE_TOKEN:
595
- with open(
596
- Path(__file__).parent / "abis" / "BalanceTrackerFixedPriceToken.json",
597
- encoding="utf-8",
598
- ) as f:
596
+ with open(payment_type_abi_path, encoding="utf-8") as f:
599
597
  abi = json.load(f)
600
598
 
601
599
  balance_tracker_contract = get_contract(
@@ -608,10 +606,12 @@ def check_prepaid_balances(
608
606
  ).call()
609
607
  if requester_balance < max_delivery_rate:
610
608
  print(
611
- f" - Sender Token deposited balance low. Needed: {max_delivery_rate}, Actual: {requester_balance}"
609
+ f" - Sender {payment_type_name} deposited balance low. Needed: {max_delivery_rate}, Actual: {requester_balance}"
612
610
  )
613
611
  print(f" - Sender Address: {requester}")
614
- print(" - Please use scripts/deposit_token.py to add balance")
612
+ print(
613
+ f" - Please use scripts/deposit_{payment_type_name}.py to add balance"
614
+ )
615
615
  sys.exit(1)
616
616
 
617
617
 
@@ -699,9 +699,7 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
699
699
  crypto = EthereumCrypto(private_key_path=private_key_path)
700
700
  ledger_api = EthereumApi(**asdict(ledger_config))
701
701
 
702
- with open(
703
- Path(__file__).parent / "abis" / "MechMarketplace.json", encoding="utf-8"
704
- ) as f:
702
+ with open(MARKETPLACE_ABI_PATH, encoding="utf-8") as f:
705
703
  abi = json.load(f)
706
704
 
707
705
  mech_marketplace_contract = get_contract(
@@ -726,14 +724,16 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
726
724
  mech_marketplace_request_config.delivery_rate = max_delivery_rate
727
725
  mech_marketplace_request_config.payment_type = payment_type
728
726
 
727
+ with open(IMECH_ABI_PATH, encoding="utf-8") as f:
728
+ abi = json.load(f)
729
+
729
730
  (
730
731
  marketplace_request_event_signature,
731
732
  marketplace_deliver_event_signature,
732
733
  ) = get_event_signatures(abi=abi)
733
-
734
734
  register_event_handlers(
735
735
  wss=wss,
736
- contract_address=contract_address,
736
+ contract_address=priority_mech_address,
737
737
  crypto=crypto,
738
738
  request_signature=marketplace_request_event_signature,
739
739
  deliver_signature=marketplace_deliver_event_signature,
@@ -741,7 +741,7 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
741
741
 
742
742
  if not use_prepaid:
743
743
  price = max_delivery_rate
744
- if payment_type == PAYMENT_TYPE_TOKEN:
744
+ if payment_type == PaymentType.TOKEN.value:
745
745
  print("Token Mech detected, approving wrapped token for price payment...")
746
746
  wxdai = CHAIN_TO_WRAPPED_TOKEN[chain_id]
747
747
  approve_tx = approve_price_tokens(
@@ -772,11 +772,14 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
772
772
  max_delivery_rate,
773
773
  )
774
774
 
775
- if payment_type == PAYMENT_TYPE_NVM:
776
- print("Nevermined Mech detected, subscription credits to be used")
775
+ if payment_type in [PaymentType.NATIVE_NVM.value, PaymentType.TOKEN_NVM.value]:
776
+ nvm_mech_type = PaymentType(payment_type).name.lower()
777
+ print(
778
+ f"{nvm_mech_type} Nevermined Mech detected, subscription credits to be used"
779
+ )
777
780
  requester = crypto.address
778
781
  requester_balance = fetch_requester_nvm_subscription_balance(
779
- requester, ledger_api, mech_payment_balance_tracker
782
+ requester, ledger_api, mech_payment_balance_tracker, payment_type
780
783
  )
781
784
  if requester_balance < price:
782
785
  print(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mech-client
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Basic client to interact with a mech
5
5
  License: Apache-2.0
6
6
  Author: David Minarsch
@@ -1,14 +1,15 @@
1
- mech_client/__init__.py,sha256=Fv_rB4SSlUfKkC4yVa0VynPADc604qwxEG5c-jAgNic,42
1
+ mech_client/__init__.py,sha256=ExTYjuMb_wq7aijLqhyCVLuGh4EGP2CZmtb4c3vobpg,42
2
2
  mech_client/abis/BalanceTrackerFixedPriceNative.json,sha256=MF5jDqSMoZztvMV4oc5ij-Qn1DAZ1Nyz9EOFRb9wSQ0,12478
3
3
  mech_client/abis/BalanceTrackerFixedPriceToken.json,sha256=kaXgResUkAb6u9bVTS3T_SNRPRP76hi-jTAhMiYwq4U,12408
4
4
  mech_client/abis/BalanceTrackerNvmSubscriptionNative.json,sha256=D23ibyhDsn4vjozFvzcKw-7wJpGM-R5GiqlcmyBIpcY,16536
5
+ mech_client/abis/BalanceTrackerNvmSubscriptionToken.json,sha256=4Bra0DdEi_pQUSD4hGdELOvjNL013GaJc-dANr--5D8,16204
5
6
  mech_client/abis/IERC1155.json,sha256=2xOx44MrKRk5oDEZ8PhCUgW7A4puK-GQizPKff-Fn1E,7459
6
7
  mech_client/abis/IMech.json,sha256=km0NMRyqBYh3jBQwPJCispsRfPwqNJ67kkZwYjuJci4,3989
7
8
  mech_client/abis/IToken.json,sha256=VrzR6Rr1DmrUzy5DygN1rKm6df4ir2KGdWsunZnuRKo,19637
8
9
  mech_client/abis/MechMarketplace.json,sha256=auKTxPTi07yD98Gz2RuwH1Gq5qRCyy8-C7QBNj3uto8,32104
9
10
  mech_client/acn.py,sha256=Rj_jLPvJ5loDQfGbu3a_O24cJC4SwIErLceSz_zVYS8,5356
10
11
  mech_client/cli.py,sha256=PWkUBwirP8DMxNG-lYmh-QAJhNPX_k6yCtfjTh7iXs8,11322
11
- mech_client/configs/mechs.json,sha256=ihF23WakBh1Jbnb45OJvPjDzZ572eud3s0Gx4qNGWwQ,5699
12
+ mech_client/configs/mechs.json,sha256=Xa91cNO4Ak2TInewUlvup6M440eyFCaYiXv8SHpY3yE,5699
12
13
  mech_client/fetch_ipfs_hash.py,sha256=tg_hYVf4deXl89x3SOBrGFUthaSeN_Vg_OHDtfjdbp4,2752
13
14
  mech_client/helpers/__init__.py,sha256=nmQig1EqBQ9EMOpgdykP3a6_2NWcoVH3-lnyHP5n0ws,1196
14
15
  mech_client/helpers/acn/README.md,sha256=WMXR2Lk0IpWjr3vpZ8cxcTHk4gwsx4wC06UPkwj9dbQ,1641
@@ -39,15 +40,15 @@ mech_client/helpers/p2p_libp2p_client/__init__.py,sha256=-GOP3D_JnmXTDomrMLCbnRk
39
40
  mech_client/helpers/p2p_libp2p_client/connection.py,sha256=b5jfcUeSoNrUw8DOSTCbK4DTi-N8bf2_pdogUOz0ep0,28606
40
41
  mech_client/helpers/p2p_libp2p_client/connection.yaml,sha256=nMiHnU_dv9EFjVNqZ-0SAnoATfadJSad-JsbDvk97Mk,1790
41
42
  mech_client/interact.py,sha256=zQ7UhlnZOfM4hnZBaRQ5efkfw6Rl-s7Kh6lciyoZL70,22028
42
- mech_client/marketplace_interact.py,sha256=DgDU1xY2zJO3MfxkWNFtJ8iZkjGBfP8MYL4vAEDRKWE,31418
43
+ mech_client/marketplace_interact.py,sha256=aMymGceGXbXYYbB5alICq5Vp-9szD3IPlfWaCoBEZlU,31631
43
44
  mech_client/mech_tool_management.py,sha256=XWQDcFStTK66-3ZzOwKtMo5c66KDjvbeDsIXHIP4SuU,7810
44
45
  mech_client/prompt_to_ipfs.py,sha256=XqSIBko15MEkpWOQNT97fRI6jNxMF5EDBDEPOJFdhyk,2533
45
46
  mech_client/push_to_ipfs.py,sha256=IfvgaPU79N_ZmCPF9d7sPCYz2uduZH0KjT_HQ2LHXoQ,2059
46
47
  mech_client/subgraph.py,sha256=6hkF8l0qxWRJ0UcdxfML6JnjYBu5BuBA6EHsHJ2nHVI,5149
47
48
  mech_client/to_png.py,sha256=pjUcFJ63MJj_r73eqnfqCWMtlpsrj6H4ZmgvIEmRcFw,2581
48
49
  mech_client/wss.py,sha256=toD_9-gNsQAoK13Zh5mQCKbmkT2Gcqz5XaNiUGyb5Js,9801
49
- mech_client-0.3.0.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
50
- mech_client-0.3.0.dist-info/METADATA,sha256=2YFbNhpBXix_HZBGf-CSW7wspGdH53EQjqWjUK6PBLc,19911
51
- mech_client-0.3.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
52
- mech_client-0.3.0.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
53
- mech_client-0.3.0.dist-info/RECORD,,
50
+ mech_client-0.4.0.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
51
+ mech_client-0.4.0.dist-info/METADATA,sha256=kZzxaub9P9awiENKOJKbxtGfACwnPiyUU2L91RhpZgg,19911
52
+ mech_client-0.4.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
53
+ mech_client-0.4.0.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
54
+ mech_client-0.4.0.dist-info/RECORD,,