Skip to content

Commit

Permalink
changes suggested at the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberosa committed Oct 23, 2024
1 parent 749007d commit 8627ba7
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 67 deletions.
12 changes: 6 additions & 6 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"contract/valory/staking_token/0.1.0": "bafybeigwsffbzx62d3ikz5kyjsewcvknrrnq3bcqgktnbrcpz4g6lyu3eq",
"contract/valory/relayer/0.1.0": "bafybeicawmds6czx7db2lcktvexwrp245jpekgulndtos5s5zdid3ilvq4",
"skill/valory/market_manager_abci/0.1.0": "bafybeidmipituxl4xva6h3aeorhqstketwxd7ka7z5fog3jprfr6qx2d3i",
"skill/valory/decision_maker_abci/0.1.0": "bafybeiestnu5636ammji7fmwqa7ztunf3rv7gkmlnguyoebre525aik3wy",
"skill/valory/trader_abci/0.1.0": "bafybeif2mtijpsifgczbsh46elf5yolz2hoqbxbidmhmq6e27jc2iyqn7i",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeid5ugnc25amu5kifyurgknpyytj26krogpiz3n2xldmcovt2d2ksi",
"skill/valory/decision_maker_abci/0.1.0": "bafybeiekxzieyfkntk5htd4w36xssdl2ewzle5a7rgaxb2fvtqpbb2dnai",
"skill/valory/trader_abci/0.1.0": "bafybeid3yikmsjfkeuammkso75knuhc65jiag3uw4edc3jniquzsm332d4",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibsp4pixtmdtrqeftyhreaoyjm2rcc2ta23s2sbdnxwqxjqfhd3ra",
"skill/valory/staking_abci/0.1.0": "bafybeifyqszbiccxwwfldrl6lz5dspuaxbqd5qnniyecusddwvxpfwiyr4",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeicsrrxjs6bup267jiek3r7eutd42ssfyjthyvxfku6qozw3xebxta",
"agent/valory/trader/0.1.0": "bafybeiawlxzrqaxn2auhckgml35voyw5z5qrxlqsk6l6a6zzou5psqfvwa",
"service/valory/trader/0.1.0": "bafybeibs6hemmojb5g7nvffa7uatsag4yjwxlhqonwenov3e5ce4nyurdq",
"service/valory/trader_pearl/0.1.0": "bafybeiagsdjrwvuxiike2byizo3kewxljqsimx5b2atwtbn5yipadh5mte"
"agent/valory/trader/0.1.0": "bafybeidu7npu33zthrubfmecpm7ysqffforui3czetjcy7cmdufr2stqlq",
"service/valory/trader/0.1.0": "bafybeigwbfc7a4ykp5wjd3khaerl2bqqp774rvzi5ajygjlc6ripuzydim",
"service/valory/trader_pearl/0.1.0": "bafybeigluoqcqzravl4ehwhe25ejhqtikszxctwalw3n7yaaairotqj5vm"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
6 changes: 3 additions & 3 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeigrdlxed3xlsnxtjhnsbl3cojruihxcqx4jxhgivkd5i2fkjncgba
- valory/termination_abci:0.1.0:bafybeib5l7jhew5ic6iq24dd23nidcoimzqkrk556gqywhoziatj33zvwm
- valory/transaction_settlement_abci:0.1.0:bafybeic7q7recyka272udwcupblwbkc3jkodgp74fvcdxb7urametg5dae
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeid5ugnc25amu5kifyurgknpyytj26krogpiz3n2xldmcovt2d2ksi
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibsp4pixtmdtrqeftyhreaoyjm2rcc2ta23s2sbdnxwqxjqfhd3ra
- valory/market_manager_abci:0.1.0:bafybeidmipituxl4xva6h3aeorhqstketwxd7ka7z5fog3jprfr6qx2d3i
- valory/decision_maker_abci:0.1.0:bafybeiestnu5636ammji7fmwqa7ztunf3rv7gkmlnguyoebre525aik3wy
- valory/trader_abci:0.1.0:bafybeif2mtijpsifgczbsh46elf5yolz2hoqbxbidmhmq6e27jc2iyqn7i
- valory/decision_maker_abci:0.1.0:bafybeiekxzieyfkntk5htd4w36xssdl2ewzle5a7rgaxb2fvtqpbb2dnai
- valory/trader_abci:0.1.0:bafybeid3yikmsjfkeuammkso75knuhc65jiag3uw4edc3jniquzsm332d4
- valory/staking_abci:0.1.0:bafybeifyqszbiccxwwfldrl6lz5dspuaxbqd5qnniyecusddwvxpfwiyr4
- valory/check_stop_trading_abci:0.1.0:bafybeicsrrxjs6bup267jiek3r7eutd42ssfyjthyvxfku6qozw3xebxta
- valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeiawlxzrqaxn2auhckgml35voyw5z5qrxlqsk6l6a6zzou5psqfvwa
agent: valory/trader:0.1.0:bafybeidu7npu33zthrubfmecpm7ysqffforui3czetjcy7cmdufr2stqlq
number_of_agents: 4
deployment:
agent:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader_pearl/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeiawlxzrqaxn2auhckgml35voyw5z5qrxlqsk6l6a6zzou5psqfvwa
agent: valory/trader:0.1.0:bafybeidu7npu33zthrubfmecpm7ysqffforui3czetjcy7cmdufr2stqlq
number_of_agents: 1
deployment:
agent:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import json
from copy import deepcopy
from math import prod
from typing import Any, Dict, Generator, Optional, Tuple, Union
from typing import Any, Dict, Generator, Optional, Tuple, Union, List

