diff --git a/packages/packages.json b/packages/packages.json index 0c86d5c7..41797ca7 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -16,14 +16,14 @@ "contract/valory/staking_token/0.1.0": "bafybeiep4r6qyilbfgzdvx6t7zvpgaioxqktmxm7puwtnbpb2ftlib43gy", "contract/valory/relayer/0.1.0": "bafybeicawmds6czx7db2lcktvexwrp245jpekgulndtos5s5zdid3ilvq4", "skill/valory/market_manager_abci/0.1.0": "bafybeicztk62pslofv6ui3aw3giw2tnvlfwfmatqbyvvzv4ampneu6isqa", - "skill/valory/decision_maker_abci/0.1.0": "bafybeigef5xufpkcrwxpekw35zqtxcsliudhagg3bybcnfpgb3hcucwaxm", - "skill/valory/trader_abci/0.1.0": "bafybeihdwrcx5c4k57g64jm47cmuug5igynm5tn6ic4k6usx4g2v2uqf5e", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeicex6xclnh3tduca2wydokodintbtfxx735fnuckmvtsns6xuyixy", + "skill/valory/decision_maker_abci/0.1.0": "bafybeicvz65mfxtxbqizsvd3r3sy7fwyutjfj5a2xu2d5uz7b2fq7xdpp4", + "skill/valory/trader_abci/0.1.0": "bafybeieop75gnpbriiltwvvbwi4p6q242xhnlts7yjur5sgrk5jvi6sr74", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeif23c7z5kfuarlu2ivcw3nbbchrnze3y2nemznnsynghis7w3scky", "skill/valory/staking_abci/0.1.0": "bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne", - "skill/valory/check_stop_trading_abci/0.1.0": "bafybeifmi64g4ki6zwbcncb35ovhd4sllw4xrszrkturpeqdhgf5bkiini", - "agent/valory/trader/0.1.0": "bafybeiandy3tuazyv5rzqzku3aic2ye7nuhily2gnch27omjfmo4rq5o4i", - "service/valory/trader/0.1.0": "bafybeidv5ovi6avyzz5vemgk6d3vz4d6n7pq276qgtuq3dyfry3hzzn32i", - "service/valory/trader_pearl/0.1.0": "bafybeigee5p7yryn6kfcozmymf7vvjraaz3htq44pbmhc5pdsswa7yay64" + "skill/valory/check_stop_trading_abci/0.1.0": "bafybeib75qrimmvensqmskdp5kzki5ijjwolqk2ojekeommakaf64mzn54", + "agent/valory/trader/0.1.0": "bafybeibrpyaz6l4rdcfkdmngh54kmqkxxfkb35clukyccvhupvqs5qcixq", + "service/valory/trader/0.1.0": "bafybeibmmbkop2wroton4tsmhxuxh7uzj6rjcksfowwpl5yuxws7fjl6xy", + "service/valory/trader_pearl/0.1.0": "bafybeidzq7nqxvdvkyjamxrvohrmu7ll2l5ptzo3lgpcnxsiickb2v2gv4" }, "third_party": { "protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index a71ef219..15c023a1 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -45,12 +45,12 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeigrdlxed3xlsnxtjhnsbl3cojruihxcqx4jxhgivkd5i2fkjncgba - valory/termination_abci:0.1.0:bafybeib5l7jhew5ic6iq24dd23nidcoimzqkrk556gqywhoziatj33zvwm - valory/transaction_settlement_abci:0.1.0:bafybeic7q7recyka272udwcupblwbkc3jkodgp74fvcdxb7urametg5dae -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeicex6xclnh3tduca2wydokodintbtfxx735fnuckmvtsns6xuyixy +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeif23c7z5kfuarlu2ivcw3nbbchrnze3y2nemznnsynghis7w3scky - valory/market_manager_abci:0.1.0:bafybeicztk62pslofv6ui3aw3giw2tnvlfwfmatqbyvvzv4ampneu6isqa -- valory/decision_maker_abci:0.1.0:bafybeigef5xufpkcrwxpekw35zqtxcsliudhagg3bybcnfpgb3hcucwaxm -- valory/trader_abci:0.1.0:bafybeihdwrcx5c4k57g64jm47cmuug5igynm5tn6ic4k6usx4g2v2uqf5e +- valory/decision_maker_abci:0.1.0:bafybeicvz65mfxtxbqizsvd3r3sy7fwyutjfj5a2xu2d5uz7b2fq7xdpp4 +- valory/trader_abci:0.1.0:bafybeieop75gnpbriiltwvvbwi4p6q242xhnlts7yjur5sgrk5jvi6sr74 - valory/staking_abci:0.1.0:bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne -- valory/check_stop_trading_abci:0.1.0:bafybeifmi64g4ki6zwbcncb35ovhd4sllw4xrszrkturpeqdhgf5bkiini +- valory/check_stop_trading_abci:0.1.0:bafybeib75qrimmvensqmskdp5kzki5ijjwolqk2ojekeommakaf64mzn54 - valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm customs: - valory/mike_strat:0.1.0:bafybeihjiol7f4ch4piwfikurdtfwzsh6qydkbsztpbwbwb2yrqdqf726m @@ -245,6 +245,7 @@ models: priority_mech_service_id: ${int:0} requester_staking_instance_address: ${str:0x0000000000000000000000000000000000000000} response_timeout: ${int:300} + expected_mech_response_time: 300 benchmarking_mode: args: enabled: ${bool:false} diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 4de2e8e4..03900683 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:bafybeiandy3tuazyv5rzqzku3aic2ye7nuhily2gnch27omjfmo4rq5o4i +agent: valory/trader:0.1.0:bafybeibrpyaz6l4rdcfkdmngh54kmqkxxfkb35clukyccvhupvqs5qcixq number_of_agents: 4 deployment: agent: @@ -145,6 +145,7 @@ type: skill rebet_chance: ${REBET_CHANCE:float:0.6} mech_interaction_sleep_time: ${MECH_INTERACTION_SLEEP_TIME:int:10} policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200} + expected_mech_response_time: ${EXPECTED_MECH_RESPONSE_TIME:int:300} benchmark_tool: &id004 args: log_dir: ${LOG_DIR:str:/benchmarks} @@ -366,6 +367,7 @@ type: skill rebet_chance: ${REBET_CHANCE:float:0.6} mech_interaction_sleep_time: ${MECH_INTERACTION_SLEEP_TIME:int:10} policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200} + expected_mech_response_time: ${EXPECTED_MECH_RESPONSE_TIME:int:300} benchmark_tool: *id004 acc_info_fields: *id005 network_subgraph: *id006 @@ -483,6 +485,7 @@ type: skill rebet_chance: ${REBET_CHANCE:float:0.6} mech_interaction_sleep_time: ${MECH_INTERACTION_SLEEP_TIME:int:10} policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200} + expected_mech_response_time: ${EXPECTED_MECH_RESPONSE_TIME:int:300} benchmark_tool: *id004 acc_info_fields: *id005 network_subgraph: *id006 @@ -600,6 +603,7 @@ type: skill rebet_chance: ${REBET_CHANCE:float:0.6} mech_interaction_sleep_time: ${MECH_INTERACTION_SLEEP_TIME:int:10} policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200} + expected_mech_response_time: ${EXPECTED_MECH_RESPONSE_TIME:int:300} benchmark_tool: *id004 acc_info_fields: *id005 network_subgraph: *id006 diff --git a/packages/valory/services/trader_pearl/service.yaml b/packages/valory/services/trader_pearl/service.yaml index 093ca3e0..8174168c 100644 --- a/packages/valory/services/trader_pearl/service.yaml +++ b/packages/valory/services/trader_pearl/service.yaml @@ -8,7 +8,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeiandy3tuazyv5rzqzku3aic2ye7nuhily2gnch27omjfmo4rq5o4i +agent: valory/trader:0.1.0:bafybeibrpyaz6l4rdcfkdmngh54kmqkxxfkb35clukyccvhupvqs5qcixq number_of_agents: 1 deployment: agent: diff --git a/packages/valory/skills/check_stop_trading_abci/rounds.py b/packages/valory/skills/check_stop_trading_abci/rounds.py index 5086fae3..21b93e89 100644 --- a/packages/valory/skills/check_stop_trading_abci/rounds.py +++ b/packages/valory/skills/check_stop_trading_abci/rounds.py @@ -21,7 +21,7 @@ from abc import ABC from enum import Enum -from typing import Dict, Set, Type +from typing import Dict, Optional, Set, Tuple, Type from packages.valory.skills.abstract_round_abci.base import ( AbciApp, @@ -61,6 +61,10 @@ def _get_deserialized(self, key: str) -> DeserializedCollection: serialized = self.db.get_strict(key) return CollectionRound.deserialize_collection(serialized) + def is_staking_kpi_met(self) -> bool: + """Get the status of the staking kpi.""" + return bool(self.db.get("is_staking_kpi_met", False)) + class CheckStopTradingRound(VotingRound): """A round for checking stop trading conditions.""" @@ -73,6 +77,18 @@ class CheckStopTradingRound(VotingRound): no_majority_event = Event.NO_MAJORITY collection_key = get_name(SynchronizedData.participant_to_votes) + def end_block(self) -> Optional[Tuple[BaseSynchronizedData, Enum]]: + """Process the end of the block.""" + res = super().end_block() + + if res is None: + return None + + is_staking_kpi_met = self.positive_vote_threshold_reached + self.synchronized_data.update(is_staking_kpi_met=is_staking_kpi_met) + + return res + class FinishedCheckStopTradingRound(DegenerateRound, ABC): """A round that represents check stop trading has finished.""" diff --git a/packages/valory/skills/check_stop_trading_abci/skill.yaml b/packages/valory/skills/check_stop_trading_abci/skill.yaml index efa30ee2..45c3db5e 100644 --- a/packages/valory/skills/check_stop_trading_abci/skill.yaml +++ b/packages/valory/skills/check_stop_trading_abci/skill.yaml @@ -14,7 +14,7 @@ fingerprint: handlers.py: bafybeiard64fwxib3rtyp67ymhf222uongcyqhfhdyttpsyqkmyh5ajipu models.py: bafybeigwdhgianx5rizlb7ebmm6pdtkixh4uehbvu5c24ysvyvojs74dfq payloads.py: bafybeidh5bqywun4chrbsci2xbcrnnzuys5sswxwbxq3yl2ksawi3xsi5q - rounds.py: bafybeigqkzikghmzjj2ceqrnvmiiagtris3livgvn6r5z5ossk73xcfqfy + rounds.py: bafybeift7b2afck4e5so2cpgyoywa76t6el6d4qwfoitvfdjw6kgf4fwie tests/__init__.py: bafybeihv2cjk4va5bc5ncqtppqg2xmmxcro34bma36trtvk32gtmhdycxu tests/test_dialogues.py: bafybeia5ac27w7ijx2nyx5dqyrnv4troo4572gjq7nrcxdncexoxucnqti tests/test_handlers.py: bafybeigpmtx2hyunzn6nxk2x4bvvybek7jvuhbk34fqlj7fgfsszcoqhxy 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 efcd346a..0d9e0e0d 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py @@ -35,7 +35,10 @@ remove_fraction_wei, ) from packages.valory.skills.decision_maker_abci.models import MultisendBatch -from packages.valory.skills.decision_maker_abci.payloads import MultisigTxPayload +from packages.valory.skills.decision_maker_abci.payloads import ( + BetPlacementPayload, + MultisigTxPayload, +) from packages.valory.skills.decision_maker_abci.states.bet_placement import ( BetPlacementRound, ) @@ -209,12 +212,12 @@ def async_act(self) -> Generator: if self.benchmarking_mode.enabled: # simulate the bet placement with self.context.benchmark_tool.measure(self.behaviour_id).local(): - payload = MultisigTxPayload(agent, None, None, True) + payload = BetPlacementPayload(agent, None, None, True, self.wallet_balance) yield from self.finish_behaviour(payload) with self.context.benchmark_tool.measure(self.behaviour_id).local(): yield from self.wait_for_condition_with_sleep(self.check_balance) - tx_submitter = betting_tx_hex = mocking_mode = None + tx_submitter = betting_tx_hex = mocking_mode = wallet_balance = None can_exchange = ( self.is_wxdai @@ -227,9 +230,14 @@ def async_act(self) -> Generator: if self.token_balance >= self.investment_amount or can_exchange: tx_submitter = self.matching_round.auto_round_id() betting_tx_hex = yield from self._prepare_safe_tx() - - payload = MultisigTxPayload( - agent, tx_submitter, betting_tx_hex, mocking_mode + wallet_balance = self.wallet_balance + + payload = BetPlacementPayload( + agent, + tx_submitter, + betting_tx_hex, + mocking_mode, + wallet_balance, ) yield from self.finish_behaviour(payload) 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 c1a4bac9..58eae2f9 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py @@ -539,10 +539,12 @@ def async_act(self) -> Generator: bet_amount = None next_mock_data_row = None bets_hash = None + decision_received_timestamp = None if prediction_response is not None and prediction_response.vote is not None: is_profitable, bet_amount = yield from self._is_profitable( prediction_response ) + decision_received_timestamp = self.synced_timestamp if is_profitable: self.store_bets() bets_hash = self.hash_stored_bets() @@ -575,6 +577,7 @@ def async_act(self) -> Generator: prediction_response.confidence if prediction_response else None, bet_amount, next_mock_data_row, + decision_received_timestamp, ) yield from self.finish_behaviour(payload) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/order_subscription.py b/packages/valory/skills/decision_maker_abci/behaviours/order_subscription.py index 6a5d123c..531485dd 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/order_subscription.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/order_subscription.py @@ -376,5 +376,6 @@ def async_act(self) -> Generator: tx_submitter=SubscriptionRound.auto_round_id(), tx_hash=payload_data, agreement_id=self.agreement_id, + wallet_balance=self.wallet_balance, ) yield from self.finish_behaviour(payload) diff --git a/packages/valory/skills/decision_maker_abci/handlers.py b/packages/valory/skills/decision_maker_abci/handlers.py index 155a5715..c46644e5 100644 --- a/packages/valory/skills/decision_maker_abci/handlers.py +++ b/packages/valory/skills/decision_maker_abci/handlers.py @@ -266,6 +266,10 @@ def _handle_get_health( is_transitioning_fast = None current_round = None rounds = None + has_required_funds = self._check_required_funds() + is_receiving_mech_responses = self._check_is_receiving_mech_responses() + is_staking_kpi_met = self.synchronized_data.is_staking_kpi_met + staking_status = self.synchronized_data.service_staking_state.name.lower() round_sequence = cast(SharedState, self.context.state).round_sequence @@ -299,6 +303,12 @@ def _handle_get_health( "reset_pause_duration": self.context.params.reset_pause_duration, "rounds": rounds, "is_transitioning_fast": is_transitioning_fast, + "agent_health": { + "is_making_on_chain_transactions": is_receiving_mech_responses, + "is_staking_kpi_met": is_staking_kpi_met, + "has_required_funds": has_required_funds, + "staking_status": staking_status, + }, } self._send_ok_response(http_msg, http_dialogue, data) @@ -337,3 +347,19 @@ def _send_not_found_response( # Send response self.context.logger.info("Responding with: {}".format(http_response)) self.context.outbox.put_message(message=http_response) + + def _check_required_funds(self) -> bool: + """Check the agent has enough funds.""" + return ( + self.synchronized_data.wallet_balance + > self.context.params.agent_balance_threshold + ) + + def _check_is_receiving_mech_responses(self) -> bool: + """Check the agent is making on chain transactions.""" + # Checks the most recent decision receive timestamp, which can only be returned after making a mech call + # (an on chain transaction) + return ( + self.synchronized_data.decision_receive_timestamp + < int(datetime.utcnow().timestamp()) - self.context.params.expected_mech_response_time + ) diff --git a/packages/valory/skills/decision_maker_abci/models.py b/packages/valory/skills/decision_maker_abci/models.py index 36cce15b..201e17d3 100644 --- a/packages/valory/skills/decision_maker_abci/models.py +++ b/packages/valory/skills/decision_maker_abci/models.py @@ -483,6 +483,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.policy_store_update_offset = self._ensure( "policy_store_update_offset", kwargs, int ) + self.expected_mech_response_time = self._ensure( + "expected_mech_response_time", kwargs, int + ) super().__init__(*args, **kwargs) @property diff --git a/packages/valory/skills/decision_maker_abci/payloads.py b/packages/valory/skills/decision_maker_abci/payloads.py index 0b8e9c2e..33ec183b 100644 --- a/packages/valory/skills/decision_maker_abci/payloads.py +++ b/packages/valory/skills/decision_maker_abci/payloads.py @@ -35,6 +35,7 @@ class DecisionReceivePayload(UpdateBetsPayload): confidence: Optional[float] bet_amount: Optional[int] next_mock_data_row: Optional[int] + decision_received_timestamp: Optional[int] @dataclass(frozen=True) @@ -79,6 +80,7 @@ class SubscriptionPayload(MultisigTxPayload): """Represents a transaction payload for subscribing.""" agreement_id: str = "" + wallet_balance: Optional[int] = None @dataclass(frozen=True) @@ -110,3 +112,10 @@ class ToolSelectionPayload(BaseTxPayload): policy: Optional[str] utilized_tools: Optional[str] selected_tool: Optional[str] + + +@dataclass(frozen=True) +class BetPlacementPayload(MultisigTxPayload): + """Represents a transaction payload for placing a bet.""" + + wallet_balance: Optional[int] = None diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index 96328ba2..18754959 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -13,14 +13,14 @@ fingerprint: __init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky behaviours/base.py: bafybeifjgxzhwzxiky3okgtv4ojumm7fj7bom6qe3ysdvs3cpu32w446g4 - behaviours/bet_placement.py: bafybeihmia64t2payxfqcnfdqg675ui2yp3hnyfwb2xhj2hn7wl237b4re + behaviours/bet_placement.py: bafybeif3blpj45w4y2ppw5lxkxndsc5crhghevagifuh4fcoofej36bq34 behaviours/blacklisting.py: bafybeifitqx2omj5qdwokizhqjkxvybtsyxo22dxkucbtxaocafzgbseku behaviours/check_benchmarking.py: bafybeiao2lyj7apezkqrpgsyzb3dwvrdgsrgtprf6iuhsmlsufvxfl5bci behaviours/claim_subscription.py: bafybeigbqkhc6mb73rbwaks32tfiqx6u2xza43uiy6rvbtrnqd6m4fru3e - behaviours/decision_receive.py: bafybeiempl2rdkxxkup7ibtvdx5kleeucfij2upglzwqlgqysifwxareom + behaviours/decision_receive.py: bafybeiaph3ft4j3br4k7bddymzv5ffcexmlup2l4prk5rvhqlilxtq57oa behaviours/decision_request.py: bafybeia22omb7tvocyfe3z2ucn5au5mcas7dg37ha42u7znefzrewjpk7y behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm - behaviours/order_subscription.py: bafybeicrmdvhci5prfldvuf3bclbbqi6j7lpv6hmphw3qwgmkmwat3od44 + behaviours/order_subscription.py: bafybeib3maqohhx35wzryy4otdcjp5thkr4sbp27ksvwidy3pwm444itra behaviours/randomness.py: bafybeiaoj3awyyg2onhpsdsn3dyczs23gr4smuzqcbw3e5ocljwxswjkce behaviours/reedem.py: bafybeiaxwp4lx62owcaqfp6xcqh6567f5yvwnl4rage2f5hmq4nltkzjjy behaviours/round_behaviour.py: bafybeih63hpia2bwwzu563hxs5yd3t5ycvxvkfnhvxbzghbyy3mw3xjl3i @@ -29,25 +29,25 @@ fingerprint: behaviours/tool_selection.py: bafybeienlxcgjs3ogyofli3d7q3p5rst3mcxxcnwqf7qolqjeefjtixeke dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm fsm_specification.yaml: bafybeigwlvvi6fav72wg4wz22xjekegenzjnub5efwz5xu6qsrjnxluspq - handlers.py: bafybeigod6gbjrxy4mbmulbzsbokeaoycoqys64vqtxnumishfukzf73za + handlers.py: bafybeiafuc7vtyhrv2phep56maadpd4lubipdzw2sszv62r2tz7hzjmsdi io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq io_/loader.py: bafybeih3sdsx5dhe4kzhtoafexjgkutsujwqy3zcdrlrkhtdks45bc7exa - models.py: bafybeieqknkktfrs5e4maq4cosevabkbneszw4dp44sz7mavr4hpdy6yem - payloads.py: bafybeihzwxhdc6a6ek2lvsyzkex4ypsl7fnahszal3dxtr7ce6wp7nmgmm + models.py: bafybeiemk4xiphf6sn7ei7rukn2veebeu2pg3j2xy5nqxcizelnkpvivqm + payloads.py: bafybeif3d4qgj635rbnp6a5lgwhgbyilta6mtytjcej2jccorckxbuaev4 policy.py: bafybeihlzs4o5e7yfmfzcvvrzkf4bhxfsg5gxnzsrpepwgfugh45gafye4 redeem_info.py: bafybeifiiix4gihfo4avraxt34sfw35v6dqq45do2drrssei2shbps63mm rounds.py: bafybeiazjcsukgefair52aw37hhvxzlopnzqqmi4ntqrinakljlcm4kt4a states/__init__.py: bafybeid23llnyp6j257dluxmrnztugo5llsrog7kua53hllyktz4dqhqoy - states/base.py: bafybeihqabaawgms5kwz544jmlxvp5y5zr5jv7qgp3kzweg7bdl5asq764 - states/bet_placement.py: bafybeibalhxhp2c4oljmiwqi6ds3g36fgtabmf42mb5sgq6z22znrcbhda + states/base.py: bafybeifkip6bw3oacpnyhko7fi3i72nv2fc33ld6bkr2myaay4qa2ybcie + states/bet_placement.py: bafybeih5eopyxubczys5u5t3bdxbxpc7mmfdyqrpqsbm2uha5jc2phza4i states/blacklisting.py: bafybeiapelgjhbjjn4uq4z5gspyirqzwzgccg5anktrp5kxdwamfnfw5mi states/check_benchmarking.py: bafybeiabv6pq7q45jd3nkor5afmlycqgec5ctuwcfbdukkjjm4imesv4ni states/claim_subscription.py: bafybeiampifhdoztggwj6gthl2hfzecmjcwnm6nic2o47q4je7j4x3ujne - states/decision_receive.py: bafybeifalcb4oxenrz63at3c267eqvo2ntfwsc6lur2jgm2damc7foegoa + states/decision_receive.py: bafybeicnqp4uf47btdkow7ivcozqxfue7u3p7efti3wggxf5iwc2uura3i states/decision_request.py: bafybeiarv3r5j7cfvxmudki2llbdl2pvf24p5mvsva6bdgrylnwdyag5xy states/final_states.py: bafybeicjrrojo3gmfaxzicwloyorlnqgzl6a2avevo4nvhoh424zwzmbti states/handle_failed_tx.py: bafybeihewm2vernvhktuorljdupjqcg2p5vs6wvsira2d62wkoyo5xlzjm - states/order_subscription.py: bafybeidrcef2op3nhq4tjgri3ct5hfhmc22xw2ep6dk4ro6tg7ob6cmioa + states/order_subscription.py: bafybeihl3pwrbccaitiukbigygd5u3weyih34pvzql3c6n5k7gjj47f2be states/randomness.py: bafybeiceoo4nx3t4dofpwczw3v5mclramwmzpwjs6hv7l56arodrjx4l5u states/redeem.py: bafybeica6cn4xg7shea2wjhbqnddgxe5zao2hkmceltze7qknxdhtsoaxe states/sampling.py: bafybeif2yuwl5swelp7oh5nfuupdf3vg2ijjzapk2xqht7e6i6ggcsl2zy @@ -104,6 +104,7 @@ skills: - valory/market_manager_abci:0.1.0:bafybeicztk62pslofv6ui3aw3giw2tnvlfwfmatqbyvvzv4ampneu6isqa - valory/transaction_settlement_abci:0.1.0:bafybeic7q7recyka272udwcupblwbkc3jkodgp74fvcdxb7urametg5dae - valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm +- valory/staking_abci:0.1.0:bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne behaviours: main: args: {} @@ -314,6 +315,8 @@ models: priority_mech_service_id: 0 requester_staking_instance_address: '0x0000000000000000000000000000000000000000' response_timeout: 300 + agent_balance_threshold: 10000000000000000 + expected_mech_response_time: 300 class_name: DecisionMakerParams benchmarking_mode: args: diff --git a/packages/valory/skills/decision_maker_abci/states/base.py b/packages/valory/skills/decision_maker_abci/states/base.py index 8d655021..33bdc463 100644 --- a/packages/valory/skills/decision_maker_abci/states/base.py +++ b/packages/valory/skills/decision_maker_abci/states/base.py @@ -38,6 +38,7 @@ MechInteractionResponse, MechMetadata, ) +from packages.valory.skills.staking_abci.rounds import StakingState from packages.valory.skills.transaction_settlement_abci.rounds import ( SynchronizedData as TxSettlementSyncedData, ) @@ -241,6 +242,32 @@ def mech_responses(self) -> List[MechInteractionResponse]: responses = json.loads(serialized) return [MechInteractionResponse(**response_item) for response_item in responses] + @property + def wallet_balance(self) -> int: + """Get the balance of the wallet.""" + wallet_balance = self.db.get("wallet_balance", 0) + if wallet_balance is None: + return 0 + return int(wallet_balance) + + @property + def decision_receive_timestamp(self) -> int: + """Get the timestamp of the mech decision.""" + decision_receive_timestamp = self.db.get("decision_receive_timestamp", 0) + if decision_receive_timestamp is None: + return 0 + return int(decision_receive_timestamp) + + @property + def is_staking_kpi_met(self) -> bool: + """Get the status of the staking kpi.""" + return bool(self.db.get("is_staking_kpi_met", False)) + + @property + def service_staking_state(self) -> StakingState: + """Get the service's staking state.""" + return StakingState(self.db.get("service_staking_state", 0)) + class TxPreparationRound(CollectSameUntilThresholdRound): """A round for preparing a transaction.""" diff --git a/packages/valory/skills/decision_maker_abci/states/bet_placement.py b/packages/valory/skills/decision_maker_abci/states/bet_placement.py index 521333e9..35e7c63f 100644 --- a/packages/valory/skills/decision_maker_abci/states/bet_placement.py +++ b/packages/valory/skills/decision_maker_abci/states/bet_placement.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------ # -# Copyright 2023 Valory AG +# Copyright 2024 Valory AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,14 @@ # ------------------------------------------------------------------------------ """This module contains the sampling state of the decision-making abci app.""" +from enum import Enum +from typing import Optional, Tuple, Type +from packages.valory.skills.abstract_round_abci.base import BaseSynchronizedData +from packages.valory.skills.decision_maker_abci.payloads import ( + BetPlacementPayload, + MultisigTxPayload, +) from packages.valory.skills.decision_maker_abci.states.base import ( Event, TxPreparationRound, @@ -28,4 +35,17 @@ class BetPlacementRound(TxPreparationRound): """A round for placing a bet.""" + payload_class: Type[MultisigTxPayload] = BetPlacementPayload + none_event = Event.INSUFFICIENT_BALANCE + + def end_block(self) -> Optional[Tuple[BaseSynchronizedData, Enum]]: + """Process the end of the block.""" + update = super().end_block() + if update is None: + return None + + sync_data, event = update + wallet_balance = self.most_voted_payload_values[-1] + sync_data = sync_data.update(wallet_balance=wallet_balance) + return sync_data, event diff --git a/packages/valory/skills/decision_maker_abci/states/decision_receive.py b/packages/valory/skills/decision_maker_abci/states/decision_receive.py index 1f1080c2..254f9685 100644 --- a/packages/valory/skills/decision_maker_abci/states/decision_receive.py +++ b/packages/valory/skills/decision_maker_abci/states/decision_receive.py @@ -60,6 +60,14 @@ def end_block(self) -> Optional[Tuple[SynchronizedData, Enum]]: synced_data, event = cast(Tuple[SynchronizedData, Enum], res) + if event == Event.DONE: + decision_receive_timestamp = self.most_voted_payload_values[-1] + + synced_data = cast( + SynchronizedData, + synced_data.update(decision_receive_timestamp=decision_receive_timestamp), + ) + if event == Event.DONE and synced_data.vote is None: return synced_data, Event.TIE diff --git a/packages/valory/skills/decision_maker_abci/states/order_subscription.py b/packages/valory/skills/decision_maker_abci/states/order_subscription.py index d4b80aa1..5c5831bd 100644 --- a/packages/valory/skills/decision_maker_abci/states/order_subscription.py +++ b/packages/valory/skills/decision_maker_abci/states/order_subscription.py @@ -68,7 +68,8 @@ def end_block(self) -> Optional[Tuple[BaseSynchronizedData, Enum]]: sync_data, event = update agreement_id = self.most_voted_payload_values[3] + wallet_balance = self.most_voted_payload_values[4] sync_data = sync_data.update( - agreement_id=agreement_id, + agreement_id=agreement_id, wallet_balance=wallet_balance ) return sync_data, event diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index bb4acb16..edd9e72f 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -27,10 +27,10 @@ skills: - valory/transaction_settlement_abci:0.1.0:bafybeic7q7recyka272udwcupblwbkc3jkodgp74fvcdxb7urametg5dae - valory/termination_abci:0.1.0:bafybeib5l7jhew5ic6iq24dd23nidcoimzqkrk556gqywhoziatj33zvwm - valory/market_manager_abci:0.1.0:bafybeicztk62pslofv6ui3aw3giw2tnvlfwfmatqbyvvzv4ampneu6isqa -- valory/decision_maker_abci:0.1.0:bafybeigef5xufpkcrwxpekw35zqtxcsliudhagg3bybcnfpgb3hcucwaxm -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeicex6xclnh3tduca2wydokodintbtfxx735fnuckmvtsns6xuyixy +- valory/decision_maker_abci:0.1.0:bafybeicvz65mfxtxbqizsvd3r3sy7fwyutjfj5a2xu2d5uz7b2fq7xdpp4 +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeif23c7z5kfuarlu2ivcw3nbbchrnze3y2nemznnsynghis7w3scky - valory/staking_abci:0.1.0:bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne -- valory/check_stop_trading_abci:0.1.0:bafybeifmi64g4ki6zwbcncb35ovhd4sllw4xrszrkturpeqdhgf5bkiini +- valory/check_stop_trading_abci:0.1.0:bafybeib75qrimmvensqmskdp5kzki5ijjwolqk2ojekeommakaf64mzn54 - valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm behaviours: main: @@ -256,6 +256,7 @@ models: priority_mech_service_id: 0 requester_staking_instance_address: '0x0000000000000000000000000000000000000000' response_timeout: 300 + expected_mech_response_time: 300 class_name: TraderParams benchmarking_mode: args: diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index e62dd609..de3d8846 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -23,7 +23,7 @@ protocols: - valory/ledger_api:1.0.0:bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni skills: - valory/abstract_round_abci:0.1.0:bafybeib733xfbndtpvkf44mtk7oyodnficgloo6xhn7xmqxxeos33es65u -- valory/decision_maker_abci:0.1.0:bafybeigef5xufpkcrwxpekw35zqtxcsliudhagg3bybcnfpgb3hcucwaxm +- valory/decision_maker_abci:0.1.0:bafybeicvz65mfxtxbqizsvd3r3sy7fwyutjfj5a2xu2d5uz7b2fq7xdpp4 - valory/staking_abci:0.1.0:bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne - valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm behaviours: