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: stop trading conditions #245

Merged
merged 22 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"contract/valory/transfer_nft_condition/0.1.0": "bafybeicgpoag2lymofz3vnen76q7gtig5hzimn32o57php4uerr6t25em4",
"skill/valory/market_manager_abci/0.1.0": "bafybeidygkw7mwhbk3ry3au5c5265vms5eti375v5jthd4be5dfnnoache",
"skill/valory/decision_maker_abci/0.1.0": "bafybeihl4fyyjj34kvouh3ujmekqm4vsn5eabpfsww7danwyqmfhxxlequ",
"skill/valory/trader_abci/0.1.0": "bafybeia7a6glncfuncgnupyhfldvp2qy5fau3n72pqdqf6zorvhug7kfiq",
"skill/valory/trader_abci/0.1.0": "bafybeidmp5fbufsvbo2jyxmh3epazeni6jxauyf7h5vssuxr74i2jlgcdi",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeifmyrqtgp4duq65ag3pnbid2xlgxemefln3mshccs6dnhdtieg4la",
"skill/valory/staking_abci/0.1.0": "bafybeicrp3dbvxcb2wa7kdgpkxu7aqji5fwq6icwcfw7anfcpqv26irsr4",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeihs2yjqyqno6h5pmhrwlpgnoqunnho54p2y46ut2hmorsaz36quru",
"agent/valory/trader/0.1.0": "bafybeignyb7bcsysmks3v7wzspscocy5t63oc4ucpakcs5vmc2g3eebxm4",
"service/valory/trader/0.1.0": "bafybeiewwtagcb6kndddzqapebdmuwrywa67nrcyud6wi32oaw5uunxyyi"
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeig7doeus3ezz57nazjmjd6qkkbkuptr3rf4btbbuxsx767jsxcnha",
"agent/valory/trader/0.1.0": "bafybeidxsseryfymbqeg67ezacy74p3e2i3sslz6fkiebf4lqmjxrx7zse",
"service/valory/trader/0.1.0": "bafybeidupsn5xvnnf7ivcznqzvfmdmh7sdllubbnifwll3obqoidwukawq"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ skills:
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeifmyrqtgp4duq65ag3pnbid2xlgxemefln3mshccs6dnhdtieg4la
- valory/market_manager_abci:0.1.0:bafybeidygkw7mwhbk3ry3au5c5265vms5eti375v5jthd4be5dfnnoache
- valory/decision_maker_abci:0.1.0:bafybeihl4fyyjj34kvouh3ujmekqm4vsn5eabpfsww7danwyqmfhxxlequ
- valory/trader_abci:0.1.0:bafybeia7a6glncfuncgnupyhfldvp2qy5fau3n72pqdqf6zorvhug7kfiq
- valory/trader_abci:0.1.0:bafybeidmp5fbufsvbo2jyxmh3epazeni6jxauyf7h5vssuxr74i2jlgcdi
- valory/staking_abci:0.1.0:bafybeicrp3dbvxcb2wa7kdgpkxu7aqji5fwq6icwcfw7anfcpqv26irsr4
- valory/check_stop_trading_abci:0.1.0:bafybeihs2yjqyqno6h5pmhrwlpgnoqunnho54p2y46ut2hmorsaz36quru
- valory/check_stop_trading_abci:0.1.0:bafybeig7doeus3ezz57nazjmjd6qkkbkuptr3rf4btbbuxsx767jsxcnha
- valory/mech_interact_abci:0.1.0:bafybeihovtfa2oocrx32pdq2af6ey37om7q7b2gy3kkd3azv6mjrclohsy
customs:
- valory/mike_strat:0.1.0:bafybeihjiol7f4ch4piwfikurdtfwzsh6qydkbsztpbwbwb2yrqdqf726m
Expand Down
2 changes: 1 addition & 1 deletion 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:bafybeignyb7bcsysmks3v7wzspscocy5t63oc4ucpakcs5vmc2g3eebxm4
agent: valory/trader:0.1.0:bafybeidxsseryfymbqeg67ezacy74p3e2i3sslz6fkiebf4lqmjxrx7zse
number_of_agents: 4
deployment: {}
---
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/check_stop_trading_abci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Description

