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
8 changes: 4 additions & 4 deletions typescript/cli/scripts/run-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function cleanup() {
set +e
pkill -f anvil
rm -rf ./test-configs/anvil/deployments
rm -rf ./tmp
rm -f ./test-configs/anvil/chains/anvil2/addresses.yaml
rm -f ./test-configs/anvil/chains/anvil3/addresses.yaml
rm -f ./test-configs/anvil/chains/anvil4/addresses.yaml
Expand All @@ -13,9 +13,9 @@ function cleanup() {
cleanup

echo "Starting anvil2, anvil3 and anvil4 chains for E2E tests"
anvil --chain-id 31338 -p 8555 --gas-price 1 > /dev/null &
anvil --chain-id 31347 -p 8600 --gas-price 1 > /dev/null &
anvil --chain-id 31348 -p 8601 --gas-price 1 > /dev/null &
anvil --chain-id 31338 -p 8555 --state /tmp/anvil2/state --gas-price 1 > /dev/null &
anvil --chain-id 31347 -p 8600 --state /tmp/anvil3/state --gas-price 1 > /dev/null &
anvil --chain-id 31348 -p 8601 --state /tmp/anvil4/state --gas-price 1 > /dev/null &

echo "Running E2E tests"
if [ -n "${CLI_E2E_TEST}" ]; then
Expand Down
72 changes: 40 additions & 32 deletions typescript/cli/src/commands/warp.ts
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rebalancer command now asks for a strategy config path to be loaded from disk. Everything is wrapped into a try to handle exit better

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ import {
} from '../context/types.js';
import { evaluateIfDryRunFailure } from '../deploy/dry-run.js';
import { runWarpRouteApply, runWarpRouteDeploy } from '../deploy/warp.js';
import { log, logBlue, logCommandHeader, logGreen } from '../logger.js';
import {
errorRed,
log,
logBlue,
logCommandHeader,
logGreen,
} from '../logger.js';
import { runWarpRouteRead } from '../read/warp.js';
import {
Executor,
Expand Down Expand Up @@ -411,7 +417,7 @@ export const check: CommandModuleWithContext<{
export const rebalancer: CommandModuleWithContext<{
warpRouteId: string;
checkFrequency: number;
strategyTolerance: string;
strategyConfigFile: string;
}> = {
command: 'rebalancer',
describe: 'Run a warp route collateral rebalancer',
Expand All @@ -427,51 +433,53 @@ export const rebalancer: CommandModuleWithContext<{
demandOption: true,
alias: 'v',
},
strategyTolerance: {
strategyConfigFile: {
type: 'string',
description:
'Tolerance threshold for imbalance detection (specified in token base units; e.g., 1000000 for 1 USDC, 1000000000000000000 for 1 ETH)',
demandOption: false,
default: '0',
description: 'The path to a strategy configuration file (.json or .yaml)',
demandOption: true,
alias: 's',
},
},
handler: async ({
context,
warpRouteId,
checkFrequency,
strategyTolerance,
strategyConfigFile,
}) => {
logCommandHeader('Hyperlane Warp Rebalancer');

// Instantiates the warp route monitor
const monitor: IMonitor = new Monitor(
context.registry,
warpRouteId,
checkFrequency,
);
try {
// Instantiates the warp route monitor
const monitor: IMonitor = new Monitor(
context.registry,
warpRouteId,
checkFrequency,
);

// Instantiates the strategy that will get rebalancing routes based on monitor results
const strategy: IStrategy = new Strategy(BigInt(strategyTolerance));
// Instantiates the strategy that will get rebalancing routes based on monitor results
const strategy: IStrategy = Strategy.fromConfigFile(strategyConfigFile);

// Instantiates the executor that will process rebalancing routes
const executor: IExecutor = new Executor();
// Instantiates the executor that will process rebalancing routes
const executor: IExecutor = new Executor();

// Observe monitor events and process rebalancing routes
monitor.subscribe((event) => {
const balances = event.balances.reduce((acc, next) => {
acc[next.chain] = next.value;
return acc;
}, {} as Record<ChainName, bigint>);
// Observe monitor events and process rebalancing routes
monitor.subscribe((event) => {
const balances = event.balances.reduce((acc, next) => {
acc[next.chain] = next.value;
return acc;
}, {} as Record<ChainName, bigint>);

const rebalancingRoutes = strategy.getRebalancingRoutes(balances);
const rebalancingRoutes = strategy.getRebalancingRoutes(balances);

executor.processRebalancingRoutes(rebalancingRoutes);
});
executor.processRebalancingRoutes(rebalancingRoutes);
});

// Starts the monitor to begin polling balances.
await monitor.start();
// Starts the monitor to begin polling balances.
await monitor.start();

logGreen('Rebalancer started successfully 🚀');
logGreen('Rebalancer started successfully 🚀');
} catch (e) {
errorRed('Rebalancer could not be started:', (e as Error).message);
process.exit(1);
}
},
};

Expand Down
1 change: 1 addition & 0 deletions typescript/cli/src/rebalancer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './executor/Executor.js';
export * from './strategy/Strategy.js';
export * from './strategy/types.js';
export * from './monitor/Monitor.js';
export * from './interfaces/IExecutor.js';
export * from './interfaces/IMonitor.js';
Expand Down
Loading