1
0

submarine_swaps: fix order of operations in get_send_amount

This commit is contained in:
ThomasV
2022-05-24 18:51:09 +02:00
parent 2362d6d010
commit 5bb99ddfaf

View File

@@ -551,6 +551,7 @@ class SwapManager(Logger):
return x
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)
# sanity check calculation can be inverted
if recv_amount is not None:
@@ -559,12 +560,16 @@ class SwapManager(Logger):
if abs(send_amount - inverted_send_amount) > 1:
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}")
# account for on-chain claim tx fee
# second, add on-chain claim tx fee
if is_reverse and recv_amount is not None:
recv_amount -= self.get_claim_fee()
return recv_amount
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)
# sanity check calculation can be inverted
if send_amount is not None:
@@ -572,9 +577,6 @@ class SwapManager(Logger):
if recv_amount != inverted_recv_amount:
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}")
# 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
def get_swap_by_tx(self, tx: Transaction) -> Optional[SwapData]: