import { type Logger } from 'pino'; import type { ChainMap, ChainName, Token } from '@hyperlane-xyz/sdk'; import type { IStrategy, InflightContext, RawBalances, Route, RouteWithContext, StrategyRoute } from '../interfaces/IStrategy.js'; import { type Metrics } from '../metrics/Metrics.js'; import { type BridgeConfig, type BridgeConfigWithOverride } from '../utils/bridgeUtils.js'; export type Delta = { chain: ChainName; amount: bigint; }; /** * Base abstract class for rebalancing strategies */ export declare abstract class BaseStrategy implements IStrategy { abstract readonly name: string; protected readonly chains: ChainName[]; protected readonly metrics?: Metrics; protected readonly logger: Logger; protected readonly bridgeConfigs: ChainMap; protected readonly tokensByChainName?: ChainMap; constructor(chains: ChainName[], logger: Logger, bridgeConfigs: ChainMap, metrics?: Metrics, tokensByChainName?: ChainMap); protected getBridgeConfigForRoute(origin: ChainName, destination: ChainName): BridgeConfig; /** * Main method to get rebalancing routes */ getRebalancingRoutes(rawBalances: RawBalances, inflightContext?: InflightContext): StrategyRoute[]; /** * Abstract method to get balances categorized by surplus and deficit * Each specific strategy should implement its own logic * * @param balances - Effective balances (after collateral reservation) * @param pendingRebalances - In-flight rebalances (origin tx confirmed, balance already deducted) * @param proposedRebalances - Routes from earlier strategies in same cycle (not yet executed) * @returns Categorized surpluses and deficits as Delta arrays */ protected abstract getCategorizedBalances(balances: RawBalances, pendingRebalances?: Route[], proposedRebalances?: StrategyRoute[]): { surpluses: Delta[]; deficits: Delta[]; }; /** * Validates the raw balances against the chains configuration */ protected validateRawBalances(rawBalances: RawBalances): void; /** * Reserve collateral for pending user transfers. * Subtracts pending transfer amounts from destination balances. * This ensures we don't drain collateral needed for incoming transfers. * * @param rawBalances - Current on-chain balances * @param pendingTransfers - Transfers that will need collateral on destination * @returns Balances with reserved amounts subtracted */ protected reserveCollateral(rawBalances: RawBalances, pendingTransfers: Route[]): RawBalances; /** * Simulate pending rebalances based on execution method. * * For **movable_collateral** (default): * - Add full amount to destination (origin already deducted on-chain) * * For **inventory**: * - Simulate the eventual final state as if the entire intent will be fulfilled * - Destination: add unfulfilled amount (total - delivered - awaiting) * This is what's NOT yet reflected in on-chain balance * - Origin: subtract pending amount (total - delivered) * This is what WILL decrease when all messages deliver * * @param rawBalances - Current balances (may already have collateral reserved) * @param pendingRebalances - In-flight rebalance operations (in_progress only) * @returns Simulated future balances after rebalances complete */ protected simulatePendingRebalances(rawBalances: RawBalances, pendingRebalances: RouteWithContext[]): RawBalances; /** * Simulate proposed rebalances by subtracting from origin AND adding to destination. * * Unlike pendingRebalances, proposedRebalances are routes from earlier strategies * in the same cycle that haven't been executed yet. Therefore: * - Origin balance has NOT been deducted on-chain * - We must simulate both sides to maintain accurate total balance * * @param rawBalances - Current balances (may already have pending rebalances simulated) * @param proposedRebalances - Routes from earlier strategies (not yet executed) * @returns Simulated balances after proposed rebalances complete */ protected simulateProposedRebalances(rawBalances: RawBalances, proposedRebalances: Route[]): RawBalances; protected filterRoutes(routes: StrategyRoute[], actualBalances: RawBalances): StrategyRoute[]; } //# sourceMappingURL=BaseStrategy.d.ts.map