diff --git a/docs/index.md b/docs/index.md index 97e9efeb..e792f19c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -31,7 +31,7 @@ In order to run a local demo service based on the IEKit: 2. Fetch the IEKit. ```bash - autonomy fetch valory/impact_evaluator:0.1.0:bafybeidzr3n2pm26sqa64bkhi2h6gqv5aucx2pn5hny4ywaebey7v6bnh4 --service + autonomy fetch valory/impact_evaluator:0.1.0:bafybeidsxutduw7l6xls4a67hgzkzqigujssjl2cfw76q3lvulbjx2lqm4 --service ``` 3. Build the Docker image of the service agents diff --git a/packages/packages.json b/packages/packages.json index f0f123a1..a606b7d3 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -14,24 +14,24 @@ "connection/valory/twitter/0.1.0": "bafybeiffqsvt3i37sd5qdsmpzf5i4hm37uosbobyogg5oyosovjs66buni", "connection/valory/openai/0.1.0": "bafybeifz2n6s6u3zvvryhhxpkvn6guyp2jwpagtyjducvgwoldtmz7ea64", "connection/valory/farcaster/0.1.0": "bafybeibbdas7lxbipksodaphjms3uop7vnzjqkroktjq2g6wbvgtlldaxi", - "skill/valory/dynamic_nft_abci/0.1.0": "bafybeia3yjwypbvnhjgr2qgx43xl4fteir3j3vh3sdhk3fmf4jktdjx7ou", - "skill/valory/twitter_scoring_abci/0.1.0": "bafybeigez4zzhncyuu7kap3xagps7o27q7kr44gdw6vvsngtav6pyjrqje", + "skill/valory/dynamic_nft_abci/0.1.0": "bafybeiclvgzmipwshjc6surbn4dspckcaajqlaig5b2x2i634qrzpbcohu", + "skill/valory/twitter_scoring_abci/0.1.0": "bafybeicyd6inmijhqivrtugw6ny4gqg25swytouq23akqfcsndwvtccofu", "skill/valory/ceramic_read_abci/0.1.0": "bafybeigz7rzfls3niv3urfb4z4vwr525ooxveelgg3djpvkg5jzetxlm2u", "skill/valory/ceramic_write_abci/0.1.0": "bafybeic6c3iub3nsr5tmr7g5vzoixbin6w64ewudfiq6u4r2fiqwbg753i", - "skill/valory/impact_evaluator_abci/0.1.0": "bafybeifzzvojqpvrwsltvzy7xin4janryewgyx5lqgtwj4wslgtszbbdrq", - "skill/valory/generic_scoring_abci/0.1.0": "bafybeif2qxifbqimm6jxejbt4a7vj7zmz2vf2tckvmtn6j6r3ly6thknve", + "skill/valory/impact_evaluator_abci/0.1.0": "bafybeie4d45tej22xdxr57din6bkik7bhhkslnz4jzmx5ijrsu7jxxrelm", + "skill/valory/generic_scoring_abci/0.1.0": "bafybeib4s7nljlbj4m4ruqcpstqlts4phklmn3j5iqm5nx57aus5bcw47i", "skill/valory/twitter_write_abci/0.1.0": "bafybeibp7zai2qwvfjd5fgpayx44x5c2zshbukpobvz2la7ws2l5f5fjde", "skill/valory/llm_abci/0.1.0": "bafybeib2k62hilwglfad33bzxkjlviw5bxwiw7z3rjvweyeamatdjznpeq", - "skill/valory/decision_making_abci/0.1.0": "bafybeigpp4vqsu73m23hfg4v4iqbbtejzpd32j3fooxrxdrz4aqa3xqbuq", - "skill/valory/olas_week_abci/0.1.0": "bafybeibautjon3yns7t6fdzrbmsa2jr6witwgkwfyoosw22ydqcgw7c4mu", + "skill/valory/decision_making_abci/0.1.0": "bafybeifbzj62j4dxaunuvvbo5lkvsp2fkajwp3rk2rcoigvl2cdywu5uw4", + "skill/valory/olas_week_abci/0.1.0": "bafybeibtlcammnitcogyg5gikxdvgcqz2bqdwjqqncbnjhbqnt533dzcgm", "skill/valory/mech_interact_abci/0.1.0": "bafybeicpskytv7osu6bdpmcweemlsb4f3m6gldzpyoxgawkczsmvlrzgma", "skill/valory/farcaster_write_abci/0.1.0": "bafybeigx2wyujnojer7er7g2eufm5lojon2dckotvsgwb6tn5iyiwdfgsu", "skill/valory/farcaster_test_abci/0.1.0": "bafybeihd3h37ngkxlqo6o3vuvdik54bwmbrjmqcxtgsr5is3tqgbk73yoa", - "skill/valory/staking_abci/0.1.0": "bafybeih5gh2w7t2osw2ljuj2nwefj45gmeageddb26bfjj3vzbwaska5rq", - "agent/valory/impact_evaluator/0.1.0": "bafybeifknacvwatg755hne2ykcpdygvrgdrbmhtmtajrs53hs5u4anksey", + "skill/valory/staking_abci/0.1.0": "bafybeicb6hrw7f5f3dcrxgwir3wviwg44w3ncvkqszuq7jfqfqyzjc352y", + "agent/valory/impact_evaluator/0.1.0": "bafybeifyc5pbogilpr63osvmcqoaq4m5jy2faa7xuvjby2i53ciqvm4lfy", "agent/valory/farcaster_test/0.1.0": "bafybeiefui6dnhhy5leqyvfrbkeleb64gap5tzctkrzzggjf4ubbxamjvy", - "service/valory/impact_evaluator/0.1.0": "bafybeidzr3n2pm26sqa64bkhi2h6gqv5aucx2pn5hny4ywaebey7v6bnh4", - "service/valory/impact_evaluator_local/0.1.0": "bafybeic25xlo37pve7dnrpguxs5dxmqh2zg4pormr3xdifboslce3zfcli" + "service/valory/impact_evaluator/0.1.0": "bafybeidsxutduw7l6xls4a67hgzkzqigujssjl2cfw76q3lvulbjx2lqm4", + "service/valory/impact_evaluator_local/0.1.0": "bafybeifxdgelvaapk3777er3onnffinwjzqdvh34kianhbkwgcuifurwv4" }, "third_party": { "protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi", diff --git a/packages/valory/agents/impact_evaluator/aea-config.yaml b/packages/valory/agents/impact_evaluator/aea-config.yaml index 21506837..5efcaa61 100644 --- a/packages/valory/agents/impact_evaluator/aea-config.yaml +++ b/packages/valory/agents/impact_evaluator/aea-config.yaml @@ -45,22 +45,22 @@ protocols: skills: - valory/abstract_abci:0.1.0:bafybeieo7pe5wqjphs5izpz5aujjbubymlxub62b3rhx6yglu65ibalffu - valory/abstract_round_abci:0.1.0:bafybeibiw4oqwqvo4jccwz5fb73iardzychgvcl66tceiildohoju2ikti -- valory/impact_evaluator_abci:0.1.0:bafybeifzzvojqpvrwsltvzy7xin4janryewgyx5lqgtwj4wslgtszbbdrq -- valory/generic_scoring_abci:0.1.0:bafybeif2qxifbqimm6jxejbt4a7vj7zmz2vf2tckvmtn6j6r3ly6thknve -- valory/twitter_scoring_abci:0.1.0:bafybeigez4zzhncyuu7kap3xagps7o27q7kr44gdw6vvsngtav6pyjrqje +- valory/impact_evaluator_abci:0.1.0:bafybeie4d45tej22xdxr57din6bkik7bhhkslnz4jzmx5ijrsu7jxxrelm +- valory/generic_scoring_abci:0.1.0:bafybeib4s7nljlbj4m4ruqcpstqlts4phklmn3j5iqm5nx57aus5bcw47i +- valory/twitter_scoring_abci:0.1.0:bafybeicyd6inmijhqivrtugw6ny4gqg25swytouq23akqfcsndwvtccofu - valory/ceramic_read_abci:0.1.0:bafybeigz7rzfls3niv3urfb4z4vwr525ooxveelgg3djpvkg5jzetxlm2u - valory/ceramic_write_abci:0.1.0:bafybeic6c3iub3nsr5tmr7g5vzoixbin6w64ewudfiq6u4r2fiqwbg753i -- valory/dynamic_nft_abci:0.1.0:bafybeia3yjwypbvnhjgr2qgx43xl4fteir3j3vh3sdhk3fmf4jktdjx7ou +- valory/dynamic_nft_abci:0.1.0:bafybeiclvgzmipwshjc6surbn4dspckcaajqlaig5b2x2i634qrzpbcohu - valory/registration_abci:0.1.0:bafybeib3n6vqkfbrcubcbliebjnuwyywdinxkbzt76n6gbn2kg7ace47dq - valory/reset_pause_abci:0.1.0:bafybeihkj6lmaypspyxe5qqrjgnolyck62pyvqoylr24ab6ue4steqcw7e - valory/termination_abci:0.1.0:bafybeifi2uodnrjsrivj53g3sjutocmyusbx6mlsb6oanqdyt2mfbyvusy - valory/transaction_settlement_abci:0.1.0:bafybeigh2vkt74jrad5gtsczrgqcuhcqe7jkgjy7jdw56yamlzwwnaymjy - valory/twitter_write_abci:0.1.0:bafybeibp7zai2qwvfjd5fgpayx44x5c2zshbukpobvz2la7ws2l5f5fjde -- valory/decision_making_abci:0.1.0:bafybeigpp4vqsu73m23hfg4v4iqbbtejzpd32j3fooxrxdrz4aqa3xqbuq +- valory/decision_making_abci:0.1.0:bafybeifbzj62j4dxaunuvvbo5lkvsp2fkajwp3rk2rcoigvl2cdywu5uw4 - valory/llm_abci:0.1.0:bafybeib2k62hilwglfad33bzxkjlviw5bxwiw7z3rjvweyeamatdjznpeq -- valory/olas_week_abci:0.1.0:bafybeibautjon3yns7t6fdzrbmsa2jr6witwgkwfyoosw22ydqcgw7c4mu +- valory/olas_week_abci:0.1.0:bafybeibtlcammnitcogyg5gikxdvgcqz2bqdwjqqncbnjhbqnt533dzcgm - valory/mech_interact_abci:0.1.0:bafybeicpskytv7osu6bdpmcweemlsb4f3m6gldzpyoxgawkczsmvlrzgma -- valory/staking_abci:0.1.0:bafybeih5gh2w7t2osw2ljuj2nwefj45gmeageddb26bfjj3vzbwaska5rq +- valory/staking_abci:0.1.0:bafybeicb6hrw7f5f3dcrxgwir3wviwg44w3ncvkqszuq7jfqfqyzjc352y default_ledger: ethereum required_ledgers: - ethereum diff --git a/packages/valory/services/impact_evaluator/service.yaml b/packages/valory/services/impact_evaluator/service.yaml index 36f39d92..b9547d0a 100644 --- a/packages/valory/services/impact_evaluator/service.yaml +++ b/packages/valory/services/impact_evaluator/service.yaml @@ -8,7 +8,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeign56hilwuoa6bgos3uqabss4gew4vadkik7vhj3ucpqw6nxtqtpe fingerprint_ignore_patterns: [] -agent: valory/impact_evaluator:0.1.0:bafybeifknacvwatg755hne2ykcpdygvrgdrbmhtmtajrs53hs5u4anksey +agent: valory/impact_evaluator:0.1.0:bafybeifyc5pbogilpr63osvmcqoaq4m5jy2faa7xuvjby2i53ciqvm4lfy number_of_agents: 4 deployment: agent: diff --git a/packages/valory/services/impact_evaluator_local/service.yaml b/packages/valory/services/impact_evaluator_local/service.yaml index cd93970e..5a9fa9cf 100644 --- a/packages/valory/services/impact_evaluator_local/service.yaml +++ b/packages/valory/services/impact_evaluator_local/service.yaml @@ -8,7 +8,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeign56hilwuoa6bgos3uqabss4gew4vadkik7vhj3ucpqw6nxtqtpe fingerprint_ignore_patterns: [] -agent: valory/impact_evaluator:0.1.0:bafybeifknacvwatg755hne2ykcpdygvrgdrbmhtmtajrs53hs5u4anksey +agent: valory/impact_evaluator:0.1.0:bafybeifyc5pbogilpr63osvmcqoaq4m5jy2faa7xuvjby2i53ciqvm4lfy number_of_agents: 1 deployment: agent: diff --git a/packages/valory/skills/decision_making_abci/skill.yaml b/packages/valory/skills/decision_making_abci/skill.yaml index bb2757ad..c1c60d5a 100644 --- a/packages/valory/skills/decision_making_abci/skill.yaml +++ b/packages/valory/skills/decision_making_abci/skill.yaml @@ -20,7 +20,7 @@ fingerprint: tasks/read_stream_preparation.py: bafybeicmjasiyecopfweobodzbmn3tbluu5q724uzzqkit6urn3lb5q354 tasks/score_preparations.py: bafybeie7cfot24zcyod5becz6t5lasvva77httfkw57qmvgjk35d3qluxa tasks/signature_validation.py: bafybeihbwrv72hnh3ytko2i5oszqgdky2j6h2wse45wvuhf2j32lo2tsjy - tasks/staking.py: bafybeih3fmaffmhscfysjyascqgqgr3to4vzpq6rbx6y4byaag3q6gcqnm + tasks/staking.py: bafybeiffboqqerm7iltlb6qkjxfehr3bwb4mljp4rlff6wuba3qhgadghu tasks/task_preparations.py: bafybeihfm3ms665fvz2qwmhmcwgl2ws5mt62pykomowoxpm6a46jlqvsmu tasks/tweet_validation_preparation.py: bafybeif3wbfskiyuij7unx72euklms7owrzwzgdu462xatvypalm6xrgca tasks/twitter_preparation.py: bafybeicn7stcvmd6oex55dwptwxpikpssbcwnj2d3xkercikg5nlzqh4k4 @@ -58,7 +58,7 @@ protocols: skills: - valory/abstract_round_abci:0.1.0:bafybeibiw4oqwqvo4jccwz5fb73iardzychgvcl66tceiildohoju2ikti - valory/ceramic_read_abci:0.1.0:bafybeigz7rzfls3niv3urfb4z4vwr525ooxveelgg3djpvkg5jzetxlm2u -- valory/staking_abci:0.1.0:bafybeih5gh2w7t2osw2ljuj2nwefj45gmeageddb26bfjj3vzbwaska5rq +- valory/staking_abci:0.1.0:bafybeicb6hrw7f5f3dcrxgwir3wviwg44w3ncvkqszuq7jfqfqyzjc352y behaviours: main: args: {} diff --git a/packages/valory/skills/decision_making_abci/tasks/staking.py b/packages/valory/skills/decision_making_abci/tasks/staking.py index 1162dd4d..2437c6a1 100644 --- a/packages/valory/skills/decision_making_abci/tasks/staking.py +++ b/packages/valory/skills/decision_making_abci/tasks/staking.py @@ -39,55 +39,6 @@ class StakingPreparation(TaskPreparation): task_name = None - def check_extra_conditions(self): - """Check whether it is time to call the checkpoint""" - - # This check is common for both the activity tracking and the checkpoint - # because we want to ensure we always call activity tracking just right before we call the checkpoint - yield - - # Ensure we are getting the last run for the checkpoint call. - # This method is used by both the checkpoint and activity tasks. - # Activity is called everytime we are about to call the checkpoint, - # so we need to refer last_run to the checkpoint always. - checkpoint_config = self.synchronized_data.centaurs_data[ - self.synchronized_data.current_centaur_index - ]["configuration"]["plugins"]["staking_checkpoint"] - - checkpoint_last_run = ( - datetime.strptime( - checkpoint_config["last_run"], "%Y-%m-%d %H:%M:%S %Z" - ).replace(tzinfo=timezone.utc) - if checkpoint_config.get("last_run", None) - else None - ) - - # If too much time has passed since last checkpoint execution, we run the staking skill - minutes_since_last_checkpoint_run = ( - (self.now_utc - checkpoint_last_run).total_seconds() / 60 - if checkpoint_last_run - else None - ) - if ( - minutes_since_last_checkpoint_run is None - or minutes_since_last_checkpoint_run - > self.params.checkpoint_threshold_minutes - ): - self.context.logger.info( - f"Too much time ({minutes_since_last_checkpoint_run}) has passed since last checkpoint execution." - ) - return True - - # If the epoch is about to end, we run the staking skill - for staking_contract_address in self.params.staking_contract_addresses: - has_epoch_ended = yield from self.has_epoch_ended(staking_contract_address) - if has_epoch_ended: - self.context.logger.info("Epoch has ended.") - return True - - self.context.logger.info("Not time to call the checkpoint yet.") - return False - def _pre_task(self): """Preparations before running the task""" yield @@ -137,7 +88,6 @@ def is_epoch_ending(self, staking_contract_address) -> Generator[None, None, boo if not epoch_end: return False - # Should not happen, but if the epoch has ended, we do not care about calling if self.now_utc > epoch_end: return False @@ -147,7 +97,9 @@ def is_epoch_ending(self, staking_contract_address) -> Generator[None, None, boo return is_epoch_ending - def has_epoch_ended(self, staking_contract_address) -> Generator[None, None, bool]: + def is_checkpoint_callable( + self, staking_contract_address + ) -> Generator[None, None, bool]: """Check if the epoch has ended""" epoch_end = yield from self.get_epoch_end(staking_contract_address) @@ -187,12 +139,16 @@ def check_extra_conditions(self): ) return True - # If the checkpoint is about to be called and there's pending updates, we run the activity update - is_checkpoint_ready = yield from super().check_extra_conditions() - if is_checkpoint_ready and pending_updates > 0: - self.context.logger.info( - "The checkpoint is about to be called. Executing..." - ) + # If there's some pending updates and the epoch is ending, we run the activity update + is_some_epoch_ending = False + for staking_contract_address in self.params.staking_contract_addresses: + is_epoch_ending = yield from self.is_epoch_ending(staking_contract_address) + if is_epoch_ending: + is_some_epoch_ending = True + break + + if pending_updates > 0 and is_some_epoch_ending: + self.context.logger.info("Some epoch is ending. Executing...") return True self.context.logger.info( @@ -207,3 +163,21 @@ class StakingCheckpointPreparation(StakingPreparation): task_name = "staking_checkpoint" task_event = Event.STAKING_CHECKPOINT.value + + def check_extra_conditions(self): + """Check whether it is time to call the checkpoint""" + + yield + + for staking_contract_address in self.params.staking_contract_addresses: + is_checkpoint_callable = yield from self.is_checkpoint_callable( + staking_contract_address + ) + if is_checkpoint_callable: + self.context.logger.info( + f"Epoch has ended for contract {staking_contract_address} and no one called the checkpoint yet." + ) + return True + + self.context.logger.info("Not time to call the checkpoint yet.") + return False diff --git a/packages/valory/skills/dynamic_nft_abci/skill.yaml b/packages/valory/skills/dynamic_nft_abci/skill.yaml index 74326bcf..eee1e8fe 100644 --- a/packages/valory/skills/dynamic_nft_abci/skill.yaml +++ b/packages/valory/skills/dynamic_nft_abci/skill.yaml @@ -31,7 +31,7 @@ protocols: - valory/http:1.0.0:bafybeifugzl63kfdmwrxwphrnrhj7bn6iruxieme3a4ntzejf6kmtuwmae skills: - valory/abstract_round_abci:0.1.0:bafybeibiw4oqwqvo4jccwz5fb73iardzychgvcl66tceiildohoju2ikti -- valory/decision_making_abci:0.1.0:bafybeigpp4vqsu73m23hfg4v4iqbbtejzpd32j3fooxrxdrz4aqa3xqbuq +- valory/decision_making_abci:0.1.0:bafybeifbzj62j4dxaunuvvbo5lkvsp2fkajwp3rk2rcoigvl2cdywu5uw4 behaviours: main: args: {} diff --git a/packages/valory/skills/generic_scoring_abci/skill.yaml b/packages/valory/skills/generic_scoring_abci/skill.yaml index bc1d39e8..1de08107 100644 --- a/packages/valory/skills/generic_scoring_abci/skill.yaml +++ b/packages/valory/skills/generic_scoring_abci/skill.yaml @@ -28,7 +28,7 @@ contracts: [] protocols: [] skills: - valory/abstract_round_abci:0.1.0:bafybeibiw4oqwqvo4jccwz5fb73iardzychgvcl66tceiildohoju2ikti -- valory/decision_making_abci:0.1.0:bafybeigpp4vqsu73m23hfg4v4iqbbtejzpd32j3fooxrxdrz4aqa3xqbuq +- valory/decision_making_abci:0.1.0:bafybeifbzj62j4dxaunuvvbo5lkvsp2fkajwp3rk2rcoigvl2cdywu5uw4 behaviours: main: args: {} diff --git a/packages/valory/skills/impact_evaluator_abci/skill.yaml b/packages/valory/skills/impact_evaluator_abci/skill.yaml index c69dd77d..f56de563 100644 --- a/packages/valory/skills/impact_evaluator_abci/skill.yaml +++ b/packages/valory/skills/impact_evaluator_abci/skill.yaml @@ -25,20 +25,20 @@ protocols: [] skills: - valory/abstract_round_abci:0.1.0:bafybeibiw4oqwqvo4jccwz5fb73iardzychgvcl66tceiildohoju2ikti - valory/ceramic_read_abci:0.1.0:bafybeigz7rzfls3niv3urfb4z4vwr525ooxveelgg3djpvkg5jzetxlm2u -- valory/generic_scoring_abci:0.1.0:bafybeif2qxifbqimm6jxejbt4a7vj7zmz2vf2tckvmtn6j6r3ly6thknve -- valory/twitter_scoring_abci:0.1.0:bafybeigez4zzhncyuu7kap3xagps7o27q7kr44gdw6vvsngtav6pyjrqje +- valory/generic_scoring_abci:0.1.0:bafybeib4s7nljlbj4m4ruqcpstqlts4phklmn3j5iqm5nx57aus5bcw47i +- valory/twitter_scoring_abci:0.1.0:bafybeicyd6inmijhqivrtugw6ny4gqg25swytouq23akqfcsndwvtccofu - valory/ceramic_write_abci:0.1.0:bafybeic6c3iub3nsr5tmr7g5vzoixbin6w64ewudfiq6u4r2fiqwbg753i -- valory/dynamic_nft_abci:0.1.0:bafybeia3yjwypbvnhjgr2qgx43xl4fteir3j3vh3sdhk3fmf4jktdjx7ou +- valory/dynamic_nft_abci:0.1.0:bafybeiclvgzmipwshjc6surbn4dspckcaajqlaig5b2x2i634qrzpbcohu - valory/registration_abci:0.1.0:bafybeib3n6vqkfbrcubcbliebjnuwyywdinxkbzt76n6gbn2kg7ace47dq - valory/reset_pause_abci:0.1.0:bafybeihkj6lmaypspyxe5qqrjgnolyck62pyvqoylr24ab6ue4steqcw7e - valory/termination_abci:0.1.0:bafybeifi2uodnrjsrivj53g3sjutocmyusbx6mlsb6oanqdyt2mfbyvusy - valory/transaction_settlement_abci:0.1.0:bafybeigh2vkt74jrad5gtsczrgqcuhcqe7jkgjy7jdw56yamlzwwnaymjy -- valory/decision_making_abci:0.1.0:bafybeigpp4vqsu73m23hfg4v4iqbbtejzpd32j3fooxrxdrz4aqa3xqbuq +- valory/decision_making_abci:0.1.0:bafybeifbzj62j4dxaunuvvbo5lkvsp2fkajwp3rk2rcoigvl2cdywu5uw4 - valory/llm_abci:0.1.0:bafybeib2k62hilwglfad33bzxkjlviw5bxwiw7z3rjvweyeamatdjznpeq - valory/twitter_write_abci:0.1.0:bafybeibp7zai2qwvfjd5fgpayx44x5c2zshbukpobvz2la7ws2l5f5fjde -- valory/olas_week_abci:0.1.0:bafybeibautjon3yns7t6fdzrbmsa2jr6witwgkwfyoosw22ydqcgw7c4mu +- valory/olas_week_abci:0.1.0:bafybeibtlcammnitcogyg5gikxdvgcqz2bqdwjqqncbnjhbqnt533dzcgm - valory/mech_interact_abci:0.1.0:bafybeicpskytv7osu6bdpmcweemlsb4f3m6gldzpyoxgawkczsmvlrzgma -- valory/staking_abci:0.1.0:bafybeih5gh2w7t2osw2ljuj2nwefj45gmeageddb26bfjj3vzbwaska5rq +- valory/staking_abci:0.1.0:bafybeicb6hrw7f5f3dcrxgwir3wviwg44w3ncvkqszuq7jfqfqyzjc352y behaviours: main: args: {} diff --git a/packages/valory/skills/olas_week_abci/skill.yaml b/packages/valory/skills/olas_week_abci/skill.yaml index 2fd4b571..08066828 100644 --- a/packages/valory/skills/olas_week_abci/skill.yaml +++ b/packages/valory/skills/olas_week_abci/skill.yaml @@ -31,7 +31,7 @@ protocols: - valory/llm:1.0.0:bafybeihj2orqapokafg7co3wlogwgf6cckaaj2bz3nuv4rm3opkoyhrlp4 skills: - valory/abstract_round_abci:0.1.0:bafybeibiw4oqwqvo4jccwz5fb73iardzychgvcl66tceiildohoju2ikti -- valory/decision_making_abci:0.1.0:bafybeigpp4vqsu73m23hfg4v4iqbbtejzpd32j3fooxrxdrz4aqa3xqbuq +- valory/decision_making_abci:0.1.0:bafybeifbzj62j4dxaunuvvbo5lkvsp2fkajwp3rk2rcoigvl2cdywu5uw4 behaviours: main: args: {} diff --git a/packages/valory/skills/staking_abci/behaviours.py b/packages/valory/skills/staking_abci/behaviours.py index 2a0e653b..6e4a8bbc 100644 --- a/packages/valory/skills/staking_abci/behaviours.py +++ b/packages/valory/skills/staking_abci/behaviours.py @@ -21,6 +21,7 @@ import json from abc import ABC +from datetime import datetime, timezone from typing import Dict, Generator, List, Optional, Set, Tuple, Type, cast from packages.valory.contracts.gnosis_safe.contract import ( @@ -38,7 +39,7 @@ AbstractRoundBehaviour, BaseBehaviour, ) -from packages.valory.skills.staking_abci.models import Params +from packages.valory.skills.staking_abci.models import Params, SharedState from packages.valory.skills.staking_abci.rounds import ( ActivityScorePayload, ActivityScoreRound, @@ -111,6 +112,10 @@ def params(self) -> Params: """Return the params.""" return cast(Params, super().params) + @property + def local_state(self) -> SharedState: + """Return the state.""" + return cast(SharedState, self.context.state) def _build_safe_tx_hash( self, @@ -195,6 +200,55 @@ def get_staked_services(self, staking_contract_address: str) -> Generator[None, return service_ids + def _get_utc_time(self): + """Check if it is process time""" + now_utc = self.local_state.round_sequence.last_round_transition_timestamp + + # Tendermint timestamps are expected to be UTC, but for some reason + # we are getting local time. We replace the hour and timezone. + # TODO: this hour replacement could be problematic in some time zones + now_utc = now_utc.replace( + hour=datetime.now(timezone.utc).hour, tzinfo=timezone.utc + ) + now_utc_str = now_utc.strftime("%Y-%m-%d %H:%M:%S %Z") + self.context.logger.info(f"Now [UTC]: {now_utc_str}") + + return now_utc + + def get_epoch_end( + self, staking_contract_address + ) -> Generator[None, None, Optional[datetime]]: + """Get the epoch end""" + + contract_api_msg = yield from self.get_contract_api_response( + performative=ContractApiMessage.Performative.GET_STATE, # type: ignore + contract_address=staking_contract_address, + contract_id=str(Staking.contract_id), + contract_callable="get_epoch_end", + chain_id=BASE_CHAIN_ID, + ) + if contract_api_msg.performative != ContractApiMessage.Performative.STATE: + self.context.logger.error( + f"Error getting the epoch end: [{contract_api_msg.performative}]" + ) + return None + + epoch_end_ts = cast(int, contract_api_msg.state.body["epoch_end"]) + epoch_end = datetime.fromtimestamp(epoch_end_ts, tz=timezone.utc) + return epoch_end + + def is_checkpoint_callable(self, staking_contract_address) -> Generator[None, None, bool]: + """Check if the epoch has ended""" + epoch_end = yield from self.get_epoch_end(staking_contract_address) + + if not epoch_end: + return False + + # If the epoch end is in the past, the epoch has ended and + # no one has called the checkpoint + return epoch_end < self._get_utc_time() + + class ActivityScoreBehaviour(StakingBaseBehaviour): """ActivityScoreBehaviour""" @@ -352,6 +406,11 @@ def get_checkpoint_hash(self) -> Generator[None, None, Optional[str]]: if not services_staked: continue + # Check if this checkpoint needs to be called + is_checkpoint_callable = yield from self.is_checkpoint_callable(staking_contract_address) + if not is_checkpoint_callable: + continue + # Use the contract api to interact with the staking contract response_msg = yield from self.get_contract_api_response( performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore diff --git a/packages/valory/skills/staking_abci/skill.yaml b/packages/valory/skills/staking_abci/skill.yaml index 3f204688..2dd9fc33 100644 --- a/packages/valory/skills/staking_abci/skill.yaml +++ b/packages/valory/skills/staking_abci/skill.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 aea_version: '>=1.0.0, <2.0.0' fingerprint: __init__.py: bafybeie3oujhxxdr5s2lvc6cosbysezqycagw5mbwvxjw24k3dzcbtgg5m - behaviours.py: bafybeibqwtcr6ymxdqdurvplismu3tfxlmjjqtgts7huudktgif7dvfrvq + behaviours.py: bafybeiauzqxszxvo3heecygltjcq3yo4vdkgdefjpd4p5po4sjjvggrvkq dialogues.py: bafybeifmmpyiwetlcgykczsq4dgwvm7tipdupf2rwcndg5cmtm7jfoxwxm fsm_specification.yaml: bafybeidnl3i5e6xb7axpzg323xcj62rksrzvopuivcjnxkktcolanr2anu handlers.py: bafybeiaufft2fwbbjbbc77md6xkq7prnzzi2nkkm2fipapgx54myabmb7y diff --git a/packages/valory/skills/twitter_scoring_abci/skill.yaml b/packages/valory/skills/twitter_scoring_abci/skill.yaml index 37c1384d..fa8d9cbe 100644 --- a/packages/valory/skills/twitter_scoring_abci/skill.yaml +++ b/packages/valory/skills/twitter_scoring_abci/skill.yaml @@ -32,7 +32,7 @@ protocols: - valory/contract_api:1.0.0:bafybeidgu7o5llh26xp3u3ebq3yluull5lupiyeu6iooi2xyymdrgnzq5i skills: - valory/abstract_round_abci:0.1.0:bafybeibiw4oqwqvo4jccwz5fb73iardzychgvcl66tceiildohoju2ikti -- valory/decision_making_abci:0.1.0:bafybeigpp4vqsu73m23hfg4v4iqbbtejzpd32j3fooxrxdrz4aqa3xqbuq +- valory/decision_making_abci:0.1.0:bafybeifbzj62j4dxaunuvvbo5lkvsp2fkajwp3rk2rcoigvl2cdywu5uw4 - valory/mech_interact_abci:0.1.0:bafybeicpskytv7osu6bdpmcweemlsb4f3m6gldzpyoxgawkczsmvlrzgma behaviours: main: