Skip to content

Commit

Permalink
Merge branch 'main' into CW-807-Add-extra-fields-for-XRP-and-XLM-exch…
Browse files Browse the repository at this point in the history
…anges
  • Loading branch information
Serhii-Borodenko committed Dec 12, 2024
2 parents 9ad1f31 + ad34caa commit 204e0b8
Show file tree
Hide file tree
Showing 62 changed files with 800 additions and 242 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr_test_build_android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ jobs:
echo "const polygonScanApiKey = '${{ secrets.POLYGON_SCAN_API_KEY }}';" >> lib/.secrets.g.dart
echo "const etherScanApiKey = '${{ secrets.ETHER_SCAN_API_KEY }}';" >> cw_evm/lib/.secrets.g.dart
echo "const moralisApiKey = '${{ secrets.MORALIS_API_KEY }}';" >> cw_evm/lib/.secrets.g.dart
echo "const nowNodesApiKey = '${{ secrets.EVM_NOWNODES_API_KEY }}';" >> cw_evm/lib/.secrets.g.dart
echo "const chatwootWebsiteToken = '${{ secrets.CHATWOOT_WEBSITE_TOKEN }}';" >> lib/.secrets.g.dart
echo "const exolixApiKey = '${{ secrets.EXOLIX_API_KEY }}';" >> lib/.secrets.g.dart
echo "const robinhoodApplicationId = '${{ secrets.ROBINHOOD_APPLICATION_ID }}';" >> lib/.secrets.g.dart
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr_test_build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ jobs:
echo "const walletConnectProjectId = '${{ secrets.WALLET_CONNECT_PROJECT_ID }}';" >> lib/.secrets.g.dart
echo "const moralisApiKey = '${{ secrets.MORALIS_API_KEY }}';" >> lib/.secrets.g.dart
echo "const polygonScanApiKey = '${{ secrets.POLYGON_SCAN_API_KEY }}';" >> cw_evm/lib/.secrets.g.dart
echo "const nowNodesApiKey = '${{ secrets.EVM_NOWNODES_API_KEY }}';" >> cw_evm/lib/.secrets.g.dart
echo "const ankrApiKey = '${{ secrets.ANKR_API_KEY }}';" >> cw_solana/lib/.secrets.g.dart
echo "const testCakePayApiKey = '${{ secrets.TEST_CAKE_PAY_API_KEY }}';" >> lib/.secrets.g.dart
echo "const cakePayApiKey = '${{ secrets.CAKE_PAY_API_KEY }}';" >> lib/.secrets.g.dart
Expand Down
2 changes: 2 additions & 0 deletions assets/ethereum_server_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
uri: rpc.flashbots.net
-
uri: eth-mainnet.public.blastapi.io
-
uri: eth.nownodes.io
-
uri: ethereum.publicnode.com
4 changes: 3 additions & 1 deletion assets/polygon_node_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
-
uri: polygon-bor.publicnode.com
-
uri: polygon.llamarpc.com
uri: polygon.llamarpc.com
-
uri: matic.nownodes.io
5 changes: 4 additions & 1 deletion cw_bitcoin/lib/electrum_transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ abstract class ElectrumTransactionHistoryBase
String _password;
int _height;

Future<void> init() async => await _load();
Future<void> init() async {
clear();
await _load();
}

