Skip to content

Commit

Permalink
Merge pull request #358 from valory-xyz/hotfix/staking-kpi-reachability
Browse files Browse the repository at this point in the history
Hotfix/staking kpi reachability
Adamantios authored Dec 16, 2024
2 parents 90a837d + b8190fc commit ff68801
Showing 26 changed files with 469 additions and 127 deletions.
18 changes: 9 additions & 9 deletions packages/packages.json
Original file line number Diff line number Diff line change
@@ -15,15 +15,15 @@
"contract/valory/mech_activity/0.1.0": "bafybeibmqmle5fnal3gxlpdmcos2kogzra4q3pr3o5nh7shplxuilji3t4",
"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": "bafybeig3sqaeqedobqdg7gynrxnbq2kgzh4gp5pe5gxo5kw4hczfjmj6e4",
"skill/valory/trader_abci/0.1.0": "bafybeigm2oqol7yvbspdapdrq3hxugybwmaazom773ncsyz6mlgps7y3pi",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibx63ico4nlp6etvtzgvlcrl3jdy6rx7zodwmxhvvb4phizd732l4",
"skill/valory/staking_abci/0.1.0": "bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeib75qrimmvensqmskdp5kzki5ijjwolqk2ojekeommakaf64mzn54",
"agent/valory/trader/0.1.0": "bafybeifwqory3yuyhi6sxkoy3ihyzdbus444pkehyoxiibjqo5mjcawbhe",
"service/valory/trader/0.1.0": "bafybeiezli7klgpvdlvdkh7wxmulyosp7f3xzmkmdtzrgtcloqdng5qcea",
"service/valory/trader_pearl/0.1.0": "bafybeic52jtgilmipang6wcr3ogbfyskwzb7iaat3lur5pe7fjkpkqc7da"
"skill/valory/market_manager_abci/0.1.0": "bafybeiaru2d32wpmcgqs64eepxud4idgubc3vmsbdwbia7gygipql2mmqi",
"skill/valory/decision_maker_abci/0.1.0": "bafybeiddnmcquiuznts67ridhpnaqw2y3rrt4nfau5kjm74zhk5lhjxi2q",
"skill/valory/trader_abci/0.1.0": "bafybeiemjz3ca7la7jkeqdr7hxo7fa77xe2fkfadzb53gdkji7abpl2eiu",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeietwknem7iiood6pwkfup322ywwjmdrmdapllrcms6jpeev5w2qfe",
"skill/valory/staking_abci/0.1.0": "bafybeicupccurmrg7qesivonlyt3nryarsmk5qf5yh6auno64wn45bybvq",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeieduekpd4zbvjztyxyooppqnmjvup6jfp74uo6hhupvtvzzscdzkq",
"agent/valory/trader/0.1.0": "bafybeihq257kwjybsvrpzhjx4wbretrsurodpckjqdhv3idlnbu4mqvfnq",
"service/valory/trader/0.1.0": "bafybeihr6m4lec5r6kuf2zikusgyqilqwhwlpyehufyndjuziylr73dlqe",
"service/valory/trader_pearl/0.1.0": "bafybeibfqhsrtekx6nvwpz2nbbjyobljcahe6wz6jikyebt7opzxlal45u"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
12 changes: 6 additions & 6 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
@@ -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:bafybeibx63ico4nlp6etvtzgvlcrl3jdy6rx7zodwmxhvvb4phizd732l4
- valory/market_manager_abci:0.1.0:bafybeicztk62pslofv6ui3aw3giw2tnvlfwfmatqbyvvzv4ampneu6isqa
- valory/decision_maker_abci:0.1.0:bafybeig3sqaeqedobqdg7gynrxnbq2kgzh4gp5pe5gxo5kw4hczfjmj6e4
- valory/trader_abci:0.1.0:bafybeigm2oqol7yvbspdapdrq3hxugybwmaazom773ncsyz6mlgps7y3pi
- valory/staking_abci:0.1.0:bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne
- valory/check_stop_trading_abci:0.1.0:bafybeib75qrimmvensqmskdp5kzki5ijjwolqk2ojekeommakaf64mzn54
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeietwknem7iiood6pwkfup322ywwjmdrmdapllrcms6jpeev5w2qfe
- valory/market_manager_abci:0.1.0:bafybeiaru2d32wpmcgqs64eepxud4idgubc3vmsbdwbia7gygipql2mmqi
- valory/decision_maker_abci:0.1.0:bafybeiddnmcquiuznts67ridhpnaqw2y3rrt4nfau5kjm74zhk5lhjxi2q
- valory/trader_abci:0.1.0:bafybeiemjz3ca7la7jkeqdr7hxo7fa77xe2fkfadzb53gdkji7abpl2eiu
- valory/staking_abci:0.1.0:bafybeicupccurmrg7qesivonlyt3nryarsmk5qf5yh6auno64wn45bybvq
- valory/check_stop_trading_abci:0.1.0:bafybeieduekpd4zbvjztyxyooppqnmjvup6jfp74uo6hhupvtvzzscdzkq
- valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm
customs:
- valory/mike_strat:0.1.0:bafybeihjiol7f4ch4piwfikurdtfwzsh6qydkbsztpbwbwb2yrqdqf726m
2 changes: 1 addition & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeifwqory3yuyhi6sxkoy3ihyzdbus444pkehyoxiibjqo5mjcawbhe
agent: valory/trader:0.1.0:bafybeihq257kwjybsvrpzhjx4wbretrsurodpckjqdhv3idlnbu4mqvfnq
number_of_agents: 4
deployment:
agent:
2 changes: 1 addition & 1 deletion packages/valory/services/trader_pearl/service.yaml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeifwqory3yuyhi6sxkoy3ihyzdbus444pkehyoxiibjqo5mjcawbhe
agent: valory/trader:0.1.0:bafybeihq257kwjybsvrpzhjx4wbretrsurodpckjqdhv3idlnbu4mqvfnq
number_of_agents: 1
deployment:
agent:
10 changes: 6 additions & 4 deletions packages/valory/skills/check_stop_trading_abci/behaviours.py
Original file line number Diff line number Diff line change
@@ -140,27 +140,29 @@ def is_staking_kpi_met(self) -> Generator[None, None, bool]:
return True
return False

