1- import { ChainId } from '@human-protocol/sdk' ;
21import { Injectable } from '@nestjs/common' ;
32import { ConfigService } from '@nestjs/config' ;
4- import { Web3Env } from '../enums/web3' ;
3+
54import {
6- LOCALHOST_CHAIN_IDS ,
7- MAINNET_CHAIN_IDS ,
8- TESTNET_CHAIN_IDS ,
9- } from '../utils/constants' ;
5+ DevelopmentChainId ,
6+ ProductionChainId ,
7+ ChainIds ,
8+ type ChainId ,
9+ } from '../constants' ;
1010
1111export interface TokensList {
1212 [ key : string ] : string | undefined ;
1313}
1414export interface NetworkDto {
15- chainId : number ;
15+ chainId : ChainId ;
1616 rpcUrl ?: string ;
1717}
1818
@@ -28,65 +28,53 @@ export class NetworkConfigService {
2828 this . networkMap = {
2929 ...( this . configService . get < string > ( 'RPC_URL_ETHEREUM' ) && {
3030 ethereum : {
31- chainId : ChainId . MAINNET ,
31+ chainId : ProductionChainId . ETHEREUM ,
3232 rpcUrl : this . configService . get < string > ( 'RPC_URL_ETHEREUM' ) ,
3333 } ,
3434 } ) ,
3535 ...( this . configService . get < string > ( 'RPC_URL_SEPOLIA' ) && {
3636 sepolia : {
37- chainId : ChainId . SEPOLIA ,
37+ chainId : DevelopmentChainId . SEPOLIA ,
3838 rpcUrl : this . configService . get < string > ( 'RPC_URL_SEPOLIA' ) ,
3939 } ,
4040 } ) ,
4141 ...( this . configService . get < string > ( 'RPC_URL_POLYGON' ) && {
4242 polygon : {
43- chainId : ChainId . POLYGON ,
43+ chainId : ProductionChainId . POLYGON_MAINNET ,
4444 rpcUrl : this . configService . get < string > ( 'RPC_URL_POLYGON' ) ,
4545 } ,
4646 } ) ,
4747 ...( this . configService . get < string > ( 'RPC_URL_POLYGON_AMOY' ) && {
4848 amoy : {
49- chainId : ChainId . POLYGON_AMOY ,
49+ chainId : DevelopmentChainId . POLYGON_AMOY ,
5050 rpcUrl : this . configService . get < string > ( 'RPC_URL_POLYGON_AMOY' ) ,
5151 } ,
5252 } ) ,
5353 ...( this . configService . get < string > ( 'RPC_URL_BSC_MAINNET' ) && {
5454 bsc : {
55- chainId : ChainId . BSC_MAINNET ,
55+ chainId : ProductionChainId . BSC_MAINNET ,
5656 rpcUrl : this . configService . get < string > ( 'RPC_URL_BSC_MAINNET' ) ,
5757 } ,
5858 } ) ,
5959 ...( this . configService . get < string > ( 'RPC_URL_BSC_TESTNET' ) && {
6060 bsctest : {
61- chainId : ChainId . BSC_TESTNET ,
61+ chainId : DevelopmentChainId . BSC_TESTNET ,
6262 rpcUrl : this . configService . get < string > ( 'RPC_URL_BSC_TESTNET' ) ,
6363 } ,
6464 } ) ,
6565 ...( this . configService . get < string > ( 'RPC_URL_LOCALHOST' ) && {
6666 localhost : {
67- chainId : ChainId . LOCALHOST ,
67+ chainId : DevelopmentChainId . LOCALHOST ,
6868 rpcUrl : this . configService . get < string > ( 'RPC_URL_LOCALHOST' ) ,
6969 } ,
7070 } ) ,
7171 } ;
72- const validChainIds = ( ( ) => {
73- switch ( this . configService . get < string > ( 'WEB3_ENV' ) ) {
74- case Web3Env . MAINNET :
75- return MAINNET_CHAIN_IDS ;
76- case Web3Env . LOCALHOST :
77- return LOCALHOST_CHAIN_IDS ;
78- default :
79- return TESTNET_CHAIN_IDS ;
80- }
81- } ) ( ) ;
8272
8373 // Remove networks without RPC URLs
8474 this . networkMap = Object . keys ( this . networkMap )
8575 . filter ( ( network ) => {
8676 const networkConfig = this . networkMap [ network ] ;
87- return (
88- networkConfig . rpcUrl && validChainIds . includes ( networkConfig . chainId )
89- ) ;
77+ return networkConfig . rpcUrl && ChainIds . includes ( networkConfig . chainId ) ;
9078 } )
9179 . reduce ( ( newNetworkMap : NetworkMapDto , network ) => {
9280 newNetworkMap [ network ] = this . networkMap [ network ] ;
0 commit comments