1
- import type { Network , Platform } from "@wormhole-foundation/sdk-base" ;
1
+ import type { Chain , Network , Platform } from "@wormhole-foundation/sdk-base" ;
2
2
import { circle } from "@wormhole-foundation/sdk-base" ;
3
- import type { ChainsConfig } from "@wormhole-foundation/sdk-definitions" ;
3
+ import type { ChainConfig , ChainsConfig } from "@wormhole-foundation/sdk-definitions" ;
4
4
import { buildConfig } from "@wormhole-foundation/sdk-definitions" ;
5
5
6
6
export const DEFAULT_TASK_TIMEOUT = 60 * 1000 ; // 1 minute in milliseconds
@@ -11,16 +11,6 @@ export type WormholeConfig<N extends Network = Network, P extends Platform = Pla
11
11
chains : ChainsConfig < N , P > ;
12
12
} ;
13
13
14
- type RecursivePartial < T > = {
15
- [ P in keyof T ] ?: T [ P ] extends ( infer U ) [ ]
16
- ? RecursivePartial < U > [ ]
17
- : T [ P ] extends object | undefined
18
- ? RecursivePartial < T [ P ] >
19
- : T [ P ] ;
20
- } ;
21
-
22
- export type ConfigOverrides < N extends Network > = RecursivePartial < WormholeConfig < N > > ;
23
-
24
14
export const CONFIG = {
25
15
Mainnet : {
26
16
api : "https://api.wormholescan.io" ,
@@ -50,28 +40,53 @@ export function networkPlatformConfigs<N extends Network, P extends Platform>(
50
40
) as ChainsConfig < N , P > ;
51
41
}
52
42
43
+ type RecursivePartial < T > = {
44
+ [ P in keyof T ] ?: T [ P ] extends ( infer U ) [ ]
45
+ ? RecursivePartial < U > [ ]
46
+ : T [ P ] extends object | undefined
47
+ ? RecursivePartial < T [ P ] >
48
+ : T [ P ] ;
49
+ } ;
50
+ export type WormholeConfigOverrides < N extends Network > = RecursivePartial < WormholeConfig < N > > ;
51
+ export type ChainsConfigOverrides < N extends Network , P extends Platform > = RecursivePartial <
52
+ ChainsConfig < N , P >
53
+ > ;
54
+ export type ChainConfigOverrides < N extends Network , C extends Chain > = RecursivePartial <
55
+ ChainConfig < N , C >
56
+ > ;
57
+
53
58
// Apply any overrides to the base config
54
- export function applyOverrides < N extends Network > (
59
+ export function applyWormholeConfigOverrides < N extends Network > (
55
60
network : N ,
56
- overrides ?: ConfigOverrides < N > ,
61
+ overrides ?: WormholeConfigOverrides < N > ,
57
62
) : WormholeConfig {
58
63
let base = CONFIG [ network ] ;
59
64
if ( ! overrides ) return base ;
65
+ return override ( base , overrides ) ;
66
+ }
67
+
68
+ // Apply any overrides to the base config
69
+ export function applyChainsConfigConfigOverrides < N extends Network , P extends Platform > (
70
+ network : N ,
71
+ platform : P ,
72
+ overrides ?: ChainsConfigOverrides < N , P > ,
73
+ ) : ChainsConfig < N , P > {
74
+ const base = networkPlatformConfigs ( network , platform ) ;
75
+ if ( ! overrides ) return base ;
76
+ return override ( base , overrides ) ;
77
+ }
60
78
61
- // recurse through the overrides and apply them to the base config
62
- function override ( base : any , overrides : any ) {
63
- if ( ! base ) base = { } ;
64
- for ( const [ key , value ] of Object . entries ( overrides ) ) {
65
- if ( typeof value === "object" && ! Array . isArray ( value ) ) {
66
- base [ key ] = override ( base [ key ] , value ) ;
67
- } else {
68
- base [ key ] = value ;
69
- }
79
+ // recurse through the overrides and apply them to the base config
80
+ function override ( base : any , overrides : any ) {
81
+ if ( ! base ) base = { } ;
82
+ for ( const [ key , value ] of Object . entries ( overrides ) ) {
83
+ if ( typeof value === "object" && ! Array . isArray ( value ) ) {
84
+ base [ key ] = override ( base [ key ] , value ) ;
85
+ } else {
86
+ base [ key ] = value ;
70
87
}
71
- return base ;
72
88
}
73
-
74
- return override ( base , overrides ) ;
89
+ return base ;
75
90
}
76
91
77
92
const inNode = typeof process !== "undefined" ;
0 commit comments