This commit is contained in:
tim
2024-08-25 21:01:45 -04:00
parent 750b4bcd65
commit cd42c5c645
2 changed files with 32 additions and 2 deletions

View File

@@ -93,6 +93,11 @@ class SwapOrder:
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]])
@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]])
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])
@@ -102,7 +107,7 @@ class SwapOrder:
SwapOrder
in: {self.tokenIn}
out: {self.tokenOut}
exchange: {self.route.exchange, 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 ""}
minFill: {self.minFillAmount}
tranches:
@@ -156,6 +161,8 @@ class ElaboratedSwapOrderStatus:
@staticmethod
def load_from_chain(tx_id: bytes, obj):
log.debug(f'load SwapOrderStatus from chain {obj}')
# 0 SwapOrder order
# 1 int fillFeeHalfBps
# 2 bool canceled
@@ -167,7 +174,7 @@ class ElaboratedSwapOrderStatus:
item = iter(obj)
order = SwapOrder.load(next(item))
order = SwapOrder.load_from_chain(next(item))
fillFeeHalfBps = int(next(item))
canceled = next(item)
state = SwapOrderState.Canceled if canceled else SwapOrderState.Open
@@ -254,6 +261,28 @@ class Tranche:
def fraction_of(self, amount):
return amount * self.fraction // MAX_FRACTION
@staticmethod
def load_from_chain(obj):
result = Tranche(
# none of these ints need to be strings because fraction is only 16 bits and the timestamps are only 32 bits
obj[0], # fraction
obj[1], # startTimeIsRelative
obj[2], # endTimeIsRelative
obj[3], # minIsBarrier
obj[4], # maxIsBarrier
obj[5], # marketOrder
obj[6], # minIsRatio
obj[7], # maxIsRatio
obj[8], # _reserved7
obj[9], # rateLimitFraction
obj[10], # rateLimitPeriod
obj[11], # startTime
obj[12], # endTime
Line.load_from_chain(obj[13]), # minLine
Line.load_from_chain(obj[14]), # maxLine
)
return result
@staticmethod
def load(obj):
result = Tranche(

View File

@@ -82,6 +82,7 @@ class Order:
if key in Order.instances:
raise ValueError
status = ElaboratedSwapOrderStatus.load_from_chain(tx_id, obj)
log.debug(f'loaded ElaboratedSwapOrderStatus {status}')
Order.order_statuses[key] = status.copy() # always copy the struct when setting. values in BlockData must be immutable
order = Order(key)
if order.is_open: