@@ -10,6 +10,7 @@ import console from 'console';
1010import { differenceInSeconds } from 'date-fns' ;
1111import Moralis from 'moralis' ;
1212import { EvmAddress , EvmChain } from 'moralis/common-evm-utils' ;
13+ import type { ReadContractReturnType } from 'viem' ;
1314import { isZeroAddress } from '../utils' ;
1415import { getPublicClient } from './client' ;
1516
@@ -413,23 +414,30 @@ const getMndOrGndLicenseRewards = async (
413414 }
414415
415416 const publicClient = await getPublicClient ( ) ;
416- const result = await publicClient . readContract ( {
417- address : config . mndContractAddress ,
418- abi : MNDContractAbi ,
419- functionName : 'calculateRewards' ,
420- args : [
421- [
422- {
423- licenseId,
424- nodeAddress : license . nodeAddress ,
425- epochs : epochs . map ( ( epoch ) => BigInt ( epoch ) ) ,
426- availabilies : epochs_vals ,
427- } ,
417+
418+ let result : ReadContractReturnType < typeof MNDContractAbi , 'calculateRewards' > | undefined ;
419+
420+ try {
421+ result = await publicClient . readContract ( {
422+ address : config . mndContractAddress ,
423+ abi : MNDContractAbi ,
424+ functionName : 'calculateRewards' ,
425+ args : [
426+ [
427+ {
428+ licenseId,
429+ nodeAddress : license . nodeAddress ,
430+ epochs : epochs . map ( ( epoch ) => BigInt ( epoch ) ) ,
431+ availabilies : epochs_vals ,
432+ } ,
433+ ] ,
428434 ] ,
429- ] ,
430- } ) ;
435+ } ) ;
436+ } catch {
437+ return undefined ;
438+ }
431439
432- if ( result . length !== 1 ) {
440+ if ( ! result || result . length !== 1 ) {
433441 throw new Error ( 'Invalid rewards calculation result' ) ;
434442 }
435443
0 commit comments