@override
void addOne(ElectrumTransactionInfo transaction) => transactions[transaction.id] = transaction;
Expand Down
3 changes: 2 additions & 1 deletion cw_core/lib/hive_type_ids.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ const SPL_TOKEN_TYPE_ID = 16;
const DERIVATION_INFO_TYPE_ID = 17;
const TRON_TOKEN_TYPE_ID = 18;
const HARDWARE_WALLET_TYPE_TYPE_ID = 19;
const MWEB_UTXO_TYPE_ID = 20;
const MWEB_UTXO_TYPE_ID = 20;
const HAVEN_SEED_STORE_TYPE_ID = 21;
36 changes: 27 additions & 9 deletions cw_evm/lib/evm_chain_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ abstract class EVMChainClient {

bool connect(Node node) {
try {
_client = Web3Client(node.uri.toString(), httpClient);
Uri? rpcUri;
bool isModifiedNodeUri = false;

if (node.uriRaw == 'eth.nownodes.io' || node.uriRaw == 'matic.nownodes.io') {
isModifiedNodeUri = true;
String nowNodeApiKey = secrets.nowNodesApiKey;

rpcUri = Uri.https(node.uriRaw, '/$nowNodeApiKey');
}

_client =
Web3Client(isModifiedNodeUri ? rpcUri!.toString() : node.uri.toString(), httpClient);

return true;
} catch (e) {
Expand Down Expand Up @@ -83,23 +94,20 @@ abstract class EVMChainClient {
}
}

Future<int> getEstimatedGas({
String? contractAddress,
Future<int> getEstimatedGasUnitsForTransaction({
required EthereumAddress toAddress,
required EthereumAddress senderAddress,
required EtherAmount value,
String? contractAddress,
EtherAmount? gasPrice,
// EtherAmount? maxFeePerGas,
// EtherAmount? maxPriorityFeePerGas,
EtherAmount? maxFeePerGas,
}) async {
try {
if (contractAddress == null) {
final estimatedGas = await _client!.estimateGas(
sender: senderAddress,
gasPrice: gasPrice,
to: toAddress,
value: value,
// maxPriorityFeePerGas: maxPriorityFeePerGas,
// maxFeePerGas: maxFeePerGas,
);

Expand Down Expand Up @@ -133,7 +141,9 @@ abstract class EVMChainClient {
required Credentials privateKey,
required String toAddress,
required BigInt amount,
required BigInt gas,
required BigInt gasFee,
required int estimatedGasUnits,
required int maxFeePerGas,
required EVMChainTransactionPriority priority,
required CryptoCurrency currency,
required int exponent,
Expand All @@ -152,6 +162,8 @@ abstract class EVMChainClient {
maxPriorityFeePerGas: EtherAmount.fromInt(EtherUnit.gwei, priority.tip),
amount: isNativeToken ? EtherAmount.inWei(amount) : EtherAmount.zero(),
data: data != null ? hexToBytes(data) : null,
maxGas: estimatedGasUnits,
maxFeePerGas: EtherAmount.fromInt(EtherUnit.wei, maxFeePerGas),
);

Uint8List signedTransaction;
Expand Down Expand Up @@ -180,7 +192,7 @@ abstract class EVMChainClient {
return PendingEVMChainTransaction(
signedTransaction: signedTransaction,
amount: amount.toString(),
fee: gas,
fee: gasFee,
sendTransaction: _sendTransaction,
exponent: exponent,
);
Expand All @@ -191,14 +203,20 @@ abstract class EVMChainClient {
required EthereumAddress to,
required EtherAmount amount,
EtherAmount? maxPriorityFeePerGas,
EtherAmount? gasPrice,
EtherAmount? maxFeePerGas,
Uint8List? data,
int? maxGas,
}) {
return Transaction(
from: from,
to: to,
maxPriorityFeePerGas: maxPriorityFeePerGas,
value: amount,
data: data,
maxGas: maxGas,
gasPrice: gasPrice,
maxFeePerGas: maxFeePerGas,
);
}

Expand Down
5 changes: 4 additions & 1 deletion cw_evm/lib/evm_chain_transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ abstract class EVMChainTransactionHistoryBase

//! Common methods across all child classes

Future<void> init() async => await _load();
Future<void> init() async {
clear();
await _load();
}

@override
Future<void> save() async {
Expand Down
61 changes: 48 additions & 13 deletions cw_evm/lib/evm_chain_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ abstract class EVMChainWalletBase
/// - The exact amount the user wants to send,
/// - The addressHex for the receiving wallet,
/// - A contract address which would be essential in determining if to calcualate the estimate for ERC20 or native ETH
Future<int> calculateActualEstimatedFeeForCreateTransaction({
Future<GasParamsHandler> calculateActualEstimatedFeeForCreateTransaction({
required amount,
required String? contractAddress,
required String receivingAddressHex,
Expand All @@ -240,22 +240,27 @@ abstract class EVMChainWalletBase
maxFeePerGas = gasPrice;
}

final estimatedGas = await _client.getEstimatedGas(
final estimatedGas = await _client.getEstimatedGasUnitsForTransaction(
contractAddress: contractAddress,
senderAddress: _evmChainPrivateKey.address,
value: EtherAmount.fromBigInt(EtherUnit.wei, amount!),
gasPrice: EtherAmount.fromInt(EtherUnit.wei, gasPrice),
toAddress: EthereumAddress.fromHex(receivingAddressHex),
// maxFeePerGas: EtherAmount.fromInt(EtherUnit.wei, maxFeePerGas),
// maxPriorityFeePerGas: EtherAmount.fromInt(EtherUnit.gwei, priority.tip),
maxFeePerGas: EtherAmount.fromInt(EtherUnit.wei, maxFeePerGas),
);

final totalGasFee = estimatedGas * maxFeePerGas;
return totalGasFee;

return GasParamsHandler(
estimatedGasUnits: estimatedGas,
estimatedGasFee: totalGasFee,
maxFeePerGas: maxFeePerGas,
gasPrice: gasPrice,
);
}
return 0;
return GasParamsHandler.zero();
} catch (e) {
return 0;
return GasParamsHandler.zero();
}
}

Expand Down Expand Up @@ -318,7 +323,7 @@ abstract class EVMChainWalletBase

gasPrice = await _client.getGasUnitPrice();

estimatedGasUnits = await _client.getEstimatedGas(
estimatedGasUnits = await _client.getEstimatedGasUnitsForTransaction(
senderAddress: _evmChainPrivateKey.address,
toAddress: _evmChainPrivateKey.address,
gasPrice: EtherAmount.fromInt(EtherUnit.wei, gasPrice),
Expand Down Expand Up @@ -349,6 +354,8 @@ abstract class EVMChainWalletBase
int exponent = transactionCurrency is Erc20Token ? transactionCurrency.decimal : 18;
num amountToEVMChainMultiplier = pow(10, exponent);
String? contractAddress;
int estimatedGasUnitsForTransaction = 0;
int maxFeePerGasForTransaction = 0;
String toAddress = _credentials.outputs.first.isParsedAddress
? _credentials.outputs.first.extractedAddress!
: _credentials.outputs.first.address;
Expand All @@ -367,14 +374,16 @@ abstract class EVMChainWalletBase
outputs.fold(0, (acc, value) => acc + (value.formattedCryptoAmount ?? 0)));
totalAmount = BigInt.from(totalOriginalAmount * amountToEVMChainMultiplier);

final estimateFees = await calculateActualEstimatedFeeForCreateTransaction(
final gasFeesModel = await calculateActualEstimatedFeeForCreateTransaction(
amount: totalAmount,
receivingAddressHex: toAddress,
priority: _credentials.priority!,
contractAddress: contractAddress,
);

estimatedFeesForTransaction = BigInt.from(estimateFees);
estimatedFeesForTransaction = BigInt.from(gasFeesModel.estimatedGasFee);
estimatedGasUnitsForTransaction = gasFeesModel.estimatedGasUnits;
maxFeePerGasForTransaction = gasFeesModel.maxFeePerGas;

if (erc20Balance.balance < totalAmount) {
throw EVMChainTransactionCreationException(transactionCurrency);
Expand All @@ -392,14 +401,16 @@ abstract class EVMChainWalletBase
totalAmount = erc20Balance.balance;
}

final estimateFees = await calculateActualEstimatedFeeForCreateTransaction(
final gasFeesModel = await calculateActualEstimatedFeeForCreateTransaction(
amount: totalAmount,
receivingAddressHex: toAddress,
priority: _credentials.priority!,
contractAddress: contractAddress,
);

estimatedFeesForTransaction = BigInt.from(estimateFees);
estimatedFeesForTransaction = BigInt.from(gasFeesModel.estimatedGasFee);
estimatedGasUnitsForTransaction = gasFeesModel.estimatedGasUnits;
maxFeePerGasForTransaction = gasFeesModel.maxFeePerGas;

if (output.sendAll && transactionCurrency is! Erc20Token) {
totalAmount = (erc20Balance.balance - estimatedFeesForTransaction);
Expand All @@ -420,12 +431,14 @@ abstract class EVMChainWalletBase
}

final pendingEVMChainTransaction = await _client.signTransaction(
estimatedGasUnits: estimatedGasUnitsForTransaction,
privateKey: _evmChainPrivateKey,
toAddress: toAddress,
amount: totalAmount,
gas: estimatedFeesForTransaction,
gasFee: estimatedFeesForTransaction,
priority: _credentials.priority!,
currency: transactionCurrency,
maxFeePerGas: maxFeePerGasForTransaction,
exponent: exponent,
contractAddress:
transactionCurrency is Erc20Token ? transactionCurrency.contractAddress : null,
Expand Down Expand Up @@ -728,3 +741,25 @@ abstract class EVMChainWalletBase
@override
final String? passphrase;
}

class GasParamsHandler {
final int estimatedGasUnits;
final int estimatedGasFee;
final int maxFeePerGas;
final int gasPrice;

GasParamsHandler(
{required this.estimatedGasUnits,
required this.estimatedGasFee,
required this.maxFeePerGas,
required this.gasPrice});

static GasParamsHandler zero() {
return GasParamsHandler(
estimatedGasUnits: 0,
estimatedGasFee: 0,
maxFeePerGas: 0,
gasPrice: 0,
);
}
}
5 changes: 4 additions & 1 deletion cw_nano/lib/nano_transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ abstract class NanoTransactionHistoryBase extends TransactionHistoryBase<NanoTra
final EncryptionFileUtils encryptionFileUtils;
String _password;

Future<void> init() async => await _load();
Future<void> init() async {
clear();
await _load();
}

@override
Future<void> save() async {
Expand Down
8 changes: 8 additions & 0 deletions cw_polygon/lib/polygon_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ class PolygonClient extends EVMChainClient {
required EtherAmount amount,
EtherAmount? maxPriorityFeePerGas,
Uint8List? data,
int? maxGas,
EtherAmount? gasPrice,
EtherAmount? maxFeePerGas,
}) {
return Transaction(
from: from,
to: to,
value: amount,
data: data,
maxGas: maxGas,
gasPrice: gasPrice,
maxFeePerGas: maxFeePerGas,
maxPriorityFeePerGas: maxPriorityFeePerGas,
);
}

Expand Down
5 changes: 4 additions & 1 deletion cw_solana/lib/solana_transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ abstract class SolanaTransactionHistoryBase extends TransactionHistoryBase<Solan
final EncryptionFileUtils encryptionFileUtils;
String _password;

Future<void> init() async => await _load();
Future<void> init() async {
clear();
await _load();
}

@override
Future<void> save() async {
Expand Down
5 changes: 4 additions & 1 deletion cw_tron/lib/tron_transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ abstract class TronTransactionHistoryBase extends TransactionHistoryBase<TronTra
final WalletInfo walletInfo;
final EncryptionFileUtils encryptionFileUtils;

Future<void> init() async => await _load();
Future<void> init() async {
clear();
await _load();
}

@override
Future<void> save() async {
Expand Down
14 changes: 12 additions & 2 deletions cw_wownero/lib/api/transaction_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,23 @@ void commitTransaction({required wownero.PendingTransaction transactionPointer})

final txCommit = wownero.PendingTransaction_commit(transactionPointer, filename: '', overwrite: false);

final String? error = (() {
String? error = (() {
final status = wownero.PendingTransaction_status(transactionPointer.cast());
if (status == 0) {
return null;
}
return wownero.Wallet_errorString(wptr!);
return wownero.PendingTransaction_errorString(transactionPointer.cast());
})();
if (error == null) {
error = (() {
final status = wownero.Wallet_status(wptr!);
if (status == 0) {
return null;
}
return wownero.Wallet_errorString(wptr!);
})();

}

if (error != null) {
throw CreationTransactionException(message: error);
Expand Down
Loading

0 comments on commit 204e0b8

Please sign in to comment.