@@ -38,6 +38,7 @@ export const TokenType = {
3838 synthetic : 'synthetic' ,
3939 collateral : 'collateral' ,
4040 native : 'native' ,
41+ crossCollateral : 'crossCollateral' ,
4142} as const ;
4243
4344export type TokenType = ( typeof TokenType ) [ keyof typeof TokenType ] ;
@@ -72,10 +73,17 @@ export interface NativeWarpConfig extends BaseWarpConfig {
7273 type : 'native' ;
7374}
7475
76+ export interface CrossCollateralWarpConfig extends BaseWarpConfig {
77+ type : 'crossCollateral' ;
78+ token : string ;
79+ crossCollateralRouters ?: Record < string , string [ ] > ;
80+ }
81+
7582export type WarpConfig =
7683 | CollateralWarpConfig
7784 | SyntheticWarpConfig
78- | NativeWarpConfig ;
85+ | NativeWarpConfig
86+ | CrossCollateralWarpConfig ;
7987
8088export interface BaseDerivedWarpConfig {
8189 owner : string ;
@@ -107,10 +115,20 @@ export interface DerivedNativeWarpConfig extends BaseDerivedWarpConfig {
107115 type : 'native' ;
108116}
109117
118+ export interface DerivedCrossCollateralWarpConfig extends BaseDerivedWarpConfig {
119+ type : 'crossCollateral' ;
120+ token : string ;
121+ name ?: string ;
122+ symbol ?: string ;
123+ decimals ?: number ;
124+ crossCollateralRouters : Record < string , string [ ] > ;
125+ }
126+
110127export type DerivedWarpConfig =
111128 | DerivedCollateralWarpConfig
112129 | DerivedSyntheticWarpConfig
113- | DerivedNativeWarpConfig ;
130+ | DerivedNativeWarpConfig
131+ | DerivedCrossCollateralWarpConfig ;
114132
115133export type WarpRouteAddresses = {
116134 deployedTokenRoute : string ;
@@ -157,10 +175,17 @@ export interface NativeWarpArtifactConfig extends BaseWarpArtifactConfig {
157175 type : typeof TokenType . native ;
158176}
159177
178+ export interface CrossCollateralWarpArtifactConfig extends BaseWarpArtifactConfig {
179+ type : typeof TokenType . crossCollateral ;
180+ token : string ;
181+ crossCollateralRouters : Record < number , Set < string > > ;
182+ }
183+
160184export interface WarpArtifactConfigs {
161185 collateral : CollateralWarpArtifactConfig ;
162186 synthetic : SyntheticWarpArtifactConfig ;
163187 native : NativeWarpArtifactConfig ;
188+ crossCollateral : CrossCollateralWarpArtifactConfig ;
164189}
165190
166191export type WarpType = keyof WarpArtifactConfigs ;
@@ -198,10 +223,14 @@ export type RawSyntheticWarpArtifactConfig =
198223export type RawNativeWarpArtifactConfig =
199224 ConfigOnChain < NativeWarpArtifactConfig > ;
200225
226+ export type RawCrossCollateralWarpArtifactConfig =
227+ ConfigOnChain < CrossCollateralWarpArtifactConfig > ;
228+
201229export interface RawWarpArtifactConfigs {
202230 collateral : RawCollateralWarpArtifactConfig ;
203231 synthetic : RawSyntheticWarpArtifactConfig ;
204232 native : RawNativeWarpArtifactConfig ;
233+ crossCollateral : RawCrossCollateralWarpArtifactConfig ;
205234}
206235
207236/**
@@ -382,6 +411,21 @@ export function warpConfigToArtifact(
382411 } ,
383412 } ;
384413
414+ case 'crossCollateral' :
415+ return {
416+ artifactState : ArtifactState . NEW ,
417+ config : {
418+ ...baseArtifactConfig ,
419+ type : 'crossCollateral' ,
420+ token : config . token ,
421+ crossCollateralRouters : convertCrossCollateralRoutersToArtifact (
422+ config . crossCollateralRouters ,
423+ chainLookup ,
424+ logger ,
425+ ) ,
426+ } ,
427+ } ;
428+
385429 default : {
386430 const invalidConfig : never = config ;
387431 throw new Error (
@@ -496,6 +540,16 @@ export function warpArtifactToDerivedConfig(
496540 type : TokenType . native ,
497541 } ;
498542
543+ case 'crossCollateral' :
544+ return {
545+ ...baseDerivedConfig ,
546+ type : TokenType . crossCollateral ,
547+ token : config . token ,
548+ crossCollateralRouters : convertCrossCollateralRoutersToDerived (
549+ config . crossCollateralRouters ,
550+ chainLookup ,
551+ ) ,
552+ } ;
499553 default : {
500554 const invalidConfig : never = config ;
501555 throw new Error (
@@ -505,6 +559,46 @@ export function warpArtifactToDerivedConfig(
505559 }
506560}
507561
562+ // Cross-Collateral Router Utilities
563+
564+ function convertCrossCollateralRoutersToArtifact (
565+ crossCollateralRouters : Record < string , string [ ] > | undefined ,
566+ chainLookup : ChainLookup ,
567+ logger ?: Logger ,
568+ ) : Record < number , Set < string > > {
569+ const result : Record < number , Set < string > > = { } ;
570+ if ( ! crossCollateralRouters ) return result ;
571+
572+ for ( const [ chainName , routers ] of Object . entries ( crossCollateralRouters ) ) {
573+ const domainId = chainLookup . getDomainId ( chainName ) ;
574+ if ( isNullish ( domainId ) ) {
575+ logger ?. warn (
576+ `Skipping cross-collateral routers for unknown chain: ${ chainName } . ` +
577+ `Chain not found in chain lookup.` ,
578+ ) ;
579+ continue ;
580+ }
581+ result [ domainId ] = new Set ( routers ) ;
582+ }
583+ return result ;
584+ }
585+
586+ function convertCrossCollateralRoutersToDerived (
587+ crossCollateralRouters : Record < number , Set < string > > ,
588+ chainLookup : ChainLookup ,
589+ ) : Record < string , string [ ] > {
590+ const result : Record < string , string [ ] > = { } ;
591+
592+ for ( const [ domainIdStr , routers ] of Object . entries ( crossCollateralRouters ) ) {
593+ const domainId = parseInt ( domainIdStr ) ;
594+ const chainName = chainLookup . getChainName ( domainId ) ;
595+ if ( ! chainName ) continue ;
596+ result [ chainName ] = Array . from ( routers ) ;
597+ }
598+
599+ return result ;
600+ }
601+
508602// Warp Router Update Utilities
509603
510604export interface WarpRouterDiff {
0 commit comments