def _compute_stop_trading(self) -> Generator:
def _compute_stop_trading(self) -> Generator[None, None, bool]:
# This is a "hacky" way of getting required data initialized on
# the Trader: On first period, the FSM needs to initialize some
# data on the trading branch so that it is available in the
# cross-period persistent keys.
if self.is_first_period:
self.context.logger.debug(f"{self.is_first_period=}")
yield # ensures this is a generator
return False

self.context.logger.debug(f"{self.params.disable_trading=}")
if self.params.disable_trading:
yield # ensures this is a generator
return True

stop_trading_conditions = []
self.context.logger.debug(f"{self.params.stop_trading_if_staking_kpi_met=}")
if self.params.stop_trading_if_staking_kpi_met:
staking_kpi_met = yield from self.is_staking_kpi_met()
self.context.logger.debug(f"{staking_kpi_met=}")
stop_trading_conditions.append(staking_kpi_met)
return staking_kpi_met

return any(stop_trading_conditions)
yield
return False

def async_act(self) -> Generator:
"""Do the action."""
4 changes: 2 additions & 2 deletions packages/valory/skills/check_stop_trading_abci/skill.yaml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
README.md: bafybeif2pq7fg5upl6vmfgfzpiwsh4nbk4zaeyz6upyucqi5tasrxgq4ee
__init__.py: bafybeifc23rlw2hzhplp3wfceixnmwq5ztnixhh7jp4dd5av3crwp3x22a
behaviours.py: bafybeifdfqkczchnbfzzb4q2gwe3qqrn5ci2tk4mq65bunivjkw4scuzse
behaviours.py: bafybeie5mkpxsd6z3vjsoacvswin6zz4q4um5gqp6jhwtn65fepx2kma3m
dialogues.py: bafybeictrrnwcijiejczy23dfvbx5kujgef3dulzqhs3etl2juvz5spm2e
fsm_specification.yaml: bafybeihhau35a5xclncjpxh5lg7qiw34xs4d5qlez7dnjpkf45d3gc57ai
handlers.py: bafybeiard64fwxib3rtyp67ymhf222uongcyqhfhdyttpsyqkmyh5ajipu
@@ -27,7 +27,7 @@ contracts:
protocols: []
skills:
- valory/abstract_round_abci:0.1.0:bafybeib733xfbndtpvkf44mtk7oyodnficgloo6xhn7xmqxxeos33es65u
- valory/staking_abci:0.1.0:bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne
- valory/staking_abci:0.1.0:bafybeicupccurmrg7qesivonlyt3nryarsmk5qf5yh6auno64wn45bybvq
behaviours:
main:
args: {}
16 changes: 16 additions & 0 deletions packages/valory/skills/decision_maker_abci/behaviours/base.py
Original file line number Diff line number Diff line change
@@ -351,6 +351,22 @@ def check_balance(self) -> WaitableConditionType:
self._report_balance()
return True

