@hyperlane-xyz/cli
Version:
A command-line utility for common Hyperlane operations
62 lines • 2.57 kB
JavaScript
import { stringify as yamlStringify } from 'yaml';
import { CoreConfigSchema, } from '@hyperlane-xyz/sdk';
import { errorRed, log, logBlue, logGreen } from '../logger.js';
import { indentYamlOrJson, readYamlOrJson, writeYamlOrJson, } from '../utils/files.js';
import { detectAndConfirmOrPrompt } from '../utils/input.js';
import { createHookConfig, createMerkleTreeConfig, createProtocolFeeConfig, } from './hooks.js';
import { createAdvancedIsmConfig, createTrustedRelayerConfig } from './ism.js';
const ENTER_DESIRED_VALUE_MSG = 'Enter the desired';
const SIGNER_PROMPT_LABEL = 'signer';
export async function createCoreDeployConfig({ context, configFilePath, advanced = false, }) {
logBlue('Creating a new core deployment config...');
const owner = await detectAndConfirmOrPrompt(async () => context.signerAddress, ENTER_DESIRED_VALUE_MSG, 'owner address', SIGNER_PROMPT_LABEL);
const defaultIsm = advanced
? await createAdvancedIsmConfig(context)
: await createTrustedRelayerConfig(context, advanced);
let defaultHook, requiredHook;
let proxyAdmin;
if (advanced) {
defaultHook = await createHookConfig({
context,
selectMessage: 'Select default hook type',
advanced,
});
requiredHook = await createHookConfig({
context,
selectMessage: 'Select required hook type',
advanced,
});
proxyAdmin = {
owner: await detectAndConfirmOrPrompt(async () => context.signerAddress, ENTER_DESIRED_VALUE_MSG, 'ProxyAdmin owner address', SIGNER_PROMPT_LABEL),
};
}
else {
defaultHook = await createMerkleTreeConfig();
requiredHook = await createProtocolFeeConfig(context, advanced);
proxyAdmin = {
owner,
};
}
try {
const coreConfig = CoreConfigSchema.parse({
owner,
defaultIsm,
defaultHook,
requiredHook,
proxyAdmin,
});
logBlue(`Core config is valid, writing to file ${configFilePath}:\n`);
log(indentYamlOrJson(yamlStringify(coreConfig, null, 2), 4));
writeYamlOrJson(configFilePath, coreConfig, 'yaml');
logGreen('✅ Successfully created new core deployment config.');
}
catch (e) {
errorRed(`Core deployment config is invalid.`);
throw e;
}
}
export function readCoreDeployConfigs(filePath) {
const config = readYamlOrJson(filePath);
return CoreConfigSchema.parse(config);
}
//# sourceMappingURL=core.js.map