PriceTrigger bugfix

This commit is contained in:
tim
2024-08-26 17:28:21 -04:00
parent cd42c5c645
commit a39eb4021f

View File

@@ -104,8 +104,8 @@ async def update_balance_triggers(vault: str, token: str, balance: int):
async def update_price_triggers(pool: OldPoolDict, price: dec): async def update_price_triggers(pool: OldPoolDict, price: dec):
price = price * dec(10) ** dec(-pool['decimals']) # adjust for pool decimals to get onchain price price = price * dec(10) ** dec(-pool['decimals']) # adjust for pool decimals to get onchain price
price = float(price) # since we use SIMD operations to evaluate lines, we must convert to float price = float(price) # since we use SIMD operations to evaluate lines, we must convert to float
updates = [pt.update(price) for pt in PriceLineTrigger.by_pool.get(pool['address'], [])] for pt in PriceLineTrigger.by_pool.get(pool['address'], []):
await asyncio.gather(*updates) pt.update(price)
inflight_execution_requests: set[TrancheKey] = set() inflight_execution_requests: set[TrancheKey] = set()
@@ -162,10 +162,11 @@ class Trigger:
def value(self, value): def value(self, value):
if value != self.value: if value != self.value:
_dirty.add(self.tk) _dirty.add(self.tk)
old = _trigger_state.get(self.tk,0)
if not value: # this conditional is inverted if not value: # this conditional is inverted
_trigger_state[self.tk] |= 1 << self.position # set _trigger_state[self.tk] = old | (1 << self.position) # set
else: else:
_trigger_state[self.tk] &= ~(1 << self.position) # clear _trigger_state[self.tk] = old & ~(1 << self.position) # clear
@abstractmethod @abstractmethod
def remove(self): ... def remove(self): ...
@@ -350,7 +351,10 @@ class PriceLineTrigger (Trigger):
self.value = value self.value = value
def remove(self): def remove(self):
try:
PriceLineTrigger.by_pool[self.pool_address].remove(self) PriceLineTrigger.by_pool[self.pool_address].remove(self)
except KeyError:
pass
async def activate_orders(): async def activate_orders():