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

Fix: Update scripts with the latest middleware #19

Merged
merged 7 commits into from
Jan 17, 2025
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Ensure your machine satisfies the requirements:

- Python `==3.10`
- [Poetry](https://python-poetry.org/docs/) `>=1.8.3`
- [Docker Engine](https://docs.docker.com/engine/install/)
- [Docker Compose](https://docs.docker.com/compose/install/)

## Resource Requirements
Expand All @@ -42,6 +41,10 @@ where `agent_config.json` is the path to your agent configuration file. Check th
| Agent | Config path | Docs |
| --- | --- | --- |
| Trader | `configs/config_predict_trader.json` | [Trader README](scripts/predict_trader/README.md) |
| Mech | `configs/config_mech.json` | [Mech README](https://github.com/valory-xyz/mech) |
| Optimus | `configs/config_optimus.json` | [Optimus README](https://github.com/valory-xyz/optimus) |
| Modius | `configs/config_modius.json` | [Modius README](https://github.com/valory-xyz/modius-quickstart) |
| Memeooorr | `configs/config_memeooorr.json` | [Memeooorr README](https://github.com/dvilelaf/meme-ooorr) |

Answer `1) No staking` when prompted:

Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include = []

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
olas-operate-middleware = { git = "https://github.com/valory-xyz/olas-operate-app.git", rev = "5de9dcf85b422f90554236a458510938b1029a86"}
olas-operate-middleware = { git = "https://github.com/valory-xyz/olas-operate-app.git", rev = "f877f0eeb0ffc307971963c958fd7c45502666e9"}
tqdm = "^4.67.1"

[tool.poetry.group.dev.dependencies]
Expand Down
6 changes: 3 additions & 3 deletions scripts/predict_trader/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ A quickstart for the trader agent for AI prediction markets on Gnosis at https:/
1. Use the `trades` command to display information about placed trades by a given address:

```bash
poetry run python scripts/predict_trader/trades.py --creator YOUR_SAFE_ADDRESS
poetry run python -m scripts.predict_trader.trades --creator YOUR_SAFE_ADDRESS
```

Or restrict the search to specific dates by defining the "from" and "to" dates:

```bash
poetry run python scripts/predict_trader/trades.py --creator YOUR_SAFE_ADDRESS --from-date 2023-08-15:03:50:00 --to-date 2023-08-20:13:45:00
poetry run python -m scripts.predict_trader.trades --creator YOUR_SAFE_ADDRESS --from-date 2023-08-15:03:50:00 --to-date 2023-08-20:13:45:00
```

2. Use the `report` command to display a summary of the service status:

```bash
poetry run python scripts/predict_trader/report.py
poetry run python -m scripts.predict_trader.report
```

3. Use this command to investigate your agent's logs:
Expand Down
5 changes: 3 additions & 2 deletions scripts/predict_trader/rank_traders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@


import datetime
import requests
import sys
from argparse import ArgumentParser
from collections import defaultdict
from string import Template
from typing import Any

import requests
from operate.operate_types import Chain
from operate.quickstart.run_service import load_local_config
from scripts.utils import get_subgraph_api_key
from scripts.predict_trader.trades import MarketAttribute, MarketState, parse_user, wei_to_xdai
Expand Down Expand Up @@ -310,7 +311,7 @@ def _print_progress_bar( # pylint: disable=too-many-arguments
user_args = _parse_args()

config = load_local_config()
rpc = config.gnosis_rpc
rpc = config.rpc[Chain.GNOSIS.value]

print("Querying Thegraph...")
all_trades_json = _query_omen_xdai_subgraph(
Expand Down
43 changes: 23 additions & 20 deletions scripts/predict_trader/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@

from operate.constants import (
OPERATE_HOME,
STAKING_TOKEN_JSON_URL,
ACTIVITY_CHECKER_JSON_URL,
STAKING_TOKEN_INSTANCE_ABI_PATH,
SERVICE_REGISTRY_TOKEN_UTILITY_JSON_URL,
MECH_ACTIVITY_CHECKER_JSON_URL,
MECH_CONTRACT_JSON_URL,
)
from operate.quickstart.run_service import load_local_config
Expand All @@ -65,7 +65,6 @@
TRADES_LOOKBACK_DAYS = 3
MULTI_TRADE_LOOKBACK_DAYS = TRADES_LOOKBACK_DAYS
SECONDS_PER_DAY = 60 * 60 * 24

OUTPUT_WIDTH = 80


Expand Down Expand Up @@ -194,16 +193,15 @@ def _warning_message(current_value: int, threshold: int = 0, message: str = "")

def _get_agent_status() -> str:
client = docker.from_env()
trader_abci_container = (
client.containers.get("trader_abci_0")
if "trader_abci_0" in [c.name for c in client.containers.list()]
else None
)
trader_tm_container = (
client.containers.get("trader_tm_0")
if "trader_tm_0" in [c.name for c in client.containers.list()]
else None
)
trader_abci_container = None
trader_tm_container = None
for container in client.containers.list():
if container.name.startswith("traderpearl") and container.name.endswith("abci_0"):
trader_abci_container = container
elif container.name.startswith("traderpearl") and container.name.endswith("tm_0"):
trader_tm_container = container
if trader_abci_container and trader_tm_container:
break

is_running = trader_abci_container and trader_tm_container
return _color_bool(is_running, "Running", "Stopped")
Expand Down Expand Up @@ -232,7 +230,12 @@ def _parse_args() -> Any:
service = get_service_from_config(template_path)
chain_config = service.chain_configs["gnosis"]
agent_address = service.keys[0].address
operator_address = operator_wallet_data["address"]
if "safes" in operator_wallet_data and "gnosis" in operator_wallet_data["safes"]:
operator_address = operator_wallet_data["safes"]["gnosis"]
else:
print("Operate wallet not found.")
sys.exit(1)

safe_address = chain_config.chain_data.multisig
service_id = chain_config.chain_data.token
rpc = chain_config.ledger_config.rpc
Expand All @@ -258,15 +261,15 @@ def _parse_args() -> Any:
w3 = Web3(HTTPProvider(rpc))

staking_token_address = config.staking_vars["CUSTOM_STAKING_ADDRESS"]
staking_token_data = requests.get(STAKING_TOKEN_JSON_URL).json()
staking_token_data = requests.get(STAKING_TOKEN_INSTANCE_ABI_PATH).json()

staking_token_abi = staking_token_data.get("abi", [])
staking_token_contract = w3.eth.contract(
address=staking_token_address, abi=staking_token_abi # type: ignore
)

staking_state = StakingState(
staking_token_contract.functions.getServiceStakingState(
staking_token_contract.functions.getStakingState(
service_id
).call()
)
Expand All @@ -277,7 +280,7 @@ def _parse_args() -> Any:
)
_print_status("Is service staked?", _color_bool(is_staked, "Yes", "No"))
if is_staked:
_print_status("Staking program", env_file_vars.get("STAKING_PROGRAM")) # type: ignore
_print_status("Staking program", config.staking_vars.get("STAKING_PROGRAM")) # type: ignore
if staking_state == StakingState.STAKED:
_print_status("Staking state", staking_state.name)
elif staking_state == StakingState.EVICTED:
Expand All @@ -286,7 +289,7 @@ def _parse_args() -> Any:
if is_staked:

activity_checker_address = staking_token_contract.functions.activityChecker().call()
activity_checker_data = requests.get(ACTIVITY_CHECKER_JSON_URL).json()
activity_checker_data = requests.get(MECH_ACTIVITY_CHECKER_JSON_URL).json()

activity_checker_abi = activity_checker_data.get("abi", [])
activity_checker_contract = w3.eth.contract(
Expand All @@ -305,7 +308,7 @@ def _parse_args() -> Any:
abi=service_registry_token_utility_abi,
)

mech_contract_address = config.staking_vars["MECH_CONTRACT_ADDRESS"]
mech_contract_address = activity_checker_contract.functions.agentMech().call()
mech_contract_data = requests.get(MECH_CONTRACT_JSON_URL).json()

mech_contract_abi = mech_contract_data.get("abi", [])
Expand All @@ -319,7 +322,7 @@ def _parse_args() -> Any:
operator_address, service_id
).call()
)
agent_id = int(config.staking_vars["AGENT_ID"].strip())
agent_id = int(config.staking_vars["AGENT_ID"])
agent_bond = service_registry_token_utility_contract.functions.getAgentBond(
service_id, agent_id
).call()
Expand Down
3 changes: 2 additions & 1 deletion scripts/predict_trader/trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from string import Template
from typing import Any, Dict, Optional

from operate.operate_types import Chain
from operate.quickstart.run_service import load_local_config
from scripts.predict_trader.mech_events import get_mech_requests
from scripts.utils import get_service_from_config, get_subgraph_api_key
Expand Down Expand Up @@ -850,7 +851,7 @@ def get_mech_statistics(mech_requests: Dict[str, Any]) -> Dict[str, Dict[str, in
user_args = _parse_args()

config = load_local_config()
rpc = config.gnosis_rpc
rpc = config.rpc[Chain.GNOSIS.value]

mech_requests = get_mech_requests(
user_args.creator,
Expand Down
10 changes: 0 additions & 10 deletions tests/test_run_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,6 @@ def handle_native_funding(output: str, logger: logging.Logger, rpc_url: str, con
wallet_address = match.group(1)
required_amount = float(match.group(2))
wallet_type = "EOA" if "EOA" in pattern else "Safe"

if "modius" in config_type.lower():
original_amount = required_amount
required_amount = 0.6
logger.info(f"Modius detected: Increasing funding from {original_amount} ETH to {required_amount} ETH for gas buffer")
if "optimus" in config_type.lower():
original_amount = required_amount
required_amount = 100
logger.info(f"Optimus detected: Increasing funding from {original_amount} ETH to {required_amount} ETH for gas buffer")

try:
w3 = Web3(Web3.HTTPProvider(rpc_url))
amount_wei = w3.to_wei(required_amount, 'ether')
Expand Down
Loading