@@ -4,8 +4,8 @@ import { EntityManager, MoreThanOrEqual } from 'typeorm'
44import { createPublicClient , fallback , http } from 'viem'
55import { base , hyperEvm , mainnet } from 'viem/chains'
66
7- import { chainConfigs } from '@originprotocol/squid-utils'
87import { MorphoVaultApy } from '@model'
8+ import { chainConfigs } from '@originprotocol/squid-utils'
99import { computeDepositImpact } from '@templates/morpho/deposit-impact'
1010
1111import './fetch-polyfill'
@@ -19,23 +19,31 @@ function parseWindowMs(window: string): number | null {
1919 return unit === 'h' ? n * 3600 * 1000 : n * 86400 * 1000
2020}
2121
22+ const clients = {
23+ [ mainnet . id ] : createPublicClient ( {
24+ chain : mainnet ,
25+ transport : fallback ( ( chainConfigs [ mainnet . id ] ?. endpoints ?? [ ] ) . map ( ( url ) => http ( url ) ) ) ,
26+ } ) ,
27+ [ base . id ] : createPublicClient ( {
28+ chain : base ,
29+ transport : fallback ( ( chainConfigs [ base . id ] ?. endpoints ?? [ ] ) . map ( ( url ) => http ( url ) ) ) ,
30+ } ) ,
31+ [ hyperEvm . id ] : createPublicClient ( {
32+ chain : hyperEvm ,
33+ transport : http ( process . env . RPC_HYPEREVM_ENDPOINT ?? 'https://rpc.hyperliquid.xyz/evm' ) ,
34+ } ) ,
35+ }
36+
2237/** Build a viem PublicClient for a given chainId. */
2338function getViemClient ( chainId : number ) {
2439 if ( chainId === mainnet . id ) {
25- return createPublicClient ( {
26- chain : mainnet ,
27- transport : fallback ( ( chainConfigs [ mainnet . id ] ?. endpoints ?? [ ] ) . map ( ( url ) => http ( url ) ) ) ,
28- } )
40+ return clients [ mainnet . id ]
2941 }
3042 if ( chainId === base . id ) {
31- return createPublicClient ( {
32- chain : base ,
33- transport : fallback ( ( chainConfigs [ base . id ] ?. endpoints ?? [ ] ) . map ( ( url ) => http ( url ) ) ) ,
34- } )
43+ return clients [ base . id ]
3544 }
3645 if ( chainId === hyperEvm . id ) {
37- const rpc = process . env . RPC_HYPEREVM_ENDPOINT ?? 'https://rpc.hyperliquid.xyz/evm'
38- return createPublicClient ( { chain : hyperEvm , transport : http ( rpc ) } )
46+ return clients [ hyperEvm . id ]
3947 }
4048 throw new Error ( `Unsupported chainId: ${ chainId } . Supported: ${ mainnet . id } , ${ base . id } , ${ hyperEvm . id } ` )
4149}
@@ -130,9 +138,7 @@ export class MorphoVaultApyResolver {
130138 } )
131139
132140 const timeWindowHours = windowMs / 3600000
133- const averageApy = snapshots . length > 0
134- ? snapshots . reduce ( ( sum , s ) => sum + s . apy , 0 ) / snapshots . length
135- : 0
141+ const averageApy = snapshots . length > 0 ? snapshots . reduce ( ( sum , s ) => sum + s . apy , 0 ) / snapshots . length : 0
136142
137143 return new MorphoVaultApyAverageResult ( { averageApy, timeWindowHours } )
138144 }
0 commit comments