Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added delay between market approval #76

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"contract/valory/conditional_tokens/0.1.0": "bafybeifbhritgoqecuilj35uzrrokm2ngfmwkoafbmzxgvpa4q3wpi6i64",
"contract/valory/fpmm_deterministic_factory/0.1.0": "bafybeih5yb4df6plwsxicp4jtywvpqmjnvfw55zw35yuycwxrx7mehoowy",
"contract/valory/realtio/0.1.0": "bafybeiaqs3onithjb76vecq5qkl5dkchm6vj76yqesdbpcpfmcjnzszhki",
"skill/valory/market_creation_manager_abci/0.1.0": "bafybeie54sfgakac22snz4xeisz2i55hwdn5lmvvcmhayxdbkycgpfofcu",
"skill/valory/market_maker_abci/0.1.0": "bafybeibtllbp7y7sa6xrhfgbwqv4ybuoxdnyxvkee7jrct7b67tt7fcwdi",
"agent/valory/market_maker/0.1.0": "bafybeigjj4fhng2r7kif2gmb2gmj7zp7ot7t3fcrbteg4at3zcyxhaihmy",
"service/valory/market_maker/0.1.0": "bafybeidyxsozmyhkqhrlyir7zsjmifgygoavnf7hboatilhkbc3ohvvwmm",
"skill/valory/market_creation_manager_abci/0.1.0": "bafybeigzauy7nsv7yu5nkauvegd3bfkaijrcbvqihh5yvt4wrpvzeke4xq",
"skill/valory/market_maker_abci/0.1.0": "bafybeigrq4m5rvnsl7zp3d4gywsvqf2qccoxzhasqisaesmjdoxrf33ufa",
"agent/valory/market_maker/0.1.0": "bafybeicvwqjsjxe4yujf5q6qfusovdq2xj7n6jpistpis3o2cb7apco3wu",
"service/valory/market_maker/0.1.0": "bafybeicawiuzyel7s7y3gucgbgva5jq6x4eim2v23euvapoo4pheb2koqy",
"contract/valory/wxdai/0.1.0": "bafybeidalocwbhmbto6ii6adldtpcughtdt6j3v4tv36utevjk2wrdyqie",
"contract/valory/fpmm/0.1.0": "bafybeiai2ruj27nnglvn7yc5atojyojo3fkmofw6wrjgz2ybps2uwdizx4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/agents/market_maker/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ protocols:
skills:
- valory/abstract_abci:0.1.0:bafybeiflcfufixmsrhobf56bn5745m2iipcfqyulwk2qegtnagb3kvaaxi
- valory/abstract_round_abci:0.1.0:bafybeiaqcl7h2famylusiffigwem7tevkcsyocdu5xd42jkmgq6kvowzgq
- valory/market_maker_abci:0.1.0:bafybeibtllbp7y7sa6xrhfgbwqv4ybuoxdnyxvkee7jrct7b67tt7fcwdi
- valory/market_maker_abci:0.1.0:bafybeigrq4m5rvnsl7zp3d4gywsvqf2qccoxzhasqisaesmjdoxrf33ufa
- valory/registration_abci:0.1.0:bafybeic2ynseiak7jpta7jfwuqwyp453b4p7lolr4wihxmpn633uekv5am
- valory/market_creation_manager_abci:0.1.0:bafybeie54sfgakac22snz4xeisz2i55hwdn5lmvvcmhayxdbkycgpfofcu
- valory/market_creation_manager_abci:0.1.0:bafybeigzauy7nsv7yu5nkauvegd3bfkaijrcbvqihh5yvt4wrpvzeke4xq
- valory/reset_pause_abci:0.1.0:bafybeidzajbe3erygeh2xbd6lrjv7nsptznjuzrt24ykgvhgotdeyhfnba
- valory/termination_abci:0.1.0:bafybeie4zvjfxvdu7qrulmur3chpjz3kpj5m4bjsxvpk4gvj5zbyyayfaa
- valory/transaction_settlement_abci:0.1.0:bafybeiaefgqbs7zsn5xe5kdwrujj7ivygkn3ujpw6crnvi3knvxw75qmja
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/market_maker/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: bafybeibwz3af6326msp4h3kqehijvmyhaytvyfbo3o2npc2w4b6zrg6pfq
fingerprint_ignore_patterns: []
agent: valory/market_maker:0.1.0:bafybeigjj4fhng2r7kif2gmb2gmj7zp7ot7t3fcrbteg4at3zcyxhaihmy
agent: valory/market_maker:0.1.0:bafybeicvwqjsjxe4yujf5q6qfusovdq2xj7n6jpistpis3o2cb7apco3wu
number_of_agents: 1
deployment:
agent:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ def async_act(self) -> Generator:
]
largest_creation_timestamp = max(creation_timestamps)

