From e5f27ed372f49aedeb55052582b2ce78dda41386 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 11 Jul 2023 09:40:23 +0300 Subject: [PATCH 1/7] docs: correct the `_prepare_safe_tx` method's docstring --- .../skills/decision_maker_abci/behaviours/bet_placement.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py index 087716a8..e4a8bb4b 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py @@ -197,12 +197,7 @@ def wait_for_condition_with_sleep( yield from self.sleep(self.params.sleep_time) def _prepare_safe_tx(self) -> Generator[None, None, str]: - """ - Sample a bet and return its id. - - The sampling logic is relatively simple at the moment - It simply selects the unprocessed bet with the largest liquidity. - """ + """Prepare the safe transaction for placing a bet and return the hex for the tx settlement skill.""" for step in ( self._calc_buy_amount, self._get_buy_data, From 9fe51f8e300282c451c09a4961e997ac4d007c7f Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 11 Jul 2023 09:43:27 +0300 Subject: [PATCH 2/7] style: rename gens to more accurately convey their purpose --- .../behaviours/bet_placement.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py index e4a8bb4b..140f8b8d 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py @@ -102,7 +102,7 @@ def _calc_buy_amount(self) -> Generator[None, None, bool]: self.buy_amount = buy_amount return True - def _get_buy_data(self) -> Generator[None, None, bool]: + def _build_buy_data(self) -> Generator[None, None, bool]: """Get the buy tx data encoded.""" response_msg = yield from self.get_contract_api_response( performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore @@ -129,12 +129,8 @@ def _get_buy_data(self) -> Generator[None, None, bool]: self.buy_data = buy_data return True - def _get_safe_tx_hash(self) -> Generator[None, None, bool]: - """ - Prepares and returns the safe tx hash. - - :return: the tx hash - """ + def _build_safe_tx_hash(self) -> Generator[None, None, bool]: + """Prepares and returns the safe tx hash.""" response_msg = yield from self.get_contract_api_response( performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore contract_address=self.synchronized_data.safe_contract_address, @@ -200,8 +196,8 @@ def _prepare_safe_tx(self) -> Generator[None, None, str]: """Prepare the safe transaction for placing a bet and return the hex for the tx settlement skill.""" for step in ( self._calc_buy_amount, - self._get_buy_data, - self._get_safe_tx_hash, + self._build_buy_data, + self._build_safe_tx_hash, ): yield from self.wait_for_condition_with_sleep(step) From 49a84ac6fc35bdafb8f607204a01fc8e98592737 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 11 Jul 2023 09:43:59 +0300 Subject: [PATCH 3/7] style: do not create alias --- packages/valory/skills/decision_maker_abci/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/models.py b/packages/valory/skills/decision_maker_abci/models.py index 597239b0..eb5ca0b7 100644 --- a/packages/valory/skills/decision_maker_abci/models.py +++ b/packages/valory/skills/decision_maker_abci/models.py @@ -29,9 +29,7 @@ SharedState as BaseSharedState, ) from packages.valory.skills.decision_maker_abci.rounds import DecisionMakerAbciApp -from packages.valory.skills.market_manager_abci.models import ( - MarketManagerParams as BaseParams, -) +from packages.valory.skills.market_manager_abci.models import MarketManagerParams Requests = BaseRequests @@ -44,7 +42,7 @@ class SharedState(BaseSharedState): abci_app_cls = DecisionMakerAbciApp -class DecisionMakerParams(BaseParams): +class DecisionMakerParams(MarketManagerParams): """Decision maker's parameters.""" def __init__(self, *args: Any, **kwargs: Any) -> None: From 8548394889c11ed473089d30bdf16e655f63fc31 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 11 Jul 2023 09:44:37 +0300 Subject: [PATCH 4/7] docs: add missing `:return:` --- .../valory/skills/decision_maker_abci/behaviours/sampling.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/sampling.py b/packages/valory/skills/decision_maker_abci/behaviours/sampling.py index 0c6991ee..6a57e2fd 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/sampling.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/sampling.py @@ -47,6 +47,8 @@ def sampled_bet_idx(self) -> int: The sampling logic is relatively simple at the moment It simply selects the unprocessed bet with the largest liquidity. + + :return: the id of the sampled bet. """ max_lq = max(self.available_bets, key=lambda bet: bet.usdLiquidityMeasure) return self.synchronized_data.bets.index(max_lq) From 47666b0abb1796dfb97de98d2b07bd70d66fd069 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 11 Jul 2023 09:45:04 +0300 Subject: [PATCH 5/7] style: remove unnecessary configurations --- .../valory/skills/market_manager_abci/skill.yaml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/packages/valory/skills/market_manager_abci/skill.yaml b/packages/valory/skills/market_manager_abci/skill.yaml index 3363b960..11dd6845 100644 --- a/packages/valory/skills/market_manager_abci/skill.yaml +++ b/packages/valory/skills/market_manager_abci/skill.yaml @@ -119,17 +119,6 @@ models: opening_margin: 300 languages: [en_US] class_name: MarketManagerParams - randomness_api: - args: - api_id: cloudflare - headers: {} - method: GET - parameters: {} - response_key: null - response_type: dict - retries: 5 - url: https://drand.cloudflare.com/public/latest - class_name: RandomnessApi omen_subgraph: args: api_id: omen @@ -151,7 +140,5 @@ models: state: args: {} class_name: SharedState -dependencies: - open-aea-test-autonomy: - version: ==0.10.7 +dependencies: {} is_abstract: true From c8e9e4d02e8c018ef179c41731651c76df7d0cf6 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 11 Jul 2023 09:46:10 +0300 Subject: [PATCH 6/7] fix: replace unused specs with required omen subgraph specs --- packages/valory/skills/market_manager_abci/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/valory/skills/market_manager_abci/models.py b/packages/valory/skills/market_manager_abci/models.py index ee4797bb..e62ab7a6 100644 --- a/packages/valory/skills/market_manager_abci/models.py +++ b/packages/valory/skills/market_manager_abci/models.py @@ -44,8 +44,8 @@ class SharedState(BaseSharedState): abci_app_cls = MarketManagerAbciApp -class RandomnessApi(ApiSpecs): - """A model that wraps ApiSpecs for randomness api specifications.""" +class OmenSubgraph(ApiSpecs): + """A model that wraps ApiSpecs for the OMEN's subgraph specifications.""" class MarketManagerParams(BaseParams): From 5129499dd2cd0288e0b6e79f3fbca5e62abf95bb Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 11 Jul 2023 09:47:01 +0300 Subject: [PATCH 7/7] feat: implement chained trader abci --- Makefile | 1 + packages/valory/skills/trader_abci/README.md | 5 + .../valory/skills/trader_abci/__init__.py | 25 +++ .../valory/skills/trader_abci/behaviours.py | 61 +++++++ .../valory/skills/trader_abci/composition.py | 76 ++++++++ .../valory/skills/trader_abci/dialogues.py | 90 ++++++++++ .../valory/skills/trader_abci/handlers.py | 50 ++++++ packages/valory/skills/trader_abci/models.py | 100 +++++++++++ packages/valory/skills/trader_abci/skill.yaml | 162 ++++++++++++++++++ tox.ini | 2 +- 10 files changed, 571 insertions(+), 1 deletion(-) create mode 100644 packages/valory/skills/trader_abci/README.md create mode 100644 packages/valory/skills/trader_abci/__init__.py create mode 100644 packages/valory/skills/trader_abci/behaviours.py create mode 100644 packages/valory/skills/trader_abci/composition.py create mode 100644 packages/valory/skills/trader_abci/dialogues.py create mode 100644 packages/valory/skills/trader_abci/handlers.py create mode 100644 packages/valory/skills/trader_abci/models.py create mode 100644 packages/valory/skills/trader_abci/skill.yaml diff --git a/Makefile b/Makefile index f4907db9..57a4d7f0 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,7 @@ all-checks: clean format code-checks security generators common-checks-1 common- fix-abci-app-specs: autonomy analyse fsm-specs --update --app-class MarketManagerAbciApp --package packages/valory/skills/market_manager_abci autonomy analyse fsm-specs --update --app-class DecisionMakerAbciApp --package packages/valory/skills/decision_maker_abci + autonomy analyse fsm-specs --update --app-class TraderAbciApp --package packages/valory/skills/trader_abci echo "Successfully validated abcis!" protolint_install: diff --git a/packages/valory/skills/trader_abci/README.md b/packages/valory/skills/trader_abci/README.md new file mode 100644 index 00000000..6d0eb56d --- /dev/null +++ b/packages/valory/skills/trader_abci/README.md @@ -0,0 +1,5 @@ +# Trader abci + +## Description + +This module contains the trader chained skill for an AEA. diff --git a/packages/valory/skills/trader_abci/__init__.py b/packages/valory/skills/trader_abci/__init__.py new file mode 100644 index 00000000..219bbfad --- /dev/null +++ b/packages/valory/skills/trader_abci/__init__.py @@ -0,0 +1,25 @@ +# -*- 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 trader chained skill for an AEA.""" + +from aea.configurations.base import PublicId + + +PUBLIC_ID = PublicId.from_str("valory/trader_abci:0.1.0") diff --git a/packages/valory/skills/trader_abci/behaviours.py b/packages/valory/skills/trader_abci/behaviours.py new file mode 100644 index 00000000..517312f1 --- /dev/null +++ b/packages/valory/skills/trader_abci/behaviours.py @@ -0,0 +1,61 @@ +# -*- 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 behaviours for the trader skill.""" + +from typing import Set, Type + +from packages.valory.skills.abstract_round_abci.behaviours import ( + AbstractRoundBehaviour, + BaseBehaviour, +) +from packages.valory.skills.decision_maker_abci.behaviours.round_behaviour import ( + AgentDecisionMakerRoundBehaviour, +) +from packages.valory.skills.market_manager_abci.behaviours import ( + MarketManagerRoundBehaviour, +) +from packages.valory.skills.registration_abci.behaviours import ( + AgentRegistrationRoundBehaviour, + RegistrationStartupBehaviour, +) +from packages.valory.skills.reset_pause_abci.behaviours import ( + ResetPauseABCIConsensusBehaviour, +) +from packages.valory.skills.termination_abci.behaviours import ( + BackgroundBehaviour, + TerminationAbciBehaviours, +) +from packages.valory.skills.trader_abci.composition import TraderAbciApp + + +class TraderConsensusBehaviour(AbstractRoundBehaviour): + """This behaviour manages the consensus stages for the trader.""" + + initial_behaviour_cls = RegistrationStartupBehaviour + abci_app_cls = TraderAbciApp + + behaviours: Set[Type[BaseBehaviour]] = { + *AgentRegistrationRoundBehaviour.behaviours, + *AgentDecisionMakerRoundBehaviour.behaviours, + *MarketManagerRoundBehaviour.behaviours, + *ResetPauseABCIConsensusBehaviour.behaviours, + *TerminationAbciBehaviours.behaviours, + } + background_behaviour_cls = BackgroundBehaviour diff --git a/packages/valory/skills/trader_abci/composition.py b/packages/valory/skills/trader_abci/composition.py new file mode 100644 index 00000000..0d13a9ba --- /dev/null +++ b/packages/valory/skills/trader_abci/composition.py @@ -0,0 +1,76 @@ +# -*- 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 trader ABCI application.""" + +from packages.valory.skills.abstract_round_abci.abci_app_chain import ( + AbciAppTransitionMapping, + chain, +) +from packages.valory.skills.decision_maker_abci.rounds import DecisionMakerAbciApp +from packages.valory.skills.decision_maker_abci.states.final_states import ( + FinishedDecisionMakerRound, + FinishedWithoutDecisionRound, +) +from packages.valory.skills.decision_maker_abci.states.sampling import SamplingRound +from packages.valory.skills.market_manager_abci.rounds import ( + FailedMarketManagerRound, + FinishedMarketManagerRound, + MarketManagerAbciApp, + UpdateBetsRound, +) +from packages.valory.skills.registration_abci.rounds import ( + AgentRegistrationAbciApp, + FinishedRegistrationRound, + RegistrationRound, +) +from packages.valory.skills.reset_pause_abci.rounds import ( + FinishedResetAndPauseErrorRound, + FinishedResetAndPauseRound, + ResetAndPauseRound, + ResetPauseAbciApp, +) +from packages.valory.skills.termination_abci.rounds import BackgroundRound +from packages.valory.skills.termination_abci.rounds import Event as TerminationEvent +from packages.valory.skills.termination_abci.rounds import TerminationAbciApp + + +abci_app_transition_mapping: AbciAppTransitionMapping = { + FinishedRegistrationRound: UpdateBetsRound, + FinishedMarketManagerRound: SamplingRound, + FailedMarketManagerRound: ResetAndPauseRound, + FinishedDecisionMakerRound: ResetAndPauseRound, + FinishedWithoutDecisionRound: ResetAndPauseRound, + FinishedResetAndPauseRound: UpdateBetsRound, + FinishedResetAndPauseErrorRound: RegistrationRound, +} + +TraderAbciApp = chain( + ( + AgentRegistrationAbciApp, + DecisionMakerAbciApp, + MarketManagerAbciApp, + ResetPauseAbciApp, + ), + abci_app_transition_mapping, +).add_termination( + background_round_cls=BackgroundRound, + termination_event=TerminationEvent.TERMINATE, + termination_abci_app=TerminationAbciApp, +) diff --git a/packages/valory/skills/trader_abci/dialogues.py b/packages/valory/skills/trader_abci/dialogues.py new file mode 100644 index 00000000..153b6ce5 --- /dev/null +++ b/packages/valory/skills/trader_abci/dialogues.py @@ -0,0 +1,90 @@ +# -*- 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 classes required for dialogue management.""" + +from packages.valory.skills.abstract_round_abci.dialogues import ( + AbciDialogue as BaseAbciDialogue, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + AbciDialogues as BaseAbciDialogues, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + ContractApiDialogue as BaseContractApiDialogue, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + ContractApiDialogues as BaseContractApiDialogues, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + HttpDialogue as BaseHttpDialogue, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + HttpDialogues as BaseHttpDialogues, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + IpfsDialogue as BaseIpfsDialogue, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + IpfsDialogues as BaseIpfsDialogues, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + LedgerApiDialogue as BaseLedgerApiDialogue, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + LedgerApiDialogues as BaseLedgerApiDialogues, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + SigningDialogue as BaseSigningDialogue, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + SigningDialogues as BaseSigningDialogues, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + TendermintDialogue as BaseTendermintDialogue, +) +from packages.valory.skills.abstract_round_abci.dialogues import ( + TendermintDialogues as BaseTendermintDialogues, +) + + +AbciDialogue = BaseAbciDialogue +AbciDialogues = BaseAbciDialogues + + +HttpDialogue = BaseHttpDialogue +HttpDialogues = BaseHttpDialogues + + +SigningDialogue = BaseSigningDialogue +SigningDialogues = BaseSigningDialogues + + +LedgerApiDialogue = BaseLedgerApiDialogue +LedgerApiDialogues = BaseLedgerApiDialogues + + +ContractApiDialogue = BaseContractApiDialogue +ContractApiDialogues = BaseContractApiDialogues + +TendermintDialogue = BaseTendermintDialogue +TendermintDialogues = BaseTendermintDialogues + + +IpfsDialogue = BaseIpfsDialogue +IpfsDialogues = BaseIpfsDialogues diff --git a/packages/valory/skills/trader_abci/handlers.py b/packages/valory/skills/trader_abci/handlers.py new file mode 100644 index 00000000..1116e911 --- /dev/null +++ b/packages/valory/skills/trader_abci/handlers.py @@ -0,0 +1,50 @@ +# -*- 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 handlers for the 'trader_abci' skill.""" + +from packages.valory.skills.abstract_round_abci.handlers import ABCIRoundHandler +from packages.valory.skills.abstract_round_abci.handlers import ( + ContractApiHandler as BaseContractApiHandler, +) +from packages.valory.skills.abstract_round_abci.handlers import ( + HttpHandler as BaseHttpHandler, +) +from packages.valory.skills.abstract_round_abci.handlers import ( + IpfsHandler as BaseIpfsHandler, +) +from packages.valory.skills.abstract_round_abci.handlers import ( + LedgerApiHandler as BaseLedgerApiHandler, +) +from packages.valory.skills.abstract_round_abci.handlers import ( + SigningHandler as BaseSigningHandler, +) +from packages.valory.skills.abstract_round_abci.handlers import ( + TendermintHandler as BaseTendermintHandler, +) + + +TraderHandler = ABCIRoundHandler +HttpHandler = BaseHttpHandler +SigningHandler = BaseSigningHandler +LedgerApiHandler = BaseLedgerApiHandler +ContractApiHandler = BaseContractApiHandler +TendermintHandler = BaseTendermintHandler +IpfsHandler = BaseIpfsHandler diff --git a/packages/valory/skills/trader_abci/models.py b/packages/valory/skills/trader_abci/models.py new file mode 100644 index 00000000..399d60f9 --- /dev/null +++ b/packages/valory/skills/trader_abci/models.py @@ -0,0 +1,100 @@ +# -*- 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. +# +# ------------------------------------------------------------------------------ + +"""Custom objects for the trader ABCI application.""" + +from typing import Dict, Type, Union, cast + +from packages.valory.skills.abstract_round_abci.models import ( + BenchmarkTool as BaseBenchmarkTool, +) +from packages.valory.skills.abstract_round_abci.models import Requests as BaseRequests +from packages.valory.skills.abstract_round_abci.models import ( + SharedState as BaseSharedState, +) +from packages.valory.skills.decision_maker_abci.models import DecisionMakerParams +from packages.valory.skills.decision_maker_abci.rounds import ( + Event as DecisionMakerEvent, +) +from packages.valory.skills.market_manager_abci.models import ( + OmenSubgraph as MarketManagerOmenSubgraph, +) +from packages.valory.skills.market_manager_abci.rounds import ( + Event as MarketManagerEvent, +) +from packages.valory.skills.reset_pause_abci.rounds import Event as ResetPauseEvent +from packages.valory.skills.termination_abci.models import TerminationParams +from packages.valory.skills.trader_abci.composition import TraderAbciApp +from packages.valory.skills.transaction_settlement_abci.rounds import Event as TSEvent + + +EventType = Union[ + Type[MarketManagerEvent], + Type[DecisionMakerEvent], + Type[TSEvent], + Type[ResetPauseEvent], +] +EventToTimeoutMappingType = Dict[ + Union[MarketManagerEvent, DecisionMakerEvent, TSEvent, ResetPauseEvent], + float, +] + + +Requests = BaseRequests +BenchmarkTool = BaseBenchmarkTool +OmenSubgraph = MarketManagerOmenSubgraph + +MARGIN = 5 + + +class TraderParams(DecisionMakerParams, TerminationParams): + """A model to represent the trader params.""" + + +class SharedState(BaseSharedState): + """Keep the current shared state of the skill.""" + + abci_app_cls = TraderAbciApp + + @property + def params(self) -> TraderParams: + """Get the parameters.""" + return cast(TraderParams, self.context.params) + + def setup(self) -> None: + """Set up.""" + super().setup() + + events = (MarketManagerEvent, DecisionMakerEvent, TSEvent, ResetPauseEvent) + round_timeout = self.params.round_timeout_seconds + round_timeout_overrides = { + cast(EventType, event).ROUND_TIMEOUT: round_timeout for event in events + } + reset_pause_timeout = self.params.reset_pause_duration + MARGIN + event_to_timeout_overrides: EventToTimeoutMappingType = { + **round_timeout_overrides, + TSEvent.RESET_TIMEOUT: round_timeout, + TSEvent.VALIDATE_TIMEOUT: self.params.validate_timeout, + TSEvent.FINALIZE_TIMEOUT: self.params.finalize_timeout, + TSEvent.CHECK_TIMEOUT: self.params.history_check_timeout, + ResetPauseEvent.RESET_AND_PAUSE_TIMEOUT: reset_pause_timeout, + } + + for event, override in event_to_timeout_overrides.items(): + TraderAbciApp.event_to_timeout[event] = override diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml new file mode 100644 index 00000000..96d80aaf --- /dev/null +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -0,0 +1,162 @@ +name: trader_abci +author: valory +version: 0.1.0 +type: skill +description: This skill implements the trader skill for an AEA. +license: Apache-2.0 +aea_version: '>=1.0.0, <2.0.0' +fingerprint: + README.md: + __init__.py: + behaviours.py: + composition.py: + dialogues.py: + fsm_specification.yaml: + handlers.py: + models.py: +fingerprint_ignore_patterns: [] +connections: [] +contracts: [] +protocols: [] +skills: +- valory/abstract_round_abci:0.1.0:bafybeiac62ennpw54gns2quk4g3yoaili2mb72nj6c52czobz5dcwj4mwi +- valory/registration_abci:0.1.0:bafybeib6fsfur5jnflcveidnaeylneybwazewufzwa5twnwovdqgwtwsxm +- valory/reset_pause_abci:0.1.0:bafybeibqz7y3i4aepuprhijwdydkcsbqjtpeea6gdzpp5fgc6abrvjz25a +- valory/termination_abci:0.1.0:bafybeieb3gnvjxxsh73g67m7rivzknwb63xu4qeagpkv7f4mqz33ecikem +- valory/market_manager_abci +- valory/decision_maker_abci +behaviours: + main: + args: {} + class_name: TraderConsensusBehaviour +handlers: + abci: + args: {} + class_name: TraderHandler + contract_api: + args: {} + class_name: ContractApiHandler + http: + args: {} + class_name: HttpHandler + ipfs: + args: {} + class_name: IpfsHandler + ledger_api: + args: {} + class_name: LedgerApiHandler + signing: + args: {} + class_name: SigningHandler + tendermint: + args: {} + class_name: TendermintHandler +models: + abci_dialogues: + args: {} + class_name: AbciDialogues + benchmark_tool: + args: + log_dir: /logs + class_name: BenchmarkTool + contract_api_dialogues: + args: {} + class_name: ContractApiDialogues + http_dialogues: + args: {} + class_name: HttpDialogues + ipfs_dialogues: + args: {} + class_name: IpfsDialogues + ledger_api_dialogues: + args: {} + class_name: LedgerApiDialogues + params: + args: + broadcast_to_server: false + cleanup_history_depth: 1 + cleanup_history_depth_current: null + decimals: 5 + drand_public_key: 868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31 + genesis_config: + genesis_time: '2022-05-20T16:00:21.735122717Z' + chain_id: chain-c4daS1 + consensus_params: + block: + max_bytes: '22020096' + max_gas: '-1' + time_iota_ms: '1000' + evidence: + max_age_num_blocks: '100000' + max_age_duration: '172800000000000' + max_bytes: '1048576' + validator: + pub_key_types: + - ed25519 + version: { } + voting_power: '10' + keeper_timeout: 30.0 + max_attempts: 10 + max_healthcheck: 120 + multisend_address: '0x0000000000000000000000000000000000000000' + on_chain_service_id: null + request_retry_delay: 1.0 + request_timeout: 10.0 + reset_pause_duration: 10 + reset_tendermint_after: 2 + retry_attempts: 400 + retry_timeout: 3 + round_timeout_seconds: 120.0 + service_id: market_manager_estimation + service_registry_address: null + setup: + all_participants: + - '0x0000000000000000000000000000000000000000' + safe_contract_address: '0x0000000000000000000000000000000000000000' + consensus_threshold: null + share_tm_config_on_startup: false + sleep_time: 5 + tendermint_check_sleep_delay: 3 + tendermint_com_url: http://localhost:8080 + tendermint_max_retries: 5 + tendermint_p2p_url: localhost:26656 + tendermint_url: http://localhost:26657 + termination_sleep: 900 + tx_timeout: 10.0 + use_termination: false + creator_per_subgraph: + omen_subgraph: [ ] + slot_count: 2 + opening_margin: 300 + languages: [ en_US ] + mech_agent_id: 3 + mech_tool: prediction-online + bet_amount_per_threshold: + 0: 0 + 0.1: 0 + 0.2: 0 + 0.3: 0 + 0.4: 0 + 0.5: 0 + 0.6: 0 + 0.7: 0 + 0.8: 0 + 0.9: 0 + 1: 0 + bet_threshold: 100000000000000000 + blacklisting_duration: 3600 + class_name: TraderParams + requests: + args: {} + class_name: Requests + signing_dialogues: + args: {} + class_name: SigningDialogues + state: + args: {} + class_name: SharedState + tendermint_dialogues: + args: {} + class_name: TendermintDialogues +dependencies: {} +is_abstract: false diff --git a/tox.ini b/tox.ini index a2b34b49..9b8529e3 100644 --- a/tox.ini +++ b/tox.ini @@ -59,7 +59,7 @@ setenv = PYTHONPATH={env:PWD:%CD%} PACKAGES_PATHS = packages/valory SKILLS_PATHS = {env:PACKAGES_PATHS}/skills - SERVICE_SPECIFIC_PACKAGES = {env:SKILLS_PATHS}/market_manager_abci {env:SKILLS_PATHS}/decision_maker_abci + SERVICE_SPECIFIC_PACKAGES = {env:SKILLS_PATHS}/market_manager_abci {env:SKILLS_PATHS}/decision_maker_abci {env:SKILLS_PATHS}/trader_abci [testenv:bandit] skipsdist = True