session.autoflush=False; metadata.x.mock=True

This commit is contained in:
Tim
2024-03-25 21:02:55 -04:00
parent abf64151ab
commit 4264997bdb
5 changed files with 26 additions and 10 deletions

View File

@@ -82,6 +82,8 @@ async def write_metadata( pools, mirror_pools ):
tokens = set(p['base'] for p in pool_dicts)
tokens.update(p['quote'] for p in pool_dicts)
tokens = await asyncio.gather(*[get_token(t) for t in tokens])
for token in tokens:
token['x'] = {'mock':True}
with open(filename, 'w') as f:
generate_metadata(tokens, pool_dicts, f)
log.info(f'wrote {filename}')

View File

@@ -74,7 +74,7 @@ class Db:
engine = _engine.get()
if engine is None:
raise RuntimeError('Cannot create session: no database engine set. Use dexorder.db.connect() first')
s = Session(engine, expire_on_commit=False)
s = Session(engine, expire_on_commit=False, autoflush=False, autocommit=False)
_session.set(s)
return s

View File

@@ -61,11 +61,13 @@ async def handle_order_placed(event: EventData):
return
vault = VaultContract(addr)
for index in range(start_index, start_index+num_orders):
obj = await vault.swapOrderStatus(index)
log.debug(f'raw order status {obj}')
order = Order.create(vault.address, index, obj)
await activate_order(order)
log.debug(f'new order {order} {order.order}')
key = OrderKey(vault.address, index)
if key not in Order.instances:
obj = await vault.swapOrderStatus(index)
log.debug(f'raw order status {obj}')
order = Order.create(vault.address, index, obj)
await activate_order(order)
log.debug(f'new order {order} {order.order}')
def handle_swap_filled(event: EventData):
@@ -231,9 +233,13 @@ def process_active_tranches():
def has_funds(tk: TrancheKey):
log.debug(f'has funds? {tk.vault}')
order = Order.of(tk)
minimum = order.status.order.minFillAmount if order.amount_is_input else 0
return vault_balances.get(tk.vault,{}).get(order.status.order.tokenIn, 0) > minimum
balances = vault_balances.get(tk.vault, {})
token_balance = balances.get(order.status.order.tokenIn, 0)
log.debug(f'minimum {minimum} balances {balances}')
return token_balance > minimum
async def process_execution_requests():

View File

@@ -60,14 +60,20 @@ def dump_tokens(out, tokens):
n = token.name,
s = token.symbol,
d = token.decimals,
x = None
else:
token: TokenDict
a = token['address']
n = token['name']
s = token['symbol']
d = token['decimals']
# noinspection PyTypedDict
x = None if 'x' not in token else token['x']
token_map[a] = token
json_dump(out, a=a, n=n, s=s, d=d)
data = dict(a=a, n=n, s=s, d=d)
if x is not None:
data['x'] = x
json_dump(out, **data)
def dump_pools(out, pools):
@@ -98,7 +104,7 @@ def dump_pools(out, pools):
data = dict(a=a, b=b, q=q, f=f, e=e, d=d)
if x is not None:
data['x'] = x
json_dump(out,**data)
json_dump(out, **data)
generating_metadata = False

View File

@@ -76,8 +76,10 @@ class Order:
@staticmethod
def create(vault: str, order_index: int, obj):
""" use when a brand new order is detected by the system """
status = SwapOrderStatus.load_from_chain(obj)
key = OrderKey(vault, order_index)
if key in Order.instances:
raise ValueError
status = SwapOrderStatus.load_from_chain(obj)
Order.order_statuses[key] = status.copy() # always copy the struct when setting. values in BlockData must be immutable
order = Order(key)
if order.is_open: