@@ -14,7 +14,12 @@ import {
1414} from '@lifi/sdk' ;
1515import bs58 from 'bs58' ;
1616import type { ChainMetadata } from '@hyperlane-xyz/sdk' ;
17- import { ProtocolType , assert , ensure0x } from '@hyperlane-xyz/utils' ;
17+ import {
18+ ProtocolType ,
19+ assert ,
20+ ensure0x ,
21+ isEVMLike ,
22+ } from '@hyperlane-xyz/utils' ;
1823import type { Logger } from 'pino' ;
1924import { type Chain , createWalletClient , http } from 'viem' ;
2025import { privateKeyToAccount } from 'viem/accounts' ;
@@ -142,12 +147,8 @@ export class LiFiBridge implements IExternalBridge {
142147 const metadataByDomainId = new Map < number , ChainMetadata > ( ) ;
143148 for ( const metadata of Object . values ( config . chainMetadata ) ) {
144149 metadataByDomainId . set ( metadata . domainId , metadata ) ;
145- if ( metadata . chainId !== undefined ) {
146- if ( metadata . protocol === ProtocolType . Ethereum ) {
147- this . chainMetadataByChainId . set ( Number ( metadata . chainId ) , metadata ) ;
148- } else {
149- this . chainMetadataByChainId . set ( metadata . domainId , metadata ) ;
150- }
150+ if ( metadata . chainId !== undefined && isEVMLike ( metadata . protocol ) ) {
151+ this . chainMetadataByChainId . set ( Number ( metadata . chainId ) , metadata ) ;
151152 }
152153 }
153154 // Also key by LiFi chain IDs so both Hyperlane domains and LiFi IDs
@@ -187,11 +188,24 @@ export class LiFiBridge implements IExternalBridge {
187188 * Iterates metadata to find matching chainId and returns first HTTP RPC URL.
188189 */
189190 private getRpcUrlForChainId ( chainId : number ) : string | undefined {
190- return this . chainMetadataByChainId . get ( chainId ) ?. rpcUrls ?. [ 0 ] ?. http ;
191+ return this . getMetadataForChainId ( chainId ) ?. rpcUrls ?. [ 0 ] ?. http ;
191192 }
192193
193194 private getProtocolTypeForChainId ( chainId : number ) : ProtocolType | undefined {
194- return this . chainMetadataByChainId . get ( chainId ) ?. protocol ;
195+ return this . getMetadataForChainId ( chainId ) ?. protocol ;
196+ }
197+
198+ private getMetadataForChainId ( chainId : number ) : ChainMetadata | undefined {
199+ const directMetadata = this . chainMetadataByChainId . get ( chainId ) ;
200+ if ( directMetadata ) {
201+ return directMetadata ;
202+ }
203+
204+ const matches = Object . values ( this . config . chainMetadata ?? { } ) . filter (
205+ ( metadata ) =>
206+ metadata . chainId !== undefined && Number ( metadata . chainId ) === chainId ,
207+ ) ;
208+ return matches . length === 1 ? matches [ 0 ] : undefined ;
195209 }
196210
197211 private addressesEqual ( a : string , b : string , chainId : number ) : boolean {
0 commit comments