@@ -5,6 +5,7 @@ import { ChainAddresses } from '@hyperlane-xyz/registry';
55import {
66 AgentConfig ,
77 ChainMap ,
8+ ChainMetadata ,
89 ChainTechnicalStack ,
910 CoreFactories ,
1011 HyperlaneContracts ,
@@ -25,6 +26,7 @@ import {
2526} from '@hyperlane-xyz/utils' ;
2627
2728import { Contexts } from '../../config/contexts.js' ;
29+ import { agentSpecificChainMetadataOverrides } from '../../config/environments/mainnet3/chains.js' ;
2830import mainnet3GasPrices from '../../config/environments/mainnet3/gasPrices.json' with { type : 'json' } ;
2931import testnet4GasPrices from '../../config/environments/testnet4/gasPrices.json' with { type : 'json' } ;
3032import {
@@ -69,20 +71,29 @@ export async function writeAgentConfig(
6971 // Get gas prices for Cosmos chains.
7072 // Instead of iterating through `addresses`, which only includes EVM chains,
7173 // iterate through the environment chain names.
74+
75+ const envConfig = getEnvironmentConfig ( environment ) ;
7276 const envAgentConfig = getAgentConfig ( Contexts . Hyperlane , environment ) ;
7377 const environmentChains = envAgentConfig . environmentChainNames ;
78+ const registry =
79+ environment !== 'test' ? await envConfig . getRegistry ( ) : undefined ;
80+
81+ // Build additional config for:
82+ // - cosmos/cosmos native chains that require special gas price handling
83+ // - any chains that have agent-specific overrides
7484 const additionalConfig = Object . fromEntries (
7585 await Promise . all (
76- environmentChains
77- . filter (
78- ( chain ) =>
79- chainIsProtocol ( chain , ProtocolType . Cosmos ) ||
80- chainIsProtocol ( chain , ProtocolType . CosmosNative ) ,
81- )
82- . map ( async ( chain ) => {
86+ environmentChains . map ( async ( chain ) => {
87+ let config : Partial < ChainMetadata > = { } ;
88+
89+ // Get Cosmos gas price if applicable
90+ if (
91+ chainIsProtocol ( chain , ProtocolType . Cosmos ) ||
92+ chainIsProtocol ( chain , ProtocolType . CosmosNative )
93+ ) {
8394 try {
8495 const gasPrice = await getCosmosChainGasPrice ( chain , multiProvider ) ;
85- return [ chain , { gasPrice } ] ;
96+ config . gasPrice = gasPrice ;
8697 } catch ( error ) {
8798 rootLogger . error ( `Error getting gas price for ${ chain } :` , error ) ;
8899 const { denom } = await multiProvider . getNativeToken ( chain ) ;
@@ -93,9 +104,27 @@ export async function writeAgentConfig(
93104 . amount
94105 : testnet4GasPrices [ chain as keyof typeof testnet4GasPrices ]
95106 . amount ;
96- return [ chain , { gasPrice : { denom, amount } } ] ;
107+ config . gasPrice = { denom, amount } ;
97108 }
98- } ) ,
109+ }
110+
111+ // Merge agent-specific overrides with general overrides
112+ // TODO: support testnet4 overrides (if we ever need to)
113+ const agentSpecificOverrides =
114+ agentSpecificChainMetadataOverrides [ chain ] ;
115+ if ( agentSpecificOverrides && registry ) {
116+ const chainMetadata = await registry . getChainMetadata ( chain ) ;
117+ assert ( chainMetadata , `Chain metadata not found for chain ${ chain } ` ) ;
118+ // Only care about blocks and transactionOverrides from the agent-specific overrides
119+ const { blocks, transactionOverrides } = objMerge (
120+ chainMetadata ,
121+ agentSpecificOverrides ,
122+ ) ;
123+ config = objMerge ( config , { blocks, transactionOverrides } ) ;
124+ }
125+
126+ return [ chain , config ] ;
127+ } ) ,
99128 ) ,
100129 ) ;
101130
0 commit comments