Skip to content

Commit

Permalink
feat: more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler committed Oct 10, 2023
1 parent 8d5174c commit dc3405e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 28 deletions.
13 changes: 3 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,9 @@ pytest-bdd>=5.0.0
dank_mids>=4.20.63
eth_retry>=0.1.18
eth-hash[pysha3]
#ez-a-sync==0.9.3
#ypricemagic==2.14.1
ez-a-sync==0.11.1
ypricemagic==2.14.6
python-telegram-bot==13.15
# GOOD #git+https://www.github.com/BobTheBuidler/eth-portfolio@5a4522a9809322c13d6398344f12ef2c9bb31027
git+https://www.github.com/BobTheBuidler/toolcache@e37b53cec64556d2b35df66767fca4c8f366a2fa
#GOOD #git+https://www.github.com/BobTheBuidler/ypricemagic@decafbb237310fc9b6d5bceb7ab6379ac2406b8a

#ez-a-sync==0.10.1
git+https://www.github.com/BobTheBuidler/ez-a-sync@0c05482020651af07ff4258511ea0a5592768c61

git+https://www.github.com/BobTheBuidler/ypricemagic@d4479e7a6e375f6a1774937e9867ef68215d2962
git+https://www.github.com/BobTheBuidler/eth-portfolio@6fcdd6cea1511370134b552dad988ce320469812
git+https://www.github.com/BobTheBuidler/eth-portfolio@2d95efc14b3301befcdcbc6187143a621e989fbd
memray
2 changes: 1 addition & 1 deletion scripts/exporters/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

warnings.simplefilter("ignore", BrownieEnvironmentWarning)

yearn = Yearn(load_strategies=False)
yearn = Yearn()

logger = logging.getLogger('yearn.transactions_exporter')

Expand Down
14 changes: 14 additions & 0 deletions services/dashboard/docker-compose.infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,17 @@ services:
volumes:
- postgres_data:/var/lib/postgresql/data
restart: always
ypostgres:
image: postgres:14
command: -c 'max_connections=${PGCONNECTIONS:-5000}'
ports:
- 5420:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=yearn-exporter
- POSTGRES_DB=postgres
networks:
- stack
volumes:
- ypostgres_data:/var/lib/postgresql/data
restart: always
8 changes: 4 additions & 4 deletions yearn/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def wait_or_exit_before(func):
@functools.wraps(func)
async def wrap(self):
task: asyncio.Task = self._task
logger.info("waiting for %s", self)
logger.debug("waiting for %s", self)
while not self._done.is_set() and not task.done():
await asyncio.sleep(10)
logger.info("%s not done", self)
logger.info("loading %s complete", self)
logger.debug("%s not done", self)
logger.debug("loading %s complete", self)
if task.done() and (e := task.exception()):
logger.info('task %s has exception %s, awaiting', task, e)
logger.debug('task %s has exception %s, awaiting', task, e)
raise e
return await func(self)
return wrap
Expand Down
2 changes: 1 addition & 1 deletion yearn/treasury/accountant/ignore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from decimal import Decimal

from brownie import chain
from y.networks import Network
from y import Network

from yearn.entities import TreasuryTx
from yearn.treasury.accountant.classes import HashMatcher, TopLevelTxGroup
Expand Down
6 changes: 3 additions & 3 deletions yearn/treasury/accountant/ignore/vaults.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

from brownie import ZERO_ADDRESS, chain
from y.networks import Network

from yearn.entities import TreasuryTx
from yearn.treasury.accountant.revenue.fees import v2_vaults
from yearn.treasury.accountant.classes import Filter, HashMatcher, IterFilter
from yearn.treasury.accountant.constants import treasury, v1, v2
from yearn.treasury.accountant.constants import treasury, v1
from yearn.utils import contract

vaults = (v1.vaults + v2.vaults) if v1 else v2.vaults
vaults = (v1.vaults + v2_vaults) if v1 else v2_vaults

def is_vault_deposit(tx: TreasuryTx) -> bool:
""" This code doesn't validate amounts but so far that's not been a problem. """
Expand Down
23 changes: 16 additions & 7 deletions yearn/v2/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,23 @@ async def _active_vaults_at(self, block=None) -> List[Vault]:
return [vault for vault, active in zip(vaults, await asyncio.gather(*[vault.is_active(block) for vault in vaults])) if active]

async def _active_vaults_at_iter(self, block=None) -> AsyncIterator[Vault]:
# ensure loader task is running
self._task
events = await self._events
# make sure the events are loaded thru now before proceeding
await events._lock.wait_for(events._init_block)
vaults = list(itertools.chain(self._vaults.values(), self._experiments.values()))
async def is_active(vault: Vault) -> bool:
return vault, await vault.is_active(block)
for fut in asyncio.as_completed([is_active(vault) for vault in vaults]):
vault, active = await fut

vaults: List[Vault] = list(itertools.chain(self._vaults.values(), self._experiments.values()))

i = 0 # TODO figure out why we need this here
while len(vaults) == 0:
await asyncio.sleep(6)
vaults = list(itertools.chain(self._vaults.values(), self._experiments.values()))
i += 1
if i >= 20:
logger.error("we're stuck")

async for vault, active in a_sync.as_completed({vault: vault.is_active(block) for vault in vaults}, aiter=True):
if active:
yield vault

Expand All @@ -206,11 +215,11 @@ def _task(self) -> asyncio.Task:
return asyncio.create_task(self.watch_events())

def _filter_vaults(self):
logger.debug('filtering vaults')
#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')
#logger.debug('vaults filtered')

def _remove_vault(self, address):
self._vaults.pop(address, None)
Expand Down
8 changes: 6 additions & 2 deletions yearn/v2/vaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def __repr__(self):
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:
return hash(self.vault.address)

def __eq__(self, other):
if isinstance(other, Vault):
return self.vault == other.vault
Expand Down Expand Up @@ -205,10 +208,10 @@ async def is_experiment(self):

@stuck_coro_debugger
async def is_active(self, block: Optional[int]) -> bool:
if block and await contract_creation_block_async(str(self.vault)) < block:
if block and await contract_creation_block_async(str(self.vault)) > block:
return False
# fixes edge case: a vault is not necessarily initialized on creation
return self.vault.activation.coroutine(block_identifier=block)
return await self.vault.activation.coroutine(block_identifier=block)

@stuck_coro_debugger
async def load_strategies(self):
Expand Down Expand Up @@ -294,6 +297,7 @@ async def _describe_strategies(self, block: int) -> List[dict]:

@stuck_coro_debugger
async def _unpack_results(self, results):
# TODO: get rid of this
results, strategy_descs, price = results
return await run_in_subprocess(
_unpack_results,
Expand Down

0 comments on commit dc3405e

Please sign in to comment.