latest_approve_market_timestamp = (
self.synchronized_data.approved_markets_timestamp
)

# Determine num_markets_to_approve so that each day there are N closing markets.
opening_timestamps = [
int(entry["openingTimestamp"])
Expand Down Expand Up @@ -444,6 +448,9 @@ def async_act(self) -> Generator:
self.context.logger.info(
f"largest_creation_timestamp={largest_creation_timestamp}"
)
self.context.logger.info(
f"latest_approve_market_execution={latest_approve_market_timestamp}"
)
self.context.logger.info(
f"min_approve_markets_epoch_seconds={min_approve_markets_epoch_seconds}"
)
Expand All @@ -460,11 +467,17 @@ def async_act(self) -> Generator:
content = (
CollectProposedMarketsRound.MAX_APPROVED_MARKETS_REACHED_PAYLOAD
)
elif (
current_timestamp - latest_approve_market_timestamp
< min_approve_markets_epoch_seconds
):
self.context.logger.info("Timeout to approve markets not reached (1).")
content = CollectProposedMarketsRound.SKIP_MARKET_APPROVAL_PAYLOAD
elif (
current_timestamp - largest_creation_timestamp
< min_approve_markets_epoch_seconds
):
self.context.logger.info("Timeout to approve markets not reached.")
self.context.logger.info("Timeout to approve markets not reached (2).")
content = CollectProposedMarketsRound.SKIP_MARKET_APPROVAL_PAYLOAD
elif num_markets_to_approve <= 0:
self.context.logger.info("No market approval required.")
Expand All @@ -485,6 +498,7 @@ def async_act(self) -> Generator:
content_data.update(latest_open_markets)
content_data.update(proposed_markets)
content_data["num_markets_to_approve"] = num_markets_to_approve
content_data["timestamp"] = current_timestamp
content = json.dumps(content_data, sort_keys=True)

payload = CollectProposedMarketsPayload(
Expand Down Expand Up @@ -622,6 +636,7 @@ def _sender_act(self) -> Generator:
content=json.dumps(markets_to_approve, sort_keys=True),
approved_markets_count=len(markets_to_approve["markets_to_approve"])
+ self.synchronized_data.approved_markets_count,
timestamp=self.last_synced_timestamp,
)

with self.context.benchmark_tool.measure(self.behaviour_id).consensus():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ class ApproveMarketsPayload(BaseTxPayload):

content: str
approved_markets_count: int
timestamp: int
48 changes: 35 additions & 13 deletions packages/valory/skills/market_creation_manager_abci/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class Event(Enum):
DEFAULT_PROPOSED_MARKETS_DATA = {"proposed_markets": [], "timestamp": 0}
DEFAULT_COLLECTED_PROPOSED_MARKETS_DATA = json.dumps(
{
"collected_proposed_markets": [],
"proposed_markets": [],
"fixedProductMarketMakers": [],
"num_markets_to_approve": 0,
"timestamp": 0,
}
)
Expand Down Expand Up @@ -113,6 +115,11 @@ def approved_markets_count(self) -> int:
"""Get the approved_markets_count."""
return cast(int, self.db.get("approved_markets_count", 0))

@property
def approved_markets_timestamp(self) -> int:
"""Get the approved_markets_count."""
return cast(int, self.db.get("approved_markets_timestamp", 0))

@property
def proposed_markets_data(self) -> dict:
"""Get the proposed_markets_data."""
Expand Down Expand Up @@ -212,6 +219,31 @@ class CollectRandomnessRound(CollectSameUntilThresholdRound):
collection_key = get_name(SynchronizedData.participant_to_randomness)
selection_key = ("ignored", get_name(SynchronizedData.most_voted_randomness))

def end_block(self) -> Optional[Tuple[BaseSynchronizedData, Enum]]:
"""Process the end of the block."""
res = super().end_block()
if res is None:
return None

synced_data, event = cast(Tuple[SynchronizedData, Enum], res)

# Fix to ensure properties are present on the SynchronizedData
# before ResetAndPause round.
synced_data = synced_data.ensure_property_is_set(
get_name(SynchronizedData.approved_markets_count)
)
synced_data = synced_data.ensure_property_is_set(
get_name(SynchronizedData.proposed_markets_count)
)
synced_data = synced_data.ensure_property_is_set(
get_name(SynchronizedData.proposed_markets_data)
)
synced_data = synced_data.ensure_property_is_set(
get_name(SynchronizedData.approved_markets_timestamp)
)

return synced_data, event


class PostTransactionRound(CollectSameUntilThresholdRound):
"""A round to be run after a transaction has been settled."""
Expand Down Expand Up @@ -384,18 +416,6 @@ def end_block(self) -> Optional[Tuple[SynchronizedData, Enum]]:
synced_data, event = cast(Tuple[SynchronizedData, Enum], res)
payload = self.most_voted_payload

# Fix to ensure properties are present on the SynchronizedData
# before ResetAndPause round.
synced_data = synced_data.ensure_property_is_set(
get_name(SynchronizedData.approved_markets_count)
)
synced_data = synced_data.ensure_property_is_set(
get_name(SynchronizedData.proposed_markets_count)
)
synced_data = synced_data.ensure_property_is_set(
get_name(SynchronizedData.proposed_markets_data)
)

if event == Event.DONE and payload == self.ERROR_PAYLOAD:
return synced_data, Event.ERROR

Expand Down Expand Up @@ -424,6 +444,7 @@ class ApproveMarketsRound(OnlyKeeperSendsRound):
payload_key = (
get_name(SynchronizedData.approved_markets_data),
get_name(SynchronizedData.approved_markets_count),
get_name(SynchronizedData.approved_markets_timestamp),
)
collection_key = get_name(SynchronizedData.participant_to_selection)

Expand Down Expand Up @@ -786,6 +807,7 @@ class MarketCreationManagerAbciApp(AbciApp[Event]):
get_name(SynchronizedData.proposed_markets_count),
get_name(SynchronizedData.proposed_markets_data),
get_name(SynchronizedData.approved_markets_count),
get_name(SynchronizedData.approved_markets_timestamp),
} # type: ignore
db_pre_conditions: Dict[AppState, Set[str]] = {
CollectRandomnessRound: set(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ aea_version: '>=1.0.0, <2.0.0'
fingerprint:
.gitignore: bafybeihdfdezgtr3s2lzq5y3oaitfrdy4u4pehionju2bdez35wcjgqx6y
__init__.py: bafybeibkyjt4covc4yhd22aw7kav45zozk3exdv344emt3lilln64soaxm
behaviours.py: bafybeibi53ecb4u6vq4uv2nad5eu4yrt3st7vuw6fdmmxy6535jibdhnha
behaviours.py: bafybeibxf3dr74u4ujhxr3ovtjzvwarbrvxvjn4nsoarcq63ghh4oljrb4
dialogues.py: bafybeicmaufkl7vdomnfciv7lw4536ssld7x4uemdapuhsyvfpd4ncibza
fsm_specification.yaml: bafybeihbesgz2dosveibkqxryyimdrxipbfjgoohg2xefipgkwb5uftq24
handlers.py: bafybeietxjfli2i57kb7heoy772rcq2znusl36gg7jjj5g3pddw7egny3q
models.py: bafybeiafms2a2lgjftxktxp2lqgbwq3pjzzixsxtgjw7eyfbvpsap2mo7e
payloads.py: bafybeicwue4g7q55q2kkbyujggnzkr7xef3hg5veimnmsdgbvylenjgxlu
rounds.py: bafybeihzj777plqs425smsgtczcob5ybbreexrdcg2gbtzw3nwm5lotn6m
payloads.py: bafybeihbxbomk27cztssu74oksxmb5ybmxxeatbdk5kt4w2tplnb3abooa
rounds.py: bafybeidcbb5qmxzoa3ksp7hpr34kwjbfesavfe4xj7d6rslkcbx32bkiai
tests/__init__.py: bafybeihfxvqnyfly72tbxnnnglshcilm2kanihqnjiasvcz3ec3csw32ti
fingerprint_ignore_patterns: []
connections:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/skills/market_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ skills:
- valory/abstract_round_abci:0.1.0:bafybeiaqcl7h2famylusiffigwem7tevkcsyocdu5xd42jkmgq6kvowzgq
- valory/registration_abci:0.1.0:bafybeic2ynseiak7jpta7jfwuqwyp453b4p7lolr4wihxmpn633uekv5am
- valory/reset_pause_abci:0.1.0:bafybeidzajbe3erygeh2xbd6lrjv7nsptznjuzrt24ykgvhgotdeyhfnba
- valory/market_creation_manager_abci:0.1.0:bafybeie54sfgakac22snz4xeisz2i55hwdn5lmvvcmhayxdbkycgpfofcu
- valory/market_creation_manager_abci:0.1.0:bafybeigzauy7nsv7yu5nkauvegd3bfkaijrcbvqihh5yvt4wrpvzeke4xq
- valory/termination_abci:0.1.0:bafybeie4zvjfxvdu7qrulmur3chpjz3kpj5m4bjsxvpk4gvj5zbyyayfaa
- valory/transaction_settlement_abci:0.1.0:bafybeiaefgqbs7zsn5xe5kdwrujj7ivygkn3ujpw6crnvi3knvxw75qmja
behaviours:
Expand Down