import { ValidationError , ValidationErrorCodes } from '@0x/api-utils' ; import { ChainId } from '@0x/contract-addresses' ; import { findTokenAddressOrThrow } from '@0x/token-metadata' ; import { addressUtils } from '@0x/utils' ; /**
 * Checks top level attributes of an object for values matching an ETH address
 * and normalizes the address by turning it to lowercase
 */ export const objectETHAddressNormalizer = < T > ( obj ) => { const normalized = { } ; for ( const [ key , value ] of Object . entries ( obj ) ) { if ( value && addressUtils . isAddress ( value as string ) ) { normalized [ key ] = ( value as string ) . toLowerCase ( ) ; } } return { ... obj , ... normalized , } ; } ; param address param chainId export function findTokenAddressOrThrowApiError ( address , field , chainId ) { try { return findTokenAddressOrThrow ( address , chainId ) ; } catch ( e ) { throw new ValidationError ( [ { field , code : ValidationErrorCodes . ValueOutOfRange , reason : e . message , } , ] ) ; } }