From d89d2dd3e0839f3625d2d10e5d88821f4df47348 Mon Sep 17 00:00:00 2001 From: Ardian Date: Tue, 12 Dec 2023 12:39:10 +0100 Subject: [PATCH 1/3] feat: wrap strategies into packages --- .../bet_amount_per_threshold/__init__.py | 20 +++++++++++++++++++ .../bet_amount_per_threshold.py | 0 .../bet_amount_per_threshold/component.yaml | 14 +++++++++++++ strategies/kelly_criterion/__init__.py | 20 +++++++++++++++++++ strategies/kelly_criterion/component.yaml | 14 +++++++++++++ .../{ => kelly_criterion}/kelly_criterion.py | 0 6 files changed, 68 insertions(+) create mode 100644 strategies/bet_amount_per_threshold/__init__.py rename strategies/{ => bet_amount_per_threshold}/bet_amount_per_threshold.py (100%) create mode 100644 strategies/bet_amount_per_threshold/component.yaml create mode 100644 strategies/kelly_criterion/__init__.py create mode 100644 strategies/kelly_criterion/component.yaml rename strategies/{ => kelly_criterion}/kelly_criterion.py (100%) diff --git a/strategies/bet_amount_per_threshold/__init__.py b/strategies/bet_amount_per_threshold/__init__.py new file mode 100644 index 000000000..011d720ed --- /dev/null +++ b/strategies/bet_amount_per_threshold/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2023 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ + +"""This module contains the bet amount per threshold strategy.""" diff --git a/strategies/bet_amount_per_threshold.py b/strategies/bet_amount_per_threshold/bet_amount_per_threshold.py similarity index 100% rename from strategies/bet_amount_per_threshold.py rename to strategies/bet_amount_per_threshold/bet_amount_per_threshold.py diff --git a/strategies/bet_amount_per_threshold/component.yaml b/strategies/bet_amount_per_threshold/component.yaml new file mode 100644 index 000000000..a53c233d4 --- /dev/null +++ b/strategies/bet_amount_per_threshold/component.yaml @@ -0,0 +1,14 @@ +name: bet_amount_per_threshold +author: valory +version: 0.1.0 +type: custom_component +description: A simple strategy that bets a fixed amount when the confidence is of a given threshold. +license: Apache-2.0 +aea_version: '>=1.0.0, <2.0.0' +fingerprint: + __init__.py: bafybeidey4syohls5hxmso6qsp5p4uhtzle5txv2mlbym6ktjzknich6oa + bet_amount_per_threshold.py: bafybeibqwl52cnz64cysjd2jnjijuakdvyrffapxq65cdzx6g65gu42deq +fingerprint_ignore_patterns: [] +entry_point: bet_amount_per_threshold.py +callable: run +dependencies: {} \ No newline at end of file diff --git a/strategies/kelly_criterion/__init__.py b/strategies/kelly_criterion/__init__.py new file mode 100644 index 000000000..f562b286a --- /dev/null +++ b/strategies/kelly_criterion/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2023 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ + +"""This module contains the kelly criterion strategy.""" diff --git a/strategies/kelly_criterion/component.yaml b/strategies/kelly_criterion/component.yaml new file mode 100644 index 000000000..76b67d0f0 --- /dev/null +++ b/strategies/kelly_criterion/component.yaml @@ -0,0 +1,14 @@ +name: kelly_criterion +author: valory +version: 0.1.0 +type: custom_component +description: The kelly criterion trading strategy. +license: Apache-2.0 +aea_version: '>=1.0.0, <2.0.0' +fingerprint: + __init__.py: bafybeidey4syohls5hxmso6qsp5p4uhtzle5txv2mlbym6ktjzknich6oa + kelly_criterion.py: bafybeibqwl52cnz64cysjd2jnjijuakdvyrffapxq65cdzx6g65gu42deq +fingerprint_ignore_patterns: [] +entry_point: kelly_criterion.py +callable: run +dependencies: {} \ No newline at end of file diff --git a/strategies/kelly_criterion.py b/strategies/kelly_criterion/kelly_criterion.py similarity index 100% rename from strategies/kelly_criterion.py rename to strategies/kelly_criterion/kelly_criterion.py From a220379fd999c7090221fda20ccb6f5d55da4608 Mon Sep 17 00:00:00 2001 From: Ardian Date: Tue, 12 Dec 2023 13:26:17 +0100 Subject: [PATCH 2/3] feat: add support for custom packages --- packages/packages.json | 10 +-- packages/valory/agents/trader/aea-config.yaml | 8 +-- packages/valory/services/trader/service.yaml | 10 +-- .../decision_maker_abci/behaviours/base.py | 39 ++++++----- .../behaviours/decision_receive.py | 3 +- .../decision_maker_abci/io_/__init__.py | 19 ++++++ .../skills/decision_maker_abci/io_/loader.py | 67 +++++++++++++++++++ .../skills/decision_maker_abci/models.py | 2 +- .../skills/decision_maker_abci/skill.yaml | 8 ++- packages/valory/skills/trader_abci/skill.yaml | 4 +- .../tx_settlement_multiplexer_abci/skill.yaml | 2 +- 11 files changed, 130 insertions(+), 42 deletions(-) create mode 100644 packages/valory/skills/decision_maker_abci/io_/__init__.py create mode 100644 packages/valory/skills/decision_maker_abci/io_/loader.py diff --git a/packages/packages.json b/packages/packages.json index 201099e08..472cb63f2 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -1,13 +1,13 @@ { "dev": { "skill/valory/market_manager_abci/0.1.0": "bafybeiei62pni5gej5wzf3wp3olwnxxrahqvlnlupedgjwvwgj3v7pnraq", - "skill/valory/decision_maker_abci/0.1.0": "bafybeigp3fmqwfvtrugdoxht3qedmu5rucu6y67s54sjchbhewu57c732q", - "skill/valory/trader_abci/0.1.0": "bafybeiag7fmfecdbiv3gwsqat5ffa7jrkyfx6ffwoqfdkwz7uwqiqjej7a", + "skill/valory/decision_maker_abci/0.1.0": "bafybeidsxaa6q4m3hbapxn5qcsthcsvwmfz6wcmndmn6wdygtzhuz2dbji", + "skill/valory/trader_abci/0.1.0": "bafybeibe33ukc63bltgfq7jvl6pkt2y2mqzzjlrx7clq3vikux4lalq7g4", "contract/valory/market_maker/0.1.0": "bafybeiehszwvmurz5b5vpqbxbvcm5ty4z553jqpsnernqwdq6d62r3z5wa", - "agent/valory/trader/0.1.0": "bafybeifpkxmezym2ow2qj6phc4eflsit5wo4ybjaegjfgm63eu76ev4woa", - "service/valory/trader/0.1.0": "bafybeid25rgsplah773wt5nq3yxxvsmgkcmbyeiys4jnumz4nq4653xpoi", + "agent/valory/trader/0.1.0": "bafybeiaxukjz26nziwuu5pner6kz74z4ielvsdzhytdyzy24zdmiydhzra", + "service/valory/trader/0.1.0": "bafybeid32vs2w4cxjzzvdhotjwqidatqh3j7mg2zahjyckshmj4ixhrvy4", "contract/valory/erc20/0.1.0": "bafybeihisiakfcftxs2hwx7yxzovao4qjuk3kqbzntiekzv5v75vpax3ui", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeig5o6o5u5p2dw5ziwu4irofyoc2xeqactldgvvldhfuw2k6tatijm", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeienit3iphqbll3drqg7ru323kdhajis6assqithasx4cotzjixzfi", "contract/valory/mech/0.1.0": "bafybeigvha4ya64ccjl7tbroa3zjqlxm64wxsqx5k2cz2xs3a7igu5qgxa", "contract/valory/realitio/0.1.0": "bafybeiblpni6gvg6vyw5tsyxwllfitnre7waz6eeoyutt2qmox7zvjat6q", "contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index 2c7d4143c..df526091e 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -43,10 +43,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeidzajbe3erygeh2xbd6lrjv7nsptznjuzrt24ykgvhgotdeyhfnba - valory/termination_abci:0.1.0:bafybeie4zvjfxvdu7qrulmur3chpjz3kpj5m4bjsxvpk4gvj5zbyyayfaa - valory/transaction_settlement_abci:0.1.0:bafybeiaefgqbs7zsn5xe5kdwrujj7ivygkn3ujpw6crnvi3knvxw75qmja -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeig5o6o5u5p2dw5ziwu4irofyoc2xeqactldgvvldhfuw2k6tatijm +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeienit3iphqbll3drqg7ru323kdhajis6assqithasx4cotzjixzfi - valory/market_manager_abci:0.1.0:bafybeiei62pni5gej5wzf3wp3olwnxxrahqvlnlupedgjwvwgj3v7pnraq -- valory/decision_maker_abci:0.1.0:bafybeigp3fmqwfvtrugdoxht3qedmu5rucu6y67s54sjchbhewu57c732q -- valory/trader_abci:0.1.0:bafybeiag7fmfecdbiv3gwsqat5ffa7jrkyfx6ffwoqfdkwz7uwqiqjej7a +- valory/decision_maker_abci:0.1.0:bafybeidsxaa6q4m3hbapxn5qcsthcsvwmfz6wcmndmn6wdygtzhuz2dbji +- valory/trader_abci:0.1.0:bafybeibe33ukc63bltgfq7jvl6pkt2y2mqzzjlrx7clq3vikux4lalq7g4 - valory/staking_abci:0.1.0:bafybeiebu4qeblyjbacjvkiiiorxb4p3yy4nuhvsssgbailmqqtgrhwcca default_ledger: ethereum required_ledgers: @@ -197,7 +197,7 @@ models: refill_check_interval: ${int:10} tool_punishment_multiplier: ${int:1} contract_timeout: ${float:300.0} - file_hash_to_strategies_json: ${list:[["bafybeid6px3gw2c3u7hnsb6p677f4l6gyr3xy7wohafwifzzsnw6dwcp6y",["bet_amount_per_threshold"]],["bafybeiaeazylun25iol746juwtgc4qeuj2rlrtyqhudztpacyybbsgglcy",["kelly_criterion"]]]} + file_hash_to_strategies_json: ${list:[["bafybeifr5cr2pbvhiwpqyqmuh7cfztaph2vzblxan7fclxawndipnehv3i",["bet_amount_per_threshold"]],["bafybeibtutgwddbqr3zneerl6pj5w45a2olmqjafafsg7uyz3pve4zl4qy",["kelly_criterion"]]]} strategies_kwargs: ${list:[["bet_kelly_fraction",0.25],["floor_balance",500000000000000000],["bet_amount_per_threshold",{"0.0":0,"0.1":0,"0.2":0,"0.3":0,"0.4":0,"0.5":0,"0.6":60000000000000000,"0.7":90000000000000000,"0.8":100000000000000000,"0.9":1000000000000000000,"1.0":10000000000000000000}]]} --- public_id: valory/p2p_libp2p_client:0.1.0 diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index cd8d526b6..0a831b70f 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeifpkxmezym2ow2qj6phc4eflsit5wo4ybjaegjfgm63eu76ev4woa +agent: valory/trader:0.1.0:bafybeiaxukjz26nziwuu5pner6kz74z4ielvsdzhytdyzy24zdmiydhzra number_of_agents: 4 deployment: {} --- @@ -110,7 +110,7 @@ type: skill tool_punishment_multiplier: ${TOOL_PUNISHMENT_MULTIPLIER:int:1} redeem_round_timeout: ${REDEEM_ROUND_TIMEOUT:float:3600.0} contract_timeout: ${CONTRACT_TIMEOUT:float:300.0} - file_hash_to_strategies_json: ${FILE_HASH_TO_STRATEGIES_JSON:list:[["bafybeid6px3gw2c3u7hnsb6p677f4l6gyr3xy7wohafwifzzsnw6dwcp6y",["bet_amount_per_threshold"]],["bafybeiaeazylun25iol746juwtgc4qeuj2rlrtyqhudztpacyybbsgglcy",["kelly_criterion"]]]} + file_hash_to_strategies_json: ${FILE_HASH_TO_STRATEGIES_JSON:list:[["bafybeifr5cr2pbvhiwpqyqmuh7cfztaph2vzblxan7fclxawndipnehv3i",["bet_amount_per_threshold"]],["bafybeibtutgwddbqr3zneerl6pj5w45a2olmqjafafsg7uyz3pve4zl4qy",["kelly_criterion"]]]} strategies_kwargs: ${STRATEGIES_KWARGS:list:[["bet_kelly_fraction",0.25],["floor_balance",500000000000000000],["bet_amount_per_threshold",{"0.0":0,"0.1":0,"0.2":0,"0.3":0,"0.4":0,"0.5":0,"0.6":60000000000000000,"0.7":90000000000000000,"0.8":100000000000000000,"0.9":1000000000000000000,"1.0":10000000000000000000}]]} use_subgraph_for_redeeming: ${USE_SUBGRAPH_FOR_REDEEMING:bool:true} benchmark_tool: &id004 @@ -194,7 +194,7 @@ type: skill tool_punishment_multiplier: ${TOOL_PUNISHMENT_MULTIPLIER:int:1} redeem_round_timeout: ${REDEEM_ROUND_TIMEOUT:float:3600.0} contract_timeout: ${CONTRACT_TIMEOUT:float:300.0} - file_hash_to_strategies_json: ${FILE_HASH_TO_STRATEGIES_JSON:list:[["bafybeid6px3gw2c3u7hnsb6p677f4l6gyr3xy7wohafwifzzsnw6dwcp6y",["bet_amount_per_threshold"]],["bafybeiaeazylun25iol746juwtgc4qeuj2rlrtyqhudztpacyybbsgglcy",["kelly_criterion"]]]} + file_hash_to_strategies_json: ${FILE_HASH_TO_STRATEGIES_JSON:list:[["bafybeifr5cr2pbvhiwpqyqmuh7cfztaph2vzblxan7fclxawndipnehv3i",["bet_amount_per_threshold"]],["bafybeibtutgwddbqr3zneerl6pj5w45a2olmqjafafsg7uyz3pve4zl4qy",["kelly_criterion"]]]} strategies_kwargs: ${STRATEGIES_KWARGS:list:[["bet_kelly_fraction",0.25],["floor_balance",500000000000000000],["bet_amount_per_threshold",{"0.0":0,"0.1":0,"0.2":0,"0.3":0,"0.4":0,"0.5":0,"0.6":60000000000000000,"0.7":90000000000000000,"0.8":100000000000000000,"0.9":1000000000000000000,"1.0":10000000000000000000}]]} use_subgraph_for_redeeming: ${USE_SUBGRAPH_FOR_REDEEMING:bool:true} benchmark_tool: *id004 @@ -276,7 +276,7 @@ type: skill tool_punishment_multiplier: ${TOOL_PUNISHMENT_MULTIPLIER:int:1} redeem_round_timeout: ${REDEEM_ROUND_TIMEOUT:float:3600.0} contract_timeout: ${CONTRACT_TIMEOUT:float:300.0} - file_hash_to_strategies_json: ${FILE_HASH_TO_STRATEGIES_JSON:list:[["bafybeid6px3gw2c3u7hnsb6p677f4l6gyr3xy7wohafwifzzsnw6dwcp6y",["bet_amount_per_threshold"]],["bafybeiaeazylun25iol746juwtgc4qeuj2rlrtyqhudztpacyybbsgglcy",["kelly_criterion"]]]} + file_hash_to_strategies_json: ${FILE_HASH_TO_STRATEGIES_JSON:list:[["bafybeifr5cr2pbvhiwpqyqmuh7cfztaph2vzblxan7fclxawndipnehv3i",["bet_amount_per_threshold"]],["bafybeibtutgwddbqr3zneerl6pj5w45a2olmqjafafsg7uyz3pve4zl4qy",["kelly_criterion"]]]} strategies_kwargs: ${STRATEGIES_KWARGS:list:[["bet_kelly_fraction",0.25],["floor_balance",500000000000000000],["bet_amount_per_threshold",{"0.0":0,"0.1":0,"0.2":0,"0.3":0,"0.4":0,"0.5":0,"0.6":60000000000000000,"0.7":90000000000000000,"0.8":100000000000000000,"0.9":1000000000000000000,"1.0":10000000000000000000}]]} use_subgraph_for_redeeming: ${USE_SUBGRAPH_FOR_REDEEMING:bool:true} benchmark_tool: *id004 @@ -358,7 +358,7 @@ type: skill tool_punishment_multiplier: ${TOOL_PUNISHMENT_MULTIPLIER:int:1} redeem_round_timeout: ${REDEEM_ROUND_TIMEOUT:float:3600.0} contract_timeout: ${CONTRACT_TIMEOUT:float:300.0} - file_hash_to_strategies_json: ${FILE_HASH_TO_STRATEGIES_JSON:list:[["bafybeid6px3gw2c3u7hnsb6p677f4l6gyr3xy7wohafwifzzsnw6dwcp6y",["bet_amount_per_threshold"]],["bafybeiaeazylun25iol746juwtgc4qeuj2rlrtyqhudztpacyybbsgglcy",["kelly_criterion"]]]} + file_hash_to_strategies_json: ${FILE_HASH_TO_STRATEGIES_JSON:list:[["bafybeifr5cr2pbvhiwpqyqmuh7cfztaph2vzblxan7fclxawndipnehv3i",["bet_amount_per_threshold"]],["bafybeibtutgwddbqr3zneerl6pj5w45a2olmqjafafsg7uyz3pve4zl4qy",["kelly_criterion"]]]} strategies_kwargs: ${STRATEGIES_KWARGS:list:[["bet_kelly_fraction",0.25],["floor_balance",500000000000000000],["bet_amount_per_threshold",{"0.0":0,"0.1":0,"0.2":0,"0.3":0,"0.4":0,"0.5":0,"0.6":60000000000000000,"0.7":90000000000000000,"0.8":100000000000000000,"0.9":1000000000000000000,"1.0":10000000000000000000}]]} use_subgraph_for_redeeming: ${USE_SUBGRAPH_FOR_REDEEMING:bool:true} benchmark_tool: *id004 diff --git a/packages/valory/skills/decision_maker_abci/behaviours/base.py b/packages/valory/skills/decision_maker_abci/behaviours/base.py index 65b7421ae..cd6f5fd24 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/base.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/base.py @@ -22,7 +22,7 @@ import dataclasses from abc import ABC from datetime import datetime, timedelta -from typing import Any, Callable, Dict, Generator, List, Optional, Set, cast +from typing import Any, Callable, Dict, Generator, List, Optional, Set, Tuple, cast from aea.configurations.data_types import PublicId from aea.protocols.base import Message @@ -42,6 +42,7 @@ BaseBehaviour, TimeoutException, ) +from packages.valory.skills.decision_maker_abci.io_.loader import ComponentPackageLoader from packages.valory.skills.decision_maker_abci.models import ( DecisionMakerParams, MultisendBatch, @@ -64,7 +65,6 @@ SAFE_GAS = 0 CID_PREFIX = "f01701220" WXDAI = "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d" -STRATEGY_RUN_METHOD = "run" BET_AMOUNT_FIELD = "bet_amount" SUPPORTED_STRATEGY_LOG_LEVELS = ("info", "warning", "error") @@ -91,32 +91,33 @@ def __init__(self, **kwargs: Any) -> None: self._policy: Optional[EGreedyPolicy] = None self._inflight_strategy_req: Optional[str] = None - def strategy_exec(self, strategy: str) -> Optional[str]: + def strategy_exec(self, strategy: str) -> Optional[Tuple[str, str]]: """Get the executable strategy file's content.""" return self.shared_state.strategies_executables.get(strategy, None) def execute_strategy(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: """Execute the strategy and return the results.""" - if STRATEGY_RUN_METHOD in globals(): - del globals()[STRATEGY_RUN_METHOD] - trading_strategy = kwargs.pop("trading_strategy", None) if trading_strategy is None: self.context.logger.error(f"No {trading_strategy!r} was given!") return {BET_AMOUNT_FIELD: 0} - strategy_exec = self.strategy_exec(trading_strategy) - if strategy_exec is None: + strategy = self.strategy_exec(trading_strategy) + if strategy is None: self.context.logger.error( f"No executable was found for {trading_strategy=}!" ) return {BET_AMOUNT_FIELD: 0} + strategy_exec, callable_method = strategy + if callable_method in globals(): + del globals()[callable_method] + exec(strategy_exec, globals()) # pylint: disable=W0122 # nosec - method = globals().get(STRATEGY_RUN_METHOD, None) + method = globals().get(callable_method, None) if method is None: self.context.logger.error( - f"No {STRATEGY_RUN_METHOD!r} method was found in {trading_strategy} strategy's executable." + f"No {callable_method!r} method was found in {trading_strategy} strategy's executable." ) return {BET_AMOUNT_FIELD: 0} @@ -269,17 +270,15 @@ def _handle_get_strategy(self, message: IpfsMessage, _: Dialogue) -> None: self.context.logger.error(f"No strategy request to handle for {message=}.") return - files = list(message.files.values()) - n_files = len(files) - if n_files != 1: - self.context.logger.error( - f"Executables for strategies should be in single files. " - f"Found {n_files} files for strategy {strategy_req} instead." - ) - # store the executable and remove the hash from the mapping because we have downloaded it - strategy_exec = files[0] - self.shared_state.strategies_executables[strategy_req] = strategy_exec + _component_yaml, strategy_exec, callable_method = ComponentPackageLoader.load( + message.files + ) + + self.shared_state.strategies_executables[strategy_req] = ( + strategy_exec, + callable_method, + ) self.shared_state.strategy_to_filehash.pop(strategy_req) self._inflight_strategy_req = None diff --git a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py index 482826ca8..9be04bc3c 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py @@ -31,6 +31,7 @@ WaitableConditionType, remove_fraction_wei, ) +from packages.valory.skills.decision_maker_abci.io_.loader import ComponentPackageLoader from packages.valory.skills.decision_maker_abci.models import ( MechInteractionResponse, MechResponseSpecs, @@ -53,7 +54,7 @@ class DecisionReceiveBehaviour(DecisionMakerBaseBehaviour): def __init__(self, **kwargs: Any) -> None: """Initialize Behaviour.""" - super().__init__(**kwargs) + super().__init__(**kwargs, loader_cls=ComponentPackageLoader) self._from_block: int = 0 self._request_id: int = 0 self._response_hex: str = "" diff --git a/packages/valory/skills/decision_maker_abci/io_/__init__.py b/packages/valory/skills/decision_maker_abci/io_/__init__.py new file mode 100644 index 000000000..fd05584d0 --- /dev/null +++ b/packages/valory/skills/decision_maker_abci/io_/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2023 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ +"""This module contains helper classes for IPFS interaction.""" diff --git a/packages/valory/skills/decision_maker_abci/io_/loader.py b/packages/valory/skills/decision_maker_abci/io_/loader.py new file mode 100644 index 000000000..ebb501cb4 --- /dev/null +++ b/packages/valory/skills/decision_maker_abci/io_/loader.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2023 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ +"""This module contains helper classes for IPFS interaction.""" +from typing import Dict + +import yaml + +from packages.valory.skills.abstract_round_abci.io_.store import SupportedObjectType + + +class ComponentPackageLoader: + """Component package loader.""" + + @staticmethod + def load(serialized_objects: Dict[str, str]) -> SupportedObjectType: + """ + Load a custom component package. + + :param serialized_objects: the serialized objects. + :return: the component.yaml, entry_point.py and callable as tuple. + """ + # the package MUST contain a component.yaml file + if "component.yaml" not in serialized_objects: + raise ValueError( + "Invalid component package. " + "The package MUST contain a component.yaml." + ) + + # load the component.yaml file + component_yaml = yaml.safe_load(serialized_objects["component.yaml"]) + if "entry_point" not in component_yaml or "callable" not in component_yaml: + raise ValueError( + "Invalid component package. " + "The component.yaml file MUST contain the 'entry_point' and 'callable' keys." + ) + + # the name of the script that needs to be executed + entry_point_name = component_yaml["entry_point"] + + # load the script + if entry_point_name not in serialized_objects: + raise ValueError( + f"Invalid component package. " + f"{entry_point_name} is not present in the component package." + ) + entry_point = serialized_objects[entry_point_name] + + # the method that needs to be called + callable_method = component_yaml["callable"] + + return component_yaml, entry_point, callable_method diff --git a/packages/valory/skills/decision_maker_abci/models.py b/packages/valory/skills/decision_maker_abci/models.py index 7b11819a2..fa351eb3f 100644 --- a/packages/valory/skills/decision_maker_abci/models.py +++ b/packages/valory/skills/decision_maker_abci/models.py @@ -154,7 +154,7 @@ def __init__(self, *args: Any, skill_context: SkillContext, **kwargs: Any) -> No super().__init__(*args, skill_context=skill_context, **kwargs) self.redeeming_progress: RedeemingProgress = RedeemingProgress() self.strategy_to_filehash: Dict[str, str] = {} - self.strategies_executables: Dict[str, str] = {} + self.strategies_executables: Dict[str, Tuple[str, str]] = {} self.in_flight_req: bool = False self.req_to_callback: Dict[str, Callable] = {} diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index 5fd6c1b1d..9370cd129 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -12,10 +12,10 @@ fingerprint: README.md: bafybeia367zzdwndvlhw27rvnwodytjo3ms7gbc3q7mhrrjqjgfasnk47i __init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky - behaviours/base.py: bafybeicquqakzxhnweowmxrd3wmnamknigpplfv5s53ofubpr3ltqct7yi + behaviours/base.py: bafybeialr3zhwjenpwp6tu74olnzghtzmuofymidhwekkvhe7uskwczrii behaviours/bet_placement.py: bafybeigtz4uimsqjjwq4r5p3a5v6niqdtqezbuf2ghy6o7syhsh4k5gjfa behaviours/blacklisting.py: bafybeierwdzn6vav54l6zym77hhx2vdx3jtnnwpbhwmwwyrqzncwjwkxu4 - behaviours/decision_receive.py: bafybeigswz7g37c7wt2fvuseiisagauzeba2hwwuhz32qarxxpi54oyo5y + behaviours/decision_receive.py: bafybeidvae35fzdmf2hvn3lqkc67zgjy5enu3vi3z5duomlqmf2v4zvxza behaviours/decision_request.py: bafybeidhmhjxt5xjhznxchqqqh6ohdssyyyzuqxv6dfdvpza7c2bxigajq behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm behaviours/reedem.py: bafybeiajaxrmyogqtvm4pjm6muyktehpfbrlslmorciv254nh23yzkbyqq @@ -25,7 +25,9 @@ fingerprint: dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm fsm_specification.yaml: bafybeidqrxj3l3e555znk4wxx6spwaijz3bhc5yialhzbhd6ngk52w7jbq handlers.py: bafybeiggoetspwcvdojmbjdd67tmkoeedikmt6vsbcium3zjaljb6jzqu4 - models.py: bafybeifvtsqmkz4br5mhvckxdbesmf7tmrzmgxuk2qa6w4wlrawrcl7rfe + io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq + io_/loader.py: bafybeih3sdsx5dhe4kzhtoafexjgkutsujwqy3zcdrlrkhtdks45bc7exa + models.py: bafybeif63pruksc6fpvmg77jmsrphc36uiawypzzcrk6nbpzoglbpxnlfy payloads.py: bafybeigcic4vewdglakzpyqevhfwsolh4ywnbvxo5bgned7gl5uo3jif7m policy.py: bafybeidpmx4ek3qze63zpuwixyf6t7bdv62ewgkzt3ljrzadiwdw64cueq redeem_info.py: bafybeibddfxwp3577c3dl2utaowwltquu5fg6crezpumoebw563wxpbfrm diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index fce951b35..34bac356c 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -25,8 +25,8 @@ skills: - valory/transaction_settlement_abci:0.1.0:bafybeiaefgqbs7zsn5xe5kdwrujj7ivygkn3ujpw6crnvi3knvxw75qmja - valory/termination_abci:0.1.0:bafybeie4zvjfxvdu7qrulmur3chpjz3kpj5m4bjsxvpk4gvj5zbyyayfaa - valory/market_manager_abci:0.1.0:bafybeiei62pni5gej5wzf3wp3olwnxxrahqvlnlupedgjwvwgj3v7pnraq -- valory/decision_maker_abci:0.1.0:bafybeigp3fmqwfvtrugdoxht3qedmu5rucu6y67s54sjchbhewu57c732q -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeig5o6o5u5p2dw5ziwu4irofyoc2xeqactldgvvldhfuw2k6tatijm +- valory/decision_maker_abci:0.1.0:bafybeidsxaa6q4m3hbapxn5qcsthcsvwmfz6wcmndmn6wdygtzhuz2dbji +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeienit3iphqbll3drqg7ru323kdhajis6assqithasx4cotzjixzfi - valory/staking_abci:0.1.0:bafybeiebu4qeblyjbacjvkiiiorxb4p3yy4nuhvsssgbailmqqtgrhwcca behaviours: main: diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index 1f89e0a22..09c1fa024 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -21,7 +21,7 @@ protocols: - valory/ledger_api:1.0.0:bafybeige5agrztgzfevyglf7mb4o7pzfttmq4f6zi765y4g2zvftbyowru skills: - valory/abstract_round_abci:0.1.0:bafybeiaqcl7h2famylusiffigwem7tevkcsyocdu5xd42jkmgq6kvowzgq -- valory/decision_maker_abci:0.1.0:bafybeigp3fmqwfvtrugdoxht3qedmu5rucu6y67s54sjchbhewu57c732q +- valory/decision_maker_abci:0.1.0:bafybeidsxaa6q4m3hbapxn5qcsthcsvwmfz6wcmndmn6wdygtzhuz2dbji - valory/staking_abci:0.1.0:bafybeiebu4qeblyjbacjvkiiiorxb4p3yy4nuhvsssgbailmqqtgrhwcca behaviours: main: From b0c3fd97710b9f449f312d99e316f3a91fc7325f Mon Sep 17 00:00:00 2001 From: Ardian Date: Tue, 12 Dec 2023 13:34:46 +0100 Subject: [PATCH 3/3] fix: add pyyaml as dep of `decision_maker_abci` --- packages/packages.json | 10 +++++----- packages/valory/agents/trader/aea-config.yaml | 6 +++--- packages/valory/services/trader/service.yaml | 2 +- packages/valory/skills/decision_maker_abci/skill.yaml | 2 ++ packages/valory/skills/trader_abci/skill.yaml | 4 ++-- .../skills/tx_settlement_multiplexer_abci/skill.yaml | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index 472cb63f2..41d48414f 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -1,13 +1,13 @@ { "dev": { "skill/valory/market_manager_abci/0.1.0": "bafybeiei62pni5gej5wzf3wp3olwnxxrahqvlnlupedgjwvwgj3v7pnraq", - "skill/valory/decision_maker_abci/0.1.0": "bafybeidsxaa6q4m3hbapxn5qcsthcsvwmfz6wcmndmn6wdygtzhuz2dbji", - "skill/valory/trader_abci/0.1.0": "bafybeibe33ukc63bltgfq7jvl6pkt2y2mqzzjlrx7clq3vikux4lalq7g4", + "skill/valory/decision_maker_abci/0.1.0": "bafybeihpno55l2qntzgxg4nkjlig5lcnnmwdkpy3udkdjwtsmyscvnxini", + "skill/valory/trader_abci/0.1.0": "bafybeifmqlvqhsiqhhq3udlgqwzpzlxb7yq4obnpwjpnnroxgzh3tocapm", "contract/valory/market_maker/0.1.0": "bafybeiehszwvmurz5b5vpqbxbvcm5ty4z553jqpsnernqwdq6d62r3z5wa", - "agent/valory/trader/0.1.0": "bafybeiaxukjz26nziwuu5pner6kz74z4ielvsdzhytdyzy24zdmiydhzra", - "service/valory/trader/0.1.0": "bafybeid32vs2w4cxjzzvdhotjwqidatqh3j7mg2zahjyckshmj4ixhrvy4", + "agent/valory/trader/0.1.0": "bafybeifj7aod2vc4ra7gsldsr5gdyy4by7v5cu3qq2m6rgcupp3icze2dm", + "service/valory/trader/0.1.0": "bafybeibpigtkpc7riys7m2g2v7surmyfcr3u2ukuahcdhmroodvz23feze", "contract/valory/erc20/0.1.0": "bafybeihisiakfcftxs2hwx7yxzovao4qjuk3kqbzntiekzv5v75vpax3ui", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeienit3iphqbll3drqg7ru323kdhajis6assqithasx4cotzjixzfi", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeib3rfkqpers7wrlunrifoeecz4rglhj7t6ggv23tpzq7j6wmjj24e", "contract/valory/mech/0.1.0": "bafybeigvha4ya64ccjl7tbroa3zjqlxm64wxsqx5k2cz2xs3a7igu5qgxa", "contract/valory/realitio/0.1.0": "bafybeiblpni6gvg6vyw5tsyxwllfitnre7waz6eeoyutt2qmox7zvjat6q", "contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index df526091e..e6f995b02 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -43,10 +43,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeidzajbe3erygeh2xbd6lrjv7nsptznjuzrt24ykgvhgotdeyhfnba - valory/termination_abci:0.1.0:bafybeie4zvjfxvdu7qrulmur3chpjz3kpj5m4bjsxvpk4gvj5zbyyayfaa - valory/transaction_settlement_abci:0.1.0:bafybeiaefgqbs7zsn5xe5kdwrujj7ivygkn3ujpw6crnvi3knvxw75qmja -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeienit3iphqbll3drqg7ru323kdhajis6assqithasx4cotzjixzfi +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeib3rfkqpers7wrlunrifoeecz4rglhj7t6ggv23tpzq7j6wmjj24e - valory/market_manager_abci:0.1.0:bafybeiei62pni5gej5wzf3wp3olwnxxrahqvlnlupedgjwvwgj3v7pnraq -- valory/decision_maker_abci:0.1.0:bafybeidsxaa6q4m3hbapxn5qcsthcsvwmfz6wcmndmn6wdygtzhuz2dbji -- valory/trader_abci:0.1.0:bafybeibe33ukc63bltgfq7jvl6pkt2y2mqzzjlrx7clq3vikux4lalq7g4 +- valory/decision_maker_abci:0.1.0:bafybeihpno55l2qntzgxg4nkjlig5lcnnmwdkpy3udkdjwtsmyscvnxini +- valory/trader_abci:0.1.0:bafybeifmqlvqhsiqhhq3udlgqwzpzlxb7yq4obnpwjpnnroxgzh3tocapm - valory/staking_abci:0.1.0:bafybeiebu4qeblyjbacjvkiiiorxb4p3yy4nuhvsssgbailmqqtgrhwcca default_ledger: ethereum required_ledgers: diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 0a831b70f..356894c11 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeiaxukjz26nziwuu5pner6kz74z4ielvsdzhytdyzy24zdmiydhzra +agent: valory/trader:0.1.0:bafybeifj7aod2vc4ra7gsldsr5gdyy4by7v5cu3qq2m6rgcupp3icze2dm number_of_agents: 4 deployment: {} --- diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index 9370cd129..28518e50a 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -307,4 +307,6 @@ dependencies: version: ==0.2.1 web3: version: <7,>=6.0.0 + pyyaml: + version: <=6.0.1,>=3.10 is_abstract: true diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 34bac356c..95ce670a0 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -25,8 +25,8 @@ skills: - valory/transaction_settlement_abci:0.1.0:bafybeiaefgqbs7zsn5xe5kdwrujj7ivygkn3ujpw6crnvi3knvxw75qmja - valory/termination_abci:0.1.0:bafybeie4zvjfxvdu7qrulmur3chpjz3kpj5m4bjsxvpk4gvj5zbyyayfaa - valory/market_manager_abci:0.1.0:bafybeiei62pni5gej5wzf3wp3olwnxxrahqvlnlupedgjwvwgj3v7pnraq -- valory/decision_maker_abci:0.1.0:bafybeidsxaa6q4m3hbapxn5qcsthcsvwmfz6wcmndmn6wdygtzhuz2dbji -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeienit3iphqbll3drqg7ru323kdhajis6assqithasx4cotzjixzfi +- valory/decision_maker_abci:0.1.0:bafybeihpno55l2qntzgxg4nkjlig5lcnnmwdkpy3udkdjwtsmyscvnxini +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeib3rfkqpers7wrlunrifoeecz4rglhj7t6ggv23tpzq7j6wmjj24e - valory/staking_abci:0.1.0:bafybeiebu4qeblyjbacjvkiiiorxb4p3yy4nuhvsssgbailmqqtgrhwcca behaviours: main: diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index 09c1fa024..9f0d894ae 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -21,7 +21,7 @@ protocols: - valory/ledger_api:1.0.0:bafybeige5agrztgzfevyglf7mb4o7pzfttmq4f6zi765y4g2zvftbyowru skills: - valory/abstract_round_abci:0.1.0:bafybeiaqcl7h2famylusiffigwem7tevkcsyocdu5xd42jkmgq6kvowzgq -- valory/decision_maker_abci:0.1.0:bafybeidsxaa6q4m3hbapxn5qcsthcsvwmfz6wcmndmn6wdygtzhuz2dbji +- valory/decision_maker_abci:0.1.0:bafybeihpno55l2qntzgxg4nkjlig5lcnnmwdkpy3udkdjwtsmyscvnxini - valory/staking_abci:0.1.0:bafybeiebu4qeblyjbacjvkiiiorxb4p3yy4nuhvsssgbailmqqtgrhwcca behaviours: main: