diff --git a/fastlane_bot/events/version_utils.py b/fastlane_bot/events/version_utils.py new file mode 100644 index 000000000..13cebef17 --- /dev/null +++ b/fastlane_bot/events/version_utils.py @@ -0,0 +1,43 @@ +from packaging import version as pkg_version +from importlib.metadata import version + + +class VersionRequirementError(Exception): + """ + A custom exception class for version requirement errors. + + Args: + installed_version (str): The installed version of web3.py. + required_version (str): The required version of web3.py. + + Raises: + None + """ + + def __init__(self, installed_version, required_version): + super().__init__( + f"" + f"\n\n************** Version Requirement Error **************\n\n" + f"Your current web3.py version is {installed_version}, which does not meet the requirement of ~= {required_version}.\n" + f"Please upgrade your web3.py version to {required_version}.\n" + f"We recommend using the latest requirements.txt file to install the latest versions of all " + f"dependencies.\n\n" + f"Run `pip install -r requirements.txt` from the project directory of the fastlane-bot repo.\n" + f"\n\n************** Version Requirement Error **************\n\n" + f"" + ) + + +def check_version_requirements(): + with open("requirements.txt", "r") as f: + requirements = f.read().splitlines() + + web3_version = [r for r in requirements if "web3" in r][0] + required_version = web3_version.split("~=")[1] + + # Get the installed version of web3 + installed_version = version("web3") + + # Check the version and raise an exception if the requirement is not met + if not pkg_version.parse(installed_version) <= pkg_version.parse("5.32.0"): + raise VersionRequirementError(installed_version, required_version) diff --git a/main.py b/main.py index 6b3a1d9b9..51f8ae5f7 100644 --- a/main.py +++ b/main.py @@ -5,9 +5,13 @@ (c) Copyright Bprotocol foundation 2023. Licensed under MIT """ + +from fastlane_bot.events.version_utils import check_version_requirements + +check_version_requirements() + import os import time -from glob import glob from typing import List import click @@ -15,7 +19,6 @@ from dotenv import load_dotenv from web3 import Web3, HTTPProvider -from fastlane_bot.events.interface import QueryInterface from fastlane_bot.events.managers.manager import Manager from fastlane_bot.events.multicall_utils import multicall_every_iteration from fastlane_bot.events.utils import ( @@ -47,7 +50,6 @@ read_csv_file, handle_tokens_csv, ) -from fastlane_bot.tools.cpc import T from fastlane_bot.utils import find_latest_timestamped_folder from run_blockchain_terraformer import terraform_blockchain @@ -216,12 +218,7 @@ "--blockchain", default="ethereum", help="Select a blockchain from the list. Blockchains not in this list do not have a deployed Fast Lane contract and are not supported.", - type=click.Choice( - [ - "ethereum", - "coinbase_base" - ] - ), + type=click.Choice(["ethereum", "coinbase_base"]), ) @click.option( "--pool_data_update_frequency", diff --git a/requirements.txt b/requirements.txt index 092ebda41..f044f26b5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,4 +17,4 @@ click~=8.1.3 setuptools~=67.6.1 protobuf==3.19.5 tqdm~=4.64.1 - +web3~=5.31.3 diff --git a/resources/NBTest/requirements.txt b/resources/NBTest/requirements.txt new file mode 100644 index 000000000..f044f26b5 --- /dev/null +++ b/resources/NBTest/requirements.txt @@ -0,0 +1,20 @@ +psutil==5.9.2 +packaging==21.3 +requests==2.28.1 +python-dateutil==2.8.1 +typing-extensions~=4.4.0 +python-dotenv~=0.16.0 +joblib~=1.2.0 +pandas~=1.5.2 +alchemy-sdk~=0.1.1 +pyarrow~=11.0.0 +networkx~=3.0 +cvxpy~=1.3.1 +matplotlib~=3.7.1 +dataclass_wizard~=0.22.2 +hexbytes~=0.2.3 +click~=8.1.3 +setuptools~=67.6.1 +protobuf==3.19.5 +tqdm~=4.64.1 +web3~=5.31.3