iwa 0.0.15__py3-none-any.whl → 0.0.17__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.
@@ -51,11 +51,21 @@ OLAS_CONTRACTS: Dict[str, Dict[str, EthereumAddress]] = {
51
51
  "0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8"
52
52
  ),
53
53
  "OLAS_SERVICE_MANAGER": EthereumAddress("0x068a4f0946cF8c7f9C1B58a3b5243Ac8843bf473"),
54
- # Legacy mech - used by TRADER staking contracts for liveness
54
+ # Legacy mech - used by NON-MM TRADER staking contracts (e.g., "Expert X (Yk OLAS)")
55
+ # Activity checker calls agentMech.getRequestsCount(multisig) to count requests.
55
56
  "OLAS_MECH": EthereumAddress("0x77af31De935740567Cf4fF1986D04B2c964A786a"),
56
- # NEW Marketplace (v2) - no staking support yet
57
+ # NEW Marketplace (v2) - used by MM staking contracts (e.g., "Expert X MM (Yk OLAS)")
58
+ # Services staked in "Expert X MM" contracts MUST use marketplace requests.
59
+ # Legacy mech requests will NOT be counted by the activity checker.
57
60
  "OLAS_MECH_MARKETPLACE": EthereumAddress("0x735FAAb1c4Ec41128c367AFb5c3baC73509f70bB"),
58
- # OLD Marketplace (v1) - used by Pearl Beta Mech Marketplace staking
61
+ # Default priority mech for marketplace requests (from olas-operate-middleware)
62
+ # This is the mech that will process requests sent via the marketplace.
63
+ # Source: https://github.com/valory-xyz/olas-operate-middleware/blob/main/operate/ledger/profiles.py
64
+ # DEFAULT_PRIORITY_MECH["0x735FAAb1c..."] = ("0xC05e7412...", 2182)
65
+ "OLAS_MECH_MARKETPLACE_PRIORITY": EthereumAddress(
66
+ "0xC05e7412439bD7e91730a6880E18d5D5873F632C"
67
+ ),
68
+ # OLD Marketplace (v1) - legacy, kept for reference
59
69
  "OLAS_MECH_MARKETPLACE_OLD": EthereumAddress("0x4554fE75c1f5576c1d7F765B2A036c199Adae329"),
60
70
  },
