@hyperlane-xyz/sdk
Version:
The official SDK for the Hyperlane Network
207 lines • 7.7 kB
JavaScript
import { z } from 'zod';
import { ZHash } from '../metadata/customZodTypes.js';
import { OwnableSchema, PausableSchema, } from '../types.js';
import { isCompliant } from '../utils/schemas.js';
// this enum should match the IInterchainSecurityModule.sol enum
// meant for the relayer
export var ModuleType;
(function (ModuleType) {
ModuleType[ModuleType["UNUSED"] = 0] = "UNUSED";
ModuleType[ModuleType["ROUTING"] = 1] = "ROUTING";
ModuleType[ModuleType["AGGREGATION"] = 2] = "AGGREGATION";
ModuleType[ModuleType["LEGACY_MULTISIG"] = 3] = "LEGACY_MULTISIG";
ModuleType[ModuleType["MERKLE_ROOT_MULTISIG"] = 4] = "MERKLE_ROOT_MULTISIG";
ModuleType[ModuleType["MESSAGE_ID_MULTISIG"] = 5] = "MESSAGE_ID_MULTISIG";
ModuleType[ModuleType["NULL"] = 6] = "NULL";
ModuleType[ModuleType["CCIP_READ"] = 7] = "CCIP_READ";
ModuleType[ModuleType["ARB_L2_TO_L1"] = 8] = "ARB_L2_TO_L1";
ModuleType[ModuleType["WEIGHTED_MERKLE_ROOT_MULTISIG"] = 9] = "WEIGHTED_MERKLE_ROOT_MULTISIG";
ModuleType[ModuleType["WEIGHTED_MESSAGE_ID_MULTISIG"] = 10] = "WEIGHTED_MESSAGE_ID_MULTISIG";
})(ModuleType || (ModuleType = {}));
// this const object can be adjusted as per deployments necessary
// meant for the deployer and checker
export const IsmType = {
CUSTOM: 'custom',
OP_STACK: 'opStackIsm',
ROUTING: 'domainRoutingIsm',
FALLBACK_ROUTING: 'defaultFallbackRoutingIsm',
AMOUNT_ROUTING: 'amountRoutingIsm',
INTERCHAIN_ACCOUNT_ROUTING: 'interchainAccountRouting',
AGGREGATION: 'staticAggregationIsm',
STORAGE_AGGREGATION: 'storageAggregationIsm',
MERKLE_ROOT_MULTISIG: 'merkleRootMultisigIsm',
MESSAGE_ID_MULTISIG: 'messageIdMultisigIsm',
STORAGE_MERKLE_ROOT_MULTISIG: 'storageMerkleRootMultisigIsm',
STORAGE_MESSAGE_ID_MULTISIG: 'storageMessageIdMultisigIsm',
TEST_ISM: 'testIsm',
PAUSABLE: 'pausableIsm',
TRUSTED_RELAYER: 'trustedRelayerIsm',
ARB_L2_TO_L1: 'arbL2ToL1Ism',
WEIGHTED_MERKLE_ROOT_MULTISIG: 'weightedMerkleRootMultisigIsm',
WEIGHTED_MESSAGE_ID_MULTISIG: 'weightedMessageIdMultisigIsm',
CCIP: 'ccipIsm',
OFFCHAIN_LOOKUP: 'offchainLookupIsm',
};
// ISM types that can be updated in-place
export const MUTABLE_ISM_TYPE = [
IsmType.ROUTING,
IsmType.FALLBACK_ROUTING,
IsmType.PAUSABLE,
IsmType.OFFCHAIN_LOOKUP,
];
/**
* @notice Statically deployed ISM types
* @dev ISM types with immutable config embedded in contract bytecode via MetaProxy
*/
export const STATIC_ISM_TYPES = [
IsmType.AGGREGATION,
IsmType.MERKLE_ROOT_MULTISIG,
IsmType.MESSAGE_ID_MULTISIG,
IsmType.WEIGHTED_MERKLE_ROOT_MULTISIG,
IsmType.WEIGHTED_MESSAGE_ID_MULTISIG,
];
export const DYNAMICALLY_ROUTED_ISM_TYPES = [
IsmType.AMOUNT_ROUTING,
IsmType.INTERCHAIN_ACCOUNT_ROUTING,
];
/** Type guard for dynamically routed ISM types */
export function isDynamicallyRoutedIsmType(type) {
return DYNAMICALLY_ROUTED_ISM_TYPES.includes(type);
}
// mapping between the two enums
export function ismTypeToModuleType(ismType) {
switch (ismType) {
case IsmType.ROUTING:
case IsmType.FALLBACK_ROUTING:
case IsmType.AMOUNT_ROUTING:
case IsmType.INTERCHAIN_ACCOUNT_ROUTING:
return ModuleType.ROUTING;
case IsmType.AGGREGATION:
case IsmType.STORAGE_AGGREGATION:
return ModuleType.AGGREGATION;
case IsmType.MERKLE_ROOT_MULTISIG:
case IsmType.STORAGE_MERKLE_ROOT_MULTISIG:
return ModuleType.MERKLE_ROOT_MULTISIG;
case IsmType.MESSAGE_ID_MULTISIG:
case IsmType.STORAGE_MESSAGE_ID_MULTISIG:
return ModuleType.MESSAGE_ID_MULTISIG;
case IsmType.OP_STACK:
case IsmType.TEST_ISM:
case IsmType.PAUSABLE:
case IsmType.CUSTOM:
case IsmType.TRUSTED_RELAYER:
case IsmType.CCIP:
return ModuleType.NULL;
case IsmType.ARB_L2_TO_L1:
return ModuleType.ARB_L2_TO_L1;
case IsmType.WEIGHTED_MERKLE_ROOT_MULTISIG:
return ModuleType.WEIGHTED_MERKLE_ROOT_MULTISIG;
case IsmType.WEIGHTED_MESSAGE_ID_MULTISIG:
return ModuleType.WEIGHTED_MESSAGE_ID_MULTISIG;
case IsmType.OFFCHAIN_LOOKUP:
return ModuleType.CCIP_READ;
}
}
export const InterchainAccountRouterIsmSchema = OwnableSchema.extend({
type: z.literal(IsmType.INTERCHAIN_ACCOUNT_ROUTING),
isms: z.record(ZHash),
});
const ValidatorInfoSchema = z.object({
signingAddress: ZHash,
weight: z.number(),
});
export const TestIsmConfigSchema = z.object({
type: z.literal(IsmType.TEST_ISM),
});
export const MultisigConfigSchema = z.object({
validators: z.array(ZHash),
threshold: z.number(),
});
export const WeightedMultisigConfigSchema = z.object({
validators: z.array(ValidatorInfoSchema),
thresholdWeight: z.number(),
});
export const TrustedRelayerIsmConfigSchema = z.object({
type: z.literal(IsmType.TRUSTED_RELAYER),
relayer: z.string(),
});
export const CCIPIsmConfigSchema = z.object({
type: z.literal(IsmType.CCIP),
originChain: z.string(),
});
export const OffchainLookupIsmConfigSchema = OwnableSchema.extend({
type: z.literal(IsmType.OFFCHAIN_LOOKUP),
urls: z.array(z.string().url()),
});
export const isOffchainLookupIsmConfig = isCompliant(OffchainLookupIsmConfigSchema);
export const OpStackIsmConfigSchema = z.object({
type: z.literal(IsmType.OP_STACK),
origin: z.string(),
nativeBridge: z.string(),
});
export const ArbL2ToL1IsmConfigSchema = z.object({
type: z.literal(IsmType.ARB_L2_TO_L1),
bridge: z.string(),
});
export const PausableIsmConfigSchema = PausableSchema.and(z.object({
type: z.literal(IsmType.PAUSABLE),
}));
export const MultisigIsmConfigSchema = MultisigConfigSchema.and(z.object({
type: z.union([
z.literal(IsmType.MERKLE_ROOT_MULTISIG),
z.literal(IsmType.MESSAGE_ID_MULTISIG),
z.literal(IsmType.STORAGE_MERKLE_ROOT_MULTISIG),
z.literal(IsmType.STORAGE_MESSAGE_ID_MULTISIG),
]),
}));
export const WeightedMultisigIsmConfigSchema = WeightedMultisigConfigSchema.and(z.object({
type: z.union([
z.literal(IsmType.WEIGHTED_MERKLE_ROOT_MULTISIG),
z.literal(IsmType.WEIGHTED_MESSAGE_ID_MULTISIG),
]),
}));
export const RoutingIsmConfigSchema = z.lazy(() => z.discriminatedUnion('type', [
z.object({
type: z.literal(IsmType.AMOUNT_ROUTING),
lowerIsm: IsmConfigSchema,
upperIsm: IsmConfigSchema,
threshold: z.number(),
}),
OwnableSchema.extend({
type: z.literal(IsmType.ROUTING),
domains: z.record(IsmConfigSchema),
}),
OwnableSchema.extend({
type: z.literal(IsmType.FALLBACK_ROUTING),
domains: z.record(IsmConfigSchema),
}),
InterchainAccountRouterIsmSchema,
]));
export const AggregationIsmConfigSchema = z
.lazy(() => z.object({
type: z.union([
z.literal(IsmType.AGGREGATION),
z.literal(IsmType.STORAGE_AGGREGATION),
]),
modules: z.array(IsmConfigSchema),
threshold: z.number(),
}))
.refine((data) => data.threshold <= data.modules.length, {
message: 'Threshold must be less than or equal to the number of modules',
});
export const IsmConfigSchema = z.union([
ZHash,
TestIsmConfigSchema,
OpStackIsmConfigSchema,
PausableIsmConfigSchema,
TrustedRelayerIsmConfigSchema,
CCIPIsmConfigSchema,
MultisigIsmConfigSchema,
WeightedMultisigIsmConfigSchema,
RoutingIsmConfigSchema,
AggregationIsmConfigSchema,
ArbL2ToL1IsmConfigSchema,
OffchainLookupIsmConfigSchema,
InterchainAccountRouterIsmSchema,
]);
//# sourceMappingURL=types.js.map