mech-client 0.4.0__py3-none-any.whl → 0.7.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.
Files changed (34) hide show
  1. mech_client/__init__.py +1 -1
  2. mech_client/abis/AgentMech.json +718 -0
  3. mech_client/abis/AgentRegistry.json +1037 -0
  4. mech_client/abis/AgreementStoreManager.base.json +766 -0
  5. mech_client/abis/AgreementStoreManager.gnosis.json +766 -0
  6. mech_client/abis/DIDRegistry.base.json +2476 -0
  7. mech_client/abis/DIDRegistry.gnosis.json +2476 -0
  8. mech_client/abis/EscrowPaymentCondition.base.json +717 -0
  9. mech_client/abis/EscrowPaymentCondition.gnosis.json +717 -0
  10. mech_client/abis/LockPaymentCondition.base.json +874 -0
  11. mech_client/abis/LockPaymentCondition.gnosis.json +874 -0
  12. mech_client/abis/NFTSalesTemplate.base.json +698 -0
  13. mech_client/abis/NFTSalesTemplate.gnosis.json +698 -0
  14. mech_client/abis/NeverminedConfig.base.json +587 -0
  15. mech_client/abis/NeverminedConfig.gnosis.json +587 -0
  16. mech_client/abis/SubscriptionNFT.base.json +300 -0
  17. mech_client/abis/SubscriptionNFT.gnosis.json +300 -0
  18. mech_client/abis/SubscriptionProvider.base.json +294 -0
  19. mech_client/abis/SubscriptionProvider.gnosis.json +294 -0
  20. mech_client/abis/SubscriptionToken.base.json +1393 -0
  21. mech_client/abis/TransferNFTCondition.base.json +1062 -0
  22. mech_client/abis/TransferNFTCondition.gnosis.json +1062 -0
  23. mech_client/cli.py +99 -10
  24. mech_client/configs/mechs.json +1 -7
  25. mech_client/interact.py +14 -39
  26. mech_client/marketplace_interact.py +130 -90
  27. mech_client/mech_tool_management.py +11 -5
  28. mech_client/subgraph.py +21 -35
  29. mech_client/wss.py +7 -6
  30. {mech_client-0.4.0.dist-info → mech_client-0.7.0.dist-info}/METADATA +53 -19
  31. {mech_client-0.4.0.dist-info → mech_client-0.7.0.dist-info}/RECORD +34 -13
  32. {mech_client-0.4.0.dist-info → mech_client-0.7.0.dist-info}/LICENSE +0 -0
  33. {mech_client-0.4.0.dist-info → mech_client-0.7.0.dist-info}/WHEEL +0 -0
  34. {mech_client-0.4.0.dist-info → mech_client-0.7.0.dist-info}/entry_points.txt +0 -0
@@ -55,7 +55,7 @@ from mech_client.wss import (
55
55
  register_event_handlers,
56
56
  wait_for_receipt,
57
57
  watch_for_marketplace_data_url_from_wss,
58
- watch_for_marketplace_request_id,
58
+ watch_for_marketplace_request_ids,
59
59
  )
60
60
 
61
61
 
@@ -73,6 +73,7 @@ class PaymentType(Enum):
73
73
  )
74
74
 
75
75
 
76
+ IPFS_URL_TEMPLATE = "https://gateway.autonolas.tech/ipfs/f01701220{}"
76
77
  ABI_DIR_PATH = Path(__file__).parent / "abis"
77
78
  IMECH_ABI_PATH = ABI_DIR_PATH / "IMech.json"
78
79
  ITOKEN_ABI_PATH = ABI_DIR_PATH / "IToken.json"
@@ -96,26 +97,22 @@ PAYMENT_TYPE_TO_ABI_PATH: Dict[str, Path] = {
96
97
  PaymentType.TOKEN_NVM.value: BALANCE_TRACKER_NVM_TOKEN_ABI_PATH,
97
98
  }
98
99
 
99
- CHAIN_TO_WRAPPED_TOKEN = {
100
- 1: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
101
- 10: "0x4200000000000000000000000000000000000006",
102
- 100: "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d",
103
- 137: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
104
- 8453: "0x4200000000000000000000000000000000000006",
105
- 42220: "0x471EcE3750Da237f93B8E339c536989b8978a438",
100
+ CHAIN_TO_PRICE_TOKEN = {
101
+ 1: "0x0001A500A6B18995B03f44bb040A5fFc28E45CB0",
102
+ 10: "0xFC2E6e6BCbd49ccf3A5f029c79984372DcBFE527",
103
+ 100: "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f",
104
+ 137: "0xFEF5d947472e72Efbb2E388c730B7428406F2F95",
105
+ 8453: "0x54330d28ca3357F294334BDC454a032e7f353416",
106
+ 42220: "0xFEF5d947472e72Efbb2E388c730B7428406F2F95",
106
107
  }
107
108
 
108
109
 
109
110
  CHAIN_TO_DEFAULT_MECH_MARKETPLACE_REQUEST_CONFIG = {
110
111
  100: {
111
- "mech_marketplace_contract": "0x735FAAb1c4Ec41128c367AFb5c3baC73509f70bB",
112
- "priority_mech_address": "0x478ad20eD958dCC5AD4ABa6F4E4cc51e07a840E4",
113
112
  "response_timeout": 300,
114
113
  "payment_data": "0x",
115
114
  },
116
115
  8453: {
117
- "mech_marketplace_contract": "0xf24eE42edA0fc9b33B7D41B06Ee8ccD2Ef7C5020",
118
- "priority_mech_address": "0xE183610A420dBD8825fed49C589Fe2d5BFd5b17a",
119
116
  "response_timeout": 300,
120
117
  "payment_data": "0x",
121
118
  },
@@ -280,8 +277,8 @@ def send_marketplace_request( # pylint: disable=too-many-arguments,too-many-loc
280
277
  ledger_api: EthereumApi,
281
278
  marketplace_contract: Web3Contract,
282
279
  gas_limit: int,
283
- prompt: str,
284
- tool: str,
280
+ prompts: tuple,
281
+ tools: tuple,
285
282
  method_args_data: MechMarketplaceRequestConfig,
286
283
  extra_attributes: Optional[Dict[str, Any]] = None,
287
284
  price: int = 10_000_000_000_000_000,
@@ -300,10 +297,10 @@ def send_marketplace_request( # pylint: disable=too-many-arguments,too-many-loc
300
297
  :type marketplace_contract: Web3Contract
301
298
  :param gas_limit: Gas limit.
302
299
  :type gas_limit: int
303
- :param prompt: The request prompt.
304
- :type prompt: str
305
- :param tool: The requested tool.
306
- :type tool: str
300
+ :param prompts: The request prompts.
301
+ :type prompts: tuple
302
+ :param tools: The requested tools.
303
+ :type tools: tuple
307
304
  :param method_args_data: Method data to use to call the marketplace contract request
308
305
  :type method_args_data: MechMarketplaceRequestConfig
309
306
  :param extra_attributes: Extra attributes to be included in the request metadata.
@@ -319,21 +316,40 @@ def send_marketplace_request( # pylint: disable=too-many-arguments,too-many-loc
319
316
  :return: The transaction hash.
320
317
  :rtype: Optional[str]
321
318
  """
322
- v1_file_hash_hex_truncated, v1_file_hash_hex = push_metadata_to_ipfs(
323
- prompt, tool, extra_attributes
324
- )
325
- print(
326
- f" - Prompt uploaded: https://gateway.autonolas.tech/ipfs/{v1_file_hash_hex}"
327
- )
328
- method_name = "request"
319
+ num_requests = len(prompts)
320
+
329
321
  method_args = {
330
- "requestData": v1_file_hash_hex_truncated,
331
322
  "maxDeliveryRate": method_args_data.delivery_rate,
332
323
  "paymentType": "0x" + cast(str, method_args_data.payment_type),
333
324
  "priorityMech": to_checksum_address(method_args_data.priority_mech_address),
334
325
  "responseTimeout": method_args_data.response_timeout,
335
326
  "paymentData": method_args_data.payment_data,
336
327
  }
328
+
329
+ if num_requests == 1:
330
+ v1_file_hash_hex_truncated, v1_file_hash_hex = push_metadata_to_ipfs(
331
+ prompts[0], tools[0], extra_attributes
332
+ )
333
+ print(
334
+ f" - Prompt uploaded: https://gateway.autonolas.tech/ipfs/{v1_file_hash_hex}"
335
+ )
336
+ method_name = "request"
337
+ method_args["requestData"] = v1_file_hash_hex_truncated
338
+
339
+ else:
340
+ request_datas = []
341
+ for prompt, tool in zip(prompts, tools):
342
+ v1_file_hash_hex_truncated, v1_file_hash_hex = push_metadata_to_ipfs(
343
+ prompt, tool, extra_attributes
344
+ )
345
+ print(
346
+ f" - Prompt uploaded: https://gateway.autonolas.tech/ipfs/{v1_file_hash_hex}"
347
+ )
348
+ request_datas.append(v1_file_hash_hex_truncated)
349
+
350
+ method_name = "requestBatch"
351
+ method_args["requestDatas"] = request_datas
352
+
337
353
  tx_args = {
338
354
  "sender_address": crypto.address,
339
355
  "value": price,
@@ -376,6 +392,7 @@ def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too
376
392
  prompt: str,
377
393
  tool: str,
378
394
  method_args_data: MechMarketplaceRequestConfig,
395
+ nonce: int,
379
396
  extra_attributes: Optional[Dict[str, Any]] = None,
380
397
  retries: Optional[int] = None,
381
398
  timeout: Optional[float] = None,
@@ -394,6 +411,8 @@ def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too
394
411
  :type tool: str
395
412
  :param method_args_data: Method data to use to call the marketplace contract request
396
413
  :type method_args_data: MechMarketplaceRequestConfig
414
+ :param nonce: Nonce to use to order offchain tasks
415
+ :type nonce: int
397
416
  :param extra_attributes: Extra attributes to be included in the request metadata.
398
417
  :type extra_attributes: Optional[Dict[str,Any]]
399
418
  :param retries: Number of retries for sending a transaction
@@ -429,7 +448,6 @@ def send_offchain_marketplace_request( # pylint: disable=too-many-arguments,too
429
448
  while tries < retries and datetime.now().timestamp() < deadline:
430
449
  tries += 1
431
450
  try:
432
- nonce = marketplace_contract.functions.mapNonces(crypto.address).call()
433
451
  delivery_rate = method_args["maxDeliveryRate"]
434
452
  request_id = marketplace_contract.functions.getRequestId(
435
453
  method_args["priorityMech"],
@@ -616,11 +634,11 @@ def check_prepaid_balances(
616
634
 
617
635
 
618
636
  def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals, too-many-statements, too-many-return-statements
619
- prompt: str,
637
+ prompts: tuple,
620
638
  priority_mech: str,
621
639
  use_prepaid: bool = False,
622
640
  use_offchain: bool = False,
623
- tool: str = "",
641
+ tools: tuple = (),
624
642
  extra_attributes: Optional[Dict[str, Any]] = None,
625
643
  private_key_path: Optional[str] = None,
626
644
  confirmation_type: ConfirmationType = ConfirmationType.WAIT_FOR_BOTH,
@@ -632,16 +650,16 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
632
650
  """
633
651
  Interact with mech marketplace contract.
634
652
 
635
- :param prompt: The interaction prompt.
636
- :type prompt: str
653
+ :param prompts: The interaction prompts.
654
+ :type prompts: tuple
637
655
  :param priority_mech: Priority mech address to use (Optional)
638
656
  :type priority_mech: str
639
657
  :param use_prepaid: Whether to use prepaid model or not.
640
658
  :type use_prepaid: bool
641
659
  :param use_offchain: Whether to use offchain model or not.
642
660
  :type use_offchain: bool
643
- :param tool: The tool to interact with (optional).
644
- :type tool: str
661
+ :param tools: The tools to interact with (optional).
662
+ :type tools: tuple
645
663
  :param extra_attributes: Extra attributes to be included in the request metadata (optional).
646
664
  :type extra_attributes: Optional[Dict[str, Any]]
647
665
  :param private_key_path: The path to the private key file (optional).
@@ -665,21 +683,23 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
665
683
  priority_mech_address = priority_mech
666
684
  mech_marketplace_contract = mech_config.mech_marketplace_contract
667
685
  chain_id = ledger_config.chain_id
686
+ num_requests = len(prompts)
668
687
 
669
688
  if mech_marketplace_contract == ADDRESS_ZERO:
670
689
  print(f"Mech Marketplace not yet supported on {chain_config}")
671
690
  return None
672
691
 
673
692
  config_values = CHAIN_TO_DEFAULT_MECH_MARKETPLACE_REQUEST_CONFIG[chain_id].copy()
674
- if priority_mech_address is not None:
675
- print("Custom Mech detected")
676
- config_values.update(
677
- {
678
- "priority_mech_address": priority_mech_address,
679
- "mech_marketplace_contract": mech_marketplace_contract,
680
- }
681
- )
693
+ if priority_mech_address is None:
694
+ print("Priority Mech Address not provided")
695
+ return None
682
696
 
697
+ config_values.update(
698
+ {
699
+ "priority_mech_address": priority_mech_address,
700
+ "mech_marketplace_contract": mech_marketplace_contract,
701
+ }
702
+ )
683
703
  mech_marketplace_request_config: MechMarketplaceRequestConfig = make_dataclass(
684
704
  "MechMarketplaceRequestConfig",
685
705
  ((k, type(v)) for k, v in config_values.items()),
@@ -740,12 +760,12 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
740
760
  )
741
761
 
742
762
  if not use_prepaid:
743
- price = max_delivery_rate
763
+ price = max_delivery_rate * num_requests
744
764
  if payment_type == PaymentType.TOKEN.value:
745
765
  print("Token Mech detected, approving wrapped token for price payment...")
746
- wxdai = CHAIN_TO_WRAPPED_TOKEN[chain_id]
766
+ price_token = CHAIN_TO_PRICE_TOKEN[chain_id]
747
767
  approve_tx = approve_price_tokens(
748
- crypto, ledger_api, wxdai, mech_payment_balance_tracker, price
768
+ crypto, ledger_api, price_token, mech_payment_balance_tracker, price
749
769
  )
750
770
  if not approve_tx:
751
771
  print("Unable to approve allowance")
@@ -799,8 +819,8 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
799
819
  marketplace_contract=mech_marketplace_contract,
800
820
  gas_limit=mech_config.gas_limit,
801
821
  price=price,
802
- prompt=prompt,
803
- tool=tool,
822
+ prompts=prompts,
823
+ tools=tools,
804
824
  method_args_data=mech_marketplace_request_config,
805
825
  extra_attributes=extra_attributes,
806
826
  retries=retries,
@@ -818,66 +838,86 @@ def marketplace_interact( # pylint: disable=too-many-arguments, too-many-locals
818
838
  print(f" - Transaction sent: {transaction_url_formatted}")
819
839
  print(" - Waiting for transaction receipt...")
820
840
 
821
- request_id = watch_for_marketplace_request_id(
841
+ request_ids = watch_for_marketplace_request_ids(
822
842
  marketplace_contract=mech_marketplace_contract,
823
843
  ledger_api=ledger_api,
824
844
  tx_hash=transaction_digest,
825
845
  )
826
- request_id_int = int.from_bytes(bytes.fromhex(request_id), byteorder="big")
827
- print(f" - Created on-chain request with ID {request_id_int}")
846
+ request_id_ints = [
847
+ int.from_bytes(bytes.fromhex(request_id), byteorder="big")
848
+ for request_id in request_ids
849
+ ]
850
+ if len(request_id_ints) == 1:
851
+ print(f" - Created on-chain request with ID {request_id_ints[0]}")
852
+ else:
853
+ print(
854
+ f" - Created on-chain requests with IDs: {', '.join(str(rid) for rid in request_id_ints)}"
855
+ )
828
856
  print("")
829
857
 
830
- data_url = wait_for_marketplace_data_url(
831
- request_id=request_id,
832
- wss=wss,
833
- mech_contract=mech_contract,
834
- subgraph_url=mech_config.subgraph_url,
835
- deliver_signature=marketplace_deliver_event_signature,
836
- ledger_api=ledger_api,
837
- crypto=crypto,
838
- confirmation_type=confirmation_type,
839
- )
858
+ for request_id, request_id_int in zip(request_ids, request_id_ints):
859
+ data_url = wait_for_marketplace_data_url(
860
+ request_id=request_id,
861
+ wss=wss,
862
+ mech_contract=mech_contract,
863
+ subgraph_url=mech_config.subgraph_url,
864
+ deliver_signature=marketplace_deliver_event_signature,
865
+ ledger_api=ledger_api,
866
+ crypto=crypto,
867
+ confirmation_type=confirmation_type,
868
+ )
840
869
 
841
- if data_url:
842
- print(f" - Data arrived: {data_url}")
843
- data = requests.get(f"{data_url}/{request_id_int}", timeout=30).json()
844
- print(" - Data from agent:")
845
- print(json.dumps(data, indent=2))
846
- return data
870
+ if data_url:
871
+ print(f" - Data arrived: {data_url}")
872
+ data = requests.get(f"{data_url}/{request_id_int}", timeout=30).json()
873
+ print(" - Data from agent:")
874
+ print(json.dumps(data, indent=2))
847
875
  return None
848
876
 
849
877
  print("Sending Offchain Mech Marketplace request...")
850
- response = send_offchain_marketplace_request(
851
- crypto=crypto,
852
- marketplace_contract=mech_marketplace_contract,
853
- prompt=prompt,
854
- tool=tool,
855
- method_args_data=mech_marketplace_request_config,
856
- extra_attributes=extra_attributes,
857
- retries=retries,
858
- timeout=timeout,
859
- sleep=sleep,
860
- )
878
+ curr_nonce = mech_marketplace_contract.functions.mapNonces(crypto.address).call() # type: ignore
879
+ responses = []
880
+
881
+ for i in range(num_requests):
882
+ response = send_offchain_marketplace_request(
883
+ crypto=crypto,
884
+ marketplace_contract=mech_marketplace_contract,
885
+ prompt=prompts[0],
886
+ tool=tools[0],
887
+ method_args_data=mech_marketplace_request_config,
888
+ nonce=curr_nonce + i,
889
+ extra_attributes=extra_attributes,
890
+ retries=retries,
891
+ timeout=timeout,
892
+ sleep=sleep,
893
+ )
894
+ responses.append(response)
861
895
 
862
- if not response:
896
+ if not responses and len(responses) != num_requests:
863
897
  return None
864
898
 
865
- request_id = response["request_id"]
866
- print(f" - Created off-chain request with ID {request_id}")
899
+ request_ids = [resp["request_id"] for resp in responses if resp is not None]
900
+ if len(request_ids) == 1:
901
+ print(f" - Created off-chain request with ID {request_ids[0]}")
902
+ else:
903
+ print(
904
+ f" - Created off-chain requests with IDs: {', '.join(str(rid) for rid in request_ids)}"
905
+ )
867
906
  print("")
868
907
 
869
908
  # @note as we are directly querying data from done task list, we get the full data instead of the ipfs hash
870
909
  print("Waiting for Offchain Mech Marketplace deliver...")
871
- data = wait_for_offchain_marketplace_data(
872
- request_id=request_id,
873
- )
874
910
 
875
- if data:
876
- task_result = data["task_result"]
877
- data_url = f"https://gateway.autonolas.tech/ipfs/f01701220{task_result}"
878
- print(f" - Data arrived: {data_url}")
879
- data = requests.get(f"{data_url}/{request_id}", timeout=30).json()
880
- print(" - Data from agent:")
881
- print(json.dumps(data, indent=2))
882
- return data
911
+ for request_id in request_ids:
912
+ data = wait_for_offchain_marketplace_data(
913
+ request_id=request_id,
914
+ )
915
+
916
+ if data:
917
+ task_result = data["task_result"]
918
+ data_url = IPFS_URL_TEMPLATE.format(task_result)
919
+ print(f" - Data arrived: {data_url}")
920
+ data = requests.get(f"{data_url}/{request_id}", timeout=30).json()
921
+ print(" - Data from agent:")
922
+ print(json.dumps(data, indent=2))
883
923
  return None
@@ -7,7 +7,13 @@ from typing import Any, Dict, List, Optional, Tuple, Union
7
7
  import requests
8
8
  from aea_ledger_ethereum import EthereumApi
9
9
 
10
- from mech_client.interact import fetch_tools, get_abi, get_contract, get_mech_config
10
+ from mech_client.interact import (
11
+ AGENT_REGISTRY_ABI_PATH,
12
+ fetch_tools,
13
+ get_abi,
14
+ get_contract,
15
+ get_mech_config,
16
+ )
11
17
 
12
18
 
13
19
  def get_total_supply(chain_config: str = "gnosis") -> int:
@@ -27,7 +33,7 @@ def get_total_supply(chain_config: str = "gnosis") -> int:
27
33
  ledger_api = EthereumApi(**asdict(ledger_config))
28
34
 
29
35
  # Fetch ABI and create contract instance
30
- abi = get_abi(mech_config.agent_registry_contract, mech_config.contract_abi_url)
36
+ abi = get_abi(AGENT_REGISTRY_ABI_PATH)
31
37
  contract = get_contract(mech_config.agent_registry_contract, abi, ledger_api)
32
38
 
33
39
  # Call the totalSupply function
@@ -58,7 +64,7 @@ def get_agent_tools(
58
64
  agent_id=agent_id,
59
65
  ledger_api=ledger_api,
60
66
  agent_registry_contract=mech_config.agent_registry_contract,
61
- contract_abi_url=mech_config.contract_abi_url,
67
+ contract_abi_path=AGENT_REGISTRY_ABI_PATH,
62
68
  include_metadata=include_metadata,
63
69
  )
64
70
  except (requests.exceptions.RequestException, json.JSONDecodeError, KeyError) as e:
@@ -155,7 +161,7 @@ def get_tool_description(unique_identifier: str, chain_config: str = "gnosis") -
155
161
  agent_id=agent_id,
156
162
  ledger_api=ledger_api,
157
163
  agent_registry_contract=mech_config.agent_registry_contract,
158
- contract_abi_url=mech_config.contract_abi_url,
164
+ contract_abi_path=AGENT_REGISTRY_ABI_PATH,
159
165
  include_metadata=True,
160
166
  )
161
167
  if isinstance(tools_result, tuple) and len(tools_result) == 2:
@@ -188,7 +194,7 @@ def get_tool_io_schema(
188
194
  agent_id=agent_id,
189
195
  ledger_api=ledger_api,
190
196
  agent_registry_contract=mech_config.agent_registry_contract,
191
- contract_abi_url=mech_config.contract_abi_url,
197
+ contract_abi_path=AGENT_REGISTRY_ABI_PATH,
192
198
  include_metadata=True,
193
199
  )
194
200
  if isinstance(tools_result, tuple) and len(tools_result) == 2:
mech_client/subgraph.py CHANGED
@@ -48,12 +48,28 @@ DELIVER_QUERY_TEMPLATE = Template(
48
48
  """
49
49
  )
50
50
  DEFAULT_TIMEOUT = 600.0
51
+ CHAIN_TO_ADDRESSES = {
52
+ "gnosis": {
53
+ 3: "0xFf82123dFB52ab75C417195c5fDB87630145ae81",
54
+ 6: "0x77af31De935740567Cf4fF1986D04B2c964A786a",
55
+ 9: "0x552cea7bc33cbbeb9f1d90c1d11d2c6daeffd053",
56
+ 11: "0x9aDe7A78A39B39a44b7a084923E93AA0B19Fd690",
57
+ 19: "0x45b73d649c7b982548d5a6dd3d35e1c5c48997d0",
58
+ },
59
+ "base": {
60
+ 1: "0x37C484cc34408d0F827DB4d7B6e54b8837Bf8BDA",
61
+ 2: "0x111D7DB1B752AB4D2cC0286983D9bd73a49bac6c",
62
+ 3: "0x111D7DB1B752AB4D2cC0286983D9bd73a49bac6c",
63
+ },
64
+ "arbitrum": {2: "0x1FDAD3a5af5E96e5a64Fc0662B1814458F114597"},
65
+ "polygon": {2: "0xbF92568718982bf65ee4af4F7020205dE2331a8a"},
66
+ "celo": {2: "0x230eD015735c0D01EA0AaD2786Ed6Bd3C6e75912"},
67
+ "optimism": {2: "0xDd40E7D93c37eFD860Bd53Ab90b2b0a8D05cf71a"},
68
+ }
51
69
 
52
70
 
53
71
  def query_agent_address( # pylint: disable=too-many-return-statements
54
72
  agent_id: int,
55
- url: str,
56
- timeout: Optional[float] = None,
57
73
  chain_config: Optional[str] = None,
58
74
  ) -> Optional[str]:
59
75
  """
@@ -61,44 +77,14 @@ def query_agent_address( # pylint: disable=too-many-return-statements
61
77
 
62
78
  :param agent_id: The ID of the agent.
63
79
  :type agent_id: int
64
- :param url: Subgraph URL.
65
- :type url: str
66
- :param timeout: Timeout for the request.
67
- :type timeout: Optional[float]
68
80
  :type chain_config: Optional[str]:
69
81
  :return: The agent address if found, None otherwise.
70
82
  :rtype: Optional[str]
71
83
  """
72
84
  # temporary hard coded until subgraph present
73
- if chain_config == "base" and agent_id == 1:
74
- return "0x37C484cc34408d0F827DB4d7B6e54b8837Bf8BDA"
75
- if chain_config == "base" and agent_id == 2:
76
- return "0x111D7DB1B752AB4D2cC0286983D9bd73a49bac6c"
77
- if chain_config == "base" and agent_id == 3:
78
- return "0x111D7DB1B752AB4D2cC0286983D9bd73a49bac6c"
79
- if chain_config == "arbitrum" and agent_id == 2:
80
- return "0x1FDAD3a5af5E96e5a64Fc0662B1814458F114597"
81
- if chain_config == "polygon" and agent_id == 2:
82
- return "0xbF92568718982bf65ee4af4F7020205dE2331a8a"
83
- if chain_config == "celo" and agent_id == 2:
84
- return "0x230eD015735c0D01EA0AaD2786Ed6Bd3C6e75912"
85
- if chain_config == "optimism" and agent_id == 2:
86
- return "0xDd40E7D93c37eFD860Bd53Ab90b2b0a8D05cf71a"
87
- client = Client(
88
- transport=AIOHTTPTransport(url=url),
89
- execute_timeout=timeout or 30.0,
90
- )
91
- response = client.execute(
92
- document=gql(
93
- request_string=AGENT_QUERY_TEMPLATE.substitute({"agent_id": agent_id})
94
- )
95
- )
96
- mechs = response["createMeches"] # pylint: disable=unsubscriptable-object
97
- if len(mechs) == 0:
98
- return None
99
-
100
- (record,) = mechs
101
- return record["mech"]
85
+ if not chain_config:
86
+ raise ValueError("Chain config not specified")
87
+ return CHAIN_TO_ADDRESSES.get(chain_config, {}).get(agent_id, None)
102
88
 
103
89
 
104
90
  async def query_deliver_hash(
mech_client/wss.py CHANGED
@@ -23,7 +23,7 @@ import asyncio
23
23
  import json
24
24
  import time
25
25
  from concurrent.futures import ThreadPoolExecutor
26
- from typing import Any, Dict, cast
26
+ from typing import Any, Dict, List, cast
27
27
 
28
28
  import websocket
29
29
  from aea.crypto.base import Crypto
@@ -143,11 +143,11 @@ def watch_for_request_id( # pylint: disable=too-many-arguments
143
143
  return request_id
144
144
 
145
145
 
146
- def watch_for_marketplace_request_id( # pylint: disable=too-many-arguments, unused-argument
146
+ def watch_for_marketplace_request_ids( # pylint: disable=too-many-arguments, unused-argument
147
147
  marketplace_contract: Web3Contract,
148
148
  ledger_api: EthereumApi,
149
149
  tx_hash: str,
150
- ) -> str:
150
+ ) -> List[str]:
151
151
  """
152
152
  Watches for events on mech.
153
153
 
@@ -167,10 +167,11 @@ def watch_for_marketplace_request_id( # pylint: disable=too-many-arguments, unu
167
167
  tx_receipt
168
168
  )
169
169
  if len(rich_logs) == 0:
170
- return "Empty Logs"
170
+ return ["Empty Logs"]
171
171
 
172
- request_id = rich_logs[0]["args"]["requestIds"][0]
173
- return request_id.hex()
172
+ request_ids = rich_logs[0]["args"]["requestIds"]
173
+ request_ids_hex = [request_id.hex() for request_id in request_ids]
174
+ return request_ids_hex
174
175
 
175
176
 
176
177
  async def watch_for_data_url_from_wss( # pylint: disable=too-many-arguments