From cef8ed21e16414f590a989fb16be652966a86f54 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 8 Oct 2026 13:12:03 +0000 Subject: [PATCH] Thornode: new `trade_limit` property --- mmgen/swap/proto/thorchain/thornode.py | 14 +++++++++++--- mmgen/tx/new_swap.py | 12 ++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mmgen/swap/proto/thorchain/thornode.py b/mmgen/swap/proto/thorchain/thornode.py index 11a19717..8c985bb7 100644 --- a/mmgen/swap/proto/thorchain/thornode.py +++ b/mmgen/swap/proto/thorchain/thornode.py @@ -51,7 +51,7 @@ class Thornode: else: self.data = self.rpc.get_quote(self.tx.send_asset, self.tx.recv_asset, self.in_amt) - async def format_quote(self, trade_limit, *, deduct_est_fee=False): + async def format_quote(self, *, deduct_est_fee=False): from ....util import make_timestr, ymsg from ....util2 import format_elapsed_hr from ....color import blue, green, cyan, pink, orange, redbg, yelbg, grnbg @@ -66,9 +66,9 @@ class Thornode: if tx.proto.has_usr_fee: gas_unit = d['gas_rate_units'] - if trade_limit: + if self.trade_limit: from . import ExpInt4 - tl_int = ExpInt4(trade_limit.to_unit('satoshi')) + tl_int = ExpInt4(self.trade_limit.to_unit('satoshi')) tl_uniamt = UniAmt(tl_int.trunc, from_unit='satoshi') ratio = float(tl_uniamt / out_amt) direction = 'ABOVE' if ratio > 1 else 'below' @@ -137,6 +137,14 @@ class Thornode: Slippage: {pink(slip_pct_disp)} """ + @property + def trade_limit(self): + match self.tx.swap_cfg.trade_limit: + case UniAmt(): # can’t use positional arg here (not supported by Decimal) + return self.tx.swap_cfg.trade_limit + case float(x): + return UniAmt(int(self.data['expected_amount_out']), from_unit='satoshi') * x + @property def inbound_address(self): addr = self.data['inbound_address'] diff --git a/mmgen/tx/new_swap.py b/mmgen/tx/new_swap.py index e53e4229..c5b78ace 100644 --- a/mmgen/tx/new_swap.py +++ b/mmgen/tx/new_swap.py @@ -184,13 +184,6 @@ class NewSwap(New): self.recv_proto.coin_addr(self.swap_proto_mod.Memo.parse(memo).address), trade_limit = trade_limit) - def get_trade_limit(self, qd): - match self.swap_cfg.trade_limit: - case UniAmt(): # can’t use positional arg here (not supported by Decimal) - return self.swap_cfg.trade_limit - case float(x): - return UniAmt(int(qd.data['expected_amount_out']), from_unit='satoshi') * x - async def update_vault_output(self, amt, *, deduct_est_fee=False): qd = self.swap_proto_mod.rpc_client(self, amt) @@ -204,8 +197,7 @@ class NewSwap(New): self.cfg._util.qmsg('OK') self.swap_quote_refresh_time = time.time() await self.set_gas(to_addr=qd.router if self.is_token else None) - trade_limit = self.get_trade_limit(qd) - msg(await qd.format_quote(trade_limit, deduct_est_fee=deduct_est_fee)) + msg(await qd.format_quote(deduct_est_fee=deduct_est_fee)) ch = get_char('Press ‘r’ to refresh quote, any other key to continue: ') msg('') if ch not in 'Rr': @@ -213,6 +205,6 @@ class NewSwap(New): self.swap_quote_expiry = qd.data['expiry'] self.update_vault_addr(qd) - self.update_data_output(trade_limit) + self.update_data_output(qd.trade_limit) self.quote_data = qd return qd.rel_fee_hint