import { toBN } from 'web3-utils' ; export enum CHAINS { MAINNET = '1' , MORDEN = '2' , ROPSTEN = '3' , RINKEBY = '4' , GOERLI = '5' , OPTIMISM = '10' , KOVAN = '42' , BSC = '56' , XDAI = '100' , POLYGON = '137' , ENERGY_WEB_CHAIN = '246' , AVALANCHE = '43114' , ARBITRUM = '42161' , VOLTA = '73799' } export const rpcUrlGetterByNetwork = { [ CHAINS . MAINNET ] : ( token ) => `https://mainnet.infura.io/v3/${ token }` , [ CHAINS . MORDEN ] : null , [ CHAINS . ROPSTEN ] : null , [ CHAINS . RINKEBY ] : ( token ) => `https://rinkeby.infura.io/v3/${ token }` , [ CHAINS . GOERLI ] : null , [ CHAINS . OPTIMISM ] : ( ) => 'https://mainnet.optimism.io' , [ CHAINS . KOVAN ] : null , [ CHAINS . BSC ] : ( ) => 'https://bsc-dataseed.binance.org' , [ CHAINS . XDAI ] : ( ) => 'https://dai.poa.network' , [ CHAINS . POLYGON ] : ( ) => 'https://rpc-mainnet.matic.network' , [ CHAINS . ENERGY_WEB_CHAIN ] : ( ) => 'https://rpc.energyweb.org' , [ CHAINS . ARBITRUM ] : ( ) => 'https://arb1.arbitrum.io/rpc' , [ CHAINS . AVALANCHE ] : ( ) => 'https://api.avax.network/ext/bc/C/rpc' , [ CHAINS . VOLTA ] : ( ) => 'https://volta-rpc.energyweb.org' , } ; type InputType = { internalType : string ; name : string ; type : string ; components : InputType [ ] ; } ; export const getInputHelper = ( input ) => { if ( input . type . startsWith ( 'tuple' ) ) { return `tuple(${ input . components . map ( ( c ) => c . internalType ) . toString ( ) })${ input . type . endsWith ( '[]' ) ? '[]' : '' }` ; } else { return input . type ; } } ; export const paramTypeNumber = new RegExp ( /^(u?int)([0-9]*)$/ ) ; export const parseInputValue = ( input , value ) : any => { const isNumberInput = paramTypeNumber . test ( input . type ) ; const isBooleanInput = input . type === 'bool' ; if ( value . charAt ( 0 ) === '[' ) { return JSON . parse ( value . replace ( /"/g , '"' ) ) ; } if ( isBooleanInput ) { return value . toLowerCase ( ) === 'true' ; } if ( isNumberInput && value ) { const bitWidth = input . type . match ( paramTypeNumber ) [ 2 ] ; return toBN ( value ) . toString ( 10 , bitWidth ) ; } return value ; } ; export const isInputValueValid = ( val ) => { const value = Number ( val ) ; if ( isNaN ( value ) || value < 0 ) { return false ; } return true ; } ; export const getCustomDataError = ( value ) => { return `Has to be a valid strict hex data ${ ! value ?. startsWith ( '0x' ) ? '(it must start with 0x)' : '' }` ; } ;