Skip to content

Commit

Permalink
merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberosa committed Nov 20, 2024
2 parents cc62c3d + ce791ac commit a940e0f
Show file tree
Hide file tree
Showing 33 changed files with 3,421 additions and 762 deletions.
14 changes: 7 additions & 7 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"contract/valory/mech_activity/0.1.0": "bafybeibmqmle5fnal3gxlpdmcos2kogzra4q3pr3o5nh7shplxuilji3t4",
"contract/valory/staking_token/0.1.0": "bafybeiep4r6qyilbfgzdvx6t7zvpgaioxqktmxm7puwtnbpb2ftlib43gy",
"contract/valory/relayer/0.1.0": "bafybeicawmds6czx7db2lcktvexwrp245jpekgulndtos5s5zdid3ilvq4",
"skill/valory/market_manager_abci/0.1.0": "bafybeib5jurq6rpbjqat44qt2iliy2bddrtcapmmqsobkj2yndhrgnnpfu",
"skill/valory/decision_maker_abci/0.1.0": "bafybeihbcnzz6sw3pydbopwj4qnamlj7xtn3jfnjkotiogsdwue5nset4i",
"skill/valory/trader_abci/0.1.0": "bafybeibbjilot5xc43l23v4x6v625fxqzhneatklkiqvnna7kxwd4h4rvi",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiabuvydv4kngz2yngpta3cb7z57qga6yfzw2lfxi7etopevj6ke6i",
"skill/valory/market_manager_abci/0.1.0": "bafybeicztk62pslofv6ui3aw3giw2tnvlfwfmatqbyvvzv4ampneu6isqa",
"skill/valory/decision_maker_abci/0.1.0": "bafybeicngtrfoad3yqbrdslmgngpfiqipqac5t4jv3rc22yyboiimp7kjq",
"skill/valory/trader_abci/0.1.0": "bafybeie57hhm6j5jfo43oq4hu2zfrteqh67zb4eatqyvrinsbc4qg4v2ma",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibevivb6pfty5ghtzjwwn2sgnn4ij263wbiziv373yfd5m4cyotpq",
"skill/valory/staking_abci/0.1.0": "bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeifmi64g4ki6zwbcncb35ovhd4sllw4xrszrkturpeqdhgf5bkiini",
"agent/valory/trader/0.1.0": "bafybeibkv4xht57pyyhc6amctow3lt2mdvjmw43nfrojfmih777k4meboe",
"service/valory/trader/0.1.0": "bafybeigxjm3b5dhgyxqapvwngc7hj3ass7saevzvnv4voodzm2k5pcrxka",
"service/valory/trader_pearl/0.1.0": "bafybeia7eb2rwhueu6il63kdtjb5n5apsx7z33p4b3tugym7htitcqnima"
"agent/valory/trader/0.1.0": "bafybeicc6jkakg6dhvqpb6esidgnffl5ses2bnk67eqs3falrkbw4aa47q",
"service/valory/trader/0.1.0": "bafybeih6cbruabwq5z2jl22pcrhzamzw4pz5yhvld4nmee3k7jkjvhmohu",
"service/valory/trader_pearl/0.1.0": "bafybeibvcu6rnngqw4i6mzqukwwn4gxc2v7hn6cydyha6ouqeyen54vcla"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
Expand Down
11 changes: 6 additions & 5 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:bafybeiabuvydv4kngz2yngpta3cb7z57qga6yfzw2lfxi7etopevj6ke6i
- valory/market_manager_abci:0.1.0:bafybeib5jurq6rpbjqat44qt2iliy2bddrtcapmmqsobkj2yndhrgnnpfu
- valory/decision_maker_abci:0.1.0:bafybeihbcnzz6sw3pydbopwj4qnamlj7xtn3jfnjkotiogsdwue5nset4i
- valory/trader_abci:0.1.0:bafybeibbjilot5xc43l23v4x6v625fxqzhneatklkiqvnna7kxwd4h4rvi
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibevivb6pfty5ghtzjwwn2sgnn4ij263wbiziv373yfd5m4cyotpq
- valory/market_manager_abci:0.1.0:bafybeicztk62pslofv6ui3aw3giw2tnvlfwfmatqbyvvzv4ampneu6isqa
- valory/decision_maker_abci:0.1.0:bafybeicngtrfoad3yqbrdslmgngpfiqipqac5t4jv3rc22yyboiimp7kjq
- valory/trader_abci:0.1.0:bafybeie57hhm6j5jfo43oq4hu2zfrteqh67zb4eatqyvrinsbc4qg4v2ma
- valory/staking_abci:0.1.0:bafybeictd5pxhscuhqntvctb7l5lfjausxt2m22rg5mkaiuj4cwwcxpvne
- valory/check_stop_trading_abci:0.1.0:bafybeifmi64g4ki6zwbcncb35ovhd4sllw4xrszrkturpeqdhgf5bkiini
- valory/mech_interact_abci:0.1.0:bafybeid6m3i5ofq7vuogqapdnoshhq7mswmudhvfcr2craw25fdwtoe3lm
Expand Down Expand Up @@ -172,7 +172,7 @@ models:
creator_per_subgraph:
omen_subgraph: ${list:["0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec"]}
slot_count: ${int:2}
opening_margin: ${int:300}
opening_margin: ${int:86400}
languages: ${list:["en_US"]}
average_block_time: ${int:5}
abt_error_mult: ${int:5}
Expand Down Expand Up @@ -237,6 +237,7 @@ models:
rebet_chance: ${float:0.6}
mech_interaction_sleep_time: ${int:10}
use_mech_marketplace: ${bool:false}
policy_store_update_offset: ${int:259200}
mech_marketplace_config:
mech_marketplace_address: ${str:0x0000000000000000000000000000000000000000}
priority_mech_address: ${str:0x0000000000000000000000000000000000000000}
Expand Down
14 changes: 9 additions & 5 deletions 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:bafybeibkv4xht57pyyhc6amctow3lt2mdvjmw43nfrojfmih777k4meboe
agent: valory/trader:0.1.0:bafybeicc6jkakg6dhvqpb6esidgnffl5ses2bnk67eqs3falrkbw4aa47q
number_of_agents: 4
deployment:
agent:
Expand Down Expand Up @@ -79,7 +79,7 @@ type: skill
creator_per_subgraph: &id003
omen_subgraph: ${OMEN_CREATORS:list:["0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec"]}
slot_count: ${SLOT_COUNT:int:2}
opening_margin: ${OPENING_MARGIN:int:300}
opening_margin: ${OPENING_MARGIN:int:86400}
languages: ${LANGUAGES:list:["en_US"]}
average_block_time: ${ABT:int:5}
abt_error_mult: ${ABT_ERROR_MULT:int:5}
Expand Down Expand Up @@ -144,6 +144,7 @@ type: skill
safe_voting_range: ${SAFE_VOTING_RANGE:int:600}
rebet_chance: ${REBET_CHANCE:float:0.6}
mech_interaction_sleep_time: ${MECH_INTERACTION_SLEEP_TIME:int:10}
policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200}
benchmark_tool: &id004
args:
log_dir: ${LOG_DIR:str:/benchmarks}
Expand Down Expand Up @@ -304,7 +305,7 @@ type: skill
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:int:1205}
creator_per_subgraph: *id003
slot_count: ${SLOT_COUNT:int:2}
opening_margin: ${OPENING_MARGIN:int:300}
opening_margin: ${OPENING_MARGIN:int:86400}
languages: ${LANGUAGES:list:["en_US"]}
average_block_time: ${ABT:int:5}
abt_error_mult: ${ABT_ERROR_MULT:int:5}
Expand Down Expand Up @@ -367,6 +368,7 @@ type: skill
safe_voting_range: ${SAFE_VOTING_RANGE:int:600}
rebet_chance: ${REBET_CHANCE:float:0.6}
mech_interaction_sleep_time: ${MECH_INTERACTION_SLEEP_TIME:int:10}
policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200}
benchmark_tool: *id004
acc_info_fields: *id005
network_subgraph: *id006
Expand Down Expand Up @@ -420,7 +422,7 @@ type: skill
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:int:1205}
creator_per_subgraph: *id003
slot_count: ${SLOT_COUNT:int:2}
opening_margin: ${OPENING_MARGIN:int:300}
opening_margin: ${OPENING_MARGIN:int:86400}
languages: ${LANGUAGES:list:["en_US"]}
average_block_time: ${ABT:int:5}
abt_error_mult: ${ABT_ERROR_MULT:int:5}
Expand Down Expand Up @@ -483,6 +485,7 @@ type: skill
safe_voting_range: ${SAFE_VOTING_RANGE:int:600}
rebet_chance: ${REBET_CHANCE:float:0.6}
mech_interaction_sleep_time: ${MECH_INTERACTION_SLEEP_TIME:int:10}
policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200}
benchmark_tool: *id004
acc_info_fields: *id005
network_subgraph: *id006
Expand Down Expand Up @@ -536,7 +539,7 @@ type: skill
history_check_timeout: ${HISTORY_CHECK_TIMEOUT:int:1205}
creator_per_subgraph: *id003
slot_count: ${SLOT_COUNT:int:2}
opening_margin: ${OPENING_MARGIN:int:300}
opening_margin: ${OPENING_MARGIN:int:86400}
languages: ${LANGUAGES:list:["en_US"]}
average_block_time: ${ABT:int:5}
abt_error_mult: ${ABT_ERROR_MULT:int:5}
Expand Down Expand Up @@ -599,6 +602,7 @@ type: skill
safe_voting_range: ${SAFE_VOTING_RANGE:int:600}
rebet_chance: ${REBET_CHANCE:float:0.6}
mech_interaction_sleep_time: ${MECH_INTERACTION_SLEEP_TIME:int:10}
policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200}
benchmark_tool: *id004
acc_info_fields: *id005
network_subgraph: *id006
Expand Down
11 changes: 6 additions & 5 deletions 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:bafybeibkv4xht57pyyhc6amctow3lt2mdvjmw43nfrojfmih777k4meboe
agent: valory/trader:0.1.0:bafybeicc6jkakg6dhvqpb6esidgnffl5ses2bnk67eqs3falrkbw4aa47q
number_of_agents: 1
deployment:
agent:
Expand Down Expand Up @@ -102,6 +102,7 @@ models:
priority_mech_service_id: ${PRIORITY_MECH_SERVICE_ID:int:0}
requester_staking_instance_address: ${REQUESTER_STAKING_INSTANCE_ADDRESS:str:0x0000000000000000000000000000000000000000}
response_timeout: ${RESPONSE_TIMEOUT:int:300}
policy_store_update_offset: ${POLICY_STORE_UPDATE_OFFSET:int:259200}
benchmark_tool:
args:
log_dir: /benchmarks
Expand All @@ -126,10 +127,10 @@ type: connection
config:
ledger_apis:
ethereum:
address: http://host.docker.internal:8545
chain_id: 100
default_gas_price_strategy: eip1559
poa_chain: false
address: ${GNOSIS_LEDGER_RPC:str:http://host.docker.internal:8545}
chain_id: ${GNOSIS_LEDGER_CHAIN_ID:int:100}
default_gas_price_strategy: ${GNOSIS_LEDGER_PRICING:str:eip1559}
poa_chain: ${GNOSIS_LEDGER_IS_POA_CHAIN:bool:false}
---
public_id: valory/p2p_libp2p_client:0.1.0
type: connection
Expand Down
16 changes: 11 additions & 5 deletions packages/valory/skills/decision_maker_abci/behaviours/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,21 @@ def processable_bet(self, bet: Bet, now: int) -> bool:
within_opening_range = bet.openingTimestamp <= (
now + self.params.sample_bets_closing_days * UNIX_DAY
)
within_safe_range = (
now
< bet.openingTimestamp
- self.params.opening_margin
- self.params.safe_voting_range
)
self.context.logger.info(f"within_opening_range ={within_opening_range}")
within_safe_range = now < bet.openingTimestamp + self.params.safe_voting_range
self.context.logger.info(f"within_safe_range ={within_safe_range}")
within_ranges = within_opening_range and within_safe_range

# rebetting is allowed only if we have already placed at least one bet in this market.
# conversely, if we should not rebet, no bets should have been placed in this market.
if self.should_rebet ^ bool(bet.n_bets):
return False

# if we should not rebet, we have all the information we need
if not self.should_rebet:
self.context.logger.info(
Expand All @@ -92,10 +102,6 @@ def processable_bet(self, bet: Bet, now: int) -> bool:
# 5. the market is never selected again, and therefore a bet is never placed on it
return within_ranges and self.has_liquidity_changed(bet)

# if we should rebet, we should have at least one bet processed in the past
if not bool(bet.n_bets):
return False

# create a filter based on whether we can rebet or not
lifetime = bet.openingTimestamp - now
t_rebetting = (lifetime // UNIX_WEEK) + UNIX_DAY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import csv
import json
from abc import ABC
from datetime import datetime
from io import StringIO
from typing import Any, Dict, Generator, List, Optional

Expand All @@ -45,6 +46,8 @@
UTILIZED_TOOLS_STORE = "utilized_tools.json"
GET = "GET"
OK_CODE = 200
MAX_STR = "max"
DATETIME_FORMAT_STR = "%Y-%m-%d %H:%M:%S"


class StorageManagerBehaviour(DecisionMakerBaseBehaviour, ABC):
Expand All @@ -57,7 +60,7 @@ def __init__(self, **kwargs: Any) -> None:
self._mech_hash: str = ""
self._utilized_tools: Dict[str, str] = {}
self._mech_tools: Optional[List[str]] = None
self._accuracy_information: StringIO = StringIO()
self._remote_accuracy_information: StringIO = StringIO()

@property
def mech_tools(self) -> List[str]:
Expand All @@ -72,14 +75,14 @@ def mech_tools(self, mech_tools: List[str]) -> None:
self._mech_tools = mech_tools

@property
def accuracy_information(self) -> StringIO:
def remote_accuracy_information(self) -> StringIO:
"""Get the accuracy information."""
return self._accuracy_information
return self._remote_accuracy_information

@accuracy_information.setter
def accuracy_information(self, accuracy_information: StringIO) -> None:
@remote_accuracy_information.setter
def remote_accuracy_information(self, accuracy_information: StringIO) -> None:
"""Set the accuracy information."""
self._accuracy_information = accuracy_information
self._remote_accuracy_information = accuracy_information

@property
def mech_id(self) -> int:
Expand Down Expand Up @@ -257,7 +260,7 @@ def _fetch_accuracy_info(self) -> Generator[None, None, bool]:

self.context.logger.info("Parsing accuracy information of the tools...")
try:
self.accuracy_information = StringIO(response.body.decode())
self.remote_accuracy_information = StringIO(response.body.decode())
except (ValueError, TypeError) as e:
self.context.logger.error(
f"Could not parse response from ipfs server, "
Expand All @@ -267,12 +270,68 @@ def _fetch_accuracy_info(self) -> Generator[None, None, bool]:

return True

def _fetch_remote_tool_date(self) -> int:
"""Fetch the max transaction date from the remote accuracy storage."""
self.context.logger.info("Checking remote accuracy information date... ")
self.context.logger.info("Trying to read max date in file...")
accuracy_information = self.remote_accuracy_information

max_transaction_date = None

if accuracy_information:
sep = self.acc_info_fields.sep
accuracy_information.seek(0) # Ensure we’re at the beginning
reader = csv.DictReader(accuracy_information.readlines(), delimiter=sep)

# try to read the maximum transaction date in the remote accuracy info
try:
for row in reader:
current_transaction_date = row.get(MAX_STR)
if (
max_transaction_date is None
or current_transaction_date > max_transaction_date
):
max_transaction_date = current_transaction_date

except TypeError:
self.context.logger.warning(
"Invalid transaction date found. Continuing with local accuracy information..."
)
return 0

if max_transaction_date:
self.context.logger.info(f"Maximum date found: {max_transaction_date}")
max_datetime = datetime.strptime(max_transaction_date, DATETIME_FORMAT_STR)
unix_timestamp = int(max_datetime.timestamp())
return unix_timestamp

self.context.logger.info("No maximum date found.")
return 0

def _check_local_policy_store_overwrite(self) -> bool:
"""Compare the local and remote policy store dates and decide which to use."""

local_policy_store_date = self.policy.updated_ts
remote_policy_store_date = self._fetch_remote_tool_date()
policy_store_update_offset = self.params.policy_store_update_offset

self.context.logger.info("Comparing tool accuracy dates...")

overwrite = (
True
if remote_policy_store_date
> (local_policy_store_date - policy_store_update_offset)
else False
)
self.context.logger.info(f"Local policy store overwrite: {overwrite}.")
return overwrite

def _update_accuracy_store(self) -> None:
"""Update the accuracy store file with the latest information available"""
self.context.logger.info("Updating accuracy information of the policy...")
sep = self.acc_info_fields.sep
reader: csv.DictReader = csv.DictReader(
self.accuracy_information, delimiter=sep
self.remote_accuracy_information, delimiter=sep
)
accuracy_store = self.policy.accuracy_store

Expand Down Expand Up @@ -312,11 +371,14 @@ def _set_policy(self) -> Generator:
)
self._policy = self.synchronized_data.policy

if self.is_first_period:
yield from self.wait_for_condition_with_sleep(
self._fetch_accuracy_info, sleep_time_override=self.params.sleep_time
)
self._update_accuracy_store()
yield from self.wait_for_condition_with_sleep(
self._fetch_accuracy_info, sleep_time_override=self.params.sleep_time
)
overwrite_local_store = self._check_local_policy_store_overwrite()

if self.is_first_period and overwrite_local_store:
self.policy.updated_ts = int(datetime.now().timestamp())
self._update_accuracy_store()

def _try_recover_utilized_tools(self) -> Dict[str, str]:
"""Try to recover the utilized tools from the tools store."""
Expand Down
3 changes: 3 additions & 0 deletions packages/valory/skills/decision_maker_abci/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
self.service_endpoint = self._ensure("service_endpoint", kwargs, str)
self.safe_voting_range = self._ensure("safe_voting_range", kwargs, int)
self.rebet_chance = self._ensure("rebet_chance", kwargs, float)
self.policy_store_update_offset = self._ensure(
"policy_store_update_offset", kwargs, int
)
super().__init__(*args, **kwargs)

@property
Expand Down
9 changes: 8 additions & 1 deletion packages/valory/skills/decision_maker_abci/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ def hook(
"""Perform the custom decoding."""
for cls_ in (AccuracyInfo, EGreedyPolicy):
cls_attributes = cls_.__annotations__.keys() # pylint: disable=no-member
if sorted(cls_attributes) == sorted(data.keys()):
if sorted(cls_attributes) == sorted(data.keys()) or (
cls_ == EGreedyPolicy
and sorted(cls_attributes - {"updated_ts"}) == sorted(data.keys())
):
# If EGreedyPolicy and 'updated_ts' is missing, set it to 0
if cls_ == EGreedyPolicy and "updated_ts" not in data:
data["updated_ts"] = 0
# if the attributes match the ones of the current class, use it to perform the deserialization
return cls_(**data)

Expand All @@ -89,6 +95,7 @@ class EGreedyPolicy:
eps: float
accuracy_store: Dict[str, AccuracyInfo] = field(default_factory=dict)
weighted_accuracy: Dict[str, float] = field(default_factory=dict)
updated_ts: int = 0

def __post_init__(self) -> None:
"""Perform post-initialization checks."""
Expand Down
Loading

0 comments on commit a940e0f

Please sign in to comment.