import type { Address, Domain } from '@hyperlane-xyz/utils'; import type { ExternalBridgeType } from '../config/types.js'; import type { BridgeTransferStatus } from '../interfaces/IExternalBridge.js'; import type { IStore } from './store/IStore.js'; // === Base Interfaces === export interface Identifiable { id: string; } export interface CrossChainAction { origin: Domain; destination: Domain; amount: bigint; } export interface Timestamped { createdAt: number; updatedAt: number; } export interface TrackedActionBase extends Identifiable, CrossChainAction, Timestamped { status: string; } // === Status Types === export type TransferStatus = 'in_progress' | 'complete'; export type RebalanceIntentStatus = | 'not_started' | 'in_progress' | 'complete' | 'cancelled' | 'failed'; export type RebalanceActionStatus = 'in_progress' | 'complete' | 'failed'; // === Execution Types === /** * Execution method for rebalancing: * - `movable_collateral`: Uses MovableCollateralRouter.rebalance() on-chain * - `inventory`: Uses external bridges + transferRemote */ export type ExecutionMethod = 'movable_collateral' | 'inventory'; /** * Type of rebalance action: * - `rebalance_message`: Standard movable collateral rebalance (Hyperlane message) * - `inventory_movement`: External bridge transfer (e.g., LiFi) to move inventory * - `inventory_deposit`: transferRemote to deposit inventory as collateral */ export type ActionType = | 'rebalance_message' | 'inventory_movement' | 'inventory_deposit'; // === Entity Types === export interface Transfer extends TrackedActionBase { status: TransferStatus; messageId: string; sender: Address; recipient: Address; } export interface RebalanceIntent extends TrackedActionBase { status: RebalanceIntentStatus; bridge?: Address; // Optional - bridge contract used (missing for recovered intents) priority?: number; // Optional - missing for recovered intents strategyType?: string; // Optional - missing for recovered intents executionMethod?: ExecutionMethod; // Optional - defaults to movable_collateral externalBridge?: ExternalBridgeType; // Optional - external bridge type (e.g., LiFi) } export interface RebalanceAction extends TrackedActionBase { status: RebalanceActionStatus; type: ActionType; // Type of action (rebalance_message, inventory_movement, inventory_deposit) intentId: string; // Links to parent RebalanceIntent messageId?: string; // Hyperlane message ID (required for rebalance_message, inventory_deposit) txHash?: string; // Origin transaction hash // Fields for inventory_movement (external bridge) externalBridgeTransferId?: string; // External bridge transfer ID (e.g., LiFi transfer ID) externalBridgeId?: ExternalBridgeType; // External bridge identifier (e.g., 'lifi') lastBridgeStatus?: BridgeTransferStatus['status']; // Last observed external bridge status nonPendingSince?: number; // Timestamp when bridge status first became non-pending } // === Type Aliases for Stores === export type ITransferStore = IStore; export type IRebalanceIntentStore = IStore< RebalanceIntent, RebalanceIntentStatus >; export type IRebalanceActionStore = IStore< RebalanceAction, RebalanceActionStatus >; // === Derived Types === /** * Represents an inventory intent that has been partially fulfilled * and can continue execution. Values are derived from action states. */ export interface PartialInventoryIntent { intent: RebalanceIntent; /** Sum of complete inventory_deposit action amounts */ completedAmount: bigint; /** Amount remaining to fulfill (0n when final deposit is fully in-flight). Formula: intent.amount - completedAmount - inflightAmount */ remaining: bigint; /** True when intent has in_progress inventory_deposit actions (not safe to continue, but still active) */ hasInflightDeposit: boolean; }