backend checks for tranche funds

This commit is contained in:
Tim
2024-03-24 20:52:43 -04:00
parent 1d8147e14f
commit b2ea1d17c1
3 changed files with 16 additions and 11 deletions

View File

@@ -1,5 +1,4 @@
import logging
import sys
from asyncio import CancelledError
from dexorder import db, blockchain, config
@@ -7,7 +6,6 @@ from dexorder.base.chain import current_chain
from dexorder.bin.executable import execute
from dexorder.blockstate.blockdata import BlockData
from dexorder.blockstate.db_state import DbState
from dexorder.configuration import parse_args
from dexorder.contract import get_contract_event
from dexorder.contract.dexorder import get_factory_contract, get_dexorder_contract
from dexorder.event_handler import init_order_triggers, init, dump_log, handle_vault_created, handle_order_placed, \

View File

@@ -224,8 +224,16 @@ def process_active_tranches():
old_req = execution_requests.get(tk)
height = current_block.get().height
if old_req is None or old_req.height <= height: # '<=' is used so proof is updated with more recent values
log.info(f'execution request for {tk}')
execution_requests[tk] = ExecutionRequest(height, proof)
if has_funds(tk):
log.info(f'execution request for {tk}')
execution_requests[tk] = ExecutionRequest(height, proof)
else: log.debug(f'underfunded tranche {tk}')
def has_funds(tk: TrancheKey):
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
async def process_execution_requests():

View File

@@ -6,13 +6,12 @@ from typing import overload
from dexorder import DELETE, db
from dexorder.base.chain import current_chain
from dexorder.base.order import OrderKey, TrancheKey
from dexorder.blockstate import BlockDict, BlockSet
from dexorder.vault_blockdata import vault_owners
from dexorder.database.model.orderindex import OrderIndex
from dexorder.base.orderlib import SwapOrderStatus, SwapOrderState
from dexorder.blockstate import BlockDict, BlockSet
from dexorder.database.model.orderindex import OrderIndex
from dexorder.routing import pool_address
from dexorder.util import json
from dexorder.vault_blockdata import vault_owners
log = logging.getLogger(__name__)
@@ -59,15 +58,15 @@ class Order:
@staticmethod
@overload
def of(key: OrderKey):...
def of(key: OrderKey) -> 'Order':...
@staticmethod
@overload
def of(vault: str, order_index: int):...
def of(vault: str, order_index: int) -> 'Order':...
@staticmethod
def of(a, b=None) -> 'Order':
key = a if b is None else OrderKey(a, b)
key = (OrderKey(a.vault, a.order_index) if type(a) is TrancheKey else a) if b is None else OrderKey(a, b)
try:
return Order.instances[key]
except KeyError: