diff --git a/fastlane_bot/config/__init__.py b/fastlane_bot/config/__init__.py index 82287e85a..a49c6ee0b 100644 --- a/fastlane_bot/config/__init__.py +++ b/fastlane_bot/config/__init__.py @@ -14,7 +14,6 @@ - Constants (``constants`` and ``selectors``; various constants) - ``MultiCaller`` and related (``multicaller``; TODO: what is this?) -- ``MultiProviderContractWrapper`` (``multiprovided``; TODO: what is this?) - ``NetworkBase`` and ``EthereumNetwork`` (``connect``; network/chain connection code TODO: details) - ``Cloaker`` (``cloaker``; deprecated) diff --git a/fastlane_bot/config/multicaller.py b/fastlane_bot/config/multicaller.py index d247776ff..d0f313063 100644 --- a/fastlane_bot/config/multicaller.py +++ b/fastlane_bot/config/multicaller.py @@ -15,7 +15,6 @@ from eth_abi import decode from web3 import Web3 -from fastlane_bot.config.multiprovider import MultiProviderContractWrapper from fastlane_bot.data.abi import MULTICALL_ABI @@ -112,7 +111,7 @@ class MultiCaller(ContextManager): __VERSION__ = "0.0.2" - def __init__(self, contract: MultiProviderContractWrapper or web3.contract.Contract, + def __init__(self, contract: web3.contract.Contract, web3: Web3, block_identifier: Any = 'latest', multicall_address = "0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696"): self._contract_calls: List[Callable] = [] diff --git a/fastlane_bot/config/multiprovider.py b/fastlane_bot/config/multiprovider.py deleted file mode 100644 index ccb89518d..000000000 --- a/fastlane_bot/config/multiprovider.py +++ /dev/null @@ -1,30 +0,0 @@ -""" -Defines the ``MultiProviderContractWrapper`` class - -TODO-MIKE: This is a very short module, so maybe the code should move somewhere else; -also -- should it really be in config? - ---- -(c) Copyright Bprotocol foundation 2023-24. -All rights reserved. -Licensed under MIT. -""" -from web3 import Web3 -from typing import Dict - -from web3.contract import Contract - - -class MultiProviderContractWrapper: - def __init__(self, abi: Dict, address: str, providers: Dict[str, str]): - self.abi = abi - self.contracts = {} - - for name, url in providers.items(): - w3 = Web3(Web3.HTTPProvider(url, request_kwargs={'timeout': 60})) - self.contracts[name] = w3.eth.contract(address=address, abi=self.abi) - - def __getattr__(self, name: str) -> Contract: - if name in self.contracts: - return self.contracts[name] - raise AttributeError(f"No provider named {name}") diff --git a/fastlane_bot/events/utils.py b/fastlane_bot/events/utils.py index f24620468..468ac82cd 100644 --- a/fastlane_bot/events/utils.py +++ b/fastlane_bot/events/utils.py @@ -28,7 +28,6 @@ from fastlane_bot import Config from fastlane_bot.bot import CarbonBot -from fastlane_bot.config.multiprovider import MultiProviderContractWrapper from fastlane_bot.data.abi import FAST_LANE_CONTRACT_ABI from fastlane_bot.exceptions import ReadOnlyException from fastlane_bot.events.interface import QueryInterface @@ -939,8 +938,6 @@ def update_pools_from_contracts( The number of jobs to run in parallel. rows_to_update : List[int] A list of rows to update. - multicall_contract : MultiProviderContractWrapper or web3.contract.Contract - The multicall contract. current_block : int, optional The current block number, by default None diff --git a/fastlane_bot/tests/test_899_CustomMulticall.py b/fastlane_bot/tests/test_899_CustomMulticall.py index d396de75a..da5628765 100644 --- a/fastlane_bot/tests/test_899_CustomMulticall.py +++ b/fastlane_bot/tests/test_899_CustomMulticall.py @@ -7,10 +7,6 @@ # ------------------------------------------------------------ - -import json - -from fastlane_bot.config.multiprovider import MultiProviderContractWrapper from fastlane_bot.data.abi import CARBON_CONTROLLER_ABI import os from unittest.mock import Mock, patch @@ -21,8 +17,7 @@ from fastlane_bot.config.multicaller import MultiCaller from fastlane_bot.config.multicaller import ContractMethodWrapper - -import pytest +from web3 import Web3 print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(MultiCaller)) print("{0.__name__} v{0.__VERSION__} ({0.__DATE__})".format(ContractMethodWrapper)) @@ -36,15 +31,8 @@ require("3.0", __VERSION__) WEB3_ALCHEMY_PROJECT_ID = os.environ.get("WEB3_ALCHEMY_PROJECT_ID") - -CONTRACT_ABI = CARBON_CONTROLLER_ABI +RPC_URL = f"https://eth-mainnet.alchemyapi.io/v2/{WEB3_ALCHEMY_PROJECT_ID}" CARBON_CONTROLLER_ADDRESS = "0xC537e898CD774e2dCBa3B14Ea6f34C93d5eA45e1" -CONTRACT_ADDRESS = CARBON_CONTROLLER_ADDRESS - -providers = { - "mainnet": f"https://eth-mainnet.alchemyapi.io/v2/{WEB3_ALCHEMY_PROJECT_ID}", - "tenderly": "https://rpc.tenderly.co/fork/5f70ee18-8d2f-40d7-8131-58d0c8ff4736", -} class MockWeb3: class HTTPProvider: @@ -93,21 +81,21 @@ def decode_abi(self): start_time = time.time() -contract = MultiProviderContractWrapper(CONTRACT_ABI, CONTRACT_ADDRESS, providers) +w3 = Web3(Web3.HTTPProvider(RPC_URL, request_kwargs={'timeout': 60})) +contract = w3.eth.contract(address=CARBON_CONTROLLER_ADDRESS, abi=CARBON_CONTROLLER_ABI) -mainnet_pairs = contract.mainnet.functions.pairs().call() -tenderly_pairs = contract.tenderly.functions.pairs().call() +mainnet_pairs = contract.caller.pairs() if len(mainnet_pairs) > 10: mainnet_pairs = mainnet_pairs[:10] -pair_fees_without_multicall = [contract.mainnet.functions.pairTradingFeePPM(pair[0], pair[1]).call() for pair in mainnet_pairs] +pair_fees_without_multicall = [contract.caller.pairTradingFeePPM(pair[0], pair[1]) for pair in mainnet_pairs] pair_fees_time_without_multicall = time.time() - start_time start_time = time.time() -strats_by_pair_without_multicall = [contract.mainnet.functions.strategiesByPair(pair[0], pair[1], 0, 5000).call() for pair in mainnet_pairs] +strats_by_pair_without_multicall = [contract.caller.strategiesByPair(pair[0], pair[1], 0, 5000) for pair in mainnet_pairs] strats_by_pair_time_without_multicall = time.time() - start_time