CW-555-Add-Solana-Wallet (#1272)

* chore: Create cw_solana package and clean up files

* feat: Add Solana Wallet - Create, Restore form seed, restore from Key, Restore from QR, Send, Receive, transaction history, spl tokens

* fix: Make transactions file specific to solana only for solana transactions

* chore: Revert inject app details script

* fix: Fix issue with node and switch current node to main beta instead of testnet

* fix: Fix merge conflicts and adjust migration version

* fix: Fetch spl token error

Signed-off-by: Blazebrain <davidadegoke16@gmail.com>

* fix: Diplay and activate spl tokens bug

* fix: Review and fixes

* fix: reverted formatting for cryptocurrency class

* fix: Review comments, split sending flow into signing and sending separately, fix issues

* fix: Revert throwing unimplenented error

* chore: Fix comment

* chore: Fix comment

* fix: Errors in flow

* Update provider_types.dart [skip ci]

* fix: Issues with solana wallet

* Update solana_wallet.dart [skip ci]

* fix: Review comments

* fix: Date time config

* fix: Revert bash script for app details

* fix: Error with balance, displaying fees, fixing sent or received identifier bug, displaying token symbol with token transaction item in transactions list

* fix: Issues with address validation when sending spl tokens and walletconnect initial setup

* fix: Issues with sending, fetching transactions history, almost wrapping up walletconnect

* fix: Adjust imports that would affect monerocom building successfully

* fix: Refine transaction direction and continue work on walletconnect

* feat: Display SPL token transfers in the transaction history and finally settle the transaction direction

* fix: Delay in transactions history dispaly, show native token transactions first, then process spl token transactions

* feat: Switch node and revert solana chain id to previous id

* fix: Remove print statement

* fix: Remove await for transactions, fetch all transaction histories instantly and adjust solana send success message

* chore: Code refactoring and streamlined wallet type check for solana send success message

* fix: Make timeout error for node silent and add spl token images

---------

Signed-off-by: Blazebrain <davidadegoke16@gmail.com>
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
Adegoke David
2024-02-23 15:39:19 +02:00
committed by GitHub
co-authored by Omar Hatem
parent 5a7ea87543
commit 109bba4301
133 changed files with 5356 additions and 353 deletions
+107 -6
View File
@@ -7,6 +7,7 @@ const ethereumOutputPath = 'lib/ethereum/ethereum.dart';
const bitcoinCashOutputPath = 'lib/bitcoin_cash/bitcoin_cash.dart';
const nanoOutputPath = 'lib/nano/nano.dart';
const polygonOutputPath = 'lib/polygon/polygon.dart';
const solanaOutputPath = 'lib/solana/solana.dart';
const walletTypesPath = 'lib/wallet_types.g.dart';
const pubspecDefaultPath = 'pubspec_default.yaml';
const pubspecOutputPath = 'pubspec.yaml';
@@ -21,6 +22,7 @@ Future<void> main(List<String> args) async {
final hasNano = args.contains('${prefix}nano');
final hasBanano = args.contains('${prefix}banano');
final hasPolygon = args.contains('${prefix}polygon');
final hasSolana = args.contains('${prefix}solana');
await generateBitcoin(hasBitcoin);
await generateMonero(hasMonero);
@@ -29,6 +31,7 @@ Future<void> main(List<String> args) async {
await generateBitcoinCash(hasBitcoinCash);
await generateNano(hasNano);
await generatePolygon(hasPolygon);
await generateSolana(hasSolana);
// await generateBanano(hasEthereum);
await generatePubspec(
@@ -40,6 +43,7 @@ Future<void> main(List<String> args) async {
hasBanano: hasBanano,
hasBitcoinCash: hasBitcoinCash,
hasPolygon: hasPolygon,
hasSolana: hasSolana,
);
await generateWalletTypes(
hasMonero: hasMonero,
@@ -50,6 +54,7 @@ Future<void> main(List<String> args) async {
hasBanano: hasBanano,
hasBitcoinCash: hasBitcoinCash,
hasPolygon: hasPolygon,
hasSolana: hasSolana,
);
}
@@ -577,13 +582,14 @@ abstract class Ethereum {
int formatterEthereumParseAmount(String amount);
double formatterEthereumAmountToDouble({TransactionInfo? transaction, BigInt? amount, int exponent = 18});
List<Erc20Token> getERC20Currencies(WalletBase wallet);
Future<void> addErc20Token(WalletBase wallet, Erc20Token token);
Future<void> deleteErc20Token(WalletBase wallet, Erc20Token token);
Future<void> addErc20Token(WalletBase wallet, CryptoCurrency token);
Future<void> deleteErc20Token(WalletBase wallet, CryptoCurrency token);
Future<Erc20Token?> getErc20Token(WalletBase wallet, String contractAddress);
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction);
void updateEtherscanUsageState(WalletBase wallet, bool isEnabled);
Web3Client? getWeb3Client(WalletBase wallet);
String getTokenAddress(CryptoCurrency asset);
}
""";
@@ -669,13 +675,14 @@ abstract class Polygon {
int formatterPolygonParseAmount(String amount);
double formatterPolygonAmountToDouble({TransactionInfo? transaction, BigInt? amount, int exponent = 18});
List<Erc20Token> getERC20Currencies(WalletBase wallet);
Future<void> addErc20Token(WalletBase wallet, Erc20Token token);
Future<void> deleteErc20Token(WalletBase wallet, Erc20Token token);
Future<void> addErc20Token(WalletBase wallet, CryptoCurrency token);
Future<void> deleteErc20Token(WalletBase wallet, CryptoCurrency token);
Future<Erc20Token?> getErc20Token(WalletBase wallet, String contractAddress);
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction);
void updatePolygonScanUsageState(WalletBase wallet, bool isEnabled);
Web3Client? getWeb3Client(WalletBase wallet);
String getTokenAddress(CryptoCurrency asset);
}
""";
@@ -885,6 +892,86 @@ abstract class NanoUtil {
await outputFile.writeAsString(output);
}
Future<void> generateSolana(bool hasImplementation) async {
final outputFile = File(solanaOutputPath);
const solanaCommonHeaders = """
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/output_info.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:hive/hive.dart';
""";
const solanaCWHeaders = """
import 'package:cw_solana/spl_token.dart';
import 'package:cw_solana/solana_wallet.dart';
import 'package:cw_solana/solana_mnemonics.dart';
import 'package:cw_solana/solana_wallet_service.dart';
import 'package:cw_solana/solana_transaction_info.dart';
import 'package:cw_solana/solana_transaction_credentials.dart';
import 'package:cw_solana/solana_wallet_creation_credentials.dart';
import 'package:solana/solana.dart';
""";
const solanaCwPart = "part 'cw_solana.dart';";
const solanaContent = """
abstract class Solana {
List<String> getSolanaWordList(String language);
WalletService createSolanaWalletService(Box<WalletInfo> walletInfoSource);
WalletCredentials createSolanaNewWalletCredentials(
{required String name, WalletInfo? walletInfo});
WalletCredentials createSolanaRestoreWalletFromSeedCredentials(
{required String name, required String mnemonic, required String password});
WalletCredentials createSolanaRestoreWalletFromPrivateKey(
{required String name, required String privateKey, required String password});
String getAddress(WalletBase wallet);
String getPrivateKey(WalletBase wallet);
String getPublicKey(WalletBase wallet);
Ed25519HDKeyPair? getWalletKeyPair(WalletBase wallet);
Object createSolanaTransactionCredentials(
List<Output> outputs, {
required CryptoCurrency currency,
});
Object createSolanaTransactionCredentialsRaw(
List<OutputInfo> outputs, {
required CryptoCurrency currency,
});
List<SPLToken> getSPLTokenCurrencies(WalletBase wallet);
Future<void> addSPLToken(WalletBase wallet, CryptoCurrency token);
Future<void> deleteSPLToken(WalletBase wallet, CryptoCurrency token);
Future<SPLToken?> getSPLToken(WalletBase wallet, String contractAddress);
CryptoCurrency assetOfTransaction(WalletBase wallet, TransactionInfo transaction);
double getTransactionAmountRaw(TransactionInfo transactionInfo);
String getTokenAddress(CryptoCurrency asset);
List<int>? getValidationLength(CryptoCurrency type);
}
""";
const solanaEmptyDefinition = 'Solana? solana;\n';
const solanaCWDefinition = 'Solana? solana = CWSolana();\n';
final output = '$solanaCommonHeaders\n' +
(hasImplementation ? '$solanaCWHeaders\n' : '\n') +
(hasImplementation ? '$solanaCwPart\n\n' : '\n') +
(hasImplementation ? solanaCWDefinition : solanaEmptyDefinition) +
'\n' +
solanaContent;
if (outputFile.existsSync()) {
await outputFile.delete();
}
await outputFile.writeAsString(output);
}
Future<void> generatePubspec(
{required bool hasMonero,
required bool hasBitcoin,
@@ -893,7 +980,8 @@ Future<void> generatePubspec(
required bool hasNano,
required bool hasBanano,
required bool hasBitcoinCash,
required bool hasPolygon}) async {
required bool hasPolygon,
required bool hasSolana}) async {
const cwCore = """
cw_core:
path: ./cw_core
@@ -934,6 +1022,10 @@ Future<void> generatePubspec(
cw_polygon:
path: ./cw_polygon
""";
const cwSolana = """
cw_solana:
path: ./cw_solana
""";
const cwEVM = """
cw_evm:
path: ./cw_evm
@@ -972,6 +1064,10 @@ Future<void> generatePubspec(
output += '\n$cwPolygon';
}
if (hasSolana) {
output += '\n$cwSolana';
}
if (hasHaven && !hasMonero) {
output += '\n$cwSharedExternal\n$cwHaven';
} else if (hasHaven) {
@@ -1002,7 +1098,8 @@ Future<void> generateWalletTypes(
required bool hasNano,
required bool hasBanano,
required bool hasBitcoinCash,
required bool hasPolygon}) async {
required bool hasPolygon,
required bool hasSolana}) async {
final walletTypesFile = File(walletTypesPath);
if (walletTypesFile.existsSync()) {
@@ -1037,6 +1134,10 @@ Future<void> generateWalletTypes(
outputContent += '\tWalletType.polygon,\n';
}
if (hasSolana) {
outputContent += '\tWalletType.solana,\n';
}
if (hasNano) {
outputContent += '\tWalletType.nano,\n';
}
+19 -1
View File
@@ -5,6 +5,7 @@ import 'utils/utils.dart';
const configPath = 'tool/.secrets-config.json';
const evmChainsConfigPath = 'tool/.evm-secrets-config.json';
const solanaConfigPath = 'tool/.solana-secrets-config.json';
Future<void> main(List<String> args) async => generateSecretsConfig(args);
@@ -18,8 +19,10 @@ Future<void> generateSecretsConfig(List<String> args) async {
final configFile = File(configPath);
final evmChainsConfigFile = File(evmChainsConfigPath);
final secrets = <String, dynamic>{};
final solanaConfigFile = File(solanaConfigPath);
final secrets = <String, dynamic>{};
secrets.addAll(extraInfo);
secrets.removeWhere((key, dynamic value) {
if (key.contains('--')) {
@@ -49,6 +52,7 @@ Future<void> generateSecretsConfig(List<String> args) async {
await configFile.writeAsString(secretsJson);
secrets.clear();
SecretKey.evmChainsSecrets.forEach((sec) {
if (secrets[sec.name] != null) {
return;
@@ -60,4 +64,18 @@ Future<void> generateSecretsConfig(List<String> args) async {
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
await evmChainsConfigFile.writeAsString(secretsJson);
secrets.clear();
SecretKey.solanaSecrets.forEach((sec) {
if (secrets[sec.name] != null) {
return;
}
secrets[sec.name] = sec.generate();
});
secretsJson = JsonEncoder.withIndent(' ').convert(secrets);
await solanaConfigFile.writeAsString(secretsJson);
}
+14
View File
@@ -8,6 +8,8 @@ const outputPath = 'lib/.secrets.g.dart';
const evmChainsConfigPath = 'tool/.evm-secrets-config.json';
const evmChainsOutputPath = 'cw_evm/lib/.secrets.g.dart';
const solanaConfigPath = 'tool/.solana-secrets-config.json';
const solanaOutputPath = 'cw_solana/lib/.secrets.g.dart';
Future<void> main(List<String> args) async => importSecretsConfig();
Future<void> importSecretsConfig() async {
@@ -21,6 +23,12 @@ Future<void> importSecretsConfig() async {
final evmChainsOutput = evmChainsInput.keys
.fold('', (String acc, String val) => acc + generateConst(val, evmChainsInput));
final solanaOutputFile = File(solanaOutputPath);
final solanaInput =
json.decode(File(solanaConfigPath).readAsStringSync()) as Map<String, dynamic>;
final solanaOutput =
solanaInput.keys.fold('', (String acc, String val) => acc + generateConst(val, solanaInput));
if (outputFile.existsSync()) {
await outputFile.delete();
}
@@ -32,4 +40,10 @@ Future<void> importSecretsConfig() async {
}
await evmChainsOutputFile.writeAsString(evmChainsOutput);
if (solanaOutputFile.existsSync()) {
await solanaOutputFile.delete();
}
await solanaOutputFile.writeAsString(solanaOutput);
}
+4
View File
@@ -44,6 +44,10 @@ class SecretKey {
SecretKey('polygonScanApiKey', () => ''),
];
static final solanaSecrets = [
SecretKey('ankrApiKey', () => ''),
];
final String name;
final String Function() generate;
}