Skip to content

Commit

Permalink
add: previous_vote and sell logic
Browse files Browse the repository at this point in the history
  • Loading branch information
annasambrook committed Dec 5, 2024
1 parent 32fb70d commit 445998e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ def async_act(self) -> Generator:
with self.context.benchmark_tool.measure(self.behaviour_id).local():
tx_submitter = betting_tx_hex = mocking_mode = None

# if the vote is the same as the previous vote then there is no change in the supported outcome, so we
# should not sell
if self.synchronized_data.vote == self.synchronized_data.previous_vote:
payload = MultisigTxPayload(
agent, tx_submitter, betting_tx_hex, mocking_mode
)

yield from self.finish_behaviour(payload)

self.return_amount = self.bets[
self.synchronized_data.sampled_bet_index
].invested_amount
Expand Down
6 changes: 6 additions & 0 deletions packages/valory/skills/decision_maker_abci/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ def vote(self) -> Optional[int]:
vote = self.db.get_strict("vote")
return int(vote) if vote is not None else None

@property
def previous_vote(self) -> Optional[int]:
"""Get the bet's previous vote index."""
previous_vote = self.db.get_strict("previous_vote")
return int(previous_vote) if previous_vote is not None else None

@property
def confidence(self) -> float:
"""Get the vote's confidence."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class DecisionReceiveRound(CollectSameUntilThresholdRound):

def end_block(self) -> Optional[Tuple[SynchronizedData, Enum]]:
"""Process the end of the block."""

# update the previous vote before calling the super method
SynchronizedData.update(
previous_vote=SynchronizedData.vote
)

res = super().end_block()
if res is None:
return None
Expand Down

0 comments on commit 445998e

Please sign in to comment.