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
committed by SomberNight
parent a9493e3c67
commit 7e8dc04008

View File

@@ -516,6 +516,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:
@@ -524,12 +525,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:
@@ -537,7 +542,4 @@ 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