@@ -4,6 +4,7 @@ import { stringify as yamlStringify } from 'yaml';
44import {
55 ChainMap ,
66 DeployedOwnableConfig ,
7+ HypERC20Deployer ,
78 IsmConfig ,
89 IsmType ,
910 MailboxClientConfig ,
@@ -22,13 +23,15 @@ import { errorRed, log, logBlue, logGreen } from '../logger.js';
2223import { runMultiChainSelectionStep } from '../utils/chains.js' ;
2324import {
2425 indentYamlOrJson ,
26+ isFile ,
2527 readYamlOrJson ,
2628 writeYamlOrJson ,
2729} from '../utils/files.js' ;
2830import {
2931 detectAndConfirmOrPrompt ,
3032 setProxyAdminConfig ,
3133} from '../utils/input.js' ;
34+ import { useProvidedWarpRouteIdOrPrompt } from '../utils/warp.js' ;
3235
3336import { createAdvancedIsmConfig } from './ism.js' ;
3437
@@ -88,13 +91,24 @@ export async function fillDefaults(
8891 ) ;
8992}
9093
91- export async function readWarpRouteDeployConfig (
92- filePath : string ,
93- context : CommandContext ,
94- ) : Promise < WarpRouteDeployConfigMailboxRequired > {
95- let config = readYamlOrJson ( filePath ) ;
96- if ( ! config )
97- throw new Error ( `No warp route deploy config found at ${ filePath } ` ) ;
94+ export async function readWarpRouteDeployConfig ( {
95+ context,
96+ ...args
97+ } :
98+ | {
99+ context : CommandContext ;
100+ warpRouteId : string ;
101+ }
102+ | {
103+ context : CommandContext ;
104+ filePath : string ;
105+ } ) : Promise < WarpRouteDeployConfigMailboxRequired > {
106+ let config =
107+ 'filePath' in args
108+ ? readYamlOrJson ( args . filePath )
109+ : await context . registry . getWarpDeployConfig ( args . warpRouteId ) ;
110+
111+ assert ( config , `No warp route deploy config found!` ) ;
98112
99113 config = await fillDefaults ( context , config as any ) ;
100114
@@ -112,7 +126,7 @@ export async function createWarpRouteDeployConfig({
112126 advanced = false ,
113127} : {
114128 context : CommandContext ;
115- outPath : string ;
129+ outPath ? : string ;
116130 advanced : boolean ;
117131} ) {
118132 logBlue ( 'Creating a new warp route deployment config...' ) ;
@@ -253,7 +267,21 @@ export async function createWarpRouteDeployConfig({
253267 const warpRouteDeployConfig = WarpRouteDeployConfigSchema . parse ( result ) ;
254268 logBlue ( `Warp Route config is valid, writing to file ${ outPath } :\n` ) ;
255269 log ( indentYamlOrJson ( yamlStringify ( warpRouteDeployConfig , null , 2 ) , 4 ) ) ;
256- writeYamlOrJson ( outPath , warpRouteDeployConfig , 'yaml' ) ;
270+ if ( outPath ) {
271+ writeYamlOrJson ( outPath , warpRouteDeployConfig , 'yaml' ) ;
272+ } else {
273+ const tokenMetadata = await HypERC20Deployer . deriveTokenMetadata (
274+ context . multiProvider ,
275+ warpRouteDeployConfig ,
276+ ) ;
277+ assert (
278+ tokenMetadata ?. symbol ,
279+ 'Error deriving token metadata, please check the provided token addresses' ,
280+ ) ;
281+ await context . registry . addWarpRouteConfig ( warpRouteDeployConfig , {
282+ symbol : tokenMetadata . symbol ,
283+ } ) ;
284+ }
257285 logGreen ( '✅ Successfully created new warp route deployment config.' ) ;
258286 } catch ( e ) {
259287 errorRed (
@@ -269,9 +297,29 @@ function restrictChoices(typeChoices: TokenType[]) {
269297
270298// Note, this is different than the function above which reads a config
271299// for a DEPLOYMENT. This gets a config for using a warp route (aka WarpCoreConfig)
272- export function readWarpCoreConfig ( filePath : string ) : WarpCoreConfig {
273- const config = readYamlOrJson ( filePath ) ;
274- if ( ! config ) throw new Error ( `No warp route config found at ${ filePath } ` ) ;
300+ export async function readWarpCoreConfig (
301+ args :
302+ | {
303+ context : CommandContext ;
304+ warpRouteId : string ;
305+ }
306+ | {
307+ filePath : string ;
308+ } ,
309+ ) : Promise < WarpCoreConfig > {
310+ let config : WarpCoreConfig | null = null ;
311+ const readWithFilePath = 'filePath' in args ;
312+ if ( readWithFilePath ) {
313+ config = readYamlOrJson ( args . filePath ) ;
314+ } else {
315+ config = await args . context . registry . getWarpRoute ( args . warpRouteId ) ;
316+ }
317+ assert (
318+ config ,
319+ `No warp route config found for warp route ${
320+ readWithFilePath ? args . filePath : args . warpRouteId
321+ } `,
322+ ) ;
275323 return WarpCoreConfigSchema . parse ( config ) ;
276324}
277325
@@ -310,3 +358,43 @@ function createFallbackRoutingConfig(owner: Address): IsmConfig {
310358 owner,
311359 } ;
312360}
361+
362+ export async function getWarpRouteDeployConfig ( {
363+ context,
364+ warpRouteDeployConfigPath,
365+ warpRouteId : providedWarpRouteId ,
366+ symbol,
367+ } : {
368+ context : CommandContext ;
369+ warpRouteDeployConfigPath ?: string ;
370+ warpRouteId ?: string ;
371+ symbol ?: string ;
372+ } ) : Promise < WarpRouteDeployConfigMailboxRequired > {
373+ let warpDeployConfig : WarpRouteDeployConfigMailboxRequired ;
374+
375+ if ( warpRouteDeployConfigPath ) {
376+ assert (
377+ isFile ( warpRouteDeployConfigPath ) ,
378+ `Warp route deployment config file not found at ${ warpRouteDeployConfigPath } ` ,
379+ ) ;
380+ log ( `Using warp route deployment config at ${ warpRouteDeployConfigPath } ` ) ;
381+
382+ warpDeployConfig = await readWarpRouteDeployConfig ( {
383+ context,
384+ filePath : warpRouteDeployConfigPath ,
385+ } ) ;
386+ } else {
387+ const warpRouteId = await useProvidedWarpRouteIdOrPrompt ( {
388+ warpRouteId : providedWarpRouteId ,
389+ context,
390+ symbol,
391+ } ) ;
392+
393+ warpDeployConfig = await readWarpRouteDeployConfig ( {
394+ context,
395+ warpRouteId,
396+ } ) ;
397+ }
398+
399+ return warpDeployConfig ;
400+ }
0 commit comments