beta announcement

This commit is contained in:
tim
2024-10-30 13:55:25 -04:00
parent b133999314
commit 3b2c58671b
2 changed files with 27 additions and 5 deletions

View File

@@ -154,6 +154,8 @@ def execute_tranches():
for tk, proof in active_tranches.items():
if tk not in inflight_execution_requests:
new_execution_requests.append((tk, proof))
else:
log.debug(f'execute {tk} already in flight')
# todo order requests and batch
for tk, proof in new_execution_requests:
create_execution_request(tk, proof)

View File

@@ -125,8 +125,11 @@ async def end_trigger_updates():
if _trigger_state.get(tk,0) == 0:
# all clear for execution. add to active list with any necessary proofs
active_tranches[tk] = PriceProof(0)
log.debug(f'active tranche {tk}')
else:
# blocked by one or more triggers being False (nonzero mask)
reason = ', '.join(t.name for t in TrancheTrigger.all[tk].blocking_triggers)
log.debug(f'tranche {tk} blocked by {reason}')
# check expiry constraint
try:
TrancheTrigger.all[tk].check_expire()
@@ -164,11 +167,20 @@ _dirty:set[TrancheKey] = set()
class Trigger:
def __init__(self, position: int, tk: TrancheKey, value: bool):
class TriggerType (Enum):
Balance = 0
Activation = 1
Expiration = 2
MinLine = 3
MaxLine = 4
def __init__(self, trigger_type: TriggerType, tk: TrancheKey, value: bool):
"""
position is the bit position of the boolean result in the tranche's constraint bitfield.
"""
self.position = position
self.position = trigger_type.value
self.name = trigger_type.name
self.tk = tk
self.value = value
_dirty.add(self.tk)
@@ -243,7 +255,7 @@ class BalanceTrigger (Trigger):
return BalanceTrigger(tk, value)
def __init__(self, tk: TrancheKey, value: bool):
super().__init__(0, tk, value)
super().__init__(Trigger.TriggerType.Balance, tk, value)
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)
@@ -273,7 +285,7 @@ class TimeTrigger (Trigger):
return TimeTrigger(is_start, tk, time, time_now)
def __init__(self, is_start: bool, tk: TrancheKey, time: int, time_now: int):
trigger_type = 1 if is_start else 2
trigger_type = Trigger.TriggerType.Activation if is_start else Trigger.TriggerType.Expiration
in_future = time_now >= time
value = in_future is is_start
self.is_start = is_start
@@ -369,7 +381,8 @@ class PriceLineTrigger (Trigger):
price_now = 1/price_now
activated = value_now < price_now if is_min else value_now > price_now
log.debug(f'initial price line {value_now} {"<" if is_min else ">"} {price_now} {activated}')
super().__init__(3 if is_min else 4, tk, activated)
trigger_type = Trigger.TriggerType.MinLine if is_min else Trigger.TriggerType.MaxLine
super().__init__(trigger_type, tk, activated)
self.inverted = inverted
self.line = line
self.is_min = is_min
@@ -557,6 +570,13 @@ class TrancheTrigger:
return OrderTriggers.instances[self.tk.order_key]
@property
def blocking_triggers(self):
triggers = [self.balance_trigger, self.activation_trigger, self.expiration_trigger,
self.min_trigger, self.max_trigger]
return [t for t in triggers if t is not None and not t.value]
def fill(self, _amount_in, _amount_out, _next_activation_time ):
if _next_activation_time != DISTANT_PAST:
# rate limit