From 2f7a15e9b0cab3d4006c368a4f5c5a4261ae1f21 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 7 May 2025 18:24:02 +0000 Subject: [PATCH] tw, swap: minor fixes and cleanups --- mmgen/proto/btc/tw/addresses.py | 3 ++- mmgen/proto/eth/tw/addresses.py | 3 +-- mmgen/proto/eth/tx/base.py | 2 +- mmgen/proto/eth/tx/info.py | 4 ++-- mmgen/proto/eth/tx/signed.py | 2 +- mmgen/swap/proto/thorchain/asset.py | 2 +- mmgen/tw/addresses.py | 11 ++++++++++- test/cmdtest_d/ethbump.py | 7 +++++++ test/cmdtest_d/ethswap.py | 18 ++++++++++++++++-- 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/mmgen/proto/btc/tw/addresses.py b/mmgen/proto/btc/tw/addresses.py index f6cfe0d8..bd6dcad7 100755 --- a/mmgen/proto/btc/tw/addresses.py +++ b/mmgen/proto/btc/tw/addresses.py @@ -73,7 +73,8 @@ class BitcoinTwAddresses(TwAddresses, BitcoinTwRPC): label = get_obj(TwLabel, proto=self.proto, text=d['label']) if label: assert label.mmid in addrs, f'{label.mmid!r} not found in addrlist!' - addrs[label.mmid]['recvd'] = coin_amt(d['amount']) + amt = coin_amt(d['amount']) + addrs[label.mmid]['recvd'] = amt addrs[label.mmid]['confs'] = d['confirmations'] qmsg('done') diff --git a/mmgen/proto/eth/tw/addresses.py b/mmgen/proto/eth/tw/addresses.py index 568b5cfe..4b9d424b 100755 --- a/mmgen/proto/eth/tw/addresses.py +++ b/mmgen/proto/eth/tw/addresses.py @@ -74,8 +74,7 @@ class EthereumTwAddresses(TwAddresses, EthereumTwView, EthereumTwRPC): addrs[e.label.mmid] = { 'addr': e.coinaddr, 'amt': bal, - 'recvd': bal, # since it’s nearly impossible to empty an Ethereum account, - # we consider a used account to be any account with a balance + 'recvd': bal, # current bal only, CF btc.tw.addresses.get_rpc_data() 'confs': 0, 'lbl': e.label} self.total += bal diff --git a/mmgen/proto/eth/tx/base.py b/mmgen/proto/eth/tx/base.py index 2387a478..5ef1e4dd 100755 --- a/mmgen/proto/eth/tx/base.py +++ b/mmgen/proto/eth/tx/base.py @@ -104,7 +104,7 @@ class Base(TxBase): assert d[3].hex() == o[to_key], f'{d[3].hex()}: invalid ‘to’ address in serialized data' if not self.is_token: if o['amt']: - assert int(d[4].hex(), 16) == o['amt'].to_unit('wei'), ( + assert int(d[4].hex(), 16) == o['amt'].toWei(), ( f'{d[4].hex()}: invalid amt in serialized data') if self.is_swap: assert d[5] == self.swap_memo.encode(), ( diff --git a/mmgen/proto/eth/tx/info.py b/mmgen/proto/eth/tx/info.py index f4a39da2..e1ae93ee 100755 --- a/mmgen/proto/eth/tx/info.py +++ b/mmgen/proto/eth/tx/info.py @@ -14,7 +14,7 @@ proto.eth.tx.info: Ethereum transaction info class from ....tx.info import TxInfo from ....util import fmt, pp_fmt -from ....color import pink, yellow, blue, cyan +from ....color import yellow, blue, cyan, pink from ....addr import MMGenID class TxInfo(TxInfo): @@ -37,7 +37,7 @@ class TxInfo(TxInfo): {toaddr} {t}{t_mmid}{tvault} Amount: {a} {c} Gas price: {g} Gwei - Start gas: {G} Kwei + Gas limit: {G} Nonce: {n} Data: {d} """.strip().replace('\t', '') + ('\nMemo: {m}' if tx.is_swap else '') diff --git a/mmgen/proto/eth/tx/signed.py b/mmgen/proto/eth/tx/signed.py index a684bd00..eef93bc8 100755 --- a/mmgen/proto/eth/tx/signed.py +++ b/mmgen/proto/eth/tx/signed.py @@ -53,7 +53,7 @@ class TokenSigned(TokenCompleted, Signed): def parse_txfile_serialized_data(self): raise NotImplementedError( - 'Signed transaction files cannot be parsed offline, because tracking wallet is required!') + 'Signed token transaction files cannot be parsed offline, because tracking wallet is required!') class AutomountSigned(TxBase.AutomountSigned, Signed): pass diff --git a/mmgen/swap/proto/thorchain/asset.py b/mmgen/swap/proto/thorchain/asset.py index b0f2c88f..58b011b0 100644 --- a/mmgen/swap/proto/thorchain/asset.py +++ b/mmgen/swap/proto/thorchain/asset.py @@ -25,7 +25,7 @@ class THORChainSwapAsset(SwapAsset): 'DOGE': _ad('Dogecoin', 'DOGE', None, 'd', False), 'RUNE': _ad('Rune (THORChain)', 'RUNE', 'THOR.RUNE', 'r', False), 'ETH.AAVE': _ad('Aave (ETH)', None, 'ETH.AAVE', None, True), - 'ETH.DAI': _ad('Sky Dollar (USDS) (ETH)', None, 'ETH.DAI', None, True), + 'ETH.DAI': _ad('MakerDAO USD (ETH)', None, 'ETH.DAI', None, True), 'ETH.DPI': _ad('DeFi Pulse Index (ETH)', None, 'ETH.DPI', None, True), 'ETH.FOX': _ad('ShapeShift FOX (ETH)', None, 'ETH.FOX', None, True), 'ETH.GUSD': _ad('Gemini Dollar (ETH)', None, 'ETH.GUSD', None, True), diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index d02111a3..d8896210 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -47,7 +47,16 @@ class TwAddresses(TwView): fmt_method = 'gen_display' class TwAddress(MMGenListItem): - valid_attrs = {'twmmid', 'addr', 'al_id', 'confs', 'comment', 'amt', 'recvd', 'date', 'skip'} + valid_attrs = { + 'twmmid', + 'addr', + 'al_id', + 'confs', + 'comment', + 'amt', + 'recvd', + 'date', + 'skip'} invalid_attrs = {'proto'} twmmid = ImmutableAttr(TwMMGenID, include_proto=True) # contains confs,txid(unused),date(unused),al_id diff --git a/test/cmdtest_d/ethbump.py b/test/cmdtest_d/ethbump.py index fa42eb00..95561be1 100755 --- a/test/cmdtest_d/ethbump.py +++ b/test/cmdtest_d/ethbump.py @@ -300,6 +300,13 @@ class CmdTestEthBump(CmdTestEthBumpMethods, CmdTestEthSwapMethods, CmdTestSwapMe def bal4(self): return self._bal_check(pat=rf'{dfl_sid}:E:12\s+4444\.3333\s') + def token_fund_user(self): + return self._token_transfer_ops( + op = 'fund_user', + mm_idxs = [1], + token_addr = 'token_addr1', + amt = self.token_fund_amt) + def token_txdo1(self): return self._token_txcreate(cmd='txdo', args=[f'{dfl_sid}:E:2,1.23456', dfl_words_file]) diff --git a/test/cmdtest_d/ethswap.py b/test/cmdtest_d/ethswap.py index 3179c603..7a48e76d 100755 --- a/test/cmdtest_d/ethswap.py +++ b/test/cmdtest_d/ethswap.py @@ -104,7 +104,7 @@ class CmdTestEthSwapMethods: def token_bal2(self): return self._token_bal_check(pat=rf'{eth_inbound_addr}\s+\S+\s+87.654321\s') - async def _swaptxmemo(self, chk): + async def _check_token_swaptx_memo(self, chk): from mmgen.proto.eth.contract import Contract self.spawn(msg_only=True) addr = get_data_from_file(self.cfg, thorchain_router_addr_file, quiet=True).strip() @@ -230,6 +230,7 @@ class CmdTestEthSwap(CmdTestSwapMethods, CmdTestRegtest): ('eth_swaptxcreate3', ''), ('eth_swaptxsign3', ''), ('eth_swaptxsend3', ''), + ('eth_swaptxmemo3', ''), # MM1 -> BTC ('eth_swaptxcreate4', ''), ('eth_swaptxsign4', ''), @@ -369,6 +370,7 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev ('swaptxcreate3', 'creating an ETH->MM1 swap transaction'), ('swaptxsign3', 'signing the transaction'), ('swaptxsend3', 'sending the transaction'), + ('swaptxmemo3', 'the memo of the sent transaction'), # MM1 -> BTC ('swaptxcreate4', 'creating an MM1->BTC swap transaction'), @@ -406,6 +408,18 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev t = self._swaptxcreate(['ETH', '8.765', 'ETH.MM1', f'{dfl_sid}:E:5']) return self._swaptxcreate_ui_common(t) + async def swaptxmemo3(self): + self.spawn(msg_only=True) + import json + fn = self.get_file_with_ext('sigtx') + tx = json.loads(get_data_from_file(self.cfg, fn, quiet=True).strip()) + txid = tx['MMGenTransaction']['coin_txid'] + chk = '=:ETH.MM1:0x48596c861c970eb4ca72c5082ff7fecd8ee5be9d:0/1/0' # E:5 + imsg(f'TxID: {txid}\nmemo: {chk}') + res = await (await self.rpc).call('eth_getTransactionByHash', '0x' + txid) + chk_equal(bytes.fromhex(res['input'].removeprefix('0x')).decode(), chk) + return 'ok' + def swaptxcreate4(self): t = self._swaptxcreate(['ETH.MM1', '87.654321', 'BTC', f'{dfl_sid}:C:2']) return self._swaptxcreate_ui_common(t) @@ -425,7 +439,7 @@ class CmdTestEthSwapEth(CmdTestEthSwapMethods, CmdTestSwapMethods, CmdTestEthdev def swaptxmemo4(self): self.mining_delay() - return self._swaptxmemo('=:b:mkQsXA7mqDtnUpkaXMbDtAL1KMeof4GPw3:0/1/0') + return self._check_token_swaptx_memo('=:b:mkQsXA7mqDtnUpkaXMbDtAL1KMeof4GPw3:0/1/0') def swaptxreceipt4(self): return self._swaptxsend(add_opts=['--receipt'], spawn_only=True)