This module contains the check stop trading skill for an AEA.
This package contains the check stop trading skill for an AEA.
13 changes: 10 additions & 3 deletions packages/valory/skills/check_stop_trading_abci/behaviours.py
jmoreira-valory marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
from packages.valory.contracts.service_staking_token.contract import StakingState


# Liveness ratio from the staking contract is expressed in calls per 10**18 seconds.
LIVENESS_RATIO_SCALE_FACTOR = 10**18

# A safety margin in case there is a delay between the moment the KPI condition is
# satisfied, and the moment where the checkpoint is called.
REQUIRED_MECH_REQUESTS_SAFETY_MARGIN = 1

class CheckStopTradingBehaviour(StakingInteractBaseBehaviour):
"""A behaviour that checks stop trading conditions."""

Expand Down Expand Up @@ -110,9 +117,9 @@ def is_staking_kpi_met(self) -> WaitableConditionType:
self.context.logger.info(f"{current_timestamp=}")

required_mech_requests = math.ceil(max(
(current_timestamp - last_ts_checkpoint) * liveness_ratio / 10**18,
(liveness_period) * liveness_ratio / 10**18
)) + 1
(current_timestamp - last_ts_checkpoint) * liveness_ratio / LIVENESS_RATIO_SCALE_FACTOR,
(liveness_period) * liveness_ratio / LIVENESS_RATIO_SCALE_FACTOR
)) + REQUIRED_MECH_REQUESTS_SAFETY_MARGIN
self.context.logger.info(f"{required_mech_requests=}")

if mech_requests_since_last_cp >= required_mech_requests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ alphabet_in:
default_start_state: CheckStopTradingRound
final_states:
- FinishedCheckStopTradingRound
- FinishedCheckStopTradingWithSkipTradingRound
- FinishedWithSkipTradingRound
label: CheckStopTradingAbciApp
start_states:
- CheckStopTradingRound
states:
- CheckStopTradingRound
- FinishedCheckStopTradingRound
- FinishedCheckStopTradingWithSkipTradingRound
- FinishedWithSkipTradingRound
transition_func:
(CheckStopTradingRound, DONE): FinishedCheckStopTradingRound
(CheckStopTradingRound, NONE): CheckStopTradingRound
(CheckStopTradingRound, NO_MAJORITY): CheckStopTradingRound
(CheckStopTradingRound, ROUND_TIMEOUT): CheckStopTradingRound
(CheckStopTradingRound, SKIP_TRADING): FinishedCheckStopTradingWithSkipTradingRound
(CheckStopTradingRound, SKIP_TRADING): FinishedWithSkipTradingRound
21 changes: 8 additions & 13 deletions packages/valory/skills/check_stop_trading_abci/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ def stop_trading(self) -> bool:
"""Get if the service must stop trading."""
return bool(self.db.get("stop_trading", False))

@property
def participant_to_selection(self) -> DeserializedCollection:
"""Get the participants to selection round."""
return self._get_deserialized("participant_to_selection")


class CheckStopTradingRound(CollectSameUntilThresholdRound):
"""A round for checking stop trading conditions."""
Expand All @@ -79,7 +74,7 @@ class CheckStopTradingRound(CollectSameUntilThresholdRound):
done_event = Event.DONE
none_event = Event.NONE
no_majority_event = Event.NO_MAJORITY
selection_key = (get_name(SynchronizedData.stop_trading),)
selection_key = get_name(SynchronizedData.stop_trading)
collection_key = get_name(SynchronizedData.participant_to_selection)

def end_block(self) -> Optional[Tuple[SynchronizedData, Enum]]:
Expand All @@ -101,7 +96,7 @@ class FinishedCheckStopTradingRound(DegenerateRound, ABC):
"""A round that represents check stop trading has finished."""


