SwapOrder.inverted
This commit is contained in:
@@ -84,6 +84,7 @@ class SwapOrder:
|
||||
minFillAmount: int
|
||||
amountIsInput: bool
|
||||
outputDirectlyToOwner: bool
|
||||
inverted: bool
|
||||
conditionalOrder: int
|
||||
tranches: list['Tranche']
|
||||
|
||||
@@ -93,17 +94,19 @@ class SwapOrder:
|
||||
|
||||
@staticmethod
|
||||
def load(obj):
|
||||
return SwapOrder(obj[0], obj[1], Route.load(obj[2]), int(obj[3]), int(obj[4]), obj[5], obj[6], obj[7],
|
||||
[Tranche.load(t) for t in obj[8]])
|
||||
return SwapOrder(obj[0], obj[1], Route.load(obj[2]), int(obj[3]), int(obj[4]), obj[5], obj[6], obj[7], obj[8],
|
||||
[Tranche.load(t) for t in obj[9]])
|
||||
|
||||
@staticmethod
|
||||
def load_from_chain(obj):
|
||||
return SwapOrder(obj[0], obj[1], Route.load(obj[2]), int(obj[3]), int(obj[4]), obj[5], obj[6], obj[7],
|
||||
[Tranche.load_from_chain(t) for t in obj[8]])
|
||||
return SwapOrder(obj[0], obj[1], Route.load(obj[2]), int(obj[3]), int(obj[4]), obj[5], obj[6], obj[7], obj[8],
|
||||
[Tranche.load_from_chain(t) for t in obj[9]])
|
||||
|
||||
def dump(self):
|
||||
return (self.tokenIn, self.tokenOut, self.route.dump(), str(self.amount), str(self.minFillAmount), self.amountIsInput,
|
||||
self.outputDirectlyToOwner, self.conditionalOrder, [t.dump() for t in self.tranches])
|
||||
return (self.tokenIn, self.tokenOut, self.route.dump(),
|
||||
str(self.amount), str(self.minFillAmount), self.amountIsInput,
|
||||
self.outputDirectlyToOwner, self.inverted, self.conditionalOrder,
|
||||
[t.dump() for t in self.tranches])
|
||||
|
||||
def __str__(self):
|
||||
msg = f'''
|
||||
@@ -113,6 +116,7 @@ SwapOrder
|
||||
exchange: {self.route.exchange.name, self.route.fee}
|
||||
amount: {"input" if self.amountIsInput else "output"} {self.amount}{" to owner" if self.outputDirectlyToOwner else ""}
|
||||
minFill: {self.minFillAmount}
|
||||
inverted: {self.inverted}
|
||||
tranches:
|
||||
'''
|
||||
for tranche in self.tranches:
|
||||
|
||||
@@ -52,7 +52,7 @@ async def handle_order_placed(event: EventData):
|
||||
log.debug(f'raw order status {obj}')
|
||||
order = Order.create(addr, index, event['transactionHash'], obj)
|
||||
await activate_order(order)
|
||||
log.debug(f'new order{order}')
|
||||
log.debug(f'new order {order.key}{order}')
|
||||
|
||||
|
||||
async def handle_swap_filled(event: EventData):
|
||||
|
||||
@@ -187,10 +187,11 @@ class Trigger:
|
||||
|
||||
@value.setter
|
||||
def value(self, value):
|
||||
state = _trigger_state.get(self.tk,0)
|
||||
old = state & (1 << self.position) == 0 # NOTE: inverted
|
||||
|
||||
if value != old:
|
||||
state = _trigger_state.get(self.tk)
|
||||
if state is not None and value == (state & (1 << self.position) == 0): # NOTE: state is inverted
|
||||
return
|
||||
if state is None:
|
||||
state = 0
|
||||
_dirty.add(self.tk)
|
||||
if not value: # this conditional is inverted
|
||||
_trigger_state[self.tk] = state | (1 << self.position) # set
|
||||
@@ -497,8 +498,7 @@ class TrancheTrigger:
|
||||
# tranche minLine and maxLine are relative to the pool and will be flipped from the orderspec if the
|
||||
# order is buying the base and selling the quote.
|
||||
price = pool_prices[pool['address']] * dec(10) ** -pool['decimals']
|
||||
inverted = order.order.tokenIn != pool['base']
|
||||
assert inverted and order.order.tokenIn == pool['quote'] or not inverted and order.order.tokenIn == pool['base']
|
||||
inverted = order.order.inverted
|
||||
min_trigger = PriceLineTrigger.create(tk, inverted, price, tranche.minLine, True, tranche.minIsBarrier)
|
||||
max_trigger = PriceLineTrigger.create(tk, inverted, price, tranche.maxLine, False, tranche.maxIsBarrier)
|
||||
return TrancheTrigger(order, tk, balance_trigger, activation_trigger, expiration_trigger, min_trigger, max_trigger)
|
||||
@@ -536,6 +536,11 @@ class TrancheTrigger:
|
||||
log.debug(f'Tranche {tk} initial status {self.status} {self}')
|
||||
|
||||
|
||||
@property
|
||||
def order_trigger(self):
|
||||
return OrderTriggers.instances[self.tk.order_key]
|
||||
|
||||
|
||||
def fill(self, _amount_in, _amount_out, _next_activation_time ):
|
||||
if _next_activation_time != DISTANT_PAST:
|
||||
# rate limit
|
||||
@@ -560,7 +565,7 @@ class TrancheTrigger:
|
||||
def check_expire(self):
|
||||
# if the expiration constraint has become False then the tranche can never execute again
|
||||
if self.expiration_trigger is not None and not self.expiration_trigger:
|
||||
OrderTriggers.instances[self.tk.order_key].expire_tranche(self.tk.tranche_index)
|
||||
self.order_trigger.expire_tranche(self.tk.tranche_index)
|
||||
|
||||
def expire(self):
|
||||
if self.closed:
|
||||
@@ -573,6 +578,7 @@ class TrancheTrigger:
|
||||
order_log.warning(f'tranche KILLED {self.tk}')
|
||||
self.status = TrancheState.Error
|
||||
self.disable()
|
||||
self.order_trigger.check_complete()
|
||||
|
||||
def slash(self):
|
||||
# slash() is called when an execute() transaction on this tranche reverts without a recognized reason.
|
||||
|
||||
Reference in New Issue
Block a user