-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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](#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 -->
- Loading branch information
1 parent
6d30eed
commit 35f8699
Showing
7 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hyperlane-xyz/cli': minor | ||
--- | ||
|
||
Add command to support creating agent configs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const ChainTypes = ['mainnet', 'testnet']; | ||
export type ChainType = (typeof ChainTypes)[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters