import { WithAddress } from '@hyperlane-xyz/utils'; import * as AltVM from './altvm.js'; import { ArtifactDeployed, ArtifactNew, IArtifactManager } from './artifact.js'; import { ChainLookup } from './chain.js'; export type HookModuleType = { config: HookConfig; derived: DerivedHookConfig; addresses: HookModuleAddresses; }; export interface HookConfigs { interchainGasPaymaster: IgpHookModuleConfig; protocolFee: ProtocolFeeHookModuleConfig; merkleTreeHook: MerkleTreeHookConfig; unknownHook: UnknownHookConfig; } export type HookType = keyof HookConfigs; export type HookConfig = HookConfigs[HookType]; export type DerivedHookConfig = WithAddress; export declare function altVmHookTypeToProviderHookType(hookType: AltVM.HookType): HookType; export declare const MUTABLE_HOOK_TYPE: HookType[]; export interface IgpHookModuleConfig { type: 'interchainGasPaymaster'; owner: string; beneficiary: string; oracleKey: string; overhead: Record; oracleConfig: Record; } export interface MerkleTreeHookConfig { type: 'merkleTreeHook'; } export interface UnknownHookConfig { type: 'unknownHook'; [key: string]: unknown; } export interface ProtocolFeeHookModuleConfig { type: 'protocolFee'; owner: string; beneficiary: string; maxProtocolFee: string; protocolFee: string; } export type ProtocolFeeHookConfig = ProtocolFeeHookModuleConfig; export type HookModuleAddresses = { deployedHook: string; mailbox: string; }; export interface DeployedHookAddress { address: string; } /** * IGP Hook config for Artifact API. * Uses domain IDs (numbers) instead of chain names (strings) for overhead and oracleConfig keys. * This differs from IgpHookModuleConfig which uses chain names for the Config API. */ export interface IgpHookConfig { type: 'interchainGasPaymaster'; owner: string; beneficiary: string; oracleKey: string; overhead: Record; oracleConfig: Record; } export interface HookArtifactConfigs { interchainGasPaymaster: IgpHookConfig; protocolFee: ProtocolFeeHookConfig; merkleTreeHook: MerkleTreeHookConfig; unknownHook: UnknownHookConfig; } /** * Should be used for the specific artifact code that * deploys or reads any kind of Hook */ export type HookArtifactConfig = HookArtifactConfigs[HookType]; /** * Describes the configuration of deployed Hook */ export type DeployedHookArtifact = ArtifactDeployed; /** * Should be used to implement an object/closure or class that is in charge of coordinating * deployment of a Hook config */ export type IHookArtifactManager = IArtifactManager; /** * Raw hook artifact configs (no nested artifacts for now, but kept for consistency) */ export interface RawHookArtifactConfigs { interchainGasPaymaster: IgpHookConfig; protocolFee: ProtocolFeeHookConfig; merkleTreeHook: MerkleTreeHookConfig; unknownHook: UnknownHookConfig; } /** * Should be used for the specific artifact code that * deploys or reads a single hook artifact on chain */ export type RawHookArtifactConfig = RawHookArtifactConfigs[HookType]; /** * Should be used to implement an object/closure or class that individually deploys * Hooks on chain */ export interface IRawHookArtifactManager extends IArtifactManager { /** * Read any hook by detecting its type and delegating to the appropriate reader. * This is the generic entry point for reading hooks of unknown types. * @param address The on-chain address of the hook * @returns The artifact configuration and deployment data */ readHook(address: string): Promise; } export declare function throwUnsupportedHookType(hookType: string, protocolName: string): never; /** * Converts HookConfig (Config API) to HookArtifactConfig (Artifact API). * * Key transformations: * - IGP hooks: String chain names → numeric domain IDs for overhead/oracleConfig keys * - MerkleTree hooks: Pass through unchanged * * @param config The hook configuration using Config API format * @param chainLookup Chain lookup interface for resolving chain names to domain IDs * @returns Artifact wrapper around HookArtifactConfig suitable for artifact writers * * @example * ```typescript * // Config API format (user-facing) * const hookConfig: HookConfig = { * type: 'interchainGasPaymaster', * owner: '0x123...', * overhead: { * ethereum: 50000, * polygon: 100000 * }, * oracleConfig: { * ethereum: { gasPrice: '10', tokenExchangeRate: '1' }, * polygon: { gasPrice: '50', tokenExchangeRate: '1.5' } * } * }; * * // Convert to Artifact API format (internal) * const artifact = hookConfigToArtifact(hookConfig, chainLookup); * // artifact.config.overhead is now Record with domain IDs as keys * // artifact.config.oracleConfig is now Record with domain IDs as keys * ``` */ export declare function hookConfigToArtifact(config: HookConfig, chainLookup: ChainLookup): ArtifactNew; /** * Determines if a new hook should be deployed instead of updating the existing one. * Deploy new hook if: * - Hook type changed * - Hook config changed (for immutable hooks like MerkleTree) * * For mutable hooks (IGP), they can be updated in-place. * * @param actual The current deployed hook configuration * @param expected The desired hook configuration * @returns true if a new hook should be deployed, false if existing can be updated */ export declare function shouldDeployNewHook(actual: HookArtifactConfig, expected: HookArtifactConfig): boolean; /** * Merges current on-chain hook artifact with expected hook artifact. * Determines whether to deploy a new hook or update/reuse existing one. * * @param currentArtifact Current deployed hook artifact (from on-chain state) * @param expectedArtifact Expected hook artifact (desired configuration) * @returns Merged artifact - either NEW (deploy needed) or DEPLOYED (update/reuse) */ export declare function mergeHookArtifacts(currentArtifact: DeployedHookArtifact | undefined, expectedArtifact: ArtifactNew | DeployedHookArtifact): ArtifactNew | DeployedHookArtifact; /** * Converts a DeployedHookArtifact to DerivedHookConfig format. * This handles the conversion between the new Artifact API and the old Config API. * * @param artifact The deployed hook artifact from the Artifact API * @param chainLookup Chain lookup interface for resolving domain IDs to chain names * @returns Hook configuration in Config API format with address */ export declare function hookArtifactToDerivedConfig(artifact: DeployedHookArtifact, chainLookup: ChainLookup): DerivedHookConfig; //# sourceMappingURL=hook.d.ts.map