diff --git a/yearn/multicall2.py b/yearn/multicall2.py index 649d6ea68..8e66e48b3 100644 --- a/yearn/multicall2.py +++ b/yearn/multicall2.py @@ -7,15 +7,13 @@ import eth_retry import requests -from brownie import Contract, chain, web3 -from brownie.network.contract import _ContractMethod +from brownie import chain, web3 +from dank_mids.brownie_patch.types import DankContractMethod from eth_abi.exceptions import InsufficientDataBytes -from y.contracts import contract_creation_block -from y.networks import Network +from y import Contract, Network, contract_creation_block from yearn.exceptions import MulticallError from yearn.typing import Block -from yearn.utils import contract JSONRPC_BATCH_MAX_SIZE = int(os.environ.get("JSONRPC_BATCH_MAX_SIZE", 10_000)) # Currently set arbitrarily, necessaary for certain node-as-a-service providers. MULTICALL_MAX_SIZE = int(os.environ.get("MULTICALL_MAX_SIZE", 500)) # Currently set arbitrarily @@ -27,7 +25,7 @@ Network.Optimism: '0xcA11bde05977b3631167028862bE2a173976CA11', # Multicall 3 Network.Base: '0xcA11bde05977b3631167028862bE2a173976CA11' # MC3 } -multicall2 = contract(MULTICALL2[chain.id]) +multicall2 = Contract(MULTICALL2[chain.id]) def fetch_multicall(*calls, block: Optional[Block] = None, require_success: bool = False) -> List[Any]: @@ -123,7 +121,7 @@ async def fetch_multicall_async(*calls, block: Optional[Block] = None, require_s return results -def _get_fn(contract: Contract, fn_name: str, fn_inputs: Any) -> _ContractMethod: +def _get_fn(contract: Contract, fn_name: str, fn_inputs: Any) -> DankContractMethod: fn = getattr(contract, fn_name) # check that there aren't multiple functions with the same name if hasattr(fn, "_get_fn_from_args"): diff --git a/yearn/treasury/accountant/__init__.py b/yearn/treasury/accountant/__init__.py index a7b2aa9cf..808f65f54 100644 --- a/yearn/treasury/accountant/__init__.py +++ b/yearn/treasury/accountant/__init__.py @@ -4,12 +4,11 @@ from brownie import Contract from brownie.exceptions import ContractNotFound from tqdm import tqdm -from y.networks import Network +from y import Contract, ContractNotVerified, Network from yearn.entities import Address from yearn.treasury.accountant.accountant import * from yearn.treasury.accountant.prepare_db import prepare_db -from yearn.utils import contract logger = logging.getLogger(__name__) @@ -30,7 +29,7 @@ Network.Fantom: "0xd9db270c1b5e3bd161e8c8503c55ceabee709552", }.get(chain.id,None) -GNOSIS_ABI = contract(GNOSIS_IMPLEMENTATION).abi if GNOSIS_IMPLEMENTATION else None +GNOSIS_ABI = Contract(GNOSIS_IMPLEMENTATION).abi if GNOSIS_IMPLEMENTATION else None @db_session @@ -43,18 +42,14 @@ def __ensure_topics_are_known(addresses: List[Address]) -> None: no_topics = [] for address in tqdm(addresses): try: - if not contract(address.address).topics: + if not Contract(address.address).topics: if not force_gnosis_safe_abi(address): no_topics.append(address) except ContractNotFound: # This is MOST LIKELY unimportant and not Yearn related. - logger.debug(f"{address.address} self destructed") - except ValueError as e: - if str(e).startswith("Source for") and str(e).endswith("has not been verified"): - continue - if "Contract source code not verified" in str(e): - continue - raise + logger.debug("%s self destructed", address.address) + except ContractNotVerified: + logger.debug("%s is not verified", address.address) no_topics_with_nick = {address.nickname for address in no_topics if address.nickname} no_topics_no_nick = [address for address in no_topics if not address.nickname] @@ -73,7 +68,7 @@ def __ensure_signatures_are_known(addresses: List[Address]) -> None: no_sigs = [] for address in tqdm(addresses): try: - if not contract(address.address).signatures: + if not Contract(address.address).signatures: if not force_gnosis_safe_abi(address): no_sigs.append(address) except ContractNotFound: diff --git a/yearn/treasury/accountant/ignore/__init__.py b/yearn/treasury/accountant/ignore/__init__.py index 82e9a7f4e..26a2c5361 100644 --- a/yearn/treasury/accountant/ignore/__init__.py +++ b/yearn/treasury/accountant/ignore/__init__.py @@ -2,7 +2,7 @@ from decimal import Decimal from brownie import chain -from y import Network +from y import Contract, Network from yearn.entities import TreasuryTx from yearn.treasury.accountant.classes import HashMatcher, TopLevelTxGroup @@ -15,7 +15,6 @@ robovault, synthetix, uniswap, unwrapper, woofy, ycrv, yla) -from yearn.utils import contract IGNORE_LABEL = "Ignore" @@ -45,11 +44,11 @@ def is_kp3r(tx: TreasuryTx) -> bool: ) or ( tx.to_address and tx.to_address.is_contract - and contract(tx.to_address.address)._build['contractName'] in contract_names + and Contract(tx.to_address.address)._build['contractName'] in contract_names ) or ( tx.from_address.is_contract - and contract(tx.from_address.address)._build['contractName'] in contract_names + and Contract(tx.from_address.address)._build['contractName'] in contract_names ) or HashMatcher(hashes).contains(tx) ) @@ -71,7 +70,7 @@ def is_bridged(tx: TreasuryTx) -> bool: elif tx.to_address and tx.to_address.token and tx.to_address.token.symbol and tx.to_address.token.symbol.startswith("any") and "LogAnySwapOut" in tx._events: for event in tx._events["LogAnySwapOut"]: token, sender, receiver, amount, from_chainid, to_chainid = event.values() - if from_chainid == chain.id and sender == tx.from_address.address and tx.token.address.address == contract(token).underlying() and Decimal(amount) / tx.token.scale == tx.amount: + if from_chainid == chain.id and sender == tx.from_address.address and tx.token.address.address == Contract(token).underlying() and Decimal(amount) / tx.token.scale == tx.amount: return True # Anyswap in - anyToken part @@ -85,7 +84,7 @@ def is_bridged(tx: TreasuryTx) -> bool: elif tx.from_address and tx.from_address.token and tx.from_address.token.symbol and tx.from_address.token.symbol.startswith("any") and "LogAnySwapIn" in tx._events: for event in tx._events["LogAnySwapIn"]: txhash, token, receiver, amount, from_chainid, to_chainid = event.values() - if to_chainid == chain.id and receiver == tx.to_address.address and tx.token.address.address == contract(token).underlying() and Decimal(amount) / tx.token.scale == tx.amount: + if to_chainid == chain.id and receiver == tx.to_address.address and tx.token.address.address == Contract(token).underlying() and Decimal(amount) / tx.token.scale == tx.amount: return True return tx in HashMatcher({ diff --git a/yearn/treasury/accountant/ignore/general.py b/yearn/treasury/accountant/ignore/general.py index f4c7e744d..4812c9f8d 100644 --- a/yearn/treasury/accountant/ignore/general.py +++ b/yearn/treasury/accountant/ignore/general.py @@ -5,8 +5,8 @@ from brownie import ZERO_ADDRESS, chain from brownie.exceptions import RPCRequestError from pony.orm import commit, select +from y import Contract, ContractNotVerified, Network, get_price from y.networks import Network -from y.prices import magic from yearn.constants import ERC20_TRANSFER_EVENT_HASH, TREASURY_WALLETS from yearn.entities import TreasuryTx @@ -17,7 +17,6 @@ from yearn.treasury.accountant.classes import Filter, HashMatcher from yearn.treasury.accountant.constants import (DISPERSE_APP, PENDING_LABEL, treasury) -from yearn.utils import contract logger = logging.getLogger(__name__) @@ -48,7 +47,7 @@ def is_disperse_dot_app(tx: TreasuryTx) -> bool: sender, receiver, amount = decode_logs([transfer])["Transfer"][0].values() if sender == DISPERSE_APP and transfer.address == tx.token.address.address: amount /= Decimal(tx.token.scale) - price = Decimal(magic.get_price(transfer.address, block=tx.block)) + price = Decimal(get_price(transfer.address, block=tx.block)) TreasuryTx( chain = cache_chain(), timestamp = chain[tx.block].timestamp, @@ -75,7 +74,7 @@ def is_disperse_dot_app(tx: TreasuryTx) -> bool: for int_tx in chain.get_transaction(tx.hash).internal_transfers: if int_tx['from'] == tx.to_address.address: amount = int_tx['value'] / Decimal(tx.token.scale) - price = Decimal(magic.get_price(eee_address, tx.block)) + price = Decimal(get_price(eee_address, tx.block)) TreasuryTx( chain = cache_chain(), timestamp = chain[tx.block].timestamp, @@ -103,11 +102,9 @@ def is_gnosis_execution(tx: TreasuryTx) -> bool: and tx.to_address.address in treasury.addresses ): try: - con = contract(tx.to_address.address) - except ValueError as e: - if "contract source code not verified" in str(e).lower() or str(e).endswith('has not been verified'): - return False - raise + con = Contract(tx.to_address.address) + except ContractNotVerified: + return False if con._build['contractName'] != "GnosisSafeProxy": return False diff --git a/yearn/treasury/accountant/prepare_db.py b/yearn/treasury/accountant/prepare_db.py index 19544c60d..a76668932 100644 --- a/yearn/treasury/accountant/prepare_db.py +++ b/yearn/treasury/accountant/prepare_db.py @@ -9,7 +9,6 @@ from yearn.outputs.postgres.utils import cache_address from yearn.partners.partners import partners from yearn.treasury.accountant.constants import BRIDGE_ASSISTOOOR, DISPERSE_APP -from yearn.utils import contract @db_session diff --git a/yearn/treasury/streams.py b/yearn/treasury/streams.py index fdf30dcaa..b180ef467 100644 --- a/yearn/treasury/streams.py +++ b/yearn/treasury/streams.py @@ -3,17 +3,18 @@ from brownie import chain from pony.orm import db_session, select +from y import Contract + from yearn.constants import YCHAD_MULTISIG, YFI from yearn.entities import Stream, Token, TxGroup from yearn.events import decode_logs, get_logs_asap -from yearn.outputs.postgres.utils import cache_token +from yearn.outputs.postgres.utils import token_dbid from yearn.treasury.constants import BUYER -from yearn.utils import contract dai = "0x6B175474E89094C44Da98b954EedeAC495271d0F" -streams_dai = contract('0x60c7B0c5B3a4Dc8C690b074727a17fF7aA287Ff2') -streams_yfi = contract('0xf3764eC89B1ad20A31ed633b1466363FAc1741c4') +streams_dai = Contract('0x60c7B0c5B3a4Dc8C690b074727a17fF7aA287Ff2') +streams_yfi = Contract('0xf3764eC89B1ad20A31ed633b1466363FAc1741c4') class YearnStreams: def __init__(self): @@ -33,10 +34,8 @@ def streams_for_recipient(self, recipient: str, at_block: Optional[int] = None) return list(select(s for s in Stream if s.to_address.address == recipient)) return list(select(s for s in Stream if s.to_address.address == recipient and (s.end_block is None or at_block <= s.end_block))) - def streams_for_token(self, token: Token, include_inactive: bool = False) -> List[Stream]: - if not isinstance(token, Token): - token = cache_token(token) - streams = list(select(s for s in Stream if s.token == token)) + def streams_for_token(self, token: str, include_inactive: bool = False) -> List[Stream]: + streams = list(select(s for s in Stream if s.token.token_id == token_dbid(token))) if include_inactive is False: streams = [s for s in streams if s.is_alive] return streams diff --git a/yearn/v1/registry.py b/yearn/v1/registry.py index 01c8caac1..1f78232f5 100644 --- a/yearn/v1/registry.py +++ b/yearn/v1/registry.py @@ -5,14 +5,12 @@ from brownie import chain, interface import dank_mids -from y.contracts import contract_creation_block_async +from y import Contract, Network, contract_creation_block_async from y.decorators import stuck_coro_debugger -from y.networks import Network from yearn.exceptions import UnsupportedNetwork from yearn.multicall2 import fetch_multicall_async from yearn.typing import Block -from yearn.utils import contract from yearn.v1.vaults import VaultV1 logger = logging.getLogger(__name__) @@ -28,8 +26,8 @@ def __init__(self) -> None: @cached_property def vaults(self) -> List[VaultV1]: - addresses_provider = contract("0x9be19Ee7Bc4099D62737a7255f5c227fBcd6dB93") - addresses_generator_v1_vaults = contract(addresses_provider.addressById("ADDRESSES_GENERATOR_V1_VAULTS")) + addresses_provider = Contract("0x9be19Ee7Bc4099D62737a7255f5c227fBcd6dB93") + addresses_generator_v1_vaults = Contract(addresses_provider.addressById("ADDRESSES_GENERATOR_V1_VAULTS")) # NOTE: we assume no more v1 vaults are deployed return [VaultV1(vault_address, *self.registry.getVaultInfo(vault_address)) for vault_address in addresses_generator_v1_vaults.assetsAddresses()] diff --git a/yearn/v2/registry.py b/yearn/v2/registry.py index 2f3eb3941..375b55170 100644 --- a/yearn/v2/registry.py +++ b/yearn/v2/registry.py @@ -21,7 +21,7 @@ from yearn.decorators import set_exc, wait_or_exit_before from yearn.exceptions import UnsupportedNetwork from yearn.multicall2 import fetch_multicall_async -from yearn.utils import Singleton, contract +from yearn.utils import Singleton from yearn.v2.vaults import Vault logger = logging.getLogger(__name__) @@ -164,7 +164,7 @@ def process_events(self, events): self.governance = event["governance"] if event.name == "NewRelease": - self.releases[event["api_version"]] = contract(event["template"]) + self.releases[event["api_version"]] = Contract(event["template"]) if event.name == "NewVault": # experiment was endorsed @@ -296,7 +296,7 @@ def _process_event(self, event: _EventItem) -> _EventItem: self._registry.governance = event["governance"] if event.name == "NewRelease": - self._registry.releases[event["api_version"]] = contract(event["template"]) + self._registry.releases[event["api_version"]] = Contract(event["template"]) if event.name == "NewVault": # experiment was endorsed