diff --git a/.gitleaksignore b/.gitleaksignore index 9ab5c264a..e3e6b89ad 100644 --- a/.gitleaksignore +++ b/.gitleaksignore @@ -15,3 +15,6 @@ b520b0c67a9ae55ba501e1e9a99abfc0738e8d49:packages/valory/skills/staking_abci/ski 4063acab1bf2654eeaa6fca86bfbc3f6ab57e399:packages/valory/services/trader/service.yaml:generic-api-key:9 392a14119facddbad6edd8f1d7553db08cdbf20c:packages/valory/skills/market_manager_abci/skill.yaml:generic-api-key:17 cfbec155d82abe64814af23610a4c69017d69096:packages/valory/skills/market_manager_abci/skill.yaml:generic-api-key:17 +ed30ffbaaf3c10476dc642d388985c250afaeb8d:packages/valory/skills/market_manager_abci/graph_tooling/requests.py:generic-api-key:221 +ed30ffbaaf3c10476dc642d388985c250afaeb8d:packages/valory/skills/market_manager_abci/graph_tooling/requests.py:generic-api-key:222 +d004f2345bf31b27c343eb52c1bc5a2698e838d6:packages/valory/skills/market_manager_abci/graph_tooling/requests.py:generic-api-key:221 diff --git a/packages/packages.json b/packages/packages.json index 002170d71..02f6656fe 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -1,13 +1,13 @@ { "dev": { - "skill/valory/market_manager_abci/0.1.0": "bafybeifdf6uoscrgvlgqceqcph2pgoygobznw6hbodpav7lubbqsyh4kby", - "skill/valory/decision_maker_abci/0.1.0": "bafybeigv6vymf2jisrrwnvobyzmtpa6566ldaq2u7r2vdslrv7h6fhvprq", - "skill/valory/trader_abci/0.1.0": "bafybeifd7s5nnyqow7pmylpdxlydezj2bipktscx2tdze6o7n3kstwbami", + "skill/valory/market_manager_abci/0.1.0": "bafybeia7vrpts3jeldxr4osltz5ekw7p3h2ib5ossutpviplkzqvfwhjua", + "skill/valory/decision_maker_abci/0.1.0": "bafybeihxo35ycripnuwcltfy64lxhaox43av7lbcozdgw2w3wupzzpdnn4", + "skill/valory/trader_abci/0.1.0": "bafybeid6md2wq6m4nwahdvv4kfbhvl67rvpn4tokgtbjvjb4qkmzhqxgui", "contract/valory/market_maker/0.1.0": "bafybeiain372i5t6eteem36vzhwh6ppka6hc4oyrxjtyzuar6rd6bjocem", - "agent/valory/trader/0.1.0": "bafybeidb4omu5cwpedqrlyjeqnkafpgje6xkt3i6ky6igoynue7ojpcegm", - "service/valory/trader/0.1.0": "bafybeibzdyrxu4scbuc6n67kggq4zxl4kaqnv7rn5yyy4zjmsynpu777p4", + "agent/valory/trader/0.1.0": "bafybeidjs3la6qd655ajn2u4lbchdi7suy5gne5rvzwgiscqrcvghz4oqy", + "service/valory/trader/0.1.0": "bafybeidkc4ww2dgcdpkoy5umbqudlz5ljufjuvhruvhil73xg3dkbj5qbq", "contract/valory/erc20/0.1.0": "bafybeiad6qbyhr3sgvclqne7tvyvqt32pcj5aq47hhkd2vmawaflhy5vna", - "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeicrvyshqokgxd7azjy6g3yzhk44lscerwnkci33eisam2foetjv4m", + "skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibal5o2ji3rxjf5plwsexpiafv6ufnntre2pikfd5qrykff3icaoi", "contract/valory/mech/0.1.0": "bafybeiauxqogu726oeethvzux6r77zgn7sw5j2l4uigqb47zlqawblkv6e", "contract/valory/realitio/0.1.0": "bafybeic5ie4oodetj4krdogydvbfxg4qggc3matpiflocah626tpevpreq", "contract/valory/realitio_proxy/0.1.0": "bafybeidx37xzjjmapwacedgzhum6grfzhp5vhouz4zu3pvpgdy5pgb2fr4", diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index c81cd73d2..6bc03818a 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -43,10 +43,10 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeibnwjcjx4lluf4cwb6es5peelu3gm7vrzlieygrzpbjlubxpvbvzy - valory/termination_abci:0.1.0:bafybeifdtxgldw33kwvsavcituzewwbr6iqfcsgk5qouqfhpwdrivyyyom - valory/transaction_settlement_abci:0.1.0:bafybeifpnkwgwpzz6uwrvfgurm26allr6shjfbp7bfbrxwy64sw3nf3fsa -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeicrvyshqokgxd7azjy6g3yzhk44lscerwnkci33eisam2foetjv4m -- valory/market_manager_abci:0.1.0:bafybeifdf6uoscrgvlgqceqcph2pgoygobznw6hbodpav7lubbqsyh4kby -- valory/decision_maker_abci:0.1.0:bafybeigv6vymf2jisrrwnvobyzmtpa6566ldaq2u7r2vdslrv7h6fhvprq -- valory/trader_abci:0.1.0:bafybeifd7s5nnyqow7pmylpdxlydezj2bipktscx2tdze6o7n3kstwbami +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibal5o2ji3rxjf5plwsexpiafv6ufnntre2pikfd5qrykff3icaoi +- valory/market_manager_abci:0.1.0:bafybeia7vrpts3jeldxr4osltz5ekw7p3h2ib5ossutpviplkzqvfwhjua +- valory/decision_maker_abci:0.1.0:bafybeihxo35ycripnuwcltfy64lxhaox43av7lbcozdgw2w3wupzzpdnn4 +- valory/trader_abci:0.1.0:bafybeid6md2wq6m4nwahdvv4kfbhvl67rvpn4tokgtbjvjb4qkmzhqxgui - valory/staking_abci:0.1.0:bafybeiccopehegiiwxzghrttdhuxtnjp7zvuiclx5zchbtvqpy45rrvdxy default_ledger: ethereum required_ledgers: @@ -158,7 +158,8 @@ models: use_termination: ${bool:false} on_chain_service_id: ${int:null} creator_per_subgraph: - omen_subgraph: ${list:["0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec"]} + omen_subgraph: ${list:[]} + polymarket_gamma_subgraph: ${list:["0x91430cad2d3975766499717fa0d66a78d814e5c5"]} slot_count: ${int:2} opening_margin: ${int:300} languages: ${list:["en_US"]} diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 2e045ac87..3c7e2b7d3 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:bafybeidb4omu5cwpedqrlyjeqnkafpgje6xkt3i6ky6igoynue7ojpcegm +agent: valory/trader:0.1.0:bafybeidjs3la6qd655ajn2u4lbchdi7suy5gne5rvzwgiscqrcvghz4oqy number_of_agents: 4 deployment: {} --- @@ -71,7 +71,8 @@ type: skill validate_timeout: ${VALIDATE_TIMEOUT:int:1205} history_check_timeout: ${HISTORY_CHECK_TIMEOUT:int:1205} creator_per_subgraph: &id003 - omen_subgraph: ${OMEN_CREATORS:list:["0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec"]} + omen_subgraph: ${OMEN_CREATORS:list:[]} + polymarket_gamma_subgraph: ${POLYMARKET_CREATORS:list:["0x91430cad2d3975766499717fa0d66a78d814e5c5"]} slot_count: ${SLOT_COUNT:int:2} opening_margin: ${OPENING_MARGIN:int:300} languages: ${LANGUAGES:list:["en_US"]} diff --git a/packages/valory/skills/decision_maker_abci/behaviours/sampling.py b/packages/valory/skills/decision_maker_abci/behaviours/sampling.py index 77e2ec131..fb88bb72e 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/sampling.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/sampling.py @@ -43,7 +43,7 @@ def available_bets(self) -> Iterator[Bet]: # Note: the openingTimestamp is misleading as it is the closing timestamp of the bet if self.params.using_kelly: - # get only bets that close in the next 48 hours + # get only bets that close in the next `sample_bets_closing_days` self.bets = [ bet for bet in self.bets diff --git a/packages/valory/skills/decision_maker_abci/models.py b/packages/valory/skills/decision_maker_abci/models.py index fa351eb3f..ec90b5a34 100644 --- a/packages/valory/skills/decision_maker_abci/models.py +++ b/packages/valory/skills/decision_maker_abci/models.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------ # -# Copyright 2023 Valory AG +# Copyright 2023-2024 Valory AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -69,7 +69,7 @@ DEFAULT_FROM_BLOCK = "earliest" ZERO_HEX = HASH_ZERO[2:] ZERO_BYTES = bytes.fromhex(ZERO_HEX) -STRATEGY_BET_AMOUNT_PER_CONF_THRESHOLD = "bet_amount_per_conf_threshold" +STRATEGY_BET_AMOUNT_PER_CONF_THRESHOLD = "bet_amount_per_threshold" STRATEGY_KELLY_CRITERION = "kelly_criterion" diff --git a/packages/valory/skills/decision_maker_abci/skill.yaml b/packages/valory/skills/decision_maker_abci/skill.yaml index bc00dce8f..3e1293b5e 100644 --- a/packages/valory/skills/decision_maker_abci/skill.yaml +++ b/packages/valory/skills/decision_maker_abci/skill.yaml @@ -21,14 +21,14 @@ fingerprint: behaviours/randomness.py: bafybeidmr33teizrs4uxlo5tdz766ds6os4pe5lttstm7jpmhgmjz5ti3q behaviours/reedem.py: bafybeibenzbek5qdtk3gobjxfmsm6tg6i3d4yltozymy23izpgbcpal5ye behaviours/round_behaviour.py: bafybeibymtirxbazjalmvfstnohaeqhmk4tggwwqhu62gm7mxdv6eabe3y - behaviours/sampling.py: bafybeibxcth4gsn7ov5liz5ma5tcflt7nvi64ku4gxlngno5vn3qr7km4u + behaviours/sampling.py: bafybeihtcqi3fpeygsp7hbwhr22vyliem4ewly6z27t7zo3e73ob3stw5a behaviours/tool_selection.py: bafybeicxw4je76uc7znx4u2hq2b2aaxcf7blwfla7lhdhkqnf3kkupsczq dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm fsm_specification.yaml: bafybeigub5ekfxfj4xaitern7lbjtlpdgjqzgwmuijrea5b6dpu2npau7m handlers.py: bafybeiggoetspwcvdojmbjdd67tmkoeedikmt6vsbcium3zjaljb6jzqu4 io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq io_/loader.py: bafybeih3sdsx5dhe4kzhtoafexjgkutsujwqy3zcdrlrkhtdks45bc7exa - models.py: bafybeif63pruksc6fpvmg77jmsrphc36uiawypzzcrk6nbpzoglbpxnlfy + models.py: bafybeigw3tbiojunr5iwuqgr6vdx6s355htlrbugiz2tgokxupauhx52iy payloads.py: bafybeigcic4vewdglakzpyqevhfwsolh4ywnbvxo5bgned7gl5uo3jif7m policy.py: bafybeihca4gc5gdj3wmvtzulqq3cr4zm6ouyt7aoscfedutzr4so4bksna redeem_info.py: bafybeifiiix4gihfo4avraxt34sfw35v6dqq45do2drrssei2shbps63mm @@ -37,7 +37,7 @@ fingerprint: states/base.py: bafybeiag6q3nlndsu4nt66rxrgogueh364v3lekqo4c5ynuuo4hql2bxum states/bet_placement.py: bafybeibalhxhp2c4oljmiwqi6ds3g36fgtabmf42mb5sgq6z22znrcbhda states/blacklisting.py: bafybeifruvxwwltndwazkzzbpc5nnnad3z5t5ofy6d3i7nssljbxl6gvxu - states/decision_receive.py: bafybeib3roo27nccj4eylaqwwzztzzzwsi6px5atjrch5wbqmpln2kyy6y + states/decision_receive.py: bafybeiclng2o5skqc7jwuqggpk6guexaot6e2clgfbhejwe4zlkgayeshq states/decision_request.py: bafybeic7otc3hjb753svbmur3yyk6szahc25yii3x4w4vcnpfz6jwvacuu states/final_states.py: bafybeidiwhuyd5zm2cq7vhv2owcrxdpm7fnvn3db6p6tql4jz5hgpalflu states/handle_failed_tx.py: bafybeihewm2vernvhktuorljdupjqcg2p5vs6wvsira2d62wkoyo5xlzjm @@ -67,7 +67,7 @@ protocols: - valory/ipfs:0.1.0:bafybeiedxeismnx3k5ty4mvvhlqideixlhqmi5mtcki4lxqfa7uqh7p33u skills: - valory/abstract_round_abci:0.1.0:bafybeicrzndcdbue34yxwwb4hmmdhgzw4owcdcdag3ifj6thpx5wie3dp4 -- valory/market_manager_abci:0.1.0:bafybeifdf6uoscrgvlgqceqcph2pgoygobznw6hbodpav7lubbqsyh4kby +- valory/market_manager_abci:0.1.0:bafybeia7vrpts3jeldxr4osltz5ekw7p3h2ib5ossutpviplkzqvfwhjua - valory/transaction_settlement_abci:0.1.0:bafybeifpnkwgwpzz6uwrvfgurm26allr6shjfbp7bfbrxwy64sw3nf3fsa behaviours: main: diff --git a/packages/valory/skills/decision_maker_abci/states/decision_receive.py b/packages/valory/skills/decision_maker_abci/states/decision_receive.py index a45b9ecd2..4b104e645 100644 --- a/packages/valory/skills/decision_maker_abci/states/decision_receive.py +++ b/packages/valory/skills/decision_maker_abci/states/decision_receive.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------ # -# Copyright 2023 Valory AG +# Copyright 2023-2024 Valory AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/packages/valory/skills/market_manager_abci/behaviours.py b/packages/valory/skills/market_manager_abci/behaviours.py index f833032e8..ec25be056 100644 --- a/packages/valory/skills/market_manager_abci/behaviours.py +++ b/packages/valory/skills/market_manager_abci/behaviours.py @@ -150,10 +150,10 @@ def _update_bets( if not can_proceed: break - bets_market_chunk = yield from self._fetch_bets() + bets_market_chunk, deserializer = yield from self._fetch_bets() if bets_market_chunk is not None: bets_updates = ( - Bet(**bet, market=self._current_market) + deserializer(**bet, market=self._current_market) for bet in bets_market_chunk if bet.get("id", "") not in existing_ids ) diff --git a/packages/valory/skills/market_manager_abci/bets.py b/packages/valory/skills/market_manager_abci/bets.py index 129ae1a94..301469984 100644 --- a/packages/valory/skills/market_manager_abci/bets.py +++ b/packages/valory/skills/market_manager_abci/bets.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------ # -# Copyright 2023 Valory AG +# Copyright 2023-2024 Valory AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,11 +24,21 @@ import dataclasses import json import sys +from datetime import datetime, timezone from enum import Enum, auto from typing import Any, Dict, List, Optional, Union BINARY_N_SLOTS = 2 +USDC = "0x2791bca1f2de4661ed88a30c99a7a9449aa84174" +NULL_ADDRESS = "0x" + "0" * 40 +OMEN_TO_POLYWRAP = dict( + id="marketMakerAddress", + market="market", + title="question", + fee="fee", + scaledLiquidityMeasure="liquidity", +) class BetStatus(Enum): @@ -58,6 +68,32 @@ class Bet: status: BetStatus = BetStatus.UNPROCESSED blacklist_expiration: float = -1 + @classmethod + def from_gamma_subgraph(cls, **kwargs: Any) -> "Bet": + """Initialize a bet's instance from gamma subgraph's attributes.""" + outcomes = eval(kwargs["outcomes"]) # nosec + outcome_token_amounts = [0] * len(outcomes) + end_date = datetime.strptime(kwargs["endDate"], "%Y-%m-%dT%H:%M:%S.%fZ") + opening_timestamp = int(end_date.replace(tzinfo=timezone.utc).timestamp()) + submitted_by = kwargs["submitted_by"] or NULL_ADDRESS + outcome_prices = eval(kwargs["outcomePrices"]) # nosec + + omen_to_polywrap_mapping = { + omen_key: kwargs[polywrap_key] + for omen_key, polywrap_key in OMEN_TO_POLYWRAP.items() + } + + return cls( + collateralToken=USDC, + creator=submitted_by, + openingTimestamp=opening_timestamp, + outcomeSlotCount=len(outcomes), + outcomeTokenAmounts=outcome_token_amounts, + outcomeTokenMarginalPrices=outcome_prices, + outcomes=outcomes, + **omen_to_polywrap_mapping, + ) + def __post_init__(self) -> None: """Post initialization to adjust the values.""" self._validate() diff --git a/packages/valory/skills/market_manager_abci/graph_tooling/queries/polymarket.py b/packages/valory/skills/market_manager_abci/graph_tooling/queries/polymarket.py new file mode 100644 index 000000000..e243e66ff --- /dev/null +++ b/packages/valory/skills/market_manager_abci/graph_tooling/queries/polymarket.py @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- +# ------------------------------------------------------------------------------ +# +# Copyright 2023-2024 Valory AG +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------------ + +"""Polymarket queries.""" + +from string import Template + + +questions_polymarket_gamma = Template( + """ + { + markets( + where: "active=true AND closed=false AND outcomes='[\\\"Yes\\\", \\\"No\\\"]' AND NOT market_maker_address=''" + order: "start_date DESC" + limit: 100 + ) { + marketMakerAddress + question + denominationToken + submitted_by + fee + endDate + outcomes + outcomePrices + liquidity + } + } + """ +) + + +questions_polymarket = Template( + """ + { + fixedProductMarketMakers( + where: { + outcomeSlotCount: ${slot_count}, + }, + orderBy: creationTimestamp + orderDirection: desc + first: 1000 + ){ + id + collateralToken { + id + name + symbol + } + creator + fee + outcomeSlotCount + outcomeTokenAmounts + outcomeTokenPrices + scaledLiquidityParameter + conditions { + id + questionId + } + } + } + """ +) + +# Missing fields: +# language_in: ${languages}, +# openingTimestamp +# outcomes + + +# Different fields: +# outcomeTokenMarginalPrices == outcomeTokenPrices ? +# scaledLiquidityParameter == scaledLiquidityMeasure ? + + +trades = Template( + """ + { + fpmmTrades ( + where: { + type: Buy, + creator: "${creator}", + fpmm_: { + creationTimestamp_gt: "${creationTimestamp_gt}", + answerFinalizedTimestamp_not: null, + isPendingArbitration: false + } + } + orderBy: fpmm__creationTimestamp + orderDirection: asc + first: ${first} + ){ + fpmm { + answerFinalizedTimestamp + collateralToken + condition { + id + outcomeSlotCount + } + creator + creationTimestamp + currentAnswer + question { + id + data + } + templateId + } + outcomeIndex + outcomeTokenMarginalPrice + outcomeTokensTraded + transactionHash + } + } + """ +) diff --git a/packages/valory/skills/market_manager_abci/graph_tooling/requests.py b/packages/valory/skills/market_manager_abci/graph_tooling/requests.py index 7dff47042..3e052a15b 100644 --- a/packages/valory/skills/market_manager_abci/graph_tooling/requests.py +++ b/packages/valory/skills/market_manager_abci/graph_tooling/requests.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------ # -# Copyright 2021-2023 Valory AG +# Copyright 2021-2024 Valory AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,12 +23,13 @@ import json from abc import ABC from enum import Enum, auto -from typing import Any, Dict, Generator, Iterator, List, Optional, Tuple, cast +from typing import Any, Callable, Dict, Generator, Iterator, List, Optional, Tuple, cast from web3 import Web3 from packages.valory.skills.abstract_round_abci.behaviour_utils import BaseBehaviour from packages.valory.skills.abstract_round_abci.models import ApiSpecs +from packages.valory.skills.market_manager_abci.bets import Bet from packages.valory.skills.market_manager_abci.graph_tooling.queries.conditional_tokens import ( user_positions as user_positions_query, ) @@ -36,8 +37,11 @@ block_number, ) from packages.valory.skills.market_manager_abci.graph_tooling.queries.omen import ( - questions, - trades, + questions as questions_omen, +) +from packages.valory.skills.market_manager_abci.graph_tooling.queries.omen import trades +from packages.valory.skills.market_manager_abci.graph_tooling.queries.polymarket import ( + questions_polymarket_gamma, ) from packages.valory.skills.market_manager_abci.graph_tooling.queries.realitio import ( answers as answers_query, @@ -47,6 +51,8 @@ ) from packages.valory.skills.market_manager_abci.models import ( MarketManagerParams, + OmenSubgraph, + PolymarketGammaSubgraph, SharedState, ) from packages.valory.skills.market_manager_abci.rounds import SynchronizedData @@ -120,10 +126,12 @@ def current_subgraph(self) -> ApiSpecs: def _prepare_fetching(self) -> bool: """Prepare for fetching a bet.""" if self._fetch_status in (FetchStatus.SUCCESS, FetchStatus.NONE): - res = next(self._creators_iterator, None) - if res is None: - return False - self._current_market, self._current_creators = res + self._current_creators = [] + while len(self._current_creators) == 0: + res = next(self._creators_iterator, None) + if res is None: + return False + self._current_market, self._current_creators = res if self._fetch_status == FetchStatus.FAIL: return False @@ -168,16 +176,26 @@ def _handle_response( self._fetch_status = FetchStatus.SUCCESS return res - def _fetch_bets(self) -> Generator[None, None, Optional[list]]: + def _fetch_bets(self) -> Generator[None, None, Tuple[Optional[list], Callable]]: """Fetch questions from the current subgraph, for the current creators.""" self._fetch_status = FetchStatus.IN_PROGRESS - query = questions.substitute( - creators=to_graphql_list(self._current_creators), - slot_count=self.params.slot_count, - opening_threshold=self.synced_time + self.params.opening_margin, - languages=to_graphql_list(self.params.languages), - ) + if isinstance(self.current_subgraph, PolymarketGammaSubgraph): + # TODO: we ignore 'creators' and simply fetch 100 latest markets. + query = questions_polymarket_gamma.substitute( + slot_count=self.params.slot_count, + ) + deserializer = Bet.from_gamma_subgraph + elif isinstance(self.current_subgraph, OmenSubgraph): + query = questions_omen.substitute( + creators=to_graphql_list(self._current_creators), + slot_count=self.params.slot_count, + opening_threshold=self.synced_time + self.params.opening_margin, + languages=to_graphql_list(self.params.languages), + ) + deserializer = Bet + else: + raise ValueError(f"Unknown API with id: {self.current_subgraph.api_id}!") res_raw = yield from self.get_http_response( content=to_content(query), @@ -191,7 +209,7 @@ def _fetch_bets(self) -> Generator[None, None, Optional[list]]: res_context="questions", ) - return bets + return bets, deserializer def _fetch_redeem_info(self) -> Generator[None, None, Optional[list]]: """Fetch redeeming information from the current subgraph.""" diff --git a/packages/valory/skills/market_manager_abci/models.py b/packages/valory/skills/market_manager_abci/models.py index 8419734c4..65b2c8d5d 100644 --- a/packages/valory/skills/market_manager_abci/models.py +++ b/packages/valory/skills/market_manager_abci/models.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------ # -# Copyright 2023 Valory AG +# Copyright 2023-2024 Valory AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -48,6 +48,14 @@ class OmenSubgraph(ApiSpecs): """A model that wraps ApiSpecs for the OMEN's subgraph specifications.""" +class PolymarketSubgraph(ApiSpecs): + """A model that wraps ApiSpecs for the Polymarket subgraph specifications.""" + + +class PolymarketGammaSubgraph(ApiSpecs): + """A model that wraps ApiSpecs for the Polymarket Gamma subgraph specifications.""" + + class NetworkSubgraph(ApiSpecs): """A model that wraps ApiSpecs for the network's subgraph specifications.""" diff --git a/packages/valory/skills/market_manager_abci/skill.yaml b/packages/valory/skills/market_manager_abci/skill.yaml index 1d4db592b..d0fe8144b 100644 --- a/packages/valory/skills/market_manager_abci/skill.yaml +++ b/packages/valory/skills/market_manager_abci/skill.yaml @@ -8,8 +8,8 @@ aea_version: '>=1.0.0, <2.0.0' fingerprint: README.md: bafybeie6miwn67uin3bphukmf7qgiifh4xtm42i5v3nuyqxzxtehxsqvcq __init__.py: bafybeigrtedqzlq5mtql2ssjsdriw76ml3666m4e2c3fay6vmyzofl6v6e - behaviours.py: bafybeidixvs5z6evcwu2nyiii4n4h7vwdc6xsyevp5wszf7h5sokfu5ryy - bets.py: bafybeid5jw3o57bivq32ojphjmu3xoulf6y6r2pnzuhyp7u6nz3pojpbuu + behaviours.py: bafybeiahcgt4r3q33lcj46bcfojbozntacggnn7fmftc3xa5czepkvnfci + bets.py: bafybeifylnqxusdcamdbrehl7myt72ux6e6iqbrkri4adbeoywz2jtlgna dialogues.py: bafybeiebofyykseqp3fmif36cqmmyf3k7d2zbocpl6t6wnlpv4szghrxbm fsm_specification.yaml: bafybeic5cvwfbiu5pywyp3h5s2elvu7jqdrcwayay7o3v3ow47vu2jw53q graph_tooling/__init__.py: bafybeigzo7nhbzafyq3fuhrlewksjvmzttiuk4vonrggtjtph4rw4ncpk4 @@ -17,12 +17,13 @@ fingerprint: graph_tooling/queries/conditional_tokens.py: bafybeic6ohkdp4rvkcfglieksv6gbzm4qocpgdjaz4sroutl37sxijthji graph_tooling/queries/network.py: bafybeigeq72ys2nrjqspj2uacaudrgljrne5a3o5jvzsktldxdq6m2xmeu graph_tooling/queries/omen.py: bafybeiesgavgoio6zeovdyvzeezz5qoosdgioktoen5ckrgyxpr4u3m3nu + graph_tooling/queries/polymarket.py: bafybeifksst3c54bjxedroe2gxtr7mga5f7ftuolj7jpdbbabn6m6xr3yy graph_tooling/queries/realitio.py: bafybeiftewjwk5fi6uqrhmalweun47voau2qkxi7hg3faxcmyy3va44zma graph_tooling/queries/trades.py: bafybeigu6c25kf3mrlvmwjeskgagswdjnnxsygpriygmip44us4xvuf7ji - graph_tooling/requests.py: bafybeieki6p6d77hi3ewd2rd4kk43v5y7buqozjnhysxopbzo64n3zy3kq + graph_tooling/requests.py: bafybeidhmj3ehool5bliavzjvnbsfvngcss5u2jsttngkpqgocwd4e2mai graph_tooling/utils.py: bafybeig5hxhnqgyfn5ym3poc5nziqwpeozqbd6wa4s6c2hjn6iyedg3t3y handlers.py: bafybeihot2i2yvfkz2gcowvt66wdu6tkjbmv7hsmc4jzt4reqeaiuphbtu - models.py: bafybeifmb4cojxesv2lcw6j3pm3yqjpsiuwyxpuexjbz656fpapdqcj2ba + models.py: bafybeid4u7za24nqa23bqpabfczwgnbwy552zx4htnwc5qdh3ax3abl67i payloads.py: bafybeicfymvvtdpkcgmkvthfzmb7dqakepkzslqrz6rcs7nxkz7qq3mrzy rounds.py: bafybeig4767ilvcz6w5xbp42y6ih3av7p4oz4a7tpm2yqmtezrjs5acebe fingerprint_ignore_patterns: [] @@ -135,6 +136,7 @@ models: serious_slash_unit_amount: 8000000000000000 creator_per_subgraph: omen_subgraph: [] + polymarket_gamma_subgraph: [] slot_count: 2 opening_margin: 300 languages: @@ -167,6 +169,30 @@ models: retries: 5 url: https://api.thegraph.com/subgraphs/name/protofire/omen-xdai class_name: OmenSubgraph + polymarket_subgraph: + args: + api_id: polymarket + headers: + Content-Type: application/json + method: POST + parameters: {} + response_key: data:fixedProductMarketMakers + response_type: list + retries: 5 + url: https://api.thegraph.com/subgraphs/name/polymarket/matic-markets + class_name: PolymarketSubgraph + polymarket_gamma_subgraph: + args: + api_id: polymarket_gamma + headers: + Content-Type: application/json + method: POST + parameters: {} + response_key: data:markets + response_type: list + retries: 5 + url: https://gamma-api.polymarket.com/query + class_name: PolymarketGammaSubgraph requests: args: {} class_name: Requests diff --git a/packages/valory/skills/trader_abci/models.py b/packages/valory/skills/trader_abci/models.py index 45188a781..b9a100464 100644 --- a/packages/valory/skills/trader_abci/models.py +++ b/packages/valory/skills/trader_abci/models.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # ------------------------------------------------------------------------------ # -# Copyright 2023 Valory AG +# Copyright 2023-2024 Valory AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -54,6 +54,12 @@ from packages.valory.skills.market_manager_abci.models import ( OmenSubgraph as MarketManagerOmenSubgraph, ) +from packages.valory.skills.market_manager_abci.models import ( + PolymarketGammaSubgraph as MarketManagerPolyMarketGammaSubgraph, +) +from packages.valory.skills.market_manager_abci.models import ( + PolymarketSubgraph as MarketManagerPolymarketSubgraph, +) from packages.valory.skills.market_manager_abci.rounds import ( Event as MarketManagerEvent, ) @@ -82,6 +88,8 @@ Requests = BaseRequests BenchmarkTool = BaseBenchmarkTool OmenSubgraph = MarketManagerOmenSubgraph +PolymarketSubgraph = MarketManagerPolymarketSubgraph +PolymarketGammaSubgraph = MarketManagerPolyMarketGammaSubgraph NetworkSubgraph = MarketManagerNetworkSubgraph MechResponseSpecs = DecisionMakerMechResponseSpecs AgentToolsSpecs = DecisionMakerAgentToolsSpecs diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 346406552..f62b6157e 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -13,7 +13,7 @@ fingerprint: dialogues.py: bafybeiebofyykseqp3fmif36cqmmyf3k7d2zbocpl6t6wnlpv4szghrxbm fsm_specification.yaml: bafybeifkeuotkaoeigtohopkm5mxgmsl2jdlsg2obpizqel6vjtyyz5uzm handlers.py: bafybeibkiqwe7hoqccjirimd44nzeqkabc7oo74romqklssion27s5sa2a - models.py: bafybeibrxivgpzamfmrl6bdngi67g72i32lmu5vgdn3jbwka265blk7ire + models.py: bafybeigqhtyji4vbtkatg6sxlywabcupvaxkn3j6bkeh2kgpmucxpyoduq fingerprint_ignore_patterns: [] connections: [] contracts: [] @@ -24,9 +24,9 @@ skills: - valory/reset_pause_abci:0.1.0:bafybeibnwjcjx4lluf4cwb6es5peelu3gm7vrzlieygrzpbjlubxpvbvzy - valory/transaction_settlement_abci:0.1.0:bafybeifpnkwgwpzz6uwrvfgurm26allr6shjfbp7bfbrxwy64sw3nf3fsa - valory/termination_abci:0.1.0:bafybeifdtxgldw33kwvsavcituzewwbr6iqfcsgk5qouqfhpwdrivyyyom -- valory/market_manager_abci:0.1.0:bafybeifdf6uoscrgvlgqceqcph2pgoygobznw6hbodpav7lubbqsyh4kby -- valory/decision_maker_abci:0.1.0:bafybeigv6vymf2jisrrwnvobyzmtpa6566ldaq2u7r2vdslrv7h6fhvprq -- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeicrvyshqokgxd7azjy6g3yzhk44lscerwnkci33eisam2foetjv4m +- valory/market_manager_abci:0.1.0:bafybeia7vrpts3jeldxr4osltz5ekw7p3h2ib5ossutpviplkzqvfwhjua +- valory/decision_maker_abci:0.1.0:bafybeihxo35ycripnuwcltfy64lxhaox43av7lbcozdgw2w3wupzzpdnn4 +- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibal5o2ji3rxjf5plwsexpiafv6ufnntre2pikfd5qrykff3icaoi - valory/staking_abci:0.1.0:bafybeiccopehegiiwxzghrttdhuxtnjp7zvuiclx5zchbtvqpy45rrvdxy behaviours: main: @@ -138,6 +138,7 @@ models: validate_timeout: 1205 creator_per_subgraph: omen_subgraph: [] + polymarket_gamma_subgraph: [] slot_count: 2 opening_margin: 300 languages: @@ -228,6 +229,30 @@ models: retries: 5 url: https://api.thegraph.com/subgraphs/name/protofire/omen-xdai class_name: OmenSubgraph + polymarket_subgraph: + args: + api_id: polymarket + headers: + Content-Type: application/json + method: POST + parameters: {} + response_key: data:fixedProductMarketMakers + response_type: list + retries: 5 + url: https://api.thegraph.com/subgraphs/name/polymarket/matic-markets + class_name: PolymarketSubgraph + polymarket_gamma_subgraph: + args: + api_id: polymarket_gamma + headers: + Content-Type: application/json + method: POST + parameters: {} + response_key: data:markets + response_type: list + retries: 5 + url: https://gamma-api.polymarket.com/query + class_name: PolymarketGammaSubgraph randomness_api: args: api_id: cloudflare diff --git a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml index 52c27b57b..67ad96855 100644 --- a/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml +++ b/packages/valory/skills/tx_settlement_multiplexer_abci/skill.yaml @@ -21,7 +21,7 @@ protocols: - valory/ledger_api:1.0.0:bafybeige5agrztgzfevyglf7mb4o7pzfttmq4f6zi765y4g2zvftbyowru skills: - valory/abstract_round_abci:0.1.0:bafybeicrzndcdbue34yxwwb4hmmdhgzw4owcdcdag3ifj6thpx5wie3dp4 -- valory/decision_maker_abci:0.1.0:bafybeigv6vymf2jisrrwnvobyzmtpa6566ldaq2u7r2vdslrv7h6fhvprq +- valory/decision_maker_abci:0.1.0:bafybeihxo35ycripnuwcltfy64lxhaox43av7lbcozdgw2w3wupzzpdnn4 - valory/staking_abci:0.1.0:bafybeiccopehegiiwxzghrttdhuxtnjp7zvuiclx5zchbtvqpy45rrvdxy behaviours: main: