import { utils } from 'ethers' ; import { BN } from '../bignumber' ; import { Uint256 } from '../types' ; export function unreachable ( x ) { return x ; } export const exists = < T > ( t ) : t is T => ! ! t ; const throwError = ( fn , t ) => { throw new Error ( `not valid, ${ fn . name } failed on ${ t }` ) ; } ; type TypeGuard < T , S > = ( t1 : T | S ) => t1 is T ; export function checkThat < T , S = undefined > ( t , isTypeT ) { if ( ! isTypeT ( t ) ) { throwError ( isTypeT , t ) ; throw 'Unreachable' ; } return t ; } export function createDestination ( address ) { return utils . hexZeroPad ( address , 32 ) ; } export function formatAmount ( amount ) { return utils . hexZeroPad ( BN . from ( amount ) , 32 ) as Uint256 ; } export function arrayToRecord < T , K extends keyof T > ( array , idProperty ) { return array . reduce ( ( obj , item ) => { obj [ item [ idProperty ] ] = item ; return obj ; } , { } as any ) ; } export function recordToArray < T > ( record ) { return Object . keys ( record ) . map ( k => record [ k ] ) . filter ( e => e !== undefined ) as Array < T > ; }