feat(cli): Support creating agent configs from CLI (#3938)
### Description - Add support for creating agent configs using the CLI - registry agent-config command with a required --chains option - This will pick up local registry data Example usage: `hyperlane registry agent-config --chains anvil8545` <!-- What's included in this PR? --> ### Drive-by changes <!-- Are there any minor or drive-by changes also included? --> ### Related issues <!-- - Fixes #[issue number here] --> - Fixes #[3720](https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/3720) ### Backward compatibility <!-- Are these changes backward compatible? Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling? Yes/No --> Yes ### Testing Manual <!-- What kind of testing have these changes undergone? None/Manual/Unit Tests -->pull/3969/head
parent
6d30eed2bb
commit
35f8699505
@ -0,0 +1,5 @@ |
||||
--- |
||||
'@hyperlane-xyz/cli': minor |
||||
--- |
||||
|
||||
Add command to support creating agent configs |
@ -0,0 +1,2 @@ |
||||
export const ChainTypes = ['mainnet', 'testnet']; |
||||
export type ChainType = (typeof ChainTypes)[number]; |
@ -0,0 +1,75 @@ |
||||
import { fromError } from 'zod-validation-error'; |
||||
|
||||
import { |
||||
AgentConfigSchema, |
||||
ChainMap, |
||||
HyperlaneCore, |
||||
HyperlaneDeploymentArtifacts, |
||||
buildAgentConfig, |
||||
} from '@hyperlane-xyz/sdk'; |
||||
import { objMap, promiseObjAll } from '@hyperlane-xyz/utils'; |
||||
|
||||
import { CommandContext } from '../context/types.js'; |
||||
import { logBlue, logGreen, logRed } from '../logger.js'; |
||||
import { writeYamlOrJson } from '../utils/files.js'; |
||||
|
||||
export async function createAgentConfig({ |
||||
context, |
||||
chains, |
||||
out, |
||||
}: { |
||||
context: CommandContext; |
||||
chains: string[]; |
||||
out: string; |
||||
}) { |
||||
logBlue('\nCreating agent config...'); |
||||
|
||||
const { registry, multiProvider, chainMetadata } = context; |
||||
const addresses = await registry.getAddresses(); |
||||
|
||||
const core = HyperlaneCore.fromAddressesMap(addresses, multiProvider); |
||||
|
||||
const startBlocks = await promiseObjAll( |
||||
objMap(addresses, async (chain, _) => { |
||||
// If the index.from is specified in the chain metadata, use that.
|
||||
const indexFrom = chainMetadata[chain].index?.from; |
||||
if (indexFrom !== undefined) { |
||||
return indexFrom; |
||||
} |
||||
|
||||
const mailbox = core.getContracts(chain).mailbox; |
||||
try { |
||||
const deployedBlock = await mailbox.deployedBlock(); |
||||
return deployedBlock.toNumber(); |
||||
} catch (err) { |
||||
logRed( |
||||
`Failed to get deployed block to set an index for ${chain}, this is potentially an issue with rpc provider or a misconfiguration`, |
||||
); |
||||
process.exit(1); |
||||
} |
||||
}), |
||||
); |
||||
|
||||
// @TODO: consider adding additional config used to pass in gas prices for Cosmos chains
|
||||
const agentConfig = buildAgentConfig( |
||||
chains, |
||||
multiProvider, |
||||
addresses as ChainMap<HyperlaneDeploymentArtifacts>, |
||||
startBlocks, |
||||
); |
||||
|
||||
try { |
||||
AgentConfigSchema.parse(agentConfig); |
||||
} catch (e) { |
||||
logRed( |
||||
`Agent config is invalid, this is possibly due to required contracts not being deployed. See details below:\n${fromError( |
||||
e, |
||||
).toString()}`,
|
||||
); |
||||
process.exit(1); |
||||
} |
||||
|
||||
logBlue(`Agent config is valid, writing to file ${out}`); |
||||
writeYamlOrJson(out, agentConfig, 'json'); |
||||
logGreen(`✅ Agent config successfully written to ${out}`); |
||||
} |
Loading…
Reference in new issue