fix: replace EVM amount parsing logic with `parseFixed` for improved precision (#2518)
Konstantin Ullrich committed
Sep 11, 2025 at 14:32 UTC
4aac641f04fac04db50534bb8d1a5379d835b272
1 file changed
+3
-4
cw_evm/lib/evm_chain_wallet.dart
+3
-4
@@ -1,7 +1,6 @@
1
import 'dart:async';
2
import 'dart:convert';
3
import 'dart:io';
4
-import 'dart:math';
4
import 'dart:typed_data';
5
6
import 'package:bip32/bip32.dart' as bip32;
@@ -11,6 +10,7 @@ import 'package:cw_core/crypto_currency.dart';
10
import 'package:cw_core/encryption_file_utils.dart';
11
import 'package:cw_core/erc20_token.dart';
12
import 'package:cw_core/node.dart';
13
+import 'package:cw_core/parse_fixed.dart';
14
import 'package:cw_core/pathForWallet.dart';
15
import 'package:cw_core/pending_transaction.dart';
16
import 'package:cw_core/sync_status.dart';
@@ -471,7 +471,6 @@ abstract class EVMChainWalletBase
471
BigInt totalAmount = BigInt.zero;
472
BigInt estimatedFeesForTransaction = BigInt.zero;
473
int exponent = transactionCurrency is Erc20Token ? transactionCurrency.decimal : 18;
474
- num amountToEVMChainMultiplier = pow(10, exponent);
474
String? contractAddress;
475
int estimatedGasUnitsForTransaction = 0;
476
int maxFeePerGasForTransaction = 0;
@@ -491,7 +490,7 @@ abstract class EVMChainWalletBase
490
491
final totalOriginalAmount = EVMChainFormatter.parseEVMChainAmountToDouble(
492
outputs.fold(0, (acc, value) => acc + (value.formattedCryptoAmount ?? 0)));
494
- totalAmount = BigInt.from(totalOriginalAmount * amountToEVMChainMultiplier);
493
+ totalAmount = parseFixed(totalOriginalAmount.toString(), exponent);
494
495
final gasFeesModel = await calculateActualEstimatedFeeForCreateTransaction(
496
amount: totalAmount,
@@ -513,7 +512,7 @@ abstract class EVMChainWalletBase
512
final totalOriginalAmount =
513
EVMChainFormatter.parseEVMChainAmountToDouble(output.formattedCryptoAmount ?? 0);
514
516
- totalAmount = BigInt.from(totalOriginalAmount * amountToEVMChainMultiplier);
515
+ totalAmount = parseFixed(totalOriginalAmount.toString(), exponent);
516
}
517
518
if (output.sendAll && transactionCurrency is Erc20Token) {