cosmic-interchain-cli
Version:
A command-line utility for Cosmic Wire's interchain messaging protocol
69 lines • 2.95 kB
JavaScript
import { WarpCoreConfigSchema, } from '@hyperlane-xyz/sdk';
import { getContext } from '../../context/context.js';
import { readYamlOrJson, writeYamlOrJson } from '../../utils/files.js';
import { hyperlaneCoreDeploy } from './core.js';
import { hyperlaneWarpApply, readWarpConfig } from './warp.js';
export const TEST_CONFIGS_PATH = './test-configs';
export const REGISTRY_PATH = `${TEST_CONFIGS_PATH}/anvil`;
export const ANVIL_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
/**
* Retrieves the deployed Warp address from the Warp core config.
*/
export function getDeployedWarpAddress(chain, warpCorePath) {
const warpCoreConfig = readYamlOrJson(warpCorePath);
WarpCoreConfigSchema.parse(warpCoreConfig);
return warpCoreConfig.tokens.find((t) => t.chainName === chain)
.addressOrDenom;
}
/**
* Updates the owner of the Warp route deployment config, and then output to a file
*/
export async function updateWarpOwnerConfig(chain, owner, warpCorePath, warpDeployPath) {
const warpDeployConfig = await readWarpConfig(chain, warpCorePath, warpDeployPath);
warpDeployConfig[chain].owner = owner;
writeYamlOrJson(warpDeployPath, warpDeployConfig);
return warpDeployPath;
}
/**
* Updates the Warp route deployment configuration with a new owner, and then applies the changes.
*/
export async function updateOwner(owner, chain, warpConfigPath, warpCoreConfigPath) {
await updateWarpOwnerConfig(chain, owner, warpCoreConfigPath, warpConfigPath);
return hyperlaneWarpApply(warpConfigPath, warpCoreConfigPath);
}
/**
* Extends the Warp route deployment with a new warp config
*/
export async function extendWarpConfig(chain, chainToExtend, extendedConfig, warpCorePath, warpDeployPath) {
const warpDeployConfig = await readWarpConfig(chain, warpCorePath, warpDeployPath);
warpDeployConfig[chainToExtend] = extendedConfig;
writeYamlOrJson(warpDeployPath, warpDeployConfig);
await hyperlaneWarpApply(warpDeployPath, warpCorePath);
return warpDeployPath;
}
/**
* Deploys new core contracts on the specified chain if it doesn't already exist, and returns the chain addresses.
*/
export async function deployOrUseExistingCore(chain, coreInputPath, key) {
const { registry } = await getContext({
registryUri: REGISTRY_PATH,
registryOverrideUri: '',
key,
});
const addresses = (await registry.getChainAddresses(chain));
if (!addresses) {
await hyperlaneCoreDeploy(chain, coreInputPath);
return deployOrUseExistingCore(chain, coreInputPath, key);
}
return addresses;
}
export async function getChainId(chainName, key) {
const { registry } = await getContext({
registryUri: REGISTRY_PATH,
registryOverrideUri: '',
key,
});
const chainMetadata = await registry.getChainMetadata(chainName);
return String(chainMetadata?.chainId);
}
//# sourceMappingURL=helpers.js.map