submarine_swaps: fix order of operations in get_send_amount
This commit is contained in:
@@ -551,6 +551,7 @@ class SwapManager(Logger):
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
def get_recv_amount(self, send_amount: Optional[int], *, is_reverse: bool) -> Optional[int]:
|
def get_recv_amount(self, send_amount: Optional[int], *, is_reverse: bool) -> Optional[int]:
|
||||||
|
# first, add percentage fee
|
||||||
recv_amount = self._get_recv_amount(send_amount, is_reverse=is_reverse)
|
recv_amount = self._get_recv_amount(send_amount, is_reverse=is_reverse)
|
||||||
# sanity check calculation can be inverted
|
# sanity check calculation can be inverted
|
||||||
if recv_amount is not None:
|
if recv_amount is not None:
|
||||||
@@ -559,12 +560,16 @@ class SwapManager(Logger):
|
|||||||
if abs(send_amount - inverted_send_amount) > 1:
|
if abs(send_amount - inverted_send_amount) > 1:
|
||||||
raise Exception(f"calc-invert-sanity-check failed. is_reverse={is_reverse}. "
|
raise Exception(f"calc-invert-sanity-check failed. is_reverse={is_reverse}. "
|
||||||
f"send_amount={send_amount} -> recv_amount={recv_amount} -> inverted_send_amount={inverted_send_amount}")
|
f"send_amount={send_amount} -> recv_amount={recv_amount} -> inverted_send_amount={inverted_send_amount}")
|
||||||
# account for on-chain claim tx fee
|
# second, add on-chain claim tx fee
|
||||||
if is_reverse and recv_amount is not None:
|
if is_reverse and recv_amount is not None:
|
||||||
recv_amount -= self.get_claim_fee()
|
recv_amount -= self.get_claim_fee()
|
||||||
return recv_amount
|
return recv_amount
|
||||||
|
|
||||||
def get_send_amount(self, recv_amount: Optional[int], *, is_reverse: bool) -> Optional[int]:
|
def get_send_amount(self, recv_amount: Optional[int], *, is_reverse: bool) -> Optional[int]:
|
||||||
|
# first, add on-chain claim tx fee
|
||||||
|
if is_reverse and recv_amount is not None:
|
||||||
|
recv_amount += self.get_claim_fee()
|
||||||
|
# second, add percentage fee
|
||||||
send_amount = self._get_send_amount(recv_amount, is_reverse=is_reverse)
|
send_amount = self._get_send_amount(recv_amount, is_reverse=is_reverse)
|
||||||
# sanity check calculation can be inverted
|
# sanity check calculation can be inverted
|
||||||
if send_amount is not None:
|
if send_amount is not None:
|
||||||
@@ -572,9 +577,6 @@ class SwapManager(Logger):
|
|||||||
if recv_amount != inverted_recv_amount:
|
if recv_amount != inverted_recv_amount:
|
||||||
raise Exception(f"calc-invert-sanity-check failed. is_reverse={is_reverse}. "
|
raise Exception(f"calc-invert-sanity-check failed. is_reverse={is_reverse}. "
|
||||||
f"recv_amount={recv_amount} -> send_amount={send_amount} -> inverted_recv_amount={inverted_recv_amount}")
|
f"recv_amount={recv_amount} -> send_amount={send_amount} -> inverted_recv_amount={inverted_recv_amount}")
|
||||||
# account for on-chain claim tx fee
|
|
||||||
if is_reverse and send_amount is not None:
|
|
||||||
send_amount += self.get_claim_fee()
|
|
||||||
return send_amount
|
return send_amount
|
||||||
|
|
||||||
def get_swap_by_tx(self, tx: Transaction) -> Optional[SwapData]:
|
def get_swap_by_tx(self, tx: Transaction) -> Optional[SwapData]:
|
||||||
|
|||||||
Reference in New Issue
Block a user