From b08bc28ea20420719689190ffae612045deb6003 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 2 Aug 2023 12:57:25 +0300 Subject: [PATCH 1/3] fix: guard against non-checksummed addresses The addresses provided by the subgraph are not checksummed. As a result, `can_exchange` was always `False`. --- .../skills/decision_maker_abci/behaviours/bet_placement.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py index 8ef1f88f7..57442229e 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py @@ -73,6 +73,11 @@ def collateral_token(self) -> str: """Get the contract address of the token that the market maker supports.""" return self.synchronized_data.sampled_bet.collateralToken + @property + def is_wxdai(self) -> bool: + """Get whether the collateral address is wxDAI.""" + return self.collateral_token.lower() == WXDAI.lower() + @property def market_maker_contract_address(self) -> str: """Get the contract address of the market maker on which the service is going to place the bet.""" @@ -341,7 +346,7 @@ def async_act(self) -> Generator: tx_submitter = betting_tx_hex = None can_exchange = ( - self.collateral_token == WXDAI + self.is_wxdai # no need to take fees into consideration because it is the safe's balance and the agents pay the fees and self.wallet_balance >= self.w_xdai_deficit ) From 225ba5fd12a18aada0e4b7ab121e7e1042fb9889 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 2 Aug 2023 12:57:41 +0300 Subject: [PATCH 2/3] feat: improve logging information --- .../behaviours/bet_placement.py | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py index 57442229e..913109236 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py @@ -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.""" @@ -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( @@ -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: @@ -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( From 3e205a6562f5c707d76747c73388b89b9c848a1b Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 2 Aug 2023 13:03:29 +0300 Subject: [PATCH 3/3] chore: run generators --- packages/packages.json | 10 +++++----- packages/valory/agents/trader/aea-config.yaml | 6 +++--- packages/valory/services/trader/service.yaml | 2 +- packages/valory/skills/decision_maker_abci/skill.yaml | 2 +- packages/valory/skills/trader_abci/skill.yaml | 4 ++-- .../skills/tx_settlement_multiplexer_abci/skill.yaml | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index 621139c39..d372e3586 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -1,13 +1,13 @@ { "dev": { "skill/valory/market_manager_abci/0.1.0": "bafybeids5us4cnfu2zboxfjjkyihxk2i4qmctwzbnrsk2uizzjl2gbjj4m", - "skill/valory/decision_maker_abci/0.1.0": "bafybeidwexscouadfvf7qqe37bknjwoj7w54aefwomu54ht2myvgjraes4", - "skill/valory/trader_abci/0.1.0": "bafybeigalvd3cp6sf4nkrl2odialcu2zqfdojjrvm6lnqucgxosiraq3sy", + "skill/valory/decision_maker_abci/0.1.0": "bafybeifxzzqxi4stwn7k6v2iotrf7rijv5bybhwyrstmozwd7zcjfkvwki", + "skill/valory/trader_abci/0.1.0": "bafybeihb25sw6gegl53dddltqa2p6pkpnexbttellqgbncq7c76pnzm6tq", "contract/valory/market_maker/0.1.0": "bafybeig3b2wfngntdypnixi2gphuqz3o6w7zba2rq6n6kepwdmth2mx3ni", - "agent/valory/trader/0.1.0": "bafybeihfpkd5kxtix6wx5lmyycmza6zdi6ltotquspuhi65zbyhibir5me", - "service/valory/trader/0.1.0": "bafybeievpm2om4fsh5duizqabun57mhntd3t5r6te2aj2p3u5bfgmeojl4", + "agent/valory/trader/0.1.0": "bafybeigepq6yg6atkfkjlqrztmcekqx5r5ydq5m7se264hg2wdbyl4mfr4", + "service/valory/trader/0.1.0": "bafybeihgcnioxjhmgv2i2iyht4cru7oqqgkwkxxp3in4bxlaae7owi7ari", "contract/valory/erc20/0.1.0": "bafybeid4dnlzxpvb7sbgo2bnnffzwk5scelytshworzbfyxce6ibdyk67i", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeig6avhzw2x5tacq7jyxgnpoz6k6s62clgsexlp55y6qdwietcfgqi", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeianobsmjh2qjwtdzyvaxpefgz4ywpyxzk7iznmsygved7wxbtl23e", "contract/valory/mech/0.1.0": "bafybeib3syh35usqjtqapqjjvobnkcxllkpjbxcb67g3vp3f566qsbhqgq" }, "third_party": { diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index 9d3cac9e5..eefb7d516 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -38,10 +38,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeialcwck7fahrr23jckv5qjwg3cdq4ai2ihyjsofnbj44jzyl4cjmm - valory/termination_abci:0.1.0:bafybeifqsogqiar4yook5bu3j6z66dbdcizey7dr3e5oxeocdjijvfbaja - valory/transaction_settlement_abci:0.1.0:bafybeiacwr7p4nhhufoey7uz2jqkegrlykdrmc7mm3rzkvh2mslu66gyle -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeig6avhzw2x5tacq7jyxgnpoz6k6s62clgsexlp55y6qdwietcfgqi +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeianobsmjh2qjwtdzyvaxpefgz4ywpyxzk7iznmsygved7wxbtl23e - valory/market_manager_abci:0.1.0:bafybeids5us4cnfu2zboxfjjkyihxk2i4qmctwzbnrsk2uizzjl2gbjj4m -- valory/decision_maker_abci:0.1.0:bafybeidwexscouadfvf7qqe37bknjwoj7w54aefwomu54ht2myvgjraes4 -- valory/trader_abci:0.1.0:bafybeigalvd3cp6sf4nkrl2odialcu2zqfdojjrvm6lnqucgxosiraq3sy +- valory/decision_maker_abci:0.1.0:bafybeifxzzqxi4stwn7k6v2iotrf7rijv5bybhwyrstmozwd7zcjfkvwki +- valory/trader_abci:0.1.0:bafybeihb25sw6gegl53dddltqa2p6pkpnexbttellqgbncq7c76pnzm6tq default_ledger: ethereum required_ledgers: - ethereum diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index a10edec53..edd38c437 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq fingerprint_ignore_patterns: [] -agent: valory/trader:0.1.0:bafybeihfpkd5kxtix6wx5lmyycmza6zdi6ltotquspuhi65zbyhibir5me +agent: valory/trader:0.1.0:bafybeigepq6yg6atkfkjlqrztmcekqx5r5ydq5m7se264hg2wdbyl4mfr4 number_of_agents: 4 deployment: {} --- diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index 31e2336fb..43badeb97 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -10,7 +10,7 @@ fingerprint: __init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky behaviours/base.py: bafybeig2zoyowdeqg44kyxdc5tzdiczzpkzpbchq6f2nwjqertfvmi6xvy - behaviours/bet_placement.py: bafybeigius6g2k2foyttxihbna2xpffeziige6273udsvam24bfcgcspfa + behaviours/bet_placement.py: bafybeic4cfzg4brkfzjkogt3kvtksewubdh67fea2o64y4nkirs4epx5ni behaviours/blacklisting.py: bafybeicvespraci44y2dtddy4wi7cdhjuyk6crjs7ztnssm2rcrovha3hm behaviours/decision_receive.py: bafybeigjct7st66x7n3go5vdp62wtdxgmgw233hyyvd3a63ly4x3ptdqbq behaviours/decision_request.py: bafybeidsvohdt2fxonh5qmctftjj5wfaa5z3ommr2yie6e7bhcml6xueuu diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index a195a821e..36c1ef445 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -25,8 +25,8 @@ skills: - valory/transaction_settlement_abci:0.1.0:bafybeiacwr7p4nhhufoey7uz2jqkegrlykdrmc7mm3rzkvh2mslu66gyle - valory/termination_abci:0.1.0:bafybeifqsogqiar4yook5bu3j6z66dbdcizey7dr3e5oxeocdjijvfbaja - valory/market_manager_abci:0.1.0:bafybeids5us4cnfu2zboxfjjkyihxk2i4qmctwzbnrsk2uizzjl2gbjj4m -- valory/decision_maker_abci:0.1.0:bafybeidwexscouadfvf7qqe37bknjwoj7w54aefwomu54ht2myvgjraes4 -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeig6avhzw2x5tacq7jyxgnpoz6k6s62clgsexlp55y6qdwietcfgqi +- valory/decision_maker_abci:0.1.0:bafybeifxzzqxi4stwn7k6v2iotrf7rijv5bybhwyrstmozwd7zcjfkvwki +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeianobsmjh2qjwtdzyvaxpefgz4ywpyxzk7iznmsygved7wxbtl23e behaviours: main: args: {} diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index d2215d0ec..3a0c92bc9 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -20,7 +20,7 @@ contracts: [] protocols: [] skills: - valory/abstract_round_abci:0.1.0:bafybeiaseziuvbzh3trjggl5hx2tv3fduqrpiwiyksudaf6nvuxmwrg74i -- valory/decision_maker_abci:0.1.0:bafybeidwexscouadfvf7qqe37bknjwoj7w54aefwomu54ht2myvgjraes4 +- valory/decision_maker_abci:0.1.0:bafybeifxzzqxi4stwn7k6v2iotrf7rijv5bybhwyrstmozwd7zcjfkvwki behaviours: main: args: {}