class FinishedCheckStopTradingWithSkipTradingRound(DegenerateRound, ABC):
class FinishedWithSkipTradingRound(DegenerateRound, ABC):
"""A round that represents check stop trading has finished with skip trading."""


Expand All @@ -120,9 +115,9 @@ class CheckStopTradingAbciApp(AbciApp[Event]): # pylint: disable=too-few-public
- no majority: 0.
- skip trading: 2.
1. FinishedCheckStopTradingRound
2. FinishedCheckStopTradingWithSkipTradingRound
2. FinishedWithSkipTradingRound

Final states: {FinishedCheckStopTradingRound, FinishedCheckStopTradingWithSkipTradingRound}
Final states: {FinishedCheckStopTradingRound, FinishedWithSkipTradingRound}

Timeouts:
round timeout: 30.0
Expand All @@ -135,20 +130,20 @@ class CheckStopTradingAbciApp(AbciApp[Event]): # pylint: disable=too-few-public
Event.NONE: CheckStopTradingRound,
Event.ROUND_TIMEOUT: CheckStopTradingRound,
Event.NO_MAJORITY: CheckStopTradingRound,
Event.SKIP_TRADING: FinishedCheckStopTradingWithSkipTradingRound,
Event.SKIP_TRADING: FinishedWithSkipTradingRound,
},
FinishedCheckStopTradingRound: {},
FinishedCheckStopTradingWithSkipTradingRound: {},
FinishedWithSkipTradingRound: {},
}
final_states: Set[AppState] = {
FinishedCheckStopTradingRound,
FinishedCheckStopTradingWithSkipTradingRound,
FinishedWithSkipTradingRound,
}
event_to_timeout: Dict[Event, float] = {
Event.ROUND_TIMEOUT: 30.0,
}
db_pre_conditions: Dict[AppState, Set[str]] = {CheckStopTradingRound: set()}
db_post_conditions: Dict[AppState, Set[str]] = {
FinishedCheckStopTradingRound: set(),
FinishedCheckStopTradingWithSkipTradingRound: set(),
FinishedWithSkipTradingRound: set(),
Adamantios marked this conversation as resolved.
Show resolved Hide resolved
}
9 changes: 4 additions & 5 deletions packages/valory/skills/check_stop_trading_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ description: This skill implements the check for stop trading for an AEA.
license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
README.md: bafybeicxomwratfnu3yqo5eav65ddxxrjfrzadqfgdcsp53dvft3xlv6ze
README.md: bafybeif2pq7fg5upl6vmfgfzpiwsh4nbk4zaeyz6upyucqi5tasrxgq4ee
__init__.py: bafybeifc23rlw2hzhplp3wfceixnmwq5ztnixhh7jp4dd5av3crwp3x22a
behaviours.py: bafybeieaps6wnm7ovxljp5mlfsgldb5qkwy35hjslhlugmdg256ifhjcqy
behaviours.py: bafybeifuppqvkvx276mlxsggyw3eaph3msyp573f2rmwlxyszy6fyzk7kq
dialogues.py: bafybeictrrnwcijiejczy23dfvbx5kujgef3dulzqhs3etl2juvz5spm2e
fsm_specification.yaml: bafybeiefujlpmnqdbfxntv5vwtuwinnu6furbteghbunuv2m4dtfeijvyi
fsm_specification.yaml: bafybeihhau35a5xclncjpxh5lg7qiw34xs4d5qlez7dnjpkf45d3gc57ai
handlers.py: bafybeiard64fwxib3rtyp67ymhf222uongcyqhfhdyttpsyqkmyh5ajipu
models.py: bafybeiecrxmuts2whh3vz5a7thoy55ef3dkjidkdgyn6amy3uxss4x2fwa
payloads.py: bafybeih7byn5bno2ecmm3fx3yr4iw4rdcffvnqjpovxjvzqqfi34aykoee
rounds.py: bafybeib5w6zlsmhf2w65le57e7dkvghunfu6b5qu5jtyoiunrgptmjgckm
rounds.py: bafybeifr63su5tzshv6vh4vdn4swxw3qruatwrns7flzu42bznevsxifwi
fingerprint_ignore_patterns: []
connections: []
contracts:
Expand Down Expand Up @@ -126,7 +126,6 @@ models:
slash_threshold_amount: 10000000000000000
light_slash_unit_amount: 5000000000000000
serious_slash_unit_amount: 8000000000000000
staking_contract_address: '0x2Ef503950Be67a98746F484DA0bBAdA339DF3326'
disable_trading: false
stop_trading_if_staking_kpi_met: true
class_name: CheckStopTradingParams
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
CheckStopTradingAbciApp,
CheckStopTradingRound,
FinishedCheckStopTradingRound,
FinishedCheckStopTradingWithSkipTradingRound,
FinishedWithSkipTradingRound,
)
from packages.valory.skills.decision_maker_abci.rounds import DecisionMakerAbciApp
from packages.valory.skills.decision_maker_abci.states.claim_subscription import (
Expand Down Expand Up @@ -111,7 +111,7 @@
FinishedRegistrationRound: UpdateBetsRound,
FinishedMarketManagerRound: CheckStopTradingRound,
FinishedCheckStopTradingRound: SamplingRound,
FinishedCheckStopTradingWithSkipTradingRound: RedeemRound,
FinishedWithSkipTradingRound: RedeemRound,
FailedMarketManagerRound: ResetAndPauseRound,
FinishedDecisionMakerRound: PreTxSettlementRound,
ChecksPassedRound: RandomnessTransactionSubmissionRound,
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fingerprint:
README.md: bafybeiab4xgadptz4mhvno4p6xvkh7p4peg7iuhotabydriu74dmj6ljga
__init__.py: bafybeido7wa33h4dtleap57vzgyb4fsofk4vindsqcekyfo5i56i2rll2a
behaviours.py: bafybeigc6hszbu66ccajny5eh7thfgsrlr36je4mzziwp4mupgvtaeu6aa
composition.py: bafybeidlwhwbcj3v62eqpte6saykvi4zijpxks2rin4ahk2e7kdfwggwom
composition.py: bafybeidazh2w4do27n2fmwh5eyca7tet5dxw4uilh4wkhoazlgyhr7w3eu
dialogues.py: bafybeiebofyykseqp3fmif36cqmmyf3k7d2zbocpl6t6wnlpv4szghrxbm
fsm_specification.yaml: bafybeicibuzg6mf6632jin3d6xylkb7if5o4dqpire6ijhor5v2e6rvo7u
handlers.py: bafybeibkiqwe7hoqccjirimd44nzeqkabc7oo74romqklssion27s5sa2a
Expand All @@ -28,7 +28,7 @@ skills:
- valory/decision_maker_abci:0.1.0:bafybeihl4fyyjj34kvouh3ujmekqm4vsn5eabpfsww7danwyqmfhxxlequ
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeifmyrqtgp4duq65ag3pnbid2xlgxemefln3mshccs6dnhdtieg4la
- valory/staking_abci:0.1.0:bafybeicrp3dbvxcb2wa7kdgpkxu7aqji5fwq6icwcfw7anfcpqv26irsr4
- valory/check_stop_trading_abci:0.1.0:bafybeihs2yjqyqno6h5pmhrwlpgnoqunnho54p2y46ut2hmorsaz36quru
- valory/check_stop_trading_abci:0.1.0:bafybeig7doeus3ezz57nazjmjd6qkkbkuptr3rf4btbbuxsx767jsxcnha
- valory/mech_interact_abci:0.1.0:bafybeihovtfa2oocrx32pdq2af6ey37om7q7b2gy3kkd3azv6mjrclohsy
behaviours:
main:
Expand Down