import { ethers } from 'ethers' ; const proto = Object . prototype ; const gpo = Object . getPrototypeOf ; param struct returns export function convertStructToPojo ( struct ) { let obj = { } ; Object . entries ( struct ) . slice ( struct . length ) . forEach ( ( [ key , value ] ) => { obj [ key ] = isStruct ( value ) ? convertStructToPojo ( value ) : value ; } ) ; return obj ; } export function convertPojoToStruct ( value , fnFragment ) { const parsedValue = { [ fnFragment . name ] : value , } ; const parsedFnFragment = { name : fnFragment . name , components : fnFragment . outputs ! , } ; return convertPojoToStructRecursive ( parsedValue , [ parsedFnFragment ] ) [ 0 ] ; } export function convertPojoToStructRecursive ( value , fnFragments ) { let res = [ ] ; fnFragments . forEach ( ( item ) => { if ( item . components ) { res . push ( convertPojoToStructRecursive ( value [ item . name ! ] , item . components ) ) ; } else { res . push ( value [ item . name ! ] ) ; } } ) ; return res ; } export function getObjectAndStruct ( obj1 , obj2 ) { if ( isPojo ( obj1 ) && isStruct ( obj2 ) ) { return [ obj1 as object , obj2 as unknown [ ] ] ; } if ( isPojo ( obj2 ) && isStruct ( obj1 ) ) { return [ obj2 as object , obj1 as unknown [ ] ] ; } return ; } param obj returns export function isStruct ( obj ) { return Array . isArray ( obj ) && Object . keys ( obj ) . length > obj . length ; } export function isPojo ( obj ) { if ( obj === null || typeof obj !== 'object' ) { return false ; } return gpo ( obj ) === proto ; }