Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/health endpoint from v20 #364

Merged
merged 17 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "bafybeiffnd7vlryxtfenwcbbvx7qzszkko4oop2n2e6jg2ahdm3zholxsq",
"skill/valory/trader_abci/0.1.0": "bafybeigygq76epkhl67uuvrjlrall65r4ilcwna2jokgjunrzg45gf2ihy",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeie4rfme364fp2m3oo447622mc75tfk4hqftiebau2tpycftd5iffe",
"skill/valory/decision_maker_abci/0.1.0": "bafybeihdqsjign6jmhtshada3sdbdmu2fp4ipfmbmfz6t3eb6nqtdjbv4i",
"skill/valory/trader_abci/0.1.0": "bafybeigon2bq6bjuy5rs4ljrjm3omz4aj2wxjmqbpotkklupwpyvhcxd2m",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeie5yy23nkp3k64imugryuv2znb6swo53funveyzu7trmr4fuwklgu",
"skill/valory/staking_abci/0.1.0": "bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeifmi64g4ki6zwbcncb35ovhd4sllw4xrszrkturpeqdhgf5bkiini",
"agent/valory/trader/0.1.0": "bafybeibhv5pummw2ngrag6sk6a7phnffp2dfsswhvtxayzizqthea52kru",
"service/valory/trader/0.1.0": "bafybeiey356lnc35rxky3gvikcpcwerdjycyb6nmrw4qlpucar3ykd2jmm",
"service/valory/trader_pearl/0.1.0": "bafybeiezfz7h5g26qimscimnawyeeo3qwgm6smszc7jgwrxest7bgqoq5q"
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeidlfobaw7p7y5qquy5k2nyalwhmqngwebvmejx6c5muhofulasepm",
"agent/valory/trader/0.1.0": "bafybeie5esogmznsouimpx4g5tbr66tfws22pensrsm7jy6lpi3hghffyi",
"service/valory/trader/0.1.0": "bafybeic6qvmy3vtg6yxjutm4zoygbuo2oz76rd277fyvz5jcoush2phe5y",
"service/valory/trader_pearl/0.1.0": "bafybeieaiwhk6lwkc25mlz2ggww24kicrh52rcwg2jfxr7wmh76dnwmjra"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
10 changes: 4 additions & 6 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:bafybeie4rfme364fp2m3oo447622mc75tfk4hqftiebau2tpycftd5iffe
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeie5yy23nkp3k64imugryuv2znb6swo53funveyzu7trmr4fuwklgu
- valory/market_manager_abci:0.1.0:bafybeicztk62pslofv6ui3aw3giw2tnvlfwfmatqbyvvzv4ampneu6isqa
- valory/decision_maker_abci:0.1.0:bafybeiffnd7vlryxtfenwcbbvx7qzszkko4oop2n2e6jg2ahdm3zholxsq
- valory/trader_abci:0.1.0:bafybeigygq76epkhl67uuvrjlrall65r4ilcwna2jokgjunrzg45gf2ihy
- valory/decision_maker_abci:0.1.0:bafybeihdqsjign6jmhtshada3sdbdmu2fp4ipfmbmfz6t3eb6nqtdjbv4i
- valory/trader_abci:0.1.0:bafybeigon2bq6bjuy5rs4ljrjm3omz4aj2wxjmqbpotkklupwpyvhcxd2m
- valory/staking_abci:0.1.0:bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne
- valory/check_stop_trading_abci:0.1.0:bafybeifmi64g4ki6zwbcncb35ovhd4sllw4xrszrkturpeqdhgf5bkiini
- valory/check_stop_trading_abci:0.1.0:bafybeidlfobaw7p7y5qquy5k2nyalwhmqngwebvmejx6c5muhofulasepm
- valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm
customs:
- valory/mike_strat:0.1.0:bafybeihjiol7f4ch4piwfikurdtfwzsh6qydkbsztpbwbwb2yrqdqf726m
Expand Down Expand Up @@ -252,8 +252,6 @@ models:
collateral_balance: ${int:10000000000000000000}
mech_cost: ${int:10000000000000000}
pool_fee: ${int:20000000000000000}
outcome_token_amounts: ${list:[11000000000000000000,9000000000000000000]}
outcome_token_marginal_prices: ${list:[0.4,0.6]}
Adamantios marked this conversation as resolved.
Show resolved Hide resolved
sep: ${str:,}
dataset_filename: ${str:benchmark_data.csv}
question_field: ${str:question}
Expand Down
4 changes: 1 addition & 3 deletions packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeibhv5pummw2ngrag6sk6a7phnffp2dfsswhvtxayzizqthea52kru
agent: valory/trader:0.1.0:bafybeie5esogmznsouimpx4g5tbr66tfws22pensrsm7jy6lpi3hghffyi
number_of_agents: 4
deployment:
agent:
Expand Down Expand Up @@ -155,8 +155,6 @@ type: skill
collateral_balance: ${BENCHMARKING_MODE_COLLATERAL_BALANCE:int:10000000000000000000}
mech_cost: ${BENCHMARKING_MODE_MECH_COST:int:10000000000000000}
pool_fee: ${BENCHMARKING_MODE_POOL_FEE:int:20000000000000000}
outcome_token_amounts: ${OUTCOME_TOKEN_AMOUNTS:list:[11000000000000000000,9000000000000000000]}
outcome_token_marginal_prices: ${OUTCOME_TOKEN_MARGINAL_PRICES:list:[0.55,0.45]}
Adamantios marked this conversation as resolved.
Show resolved Hide resolved
sep: ${BENCHMARKING_MODE_SEP:str:,}
dataset_filename: ${BENCHMARKING_MODE_DATASET_FILENAME:str:benchmark_data.csv}
question_field: ${BENCHMARKING_MODE_QUESTION_FIELD:str:question}
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader_pearl/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeibhv5pummw2ngrag6sk6a7phnffp2dfsswhvtxayzizqthea52kru
agent: valory/trader:0.1.0:bafybeie5esogmznsouimpx4g5tbr66tfws22pensrsm7jy6lpi3hghffyi
number_of_agents: 1
deployment:
agent:
Expand Down
20 changes: 19 additions & 1 deletion packages/valory/skills/check_stop_trading_abci/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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."""
Expand All @@ -73,6 +77,20 @@ 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

sync_data, event = res

Adamantios marked this conversation as resolved.
Show resolved Hide resolved
is_staking_kpi_met = self.positive_vote_threshold_reached
sync_data = self.synchronized_data.update(is_staking_kpi_met=is_staking_kpi_met)

return sync_data, event


class FinishedCheckStopTradingRound(DegenerateRound, ABC):
"""A round that represents check stop trading has finished."""
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/check_stop_trading_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fingerprint:
handlers.py: bafybeiard64fwxib3rtyp67ymhf222uongcyqhfhdyttpsyqkmyh5ajipu
models.py: bafybeigwdhgianx5rizlb7ebmm6pdtkixh4uehbvu5c24ysvyvojs74dfq
payloads.py: bafybeidh5bqywun4chrbsci2xbcrnnzuys5sswxwbxq3yl2ksawi3xsi5q
rounds.py: bafybeigqkzikghmzjj2ceqrnvmiiagtris3livgvn6r5z5ossk73xcfqfy
rounds.py: bafybeid2nu2uv2aa4mhmxde2ar3q35ziartegngqzymp3gmpmjqnseztd4
tests/__init__.py: bafybeihv2cjk4va5bc5ncqtppqg2xmmxcro34bma36trtvk32gtmhdycxu
tests/test_dialogues.py: bafybeia5ac27w7ijx2nyx5dqyrnv4troo4572gjq7nrcxdncexoxucnqti
tests/test_handlers.py: bafybeigpmtx2hyunzn6nxk2x4bvvybek7jvuhbk34fqlj7fgfsszcoqhxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -228,8 +231,12 @@ def async_act(self) -> Generator:
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
payload = BetPlacementPayload(
agent,
tx_submitter,
betting_tx_hex,
mocking_mode,
wallet_balance=self.wallet_balance,
)
Adamantios marked this conversation as resolved.
Show resolved Hide resolved

yield from self.finish_behaviour(payload)
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ def async_act(self) -> Generator:
prediction_response.confidence if prediction_response else None,
bet_amount,
next_mock_data_row,
decision_received_timestamp=self.synced_timestamp,
Adamantios marked this conversation as resolved.
Show resolved Hide resolved
)

yield from self.finish_behaviour(payload)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
26 changes: 26 additions & 0 deletions packages/valory/skills/decision_maker_abci/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
< 2 * self.context.params.reset_pause_duration
Adamantios marked this conversation as resolved.
Show resolved Hide resolved
)
9 changes: 9 additions & 0 deletions packages/valory/skills/decision_maker_abci/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -77,6 +78,7 @@ class SubscriptionPayload(MultisigTxPayload):
"""Represents a transaction payload for subscribing."""

agreement_id: str = ""
wallet_balance: Optional[int] = None


@dataclass(frozen=True)
Expand Down Expand Up @@ -108,3 +110,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
20 changes: 11 additions & 9 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ fingerprint:
__init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a
behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky
behaviours/base.py: bafybeidjmsljdaw7y5chzzkub63mzf5ydpauch5ugojds5jwpeyvovkq3y
behaviours/bet_placement.py: bafybeihmia64t2payxfqcnfdqg675ui2yp3hnyfwb2xhj2hn7wl237b4re
behaviours/bet_placement.py: bafybeibkssszgm5e5sjiugjhfnzikj53kx2jrm5p6nkymj3j4mcx35ebsq
behaviours/blacklisting.py: bafybeicqwj7o4l7qcym5xjqwq45jngqkhyf44mn6qise2ysyfnlnwz7pdy
behaviours/check_benchmarking.py: bafybeiao2lyj7apezkqrpgsyzb3dwvrdgsrgtprf6iuhsmlsufvxfl5bci
behaviours/claim_subscription.py: bafybeigbqkhc6mb73rbwaks32tfiqx6u2xza43uiy6rvbtrnqd6m4fru3e
behaviours/decision_receive.py: bafybeifb7aeu6g4xzmiyfc5ltipigsikfot3foux55gw5oaz2o5u5a4ume
behaviours/decision_receive.py: bafybeibj32a7vvaolcevth2vw4heug5gpagar25zrd74lv467h4332yww4
behaviours/decision_request.py: bafybeiabjzzcwcfbfmtoftjhewmkgbhxfnigbc5cwmmxl6cob5gv64jwwa
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
Expand All @@ -29,25 +29,25 @@ fingerprint:
behaviours/tool_selection.py: bafybeienlxcgjs3ogyofli3d7q3p5rst3mcxxcnwqf7qolqjeefjtixeke
dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm
fsm_specification.yaml: bafybeiabt2fonv63hozgr7bt4d5auom76iufzh6etpnmbwekktckz7644a
handlers.py: bafybeigod6gbjrxy4mbmulbzsbokeaoycoqys64vqtxnumishfukzf73za
handlers.py: bafybeie7rhzjgbrmlc3iu6v4rkwkxpix3metov3pzutbkzc5uwcrt47mqq
io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq
io_/loader.py: bafybeih3sdsx5dhe4kzhtoafexjgkutsujwqy3zcdrlrkhtdks45bc7exa
models.py: bafybeifhmwxoix5fqka4phtmv6324osei52zwirg3ogziondvlq33brnby
payloads.py: bafybeicloiy4ax7dlipwp4czlueflgjgtlev4a6vhn2m7ztoehnemiiko4
payloads.py: bafybeiflpde45x6zbthxv7c6p6kasju6j2ueqinr66gappc52gwz54vh5e
policy.py: bafybeihlzs4o5e7yfmfzcvvrzkf4bhxfsg5gxnzsrpepwgfugh45gafye4
redeem_info.py: bafybeifiiix4gihfo4avraxt34sfw35v6dqq45do2drrssei2shbps63mm
rounds.py: bafybeihczrvkid4lqoai7myqqs4f3g5diqsnjotxtqhxhm5c7oowzifbqy
states/__init__.py: bafybeid23llnyp6j257dluxmrnztugo5llsrog7kua53hllyktz4dqhqoy
states/base.py: bafybeicrzw6p4dq52adkdjlduplt3expzajqmd3nkcpsw5yalfc3dwv75q
states/bet_placement.py: bafybeibalhxhp2c4oljmiwqi6ds3g36fgtabmf42mb5sgq6z22znrcbhda
states/base.py: bafybeihjq3t43od4sf64rtsuwkrzrjqpngf3ekbefwyeoax5g6eg5sal2m
states/bet_placement.py: bafybeieq3bi2m4m5vclg4nmczqi62hlfp7ftixpamao22wuh4ulx4emlai
states/blacklisting.py: bafybeiapelgjhbjjn4uq4z5gspyirqzwzgccg5anktrp5kxdwamfnfw5mi
states/check_benchmarking.py: bafybeiabv6pq7q45jd3nkor5afmlycqgec5ctuwcfbdukkjjm4imesv4ni
states/claim_subscription.py: bafybeiampifhdoztggwj6gthl2hfzecmjcwnm6nic2o47q4je7j4x3ujne
states/decision_receive.py: bafybeicr7bxjbgzo4thqlsczsyebabhplfztkd3c3og3wm6cxhv56pad5q
states/decision_receive.py: bafybeid6b5dw2tqdojteezx4l23ahkxvqxtx4bqefaqb4dufmhp2a5yc4e
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: bafybeihriyyskmlupjiwytx2pdpftms7plkjku5bip64c3ztx7oi3n43ci
Expand Down Expand Up @@ -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: {}
Expand Down Expand Up @@ -314,6 +315,7 @@ models:
priority_mech_service_id: 0
requester_staking_instance_address: '0x0000000000000000000000000000000000000000'
response_timeout: 300
agent_balance_threshold: 10000000000000000
class_name: DecisionMakerParams
benchmarking_mode:
args:
Expand Down
27 changes: 27 additions & 0 deletions packages/valory/skills/decision_maker_abci/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -230,6 +231,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."""
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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,
Expand All @@ -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[4]
sync_data = sync_data.update(wallet_balance=wallet_balance)
return sync_data, event
Loading