from packages.valory.skills.decision_maker_abci.behaviours.base import (
DecisionMakerBaseBehaviour,
Expand Down Expand Up @@ -204,13 +204,14 @@ def _get_bet_sample_info(bet: Bet, vote: int) -> Tuple[int, int]:

return selected_type_tokens_in_pool, other_tokens_in_pool

def _calc_binary_shares(
self, bet: Bet, net_bet_amount: int, vote: int
) -> Tuple[int, int]:
"""Calculate the claimed shares. This calculation only works for binary markets."""
# calculate the pool's k (x*y=k)
token_amounts = bet.outcomeTokenAmounts
self.context.logger.info(f"Token amounts: {[x for x in token_amounts]}")
def _compute_new_tokens_distribution(
self,
token_amounts: List[int],
prices: List[float],
net_bet_amount: int,
vote: int,
) -> Tuple:

k = prod(token_amounts)
self.context.logger.info(f"k: {k}")

Expand All @@ -219,12 +220,6 @@ def _calc_binary_shares(
bet_per_token = net_bet_amount / BINARY_N_SLOTS
self.context.logger.info(f"Bet per token: {bet_per_token}")

# calculate the number of the traded tokens
prices = bet.outcomeTokenMarginalPrices
self.context.logger.info(f"Prices: {prices}")

if prices is None:
return 0, 0
tokens_traded = [int(bet_per_token / prices[i]) for i in range(BINARY_N_SLOTS)]
self.context.logger.info(f"Tokens traded: {[x for x in tokens_traded]}")

Expand Down Expand Up @@ -268,6 +263,33 @@ def _calc_binary_shares(
available_shares = int(selected_type_tokens_in_pool * price)
self.context.logger.info(f"Available shares: {available_shares}")

return (
selected_type_tokens_in_pool,
other_tokens_in_pool,
other_shares,
num_shares,
available_shares,
)

def _calc_binary_shares(
self, bet: Bet, net_bet_amount: int, vote: int
) -> Tuple[int, int]:
"""Calculate the claimed shares. This calculation only works for binary markets."""
# calculate the pool's k (x*y=k)
token_amounts = bet.outcomeTokenAmounts
self.context.logger.info(f"Token amounts: {[x for x in token_amounts]}")

# calculate the number of the traded tokens
prices = bet.outcomeTokenMarginalPrices
self.context.logger.info(f"Prices: {prices}")

if prices is None:
return 0, 0

_, _, _, num_shares, available_shares = self._compute_new_tokens_distribution(
token_amounts, prices, net_bet_amount, vote
)

return num_shares, available_shares

def _get_mocked_bet(self) -> Bet:
Expand Down Expand Up @@ -311,35 +333,15 @@ def _calculate_new_liquidity(
token_amounts = self.shared_state.current_liquidity_amounts
k = prod(token_amounts)
prices = self.shared_state.current_liquidity_prices
self.context.logger.info(f"Token prices: {prices}")
bet_per_token = net_bet_amount / BINARY_N_SLOTS

# calculate the number of the traded tokens
if prices is None:
return None
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)
self.context.logger.info(f"Selected shares: {selected_shares}")

# get the shares for the opposite answer
other_shares = tokens_traded.pop()
self.context.logger.info(f"Other shares: {other_shares}")

# 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)
self.context.logger.info(
f"Selected type tokens in pool: {selected_type_tokens_in_pool}"
selected_type_tokens_in_pool, other_tokens_in_pool, other_shares, _, _ = (
self._compute_new_tokens_distribution(
token_amounts, prices, net_bet_amount, vote
)
)

# get the number of tokens in the pool for the opposite answer
other_tokens_in_pool = token_amounts.pop()
self.context.logger.info(f"Other tokens in pool: {other_tokens_in_pool}")

# 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
new_other = other_tokens_in_pool + other_shares
new_selected = int(k / new_other)
if vote == 0:
Expand All @@ -363,13 +365,14 @@ def _update_liquidity_info(
liquidity_info = self._calculate_new_liquidity(net_bet_amount, vote)
if liquidity_info is None:
return None
# to compute the new price we need the previous constants
prices = self.shared_state.current_liquidity_prices

# linter checks
if liquidity_info.l0_start is None or liquidity_info.l1_start is None:
return None

# to compute the new price we need the previous constants
prices = self.shared_state.current_liquidity_prices

liquidity_constants = [
liquidity_info.l0_start * prices[0],
liquidity_info.l1_start * prices[1],
Expand Down
22 changes: 11 additions & 11 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def validate_end_information(self) -> Tuple[int, int]:
# return the values for type checking purposes (`mypy` would complain that they might be `None` otherwise)
return self.l0_end, self.l1_end

def get_new_prices(self, liquidity_constants: List) -> List[float]:
def get_new_prices(self, liquidity_constants: List[float]) -> List[float]:
"""Calculate and return the new prices based on the end liquidity and the liquidity constants of the market."""
l0_end, l1_end = self.validate_end_information()
new_p0 = liquidity_constants[0] / l0_end
Expand Down Expand Up @@ -379,11 +379,11 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
"tool_punishment_multiplier", kwargs, int
)
self.contract_timeout: float = self._ensure("contract_timeout", kwargs, float)
self.file_hash_to_strategies: Dict[
str, List[str]
] = nested_list_todict_workaround(
kwargs,
"file_hash_to_strategies_json",
self.file_hash_to_strategies: Dict[str, List[str]] = (
nested_list_todict_workaround(
kwargs,
"file_hash_to_strategies_json",
)
)
self.strategies_kwargs: Dict[str, List[Any]] = nested_list_todict_workaround(
kwargs, "strategies_kwargs"
Expand All @@ -395,11 +395,11 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
)
self.use_nevermined = self._ensure("use_nevermined", kwargs, bool)
self.rpc_sleep_time: int = self._ensure("rpc_sleep_time", kwargs, int)
self.mech_to_subscription_params: Dict[
str, Any
] = nested_list_todict_workaround(
kwargs,
"mech_to_subscription_params",
self.mech_to_subscription_params: Dict[str, Any] = (
nested_list_todict_workaround(
kwargs,
"mech_to_subscription_params",
)
)
self.service_endpoint = self._ensure("service_endpoint", kwargs, str)
self.safe_voting_range = self._ensure("safe_voting_range", kwargs, int)
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fingerprint:
behaviours/blacklisting.py: bafybeicqwj7o4l7qcym5xjqwq45jngqkhyf44mn6qise2ysyfnlnwz7pdy
behaviours/check_benchmarking.py: bafybeiao2lyj7apezkqrpgsyzb3dwvrdgsrgtprf6iuhsmlsufvxfl5bci
behaviours/claim_subscription.py: bafybeigbqkhc6mb73rbwaks32tfiqx6u2xza43uiy6rvbtrnqd6m4fru3e
behaviours/decision_receive.py: bafybeihtu2btaw2q2zzbhkbz6acepqoybnracxssufmqxi6xqrprqclmni
behaviours/decision_receive.py: bafybeibtboftndfqvlmv76waqfutzvsxz4tfdbzo54flrg3ehe24mgliwq
behaviours/decision_request.py: bafybeiabjzzcwcfbfmtoftjhewmkgbhxfnigbc5cwmmxl6cob5gv64jwwa
behaviours/handle_failed_tx.py: bafybeidxpc6u575ymct5tdwutvzov6zqfdoio5irgldn3fw7q3lg36mmxm
behaviours/order_subscription.py: bafybeicrmdvhci5prfldvuf3bclbbqi6j7lpv6hmphw3qwgmkmwat3od44
Expand All @@ -32,7 +32,7 @@ fingerprint:
handlers.py: bafybeigod6gbjrxy4mbmulbzsbokeaoycoqys64vqtxnumishfukzf73za
io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq
io_/loader.py: bafybeih3sdsx5dhe4kzhtoafexjgkutsujwqy3zcdrlrkhtdks45bc7exa
models.py: bafybeiae5qu5h45gfkqsfydqs4fdl3kl55xrj5c4btr3oc77x2l33gbcma
models.py: bafybeibsuv3tc7ynl5mvtzcdm2hiqrm7twardh6aaspmii45btv7dptuoi
payloads.py: bafybeicloiy4ax7dlipwp4czlueflgjgtlev4a6vhn2m7ztoehnemiiko4
policy.py: bafybeihcltocxg7zsmvjtx44ilal4zir4fz2rupgmhacktzv5neb2lmas4
redeem_info.py: bafybeifiiix4gihfo4avraxt34sfw35v6dqq45do2drrssei2shbps63mm
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeic7q7recyka272udwcupblwbkc3jkodgp74fvcdxb7urametg5dae
- valory/termination_abci:0.1.0:bafybeib5l7jhew5ic6iq24dd23nidcoimzqkrk556gqywhoziatj33zvwm
- valory/market_manager_abci:0.1.0:bafybeidmipituxl4xva6h3aeorhqstketwxd7ka7z5fog3jprfr6qx2d3i
- valory/decision_maker_abci:0.1.0:bafybeiestnu5636ammji7fmwqa7ztunf3rv7gkmlnguyoebre525aik3wy
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeid5ugnc25amu5kifyurgknpyytj26krogpiz3n2xldmcovt2d2ksi
- valory/decision_maker_abci:0.1.0:bafybeiekxzieyfkntk5htd4w36xssdl2ewzle5a7rgaxb2fvtqpbb2dnai
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibsp4pixtmdtrqeftyhreaoyjm2rcc2ta23s2sbdnxwqxjqfhd3ra
- valory/staking_abci:0.1.0:bafybeifyqszbiccxwwfldrl6lz5dspuaxbqd5qnniyecusddwvxpfwiyr4
- valory/check_stop_trading_abci:0.1.0:bafybeicsrrxjs6bup267jiek3r7eutd42ssfyjthyvxfku6qozw3xebxta
- valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protocols:
- valory/ledger_api:1.0.0:bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni
skills:
- valory/abstract_round_abci:0.1.0:bafybeib733xfbndtpvkf44mtk7oyodnficgloo6xhn7xmqxxeos33es65u
- valory/decision_maker_abci:0.1.0:bafybeiestnu5636ammji7fmwqa7ztunf3rv7gkmlnguyoebre525aik3wy
- valory/decision_maker_abci:0.1.0:bafybeiekxzieyfkntk5htd4w36xssdl2ewzle5a7rgaxb2fvtqpbb2dnai
- valory/staking_abci:0.1.0:bafybeifyqszbiccxwwfldrl6lz5dspuaxbqd5qnniyecusddwvxpfwiyr4
- valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm
behaviours:
Expand Down

0 comments on commit 8627ba7

Please sign in to comment.