mirror fixes
This commit is contained in:
@@ -13,7 +13,6 @@ polling = [seconds between price updates. If zero or negative, prices are update
|
||||
|
||||
|
||||
import asyncio
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
from datetime import timedelta
|
||||
@@ -59,6 +58,7 @@ async def get_token_info( token ):
|
||||
if token not in _token_infos:
|
||||
t = ERC20(token)
|
||||
name, symbol, decimals = await asyncio.gather(t.name(), t.symbol(), t.decimals())
|
||||
log.debug(f'original token: {name} {symbol} .{decimals} {token}')
|
||||
_token_infos[token] = [token, name, symbol, decimals]
|
||||
return _token_infos[token]
|
||||
|
||||
@@ -144,45 +144,39 @@ async def main():
|
||||
return
|
||||
mirrorenv = ContractProxy(mirror_addr, 'MirrorEnv')
|
||||
|
||||
pool_infos = await asyncio.gather(*[get_pool_info(pool) for pool in pools])
|
||||
pool_infos = [await get_pool_info(pool) for pool in pools]
|
||||
tokens = set(i[1] for i in pool_infos).union(i[2] for i in pool_infos)
|
||||
|
||||
log.debug(f'Mirroring tokens')
|
||||
token_infos = await asyncio.gather(*[get_token_info(t) for t in tokens], return_exceptions=True)
|
||||
for token, x in zip(tokens, token_infos):
|
||||
if isinstance(x, Exception):
|
||||
log.error(f'Failed to mirror token {token}: {x}')
|
||||
txs = []
|
||||
for t in tokens:
|
||||
info = await get_token_info(t)
|
||||
try:
|
||||
tx = await mirrorenv.transact.mirrorToken(info, gas=LOTSA_GAS)
|
||||
except Exception:
|
||||
log.exception(f'Failed to mirror token {t}')
|
||||
exit(1)
|
||||
txs = await asyncio.gather(*[mirrorenv.transact.mirrorToken(info, gas=LOTSA_GAS) for info in token_infos], return_exceptions=True)
|
||||
for token, x in zip(tokens, txs):
|
||||
if isinstance(x, Exception):
|
||||
log.error(f'Failed to mirror token {token}: {x}')
|
||||
exit(1)
|
||||
await asyncio.gather(*[tx.wait() for tx in txs])
|
||||
txs.append(tx.wait())
|
||||
await asyncio.gather(*txs)
|
||||
log.info('Tokens deployed')
|
||||
# for token in tokens:
|
||||
# # log.debug(f'Mirroring token {token}')
|
||||
# info = await get_token_info(token)
|
||||
# tx = await mirrorenv.transact.mirrorToken(info, gas=LOTSA_GAS)
|
||||
# await tx.wait()
|
||||
# log.debug(f'Mirrored token {token}')
|
||||
|
||||
log.debug(f'Mirroring pools {", ".join(pools)}')
|
||||
to_mirror = list(pool_infos)
|
||||
while to_mirror:
|
||||
results = await asyncio.gather(*[(await mirrorenv.transact.mirrorPool(info, gas=LOTSA_GAS)).wait()
|
||||
for info in to_mirror], return_exceptions=True)
|
||||
pool_exceptions = [(p,r) for p,r in zip(to_mirror,results) if isinstance(r,Exception)]
|
||||
for p,r in pool_exceptions:
|
||||
log.error(f'Error mirroring {p}: {r}')
|
||||
to_mirror = [p for p,r in pool_exceptions]
|
||||
if to_mirror:
|
||||
await asyncio.sleep(delay)
|
||||
txs = []
|
||||
for pool, info in zip(pools, pool_infos):
|
||||
try:
|
||||
tx = await mirrorenv.transact.mirrorPool(info, gas=LOTSA_GAS)
|
||||
except Exception:
|
||||
log.exception(f'Failed to mirror pool {pool}')
|
||||
exit(1)
|
||||
txs.append(tx.wait())
|
||||
await asyncio.gather(*txs)
|
||||
log.info('Pools deployed')
|
||||
|
||||
mirror_pools = []
|
||||
# log.debug(f'Getting pool info {" ".join(pools)}')
|
||||
for pool in pools:
|
||||
mirror_addr, mirror_inverted = await mirrorenv.pools(pool)
|
||||
if mirror_inverted == ADDRESS_0:
|
||||
if mirror_addr == ADDRESS_0:
|
||||
raise ValueError(f'Pool {pool} was not successfully mirrored')
|
||||
log.debug(f'\t{pool} => {mirror_addr} inverted={mirror_inverted}')
|
||||
mirror_pools.append((mirror_addr, mirror_inverted))
|
||||
@@ -191,7 +185,7 @@ async def main():
|
||||
if update_once:
|
||||
log.info(f'Updating pools once')
|
||||
else:
|
||||
log.info(f'Updating pools every {delay} seconds')
|
||||
log.info(f'Updating a pool every {delay} seconds')
|
||||
delay = timedelta(seconds=delay)
|
||||
to_update = pools
|
||||
pool_iter = iter(to_update)
|
||||
|
||||
Reference in New Issue
Block a user