Skip to content

Commit

Permalink
feat: improve logging information
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantios committed Aug 2, 2023
1 parent b08bc28 commit 225ba5f
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
WXDAI = "0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d"


def wei_to_native(wei: int) -> float:
"""Convert WEI to native token."""
return wei / 10**18


class BetPlacementBehaviour(DecisionMakerBaseBehaviour):
"""A behaviour in which the agents blacklist the sampled bet."""

Expand Down Expand Up @@ -108,6 +113,14 @@ def txs_value(self) -> int:
"""Get the total value of the transactions."""
return sum(batch.value for batch in self.multisend_batches)

def _collateral_amount_info(self, amount: int) -> str:
"""Get a description of the collateral token's amount."""
return (
f"{wei_to_native(amount)} wxDAI"
if self.is_wxdai
else f"{amount} WEI of the collateral token with address {self.collateral_token}"
)

def _check_balance(self) -> WaitableConditionType:
"""Check the safe's balance."""
response_msg = yield from self.get_contract_api_response(
Expand All @@ -133,6 +146,10 @@ def _check_balance(self) -> WaitableConditionType:

self.token_balance = int(token)
self.wallet_balance = int(wallet)

native = wei_to_native(self.wallet_balance)
collateral = self._collateral_amount_info(self.token_balance)
self.context.logger.info(f"The safe has {native} xDAI and {collateral}.")
return True

def _build_exchange_tx(self) -> WaitableConditionType:
Expand Down Expand Up @@ -322,12 +339,12 @@ def _prepare_safe_tx(self) -> Generator[None, None, str]:
):
yield from self.wait_for_condition_with_sleep(step)

outcome = self.synchronized_data.sampled_bet.get_outcome(self.outcome_index)
investment = self._collateral_amount_info(self.investment_amount)
self.context.logger.info(
"Preparing a mutlisig transaction to place a bet for "
f"{self.synchronized_data.sampled_bet.get_outcome(self.outcome_index)!r}, "
f"with confidence {self.synchronized_data.confidence!r}, "
f"for the amount of {self.investment_amount!r}, which is equal to the amount of "
f"{self.buy_amount!r} of the corresponding conditional token."
f"Preparing a mutlisig transaction to place a bet for {outcome!r}, with confidence "
f"{self.synchronized_data.confidence!r}, for the amount of {investment}, which is equal to the amount of "
f"{self.buy_amount!r} WEI of the conditional token corresponding to {outcome!r}."
)

return hash_payload_to_hex(
Expand Down

0 comments on commit 225ba5f

Please sign in to comment.