def update_bet_transaction_information(self) -> None:
"""Get whether the bet's invested amount should be updated."""
sampled_bet = self.sampled_bet
# Update the bet's invested amount, the new bet amount is added to previously invested amount
sampled_bet.invested_amount += self.synchronized_data.bet_amount
# Update bet transaction timestamp
sampled_bet.processed_timestamp = self.synced_timestamp
# update no of bets made
sampled_bet.n_bets += 1
# Update Queue number for priority logic
sampled_bet.queue_status = sampled_bet.queue_status.next_status()

# the bets are stored here, but we do not update the hash in the synced db in the redeeming round
# this will need to change if this sovereign agent is ever converted to a multi-agent service
self.store_bets()

def send_message(
self, msg: Message, dialogue: Dialogue, callback: Callable
) -> None:
Original file line number Diff line number Diff line change
@@ -45,9 +45,10 @@ def _blacklist(self) -> None:
"""Blacklist the sampled bet."""
sampled_bet_index = self.synchronized_data.sampled_bet_index
sampled_bet = self.bets[sampled_bet_index]

# the question is blacklisted, i.e., we did not place a bet on it,
# therefore, we decrease the number of bets which was increased on sampling
sampled_bet.n_bets -= 1
# therefore, we bump to the queue status to next status
sampled_bet.queue_status = sampled_bet.queue_status.next_status()

def setup(self) -> None:
"""Setup the behaviour"""
Original file line number Diff line number Diff line change
@@ -508,25 +508,18 @@ def _update_selected_bet(
) -> None:
"""Update the selected bet."""
# update the bet's timestamp of processing and its number of bets for the given id
if self.benchmarking_mode.enabled:
active_sampled_bet = self.get_active_sampled_bet()
active_sampled_bet.processed_timestamp = (
self.shared_state.get_simulated_now_timestamp(
self.bets, self.params.safe_voting_range
)
)
self.context.logger.info(f"Updating bet id: {active_sampled_bet.id}")
self.context.logger.info(
f"with the timestamp:{datetime.fromtimestamp(active_sampled_bet.processed_timestamp)}"
active_sampled_bet = self.get_active_sampled_bet()
active_sampled_bet.processed_timestamp = (
self.shared_state.get_simulated_now_timestamp(
self.bets, self.params.safe_voting_range
)
if prediction_response is not None:
active_sampled_bet.n_bets += 1

else:
# update the bet's timestamp of processing and its number of bets for the given
sampled_bet = self.sampled_bet
sampled_bet.n_bets += 1
sampled_bet.processed_timestamp = self.synced_timestamp
)
self.context.logger.info(f"Updating bet id: {active_sampled_bet.id}")
self.context.logger.info(
f"with the timestamp:{datetime.fromtimestamp(active_sampled_bet.processed_timestamp)}"
)
if prediction_response is not None:
active_sampled_bet.n_bets += 1

self.store_bets()

@@ -558,6 +551,7 @@ def async_act(self) -> Generator:
prediction_response,
bet_amount,
)

# always remove the processed trade from the benchmarking input file
# now there is one reader pointer per market
if self.benchmarking_mode.enabled:
@@ -568,7 +562,8 @@ def async_act(self) -> Generator:
if rows_queue:
rows_queue.pop(0)

self._update_selected_bet(prediction_response)
self._update_selected_bet(prediction_response)

payload = DecisionReceivePayload(
self.context.agent_address,
bets_hash,
14 changes: 14 additions & 0 deletions packages/valory/skills/decision_maker_abci/behaviours/reedem.py
Original file line number Diff line number Diff line change
@@ -52,6 +52,9 @@
FPMM,
Trade,
)
from packages.valory.skills.decision_maker_abci.states.bet_placement import (
BetPlacementRound,
)
from packages.valory.skills.decision_maker_abci.states.redeem import RedeemRound
from packages.valory.skills.market_manager_abci.graph_tooling.requests import (
FetchStatus,
@@ -970,6 +973,17 @@ def async_act(self) -> Generator:
if self.benchmarking_mode.enabled:
payload = self._benchmarking_act()
else:
# Checking if the last round that submitted the transaction was the bet placement round
# If so, we need to update the bet transaction information, because the transaction was successful
# tx settlement multiplexer assures transitions from Post transaction to Redeem round
# only if the transaction was successful
if (
self.synchronized_data.did_transact
and self.synchronized_data.tx_submitter
== BetPlacementRound.auto_round_id()
):
self.update_bet_transaction_information()

payload = yield from self._normal_act()
if payload is None:
return
Loading

0 comments on commit ff68801

Please sign in to comment.