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

feat: quite a lot of stuff I've maintained for the past few months #715

Merged
merged 55 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
69eab43
chore: replace deprecated Logger.warn
BobTheBuidler Oct 8, 2024
b2602e2
feat: filter out lps with vaults
BobTheBuidler Oct 8, 2024
63887a0
feat: refactor to prep for bal apy previews
BobTheBuidler Oct 8, 2024
44e9f83
update make
0xBasically Oct 8, 2024
60988ef
feat: delay curve loading
BobTheBuidler Oct 8, 2024
7448733
chore: remove deprecated code
BobTheBuidler Oct 8, 2024
9e93063
chore: add comment
BobTheBuidler Oct 8, 2024
1fe6f0e
feat: async log loading
BobTheBuidler Oct 8, 2024
aa03fa7
feat: more stuff
BobTheBuidler Oct 8, 2024
589d446
feat: more stuff
BobTheBuidler Oct 8, 2024
d6c18c9
fix: load_strategies
BobTheBuidler Oct 8, 2024
8f8ae24
fix: Harvests
BobTheBuidler Oct 8, 2024
008913d
fix: registry loader time
BobTheBuidler Oct 8, 2024
5392357
str not encodable
BobTheBuidler Oct 8, 2024
bac8316
feat: support rkp3r in ypm
BobTheBuidler Oct 8, 2024
e19b386
fix: vault loader
BobTheBuidler Oct 8, 2024
8bee62e
chore: cleanup treasury-txs logs
BobTheBuidler Oct 8, 2024
fb5fb53
chore: contract -> Contract
BobTheBuidler Oct 8, 2024
c18f5fa
chore: cleanup
BobTheBuidler Oct 8, 2024
66f87f5
chore: add comment
BobTheBuidler Oct 8, 2024
3ee9aa3
feat: asyncify curve simple
BobTheBuidler Oct 8, 2024
3867862
chore: remove unneeded code
BobTheBuidler Oct 8, 2024
08eaa3a
fix: treasury txs TypeErr
BobTheBuidler Oct 8, 2024
1c60a6f
fix: from_address is None
BobTheBuidler Oct 8, 2024
090fa54
fix: SyntaxError
BobTheBuidler Oct 8, 2024
f6a19f1
fix(temp): logs for treasury-tx
BobTheBuidler Oct 8, 2024
d822ac2
chore: refactor with new dep members
BobTheBuidler Oct 8, 2024
a9b10dd
chore: replace contract with Contract
BobTheBuidler Oct 8, 2024
2a901c0
feat: optimize db entity handling
BobTheBuidler Oct 8, 2024
e22c38e
feat: load streams with treasry txs exporter
BobTheBuidler Oct 8, 2024
0a04813
fix: asyncify yeth
BobTheBuidler Oct 8, 2024
de1bb0a
feat: make build --no-cache
BobTheBuidler Oct 8, 2024
fbe8fe9
feat: processing queue
BobTheBuidler Oct 8, 2024
b35b609
fix: adapt to ypm 3.6
BobTheBuidler Oct 8, 2024
9a7d3b0
feat: make way less eth_getLogs calls
BobTheBuidler Oct 8, 2024
32354d1
feat: disable sms exporter on base
BobTheBuidler Oct 8, 2024
0117236
chore: replace deprecated dank_w3
BobTheBuidler Oct 8, 2024
885ae0a
fix: treasury and sms on non-mainnet
BobTheBuidler Oct 8, 2024
0363c0e
feat: use Queue, save ram
BobTheBuidler Oct 8, 2024
ca902c5
feat: sort txs
BobTheBuidler Oct 8, 2024
84774db
fix: hanging sorter
BobTheBuidler Oct 8, 2024
b752259
feat: brownie 1.20.3 disables eager caching
BobTheBuidler Oct 8, 2024
1627d97
feat: faster eth-abi
BobTheBuidler Oct 8, 2024
c8aec10
feat: faster builds with poetry
BobTheBuidler Nov 9, 2024
db9cff1
chore: add shitcoins to shitcoins
BobTheBuidler Nov 9, 2024
0c73a52
feat: sort txs
BobTheBuidler Nov 9, 2024
29c3c52
chore: bump eth-portfolio and ypricemagic
BobTheBuidler Nov 9, 2024
5f53f2f
feat: a bunch of old stuff
BobTheBuidler Nov 9, 2024
716ab75
chore: remove unused imports
BobTheBuidler Nov 9, 2024
49992cf
chore: refactor accountant
BobTheBuidler Nov 9, 2024
b3a4f1c
chore: bump deps
BobTheBuidler Nov 9, 2024
2cf031b
feat: optimize streams with caches
BobTheBuidler Nov 9, 2024
95f6f3b
chore: add detail to exc
BobTheBuidler Nov 9, 2024
df2aa4a
chore: rename constant
BobTheBuidler Nov 9, 2024
661963a
chore: bump brownie to 1.20
BobTheBuidler Nov 9, 2024
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
Prev Previous commit
Next Next commit
fix: load_strategies
  • Loading branch information
