olas-operate-middleware 0.6.3__py3-none-any.whl → 0.8.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.
- {olas_operate_middleware-0.6.3.dist-info → olas_operate_middleware-0.8.0.dist-info}/METADATA +1 -1
- {olas_operate_middleware-0.6.3.dist-info → olas_operate_middleware-0.8.0.dist-info}/RECORD +21 -20
- operate/bridge/{bridge.py → bridge_manager.py} +99 -62
- operate/bridge/providers/{lifi_bridge_provider.py → lifi_provider.py} +94 -81
- operate/bridge/providers/native_bridge_provider.py +124 -115
- operate/bridge/providers/{bridge_provider.py → provider.py} +132 -150
- operate/bridge/providers/relay_provider.py +442 -0
- operate/cli.py +140 -110
- operate/constants.py +1 -0
- operate/ledger/profiles.py +11 -1
- operate/operate_types.py +10 -0
- operate/quickstart/claim_staking_rewards.py +1 -1
- operate/quickstart/reset_staking.py +1 -1
- operate/quickstart/run_service.py +34 -11
- operate/quickstart/terminate_on_chain_service.py +1 -1
- operate/quickstart/utils.py +0 -1
- operate/services/agent_runner.py +168 -91
- operate/services/manage.py +126 -72
- {olas_operate_middleware-0.6.3.dist-info → olas_operate_middleware-0.8.0.dist-info}/LICENSE +0 -0
- {olas_operate_middleware-0.6.3.dist-info → olas_operate_middleware-0.8.0.dist-info}/WHEEL +0 -0
- {olas_operate_middleware-0.6.3.dist-info → olas_operate_middleware-0.8.0.dist-info}/entry_points.txt +0 -0
|
@@ -201,9 +201,6 @@ def configure_local_config(
|
|
|
201
201
|
)
|
|
202
202
|
os.environ[f"{chain.upper()}_LEDGER_RPC"] = config.rpc[chain]
|
|
203
203
|
|
|
204
|
-
if config.password_migrated is None:
|
|
205
|
-
config.password_migrated = False
|
|
206
|
-
|
|
207
204
|
config.principal_chain = template["home_chain"]
|
|
208
205
|
|
|
209
206
|
home_chain = Chain.from_string(config.principal_chain)
|
|
@@ -389,8 +386,32 @@ def configure_local_config(
|
|
|
389
386
|
):
|
|
390
387
|
print_section("Please enter the arguments that will be used by the service.")
|
|
391
388
|
|
|
389
|
+
service_manager = operate.service_manager()
|
|
390
|
+
mech_configs = service_manager.get_mech_configs(
|
|
391
|
+
chain=config.principal_chain,
|
|
392
|
+
ledger_api=ledger_api,
|
|
393
|
+
staking_program_id=config.staking_program_id,
|
|
394
|
+
)
|
|
395
|
+
|
|
392
396
|
for env_var_name, env_var_data in template["env_variables"].items():
|
|
393
397
|
if env_var_data["provision_type"] == ServiceEnvProvisionType.USER:
|
|
398
|
+
# PRIORITY_MECH_ADDRESS and PRIORITY_MECH_SERVICE_ID are given dynamic default values
|
|
399
|
+
if env_var_name == "PRIORITY_MECH_ADDRESS":
|
|
400
|
+
env_var_data["value"] = mech_configs.priority_mech_address
|
|
401
|
+
if (
|
|
402
|
+
env_var_name in config.user_provided_args
|
|
403
|
+
and env_var_data["value"] != config.user_provided_args[env_var_name]
|
|
404
|
+
):
|
|
405
|
+
del config.user_provided_args[env_var_name]
|
|
406
|
+
|
|
407
|
+
if env_var_name == "PRIORITY_MECH_SERVICE_ID":
|
|
408
|
+
env_var_data["value"] = mech_configs.priority_mech_service_id
|
|
409
|
+
if (
|
|
410
|
+
env_var_name in config.user_provided_args
|
|
411
|
+
and env_var_data["value"] != config.user_provided_args[env_var_name]
|
|
412
|
+
):
|
|
413
|
+
del config.user_provided_args[env_var_name]
|
|
414
|
+
|
|
394
415
|
if env_var_name not in config.user_provided_args:
|
|
395
416
|
print(f"Description: {env_var_data['description']}")
|
|
396
417
|
if env_var_data["value"]:
|
|
@@ -426,7 +447,7 @@ def configure_local_config(
|
|
|
426
447
|
return config
|
|
427
448
|
|
|
428
449
|
|
|
429
|
-
def ask_password_if_needed(operate: "OperateApp"
|
|
450
|
+
def ask_password_if_needed(operate: "OperateApp") -> None:
|
|
430
451
|
"""Ask password if needed."""
|
|
431
452
|
if operate.user_account is None:
|
|
432
453
|
print_section("Set up local user account")
|
|
@@ -436,8 +457,6 @@ def ask_password_if_needed(operate: "OperateApp", config: QuickstartConfig) -> N
|
|
|
436
457
|
password=password,
|
|
437
458
|
path=operate._path / "user.json",
|
|
438
459
|
)
|
|
439
|
-
config.password_migrated = True
|
|
440
|
-
config.store()
|
|
441
460
|
else:
|
|
442
461
|
_password = None
|
|
443
462
|
while _password is None:
|
|
@@ -590,8 +609,8 @@ def _ask_funds_from_requirements(
|
|
|
590
609
|
return False
|
|
591
610
|
|
|
592
611
|
|
|
593
|
-
def
|
|
594
|
-
"""
|
|
612
|
+
def _maybe_create_master_eoa(operate: "OperateApp") -> None:
|
|
613
|
+
"""Maybe create the Master EOA."""
|
|
595
614
|
if not operate.wallet_manager.exists(ledger_type=LedgerType.ETHEREUM):
|
|
596
615
|
print("Creating the Master EOA...")
|
|
597
616
|
wallet, mnemonic = operate.wallet_manager.create(
|
|
@@ -606,9 +625,12 @@ def ensure_enough_funds(operate: "OperateApp", service: Service) -> None:
|
|
|
606
625
|
ask_or_get_from_env(
|
|
607
626
|
"Press enter to continue...", False, "CONTINUE", raise_if_missing=False
|
|
608
627
|
)
|
|
609
|
-
else:
|
|
610
|
-
wallet = operate.wallet_manager.load(ledger_type=LedgerType.ETHEREUM)
|
|
611
628
|
|
|
629
|
+
|
|
630
|
+
def ensure_enough_funds(operate: "OperateApp", service: Service) -> None:
|
|
631
|
+
"""Ensure enough funds."""
|
|
632
|
+
_maybe_create_master_eoa(operate)
|
|
633
|
+
wallet = operate.wallet_manager.load(ledger_type=LedgerType.ETHEREUM)
|
|
612
634
|
manager = operate.service_manager()
|
|
613
635
|
|
|
614
636
|
backup_owner = None
|
|
@@ -647,11 +669,12 @@ def run_service(
|
|
|
647
669
|
|
|
648
670
|
operate.service_manager().migrate_service_configs()
|
|
649
671
|
operate.wallet_manager.migrate_wallet_configs()
|
|
672
|
+
ask_password_if_needed(operate)
|
|
673
|
+
_maybe_create_master_eoa(operate)
|
|
650
674
|
|
|
651
675
|
config = configure_local_config(template, operate)
|
|
652
676
|
manager = operate.service_manager()
|
|
653
677
|
service = get_service(manager, template)
|
|
654
|
-
ask_password_if_needed(operate, config)
|
|
655
678
|
|
|
656
679
|
# reload manger and config after setting operate.password
|
|
657
680
|
manager = operate.service_manager(skip_dependency_check=skip_dependency_check)
|
|
@@ -62,7 +62,7 @@ def terminate_service(operate: "OperateApp", config_path: str) -> None:
|
|
|
62
62
|
return
|
|
63
63
|
|
|
64
64
|
config = configure_local_config(template, operate)
|
|
65
|
-
ask_password_if_needed(operate
|
|
65
|
+
ask_password_if_needed(operate)
|
|
66
66
|
manager = operate.service_manager()
|
|
67
67
|
service = get_service(manager, template)
|
|
68
68
|
ensure_enough_funds(operate, service)
|
operate/quickstart/utils.py
CHANGED
|
@@ -277,7 +277,6 @@ class QuickstartConfig(LocalResource):
|
|
|
277
277
|
|
|
278
278
|
path: Path
|
|
279
279
|
rpc: Optional[Dict[str, str]] = None
|
|
280
|
-
password_migrated: Optional[bool] = None
|
|
281
280
|
staking_program_id: Optional[str] = None
|
|
282
281
|
principal_chain: Optional[str] = None
|
|
283
282
|
user_provided_args: Optional[Dict[str, str]] = None
|
operate/services/agent_runner.py
CHANGED
|
@@ -18,116 +18,193 @@
|
|
|
18
18
|
#
|
|
19
19
|
# -------------------------------------------------------------
|
|
20
20
|
"""Source dode to download and run agent from the repos."""
|
|
21
|
+
import hashlib
|
|
21
22
|
import os
|
|
22
23
|
import platform
|
|
23
24
|
import shutil
|
|
24
25
|
import stat
|
|
26
|
+
from dataclasses import dataclass
|
|
25
27
|
from pathlib import Path
|
|
26
28
|
from tempfile import TemporaryDirectory
|
|
27
29
|
from typing import Tuple
|
|
28
30
|
|
|
29
31
|
import requests
|
|
30
32
|
from aea.configurations.data_types import PublicId
|
|
33
|
+
from aea.helpers.logging import setup_logger
|
|
31
34
|
|
|
32
35
|
|
|
36
|
+
@dataclass
|
|
37
|
+
class AgentRelease:
|
|
38
|
+
"""Agent release dataclass."""
|
|
39
|
+
|
|
40
|
+
owner: str
|
|
41
|
+
repo: str
|
|
42
|
+
release: str
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def release_url(self) -> str:
|
|
46
|
+
"""Get release api url."""
|
|
47
|
+
return f"https://api.github.com/repos/{self.owner}/{self.repo}/releases/tags/{self.release}"
|
|
48
|
+
|
|
49
|
+
def get_url_and_hash(self, asset_name: str) -> tuple[str, str]:
|
|
50
|
+
"""Get download url and asset sha256 hash."""
|
|
51
|
+
release_data = requests.get(self.release_url).json()
|
|
52
|
+
|
|
53
|
+
assets_filtered = [i for i in release_data["assets"] if i["name"] == asset_name]
|
|
54
|
+
if not assets_filtered:
|
|
55
|
+
raise ValueError(
|
|
56
|
+
f"Asset {asset_name} not found in release {self.release_url}"
|
|
57
|
+
)
|
|
58
|
+
asset = assets_filtered[0]
|
|
59
|
+
file_hash = asset["digest"]
|
|
60
|
+
file_url = asset["browser_download_url"]
|
|
61
|
+
|
|
62
|
+
return file_url, file_hash
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# list of agents releases supported
|
|
33
66
|
AGENTS_SUPPORTED = {
|
|
34
|
-
"valory":
|
|
35
|
-
"trader"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
67
|
+
"valory/trader": AgentRelease(
|
|
68
|
+
owner="valory-xyz", repo="trader", release="v0.0.101"
|
|
69
|
+
),
|
|
70
|
+
"valory/optimus": AgentRelease(
|
|
71
|
+
owner="valory-xyz", repo="optimus", release="v0.0.103"
|
|
72
|
+
),
|
|
73
|
+
"dvilela/memeooorr": AgentRelease(
|
|
74
|
+
owner="valory-xyz", repo="meme-ooorr", release="v0.0.101"
|
|
75
|
+
),
|
|
41
76
|
}
|
|
42
77
|
|
|
43
78
|
|
|
44
|
-
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
raise ValueError("
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
79
|
+
class AgentRunnerManager:
|
|
80
|
+
"""Agent Runner Manager."""
|
|
81
|
+
|
|
82
|
+
logger = setup_logger(name="operate.agent_runner_manager")
|
|
83
|
+
AGENTS = AGENTS_SUPPORTED
|
|
84
|
+
|
|
85
|
+
@staticmethod
|
|
86
|
+
def get_agent_runner_executable_name() -> str:
|
|
87
|
+
"""Get runner executable name by platform running."""
|
|
88
|
+
if platform.system() == "Darwin":
|
|
89
|
+
os_name = "macos"
|
|
90
|
+
elif platform.system() == "Windows":
|
|
91
|
+
os_name = "windows"
|
|
92
|
+
else:
|
|
93
|
+
raise ValueError("Platform not supported!")
|
|
94
|
+
|
|
95
|
+
if platform.machine().lower() in ("x86_64", "amd64"):
|
|
96
|
+
arch = "x64"
|
|
97
|
+
elif platform.machine().lower() == "arm64":
|
|
98
|
+
arch = "arm64"
|
|
99
|
+
if os_name == "windows":
|
|
100
|
+
raise ValueError("Windows arm64 is not supported!")
|
|
101
|
+
else:
|
|
102
|
+
raise ValueError(f"unsupported arch: {platform.machine()}")
|
|
103
|
+
|
|
104
|
+
exec_name = f"agent_runner_{os_name}_{arch}"
|
|
105
|
+
if platform.system() == "Windows":
|
|
106
|
+
exec_name += ".exe"
|
|
107
|
+
return exec_name
|
|
108
|
+
|
|
109
|
+
@staticmethod
|
|
110
|
+
def parse_agent(public_id_str: str) -> Tuple[str, str]:
|
|
111
|
+
"""Get authorn and name from agent public string id."""
|
|
112
|
+
public_id = PublicId.from_str(public_id_string=public_id_str)
|
|
113
|
+
return (public_id.author, public_id.name)
|
|
114
|
+
|
|
115
|
+
@classmethod
|
|
116
|
+
def download_file(cls, url: str, save_path: Path) -> None:
|
|
117
|
+
"""Download file of agent runner."""
|
|
118
|
+
try:
|
|
119
|
+
# Send a GET request to the URL
|
|
120
|
+
response = requests.get(url, stream=True)
|
|
121
|
+
response.raise_for_status() # Raise an error for bad status codes (4xx or 5xx)
|
|
122
|
+
|
|
123
|
+
# Open the file in binary write mode and save the content
|
|
124
|
+
with open(save_path, "wb") as file:
|
|
125
|
+
for chunk in response.iter_content(chunk_size=8192):
|
|
126
|
+
file.write(chunk)
|
|
127
|
+
|
|
128
|
+
cls.logger.info(f"File downloaded and saved to {save_path}")
|
|
129
|
+
except requests.exceptions.RequestException as e:
|
|
130
|
+
cls.logger.error(f"Error downloading file: {e}")
|
|
131
|
+
raise
|
|
132
|
+
|
|
133
|
+
@classmethod
|
|
134
|
+
def get_agent_release_by_public_id(cls, agent_public_id_str: str) -> AgentRelease:
|
|
135
|
+
"""Get agent release object according to public id."""
|
|
136
|
+
agent_author, agent_name = cls.parse_agent(public_id_str=agent_public_id_str)
|
|
137
|
+
|
|
138
|
+
agent_name = f"{agent_author}/{agent_name}"
|
|
139
|
+
agent_release = cls.AGENTS.get(agent_name, None)
|
|
140
|
+
if agent_release is None:
|
|
141
|
+
raise ValueError(f"{agent_name} is not supported!")
|
|
142
|
+
return agent_release
|
|
143
|
+
|
|
144
|
+
@staticmethod
|
|
145
|
+
def get_local_file_sha256(path: Path) -> str:
|
|
146
|
+
"""Get local file sha256."""
|
|
147
|
+
sha256_hash = hashlib.sha256()
|
|
148
|
+
with open(path, "rb") as f:
|
|
149
|
+
for byte_block in iter(lambda: f.read(4096), b""):
|
|
150
|
+
sha256_hash.update(byte_block)
|
|
151
|
+
return "sha256:" + sha256_hash.hexdigest()
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def update_agent_runner(
|
|
155
|
+
cls, target_path: Path, agent_runner_name: str, agent_release: AgentRelease
|
|
156
|
+
) -> None:
|
|
157
|
+
"""Download agent runner."""
|
|
158
|
+
download_url, remote_file_hash = agent_release.get_url_and_hash(
|
|
159
|
+
agent_runner_name
|
|
102
160
|
)
|
|
103
|
-
repo_url = AGENTS_SUPPORTED[agent_author][agent_name]
|
|
104
|
-
download_url = f"{repo_url}{agent_runner_name}"
|
|
105
|
-
try:
|
|
106
|
-
with TemporaryDirectory() as tmp_dir:
|
|
107
|
-
tmp_file = Path(tmp_dir) / "agent_runner"
|
|
108
|
-
download_file(download_url, tmp_file)
|
|
109
|
-
shutil.copy2(tmp_file, target_path)
|
|
110
|
-
if os.name == "posix":
|
|
111
|
-
target_path.chmod(target_path.stat().st_mode | stat.S_IEXEC)
|
|
112
|
-
except Exception:
|
|
113
|
-
# remove in cae of errors
|
|
114
|
-
if target_path.exists():
|
|
115
|
-
target_path.unlink(missing_ok=True)
|
|
116
|
-
raise
|
|
117
161
|
|
|
162
|
+
if target_path.exists():
|
|
163
|
+
# check sha
|
|
164
|
+
current_file_hash = cls.get_local_file_sha256(target_path)
|
|
165
|
+
if remote_file_hash == current_file_hash:
|
|
166
|
+
cls.logger.info(
|
|
167
|
+
"local and remote files hashes are match, nothing to download"
|
|
168
|
+
)
|
|
169
|
+
return
|
|
170
|
+
cls.logger.info(
|
|
171
|
+
"local and remote files hashes does not match, go to download"
|
|
172
|
+
)
|
|
173
|
+
else:
|
|
174
|
+
cls.logger.info("local file not found, go to download")
|
|
175
|
+
|
|
176
|
+
try:
|
|
177
|
+
with TemporaryDirectory() as tmp_dir:
|
|
178
|
+
tmp_file = Path(tmp_dir) / "agent_runner"
|
|
179
|
+
cls.download_file(download_url, tmp_file)
|
|
180
|
+
shutil.copy2(tmp_file, target_path)
|
|
181
|
+
if os.name == "posix":
|
|
182
|
+
target_path.chmod(target_path.stat().st_mode | stat.S_IEXEC)
|
|
183
|
+
except Exception:
|
|
184
|
+
# remove in caae of errors
|
|
185
|
+
if target_path.exists():
|
|
186
|
+
target_path.unlink(missing_ok=True)
|
|
187
|
+
raise
|
|
188
|
+
|
|
189
|
+
@classmethod
|
|
190
|
+
def get_agent_runner_path(cls, service_dir: Path, agent_public_id_str: str) -> str:
|
|
191
|
+
"""Get path to the agent runner bin palced."""
|
|
192
|
+
agent_runner_name = cls.get_agent_runner_executable_name()
|
|
193
|
+
agent_runner_path: Path = service_dir / agent_runner_name
|
|
194
|
+
agent_release = cls.get_agent_release_by_public_id(
|
|
195
|
+
agent_public_id_str=agent_public_id_str
|
|
196
|
+
)
|
|
118
197
|
|
|
119
|
-
|
|
120
|
-
"""Get path to the agent runner bin palced."""
|
|
121
|
-
agent_runner_name = get_agent_runner_executable_name()
|
|
122
|
-
agent_runner_path: Path = service_dir / agent_runner_name
|
|
123
|
-
|
|
124
|
-
if agent_runner_path.exists():
|
|
125
|
-
print(f"agent runner {agent_runner_path} already exists. dont download it.")
|
|
126
|
-
else:
|
|
127
|
-
print(f"agent runner {agent_runner_path} does not exists. downloading it.")
|
|
128
|
-
download_agent_runner(
|
|
198
|
+
cls.update_agent_runner(
|
|
129
199
|
target_path=agent_runner_path,
|
|
130
200
|
agent_runner_name=agent_runner_name,
|
|
131
|
-
|
|
201
|
+
agent_release=agent_release,
|
|
132
202
|
)
|
|
133
|
-
|
|
203
|
+
return str(agent_runner_path)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def get_agent_runner_path(service_dir: Path, agent_public_id_str: str) -> str:
|
|
207
|
+
"""Get path to the agent runner bin placed."""
|
|
208
|
+
return AgentRunnerManager.get_agent_runner_path(
|
|
209
|
+
service_dir=service_dir, agent_public_id_str=agent_public_id_str
|
|
210
|
+
)
|
operate/services/manage.py
CHANGED
|
@@ -36,7 +36,7 @@ from pathlib import Path
|
|
|
36
36
|
import requests
|
|
37
37
|
from aea.helpers.base import IPFSHash
|
|
38
38
|
from aea.helpers.logging import setup_logger
|
|
39
|
-
from aea_ledger_ethereum import EthereumCrypto
|
|
39
|
+
from aea_ledger_ethereum import EthereumCrypto, LedgerApi
|
|
40
40
|
from autonomy.chain.base import registry_contracts
|
|
41
41
|
from autonomy.chain.config import CHAIN_PROFILES, ChainType
|
|
42
42
|
|
|
@@ -52,7 +52,7 @@ from operate.ledger import PUBLIC_RPCS, get_currency_denom
|
|
|
52
52
|
from operate.ledger.profiles import (
|
|
53
53
|
CONTRACTS,
|
|
54
54
|
DEFAULT_MASTER_EOA_FUNDS,
|
|
55
|
-
|
|
55
|
+
DEFAULT_PRIORITY_MECH,
|
|
56
56
|
OLAS,
|
|
57
57
|
STAKING,
|
|
58
58
|
USDC,
|
|
@@ -63,6 +63,7 @@ from operate.operate_types import (
|
|
|
63
63
|
Chain,
|
|
64
64
|
FundingValues,
|
|
65
65
|
LedgerConfig,
|
|
66
|
+
MechMarketplaceConfig,
|
|
66
67
|
OnChainState,
|
|
67
68
|
ServiceEnvProvisionType,
|
|
68
69
|
ServiceTemplate,
|
|
@@ -518,6 +519,103 @@ class ServiceManager:
|
|
|
518
519
|
chain=chain,
|
|
519
520
|
)
|
|
520
521
|
|
|
522
|
+
def get_mech_configs(
|
|
523
|
+
self,
|
|
524
|
+
chain: str,
|
|
525
|
+
ledger_api: LedgerApi,
|
|
526
|
+
staking_program_id: str | None = None,
|
|
527
|
+
) -> MechMarketplaceConfig:
|
|
528
|
+
"""Get the mech configs."""
|
|
529
|
+
sftxb = self.get_eth_safe_tx_builder(
|
|
530
|
+
ledger_config=LedgerConfig(
|
|
531
|
+
chain=Chain(chain),
|
|
532
|
+
rpc=ledger_api.api.provider.endpoint_uri,
|
|
533
|
+
)
|
|
534
|
+
)
|
|
535
|
+
staking_contract = get_staking_contract(
|
|
536
|
+
chain=chain,
|
|
537
|
+
staking_program_id=staking_program_id,
|
|
538
|
+
)
|
|
539
|
+
if staking_contract is None:
|
|
540
|
+
return MechMarketplaceConfig(
|
|
541
|
+
use_mech_marketplace=False,
|
|
542
|
+
mech_marketplace_address=ZERO_ADDRESS,
|
|
543
|
+
priority_mech_address=ZERO_ADDRESS,
|
|
544
|
+
priority_mech_service_id=0,
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
target_staking_params = sftxb.get_staking_params(
|
|
548
|
+
staking_contract=get_staking_contract(
|
|
549
|
+
chain=chain,
|
|
550
|
+
staking_program_id=staking_program_id,
|
|
551
|
+
),
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
try:
|
|
555
|
+
# Try if activity checker is a MechActivityChecker contract
|
|
556
|
+
mech_activity_contract = t.cast(
|
|
557
|
+
MechActivityContract,
|
|
558
|
+
MechActivityContract.from_dir(
|
|
559
|
+
directory=str(DATA_DIR / "contracts" / "mech_activity")
|
|
560
|
+
),
|
|
561
|
+
)
|
|
562
|
+
|
|
563
|
+
priority_mech_address = (
|
|
564
|
+
mech_activity_contract.get_instance(
|
|
565
|
+
ledger_api=ledger_api,
|
|
566
|
+
contract_address=target_staking_params["activity_checker"],
|
|
567
|
+
)
|
|
568
|
+
.functions.agentMech()
|
|
569
|
+
.call()
|
|
570
|
+
)
|
|
571
|
+
use_mech_marketplace = False
|
|
572
|
+
mech_marketplace_address = ZERO_ADDRESS
|
|
573
|
+
priority_mech_service_id = 0
|
|
574
|
+
|
|
575
|
+
except Exception: # pylint: disable=broad-except
|
|
576
|
+
# Try if activity checker is a RequesterActivityChecker contract
|
|
577
|
+
try:
|
|
578
|
+
requester_activity_checker = t.cast(
|
|
579
|
+
RequesterActivityCheckerContract,
|
|
580
|
+
RequesterActivityCheckerContract.from_dir(
|
|
581
|
+
directory=str(
|
|
582
|
+
DATA_DIR / "contracts" / "requester_activity_checker"
|
|
583
|
+
)
|
|
584
|
+
),
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
mech_marketplace_address = (
|
|
588
|
+
requester_activity_checker.get_instance(
|
|
589
|
+
ledger_api=ledger_api,
|
|
590
|
+
contract_address=target_staking_params["activity_checker"],
|
|
591
|
+
)
|
|
592
|
+
.functions.mechMarketplace()
|
|
593
|
+
.call()
|
|
594
|
+
)
|
|
595
|
+
|
|
596
|
+
use_mech_marketplace = True
|
|
597
|
+
priority_mech_address, priority_mech_service_id = DEFAULT_PRIORITY_MECH[
|
|
598
|
+
mech_marketplace_address
|
|
599
|
+
]
|
|
600
|
+
|
|
601
|
+
except Exception as e: # pylint: disable=broad-except
|
|
602
|
+
self.logger.error(f"{e}: {traceback.format_exc()}")
|
|
603
|
+
self.logger.warning(
|
|
604
|
+
"Cannot determine type of activity checker contract. Using default parameters. "
|
|
605
|
+
"NOTE: This will be an exception in the future!"
|
|
606
|
+
)
|
|
607
|
+
priority_mech_address = "0x77af31De935740567Cf4fF1986D04B2c964A786a"
|
|
608
|
+
use_mech_marketplace = False
|
|
609
|
+
mech_marketplace_address = ZERO_ADDRESS
|
|
610
|
+
priority_mech_service_id = 0
|
|
611
|
+
|
|
612
|
+
return MechMarketplaceConfig(
|
|
613
|
+
use_mech_marketplace=use_mech_marketplace,
|
|
614
|
+
mech_marketplace_address=mech_marketplace_address,
|
|
615
|
+
priority_mech_address=priority_mech_address,
|
|
616
|
+
priority_mech_service_id=priority_mech_service_id,
|
|
617
|
+
)
|
|
618
|
+
|
|
521
619
|
def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,too-many-locals
|
|
522
620
|
self,
|
|
523
621
|
service_config_id: str,
|
|
@@ -582,73 +680,29 @@ class ServiceManager:
|
|
|
582
680
|
# TODO A customized, arbitrary computation mechanism should be devised.
|
|
583
681
|
env_var_to_value = {}
|
|
584
682
|
if chain == service.home_chain:
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
directory=str(DATA_DIR / "contracts" / "mech_activity")
|
|
591
|
-
),
|
|
592
|
-
)
|
|
593
|
-
|
|
594
|
-
agent_mech = (
|
|
595
|
-
mech_activity_contract.get_instance(
|
|
596
|
-
ledger_api=sftxb.ledger_api,
|
|
597
|
-
contract_address=target_staking_params["activity_checker"],
|
|
598
|
-
)
|
|
599
|
-
.functions.agentMech()
|
|
600
|
-
.call()
|
|
601
|
-
)
|
|
602
|
-
use_mech_marketplace = False
|
|
603
|
-
mech_marketplace_address = ZERO_ADDRESS
|
|
604
|
-
priority_mech_address = ZERO_ADDRESS
|
|
605
|
-
|
|
606
|
-
except Exception: # pylint: disable=broad-except
|
|
607
|
-
# Try if activity checker is a RequesterActivityChecker contract
|
|
608
|
-
try:
|
|
609
|
-
requester_activity_checker = t.cast(
|
|
610
|
-
RequesterActivityCheckerContract,
|
|
611
|
-
RequesterActivityCheckerContract.from_dir(
|
|
612
|
-
directory=str(
|
|
613
|
-
DATA_DIR / "contracts" / "requester_activity_checker"
|
|
614
|
-
)
|
|
615
|
-
),
|
|
616
|
-
)
|
|
617
|
-
|
|
618
|
-
mech_marketplace_address = (
|
|
619
|
-
requester_activity_checker.get_instance(
|
|
620
|
-
ledger_api=sftxb.ledger_api,
|
|
621
|
-
contract_address=target_staking_params["activity_checker"],
|
|
622
|
-
)
|
|
623
|
-
.functions.mechMarketplace()
|
|
624
|
-
.call()
|
|
625
|
-
)
|
|
683
|
+
mech_configs: MechMarketplaceConfig = self.get_mech_configs(
|
|
684
|
+
chain=chain,
|
|
685
|
+
ledger_api=sftxb.ledger_api,
|
|
686
|
+
staking_program_id=user_params.staking_program_id,
|
|
687
|
+
)
|
|
626
688
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
agent_mech = priority_mech_address = service.env_variables[
|
|
636
|
-
"PRIORITY_MECH_ADDRESS"
|
|
637
|
-
]["value"]
|
|
638
|
-
else:
|
|
639
|
-
agent_mech = (
|
|
640
|
-
priority_mech_address
|
|
641
|
-
) = DEFAULT_MECH_MARKETPLACE_PRIORITY_MECH
|
|
689
|
+
if (
|
|
690
|
+
"PRIORITY_MECH_ADDRESS" in service.env_variables
|
|
691
|
+
and service.env_variables["PRIORITY_MECH_ADDRESS"]["provision_type"]
|
|
692
|
+
== ServiceEnvProvisionType.USER
|
|
693
|
+
):
|
|
694
|
+
mech_configs.priority_mech_address = service.env_variables[
|
|
695
|
+
"PRIORITY_MECH_ADDRESS"
|
|
696
|
+
]["value"]
|
|
642
697
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
priority_mech_address = ZERO_ADDRESS
|
|
698
|
+
if (
|
|
699
|
+
"PRIORITY_MECH_SERVICE_ID" in service.env_variables
|
|
700
|
+
and service.env_variables["PRIORITY_MECH_SERVICE_ID"]["provision_type"]
|
|
701
|
+
== ServiceEnvProvisionType.USER
|
|
702
|
+
):
|
|
703
|
+
mech_configs.priority_mech_service_id = service.env_variables[
|
|
704
|
+
"PRIORITY_MECH_SERVICE_ID"
|
|
705
|
+
]["value"]
|
|
652
706
|
|
|
653
707
|
env_var_to_value.update(
|
|
654
708
|
{
|
|
@@ -666,10 +720,10 @@ class ServiceManager:
|
|
|
666
720
|
"staking_contract"
|
|
667
721
|
),
|
|
668
722
|
"MECH_MARKETPLACE_CONFIG": (
|
|
669
|
-
f'{{"mech_marketplace_address":"{mech_marketplace_address}",'
|
|
670
|
-
f'"priority_mech_address":"{priority_mech_address}",'
|
|
723
|
+
f'{{"mech_marketplace_address":"{mech_configs.mech_marketplace_address}",'
|
|
724
|
+
f'"priority_mech_address":"{mech_configs.priority_mech_address}",'
|
|
671
725
|
f'"priority_mech_staking_instance_address":"0x998dEFafD094817EF329f6dc79c703f1CF18bC90",'
|
|
672
|
-
f'"priority_mech_service_id":{
|
|
726
|
+
f'"priority_mech_service_id":{mech_configs.priority_mech_service_id},'
|
|
673
727
|
f'"requester_staking_instance_address":"{target_staking_params.get("staking_contract")}",'
|
|
674
728
|
f'"response_timeout":300}}'
|
|
675
729
|
),
|
|
@@ -679,9 +733,9 @@ class ServiceManager:
|
|
|
679
733
|
"MECH_ACTIVITY_CHECKER_CONTRACT": target_staking_params.get(
|
|
680
734
|
"activity_checker"
|
|
681
735
|
),
|
|
682
|
-
"MECH_CONTRACT_ADDRESS":
|
|
736
|
+
"MECH_CONTRACT_ADDRESS": mech_configs.priority_mech_address,
|
|
683
737
|
"MECH_REQUEST_PRICE": "10000000000000000",
|
|
684
|
-
"USE_MECH_MARKETPLACE": use_mech_marketplace,
|
|
738
|
+
"USE_MECH_MARKETPLACE": mech_configs.use_mech_marketplace,
|
|
685
739
|
}
|
|
686
740
|
)
|
|
687
741
|
|
|
File without changes
|
|
File without changes
|
{olas_operate_middleware-0.6.3.dist-info → olas_operate_middleware-0.8.0.dist-info}/entry_points.txt
RENAMED
|
File without changes
|