CW-672: Enhance ETH Wallet Fee Calculation - Fix ERC20 Transaction Fee (#1548)

* fix: Eth transaction fees WIP * Revert "fix: Eth transaction fees WIP" This reverts commit b9a469bc7e22134d78bf0cc4c00485e1d4515ebd. * fix: Modifying fee WIP * fix: Enhance ETH Wallet fee calculation WIP * feat: Enhance Transaction fees for ETH Transactions, Native transactions done, left with ERC20 transactions * fix: Pre PR cleanups * fix: ETH transaction fees for ERC20 transactions * fix: ETH transaction fees for ERC20 transactions * chore: Clarify comment in getEstimatedGas * fix: Switch call to estimate gas units to a more cleaner approach

David Adegoke committed Jul 23, 2024 at 01:21 UTC a4282cb70402e7ed93a54f12d23718084d549c3f
2 files changed +9 -11
cw_evm/lib/evm_chain_client.dart
+9 -9
@@ -72,12 +72,12 @@ abstract class EVMChainClient {
72 }
73 }
74
75 - Future<int> getGasBaseFee() async {
75 + Future<int?> getGasBaseFee() async {
76 try {
77 final blockInfo = await _client!.getBlockInformation(isContainFullObj: false);
78 final baseFee = blockInfo.baseFeePerGas;
79
80 - return baseFee!.getInWei.toInt();
80 + return baseFee?.getInWei.toInt();
81 } catch (_) {
82 return 0;
83 }
@@ -110,19 +110,19 @@ abstract class EVMChainClient {
110 EthereumAddress.fromHex(contractAddress),
111 );
112
113 - final transferFunction = contract.function('transferFrom');
113 + final transfer = contract.function('transfer');
114
115 - final estimatedGas = await _client!.estimateGas(
115 + // Estimate gas units
116 + final gasEstimate = await _client!.estimateGas(
117 sender: senderAddress,
117 - to: toAddress,
118 - value: value,
119 - data: transferFunction.encodeCall([
120 - senderAddress,
118 + to: EthereumAddress.fromHex(contractAddress),
119 + data: transfer.encodeCall([
120 toAddress,
121 value.getInWei,
122 ]),
123 );
125 - return estimatedGas.toInt();
124 +
125 + return gasEstimate.toInt();
126 }
127 } catch (_) {
128 return 0;
cw_evm/lib/evm_chain_wallet.dart
-2
@@ -387,8 +387,6 @@ abstract class EVMChainWalletBase
387
388 estimatedFeesForTransaction = BigInt.from(estimateFees);
389
390 - debugPrint('Estimated Fees for Transaction: $estimatedFeesForTransaction');
391 -
390 if (output.sendAll && transactionCurrency is! Erc20Token) {
391 totalAmount = (erc20Balance.balance - estimatedFeesForTransaction);
392