Skip to content

Commit

Permalink
feat: adds initial BNB chain support (#2825)
Browse files Browse the repository at this point in the history
* feat: adds initial BNB chain support

* fix: pr review comments

---------

Co-authored-by: Nicole O'Brien <[email protected]>
  • Loading branch information
jeeanribeiro and nicole-obrien authored Sep 18, 2024
1 parent 05f471d commit 67b2f34
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum EtherscanExplorerEndpoint {
Address = 'address',
Token = 'token',
Transaction = 'tx',
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum ExplorerType {
Stardust = 'stardust',
Blockscout = 'blockscout',
Etherscan = 'etherscan',
}
1 change: 1 addition & 0 deletions packages/shared/src/lib/auxiliary/explorer/enums/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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 }> = {
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -177,13 +191,28 @@ 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<IPureEvmNetworkConfiguration[]> = [
ETHEREUM_NETWORK_CONFIGURATION,
ARBITRUM_NETWORK_CONFIGURATION,
BASE_NETWORK_CONFIGURATION,
BLAST_NETWORK_CONFIGURATION,
OPTIMISM_NETWORK_CONFIGURATION,
IMMUTABLE_NETWORK_CONFIGURATION,
BNB_NETWORK_CONFIGURATION,
]

export const KNOWN_EVM_TESTNET_NETWORKS_CONFIGURATIONS: Readonly<IPureEvmNetworkConfiguration[]> = [
Expand All @@ -193,6 +222,7 @@ export const KNOWN_EVM_TESTNET_NETWORKS_CONFIGURATIONS: Readonly<IPureEvmNetwork
BLAST_TESTNET_NETWORK_CONFIGURATION,
OPTIMISM_TESTNET_NETWORK_CONFIGURATION,
IMMUTABLE_TESTNET_NETWORK_CONFIGURATION,
BNB_TESTNET_NETWORK_CONFIGURATION,
]

export const KNOWN_EVM_NETWORKS_CONFIGURATIONS: Readonly<IPureEvmNetworkConfiguration[]> = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const SupportedL1EvmNetworkId: Record<string, EvmNetworkId> = {
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<string, EvmNetworkId> = {
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/lib/core/network/enums/chain-id.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export enum ChainId {
Blast = '81457',
BlastSepoliaTestnet = '168587773',

// BNB
Bnb = '56',
BnbTestnet = '97',

// Optimism
Optimism = '10',
OptimismSepoliaTestnet = '11155420',
Expand Down

0 comments on commit 67b2f34

Please sign in to comment.