Skip to content

Commit

Permalink
refactor: use a function to remove the fraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantios committed Sep 6, 2023
1 parent ae943a3 commit 4e65968
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/valory/skills/decision_maker_abci/behaviours/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
SAFE_GAS = 0


def remove_fraction_wei(amount: int, fraction: float) -> int:
"""Removes the given fraction from the given integer amount and returns the value as an integer."""
if 0 <= fraction <= 1:
keep_percentage = 1 - fraction
return int(amount * keep_percentage)
raise ValueError(f"The given fraction {fraction!r} is not in the range [0, 1].")


class DecisionMakerBaseBehaviour(BaseBehaviour, ABC):
"""Represents the base class for the decision-making FSM behaviour."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from packages.valory.skills.decision_maker_abci.behaviours.base import (
DecisionMakerBaseBehaviour,
WaitableConditionType,
remove_fraction_wei,
)
from packages.valory.skills.decision_maker_abci.models import (
MechInteractionResponse,
Expand Down Expand Up @@ -273,7 +274,7 @@ def _is_profitable(self, confidence: float, vote: int) -> bool:
"""Whether the decision is profitable or not."""
bet = self.synchronized_data.sampled_bet
bet_amount = self.params.get_bet_amount(confidence)
net_bet_amount = int(bet_amount * (1 - self.wei_to_native(bet.fee)))
net_bet_amount = remove_fraction_wei(bet_amount, self.wei_to_native(bet.fee))
num_shares, available_shares = self._calc_binary_shares(net_bet_amount, vote)
mech_price = self.synchronized_data.mech_price
bet_threshold = self.params.bet_threshold
Expand Down

0 comments on commit 4e65968

Please sign in to comment.