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