Compare commits
2 Commits
af0f35eba5
...
646449e456
| Author | SHA1 | Date | |
|---|---|---|---|
| 646449e456 | |||
| 1bcf73de22 |
@@ -15,7 +15,7 @@ async def token_decimals(addr):
|
||||
try:
|
||||
decimals = await ERC20(addr).decimals()
|
||||
except CONTRACT_ERRORS:
|
||||
log.warning(f'token {addr} has no decimals()')
|
||||
log.debug(f'token {addr} has no decimals()')
|
||||
decimals = 0
|
||||
except Exception:
|
||||
log.debug(f'could not get token decimals for {addr}')
|
||||
|
||||
@@ -4,7 +4,7 @@ import logging
|
||||
from web3.types import EventData
|
||||
|
||||
from dexorder import db, metric, current_w3, timestamp
|
||||
from dexorder.accounting import accounting_fill, accounting_placement, accounting_lock
|
||||
from dexorder.accounting import accounting_fill, accounting_placement
|
||||
from dexorder.base.chain import current_chain
|
||||
from dexorder.base.order import TrancheKey, OrderKey
|
||||
from dexorder.base.orderlib import SwapOrderState
|
||||
|
||||
@@ -127,7 +127,7 @@ class Order:
|
||||
key = a if b is None else OrderKey(a, b)
|
||||
assert key not in Order.instances
|
||||
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.tranche_keys = [TrancheKey(key.vault, key.order_index, i) for i in range(len(self.status.trancheStatus))]
|
||||
# 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]
|
||||
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
|
||||
def state(self):
|
||||
return self.status.state
|
||||
|
||||
@@ -210,10 +210,10 @@ class Trigger:
|
||||
|
||||
|
||||
async def has_funds(tk: TrancheKey):
|
||||
log.debug(f'has funds? {tk.vault}')
|
||||
# log.debug(f'has funds? {tk.vault}')
|
||||
order = Order.of(tk)
|
||||
balances = vault_balances.get(tk.vault, {})
|
||||
log.debug(f'balances {balances}')
|
||||
# log.debug(f'balances {balances}')
|
||||
token_addr = order.status.order.tokenIn
|
||||
token_balance = balances.get(token_addr)
|
||||
log.debug(f'amount of {token_addr} = {token_balance}')
|
||||
@@ -256,6 +256,7 @@ class BalanceTrigger (Trigger):
|
||||
self.order = Order.of(self.tk)
|
||||
self.vault_token = self.tk.vault, self.order.status.order.tokenIn
|
||||
BalanceTrigger.by_vault_token[self.vault_token].add(self)
|
||||
self._value_changed()
|
||||
# log.debug(f'initializing Balance Trigger {id(self)} {tk} {value} {self.value}')
|
||||
|
||||
async def update(self, balance):
|
||||
@@ -268,6 +269,17 @@ class BalanceTrigger (Trigger):
|
||||
except (KeyError, ValueError):
|
||||
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):
|
||||
|
||||
|
||||
@@ -91,8 +91,9 @@ async def load_token(address: str) -> Optional[OldTokenDict]:
|
||||
try:
|
||||
decimals = await dec_prom
|
||||
except CONTRACT_ERRORS:
|
||||
log.warning(f'token {address} has no decimals()')
|
||||
log.info(f'token {address} has no decimals()')
|
||||
decimals = 0
|
||||
return None # we do not support coins that don't specify decimals.
|
||||
approved = False # never approve new coins
|
||||
chain_id = current_chain.get().id
|
||||
symbol = await symbol_prom
|
||||
|
||||
Reference in New Issue
Block a user