61
71
  "ethereum": {
@@ -10,6 +10,8 @@ requests relative to the time elapsed since the last checkpoint.
10
10
 
11
11
  from typing import Tuple
12
12
 
13
+ from web3 import Web3
14
+
13
15
  from iwa.core.constants import DEFAULT_MECH_CONTRACT_ADDRESS
14
16
  from iwa.core.types import EthereumAddress
15
17
  from iwa.plugins.olas.contracts.base import OLAS_ABI_PATH, ContractInstance
@@ -43,18 +45,34 @@ class ActivityCheckerContract(ContractInstance):
43
45
  """
44
46
  super().__init__(address, chain_name=chain_name)
45
47
 
46
- # Get the mech address this checker tracks
47
- agent_mech_function = getattr(self.contract.functions, "agentMech", None)
48
- self.agent_mech = (
49
- agent_mech_function().call() if agent_mech_function else DEFAULT_MECH_CONTRACT_ADDRESS
50
- )
48
+ # Check for marketplace-aware checker
49
+ try:
50
+ mech_mp_function = getattr(self.contract.functions, "mechMarketplace", None)
51
+ self.mech_marketplace = mech_mp_function().call() if mech_mp_function else None
52
+ except Exception:
53
+ self.mech_marketplace = None
54
+
55
+ # Get the mech address this checker tracks (legacy or priority mech)
56
+ try:
57
+ agent_mech_function = getattr(self.contract.functions, "agentMech", None)
58
+ self.agent_mech = (
59
+ agent_mech_function().call() if agent_mech_function else DEFAULT_MECH_CONTRACT_ADDRESS
60
+ )
61
+ except Exception:
62
+ self.agent_mech = DEFAULT_MECH_CONTRACT_ADDRESS
51
63
 
52
64
  # Get liveness ratio (requests per second * 1e18)
53
- self.liveness_ratio = self.contract.functions.livenessRatio().call()
65
+ try:
66
+ self.liveness_ratio = self.contract.functions.livenessRatio().call()
67
+ except Exception:
68
+ self.liveness_ratio = 0
54
69
 
55
70
  def get_multisig_nonces(self, multisig: EthereumAddress) -> Tuple[int, int]:
56
71
  """Get the nonces for a multisig address.
57
72
 
73
+ This method reads directly from the source contracts to ensure fresh data
74
+ and compatibility with Legacy/MM contracts.
75
+
58
76
  Args:
59
77
  multisig: The multisig address to check.
60
78
 
@@ -64,8 +82,52 @@ class ActivityCheckerContract(ContractInstance):
64
82
  - mech_requests_count: Total mech requests made
65
83
 
66
84
  """
67
- nonces = self.contract.functions.getMultisigNonces(multisig).call()
68
- return (nonces[0], nonces[1])
85
+ # 1. Get Safe Nonce
86
+ safe_nonce = 0
87
+ try:
88
+ # Minimal ABI for Safe nonce
89
+ safe_abi = [{"name": "nonce", "type": "function", "inputs": [], "outputs": [{"type": "uint256"}]}]
90
+ safe_contract = self.chain_interface.web3._web3.eth.contract(
91
+ address=Web3.to_checksum_address(multisig), abi=safe_abi
92
+ )
93
+ safe_nonce = safe_contract.functions.nonce().call()
94
+ except Exception as e:
95
+ # Fallback or log error? If safe read fails, something is very wrong.
96
+ # But we don't want to crash the whole status check if possible.
97
+ # For now, let's log and keep 0 or re-raise if critical.
98
+ # safe_nonce is critical for liveness check (diffNonces).
99
+ from loguru import logger
100
+ logger.warning(f"Failed to read Safe nonce for {multisig}: {e}")
101
+
102
+ # 2. Get Mech Requests Count
103
+ mech_requests = 0
104
+
105
+ if self.mech_marketplace:
106
+ # Case A: Marketplace (MM)
107
+ try:
108
+ # Minimal ABI for Marketplace mapRequestCounts
109
+ mp_abi = [{"name": "mapRequestCounts", "type": "function", "inputs": [{"type": "address"}], "outputs": [{"type": "uint256"}]}]
110
+ mp_contract = self.chain_interface.web3._web3.eth.contract(
111
+ address=Web3.to_checksum_address(self.mech_marketplace), abi=mp_abi
112
+ )
113
+ mech_requests = mp_contract.functions.mapRequestCounts(multisig).call()
114
+ except Exception as e:
115
+ from loguru import logger
116
+ logger.warning(f"Failed to read Marketplace requests for {multisig}: {e}")
117
+ else:
118
+ # Case B: Legacy (AgentMech)
119
+ try:
120
+ # Minimal ABI for AgentMech getRequestsCount
121
+ mech_abi = [{"name": "getRequestsCount", "type": "function", "inputs": [{"type": "address"}], "outputs": [{"type": "uint256"}]}]
122
+ mech_contract = self.chain_interface.web3._web3.eth.contract(
123
+ address=Web3.to_checksum_address(self.agent_mech), abi=mech_abi
124
+ )
125
+ mech_requests = mech_contract.functions.getRequestsCount(multisig).call()
126
+ except Exception as e:
127
+ from loguru import logger
128
+ logger.warning(f"Failed to read AgentMech requests for {multisig}: {e}")
129
+
130
+ return (safe_nonce, mech_requests)
69
131
 
70
132
  def is_ratio_pass(
71
133
  self,
@@ -1,4 +1,29 @@
1
- """Mech manager mixin."""
1
+ """Mech manager mixin.
2
+
3
+ This module handles sending mech requests for OLAS services. There are TWO
4
+ distinct flows for mech requests, and the correct one MUST be used based on
5
+ the service's staking contract:
6
+
7
+ 1. **Legacy Mech Flow** (use_marketplace=False):
8
+ - Sends requests directly to the legacy mech contract (0x77af31De...)
9
+ - Used by NON-MM staking contracts (e.g., "Expert X (Yk OLAS)")
10
+ - Activity checker calls `agentMech.getRequestsCount(multisig)` to count
11
+
12
+ 2. **Marketplace Flow** (use_marketplace=True):
13
+ - Sends requests via MechMarketplace contract (0x735FAAb1c...)
14
+ - Used by MM staking contracts (e.g., "Expert X MM (Yk OLAS)")
15
+ - Activity checker calls `mechMarketplace.mapRequestCounts(multisig)` to count
16
+ - Requires a priority_mech that is registered on the marketplace
17
+ - Default priority_mech from olas-operate-middleware: 0xC05e7412...
18
+
19
+ **IMPORTANT**: If a service is staked in an MM contract but sends legacy mech
20
+ requests, those requests will NOT be counted by the activity checker, and the
21
+ service will not receive staking rewards.
22
+
23
+ The `get_marketplace_config()` method automatically detects which flow to use
24
+ by checking if the staking contract's activity checker has a `mechMarketplace`
25
+ field set to a non-zero address.
26
+ """
2
27
 
3
28
  from typing import Optional
4
29
 
@@ -17,12 +42,60 @@ from iwa.plugins.olas.contracts.mech_marketplace import MechMarketplaceContract
17
42
  class MechManagerMixin:
18
43
  """Mixin for Mech interactions."""
19
44
 
45
+ def get_marketplace_config(self) -> tuple:
46
+ """Check if current service requires marketplace mech requests.
47
+
48
+ Queries the staking contract's activityChecker to determine if it
49
+ tracks marketplace requests.
50
+
51
+ Returns:
52
+ Tuple of (use_marketplace, marketplace_address, priority_mech):
53
+ - use_marketplace: True if marketplace requests are required.
54
+ - marketplace_address: Address of the mech marketplace (if applicable).
55
+ - priority_mech: Address of the priority mech (if applicable).
56
+
57
+ """
58
+ from iwa.core.constants import ZERO_ADDRESS
59
+
60
+ if not self.service or not self.service.staking_contract_address:
61
+ return (False, None, None)
62
+
63
+ try:
64
+ # Get staking contract with its activity checker
65
+ from iwa.plugins.olas.contracts.staking import StakingContract
66
+
67
+ staking = StakingContract(
68
+ self.service.staking_contract_address, chain_name=self.chain_name
69
+ )
70
+
71
+ # StakingContract has activity_checker attribute set in __init__
72
+ checker = staking.activity_checker
73
+
74
+ if checker.mech_marketplace and checker.mech_marketplace != ZERO_ADDRESS:
75
+ # Use the default marketplace priority mech from constants
76
+ from iwa.plugins.olas.constants import OLAS_CONTRACTS
77
+
78
+ protocol_contracts = OLAS_CONTRACTS.get(self.chain_name, {})
79
+ priority_mech = protocol_contracts.get("OLAS_MECH_MARKETPLACE_PRIORITY")
80
+
81
+ logger.info(
82
+ f"[MECH] Service {self.service.service_id} requires marketplace requests "
83
+ f"(marketplace={checker.mech_marketplace}, priority_mech={priority_mech})"
84
+ )
85
+ return (True, checker.mech_marketplace, priority_mech)
86
+
87
+ return (False, None, None)
88
+
89
+ except Exception as e:
90
+ logger.debug(f"[MECH] Failed to detect marketplace config: {e}")
91
+ return (False, None, None)
92
+
20
93
  def send_mech_request(
21
94
  self,
22
95
  data: bytes,
23
96
  value: Optional[int] = None,
24
97
  mech_address: Optional[str] = None,
25
- use_marketplace: bool = False,
98
+ use_marketplace: Optional[bool] = None,
26
99
  use_new_abi: bool = False,
27
100
  priority_mech: Optional[str] = None,
28
101
  max_delivery_rate: Optional[int] = None,
@@ -37,6 +110,7 @@ class MechManagerMixin:
37
110
  value: Payment value in wei. For marketplace, should match mech's maxDeliveryRate.
38
111
  mech_address: Address of the Mech contract (for legacy/direct flow).
39
112
  use_marketplace: Whether to use the Mech Marketplace flow.
113
+ If None, auto-detects based on staking contract.
40
114
  use_new_abi: Whether to use new ABI for legacy flow.
41
115
  priority_mech: Priority mech address (required for marketplace).
42
116
  max_delivery_rate: Max delivery rate in wei (for marketplace). If None, uses value.
@@ -59,6 +133,14 @@ class MechManagerMixin:
59
133
  logger.error(f"Service {service_id} has no multisig address")
60
134
  return None
61
135
 
136
+ # Auto-detect marketplace requirement if not explicitly specified
137
+ if use_marketplace is None:
138
+ use_marketplace, detected_marketplace, detected_priority_mech = (
139
+ self.get_marketplace_config()
140
+ )
141
+ if use_marketplace:
142
+ priority_mech = priority_mech or detected_priority_mech
143
+
62
144
  if use_marketplace:
63
145
  return self._send_marketplace_mech_request(
64
146
  data=data,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iwa
3
- Version: 0.0.15
3
+ Version: 0.0.17
4
4
  Summary: A secure, modular, and plugin-based framework for crypto agents and ops
5
5
  Requires-Python: <4.0,>=3.12
6
6
  Description-Content-Type: text/markdown
@@ -56,12 +56,12 @@ iwa/plugins/gnosis/cow/types.py,sha256=-9VRiFhAkmN1iIJ95Pg7zLFSeXtkkW00sl13usxi3
56
56
  iwa/plugins/gnosis/tests/test_cow.py,sha256=iVy5ockMIcPZWsX4WGXU91DhBsYEZ5NOxtFzAQ2sK3o,8440
57
57
  iwa/plugins/gnosis/tests/test_safe.py,sha256=pw1zrYvAiVtmPIU5k7BtOQpDNAQTSTrLIaeljCjSahc,3216
58
58
  iwa/plugins/olas/__init__.py,sha256=_NhBczzM61fhGYwGhnWfEeL8Jywyy_730GASe2BxzeQ,106
59
- iwa/plugins/olas/constants.py,sha256=mFUMDB46WbM9Y8sw7c-i9TRyJVrDNZXdCXa64M5tI6A,6608
59
+ iwa/plugins/olas/constants.py,sha256=nbthnzu90xgfbXOU2GwovbNmDLUBNDSZBrEQ02H-5wk,7381
60
60
  iwa/plugins/olas/importer.py,sha256=f8KlZ9dGcNbpg8uoTYbO9sDvbluZoslhpWFLqPjPnLA,26717
61
61
  iwa/plugins/olas/mech_reference.py,sha256=CaSCpQnQL4F7wOG6Ox6Zdoy-uNEQ78YBwVLILQZKL8Q,5782
62
62
  iwa/plugins/olas/models.py,sha256=xC5hYakX53pBT6zZteM9cyiC7t6XRLLpobjQmDYueOo,3520
63
63
  iwa/plugins/olas/plugin.py,sha256=S_vnvZ02VdVWD7N5kp7u5JIRQ2JLtfwGDZ7OHkAN0M8,9390
64
- iwa/plugins/olas/contracts/activity_checker.py,sha256=UDbCgFOyuEhHf1qoUwCUdLc8oK8ksuAYE-ZgKrMBnwg,3415
64
+ iwa/plugins/olas/contracts/activity_checker.py,sha256=sQSzBWF7meXzCzVw4G0wowjTTRddraGPppQ8PyLcuaU,6429
65
65
  iwa/plugins/olas/contracts/base.py,sha256=y73aQbDq6l4zUpz_eQAg4MsLkTAEqjjupXlcvxjfgCI,240
66
66
  iwa/plugins/olas/contracts/mech.py,sha256=dXYtyORc-oiu9ga5PtTquOFkoakb6BLGKvlUsteygIg,2767
67
67
  iwa/plugins/olas/contracts/mech_marketplace.py,sha256=hMADl5MQGvT2wLRKu4vHGe4RrAZVq8Y2M_EvXWWz528,1554
@@ -82,7 +82,7 @@ iwa/plugins/olas/service_manager/__init__.py,sha256=GXiThMEY3nPgHUl1i-DLrF4h96z9
82
82
  iwa/plugins/olas/service_manager/base.py,sha256=CCTH7RiYtgyFwRszrMLxNf1rNM_6leWHuJJmse4m2wI,4854
83
83
  iwa/plugins/olas/service_manager/drain.py,sha256=IS7YYKuQdkULcNdxfHVzjcq95pXKdpajolzLL78u4jc,12430
84
84
  iwa/plugins/olas/service_manager/lifecycle.py,sha256=DIB6yrP0VPICu6558uQJuFp2sgrA66iVNTzZVUUowGw,47159
85
- iwa/plugins/olas/service_manager/mech.py,sha256=72-tEap-aYd0gebcH6y_De1SNeL6OrXn7sWuv_Ok_-Y,12224
85
+ iwa/plugins/olas/service_manager/mech.py,sha256=Rl4FJIYrT9L4gzTd7-7xBZaxBEHWFyMmN5TuSNfEdZc,15964
86
86
  iwa/plugins/olas/service_manager/staking.py,sha256=Z9GzlPfY7qSSjc9xPhWvb9qywxu_7OB3Gc1eBli07pY,28058
87
87
  iwa/plugins/olas/tests/conftest.py,sha256=4vM7EI00SrTGyeP0hNzsGSQHEj2-iznVgzlNh2_OGfo,739
88
88
  iwa/plugins/olas/tests/test_importer.py,sha256=i9LKov7kNRECB3hmRnhKBwcfx3uxtjWe4BB77bOOpeo,4282
@@ -150,7 +150,7 @@ iwa/web/tests/test_web_endpoints.py,sha256=C264MH-CTyDW4GLUrTXBgLJKUk4-89pFAScBd
150
150
  iwa/web/tests/test_web_olas.py,sha256=0CVSsrncOeJ3x0ECV7mVLQV_CXZRrOqGiVjgLIi6hZ8,16308
151
151
  iwa/web/tests/test_web_swap.py,sha256=7A4gBJFL01kIXPtW1E1J17SCsVc_0DmUn-R8kKrnnVA,2974
152
152
  iwa/web/tests/test_web_swap_coverage.py,sha256=zGNrzlhZ_vWDCvWmLcoUwFgqxnrp_ACbo49AtWBS_Kw,5584
153
- iwa-0.0.15.dist-info/licenses/LICENSE,sha256=eIubm_IlBHPYRQlLNZKbBNKhJUUP3JH0A2miZUhAVfI,1078
153
+ iwa-0.0.17.dist-info/licenses/LICENSE,sha256=eIubm_IlBHPYRQlLNZKbBNKhJUUP3JH0A2miZUhAVfI,1078
154
154
  tests/legacy_cow.py,sha256=oOkZvIxL70ReEoD9oHQbOD5GpjIr6AGNHcOCgfPlerU,8389
155
155
  tests/legacy_safe.py,sha256=AssM2g13E74dNGODu_H0Q0y412lgqsrYnEzI97nm_Ts,2972
156
156
  tests/legacy_transaction_retry_logic.py,sha256=D9RqZ7DBu61Xr2djBAodU2p9UE939LL-DnQXswX5iQk,1497
@@ -202,8 +202,8 @@ tests/test_utils.py,sha256=vkP49rYNI8BRzLpWR3WnKdDr8upeZjZcs7Rx0pjbQMo,1292
202
202
  tests/test_workers.py,sha256=MInwdkFY5LdmFB3o1odIaSD7AQZb3263hNafO1De5PE,2793
203
203
  tools/create_and_stake_service.py,sha256=1xwy_bJQI1j9yIQ968Oc9Db_F6mk1659LuuZntTASDE,3742
204
204
  tools/verify_drain.py,sha256=PkMjblyOOAuQge88FwfEzRtCYeEtJxXhPBmtQYCoQ-8,6743
205
- iwa-0.0.15.dist-info/METADATA,sha256=J9pChdhUaRH85yUje-9tNp2xCTdncgmxJHnMuV9kv7M,7295
206
- iwa-0.0.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
207
- iwa-0.0.15.dist-info/entry_points.txt,sha256=nwB6kscrfA7M00pYmL2j-sBH6eF6h2ga9IK1BZxdiyQ,241
208
- iwa-0.0.15.dist-info/top_level.txt,sha256=kedS9cRUbm4JE2wYeabIXilhHjN8KCw0IGbqqqsw0Bs,16
209
- iwa-0.0.15.dist-info/RECORD,,
205
+ iwa-0.0.17.dist-info/METADATA,sha256=vzZKb09UmfMfeWTcLbJnUCxWHIr-DGWNvSvUM5k9RcQ,7295
206
+ iwa-0.0.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
207
+ iwa-0.0.17.dist-info/entry_points.txt,sha256=nwB6kscrfA7M00pYmL2j-sBH6eF6h2ga9IK1BZxdiyQ,241
208
+ iwa-0.0.17.dist-info/top_level.txt,sha256=kedS9cRUbm4JE2wYeabIXilhHjN8KCw0IGbqqqsw0Bs,16
209
+ iwa-0.0.17.dist-info/RECORD,,
File without changes