From 00e82b0d8205fa330cbe0fd324fef94cc09f61e1 Mon Sep 17 00:00:00 2001 From: KahanMajmudar Date: Tue, 19 Nov 2024 10:36:54 +0000 Subject: [PATCH 1/8] updated default topup values and added required config vars --- run_service.py | 98 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-) diff --git a/run_service.py b/run_service.py index 53db95e..d0520de 100644 --- a/run_service.py +++ b/run_service.py @@ -23,6 +23,7 @@ import os import sys import time +import ast import typing as t from dataclasses import dataclass from pathlib import Path @@ -58,10 +59,10 @@ def unit_to_wei(unit: float) -> int: return int(unit * 1e18) -WALLET_TOPUP = unit_to_wei(0.005) -MASTER_SAFE_TOPUP = unit_to_wei(0.001) -SAFE_TOPUP = unit_to_wei(0.002) -AGENT_TOPUP = unit_to_wei(0.001) +WALLET_TOPUP = unit_to_wei(0.5) +MASTER_SAFE_TOPUP = unit_to_wei(0.5) +SAFE_TOPUP = unit_to_wei(0.5) +AGENT_TOPUP = unit_to_wei(0.5) COST_OF_BOND = 1 @@ -69,14 +70,17 @@ def unit_to_wei(unit: float) -> int: COST_OF_BOND_STAKING = 5 * 10**19 # 50 OLAS WARNING_ICON = colored("\u26A0", "yellow") OPERATE_HOME = Path.cwd() / ".mech_quickstart" +DEFAULT_TOOLS_TO_PACKAGE_HASH = None +DEFAULT_MECH_TO_SUBSCRIPTION = None +DEFAULT_MECH_TO_CONFIG = None CHAIN_ID_TO_METADATA = { 100: { "name": "Gnosis", "token": "xDAI", - "firstTimeTopUp": unit_to_wei(0.001), - "operationalFundReq": unit_to_wei(0.001), + "firstTimeTopUp": unit_to_wei(0.5), + "operationalFundReq": unit_to_wei(0.5), "usdcRequired": False, "gasParams": { # this means default values will be used @@ -137,9 +141,11 @@ class MechQuickstartConfig(LocalResource): path: Path gnosis_rpc: t.Optional[str] = None - password_migrated: t.Optional[bool] = None - use_staking: t.Optional[bool] = None home_chain_id: t.Optional[int] = None + api_keys: t.Optional[dict] = None + tools_to_packages_hash: t.Optional[dict] = None + mech_to_subscription: t.Optional[dict] = None + mech_to_config: t.Optional[dict] = None @classmethod def from_json(cls, obj: t.Dict) -> "LocalResource": @@ -300,8 +306,80 @@ def get_local_config() -> MechQuickstartConfig: f"Please enter a {ChainType.from_id(mech_quickstart_config.home_chain_id).name} RPC URL: " ) - if mech_quickstart_config.password_migrated is None: - mech_quickstart_config.password_migrated = False + if mech_quickstart_config.tools_to_packages_hash is None: + tools_to_packages_hash = ( + input( + f"Do you want to set the tools_to_packages_hash dict(set to {DEFAULT_TOOLS_TO_PACKAGE_HASH})? (y/n): " + ).lower() + == "y" + ) + if tools_to_packages_hash: + while True: + user_input = input(f"Please enter the tools_to_packages_hash dict: ") + tools_to_packages_hash = ast.literal_eval(user_input) + if not isinstance(tools_to_packages_hash, dict): + print("Error: Please enter a valid dict.") + continue + else: + mech_quickstart_config.tools_to_packages_hash = ( + tools_to_packages_hash + ) + break + else: + mech_quickstart_config.tools_to_packages_hash = ( + DEFAULT_TOOLS_TO_PACKAGE_HASH + ) + + if mech_quickstart_config.api_keys is None: + user_input = input(f"Add API keys required to run your tools: ") + while True: + api_keys = ast.literal_eval(user_input) + if not isinstance(api_keys, dict): + print("Error: Please enter a valid dict.") + continue + else: + mech_quickstart_config.api_keys = api_keys + break + + if mech_quickstart_config.mech_to_subscription is None: + mech_to_subscription = ( + input( + f"Do you want to set the mech_to_subscription dict(set to {DEFAULT_MECH_TO_SUBSCRIPTION})? (y/n): " + ).lower() + == "y" + ) + if mech_to_subscription: + while True: + user_input = input(f"Please enter the mech_to_subscription dict: ") + mech_to_subscription = ast.literal_eval(user_input) + if not isinstance(mech_to_subscription, dict): + print("Error: Please enter a valid dict.") + continue + else: + mech_quickstart_config.mech_to_subscription = mech_to_subscription + break + else: + mech_quickstart_config.mech_to_subscription = DEFAULT_MECH_TO_SUBSCRIPTION + + if mech_quickstart_config.mech_to_config is None: + mech_to_config = ( + input( + f"Do you want to set the mech_to_config dict(set to {DEFAULT_MECH_TO_CONFIG})? (y/n): " + ).lower() + == "y" + ) + if mech_to_config: + while True: + user_input = input(f"Please enter the mech_to_config dict: ") + mech_to_config = ast.literal_eval(user_input) + if not isinstance(mech_to_config, dict): + print("Error: Please enter a valid dict.") + continue + else: + mech_quickstart_config.mech_to_config = mech_to_config + break + else: + mech_quickstart_config.mech_to_config = DEFAULT_MECH_TO_CONFIG mech_quickstart_config.store() return mech_quickstart_config From baa305c524b8b00328d82b35cdc521882af0cdd3 Mon Sep 17 00:00:00 2001 From: KahanMajmudar Date: Tue, 19 Nov 2024 10:37:28 +0000 Subject: [PATCH 2/8] removed password migration --- run_service.py | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/run_service.py b/run_service.py index d0520de..243019d 100644 --- a/run_service.py +++ b/run_service.py @@ -392,27 +392,6 @@ def apply_env_vars(env_vars: t.Dict[str, str]) -> None: os.environ[key] = str(value) -def handle_password_migration( - operate: OperateApp, config: MechQuickstartConfig -) -> t.Optional[str]: - """Handle password migration.""" - if not config.password_migrated: - print("Add password...") - old_password, new_password = "12345", ask_confirm_password() - operate.user_account.update(old_password, new_password) - if operate.wallet_manager.exists(LedgerType.ETHEREUM): - operate.password = old_password - wallet = operate.wallet_manager.load(LedgerType.ETHEREUM) - wallet.crypto.dump(str(wallet.key_path), password=new_password) - wallet.password = new_password - wallet.store() - - config.password_migrated = True - config.store() - return new_password - return None - - def get_service_template(config: MechQuickstartConfig) -> ServiceTemplate: """Get the service template""" return ServiceTemplate( @@ -573,15 +552,6 @@ def main() -> None: mech_quickstart_config.password_migrated = True mech_quickstart_config.store() - # Load account - else: - password = handle_password_migration(operate, mech_quickstart_config) - if password is None: - password = getpass.getpass("Enter local user account password: ") - if not operate.user_account.is_valid(password=password): - print("Invalid password!") - sys.exit(1) - operate.password = password # Create the main wallet From 993dc84c8b4ee08a726154f9623480c83fac296c Mon Sep 17 00:00:00 2001 From: KahanMajmudar Date: Tue, 19 Nov 2024 10:43:19 +0000 Subject: [PATCH 3/8] added mech hash as user input --- run_service.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/run_service.py b/run_service.py index 243019d..8a1c3d2 100644 --- a/run_service.py +++ b/run_service.py @@ -73,6 +73,7 @@ def unit_to_wei(unit: float) -> int: DEFAULT_TOOLS_TO_PACKAGE_HASH = None DEFAULT_MECH_TO_SUBSCRIPTION = None DEFAULT_MECH_TO_CONFIG = None +DEFAULT_MECH_HASH = "bafybeiceat2qaz7bqrpgobj3qiubjqyzehydexku2qhe6ob4w2woaehunq" CHAIN_ID_TO_METADATA = { @@ -146,6 +147,7 @@ class MechQuickstartConfig(LocalResource): tools_to_packages_hash: t.Optional[dict] = None mech_to_subscription: t.Optional[dict] = None mech_to_config: t.Optional[dict] = None + mech_hash: t.Optional[str] = None @classmethod def from_json(cls, obj: t.Dict) -> "LocalResource": @@ -381,6 +383,21 @@ def get_local_config() -> MechQuickstartConfig: else: mech_quickstart_config.mech_to_config = DEFAULT_MECH_TO_CONFIG + if mech_quickstart_config.mech_hash is None: + mech_hash = ( + input( + f"Do you want to set the mech_hash dict(set to {DEFAULT_MECH_HASH})? (y/n): " + ).lower() + == "y" + ) + if mech_hash: + while True: + user_input = input(f"Please enter the mech_hash: ") + mech_quickstart_config.mech_hash = user_input + break + else: + mech_quickstart_config.mech_hash = DEFAULT_MECH_HASH + mech_quickstart_config.store() return mech_quickstart_config @@ -397,7 +414,7 @@ def get_service_template(config: MechQuickstartConfig) -> ServiceTemplate: return ServiceTemplate( { "name": "mech_quickstart", - "hash": "bafybeiceat2qaz7bqrpgobj3qiubjqyzehydexku2qhe6ob4w2woaehunq", + "hash": f"{config.mech_hash}", "description": "The mech executes AI tasks requested on-chain and delivers the results to the requester.", "image": "https://gateway.autonolas.tech/ipfs/bafybeidzpenez565d7vp7jexfrwisa2wijzx6vwcffli57buznyyqkrceq", "service_version": "v0.1.0", From aa60284e3e1ceba2db87502ad810a85f1e34d15e Mon Sep 17 00:00:00 2001 From: KahanMajmudar Date: Tue, 19 Nov 2024 10:44:34 +0000 Subject: [PATCH 4/8] added dummy nft ipfs hash --- run_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_service.py b/run_service.py index 8a1c3d2..b7fe40b 100644 --- a/run_service.py +++ b/run_service.py @@ -424,7 +424,7 @@ def get_service_template(config: MechQuickstartConfig) -> ServiceTemplate: { "staking_program_id": "mech_service", "rpc": config.gnosis_rpc, - "nft": "", + "nft": "bafybeiaakdeconw7j5z76fgghfdjmsr6tzejotxcwnvmp3nroaw3glgyve", "cost_of_bond": COST_OF_BOND, "threshold": 1, "use_staking": True, From 6b0aad5ef851817504c21d8a6e8074fe786d2d7a Mon Sep 17 00:00:00 2001 From: KahanMajmudar Date: Tue, 19 Nov 2024 10:46:06 +0000 Subject: [PATCH 5/8] updated staking id from mech_service to mech_marketplace --- run_service.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/run_service.py b/run_service.py index b7fe40b..2d0d5d8 100644 --- a/run_service.py +++ b/run_service.py @@ -422,7 +422,7 @@ def get_service_template(config: MechQuickstartConfig) -> ServiceTemplate: "configurations": { str(config.home_chain_id): ConfigurationTemplate( { - "staking_program_id": "mech_service", + "staking_program_id": "mech_marketplace", "rpc": config.gnosis_rpc, "nft": "bafybeiaakdeconw7j5z76fgghfdjmsr6tzejotxcwnvmp3nroaw3glgyve", "cost_of_bond": COST_OF_BOND, @@ -466,11 +466,13 @@ def get_erc20_balance(ledger_api: LedgerApi, token: str, account: str) -> int: # @note patching operate -> legder -> profiles.py -> staking dict for gnosis -STAKING[ChainType.GNOSIS]["mech_service"] = "0x998dEFafD094817EF329f6dc79c703f1CF18bC90" +STAKING[ChainType.GNOSIS][ + "mech_marketplace" +] = "0x998dEFafD094817EF329f6dc79c703f1CF18bC90" gnosis_staking_fallback = dict( agent_ids=[43], service_registry=CONTRACTS[ChainType.GNOSIS]["service_registry"], # nosec - staking_token=STAKING[ChainType.GNOSIS]["mech_service"], # nosec + staking_token=STAKING[ChainType.GNOSIS]["mech_marketplace"], # nosec service_registry_token_utility=CONTRACTS[ChainType.GNOSIS][ "service_registry_token_utility" ], # nosec @@ -730,7 +732,7 @@ def main() -> None: "RESET_PAUSE_DURATION": 10, "MINIMUM_GAS_BALANCE": 0.02, "DB_PATH": "/logs/mech.db", - "STAKING_TOKEN_CONTRACT_ADDRESS": STAKING[home_chain_type]["mech_service"], + "STAKING_TOKEN_CONTRACT_ADDRESS": STAKING[home_chain_type]["mech_marketplace"], } apply_env_vars(env_vars) From bb2d331236cc3cadb67c128b3623e60a4c70f707 Mon Sep 17 00:00:00 2001 From: KahanMajmudar Date: Tue, 19 Nov 2024 11:02:17 +0000 Subject: [PATCH 6/8] removed gas vars and updated env_vars with required values --- run_service.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/run_service.py b/run_service.py index 2d0d5d8..51aa24e 100644 --- a/run_service.py +++ b/run_service.py @@ -607,10 +607,6 @@ def main() -> None: os.environ["OPEN_AUTONOMY_SUBGRAPH_URL"] = ( "https://subgraph.autonolas.tech/subgraphs/name/autonolas-staging" ) - os.environ["MAX_PRIORITY_FEE_PER_GAS"] = chain_metadata["gasParams"][ - "MAX_PRIORITY_FEE_PER_GAS" - ] - os.environ["MAX_FEE_PER_GAS"] = chain_metadata["gasParams"]["MAX_FEE_PER_GAS"] service_exists = ( manager._get_on_chain_state(chain_config) != OnChainState.NON_EXISTENT ) @@ -733,6 +729,10 @@ def main() -> None: "MINIMUM_GAS_BALANCE": 0.02, "DB_PATH": "/logs/mech.db", "STAKING_TOKEN_CONTRACT_ADDRESS": STAKING[home_chain_type]["mech_marketplace"], + "TOOLS_TO_PACKAGE_HASH": mech_quickstart_config.tools_to_packages_hash, + "API_KEYS": mech_quickstart_config.api_keys, + "MECH_TO_SUBSCRIPTION": mech_quickstart_config.mech_to_subscription, + "MECH_TO_CONFIG": mech_quickstart_config.mech_to_config, } apply_env_vars(env_vars) From 03c3f7e0caea8cbc681c6b20df53b17aa19228d9 Mon Sep 17 00:00:00 2001 From: KahanMajmudar Date: Tue, 19 Nov 2024 15:49:50 +0000 Subject: [PATCH 7/8] updated default mech hash --- run_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_service.py b/run_service.py index 51aa24e..26d6329 100644 --- a/run_service.py +++ b/run_service.py @@ -73,7 +73,7 @@ def unit_to_wei(unit: float) -> int: DEFAULT_TOOLS_TO_PACKAGE_HASH = None DEFAULT_MECH_TO_SUBSCRIPTION = None DEFAULT_MECH_TO_CONFIG = None -DEFAULT_MECH_HASH = "bafybeiceat2qaz7bqrpgobj3qiubjqyzehydexku2qhe6ob4w2woaehunq" +DEFAULT_MECH_HASH = "bafybeibx772eooap6m7cdjwfyt5pespe22i2mva24y255vw22cd5d7bfuq" CHAIN_ID_TO_METADATA = { From 412f3c147f385ad96f1a28a120617bd862d47a02 Mon Sep 17 00:00:00 2001 From: Ardian Date: Wed, 20 Nov 2024 10:28:33 +0100 Subject: [PATCH 8/8] chore: merge errors --- run_service.py | 7 +------ utils.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/run_service.py b/run_service.py index d38b585..e9ebb6b 100644 --- a/run_service.py +++ b/run_service.py @@ -23,7 +23,6 @@ import os import sys import time -import ast import typing as t from dotenv import load_dotenv @@ -54,10 +53,6 @@ COST_OF_BOND = 1 COST_OF_STAKING = 10**20 # 100 OLAS COST_OF_BOND_STAKING = 5 * 10**19 # 50 OLAS -DEFAULT_TOOLS_TO_PACKAGE_HASH = None -DEFAULT_MECH_TO_SUBSCRIPTION = None -DEFAULT_MECH_TO_CONFIG = None -DEFAULT_MECH_HASH = "bafybeibx772eooap6m7cdjwfyt5pespe22i2mva24y255vw22cd5d7bfuq" CHAIN_ID_TO_METADATA = { @@ -95,7 +90,7 @@ def get_service_template(config: MechQuickstartConfig) -> ServiceTemplate: return ServiceTemplate( { "name": "mech_quickstart", - "hash": "bafybeibx772eooap6m7cdjwfyt5pespe22i2mva24y255vw22cd5d7bfuq", + "hash": str(config.mech_hash), "description": "The mech executes AI tasks requested on-chain and delivers the results to the requester.", "image": "https://gateway.autonolas.tech/ipfs/bafybeidzpenez565d7vp7jexfrwisa2wijzx6vwcffli57buznyyqkrceq", "service_version": "v0.1.0", diff --git a/utils.py b/utils.py index b0fa100..5a39e10 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,5 @@ # utils.py +import ast import getpass import json import os @@ -37,6 +38,10 @@ WARNING_ICON = colored("\u26A0", "yellow") OPERATE_HOME = Path.cwd() / ".mech_quickstart" +DEFAULT_TOOLS_TO_PACKAGE_HASH = None +DEFAULT_MECH_TO_SUBSCRIPTION = None +DEFAULT_MECH_TO_CONFIG = None +DEFAULT_MECH_HASH = "bafybeibx772eooap6m7cdjwfyt5pespe22i2mva24y255vw22cd5d7bfuq" @dataclass class MechQuickstartConfig(LocalResource): @@ -50,6 +55,8 @@ class MechQuickstartConfig(LocalResource): metadata_hash: t.Optional[str] = None agent_id: t.Optional[int] = None mech_address: t.Optional[str] = None + tools_to_packages_hash: t.Optional[dict] = None + mech_hash: t.Optional[str] = None home_chain_id: t.Optional[int] = None @classmethod @@ -330,6 +337,46 @@ def get_local_config() -> MechQuickstartConfig: # TODO: default value is not a good idea here, we need to think of better ways to do this. mech_quickstart_config.metadata_hash = input_with_default_value("Please provide the metadata hash", "f01701220caa53607238e340da63b296acab232c18a48e954f0af6ff2b835b2d93f1962f0") + if mech_quickstart_config.tools_to_packages_hash is None: + tools_to_packages_hash = ( + input( + f"Do you want to set the tools_to_packages_hash dict(set to {DEFAULT_TOOLS_TO_PACKAGE_HASH})? (y/n): " + ).lower() + == "y" + ) + if tools_to_packages_hash: + while True: + user_input = input(f"Please enter the tools_to_packages_hash dict: ") + tools_to_packages_hash = ast.literal_eval(user_input) + if not isinstance(tools_to_packages_hash, dict): + print("Error: Please enter a valid dict.") + continue + else: + mech_quickstart_config.tools_to_packages_hash = ( + tools_to_packages_hash + ) + break + else: + mech_quickstart_config.tools_to_packages_hash = ( + DEFAULT_TOOLS_TO_PACKAGE_HASH + ) + + if mech_quickstart_config.mech_hash is None: + mech_hash = ( + input( + f"Do you want to set the mech_hash dict(set to {DEFAULT_MECH_HASH})? (y/n): " + ).lower() + == "y" + ) + if mech_hash: + while True: + user_input = input(f"Please enter the mech_hash: ") + mech_quickstart_config.mech_hash = user_input + break + else: + mech_quickstart_config.mech_hash = DEFAULT_MECH_HASH + + mech_quickstart_config.store() return mech_quickstart_config