@ -1,25 +1,72 @@
import {
import {
ChainMap ,
ChainName ,
ChainName ,
HyperlaneAddresses ,
HyperlaneAgentAddresses ,
HyperlaneDeployer ,
HyperlaneDeployer ,
MultiProvider ,
buildAgentConfig ,
buildContracts ,
buildContracts ,
objMap ,
promiseObjAll ,
serializeContracts ,
serializeContracts ,
} from '@hyperlane-xyz/sdk' ;
} from '@hyperlane-xyz/sdk' ;
import { getAgentConfigDirectory } from '../scripts/utils' ;
import { DeployEnvironment , deployEnvToSdkEnv } from './config/environment' ;
import {
import {
readJSONAtPath ,
readJSONAtPath ,
writeJSON ,
writeJsonAtPath ,
writeJsonAtPath ,
writeMergedJSONAtPath ,
writeMergedJSONAtPath ,
} from './utils/utils' ;
} from './utils/utils' ;
export async function writeAgentConfig (
addressesPath : string ,
multiProvider : MultiProvider ,
environment : DeployEnvironment ,
) {
let addresses : ChainMap < HyperlaneAddresses > = { } ;
try {
addresses = readJSONAtPath ( addressesPath ) ;
} catch ( e ) {
console . error ( 'Failed to load cached addresses' ) ;
}
// Write agent config indexing from the deployed or latest block numbers.
// For non-net-new deployments, these changes will need to be
// reverted manually.
const startBlocks = await promiseObjAll (
objMap ( addresses , ( chain , _ ) = >
multiProvider . getProvider ( chain ) . getBlockNumber ( ) ,
) ,
) ;
const agentConfig = buildAgentConfig (
multiProvider . getKnownChainNames ( ) ,
multiProvider ,
addresses as ChainMap < HyperlaneAgentAddresses > ,
startBlocks ,
) ;
const sdkEnv = deployEnvToSdkEnv [ environment ] ;
writeJSON ( getAgentConfigDirectory ( ) , ` ${ sdkEnv } _config.json ` , agentConfig ) ;
}
export async function deployWithArtifacts (
export async function deployWithArtifacts (
deployer : HyperlaneDeployer < any , any , any > ,
deployer : HyperlaneDeployer < any , any , any > ,
cache ? : {
cache : {
addresses : string ;
addresses : string ;
verification : string ;
verification : string ;
read : boolean ;
write : boolean ;
} ,
} ,
fork? : ChainName ,
fork? : ChainName ,
agentConfig ? : {
multiProvider : MultiProvider ;
addresses : string ;
environment : DeployEnvironment ;
} ,
) {
) {
if ( cache ) {
if ( cache . read ) {
let addresses = { } ;
let addresses = { } ;
try {
try {
addresses = readJSONAtPath ( cache . addresses ) ;
addresses = readJSONAtPath ( cache . addresses ) ;
@ -41,7 +88,7 @@ export async function deployWithArtifacts(
console . error ( 'Failed to deploy contracts' , e ) ;
console . error ( 'Failed to deploy contracts' , e ) ;
}
}
if ( cache ) {
if ( cache . write ) {
// cache addresses of deployed contracts
// cache addresses of deployed contracts
writeMergedJSONAtPath (
writeMergedJSONAtPath (
cache . addresses ,
cache . addresses ,
@ -60,4 +107,11 @@ export async function deployWithArtifacts(
deployer . mergeWithExistingVerificationInputs ( savedVerification ) ;
deployer . mergeWithExistingVerificationInputs ( savedVerification ) ;
writeJsonAtPath ( cache . verification , inputs ) ;
writeJsonAtPath ( cache . verification , inputs ) ;
}
}
if ( agentConfig ) {
await writeAgentConfig (
agentConfig . addresses ,
agentConfig . multiProvider ,
agentConfig . environment ,
) ;
}
}
}