mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-27 06:18:50 +01:00
* feat: Add Binance Smart Chain support to wallet types and EVM chain registry * feat: Add BSC node list and support in wallet type and chain ID mappings * feat: Add BSC default tokens and update evm utility functions * feat: Integrate BSC support in node settings and management * feat: Add BSC support to config scripts and wallet type generation * feat: Add BSC support to EVM chain ID and switcher * feat: Extend BSC support in wallet utilities and chain type checks * feat: Add BSC support to different wallet functions * feat: Add BSCURI class and implement for uri handling * feat: Update Android and iOS configurations to support BSC URL schemes * feat: Add BSC support to different functionalities and settings * refactor: Update wallet type name from'Binance Smart Chain' to BNB Smart Chain * feat: Add switcher icon and updates token utils * Review fixes * More changes to BSC name, wallet listing and images * Add more default tokens
239 lines
6.5 KiB
Dart
239 lines
6.5 KiB
Dart
import 'package:cw_core/crypto_currency.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:cw_evm/utils/network_chain_utils.dart';
|
|
|
|
/// Centralized registry for all EVM chain configurations
|
|
class EvmChainRegistry {
|
|
static final EvmChainRegistry _instance = EvmChainRegistry._internal();
|
|
factory EvmChainRegistry() => _instance;
|
|
EvmChainRegistry._internal() {
|
|
initialize();
|
|
}
|
|
|
|
final Map<int, ChainConfig> _chains = {};
|
|
final Map<WalletType, int> _walletTypeToChainId = {};
|
|
final Map<int, WalletType> _chainIdToWalletType = {};
|
|
final Map<String, int> _tagToChainId = {};
|
|
final Map<String, int> _caip2ToChainId = {};
|
|
|
|
bool _initialized = false;
|
|
|
|
/// Initialize registry with all supported EVM chains
|
|
void initialize() {
|
|
if (_initialized) return;
|
|
_initialized = true;
|
|
|
|
// Ethereum Mainnet
|
|
_registerChain(
|
|
const ChainConfig(
|
|
chainId: 1,
|
|
name: 'Ethereum',
|
|
shortCode: 'eth',
|
|
caip2: 'eip155:1',
|
|
nativeCurrency: CryptoCurrency.eth,
|
|
capabilities: ChainCapabilities(
|
|
supportsERC20: true,
|
|
supportsEIP1559: true,
|
|
supportsInternalTx: true,
|
|
supportsSubscriptions: false,
|
|
supportsENS: true,
|
|
),
|
|
defaultRpcEndpoints: [
|
|
'ethereum-rpc.publicnode.com',
|
|
'eth.llamarpc.com',
|
|
'rpc.flashbots.net',
|
|
'eth-mainnet.public.blastapi.io',
|
|
'eth.nownodes.io',
|
|
'ethereum.publicnode.com',
|
|
],
|
|
explorerUrls: [
|
|
'https://etherscan.io',
|
|
],
|
|
feeModel: FeeModel(
|
|
type: FeeType.eip1559,
|
|
defaultGasLimit: 21000,
|
|
),
|
|
),
|
|
WalletType.ethereum,
|
|
'ETH',
|
|
);
|
|
|
|
// Polygon
|
|
_registerChain(
|
|
const ChainConfig(
|
|
chainId: 137,
|
|
name: 'Polygon',
|
|
shortCode: 'polygon',
|
|
caip2: 'eip155:137',
|
|
nativeCurrency: CryptoCurrency.maticpoly,
|
|
capabilities: ChainCapabilities(
|
|
supportsERC20: true,
|
|
supportsEIP1559: true,
|
|
supportsInternalTx: true,
|
|
supportsSubscriptions: false,
|
|
supportsENS: false,
|
|
),
|
|
defaultRpcEndpoints: [
|
|
'polygon-rpc.com',
|
|
'polygon-bor-rpc.publicnode.com',
|
|
'polygon.llamarpc.com',
|
|
'matic.nownodes.io',
|
|
],
|
|
explorerUrls: [
|
|
'https://polygonscan.com',
|
|
],
|
|
feeModel: FeeModel(
|
|
type: FeeType.eip1559,
|
|
defaultGasLimit: 21000,
|
|
),
|
|
),
|
|
WalletType.polygon,
|
|
'POL',
|
|
);
|
|
|
|
// Base
|
|
_registerChain(
|
|
const ChainConfig(
|
|
chainId: 8453,
|
|
name: 'Base',
|
|
shortCode: 'base',
|
|
caip2: 'eip155:8453',
|
|
nativeCurrency: CryptoCurrency.baseEth,
|
|
capabilities: ChainCapabilities(
|
|
supportsERC20: true,
|
|
supportsEIP1559: true,
|
|
supportsInternalTx: true,
|
|
supportsSubscriptions: false,
|
|
supportsENS: false,
|
|
),
|
|
defaultRpcEndpoints: [
|
|
'base.nownodes.io',
|
|
'base.llamarpc.com',
|
|
'base-rpc.publicnode.com',
|
|
'1rpc.io/base',
|
|
],
|
|
explorerUrls: [
|
|
'https://basescan.org',
|
|
],
|
|
feeModel: FeeModel(
|
|
type: FeeType.eip1559,
|
|
defaultGasLimit: 21000,
|
|
),
|
|
),
|
|
WalletType.base,
|
|
'BASE',
|
|
);
|
|
|
|
// Arbitrum
|
|
_registerChain(
|
|
const ChainConfig(
|
|
chainId: 42161,
|
|
name: 'Arbitrum',
|
|
shortCode: 'arbitrum',
|
|
caip2: 'eip155:42161',
|
|
nativeCurrency: CryptoCurrency.arbEth,
|
|
capabilities: ChainCapabilities(
|
|
supportsERC20: true,
|
|
supportsEIP1559: true,
|
|
supportsInternalTx: true,
|
|
supportsSubscriptions: false,
|
|
supportsENS: false,
|
|
),
|
|
defaultRpcEndpoints: [
|
|
'arbitrum.nownodes.io',
|
|
'arbitrum.drpc.org',
|
|
'arbitrum-one-rpc.publicnode.com',
|
|
],
|
|
explorerUrls: [
|
|
'https://arbiscan.io',
|
|
],
|
|
feeModel: FeeModel(
|
|
type: FeeType.eip1559,
|
|
defaultGasLimit: 21000,
|
|
),
|
|
),
|
|
WalletType.arbitrum,
|
|
'ARB',
|
|
);
|
|
|
|
// BNB Smart Chain
|
|
_registerChain(
|
|
const ChainConfig(
|
|
chainId: 56,
|
|
name: 'BNB Smart Chain',
|
|
shortCode: 'bsc',
|
|
caip2: 'eip155:56',
|
|
nativeCurrency: CryptoCurrency.bnb,
|
|
capabilities: ChainCapabilities(
|
|
supportsERC20: true,
|
|
supportsEIP1559: true,
|
|
supportsInternalTx: true,
|
|
supportsSubscriptions: false,
|
|
supportsENS: false,
|
|
),
|
|
defaultRpcEndpoints: [
|
|
'bsc-dataseed1.binance.org',
|
|
'bsc-dataseed2.binance.org',
|
|
'bsc-dataseed1.defibit.io',
|
|
'bsc-dataseed1.nodereal.io',
|
|
'bsc.llamarpc.com',
|
|
'bsc-rpc.publicnode.com',
|
|
],
|
|
explorerUrls: [
|
|
'https://bscscan.com',
|
|
],
|
|
feeModel: FeeModel(
|
|
type: FeeType.eip1559,
|
|
defaultGasLimit: 21000,
|
|
),
|
|
),
|
|
WalletType.bsc,
|
|
'BSC',
|
|
);
|
|
}
|
|
|
|
void _registerChain(
|
|
ChainConfig config,
|
|
WalletType walletType,
|
|
String tag,
|
|
) {
|
|
_chains[config.chainId] = config;
|
|
_walletTypeToChainId[walletType] = config.chainId;
|
|
_chainIdToWalletType[config.chainId] = walletType;
|
|
_tagToChainId[tag.toUpperCase()] = config.chainId;
|
|
_caip2ToChainId[config.caip2] = config.chainId;
|
|
}
|
|
|
|
ChainConfig? getChainConfig(int chainId) => _chains[chainId];
|
|
|
|
ChainConfig? getChainConfigByWalletType(WalletType walletType) {
|
|
final chainId = _walletTypeToChainId[walletType];
|
|
return chainId != null ? _chains[chainId] : null;
|
|
}
|
|
|
|
/// Get chain configuration by tag (e.g., 'ETH', 'POL', 'BASE', 'ARB')
|
|
ChainConfig? getChainConfigByTag(String tag) {
|
|
final chainId = _tagToChainId[tag.toUpperCase()];
|
|
return chainId != null ? _chains[chainId] : null;
|
|
}
|
|
|
|
/// Get chain configuration by CAIP-2 identifier (e.g. 'eip155:1')
|
|
ChainConfig? getChainConfigByCaip2(String caip2) {
|
|
final chainId = _caip2ToChainId[caip2];
|
|
return chainId != null ? _chains[chainId] : null;
|
|
}
|
|
|
|
WalletType? getWalletTypeByChainId(int chainId) => _chainIdToWalletType[chainId];
|
|
|
|
int? getChainIdByWalletType(WalletType walletType) => _walletTypeToChainId[walletType];
|
|
|
|
bool isChainRegistered(int chainId) => _chains.containsKey(chainId);
|
|
|
|
List<int> getRegisteredChainIds() => _chains.keys.toList();
|
|
|
|
List<ChainConfig> getAllChains() => _chains.values.toList();
|
|
|
|
List<WalletType> getRegisteredWalletTypes() =>
|
|
_walletTypeToChainId.keys.toList();
|
|
}
|