From 67b2f34cbb8a861b7a6d9b04783af9b421c83de1 Mon Sep 17 00:00:00 2001 From: Jean Ribeiro Date: Wed, 18 Sep 2024 10:18:40 -0300 Subject: [PATCH] feat: adds initial BNB chain support (#2825) * feat: adds initial BNB chain support * fix: pr review comments --------- Co-authored-by: Nicole O'Brien --- .../enums/etherscan-explorer-endpoint.enum.ts | 5 +++ .../explorer/enums/explorer-type.enum.ts | 1 + .../src/lib/auxiliary/explorer/enums/index.ts | 1 + .../explorer/utils/getExplorerEndpoint.ts | 19 +++++++++-- .../constants/default-base-token.constant.ts | 18 +++++++++++ .../constants/default-coin-type.constant.ts | 2 ++ ...gurations-for-stardust-network.constant.ts | 32 ++++++++++++++++++- .../default-explorer-configs.constant.ts | 10 ++++++ .../supported-network-id.constant.ts | 2 ++ .../lib/core/network/enums/chain-id.enum.ts | 4 +++ 10 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 packages/shared/src/lib/auxiliary/explorer/enums/etherscan-explorer-endpoint.enum.ts diff --git a/packages/shared/src/lib/auxiliary/explorer/enums/etherscan-explorer-endpoint.enum.ts b/packages/shared/src/lib/auxiliary/explorer/enums/etherscan-explorer-endpoint.enum.ts new file mode 100644 index 0000000000..584b59ab65 --- /dev/null +++ b/packages/shared/src/lib/auxiliary/explorer/enums/etherscan-explorer-endpoint.enum.ts @@ -0,0 +1,5 @@ +export enum EtherscanExplorerEndpoint { + Address = 'address', + Token = 'token', + Transaction = 'tx', +} diff --git a/packages/shared/src/lib/auxiliary/explorer/enums/explorer-type.enum.ts b/packages/shared/src/lib/auxiliary/explorer/enums/explorer-type.enum.ts index 36977e0813..86e3ac4cb1 100644 --- a/packages/shared/src/lib/auxiliary/explorer/enums/explorer-type.enum.ts +++ b/packages/shared/src/lib/auxiliary/explorer/enums/explorer-type.enum.ts @@ -1,4 +1,5 @@ export enum ExplorerType { Stardust = 'stardust', Blockscout = 'blockscout', + Etherscan = 'etherscan', } diff --git a/packages/shared/src/lib/auxiliary/explorer/enums/index.ts b/packages/shared/src/lib/auxiliary/explorer/enums/index.ts index 939431eea1..37ca1499fd 100644 --- a/packages/shared/src/lib/auxiliary/explorer/enums/index.ts +++ b/packages/shared/src/lib/auxiliary/explorer/enums/index.ts @@ -1,4 +1,5 @@ export * from './blockscout-explorer-endpoint.enum' +export * from './etherscan-explorer-endpoint.enum' export * from './explorer-endpoint.enum' export * from './explorer-type.enum' export * from './stardust-explorer-endpoint.enum' diff --git a/packages/shared/src/lib/auxiliary/explorer/utils/getExplorerEndpoint.ts b/packages/shared/src/lib/auxiliary/explorer/utils/getExplorerEndpoint.ts index 2e2b1e601a..2e1619724b 100644 --- a/packages/shared/src/lib/auxiliary/explorer/utils/getExplorerEndpoint.ts +++ b/packages/shared/src/lib/auxiliary/explorer/utils/getExplorerEndpoint.ts @@ -1,4 +1,9 @@ -import { BlockscoutExplorerEndpoint, ExplorerEndpoint, StardustExplorerEndpoint } from '../enums' +import { + BlockscoutExplorerEndpoint, + EtherscanExplorerEndpoint, + ExplorerEndpoint, + StardustExplorerEndpoint, +} from '../enums' import { ExplorerType } from '@auxiliary/explorer' const STARDUST_EXPLORER_ENDPOINTS: Readonly<{ [key in ExplorerEndpoint]?: string }> = { @@ -15,15 +20,23 @@ const BLOCKSCOUT_EXPLORER_ENDPOINTS: Readonly<{ [key in ExplorerEndpoint]?: stri [ExplorerEndpoint.Address]: BlockscoutExplorerEndpoint.Address, } +const ETHERSCAN_EXPLORER_ENDPOINTS: Readonly<{ [key in ExplorerEndpoint]?: string }> = { + [ExplorerEndpoint.Transaction]: EtherscanExplorerEndpoint.Transaction, + [ExplorerEndpoint.Token]: EtherscanExplorerEndpoint.Token, + [ExplorerEndpoint.Address]: EtherscanExplorerEndpoint.Address, +} + export function getExplorerEndpoint( explorerType: ExplorerType | undefined, explorerEndpoint: ExplorerEndpoint ): string | undefined { switch (explorerType) { - case ExplorerType.Blockscout: - return BLOCKSCOUT_EXPLORER_ENDPOINTS[explorerEndpoint] case ExplorerType.Stardust: return STARDUST_EXPLORER_ENDPOINTS[explorerEndpoint] + case ExplorerType.Blockscout: + return BLOCKSCOUT_EXPLORER_ENDPOINTS[explorerEndpoint] + case ExplorerType.Etherscan: + return ETHERSCAN_EXPLORER_ENDPOINTS[explorerEndpoint] default: return undefined } diff --git a/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts b/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts index c05420df9f..dd6b2a9da9 100644 --- a/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-base-token.constant.ts @@ -53,6 +53,22 @@ export const EVM_BASE_TOKEN: IBaseToken = { decimals: 18, } +export const BNB_BASE_TOKEN: IBaseToken = { + standard: TokenStandard.BaseToken, + name: 'BNB', + tickerSymbol: 'BNB', + unit: 'BNB', + decimals: 18, +} + +export const BNB_TESTNET_BASE_TOKEN: IBaseToken = { + standard: TokenStandard.BaseToken, + name: 'Test BNB', + tickerSymbol: 'tBNB', + unit: 'tBNB', + decimals: 18, +} + export const DEFAULT_BASE_TOKEN: Readonly<{ [id in NetworkId]: IBaseToken }> = { [SupportedNetworkId.Iota]: IOTA_BASE_TOKEN, [SupportedNetworkId.Shimmer]: SHIMMER_BASE_TOKEN, @@ -65,4 +81,6 @@ export const DEFAULT_BASE_TOKEN: Readonly<{ [id in NetworkId]: IBaseToken }> = { [SupportedNetworkId.Ethereum]: EVM_BASE_TOKEN, [SupportedNetworkId.Sepolia]: EVM_BASE_TOKEN, [SupportedNetworkId.GenericEvm]: EVM_BASE_TOKEN, + [SupportedNetworkId.Bnb]: BNB_BASE_TOKEN, + [SupportedNetworkId.BnbTestnet]: BNB_TESTNET_BASE_TOKEN, } diff --git a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts index 9dfd86839e..30598f9bea 100644 --- a/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-coin-type.constant.ts @@ -18,4 +18,6 @@ export const DEFAULT_COIN_TYPE: Readonly<{ [key in NetworkId]: number }> = { [SupportedNetworkId.Ethereum]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.Sepolia]: ETHEREUM_COIN_TYPE, [SupportedNetworkId.GenericEvm]: ETHEREUM_COIN_TYPE, + [SupportedNetworkId.Bnb]: ETHEREUM_COIN_TYPE, + [SupportedNetworkId.BnbTestnet]: ETHEREUM_COIN_TYPE, } diff --git a/packages/shared/src/lib/core/network/constants/default-evm-network-configurations-for-stardust-network.constant.ts b/packages/shared/src/lib/core/network/constants/default-evm-network-configurations-for-stardust-network.constant.ts index 17d2703db8..bdfa5a81b3 100644 --- a/packages/shared/src/lib/core/network/constants/default-evm-network-configurations-for-stardust-network.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-evm-network-configurations-for-stardust-network.constant.ts @@ -2,7 +2,7 @@ import { isFeatureEnabled } from '@lib/features/utils' import { ChainId, NetworkNamespace, NetworkType } from '../enums' import { IPureEvmNetworkConfiguration } from '../interfaces' import { StardustNetworkId } from '../types' -import { EVM_BASE_TOKEN } from './default-base-token.constant' +import { BNB_BASE_TOKEN, BNB_TESTNET_BASE_TOKEN, EVM_BASE_TOKEN } from './default-base-token.constant' import { DEFAULT_COIN_TYPE } from './default-coin-type.constant' import { DEFAULT_EXPLORER_CONFIGS } from './default-explorer-configs.constant' import { @@ -95,6 +95,20 @@ export const IMMUTABLE_NETWORK_CONFIGURATION: IPureEvmNetworkConfiguration = { rpcEndpoint: 'https://rpc.immutable.com', } +// BNB Mainnet + +export const BNB_NETWORK_CONFIGURATION: IPureEvmNetworkConfiguration = { + type: NetworkType.Evm, + name: 'BNB Smart Chain', + baseToken: BNB_BASE_TOKEN, + id: SupportedL1EvmNetworkId.Bnb, + chainId: ChainId.Bnb, + namespace: NetworkNamespace.Evm, + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.Bnb] ?? 0, + explorer: DEFAULT_EXPLORER_CONFIGS[SupportedNetworkId.Bnb], + rpcEndpoint: 'https://bsc-dataseed1.binance.org/', +} + // Ethereum Sepolia Testnet export const SEPOLIA_NETWORK_CONFIGURATION: IPureEvmNetworkConfiguration = { @@ -177,6 +191,20 @@ export const IMMUTABLE_TESTNET_NETWORK_CONFIGURATION: IPureEvmNetworkConfigurati rpcEndpoint: 'https://rpc.testnet.immutable.com', } +// BNB Testnets + +export const BNB_TESTNET_NETWORK_CONFIGURATION: IPureEvmNetworkConfiguration = { + type: NetworkType.Evm, + name: 'BNB Smart Chain Testnet', + baseToken: BNB_TESTNET_BASE_TOKEN, + id: SupportedL1EvmNetworkId.BnbTestnet, + chainId: ChainId.BnbTestnet, + namespace: NetworkNamespace.Evm, + coinType: DEFAULT_COIN_TYPE[SupportedNetworkId.BnbTestnet] ?? 0, + explorer: DEFAULT_EXPLORER_CONFIGS[SupportedNetworkId.BnbTestnet], + rpcEndpoint: 'https://data-seed-prebsc-1-s1.binance.org:8545', +} + export const KNOWN_EVM_MAINNET_NETWORKS_CONFIGURATIONS: Readonly = [ ETHEREUM_NETWORK_CONFIGURATION, ARBITRUM_NETWORK_CONFIGURATION, @@ -184,6 +212,7 @@ export const KNOWN_EVM_MAINNET_NETWORKS_CONFIGURATIONS: Readonly = [ @@ -193,6 +222,7 @@ export const KNOWN_EVM_TESTNET_NETWORKS_CONFIGURATIONS: Readonly = [ diff --git a/packages/shared/src/lib/core/network/constants/default-explorer-configs.constant.ts b/packages/shared/src/lib/core/network/constants/default-explorer-configs.constant.ts index 0b0d005ffc..4205945306 100644 --- a/packages/shared/src/lib/core/network/constants/default-explorer-configs.constant.ts +++ b/packages/shared/src/lib/core/network/constants/default-explorer-configs.constant.ts @@ -83,6 +83,16 @@ export const DEFAULT_EXPLORER_CONFIGS: Readonly<{ [key in NetworkId]?: IExplorer url: 'https://blast-testnet.blockscout.com', }, + // BNB Smart Chain + [SupportedNetworkId.Bnb]: { + type: ExplorerType.Etherscan, + url: 'https://bscscan.com', + }, + [SupportedNetworkId.BnbTestnet]: { + type: ExplorerType.Etherscan, + url: 'https://testnet.bscscan.com', + }, + // Immutable [SupportedNetworkId.Immutable]: { type: ExplorerType.Blockscout, diff --git a/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts b/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts index 3e99c9941d..e7e9d3ea71 100644 --- a/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts +++ b/packages/shared/src/lib/core/network/constants/supported-network-id.constant.ts @@ -21,6 +21,8 @@ export const SupportedL1EvmNetworkId: Record = { GenericEvm: `${NetworkNamespace.Evm}:*`, Ethereum: `${NetworkNamespace.Evm}:${ChainId.Ethereum}`, Sepolia: `${NetworkNamespace.Evm}:${ChainId.Sepolia}`, + Bnb: `${NetworkNamespace.Evm}:${ChainId.Bnb}`, + BnbTestnet: `${NetworkNamespace.Evm}:${ChainId.BnbTestnet}`, } export const SupportedL2EvmNetworkId: Record = { diff --git a/packages/shared/src/lib/core/network/enums/chain-id.enum.ts b/packages/shared/src/lib/core/network/enums/chain-id.enum.ts index 192c960da0..b5824d6bd1 100644 --- a/packages/shared/src/lib/core/network/enums/chain-id.enum.ts +++ b/packages/shared/src/lib/core/network/enums/chain-id.enum.ts @@ -23,6 +23,10 @@ export enum ChainId { Blast = '81457', BlastSepoliaTestnet = '168587773', + // BNB + Bnb = '56', + BnbTestnet = '97', + // Optimism Optimism = '10', OptimismSepoliaTestnet = '11155420',