Skip to content

Commit

Permalink
fix: changes after code checks
Browse files Browse the repository at this point in the history
  • Loading branch information
annasambrook committed Dec 19, 2024
1 parent 47caf37 commit 9fdab40
Show file tree
Hide file tree
Showing 18 changed files with 218 additions and 170 deletions.
4 changes: 3 additions & 1 deletion packages/valory/skills/check_stop_trading_abci/behaviours.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def async_act(self) -> Generator:
with self.context.benchmark_tool.measure(self.behaviour_id).local():
stop_trading = yield from self._compute_stop_trading()
self.context.logger.info(f"Computed {stop_trading=}")
payload = CheckStopTradingPayload(self.context.agent_address, stop_trading, self.mech_request_count)
payload = CheckStopTradingPayload(
self.context.agent_address, stop_trading, self.mech_request_count
)

with self.context.benchmark_tool.measure(self.behaviour_id).consensus():
yield from self.send_a2a_transaction(payload)
Expand Down
8 changes: 5 additions & 3 deletions packages/valory/skills/check_stop_trading_abci/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def is_staking_kpi_met(self) -> bool:
@property
def n_mech_requests(self) -> int:
"""Get the number of mech requests."""
return int(self.db.get("n_mech_requests", 0))
n_mech_requests = self.db.get("n_mech_requests", 0)
if n_mech_requests is None:
return 0
return n_mech_requests


class CheckStopTradingRound(VotingRound):
Expand Down Expand Up @@ -103,8 +106,7 @@ def end_block(self) -> Optional[Tuple[BaseSynchronizedData, Enum]]:
n_mech_requests = self.mech_request_count

self.synchronized_data.update(
is_staking_kpi_met=is_staking_kpi_met,
n_mech_requests=n_mech_requests
is_staking_kpi_met=is_staking_kpi_met, n_mech_requests=n_mech_requests
)

return res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
def test_check_stop_trading_payload() -> None:
"""Test `CheckStopTradingPayload`."""

payload = CheckStopTradingPayload(sender="sender", vote=True)
payload = CheckStopTradingPayload(sender="sender", vote=True, mech_request_count=1)

assert payload.vote
assert payload.data == {"vote": True}
assert payload.mech_request_count == 1
assert CheckStopTradingPayload.from_json(payload.json) == payload
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def get_participant_to_votes(
"""participant_to_votes"""

return {
participant: CheckStopTradingPayload(sender=participant, vote=vote)
participant: CheckStopTradingPayload(
sender=participant, vote=vote, mech_request_count=1
)
for participant in participants
}

Expand All @@ -102,10 +104,11 @@ def get_participant_to_votes_serialized(
def get_payloads(
payload_cls: Type[CheckStopTradingPayload],
data: Optional[str],
mech_request_count: int,
) -> Mapping[str, CheckStopTradingPayload]:
"""Get payloads."""
return {
participant: payload_cls(participant, data is not None)
participant: payload_cls(participant, data is not None, mech_request_count)
for participant in get_participants()
}

Expand Down Expand Up @@ -198,6 +201,7 @@ class TestCheckStopTradingRound(BaseCheckStopTradingRoundTest):
payloads=get_payloads(
payload_cls=CheckStopTradingPayload,
data=get_dummy_check_stop_trading_payload_serialized(),
mech_request_count=1,
),
final_data={},
event=Event.SKIP_TRADING,
Expand All @@ -217,6 +221,7 @@ class TestCheckStopTradingRound(BaseCheckStopTradingRoundTest):
payloads=get_payloads(
payload_cls=CheckStopTradingPayload,
data=get_dummy_check_stop_trading_payload_serialized(),
mech_request_count=1,
),
final_data={},
event=Event.NO_MAJORITY,
Expand Down
43 changes: 0 additions & 43 deletions packages/valory/skills/decision_maker_abci/behaviours/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from aea.protocols.base import Message
from aea.protocols.dialogue.base import Dialogue

from packages.valory.contracts.erc20.contract import ERC20
from packages.valory.contracts.gnosis_safe.contract import (
GnosisSafeContract,
SafeOperation,
Expand Down Expand Up @@ -109,8 +108,6 @@ class DecisionMakerBaseBehaviour(BetsManagerBehaviour, ABC):
def __init__(self, **kwargs: Any) -> None:
"""Initialize the bet placement behaviour."""
super().__init__(**kwargs)
# self.token_balance = 0
# self.wallet_balance = 0
self.multisend_batches: List[MultisendBatch] = []
self.multisend_data = b""
self._safe_tx_hash = ""
Expand Down Expand Up @@ -265,23 +262,6 @@ def is_first_period(self) -> bool:
or self.shared_state.mock_data is None
)

# @property
# def sampled_bet(self) -> Bet:
# """Get the sampled bet and reset the bets list."""
# self.read_bets()
# bet_index = self.synchronized_data.sampled_bet_index
# return self.bets[bet_index]

# @property
# def collateral_token(self) -> str:
# """Get the contract address of the token that the market maker supports."""
# return self.sampled_bet.collateralToken
#
# @property
# def is_wxdai(self) -> bool:
# """Get whether the collateral address is wxDAI."""
# return self.collateral_token.lower() == WXDAI.lower()

@staticmethod
def wei_to_native(wei: int) -> float:
"""Convert WEI to native token."""
Expand Down Expand Up @@ -325,29 +305,6 @@ def check_balance(self) -> WaitableConditionType:
self._mock_balance_check()
return True

# response_msg = yield from self.get_contract_api_response(
# performative=ContractApiMessage.Performative.GET_RAW_TRANSACTION, # type: ignore
# contract_address=self.collateral_token,
# contract_id=str(ERC20.contract_id),
# contract_callable="check_balance",
# account=self.synchronized_data.safe_contract_address,
# )
# if response_msg.performative != ContractApiMessage.Performative.RAW_TRANSACTION:
# self.context.logger.error(
# f"Could not calculate the balance of the safe: {response_msg}"
# )
# return False
#
# token = response_msg.raw_transaction.body.get("token", None)
# wallet = response_msg.raw_transaction.body.get("wallet", None)
# if token is None or wallet is None:
# self.context.logger.error(
# f"Something went wrong while trying to get the balance of the safe: {response_msg}"
# )
# return False
#
# self.token_balance = int(token)
# self.wallet_balance = int(wallet)
yield from self.wait_for_condition_with_sleep(self.get_balance)

self._report_balance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def async_act(self) -> Generator:
betting_tx_hex,
mocking_mode,
wallet_balance,
token_balance
token_balance,
)

yield from self.finish_behaviour(payload)
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,7 @@ def async_act(self) -> Generator:
self.shared_state.bet_id_row_manager = bets_mapping

agent = self.context.agent_address
payload = DecisionRequestPayload(agent, payload_content, mocking_mode, decision_request_timestamp)
payload = DecisionRequestPayload(
agent, payload_content, mocking_mode, decision_request_timestamp
)
yield from self.finish_behaviour(payload)
Loading

0 comments on commit 9fdab40

Please sign in to comment.