chore(sdk): support DefaultFallbackRoutingIsm in sdk metadata builder (#4162)

### Description

Support DefaultFallbackRoutingIsm in sdk metadata builder


### Backward compatibility

Yes

### Testing

Manually processed
https://explorer.hyperlane.xyz/message/0x7d5f8450965a97735e39007f7cb9db135852123d589d81f81c113d84e3a70ceb
pull/4391/head
Nam Chu Hoai 3 months ago committed by GitHub
parent 092ce5fd39
commit 3ad5918da5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/nice-deers-tan.md
  2. 19
      typescript/sdk/src/ism/metadata/builder.ts
  3. 49
      typescript/sdk/src/ism/metadata/routing.ts

@ -0,0 +1,5 @@
---
"@hyperlane-xyz/sdk": patch
---
Support DefaultFallbackRoutingIsm in metadata builder

@ -23,7 +23,10 @@ import {
import { ArbL2ToL1Metadata, ArbL2ToL1MetadataBuilder } from './arbL2ToL1.js';
import { MultisigMetadata, MultisigMetadataBuilder } from './multisig.js';
import { NullMetadata, NullMetadataBuilder } from './null.js';
import { RoutingMetadata, RoutingMetadataBuilder } from './routing.js';
import {
DefaultFallbackRoutingMetadataBuilder,
RoutingMetadata,
} from './routing.js';
export type StructuredMetadata =
| NullMetadata
@ -50,7 +53,7 @@ export class BaseMetadataBuilder implements MetadataBuilder {
public nullMetadataBuilder: NullMetadataBuilder;
public multisigMetadataBuilder: MultisigMetadataBuilder;
public aggregationMetadataBuilder: AggregationMetadataBuilder;
public routingMetadataBuilder: RoutingMetadataBuilder;
public routingMetadataBuilder: DefaultFallbackRoutingMetadataBuilder;
public arbL2ToL1MetadataBuilder: ArbL2ToL1MetadataBuilder;
public multiProvider: MultiProvider;
@ -59,7 +62,9 @@ export class BaseMetadataBuilder implements MetadataBuilder {
constructor(core: HyperlaneCore) {
this.multisigMetadataBuilder = new MultisigMetadataBuilder(core);
this.aggregationMetadataBuilder = new AggregationMetadataBuilder(this);
this.routingMetadataBuilder = new RoutingMetadataBuilder(this);
this.routingMetadataBuilder = new DefaultFallbackRoutingMetadataBuilder(
this,
);
this.nullMetadataBuilder = new NullMetadataBuilder(core.multiProvider);
this.arbL2ToL1MetadataBuilder = new ArbL2ToL1MetadataBuilder(core);
this.multiProvider = core.multiProvider;
@ -99,6 +104,7 @@ export class BaseMetadataBuilder implements MetadataBuilder {
});
case IsmType.ROUTING:
case IsmType.FALLBACK_ROUTING:
return this.routingMetadataBuilder.build(
{
...context,
@ -123,7 +129,7 @@ export class BaseMetadataBuilder implements MetadataBuilder {
}
default:
throw new Error(`Unsupported ISM type: ${ism.type}`);
throw new Error(`Unsupported ISM: ${ism}`);
}
}
@ -144,7 +150,10 @@ export class BaseMetadataBuilder implements MetadataBuilder {
return AggregationMetadataBuilder.decode(metadata, { ...context, ism });
case IsmType.ROUTING:
return RoutingMetadataBuilder.decode(metadata, { ...context, ism });
return DefaultFallbackRoutingMetadataBuilder.decode(metadata, {
...context,
ism,
});
case IsmType.ARB_L2_TO_L1:
return ArbL2ToL1MetadataBuilder.decode(metadata, {

@ -1,7 +1,8 @@
import { DefaultFallbackRoutingIsm__factory } from '@hyperlane-xyz/core';
import { WithAddress, assert } from '@hyperlane-xyz/utils';
import { ChainName } from '../../types.js';
import { DerivedIsmConfig } from '../EvmIsmReader.js';
import { DerivedIsmConfig, EvmIsmReader } from '../EvmIsmReader.js';
import { IsmType, RoutingIsmConfig } from '../types.js';
import {
@ -56,3 +57,49 @@ export class RoutingMetadataBuilder implements MetadataBuilder {
};
}
}
export class DefaultFallbackRoutingMetadataBuilder extends RoutingMetadataBuilder {
public async build(
context: MetadataContext<WithAddress<RoutingIsmConfig>>,
maxDepth = 10,
): Promise<string> {
const originChain = this.baseMetadataBuilder.multiProvider.getChainName(
context.message.parsed.origin,
);
const isRouted = !!context.ism.domains[originChain];
if (isRouted) {
return super.build(context, maxDepth);
}
if (context.ism.type !== IsmType.FALLBACK_ROUTING) {
throw new Error(
`Origin domain ${originChain} is not enrolled in DomainRoutingIsm`,
);
}
const destinationProvider =
this.baseMetadataBuilder.multiProvider.getProvider(
context.message.parsed.destination,
);
const fallbackIsm = DefaultFallbackRoutingIsm__factory.connect(
context.ism.address,
destinationProvider,
);
const defaultIsmAddress = await fallbackIsm.module(
context.message.parsed.origin,
);
const ismReader = new EvmIsmReader(
this.baseMetadataBuilder.multiProvider,
context.message.parsed.destination,
);
const defaultIsmConfig = await ismReader.deriveIsmConfig(defaultIsmAddress);
const originContext = {
...context,
ism: defaultIsmConfig,
};
return this.baseMetadataBuilder.build(originContext, maxDepth - 1);
}
}

Loading…
Cancel
Save