From ff965046dddc266fae38c4f9196d1e72fd5cb26f Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 12:23:45 +0300 Subject: [PATCH 01/15] refactor: use the `scaledLiquidityMeasure` instead --- .../skills/decision_maker_abci/behaviours/sampling.py | 2 +- packages/valory/skills/market_manager_abci/bets.py | 8 ++++---- .../market_manager_abci/graph_tooling/queries/omen.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/sampling.py b/packages/valory/skills/decision_maker_abci/behaviours/sampling.py index b7011158f..39f1384eb 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/sampling.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/sampling.py @@ -73,7 +73,7 @@ def _sample(self) -> Tuple[Optional[str], Optional[int]]: idx = self._sampled_bet_idx(available_bets) - if self.synchronized_data.bets[idx].usdLiquidityMeasure == 0: + if self.synchronized_data.bets[idx].scaledLiquidityMeasure == 0: msg = "There were no unprocessed bets with non-zero liquidity!" self.context.logger.warning(msg) return None, None diff --git a/packages/valory/skills/market_manager_abci/bets.py b/packages/valory/skills/market_manager_abci/bets.py index fbd3b6be2..549c895d2 100644 --- a/packages/valory/skills/market_manager_abci/bets.py +++ b/packages/valory/skills/market_manager_abci/bets.py @@ -54,7 +54,7 @@ class Bet: outcomeTokenAmounts: Optional[List[int]] outcomeTokenMarginalPrices: Optional[List[float]] outcomes: Optional[List[str]] - usdLiquidityMeasure: float + scaledLiquidityMeasure: float status: BetStatus = BetStatus.UNPROCESSED blacklist_expiration: float = -1 @@ -66,7 +66,7 @@ def __post_init__(self) -> None: def __lt__(self, other: "Bet") -> bool: """Implements less than operator.""" - return self.usdLiquidityMeasure < other.usdLiquidityMeasure + return self.scaledLiquidityMeasure < other.scaledLiquidityMeasure def _blacklist_forever(self) -> None: """Blacklist a bet forever. Should only be used in cases where it is impossible to bet.""" @@ -86,7 +86,7 @@ def _validate(self) -> None: self.openingTimestamp, self.outcomeSlotCount, self.outcomes, - self.usdLiquidityMeasure, + self.scaledLiquidityMeasure, ) nulls_exist = any(val is None or val == "null" for val in necessary_values) @@ -124,7 +124,7 @@ def _cast(self) -> None: def _check_usefulness(self) -> None: """If the bet is deemed unhelpful, then blacklist it.""" - if self.usdLiquidityMeasure == 0: + if self.scaledLiquidityMeasure == 0: self._blacklist_forever() def get_outcome(self, index: int) -> str: diff --git a/packages/valory/skills/market_manager_abci/graph_tooling/queries/omen.py b/packages/valory/skills/market_manager_abci/graph_tooling/queries/omen.py index 424307205..f7f932112 100644 --- a/packages/valory/skills/market_manager_abci/graph_tooling/queries/omen.py +++ b/packages/valory/skills/market_manager_abci/graph_tooling/queries/omen.py @@ -46,7 +46,7 @@ outcomeTokenAmounts outcomeTokenMarginalPrices outcomes - usdLiquidityMeasure + scaledLiquidityMeasure } } """ From 14da60d6d568217d1634fd14256838f831c02c10 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 12:26:13 +0300 Subject: [PATCH 02/15] feat: store the mech's price --- .../behaviours/decision_request.py | 8 ++++---- .../valory/skills/decision_maker_abci/payloads.py | 7 +++++++ .../valory/skills/decision_maker_abci/states/base.py | 9 +++++++-- .../decision_maker_abci/states/decision_request.py | 12 ++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/decision_request.py b/packages/valory/skills/decision_maker_abci/behaviours/decision_request.py index 82186bcbd..456702efe 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/decision_request.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/decision_request.py @@ -38,7 +38,7 @@ SAFE_GAS, WaitableConditionType, ) -from packages.valory.skills.decision_maker_abci.payloads import MultisigTxPayload +from packages.valory.skills.decision_maker_abci.payloads import RequestPayload from packages.valory.skills.decision_maker_abci.states.decision_request import ( DecisionRequestRound, ) @@ -197,11 +197,11 @@ def async_act(self) -> Generator: """Do the action.""" with self.context.benchmark_tool.measure(self.behaviour_id).local(): - tx_submitter = mech_tx_hex = None + tx_submitter = mech_tx_hex = price = None if self.n_slots_supported: tx_submitter = self.matching_round.auto_round_id() mech_tx_hex = yield from self._prepare_safe_tx() + price = self.price agent = self.context.agent_address - payload = MultisigTxPayload(agent, tx_submitter, mech_tx_hex) - + payload = RequestPayload(agent, tx_submitter, mech_tx_hex, price) yield from self.finish_behaviour(payload) diff --git a/packages/valory/skills/decision_maker_abci/payloads.py b/packages/valory/skills/decision_maker_abci/payloads.py index 718b7a543..1aea905b7 100644 --- a/packages/valory/skills/decision_maker_abci/payloads.py +++ b/packages/valory/skills/decision_maker_abci/payloads.py @@ -50,6 +50,13 @@ class MultisigTxPayload(BaseTxPayload): tx_hash: Optional[str] +@dataclass(frozen=True) +class RequestPayload(MultisigTxPayload): + """Represents a transaction payload for preparing an on-chain transaction for a mech request.""" + + price: Optional[int] + + @dataclass(frozen=True) class VotingPayload(BaseTxPayload): """Represents a transaction payload for voting.""" diff --git a/packages/valory/skills/decision_maker_abci/states/base.py b/packages/valory/skills/decision_maker_abci/states/base.py index 06b9a3dd5..bb7d3a87f 100644 --- a/packages/valory/skills/decision_maker_abci/states/base.py +++ b/packages/valory/skills/decision_maker_abci/states/base.py @@ -20,7 +20,7 @@ """This module contains the base functionality for the rounds of the decision-making abci app.""" from enum import Enum -from typing import Optional +from typing import Optional, Tuple from packages.valory.skills.abstract_round_abci.base import ( CollectSameUntilThresholdRound, @@ -70,6 +70,11 @@ def sampled_bet(self) -> Bet: """Get the sampled bet.""" return self.bets[self.sampled_bet_index] + @property + def mech_price(self) -> int: + """Get the mech's request price.""" + return int(self.db.get_strict("mech_price")) + @property def vote(self) -> Optional[int]: """Get the bet's vote index.""" @@ -115,7 +120,7 @@ class TxPreparationRound(CollectSameUntilThresholdRound): done_event = Event.DONE none_event = Event.NONE no_majority_event = Event.NO_MAJORITY - selection_key = ( + selection_key: Tuple[str, ...] = ( get_name(SynchronizedData.tx_submitter), get_name(SynchronizedData.most_voted_tx_hash), ) diff --git a/packages/valory/skills/decision_maker_abci/states/decision_request.py b/packages/valory/skills/decision_maker_abci/states/decision_request.py index e898c0af8..fb11239b2 100644 --- a/packages/valory/skills/decision_maker_abci/states/decision_request.py +++ b/packages/valory/skills/decision_maker_abci/states/decision_request.py @@ -19,8 +19,16 @@ """This module contains the decision requesting state of the decision-making abci app.""" +from typing import Type + +from packages.valory.skills.abstract_round_abci.base import get_name +from packages.valory.skills.decision_maker_abci.payloads import ( + MultisigTxPayload, + RequestPayload, +) from packages.valory.skills.decision_maker_abci.states.base import ( Event, + SynchronizedData, TxPreparationRound, ) @@ -28,4 +36,8 @@ class DecisionRequestRound(TxPreparationRound): """A round in which the agents prepare a tx to initiate a request to a mech to determine the answer to a bet.""" + payload_class: Type[MultisigTxPayload] = RequestPayload + selection_key = TxPreparationRound.selection_key + ( + get_name(SynchronizedData.mech_price), + ) none_event = Event.SLOTS_UNSUPPORTED_ERROR From 86d9986601b4677a20457fe1a79a6c2e66d648f9 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 12:29:26 +0300 Subject: [PATCH 03/15] refactor: compute profitability in a more rational manner This makes the strategy more sensible and potentially more profitable. --- .../behaviours/decision_receive.py | 81 ++++++++++++++++--- .../valory/skills/market_manager_abci/bets.py | 6 +- 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py index 8fd5d7bbe..c0c3a6034 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py @@ -19,6 +19,7 @@ """This module contains the behaviour for the decision-making of the skill.""" +from math import prod from typing import Any, Generator, Optional, Tuple, Union from packages.valory.contracts.mech.contract import Mech @@ -36,6 +37,7 @@ from packages.valory.skills.decision_maker_abci.states.decision_receive import ( DecisionReceiveRound, ) +from packages.valory.skills.market_manager_abci.bets import BINARY_N_SLOTS IPFS_HASH_PREFIX = "f01701220" @@ -221,20 +223,81 @@ def _get_decision( return self.mech_response.result.vote, self.mech_response.result.confidence - def _is_profitable(self, confidence: float) -> bool: + def _calc_binary_shares(self, net_bet_amount: int, vote: int) -> Tuple[int, int]: + """Calculate the claimed shares. This calculation only works for binary markets.""" + bet = self.synchronized_data.sampled_bet + + # calculate the pool's k (x*y=k) + token_amounts = bet.outcomeTokenAmounts + if token_amounts is None: + return 0, 0 + k = prod(token_amounts) + + # the OMEN market trades an equal amount of the investment to each of the tokens in the pool + # here we calculate the bet amount per pool's token + bet_per_token = net_bet_amount / BINARY_N_SLOTS + + # calculate the number of the traded tokens + prices = bet.outcomeTokenMarginalPrices + if prices is None: + return 0, 0 + tokens_traded = [int(bet_per_token / prices[i]) for i in range(BINARY_N_SLOTS)] + + # get the shares for the answer that the service has selected + selected_shares = tokens_traded.pop(vote) + + # get the shares for the opposite answer + other_shares = tokens_traded.pop() + + # get the number of tokens in the pool for the answer that the service has selected + selected_type_tokens_in_pool = token_amounts.pop(vote) + + # get the number of tokens in the pool for the opposite answer + other_tokens_in_pool = token_amounts.pop() + + # the OMEN market then trades the opposite tokens to the tokens of the answer that has been selected, + # preserving the balance of the pool + # here we calculate the number of shares that we get after trading the tokens for the opposite answer + tokens_remaining_in_pool = int(k / (other_tokens_in_pool + other_shares)) + swapped_shares = selected_type_tokens_in_pool - tokens_remaining_in_pool + + # calculate the resulting number of shares if the service would take that position + num_shares = selected_shares + swapped_shares + # calculate the available number of shares + price = prices[vote] + available_shares = int(selected_type_tokens_in_pool * price) + + return num_shares, available_shares + + 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))) + 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 - if bet_threshold < 0: + if bet_threshold <= 0: self.context.logger.warning( - f"A negative bet threshold was given ({bet_threshold}), " - f"which means that the profitability check will be bypassed!" + f"A non-positive bet threshold was given ({bet_threshold}). The threshold will be disabled, " + f"which means that any non-negative potential profit will be considered profitable!" ) - return True + bet_threshold = 0 - bet_amount = self.params.get_bet_amount(confidence) - fee = self.synchronized_data.sampled_bet.fee - return bet_amount - fee >= bet_threshold + potential_net_profit = num_shares - net_bet_amount - mech_price - bet_threshold + is_profitable = potential_net_profit >= 0 and num_shares <= available_shares + shares_out = self.wei_to_native(num_shares) + available_in = self.wei_to_native(available_shares) + shares_out_of = f"{shares_out} / {available_in}" + self.context.logger.info( + f"The current liquidity of the market is {bet.scaledLiquidityMeasure} xDAI. " + f"The potential net profit is {self.wei_to_native(potential_net_profit)} xDAI " + f"from buying {shares_out_of} shares for the option {bet.get_outcome(vote)}.\n" + f"Decision for profitability of this market: {is_profitable}." + ) + + return is_profitable def async_act(self) -> Generator: """Do the action.""" @@ -243,7 +306,7 @@ def async_act(self) -> Generator: vote, confidence = yield from self._get_decision() is_profitable = None if vote is not None and confidence is not None: - is_profitable = self._is_profitable(confidence) + is_profitable = self._is_profitable(confidence, vote) payload = DecisionReceivePayload( self.context.agent_address, is_profitable, diff --git a/packages/valory/skills/market_manager_abci/bets.py b/packages/valory/skills/market_manager_abci/bets.py index 549c895d2..129ae1a94 100644 --- a/packages/valory/skills/market_manager_abci/bets.py +++ b/packages/valory/skills/market_manager_abci/bets.py @@ -51,8 +51,8 @@ class Bet: fee: int openingTimestamp: int outcomeSlotCount: int - outcomeTokenAmounts: Optional[List[int]] - outcomeTokenMarginalPrices: Optional[List[float]] + outcomeTokenAmounts: List[int] + outcomeTokenMarginalPrices: List[float] outcomes: Optional[List[str]] scaledLiquidityMeasure: float status: BetStatus = BetStatus.UNPROCESSED @@ -87,6 +87,8 @@ def _validate(self) -> None: self.outcomeSlotCount, self.outcomes, self.scaledLiquidityMeasure, + self.outcomeTokenAmounts, + self.outcomeTokenMarginalPrices, ) nulls_exist = any(val is None or val == "null" for val in necessary_values) From c6bf41229384ec896b0824b0dab6d0317245e3fa Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 12:33:18 +0300 Subject: [PATCH 04/15] chore: run generators --- packages/packages.json | 12 ++++++------ packages/valory/agents/trader/aea-config.yaml | 8 ++++---- packages/valory/services/trader/service.yaml | 2 +- .../valory/skills/decision_maker_abci/skill.yaml | 14 +++++++------- .../valory/skills/market_manager_abci/skill.yaml | 4 ++-- packages/valory/skills/trader_abci/skill.yaml | 6 +++--- .../tx_settlement_multiplexer_abci/skill.yaml | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index dda9ac21c..abdb10d2c 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -1,13 +1,13 @@ { "dev": { - "skill/valory/market_manager_abci/0.1.0": "bafybeibwcm2wqoucpbep6pav4fb5mofhjahxiqszul4wcv4xr52dei6pe4", - "skill/valory/decision_maker_abci/0.1.0": "bafybeiejy2zxj5wzriay2vwecgvxxprwvs6rt32627jtjfn7gtsy46eimy", - "skill/valory/trader_abci/0.1.0": "bafybeiexo6pdhhdipnceixtls47jonhflcqsxnbv2c333zmgfxmoygfwgu", + "skill/valory/market_manager_abci/0.1.0": "bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi", + "skill/valory/decision_maker_abci/0.1.0": "bafybeiapptasim4es2d6c5y77xgdb4gxerptjrqs5yuk2f4j6jtgkjxnx4", + "skill/valory/trader_abci/0.1.0": "bafybeib6ftuul7xywf6jo3djf5oxbpf2v56mk5jo3apcrjw6b6t6jyeuyu", "contract/valory/market_maker/0.1.0": "bafybeiftimqgvrbval2lxp7au6y72amioo4gtcdth2dflrbwa47i6opyb4", - "agent/valory/trader/0.1.0": "bafybeidclpkg6uwii2d5gk74b4l6pv3vfgrg5tt3njumhk2ab3uidcogky", - "service/valory/trader/0.1.0": "bafybeidug5h7tac43yp5t6mfyl3qdmfwzh63otz63l547iiguosyyygmnq", + "agent/valory/trader/0.1.0": "bafybeigqa5m2glgteznsq5u7b6xozxacxwdc3fzqszjydur7jggdvz4bti", + "service/valory/trader/0.1.0": "bafybeifbkjth5pf3uivauzwy442z6fxq2brnpc4oa5o42fa4abyhcpnsxe", "contract/valory/erc20/0.1.0": "bafybeifjwr6rwklgg2uk2zkfysn55qqy7dfi4jx7sek6lzdup37fynhpxe", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiffvwkifzq4eiqr4syfbbsfjcrsea5wj55ttismoxozt6trithu7u", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiekmihdxbomflh7baa4nnh73hgigd4taqsld7swa4lmlltpcisn6u", "contract/valory/mech/0.1.0": "bafybeie753wdqks6k4x5fqlpo7tgll2avutjcaodpwlptqvzefsi5xbvai", "contract/valory/realitio/0.1.0": "bafybeid5cdncqui3egi57eh6ptz2yqxsjpnmwzdc2siewuown3gktdwm6m", "contract/valory/realitio_proxy/0.1.0": "bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index 6e5f34131..b1802da75 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -41,10 +41,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeifoihgilpfr76hc5skzspm6qehkwivx7ld2cy3veipcsi4gr2c7na - valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu - valory/transaction_settlement_abci:0.1.0:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiffvwkifzq4eiqr4syfbbsfjcrsea5wj55ttismoxozt6trithu7u -- valory/market_manager_abci:0.1.0:bafybeibwcm2wqoucpbep6pav4fb5mofhjahxiqszul4wcv4xr52dei6pe4 -- valory/decision_maker_abci:0.1.0:bafybeiejy2zxj5wzriay2vwecgvxxprwvs6rt32627jtjfn7gtsy46eimy -- valory/trader_abci:0.1.0:bafybeiexo6pdhhdipnceixtls47jonhflcqsxnbv2c333zmgfxmoygfwgu +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiekmihdxbomflh7baa4nnh73hgigd4taqsld7swa4lmlltpcisn6u +- valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi +- valory/decision_maker_abci:0.1.0:bafybeiapptasim4es2d6c5y77xgdb4gxerptjrqs5yuk2f4j6jtgkjxnx4 +- valory/trader_abci:0.1.0:bafybeib6ftuul7xywf6jo3djf5oxbpf2v56mk5jo3apcrjw6b6t6jyeuyu default_ledger: ethereum required_ledgers: - ethereum diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index fad45392b..fb9cb125b 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:bafybeidclpkg6uwii2d5gk74b4l6pv3vfgrg5tt3njumhk2ab3uidcogky +agent: valory/trader:0.1.0:bafybeigqa5m2glgteznsq5u7b6xozxacxwdc3fzqszjydur7jggdvz4bti 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 0b5daac9f..cb525c784 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -15,25 +15,25 @@ fingerprint: behaviours/base.py: bafybeibrqxw7jdslsew226tss3p3s7fhj6rkwz6fig46zgnp54ijyspgly behaviours/bet_placement.py: bafybeicdmayxmxvydechibri7z45wrx7n354eny4s5aval5mk2pqdszh64 behaviours/blacklisting.py: bafybeicvespraci44y2dtddy4wi7cdhjuyk6crjs7ztnssm2rcrovha3hm - behaviours/decision_receive.py: bafybeigjct7st66x7n3go5vdp62wtdxgmgw233hyyvd3a63ly4x3ptdqbq - behaviours/decision_request.py: bafybeienx5mvflzrgbocqdnqwkyvi3s5xxcgwcaxcrzd2vqazqntn3pyfi + behaviours/decision_receive.py: bafybeiagj6ilqz7rfjaqa4b3rtunyhigtxhwkb4auylquq77ltjdczksj4 + behaviours/decision_request.py: bafybeifjlh5cfitjd6wjcvcgoji2bhsi4r5nzpqocotwprmn26eiphlmqq behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm behaviours/reedem.py: bafybeians77pl4tc6enkf4vmkzeg4kjjnjugtm5to36ma4z6x4a5hurmuq behaviours/round_behaviour.py: bafybeifk5utwuaneima4rdeow7tcpbe6hcc2utlzxcw3w7vsm5zw7zpamm - behaviours/sampling.py: bafybeiesza5cols7opbpp3g3ozyqmskl5g6cqdjow4vsq4r7tet2xkyruq + behaviours/sampling.py: bafybeiadikynvkaofbko72jc45xthhmmjfmlkpgramormhxwk5u47rnwdu dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm fsm_specification.yaml: bafybeigrljw66oxyvn5wqecfgkcx7ozkjg7xuv75zcjmo25fft37qyed6y handlers.py: bafybeihj33szgrcxnpd73s4nvluyxwwsvhjum2cuq3ilhhe6vfola3k7vy models.py: bafybeibyfpucv2e6kltxpjkwobeg3u2ejrceba6cyuecuwbmpv4q7zmu3m - payloads.py: bafybeigate7v3haokrquzojwl6ycgf3zosclgjhmiuqhrx3kpbnj6hacte + payloads.py: bafybeifbnyviargcj5w5kbuuvc3o4y5sdogtuynd2b4ca4xsfbi3cqcwlm redeem_info.py: bafybeie3s7syjr5dfwg33l4663zhkeiokvpulenndwboiyv4imzxr4bdyy rounds.py: bafybeihpstybessozkb3hjxhf3gvf323zw4d575ihmxrsuzcyhqtbsruoq states/__init__.py: bafybeid23llnyp6j257dluxmrnztugo5llsrog7kua53hllyktz4dqhqoy - states/base.py: bafybeigyicytkdcho5l4i6a6b724zv7otwekecvztbf7wvx7zh6crugbny + states/base.py: bafybeif42mqu6wu55iyjyqxto3poyta22gdsswgtus55lo4qpmv74wvlmm states/bet_placement.py: bafybeibalhxhp2c4oljmiwqi6ds3g36fgtabmf42mb5sgq6z22znrcbhda states/blacklisting.py: bafybeiao747i4z7owk6dmwfuzdijag55m3ryj3nowfoggvczpgk3koza44 states/decision_receive.py: bafybeifm3oyq2aji7f5yag6wpe4vr3ivi74pybdsk2jvmziiidx5nt7t4a - states/decision_request.py: bafybeiguje2p3qmqvg6bujf5n7ncr4ss63mviqp4rbnequel37ocuhhvgm + states/decision_request.py: bafybeic7otc3hjb753svbmur3yyk6szahc25yii3x4w4vcnpfz6jwvacuu states/final_states.py: bafybeidiwhuyd5zm2cq7vhv2owcrxdpm7fnvn3db6p6tql4jz5hgpalflu states/handle_failed_tx.py: bafybeihewm2vernvhktuorljdupjqcg2p5vs6wvsira2d62wkoyo5xlzjm states/redeem.py: bafybeifl7qgs2xvm4nykloec5tq47sriqah3dzahv3gppvgtrrxzw5yyyq @@ -53,7 +53,7 @@ protocols: - valory/contract_api:1.0.0:bafybeiasywsvax45qmugus5kxogejj66c5taen27h4voriodz7rgushtqa skills: - valory/abstract_round_abci:0.1.0:bafybeif3cqkks5qx3lqi6nwwhebcirhazt2vidw3sueeqsyxvjeszjt3om -- valory/market_manager_abci:0.1.0:bafybeibwcm2wqoucpbep6pav4fb5mofhjahxiqszul4wcv4xr52dei6pe4 +- valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi - valory/transaction_settlement_abci:0.1.0:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi behaviours: main: diff --git a/packages/valory/skills/market_manager_abci/skill.yaml b/packages/valory/skills/market_manager_abci/skill.yaml index 5ef3996dc..94462f1e1 100644 --- a/packages/valory/skills/market_manager_abci/skill.yaml +++ b/packages/valory/skills/market_manager_abci/skill.yaml @@ -9,13 +9,13 @@ fingerprint: README.md: bafybeie6miwn67uin3bphukmf7qgiifh4xtm42i5v3nuyqxzxtehxsqvcq __init__.py: bafybeigrtedqzlq5mtql2ssjsdriw76ml3666m4e2c3fay6vmyzofl6v6e behaviours.py: bafybeigy224z5niaiafpkaj4jfatw3loywn7onn2obr33tld6lj3dkk33q - bets.py: bafybeidt7njf6fqzxqzmqe6p3k7pxwjhvsd7ynofb76x3ao32izbswilie + bets.py: bafybeid5jw3o57bivq32ojphjmu3xoulf6y6r2pnzuhyp7u6nz3pojpbuu dialogues.py: bafybeiebofyykseqp3fmif36cqmmyf3k7d2zbocpl6t6wnlpv4szghrxbm fsm_specification.yaml: bafybeic5cvwfbiu5pywyp3h5s2elvu7jqdrcwayay7o3v3ow47vu2jw53q graph_tooling/__init__.py: bafybeigzo7nhbzafyq3fuhrlewksjvmzttiuk4vonrggtjtph4rw4ncpk4 graph_tooling/queries/__init__.py: bafybeihbybnl53i7k57ql5ujt5ru5n2eg324jfndh4lcnm4fk52mwbkjda graph_tooling/queries/network.py: bafybeigeq72ys2nrjqspj2uacaudrgljrne5a3o5jvzsktldxdq6m2xmeu - graph_tooling/queries/omen.py: bafybeibgo3d5aqgbpyzkl5ujvhi4gj3mo4oymtpuwfkodlis4ti7pafjvm + graph_tooling/queries/omen.py: bafybeie3g27ald6eb35uonu4itfxsj7gvkqdrhj3sn5mfrotodyq5m3nzu graph_tooling/requests.py: bafybeiee27knuanzuvk4boop6ycfn3vlpm22zgclwynkgeiauywjeo2r3e handlers.py: bafybeihot2i2yvfkz2gcowvt66wdu6tkjbmv7hsmc4jzt4reqeaiuphbtu models.py: bafybeifmb4cojxesv2lcw6j3pm3yqjpsiuwyxpuexjbz656fpapdqcj2ba diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index d220e7200..c6c2ee520 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -24,9 +24,9 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeifoihgilpfr76hc5skzspm6qehkwivx7ld2cy3veipcsi4gr2c7na - valory/transaction_settlement_abci:0.1.0:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi - valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu -- valory/market_manager_abci:0.1.0:bafybeibwcm2wqoucpbep6pav4fb5mofhjahxiqszul4wcv4xr52dei6pe4 -- valory/decision_maker_abci:0.1.0:bafybeiejy2zxj5wzriay2vwecgvxxprwvs6rt32627jtjfn7gtsy46eimy -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiffvwkifzq4eiqr4syfbbsfjcrsea5wj55ttismoxozt6trithu7u +- valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi +- valory/decision_maker_abci:0.1.0:bafybeiapptasim4es2d6c5y77xgdb4gxerptjrqs5yuk2f4j6jtgkjxnx4 +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiekmihdxbomflh7baa4nnh73hgigd4taqsld7swa4lmlltpcisn6u 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 6362dcd23..47f1ef96b 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:bafybeif3cqkks5qx3lqi6nwwhebcirhazt2vidw3sueeqsyxvjeszjt3om -- valory/decision_maker_abci:0.1.0:bafybeiejy2zxj5wzriay2vwecgvxxprwvs6rt32627jtjfn7gtsy46eimy +- valory/decision_maker_abci:0.1.0:bafybeiapptasim4es2d6c5y77xgdb4gxerptjrqs5yuk2f4j6jtgkjxnx4 behaviours: main: args: {} From a2e6056a0cfa7c1d03cdf586eff9b78795be21f7 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 12:34:36 +0300 Subject: [PATCH 05/15] fix: handle any of the read timeout exceptions --- packages/valory/contracts/conditional_tokens/contract.py | 5 +++-- packages/valory/contracts/conditional_tokens/contract.yaml | 2 ++ packages/valory/contracts/realitio/contract.py | 5 +++-- packages/valory/contracts/realitio/contract.yaml | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/valory/contracts/conditional_tokens/contract.py b/packages/valory/contracts/conditional_tokens/contract.py index 77b3cec16..6a9244420 100644 --- a/packages/valory/contracts/conditional_tokens/contract.py +++ b/packages/valory/contracts/conditional_tokens/contract.py @@ -21,7 +21,8 @@ from typing import List, Dict -import requests +from requests.exceptions import ReadTimeout as RequestsReadTimeoutError +from urllib3.exceptions import ReadTimeoutError as Urllib3ReadTimeoutError from aea.common import JSONLike from aea.configurations.base import PublicId from aea.contracts.base import Contract @@ -86,7 +87,7 @@ def check_redeemed( try: redeemed = list(payout_filter.deploy(ledger_api.api).get_all_entries()) - except requests.exceptions.ReadTimeout as exc: + except (Urllib3ReadTimeoutError, RequestsReadTimeoutError) as exc: msg = ( "The RPC timed out! This usually happens if the filtering is too wide. " f"The service tried to filter from block {earliest_block} to latest, " diff --git a/packages/valory/contracts/conditional_tokens/contract.yaml b/packages/valory/contracts/conditional_tokens/contract.yaml index 594cbabb7..72a8b6381 100644 --- a/packages/valory/contracts/conditional_tokens/contract.yaml +++ b/packages/valory/contracts/conditional_tokens/contract.yaml @@ -19,4 +19,6 @@ dependencies: version: ==6.0.1 requests: version: ==2.28.2 + urllib3: + version: ==1.26.16 contracts: [] diff --git a/packages/valory/contracts/realitio/contract.py b/packages/valory/contracts/realitio/contract.py index 47fc6c165..399843d23 100644 --- a/packages/valory/contracts/realitio/contract.py +++ b/packages/valory/contracts/realitio/contract.py @@ -21,7 +21,8 @@ from typing import List, Tuple -import requests +from requests.exceptions import ReadTimeout as RequestsReadTimeoutError +from urllib3.exceptions import ReadTimeoutError as Urllib3ReadTimeoutError from aea.common import JSONLike from aea.configurations.base import PublicId from aea.contracts.base import Contract @@ -73,7 +74,7 @@ def _get_claim_params( try: answered = list(answer_filter.deploy(ledger_api.api).get_all_entries()) - except requests.exceptions.ReadTimeout as exc: + except (Urllib3ReadTimeoutError, RequestsReadTimeoutError) as exc: msg = ( "The RPC timed out! This usually happens if the filtering is too wide. " f"The service tried to filter from block {from_block} to latest, " diff --git a/packages/valory/contracts/realitio/contract.yaml b/packages/valory/contracts/realitio/contract.yaml index c003700e6..defbd51b9 100644 --- a/packages/valory/contracts/realitio/contract.yaml +++ b/packages/valory/contracts/realitio/contract.yaml @@ -20,4 +20,6 @@ dependencies: version: ==6.0.1 requests: version: ==2.28.2 + urllib3: + version: ==1.26.16 contracts: [] From 6dd724b42ac56e16fef5e44eca3d1f6b54a369d7 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 15:31:07 +0300 Subject: [PATCH 06/15] refactor: use messages instead of exceptions from contracts --- .../contracts/conditional_tokens/contract.py | 8 ++------ .../valory/contracts/realitio/contract.py | 19 +++++++++---------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/packages/valory/contracts/conditional_tokens/contract.py b/packages/valory/contracts/conditional_tokens/contract.py index 6a9244420..3aec5e351 100644 --- a/packages/valory/contracts/conditional_tokens/contract.py +++ b/packages/valory/contracts/conditional_tokens/contract.py @@ -35,10 +35,6 @@ DEFAULT_TO_BLOCK = "latest" -class RPCTimedOutError(Exception): - """Exception to raise when the RPC times out.""" - - class ConditionalTokensContract(Contract): """The ConditionalTokens smart contract.""" @@ -87,7 +83,7 @@ def check_redeemed( try: redeemed = list(payout_filter.deploy(ledger_api.api).get_all_entries()) - except (Urllib3ReadTimeoutError, RequestsReadTimeoutError) as exc: + except (Urllib3ReadTimeoutError, RequestsReadTimeoutError): msg = ( "The RPC timed out! This usually happens if the filtering is too wide. " f"The service tried to filter from block {earliest_block} to latest, " @@ -96,7 +92,7 @@ def check_redeemed( "Please consider manually redeeming for the market with condition id " f"{earliest_condition_id!r} if this issue persists." ) - raise RPCTimedOutError(msg) from exc + return dict(error=msg) payouts = {} for redeeming in redeemed: diff --git a/packages/valory/contracts/realitio/contract.py b/packages/valory/contracts/realitio/contract.py index 399843d23..478f832fc 100644 --- a/packages/valory/contracts/realitio/contract.py +++ b/packages/valory/contracts/realitio/contract.py @@ -19,7 +19,7 @@ """This module contains the Realitio_v2_1 contract definition.""" -from typing import List, Tuple +from typing import List, Tuple, Union from requests.exceptions import ReadTimeout as RequestsReadTimeoutError from urllib3.exceptions import ReadTimeoutError as Urllib3ReadTimeoutError @@ -35,10 +35,6 @@ ZERO_BYTES = bytes.fromhex(ZERO_HEX) -class RPCTimedOutError(Exception): - """Exception to raise when the RPC times out.""" - - class RealitioContract(Contract): """The Realitio_v2_1 smart contract.""" @@ -63,7 +59,7 @@ def _get_claim_params( contract_address: str, from_block: BlockIdentifier, question_id: bytes, - ) -> Tuple[bytes, List[bytes], List[ChecksumAddress], List[int], List[bytes]]: + ) -> Union[str, Tuple[bytes, List[bytes], List[ChecksumAddress], List[int], List[bytes]]]: """Filters the `LogNewAnswer` event by question id to calculate the history hashes.""" contract_instance = cls.get_instance(ledger_api, contract_address) @@ -74,7 +70,7 @@ def _get_claim_params( try: answered = list(answer_filter.deploy(ledger_api.api).get_all_entries()) - except (Urllib3ReadTimeoutError, RequestsReadTimeoutError) as exc: + except (Urllib3ReadTimeoutError, RequestsReadTimeoutError): msg = ( "The RPC timed out! This usually happens if the filtering is too wide. " f"The service tried to filter from block {from_block} to latest, " @@ -82,13 +78,13 @@ def _get_claim_params( "Please consider manually redeeming for the market with question id " f"{question_id!r} if this issue persists." ) - raise RPCTimedOutError(msg) from exc + return msg else: n_answered = len(answered) if n_answered == 0: - msg = f"No answers have been given for question with id {question_id}!" - raise ValueError(msg) + msg = f"No answers have been given for question with id {question_id.hex()}!" + return msg history_hashes = [] addresses = [] @@ -124,6 +120,9 @@ def build_claim_winnings( claim_params = cls._get_claim_params( ledger_api, contract_address, from_block, question_id ) + if isinstance(claim_params, str): + return dict(error=claim_params) + data = contract.encodeABI( fn_name="claimWinnings", args=claim_params, From 6d77c4870eb5b337e554280863f5fb5ef70ea7ff Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 15:31:48 +0300 Subject: [PATCH 07/15] refactor: update error message --- packages/valory/contracts/conditional_tokens/contract.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/valory/contracts/conditional_tokens/contract.py b/packages/valory/contracts/conditional_tokens/contract.py index 3aec5e351..0456050ef 100644 --- a/packages/valory/contracts/conditional_tokens/contract.py +++ b/packages/valory/contracts/conditional_tokens/contract.py @@ -87,10 +87,10 @@ def check_redeemed( msg = ( "The RPC timed out! This usually happens if the filtering is too wide. " f"The service tried to filter from block {earliest_block} to latest, " - f"as the earliest market creation transaction took place at block {earliest_block}." + f"as the earliest market creation transaction took place at block {earliest_block}. " f"Did the creation happen too long in the past?\n" - "Please consider manually redeeming for the market with condition id " - f"{earliest_condition_id!r} if this issue persists." + f"The market with condition id {earliest_condition_id!r} " + f"is the oldest one and the block filtering was set based on it." ) return dict(error=msg) From d61c01df1b5a1d6becaa4f649527f405dae06653 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 15:32:39 +0300 Subject: [PATCH 08/15] fix: do not check if redeemed when no trades are available --- .../valory/skills/decision_maker_abci/behaviours/reedem.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/reedem.py b/packages/valory/skills/decision_maker_abci/behaviours/reedem.py index c4c4abfa8..595083910 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/reedem.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/reedem.py @@ -267,6 +267,9 @@ def _conditional_tokens_interact( def _check_already_redeemed(self) -> WaitableConditionType: """Check whether we have already redeemed for this bet.""" + if len(self.trades) == 0: + return True + kwargs: Dict[str, Any] = { key: [] for key in ( From ae943a33e2134cd36f27c307219ca357411cb844 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 12:41:31 +0300 Subject: [PATCH 09/15] chore: run generators --- packages/packages.json | 14 +++++++------- packages/valory/agents/trader/aea-config.yaml | 10 +++++----- .../contracts/conditional_tokens/contract.yaml | 2 +- packages/valory/contracts/realitio/contract.yaml | 2 +- packages/valory/services/trader/service.yaml | 2 +- .../valory/skills/decision_maker_abci/skill.yaml | 6 +++--- packages/valory/skills/trader_abci/skill.yaml | 4 ++-- .../tx_settlement_multiplexer_abci/skill.yaml | 2 +- pyproject.toml | 1 + tox.ini | 1 + 10 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index abdb10d2c..c2ea36428 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -1,17 +1,17 @@ { "dev": { "skill/valory/market_manager_abci/0.1.0": "bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi", - "skill/valory/decision_maker_abci/0.1.0": "bafybeiapptasim4es2d6c5y77xgdb4gxerptjrqs5yuk2f4j6jtgkjxnx4", - "skill/valory/trader_abci/0.1.0": "bafybeib6ftuul7xywf6jo3djf5oxbpf2v56mk5jo3apcrjw6b6t6jyeuyu", + "skill/valory/decision_maker_abci/0.1.0": "bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy", + "skill/valory/trader_abci/0.1.0": "bafybeigjfwyknvwpevqqavbj57lncpdd3ehvg73vit4nflcu5e2ue4pd6e", "contract/valory/market_maker/0.1.0": "bafybeiftimqgvrbval2lxp7au6y72amioo4gtcdth2dflrbwa47i6opyb4", - "agent/valory/trader/0.1.0": "bafybeigqa5m2glgteznsq5u7b6xozxacxwdc3fzqszjydur7jggdvz4bti", - "service/valory/trader/0.1.0": "bafybeifbkjth5pf3uivauzwy442z6fxq2brnpc4oa5o42fa4abyhcpnsxe", + "agent/valory/trader/0.1.0": "bafybeigu6x25vtbu44tiovd3dd7eygwwf4q6lgnafdswzvhtw26xu66udu", + "service/valory/trader/0.1.0": "bafybeignuhovmv5sbeyodkmgohntokcnm55yrscjd7bybrlq3sng2ytmvy", "contract/valory/erc20/0.1.0": "bafybeifjwr6rwklgg2uk2zkfysn55qqy7dfi4jx7sek6lzdup37fynhpxe", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiekmihdxbomflh7baa4nnh73hgigd4taqsld7swa4lmlltpcisn6u", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa", "contract/valory/mech/0.1.0": "bafybeie753wdqks6k4x5fqlpo7tgll2avutjcaodpwlptqvzefsi5xbvai", - "contract/valory/realitio/0.1.0": "bafybeid5cdncqui3egi57eh6ptz2yqxsjpnmwzdc2siewuown3gktdwm6m", + "contract/valory/realitio/0.1.0": "bafybeigb722aznqhc5lsbt3dn4bpyaqe5hnl5onmnestqmzliwtvl3eaom", "contract/valory/realitio_proxy/0.1.0": "bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy", - "contract/valory/conditional_tokens/0.1.0": "bafybeiftqtsn6yygfhubzcsc2jluhhx5pt2udzvh4cjr26a4qxmp4bjqba" + "contract/valory/conditional_tokens/0.1.0": "bafybeiaqcyzbuhv4ey2h7hn2dq5zibf3pmkotx2t7fihdawf5h4u4uu65e" }, "third_party": { "protocol/open_aea/signing/1.0.0": "bafybeifuxs7gdg2okbn7uofymenjlmnih2wxwkym44lsgwmklgwuckxm2m", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index b1802da75..0d14ac321 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -22,8 +22,8 @@ contracts: - valory/erc20:0.1.0:bafybeifjwr6rwklgg2uk2zkfysn55qqy7dfi4jx7sek6lzdup37fynhpxe - valory/multisend:0.1.0:bafybeie7m7pjbnw7cccpbvmbgkut24dtlt4cgvug3tbac7gej37xvwbv3a - valory/mech:0.1.0:bafybeie753wdqks6k4x5fqlpo7tgll2avutjcaodpwlptqvzefsi5xbvai -- valory/conditional_tokens:0.1.0:bafybeiftqtsn6yygfhubzcsc2jluhhx5pt2udzvh4cjr26a4qxmp4bjqba -- valory/realitio:0.1.0:bafybeid5cdncqui3egi57eh6ptz2yqxsjpnmwzdc2siewuown3gktdwm6m +- valory/conditional_tokens:0.1.0:bafybeiaqcyzbuhv4ey2h7hn2dq5zibf3pmkotx2t7fihdawf5h4u4uu65e +- valory/realitio:0.1.0:bafybeigb722aznqhc5lsbt3dn4bpyaqe5hnl5onmnestqmzliwtvl3eaom - valory/realitio_proxy:0.1.0:bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy protocols: - open_aea/signing:1.0.0:bafybeifuxs7gdg2okbn7uofymenjlmnih2wxwkym44lsgwmklgwuckxm2m @@ -41,10 +41,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeifoihgilpfr76hc5skzspm6qehkwivx7ld2cy3veipcsi4gr2c7na - valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu - valory/transaction_settlement_abci:0.1.0:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiekmihdxbomflh7baa4nnh73hgigd4taqsld7swa4lmlltpcisn6u +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa - valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi -- valory/decision_maker_abci:0.1.0:bafybeiapptasim4es2d6c5y77xgdb4gxerptjrqs5yuk2f4j6jtgkjxnx4 -- valory/trader_abci:0.1.0:bafybeib6ftuul7xywf6jo3djf5oxbpf2v56mk5jo3apcrjw6b6t6jyeuyu +- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy +- valory/trader_abci:0.1.0:bafybeigjfwyknvwpevqqavbj57lncpdd3ehvg73vit4nflcu5e2ue4pd6e default_ledger: ethereum required_ledgers: - ethereum diff --git a/packages/valory/contracts/conditional_tokens/contract.yaml b/packages/valory/contracts/conditional_tokens/contract.yaml index 72a8b6381..c3288710d 100644 --- a/packages/valory/contracts/conditional_tokens/contract.yaml +++ b/packages/valory/contracts/conditional_tokens/contract.yaml @@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0' fingerprint: __init__.py: bafybeidhdxio3oq5gqdnxmngumvt3fcd6zyiyrpk5f2k4dwhflbg4e5iky build/ConditionalTokens.json: bafybeia2ahis7zx2yhhf23kpkcxu56hto6fwg6ptjg5ld46lp4dgz7cz3e - contract.py: bafybeic2j4bpss23dgsavdxnng5ulas4hchmwn4djs4ock4i7dawab3hxu + contract.py: bafybeiamr2y22rcwlf2h75uryweqx4qjztjrmhzb2flivkcfqvifedvdpi fingerprint_ignore_patterns: [] class_name: ConditionalTokensContract contract_interface_paths: diff --git a/packages/valory/contracts/realitio/contract.yaml b/packages/valory/contracts/realitio/contract.yaml index defbd51b9..07ebac706 100644 --- a/packages/valory/contracts/realitio/contract.yaml +++ b/packages/valory/contracts/realitio/contract.yaml @@ -8,7 +8,7 @@ aea_version: '>=1.0.0, <2.0.0' fingerprint: __init__.py: bafybeictahkgfmlqv5kksvj6klmxtmjdpeq4sp3x7dp2yr5x4kmzbcihse build/Realitio.json: bafybeiagi7zoeoy5s7duhg4oeuekj2s6z5mad2z6g2pn3n5elsvze25qiu - contract.py: bafybeiack5tz6vyesyvpq6wqhkkrdfevjedopdvjgyv5erhatknw2fazz4 + contract.py: bafybeibygb64t4bhajvoyf54o6tkvwedsczhwltkqwwxmix2w6ar2wcvyy fingerprint_ignore_patterns: [] class_name: RealitioContract contract_interface_paths: diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index fb9cb125b..66c6c4cc7 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:bafybeigqa5m2glgteznsq5u7b6xozxacxwdc3fzqszjydur7jggdvz4bti +agent: valory/trader:0.1.0:bafybeigu6x25vtbu44tiovd3dd7eygwwf4q6lgnafdswzvhtw26xu66udu 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 cb525c784..24c9f8205 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -18,7 +18,7 @@ fingerprint: behaviours/decision_receive.py: bafybeiagj6ilqz7rfjaqa4b3rtunyhigtxhwkb4auylquq77ltjdczksj4 behaviours/decision_request.py: bafybeifjlh5cfitjd6wjcvcgoji2bhsi4r5nzpqocotwprmn26eiphlmqq behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm - behaviours/reedem.py: bafybeians77pl4tc6enkf4vmkzeg4kjjnjugtm5to36ma4z6x4a5hurmuq + behaviours/reedem.py: bafybeib25frcafu6iikppidwqqovwjkzkxif6m3f4crmklohpj6yixprsq behaviours/round_behaviour.py: bafybeifk5utwuaneima4rdeow7tcpbe6hcc2utlzxcw3w7vsm5zw7zpamm behaviours/sampling.py: bafybeiadikynvkaofbko72jc45xthhmmjfmlkpgramormhxwk5u47rnwdu dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm @@ -46,8 +46,8 @@ contracts: - valory/erc20:0.1.0:bafybeifjwr6rwklgg2uk2zkfysn55qqy7dfi4jx7sek6lzdup37fynhpxe - valory/multisend:0.1.0:bafybeie7m7pjbnw7cccpbvmbgkut24dtlt4cgvug3tbac7gej37xvwbv3a - valory/mech:0.1.0:bafybeie753wdqks6k4x5fqlpo7tgll2avutjcaodpwlptqvzefsi5xbvai -- valory/conditional_tokens:0.1.0:bafybeiftqtsn6yygfhubzcsc2jluhhx5pt2udzvh4cjr26a4qxmp4bjqba -- valory/realitio:0.1.0:bafybeid5cdncqui3egi57eh6ptz2yqxsjpnmwzdc2siewuown3gktdwm6m +- valory/conditional_tokens:0.1.0:bafybeiaqcyzbuhv4ey2h7hn2dq5zibf3pmkotx2t7fihdawf5h4u4uu65e +- valory/realitio:0.1.0:bafybeigb722aznqhc5lsbt3dn4bpyaqe5hnl5onmnestqmzliwtvl3eaom - valory/realitio_proxy:0.1.0:bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy protocols: - valory/contract_api:1.0.0:bafybeiasywsvax45qmugus5kxogejj66c5taen27h4voriodz7rgushtqa diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index c6c2ee520..7e0d119a4 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:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi - valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu - valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi -- valory/decision_maker_abci:0.1.0:bafybeiapptasim4es2d6c5y77xgdb4gxerptjrqs5yuk2f4j6jtgkjxnx4 -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiekmihdxbomflh7baa4nnh73hgigd4taqsld7swa4lmlltpcisn6u +- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa 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 47f1ef96b..2e031116a 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:bafybeif3cqkks5qx3lqi6nwwhebcirhazt2vidw3sueeqsyxvjeszjt3om -- valory/decision_maker_abci:0.1.0:bafybeiapptasim4es2d6c5y77xgdb4gxerptjrqs5yuk2f4j6jtgkjxnx4 +- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy behaviours: main: args: {} diff --git a/pyproject.toml b/pyproject.toml index d0f203c26..8816b4d94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ eth-utils = "==2.2.0" eth-abi = "==4.0.0" pycryptodome = "==3.18.0" pytest = "==7.2.1" +urllib3 = "==1.26.16" [tool.poetry.group.dev.dependencies.tomte] version = "==0.2.12" diff --git a/tox.ini b/tox.ini index aee217b87..47a4de9c5 100644 --- a/tox.ini +++ b/tox.ini @@ -50,6 +50,7 @@ deps = eth-abi==4.0.0 pycryptodome==3.18.0 pytest==7.2.1 + urllib3==1.26.16 [testenv] basepython = python3 From 4e6596824903c71cdb0cdcb3dbba63ebc060b454 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 13:30:48 +0300 Subject: [PATCH 10/15] refactor: use a function to remove the fraction --- .../valory/skills/decision_maker_abci/behaviours/base.py | 8 ++++++++ .../decision_maker_abci/behaviours/decision_receive.py | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/base.py b/packages/valory/skills/decision_maker_abci/behaviours/base.py index acc562d1d..889a40483 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/base.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/base.py @@ -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.""" diff --git a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py index c0c3a6034..8478c5ff8 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py @@ -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, @@ -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 From d4f496cf0078c16b75a27c6c697e77f4a161bc3b Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 13:43:44 +0300 Subject: [PATCH 11/15] feat: apply a slippage to the `minOutcomeTokensToBuy` --- packages/valory/agents/trader/aea-config.yaml | 1 + packages/valory/services/trader/service.yaml | 4 ++++ .../behaviours/bet_placement.py | 3 ++- .../valory/skills/decision_maker_abci/models.py | 17 +++++++++++++++++ .../skills/decision_maker_abci/skill.yaml | 1 + packages/valory/skills/trader_abci/skill.yaml | 1 + 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index 0d14ac321..63cbdfcf2 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -185,6 +185,7 @@ models: realitio_proxy_address: ${str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${int:5} + slippage: ${float:0.01} --- public_id: valory/p2p_libp2p_client:0.1.0 type: connection diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 66c6c4cc7..5d1a90e9f 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -102,6 +102,7 @@ type: skill realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} + slippage: ${SLIPPAGE:float:0.01} benchmark_tool: &id005 args: log_dir: ${LOG_DIR:str:/benchmarks} @@ -164,6 +165,7 @@ type: skill realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} + slippage: ${SLIPPAGE:float:0.01} benchmark_tool: *id005 2: models: @@ -224,6 +226,7 @@ type: skill realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} + slippage: ${SLIPPAGE:float:0.01} benchmark_tool: *id005 3: models: @@ -284,6 +287,7 @@ type: skill realitio_proxy_address: ${REALITIO_PROXY_ADDRESS:str:0xAB16D643bA051C11962DA645f74632d3130c81E2} realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} + slippage: ${SLIPPAGE:float:0.01} benchmark_tool: *id005 --- public_id: valory/ledger:0.19.0 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 de97764e4..fa7b027f7 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/bet_placement.py @@ -31,6 +31,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 MultisendBatch from packages.valory.skills.decision_maker_abci.payloads import MultisigTxPayload @@ -199,7 +200,7 @@ def _calc_buy_amount(self) -> WaitableConditionType: ) return False - self.buy_amount = int(buy_amount) + self.buy_amount = remove_fraction_wei(buy_amount, self.params.slippage) return True def _build_buy_tx(self) -> WaitableConditionType: diff --git a/packages/valory/skills/decision_maker_abci/models.py b/packages/valory/skills/decision_maker_abci/models.py index 8bc558e9a..4b861687c 100644 --- a/packages/valory/skills/decision_maker_abci/models.py +++ b/packages/valory/skills/decision_maker_abci/models.py @@ -120,6 +120,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # this is the max number of redeeming operations that will be batched on a single multisend transaction. # increasing this number equals fewer fees but more chances for the transaction to fail self.redeeming_batch_size = self._ensure("redeeming_batch_size", kwargs, int) + # a slippage in the range of [0, 1] to apply to the `minOutcomeTokensToBuy` when buying shares on a fpmm + self._slippage = 0.0 + self.slippage = self._ensure("slippage", kwargs, float) super().__init__(*args, **kwargs) @property @@ -134,6 +137,20 @@ def prompt_template(self) -> PromptTemplate: """Get the prompt template as a string `PromptTemplate`.""" return PromptTemplate(self._prompt_template) + @property + def slippage(self) -> float: + """Get the slippage.""" + return self._slippage + + @slippage.setter + def slippage(self, slippage: float) -> None: + """Set the slippage.""" + if slippage < 0 or slippage > 1: + raise ValueError( + f"The configured slippage {slippage!r} is not in the range [0, 1]." + ) + self._slippage = slippage + def get_bet_amount(self, confidence: float) -> int: """Get the bet amount given a prediction's confidence.""" threshold = round(confidence, 1) diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index 24c9f8205..5231cadbd 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -180,6 +180,7 @@ models: realitio_proxy_address: '0xAB16D643bA051C11962DA645f74632d3130c81E2' realitio_address: '0x79e32aE03fb27B07C89c0c568F80287C01ca2E57' redeeming_batch_size: 5 + slippage: 0.01 class_name: DecisionMakerParams mech_response: args: diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 7e0d119a4..2b4d8b499 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -167,6 +167,7 @@ models: realitio_proxy_address: '0xAB16D643bA051C11962DA645f74632d3130c81E2' realitio_address: '0x79e32aE03fb27B07C89c0c568F80287C01ca2E57' redeeming_batch_size: 5 + slippage: 0.01 class_name: TraderParams network_subgraph: args: From 06628213aa0b0c42d2a5a6fcdf33d725cd3b8626 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 17:17:47 +0300 Subject: [PATCH 12/15] 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 | 8 ++++---- packages/valory/skills/trader_abci/skill.yaml | 4 ++-- .../skills/tx_settlement_multiplexer_abci/skill.yaml | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index c2ea36428..35a28fabd 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -1,13 +1,13 @@ { "dev": { "skill/valory/market_manager_abci/0.1.0": "bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi", - "skill/valory/decision_maker_abci/0.1.0": "bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy", - "skill/valory/trader_abci/0.1.0": "bafybeigjfwyknvwpevqqavbj57lncpdd3ehvg73vit4nflcu5e2ue4pd6e", + "skill/valory/decision_maker_abci/0.1.0": "bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva", + "skill/valory/trader_abci/0.1.0": "bafybeihcdi3ccfk5g24luowanzshx62mmvzgkodi5az3imjchsx3kioywa", "contract/valory/market_maker/0.1.0": "bafybeiftimqgvrbval2lxp7au6y72amioo4gtcdth2dflrbwa47i6opyb4", - "agent/valory/trader/0.1.0": "bafybeigu6x25vtbu44tiovd3dd7eygwwf4q6lgnafdswzvhtw26xu66udu", - "service/valory/trader/0.1.0": "bafybeignuhovmv5sbeyodkmgohntokcnm55yrscjd7bybrlq3sng2ytmvy", + "agent/valory/trader/0.1.0": "bafybeidwaaelw6pjl4azfhbvr2k5reywazy244k3tj74fl523lswzhvgeq", + "service/valory/trader/0.1.0": "bafybeidvydnmhv3jr22peqds545dy2odwiyqp465fpsidlw7bmqionovca", "contract/valory/erc20/0.1.0": "bafybeifjwr6rwklgg2uk2zkfysn55qqy7dfi4jx7sek6lzdup37fynhpxe", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu", "contract/valory/mech/0.1.0": "bafybeie753wdqks6k4x5fqlpo7tgll2avutjcaodpwlptqvzefsi5xbvai", "contract/valory/realitio/0.1.0": "bafybeigb722aznqhc5lsbt3dn4bpyaqe5hnl5onmnestqmzliwtvl3eaom", "contract/valory/realitio_proxy/0.1.0": "bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index 63cbdfcf2..bc7585026 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -41,10 +41,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeifoihgilpfr76hc5skzspm6qehkwivx7ld2cy3veipcsi4gr2c7na - valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu - valory/transaction_settlement_abci:0.1.0:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu - valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi -- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy -- valory/trader_abci:0.1.0:bafybeigjfwyknvwpevqqavbj57lncpdd3ehvg73vit4nflcu5e2ue4pd6e +- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva +- valory/trader_abci:0.1.0:bafybeihcdi3ccfk5g24luowanzshx62mmvzgkodi5az3imjchsx3kioywa default_ledger: ethereum required_ledgers: - ethereum diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 5d1a90e9f..5aac006e7 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:bafybeigu6x25vtbu44tiovd3dd7eygwwf4q6lgnafdswzvhtw26xu66udu +agent: valory/trader:0.1.0:bafybeidwaaelw6pjl4azfhbvr2k5reywazy244k3tj74fl523lswzhvgeq 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 5231cadbd..711ecc1c2 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -12,10 +12,10 @@ fingerprint: README.md: bafybeia367zzdwndvlhw27rvnwodytjo3ms7gbc3q7mhrrjqjgfasnk47i __init__.py: bafybeih563ujnigeci2ldzh7hakbau6a222vsed7leg3b7lq32vcn3nm4a behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky - behaviours/base.py: bafybeibrqxw7jdslsew226tss3p3s7fhj6rkwz6fig46zgnp54ijyspgly - behaviours/bet_placement.py: bafybeicdmayxmxvydechibri7z45wrx7n354eny4s5aval5mk2pqdszh64 + behaviours/base.py: bafybeiaxgbkrrskfod55lhynd4ttkwrn6qwzugfmmwikzod4ar6pmjmcu4 + behaviours/bet_placement.py: bafybeifwwvvwh4qgf3jkyvza4wfvjv63il2xewsklsjtpyanp23y6hg2aa behaviours/blacklisting.py: bafybeicvespraci44y2dtddy4wi7cdhjuyk6crjs7ztnssm2rcrovha3hm - behaviours/decision_receive.py: bafybeiagj6ilqz7rfjaqa4b3rtunyhigtxhwkb4auylquq77ltjdczksj4 + behaviours/decision_receive.py: bafybeihe73gjp2dv5czue4mxpxtcsssde7xwwh4fkouzozckkkfzaubnhy behaviours/decision_request.py: bafybeifjlh5cfitjd6wjcvcgoji2bhsi4r5nzpqocotwprmn26eiphlmqq behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm behaviours/reedem.py: bafybeib25frcafu6iikppidwqqovwjkzkxif6m3f4crmklohpj6yixprsq @@ -24,7 +24,7 @@ fingerprint: dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm fsm_specification.yaml: bafybeigrljw66oxyvn5wqecfgkcx7ozkjg7xuv75zcjmo25fft37qyed6y handlers.py: bafybeihj33szgrcxnpd73s4nvluyxwwsvhjum2cuq3ilhhe6vfola3k7vy - models.py: bafybeibyfpucv2e6kltxpjkwobeg3u2ejrceba6cyuecuwbmpv4q7zmu3m + models.py: bafybeibqou3ryuszu2vbwdp5b7fkj5oxmflgh3z3a7tuajbdxgzdolgmee payloads.py: bafybeifbnyviargcj5w5kbuuvc3o4y5sdogtuynd2b4ca4xsfbi3cqcwlm redeem_info.py: bafybeie3s7syjr5dfwg33l4663zhkeiokvpulenndwboiyv4imzxr4bdyy rounds.py: bafybeihpstybessozkb3hjxhf3gvf323zw4d575ihmxrsuzcyhqtbsruoq diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 2b4d8b499..6bcd8f014 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:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi - valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu - valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi -- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiebb35mjfl54woxgu2coald56v3wfgglm26tbdizhmzautquxw6fa +- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu 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 2e031116a..0adde1ddb 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:bafybeif3cqkks5qx3lqi6nwwhebcirhazt2vidw3sueeqsyxvjeszjt3om -- valory/decision_maker_abci:0.1.0:bafybeicmnirdfwyflzc23nvoejdux4cvuhfah4imzrwdcbvnmy3qumqlzy +- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva behaviours: main: args: {} From 01221a222c53b9ae2d1ec03bf286e1626e83fa7a Mon Sep 17 00:00:00 2001 From: Adamantios Date: Wed, 6 Sep 2023 17:33:38 +0300 Subject: [PATCH 13/15] docs: update notes on expected return --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9dfdf7103..9ebefc76c 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ These are the description of the variables used by the Trader service: - `OMEN_CREATORS`: addresses of the market creator(s) that the service will track for placing bets on Omen. The address `0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec` corresponds to the Market creator agent for the Hackathon. - `BET_AMOUNT_PER_THRESHOLD_X`: amount (wei) to bet when the prediction returned by the AI Mech surpasses a threshold of `X`% confidence for a given prediction market. In the values provided above the amounts vary between 0.03 xDAI (60% confidence) and 0.1 xDAI (100% confidence). -- `BET_THRESHOLD`: threshold (wei) for placing a bet. A bet will only be placed if `expected_return - bet_fees >= BET_THRESHOLD`. [See below](#some-notes-on-the-service). +- `BET_THRESHOLD`: threshold (wei) for placing a bet. A bet will only be placed if `potential_net_profit - BET_THRESHOLD >= 0`. [See below](#some-notes-on-the-service). - `PROMPT_TEMPLATE`: prompt to be used with the prediction AI Mech. Please keep it as a single line including the placeholders `@{question}`, `@{yes}` and `@{no}`. @@ -153,8 +153,15 @@ Once you have configured (exported) the environment variables, you are in positi Please take into consideration the following: - If the service does not have enough funds for placing a bet, you will see an `Event.INSUFICIENT_FUNDS` in the service logs. -- If the service determines that a bet is not profitable (i.e., `expected_return - bet_fees < BET_THRESHOLD`), you will see an `Event.UNPROFITABLE` in the service logs, and the service will transition into the blacklisting round. This round blacklists a bet for a predetermined amount of time. This can be adjusted by using the `BLACKLISTING_DURATION` environment variable. -- For simplicity, the current implementation considers `expected_return = bet_amount`, although this calculation might be refined. +- If the service determines that a bet is not profitable + (i.e., `potential_net_profit - BET_THRESHOLD < 0`), you will see an `Event.UNPROFITABLE` in the service logs, + and the service will transition into the blacklisting round. + This round blacklists a bet for a predetermined amount of time. + This can be adjusted by using the `BLACKLISTING_DURATION` environment variable. +- For simplicity, + the current implementation considers `potential_net_profit = num_shares - net_bet_amount - mech_price - BET_THRESHOLD`, + although this calculation might be refined. + The `net_bet_amount` is the bet amount minus the FPMM's fees. - When assigning `BET_THRESHOLD` take into consideration that fees (at the time of writing this guide) are in the range of 0.02 xDAI. See, for example, [here](https://api.thegraph.com/subgraphs/name/protofire/omen-xdai/graphql?query=%7B%0A++fixedProductMarketMakers%28%0A++++where%3A+%7B%0A++++++creator_in%3A+%5B%220x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec%22%5D%2C%0A++++++outcomeSlotCount%3A+2%2C%0A++++++isPendingArbitration%3A+false%0A++++%7D%2C%0A++++orderBy%3A+creationTimestamp%0A++++orderDirection%3A+desc%0A++%29%7B%0A++++fee%0A++%7D%0A%7D). We urge you to keep an eye on these fees, as they might vary. ## For advanced users From 30bf870d342dd3bb85727569179194dd5d3e2813 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Thu, 7 Sep 2023 09:31:23 +0300 Subject: [PATCH 14/15] refactor: do not consider the mech's price https://github.com/valory-xyz/trader/pull/72#discussion_r1317196350 --- .../skills/decision_maker_abci/behaviours/decision_receive.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py index 8478c5ff8..342537407 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/decision_receive.py @@ -276,7 +276,6 @@ def _is_profitable(self, confidence: float, vote: int) -> bool: bet_amount = self.params.get_bet_amount(confidence) 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 if bet_threshold <= 0: @@ -286,7 +285,7 @@ def _is_profitable(self, confidence: float, vote: int) -> bool: ) bet_threshold = 0 - potential_net_profit = num_shares - net_bet_amount - mech_price - bet_threshold + potential_net_profit = num_shares - net_bet_amount - bet_threshold is_profitable = potential_net_profit >= 0 and num_shares <= available_shares shares_out = self.wei_to_native(num_shares) available_in = self.wei_to_native(available_shares) From 7d244153336aac0be3b2a028d08db451a2a04cac Mon Sep 17 00:00:00 2001 From: Adamantios Date: Thu, 7 Sep 2023 09:36:46 +0300 Subject: [PATCH 15/15] 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 35a28fabd..7cc76e354 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -1,13 +1,13 @@ { "dev": { "skill/valory/market_manager_abci/0.1.0": "bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi", - "skill/valory/decision_maker_abci/0.1.0": "bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva", - "skill/valory/trader_abci/0.1.0": "bafybeihcdi3ccfk5g24luowanzshx62mmvzgkodi5az3imjchsx3kioywa", + "skill/valory/decision_maker_abci/0.1.0": "bafybeibadjiuw4icm64rm5mrooht6he2xw6ery6yxu5qnwhqkpwlfhen2m", + "skill/valory/trader_abci/0.1.0": "bafybeif7zbal6iqiui3dwqfswnev6tcjsszixhrpv3m6kufgxfvh7veadi", "contract/valory/market_maker/0.1.0": "bafybeiftimqgvrbval2lxp7au6y72amioo4gtcdth2dflrbwa47i6opyb4", - "agent/valory/trader/0.1.0": "bafybeidwaaelw6pjl4azfhbvr2k5reywazy244k3tj74fl523lswzhvgeq", - "service/valory/trader/0.1.0": "bafybeidvydnmhv3jr22peqds545dy2odwiyqp465fpsidlw7bmqionovca", + "agent/valory/trader/0.1.0": "bafybeietnokftb3klhladvtrrrwhizq7nj64s4tqxbw3xwylxpgulr4g5u", + "service/valory/trader/0.1.0": "bafybeiczvwvd7s2q7yc5lh4qxzolpga4f2xstme4rzq6sot7oefnz7dqim", "contract/valory/erc20/0.1.0": "bafybeifjwr6rwklgg2uk2zkfysn55qqy7dfi4jx7sek6lzdup37fynhpxe", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiez2gopga42empgxlgprmw34joobw3rx2h5ybnk2u35vdmpkjtjfq", "contract/valory/mech/0.1.0": "bafybeie753wdqks6k4x5fqlpo7tgll2avutjcaodpwlptqvzefsi5xbvai", "contract/valory/realitio/0.1.0": "bafybeigb722aznqhc5lsbt3dn4bpyaqe5hnl5onmnestqmzliwtvl3eaom", "contract/valory/realitio_proxy/0.1.0": "bafybeibvndq6756qck7forgeavhdbn6ykgqs2ufyg7n5g6qdfpveatxuwy", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index bc7585026..c65f7ac27 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -41,10 +41,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeifoihgilpfr76hc5skzspm6qehkwivx7ld2cy3veipcsi4gr2c7na - valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu - valory/transaction_settlement_abci:0.1.0:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiez2gopga42empgxlgprmw34joobw3rx2h5ybnk2u35vdmpkjtjfq - valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi -- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva -- valory/trader_abci:0.1.0:bafybeihcdi3ccfk5g24luowanzshx62mmvzgkodi5az3imjchsx3kioywa +- valory/decision_maker_abci:0.1.0:bafybeibadjiuw4icm64rm5mrooht6he2xw6ery6yxu5qnwhqkpwlfhen2m +- valory/trader_abci:0.1.0:bafybeif7zbal6iqiui3dwqfswnev6tcjsszixhrpv3m6kufgxfvh7veadi default_ledger: ethereum required_ledgers: - ethereum diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 5aac006e7..5aea81645 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:bafybeidwaaelw6pjl4azfhbvr2k5reywazy244k3tj74fl523lswzhvgeq +agent: valory/trader:0.1.0:bafybeietnokftb3klhladvtrrrwhizq7nj64s4tqxbw3xwylxpgulr4g5u 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 711ecc1c2..125f5a49d 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -15,7 +15,7 @@ fingerprint: behaviours/base.py: bafybeiaxgbkrrskfod55lhynd4ttkwrn6qwzugfmmwikzod4ar6pmjmcu4 behaviours/bet_placement.py: bafybeifwwvvwh4qgf3jkyvza4wfvjv63il2xewsklsjtpyanp23y6hg2aa behaviours/blacklisting.py: bafybeicvespraci44y2dtddy4wi7cdhjuyk6crjs7ztnssm2rcrovha3hm - behaviours/decision_receive.py: bafybeihe73gjp2dv5czue4mxpxtcsssde7xwwh4fkouzozckkkfzaubnhy + behaviours/decision_receive.py: bafybeifn4xuv2z3niyhgd35ufncrdpaisw7pd4qkw2vv3cte5koqe2mxqy behaviours/decision_request.py: bafybeifjlh5cfitjd6wjcvcgoji2bhsi4r5nzpqocotwprmn26eiphlmqq behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm behaviours/reedem.py: bafybeib25frcafu6iikppidwqqovwjkzkxif6m3f4crmklohpj6yixprsq diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 6bcd8f014..8a658b597 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:bafybeiglsnh2hvfau5gab7requh34k4sbqwbjvrhhqjpes4hakcwq46cpi - valory/termination_abci:0.1.0:bafybeigcsls72uosoui2y5ppmnvsljjhnxakkeh3fdohklcg66aqq4g7xu - valory/market_manager_abci:0.1.0:bafybeih6tmi4blhdqkjgtvqkwbtbky5kzhl57h6ze4rtr3r2rh43pkhvyi -- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiauossubd7ikfyuml4kot4motcxnn2tbe7xubelc3ut4hdyanwfvu +- valory/decision_maker_abci:0.1.0:bafybeibadjiuw4icm64rm5mrooht6he2xw6ery6yxu5qnwhqkpwlfhen2m +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiez2gopga42empgxlgprmw34joobw3rx2h5ybnk2u35vdmpkjtjfq 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 0adde1ddb..a75f8c6c6 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:bafybeif3cqkks5qx3lqi6nwwhebcirhazt2vidw3sueeqsyxvjeszjt3om -- valory/decision_maker_abci:0.1.0:bafybeihgz63nppx4qla6pu2gnndqfewt5forymbst6tbqzaquzj2ifxzva +- valory/decision_maker_abci:0.1.0:bafybeibadjiuw4icm64rm5mrooht6he2xw6ery6yxu5qnwhqkpwlfhen2m behaviours: main: args: {}