Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/separate-rebalancer-package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@hyperlane-xyz/rebalancer": minor
"@hyperlane-xyz/cli": minor
---

feat: separate rebalancer package

- Extract rebalancer logic from CLI into dedicated `@hyperlane-xyz/rebalancer` package
- New package supports both manual CLI execution and continuous daemon mode for K8s deployments
- CLI now imports from new package, maintaining backward compatibility for manual rebalancing
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ COPY typescript/http-registry-server/package.json ./typescript/http-registry-ser
COPY typescript/infra/package.json ./typescript/infra/
COPY typescript/provider-sdk/package.json ./typescript/provider-sdk/
COPY typescript/radix-sdk/package.json ./typescript/radix-sdk/
COPY typescript/rebalancer/package.json ./typescript/rebalancer/
COPY typescript/sdk/package.json ./typescript/sdk/
COPY typescript/tsconfig/package.json ./typescript/tsconfig/
COPY typescript/utils/package.json ./typescript/utils/
Expand Down
305 changes: 204 additions & 101 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions typescript/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@hyperlane-xyz/http-registry-server": "workspace:*",
"@hyperlane-xyz/provider-sdk": "workspace:*",
"@hyperlane-xyz/radix-sdk": "workspace:*",
"@hyperlane-xyz/rebalancer": "workspace:*",
"@hyperlane-xyz/registry": "catalog:",
"@hyperlane-xyz/sdk": "workspace:*",
"@hyperlane-xyz/tsconfig": "workspace:^",
Expand Down
68 changes: 57 additions & 11 deletions typescript/cli/src/commands/warp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import util from 'util';
import { stringify as yamlStringify } from 'yaml';
import { CommandModule } from 'yargs';

import { RebalancerConfig, RebalancerService } from '@hyperlane-xyz/rebalancer';
import {
RawForkedChainConfigByChain,
RawForkedChainConfigByChainSchema,
Expand All @@ -15,6 +16,7 @@ import {
difference,
intersection,
objFilter,
rootLogger,
} from '@hyperlane-xyz/utils';

import { runWarpRouteCheck } from '../check/warp.js';
Expand All @@ -35,7 +37,6 @@ import {
logGreen,
} from '../logger.js';
import { getWarpRouteConfigsByCore, runWarpRouteRead } from '../read/warp.js';
import { RebalancerRunner } from '../rebalancer/runner.js';
import { sendTestTransfer } from '../send/transfer.js';
import { ExtendedChainSubmissionStrategySchema } from '../submitters/types.js';
import {
Expand Down Expand Up @@ -490,18 +491,63 @@ export const rebalancer: CommandModuleWithWriteContext<{
},
},
handler: async (args) => {
let runner: RebalancerRunner;
try {
const { context, ...rest } = args;
runner = await RebalancerRunner.create(rest, context);
} catch (e: any) {
// exit on startup errors
errorRed(`Rebalancer startup error: ${util.format(e)}`);
process.exit(1);
}
const {
context,
config: configPath,
checkFrequency,
withMetrics,
monitorOnly,
manual,
origin,
destination,
amount,
} = args;

logCommandHeader('Hyperlane Warp Route Rebalancer');

try {
await runner.run();
// Load rebalancer configuration
const rebalancerConfig = RebalancerConfig.load(configPath);

// Determine execution mode
const mode = manual ? 'manual' : 'daemon';

// Create rebalancer service
const service = new RebalancerService(
context.multiProvider,
context.multiProtocolProvider,
context.registry,
rebalancerConfig,
{
mode,
checkFrequency,
withMetrics,
monitorOnly,
coingeckoApiKey: process.env.COINGECKO_API_KEY,
logger: rootLogger.child({ module: 'rebalancer' }),
},
);

// Execute based on mode
if (manual) {
if (!origin || !destination || !amount) {
errorRed(
'Origin, destination, and amount are required for manual rebalance',
);
process.exit(1);
}

await service.executeManual({
origin,
destination,
amount,
});

logGreen('✅ Manual rebalance completed successfully');
} else {
// Start daemon mode
await service.start();
}
} catch (e: any) {
errorRed(`Rebalancer error: ${util.format(e)}`);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RebalancerConfig } from '@hyperlane-xyz/rebalancer';
import {
ChainName,
DeployedCoreAddresses,
Expand All @@ -9,7 +10,6 @@ import { ProtocolType, assert } from '@hyperlane-xyz/utils';
import { CommandType } from '../../../commands/signCommands.js';
import { readCoreDeployConfigs } from '../../../config/core.js';
import { getWarpRouteDeployConfig } from '../../../config/warp.js';
import { RebalancerConfig } from '../../../rebalancer/config/RebalancerConfig.js';
import {
runMultiChainSelectionStep,
runSingleChainSelectionStep,
Expand Down
177 changes: 0 additions & 177 deletions typescript/cli/src/rebalancer/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions typescript/cli/src/rebalancer/index.ts

This file was deleted.

Loading
Loading