underfunded state

This commit is contained in:
tim
2025-03-03 21:43:17 -04:00
parent 1bcf73de22
commit 646449e456
4 changed files with 26 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ async def token_decimals(addr):
try: try:
decimals = await ERC20(addr).decimals() decimals = await ERC20(addr).decimals()
except CONTRACT_ERRORS: except CONTRACT_ERRORS:
log.warning(f'token {addr} has no decimals()') log.debug(f'token {addr} has no decimals()')
decimals = 0 decimals = 0
except Exception: except Exception:
log.debug(f'could not get token decimals for {addr}') log.debug(f'could not get token decimals for {addr}')

View File

@@ -127,7 +127,7 @@ class Order:
key = a if b is None else OrderKey(a, b) key = a if b is None else OrderKey(a, b)
assert key not in Order.instances assert key not in Order.instances
self.key = key self.key = key
self.status: ElaboratedSwapOrderStatus = Order.order_statuses[key].copy() self._status: ElaboratedSwapOrderStatus = Order.order_statuses[key].copy()
self.pool_address: str = pool_address(self.status.order) self.pool_address: str = pool_address(self.status.order)
self.tranche_keys = [TrancheKey(key.vault, key.order_index, i) for i in range(len(self.status.trancheStatus))] self.tranche_keys = [TrancheKey(key.vault, key.order_index, i) for i in range(len(self.status.trancheStatus))]
# flattenings of various static data # flattenings of various static data
@@ -138,6 +138,14 @@ class Order:
self.tranche_amounts = [t.fraction_of(self.amount) for t in self.order.tranches] self.tranche_amounts = [t.fraction_of(self.amount) for t in self.order.tranches]
Order.instances[self.key] = self Order.instances[self.key] = self
@property
def status(self):
return self._status
@status.setter
def status(self, v):
self._status = Order.order_statuses[self.key] = v
@property @property
def state(self): def state(self):
return self.status.state return self.status.state

View File

@@ -210,10 +210,10 @@ class Trigger:
async def has_funds(tk: TrancheKey): async def has_funds(tk: TrancheKey):
log.debug(f'has funds? {tk.vault}') # log.debug(f'has funds? {tk.vault}')
order = Order.of(tk) order = Order.of(tk)
balances = vault_balances.get(tk.vault, {}) balances = vault_balances.get(tk.vault, {})
log.debug(f'balances {balances}') # log.debug(f'balances {balances}')
token_addr = order.status.order.tokenIn token_addr = order.status.order.tokenIn
token_balance = balances.get(token_addr) token_balance = balances.get(token_addr)
log.debug(f'amount of {token_addr} = {token_balance}') log.debug(f'amount of {token_addr} = {token_balance}')
@@ -256,6 +256,7 @@ class BalanceTrigger (Trigger):
self.order = Order.of(self.tk) self.order = Order.of(self.tk)
self.vault_token = self.tk.vault, self.order.status.order.tokenIn self.vault_token = self.tk.vault, self.order.status.order.tokenIn
BalanceTrigger.by_vault_token[self.vault_token].add(self) BalanceTrigger.by_vault_token[self.vault_token].add(self)
self._value_changed()
# log.debug(f'initializing Balance Trigger {id(self)} {tk} {value} {self.value}') # log.debug(f'initializing Balance Trigger {id(self)} {tk} {value} {self.value}')
async def update(self, balance): async def update(self, balance):
@@ -268,6 +269,17 @@ class BalanceTrigger (Trigger):
except (KeyError, ValueError): except (KeyError, ValueError):
pass pass
def _value_changed(self):
ok = self.value
order = Order.of(self.tk)
old_state = order.status.state
if not ok and old_state == SwapOrderState.Open:
order.status = order.status.copy()
order.status.state = SwapOrderState.Underfunded
elif ok and old_state == SwapOrderState.Underfunded:
order.status = order.status.copy()
order.status.state = SwapOrderState.Open
class TimeTrigger (Trigger): class TimeTrigger (Trigger):

View File

@@ -91,8 +91,9 @@ async def load_token(address: str) -> Optional[OldTokenDict]:
try: try:
decimals = await dec_prom decimals = await dec_prom
except CONTRACT_ERRORS: except CONTRACT_ERRORS:
log.warning(f'token {address} has no decimals()') log.info(f'token {address} has no decimals()')
decimals = 0 decimals = 0
return None # we do not support coins that don't specify decimals.
approved = False # never approve new coins approved = False # never approve new coins
chain_id = current_chain.get().id chain_id = current_chain.get().id
symbol = await symbol_prom symbol = await symbol_prom