BobTheBuidler committed Oct 8, 2024
commit d6c18c9741d9536b5988e6bcf592cf3361d189e6
2 changes: 0 additions & 2 deletions yearn/v2/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,9 @@ def _task(self) -> asyncio.Task:
return asyncio.create_task(self.watch_events())

def _filter_vaults(self):
#logger.debug('filtering vaults')
if chain.id in DEPRECATED_VAULTS:
for vault in DEPRECATED_VAULTS[chain.id]:
self._remove_vault(vault)
#logger.debug('vaults filtered')

def _remove_vault(self, address):
self._vaults.pop(address, None)
Expand Down
91 changes: 44 additions & 47 deletions yearn/v2/vaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import logging
import re
import time
from contextlib import suppress
from functools import cached_property
from typing import (TYPE_CHECKING, Any, AsyncIterator, Dict, List, NoReturn,
Optional, Union)

import a_sync
from a_sync.utils.iterators import exhaust_iterator
from async_property import async_cached_property, async_property
from brownie import chain
from brownie.network.event import _EventItem
Expand All @@ -23,7 +24,6 @@
from y.utils.events import ProcessedEvents

from yearn.common import Tvl
from yearn.decorators import set_exc
from yearn.multicall2 import fetch_multicall_async
from yearn.special import Ygov
from yearn.typing import Address
Expand Down Expand Up @@ -124,13 +124,12 @@ def __init__(self, vault: Contract, api_version=None, token=None, registry=None)

# load strategies from events and watch for freshly attached strategies
self._events = VaultEvents(self)
self._done = a_sync.Event(name=f"{self.__module__}.{self.__class__.__name__}._done")
self._task = None

def __repr__(self):
strategies = "..." # don't block if we don't have the strategies loaded
if self._done.is_set():
strategies = ", ".join(f"{strategy}" for strategy in self._strategies)
with suppress(RuntimeError): # NOTE on RuntimeError, event loop isnt running and task doesn't exist. can't be created, is not complete. no need to check strats.
if self._task.done():
strategies = ", ".join(f"{strategy}" for strategy in self._strategies)
return f'<Vault {self.vault} name="{self.name}" token={self.token} strategies=[{strategies}]>'

def __hash__(self) -> int:
Expand Down Expand Up @@ -215,21 +214,16 @@ async def is_active(self, block: Optional[int]) -> bool:

@stuck_coro_debugger
async def load_strategies(self):
self._task
await self._done.wait()
if self._task.done() and (e := self._task.exception()):
raise e
await self._task

@set_exc
async def watch_events(self) -> NoReturn:
start = time.time()
height = await dank_w3.eth.block_number
done_task = asyncio.create_task(self._events._lock.wait_for(height))
def done_callback(task: asyncio.Task) -> None:
logger.info("loaded %d strategies %s in %.3fs", len(self._strategies), self.name, time.time() - start)
self._done.set()
done_task.add_done_callback(done_callback)
self._events._ensure_task()
async for event in self._events.events(await dank_w3.eth.block_number):
# we iterate thru the list to ensure they're loaded thru now
pass
logger.info("loaded %d strategies %s in %.3fs", len(self._strategies), self.name, time.time() - start)
# Keep the loader running in the background
self._daemon = asyncio.create_task(exhaust_iterator(self._events))

@stuck_coro_debugger
async def describe(self, block=None):
Expand Down Expand Up @@ -313,40 +307,43 @@ async def _unpack_results(self, results):
)


class VaultEvents(ProcessedEvents[int]):
class VaultEvents(ProcessedEvents[_EventItem]):
__slots__ = "vault",
def __init__(self, vault: Vault, **kwargs: Any):
topics = [[encode_hex(event_abi_to_log_topic(event)) for event in vault.vault.abi if event["type"] == "event" and event["name"] in STRATEGY_EVENTS]]
super().__init__(addresses=[str(vault.vault)], topics=topics, **kwargs)
self.vault = vault
def _process_event(self, event: _EventItem) -> _EventItem:
# some issues during the migration of this strat prevented it from being verified so we skip it here...
if chain.id == Network.Optimism:
failed_migration = False
for key in ["newVersion", "oldVersion", "strategy"]:
failed_migration |= (key in event and event[key] == "0x4286a40EB3092b0149ec729dc32AD01942E13C63")
if failed_migration:
return event
try:
if chain.id == Network.Optimism:
failed_migration = False
for key in ["newVersion", "oldVersion", "strategy"]:
failed_migration |= (key in event and event[key] == "0x4286a40EB3092b0149ec729dc32AD01942E13C63")
if failed_migration:
return event

if event.name == "StrategyAdded":
strategy_address = event["strategy"]
logger.debug("%s strategy added %s", self.vault.name, strategy_address)
try:
self.vault._strategies[strategy_address] = Strategy(strategy_address, self.vault)
except ValueError:
logger.error(f"Error loading strategy {strategy_address}")
pass
elif event.name == "StrategyRevoked":
logger.debug("%s strategy revoked %s", self.vault.name, event["strategy"])
self.vault._revoked[event["strategy"]] = self.vault._strategies.pop(
event["strategy"], Strategy(event["strategy"], self.vault)
)
elif event.name == "StrategyMigrated":
logger.debug("%s strategy migrated %s -> %s", self.vault.name, event["oldVersion"], event["newVersion"])
self.vault._revoked[event["oldVersion"]] = self.vault._strategies.pop(
event["oldVersion"], Strategy(event["oldVersion"], self.vault)
)
self.vault._strategies[event["newVersion"]] = Strategy(event["newVersion"], self.vault)
elif event.name == "StrategyReported":
self.vault._reports.append(event)
return event
if event.name == "StrategyAdded":
strategy_address = event["strategy"]
logger.debug("%s strategy added %s", self.vault.name, strategy_address)
try:
self.vault._strategies[strategy_address] = Strategy(strategy_address, self.vault)
except ValueError:
logger.error(f"Error loading strategy {strategy_address}")
elif event.name == "StrategyRevoked":
logger.debug("%s strategy revoked %s", self.vault.name, event["strategy"])
self.vault._revoked[event["strategy"]] = self.vault._strategies.pop(
event["strategy"], Strategy(event["strategy"], self.vault)
)
elif event.name == "StrategyMigrated":
logger.debug("%s strategy migrated %s -> %s", self.vault.name, event["oldVersion"], event["newVersion"])
self.vault._revoked[event["oldVersion"]] = self.vault._strategies.pop(
event["oldVersion"], Strategy(event["oldVersion"], self.vault)
)
self.vault._strategies[event["newVersion"]] = Strategy(event["newVersion"], self.vault)
elif event.name == "StrategyReported":
self.vault._reports.append(event)
return event
except Exception as e:
logger.exception(e)
raise e