diff --git a/packages/valory/agents/trader/aea-config.yaml b/packages/valory/agents/trader/aea-config.yaml index c65f7ac27..343408ce3 100644 --- a/packages/valory/agents/trader/aea-config.yaml +++ b/packages/valory/agents/trader/aea-config.yaml @@ -186,6 +186,7 @@ models: realitio_address: ${str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${int:5} slippage: ${float:0.01} + redeem_margin_days: ${int:15} --- public_id: valory/p2p_libp2p_client:0.1.0 type: connection diff --git a/packages/valory/contracts/conditional_tokens/contract.py b/packages/valory/contracts/conditional_tokens/contract.py index 0456050ef..07f470417 100644 --- a/packages/valory/contracts/conditional_tokens/contract.py +++ b/packages/valory/contracts/conditional_tokens/contract.py @@ -91,6 +91,8 @@ def check_redeemed( f"Did the creation happen too long in the past?\n" f"The market with condition id {earliest_condition_id!r} " f"is the oldest one and the block filtering was set based on it." + "If the issue persists, try to decrease the value of `redeem_margin_days` " + f"in the agent's configuration, based on the date corresponding to the block number {earliest_block}." ) return dict(error=msg) diff --git a/packages/valory/services/trader/service.yaml b/packages/valory/services/trader/service.yaml index 5aea81645..3d09a1097 100644 --- a/packages/valory/services/trader/service.yaml +++ b/packages/valory/services/trader/service.yaml @@ -103,6 +103,7 @@ type: skill realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} slippage: ${SLIPPAGE:float:0.01} + redeem_margin_days: ${REDEEM_MARGIN_DAYS:int:15} benchmark_tool: &id005 args: log_dir: ${LOG_DIR:str:/benchmarks} @@ -166,6 +167,7 @@ type: skill realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} slippage: ${SLIPPAGE:float:0.01} + redeem_margin_days: ${REDEEM_MARGIN_DAYS:int:15} benchmark_tool: *id005 2: models: @@ -227,6 +229,7 @@ type: skill realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} slippage: ${SLIPPAGE:float:0.01} + redeem_margin_days: ${REDEEM_MARGIN_DAYS:int:15} benchmark_tool: *id005 3: models: @@ -288,6 +291,7 @@ type: skill realitio_address: ${REALITIO_ADDRESS:str:0x79e32aE03fb27B07C89c0c568F80287C01ca2E57} redeeming_batch_size: ${REDEEMING_BATCH_SIZE:int:5} slippage: ${SLIPPAGE:float:0.01} + redeem_margin_days: ${REDEEM_MARGIN_DAYS:int:15} benchmark_tool: *id005 --- public_id: valory/ledger:0.19.0 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 f7f932112..d22846fc8 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 @@ -61,6 +61,7 @@ creator: "${creator}", fpmm_: { answerFinalizedTimestamp_not: null, + creationTimestamp_gt: "${from_timestamp}", isPendingArbitration: false } } 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 43be8e56d..78ba61b43 100644 --- a/packages/valory/skills/market_manager_abci/graph_tooling/requests.py +++ b/packages/valory/skills/market_manager_abci/graph_tooling/requests.py @@ -41,6 +41,9 @@ from packages.valory.skills.market_manager_abci.rounds import SynchronizedData +DAY_UNIX = 24 * 60 * 60 + + def to_content(query: str) -> bytes: """Convert the given query string to payload content, i.e., add it under a `queries` key and convert it to bytes.""" finalized_query = {"query": query} @@ -184,7 +187,9 @@ def _fetch_redeem_info(self) -> Generator[None, None, Optional[list]]: self._fetch_status = FetchStatus.IN_PROGRESS safe = self.synchronized_data.safe_contract_address - query = trades.substitute(creator=safe.lower()) + redeem_margin = self.params.redeem_margin_days * DAY_UNIX + from_timestamp = self.synced_time - redeem_margin + query = trades.substitute(creator=safe.lower(), from_timestamp=from_timestamp) # workaround because we cannot have multiple response keys for a single `ApiSpec` res_key_backup = self.current_subgraph.response_info.response_key diff --git a/packages/valory/skills/market_manager_abci/models.py b/packages/valory/skills/market_manager_abci/models.py index 8419734c4..f23744b88 100644 --- a/packages/valory/skills/market_manager_abci/models.py +++ b/packages/valory/skills/market_manager_abci/models.py @@ -38,6 +38,9 @@ BenchmarkTool = BaseBenchmarkTool +GNOSIS_RPC_TIMEOUT_DAYS = 25 + + class SharedState(BaseSharedState): """Keep the current shared state of the skill.""" @@ -72,8 +75,40 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.languages: List[str] = self._ensure("languages", kwargs, List[str]) self.average_block_time: int = self._ensure("average_block_time", kwargs, int) self.abt_error_mult: int = self._ensure("abt_error_mult", kwargs, int) + self._redeem_margin_days: int = 0 + self.redeem_margin_days = self._ensure("redeem_margin_days", kwargs, int) super().__init__(*args, **kwargs) + @property + def redeem_margin_days(self) -> int: + """Get the margin in days of the redeeming information.""" + return self._redeem_margin_days + + @redeem_margin_days.setter + def redeem_margin_days(self, redeem_margin_days: int) -> None: + """Get the margin in days of the redeeming information.""" + value_enforcement = ( + f"The value needs to be in the exclusive range (0, {GNOSIS_RPC_TIMEOUT_DAYS}) " + f"and manual redeeming has to be performed for markets older than {GNOSIS_RPC_TIMEOUT_DAYS - 1} days." + ) + + if redeem_margin_days <= 0: + raise ValueError( + "The margin in days for the redeeming information (`redeem_margin_days`) " + f"cannot be set to {redeem_margin_days} <= 0. {value_enforcement}" + ) + if redeem_margin_days >= GNOSIS_RPC_TIMEOUT_DAYS: + raise ValueError( + "Due to a constraint of the Gnosis RPCs, it is not possible to configure the redeeming " + f"information's time window to exceed {GNOSIS_RPC_TIMEOUT_DAYS - 1} days " + f"(currently {redeem_margin_days=}). To clarify, these RPCs experience timeouts " + "when attempting to filter for historical on-chain events. " + "Practical testing of the service has revealed that timeouts consistently occur for blocks " + f"approximately {GNOSIS_RPC_TIMEOUT_DAYS} days old. {value_enforcement}" + ) + + self._redeem_margin_days = redeem_margin_days + @property def creators_iterator(self) -> Iterator[Tuple[str, List[str]]]: """Return an iterator of market per creators.""" diff --git a/packages/valory/skills/market_manager_abci/skill.yaml b/packages/valory/skills/market_manager_abci/skill.yaml index 94462f1e1..87edb1178 100644 --- a/packages/valory/skills/market_manager_abci/skill.yaml +++ b/packages/valory/skills/market_manager_abci/skill.yaml @@ -137,6 +137,7 @@ models: - en_US average_block_time: 5 abt_error_mult: 5 + redeem_margin_days: 15 class_name: MarketManagerParams network_subgraph: args: diff --git a/packages/valory/skills/trader_abci/skill.yaml b/packages/valory/skills/trader_abci/skill.yaml index 8a658b597..5c47d3c03 100644 --- a/packages/valory/skills/trader_abci/skill.yaml +++ b/packages/valory/skills/trader_abci/skill.yaml @@ -168,6 +168,7 @@ models: realitio_address: '0x79e32aE03fb27B07C89c0c568F80287C01ca2E57' redeeming_batch_size: 5 slippage: 0.01 + redeem_margin_days: 15 class_name: TraderParams network_subgraph: args: