Skip to content

Commit 5caac66

Browse files
authored
feat(provider-sdk): add crossCollateral warp token type (#8380)
1 parent 8241083 commit 5caac66

6 files changed

Lines changed: 129 additions & 2 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@hyperlane-xyz/provider-sdk": minor
3+
"@hyperlane-xyz/sealevel-sdk": patch
4+
"@hyperlane-xyz/radix-sdk": patch
5+
"@hyperlane-xyz/cosmos-sdk": patch
6+
"@hyperlane-xyz/aleo-sdk": patch
7+
---
8+
9+
Added `crossCollateral` warp token type to the provider-sdk type system. All protocol SDK artifact managers were updated to handle the new type in their exhaustive switches.

typescript/aleo-sdk/src/warp/warp-artifact-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export class AleoWarpArtifactManager implements IRawWarpArtifactManager {
7575
this.aleoClient,
7676
this.onChainArtifactManagers,
7777
),
78+
crossCollateral: () => {
79+
throw new Error('Cross-collateral tokens are not supported on Aleo');
80+
},
7881
};
7982

8083
return readers[type]();
@@ -108,6 +111,9 @@ export class AleoWarpArtifactManager implements IRawWarpArtifactManager {
108111
signer,
109112
this.onChainArtifactManagers,
110113
),
114+
crossCollateral: () => {
115+
throw new Error('Cross-collateral tokens are not supported on Aleo');
116+
},
111117
};
112118

113119
return writers[type]();

typescript/cosmos-sdk/src/warp/warp-artifact-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export class CosmosWarpArtifactManager implements IRawWarpArtifactManager {
9898
native: () => {
9999
throw new Error('Native tokens are not supported on Cosmos');
100100
},
101+
crossCollateral: () => {
102+
throw new Error('Cross-collateral tokens are not supported on Cosmos');
103+
},
101104
};
102105

103106
return readers[type]();
@@ -143,6 +146,9 @@ export class CosmosWarpArtifactManager implements IRawWarpArtifactManager {
143146
native: () => {
144147
throw new Error('Native tokens are not supported on Cosmos');
145148
},
149+
crossCollateral: () => {
150+
throw new Error('Cross-collateral tokens are not supported on Cosmos');
151+
},
146152
};
147153

148154
return writers[type]();

typescript/provider-sdk/src/warp.ts

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const TokenType = {
3838
synthetic: 'synthetic',
3939
collateral: 'collateral',
4040
native: 'native',
41+
crossCollateral: 'crossCollateral',
4142
} as const;
4243

4344
export 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+
7582
export type WarpConfig =
7683
| CollateralWarpConfig
7784
| SyntheticWarpConfig
78-
| NativeWarpConfig;
85+
| NativeWarpConfig
86+
| CrossCollateralWarpConfig;
7987

8088
export 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+
110127
export type DerivedWarpConfig =
111128
| DerivedCollateralWarpConfig
112129
| DerivedSyntheticWarpConfig
113-
| DerivedNativeWarpConfig;
130+
| DerivedNativeWarpConfig
131+
| DerivedCrossCollateralWarpConfig;
114132

115133
export 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+
160184
export interface WarpArtifactConfigs {
161185
collateral: CollateralWarpArtifactConfig;
162186
synthetic: SyntheticWarpArtifactConfig;
163187
native: NativeWarpArtifactConfig;
188+
crossCollateral: CrossCollateralWarpArtifactConfig;
164189
}
165190

166191
export type WarpType = keyof WarpArtifactConfigs;
@@ -198,10 +223,14 @@ export type RawSyntheticWarpArtifactConfig =
198223
export type RawNativeWarpArtifactConfig =
199224
ConfigOnChain<NativeWarpArtifactConfig>;
200225

226+
export type RawCrossCollateralWarpArtifactConfig =
227+
ConfigOnChain<CrossCollateralWarpArtifactConfig>;
228+
201229
export 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

510604
export interface WarpRouterDiff {

typescript/radix-sdk/src/warp/warp-artifact-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export class RadixWarpArtifactManager implements IRawWarpArtifactManager {
6363
native: () => {
6464
throw new Error('Native tokens are not supported on Radix');
6565
},
66+
crossCollateral: () => {
67+
throw new Error('Cross-collateral tokens are not supported on Radix');
68+
},
6669
};
6770

6871
return readers[type]();
@@ -87,6 +90,9 @@ export class RadixWarpArtifactManager implements IRawWarpArtifactManager {
8790
native: () => {
8891
throw new Error('Native tokens are not supported on Radix');
8992
},
93+
crossCollateral: () => {
94+
throw new Error('Cross-collateral tokens are not supported on Radix');
95+
},
9096
};
9197

9298
return writers[type]();

typescript/svm-sdk/src/warp/warp-artifact-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export class SvmWarpArtifactManager implements IRawWarpArtifactManager {
5353
native: () => new SvmNativeTokenReader(this.rpc),
5454
synthetic: () => new SvmSyntheticTokenReader(this.rpc),
5555
collateral: () => new SvmCollateralTokenReader(this.rpc),
56+
crossCollateral: () => {
57+
throw new Error('Cross-collateral tokens are not yet supported on SVM');
58+
},
5659
};
5760

5861
return readers[type]();
@@ -99,6 +102,9 @@ export class SvmWarpArtifactManager implements IRawWarpArtifactManager {
99102
this.rpc,
100103
signer,
101104
),
105+
crossCollateral: () => {
106+
throw new Error('Cross-collateral tokens are not yet supported on SVM');
107+
},
102108
};
103109

104110
return writers[type]();

0 commit comments

Comments
 (0)