import { AbiOutputParameter , AbiParameter , EvmOutputType , EvmType , TupleType } from 'typechain' ; export function codegenInputTypes ( input ) { if ( input . length === 0 ) { return '' ; } return ( input . map ( ( input , index ) => `${ input . name || `arg${ index }` }: ${ codegenInputType ( input . type ) }` ) . join ( ', ' ) + ', ' ) ; } export function codegenOutputTypes ( outputs ) { if ( outputs . length === 1 ) { return codegenOutputType ( outputs [ 0 ] . type ) ; } else { return `{${ outputs . map ( ( param , index ) => `${ index }: ${ codegenOutputType ( param . type ) }` ) . join ( ', ' ) }}` ; } } export function codegenInputType ( evmType ) { switch ( evmType . type ) { case 'integer' : return 'number | BN | string' ; case 'uinteger' : return 'number | BN | string' ; case 'address' : return 'string' ; case 'bytes' : return 'string' ; case 'dynamic-bytes' : return 'string' ; case 'array' : return `(${ codegenInputType ( evmType . itemType ) })[]` ; case 'boolean' : return 'boolean' ; case 'string' : return 'string' ; case 'tuple' : return codegenTupleType ( evmType , codegenInputType ) ; case 'unknown' : return 'any' ; } } export function codegenOutputType ( evmType ) { switch ( evmType . type ) { case 'integer' : return 'BN' ; case 'uinteger' : return 'BN' ; case 'address' : return 'string' ; case 'void' : return 'void' ; case 'bytes' : case 'dynamic-bytes' : return 'string' ; case 'array' : return `(${ codegenOutputType ( evmType . itemType ) })[]` ; case 'boolean' : return 'boolean' ; case 'string' : return 'string' ; case 'tuple' : return codegenTupleType ( evmType , codegenOutputType ) ; case 'unknown' : return 'any' ; } } function codegenTupleType ( tuple , generator ) { return '{' + tuple . components . map ( ( component ) => `${ component . name }: ${ generator ( component . type ) }` ) . join ( ', ' ) + '}' ; }