-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathconfig.ts
More file actions
108 lines (99 loc) · 3.33 KB
/
Copy pathconfig.ts
File metadata and controls
108 lines (99 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import type { Chain, Network, Platform } from "@wormhole-foundation/sdk-base";
import { circle, executor } from "@wormhole-foundation/sdk-base";
import type {
CapabilitiesResponse,
ChainConfig,
ChainsConfig,
} from "@wormhole-foundation/sdk-definitions";
import { buildConfig } from "@wormhole-foundation/sdk-definitions";
export const DEFAULT_TASK_TIMEOUT = 60 * 1000; // 1 minute in milliseconds
export type WormholeConfig<N extends Network = Network, P extends Platform = Platform> = {
api: string;
circleAPI: string;
executorAPI: string;
chains: ChainsConfig<N, P>;
executor?: {
/** Override the default capabilities fetcher (e.g. to cache or use a custom endpoint). */
getCapabilities?: (network: Network) => Promise<CapabilitiesResponse>;
};
};
export const CONFIG = {
Mainnet: {
api: "https://api.wormholescan.io",
circleAPI: circle.circleAPI("Mainnet"),
executorAPI: executor.executorAPI("Mainnet"),
chains: buildConfig("Mainnet"),
},
Testnet: {
api: "https://api.testnet.wormholescan.io",
circleAPI: circle.circleAPI("Testnet"),
executorAPI: executor.executorAPI("Testnet"),
chains: buildConfig("Testnet"),
},
Devnet: {
api: "http://guardian:7071", // Tilt Guardian REST api
circleAPI: "",
executorAPI: "",
chains: buildConfig("Devnet"),
},
} as const satisfies Record<Network, WormholeConfig>;
export function networkPlatformConfigs<N extends Network, P extends Platform>(
network: N,
platform: P,
): ChainsConfig<N, P> {
return Object.fromEntries(
Object.entries(CONFIG[network].chains).filter(([_, c]) => {
return c.platform == platform;
}),
) as ChainsConfig<N, P>;
}
type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends (infer U)[]
? RecursivePartial<U>[]
: T[P] extends (...args: any[]) => any
? T[P]
: T[P] extends object | undefined
? RecursivePartial<T[P]>
: T[P];
};
export type WormholeConfigOverrides<N extends Network> = RecursivePartial<WormholeConfig<N>>;
export type ChainsConfigOverrides<N extends Network, P extends Platform> = RecursivePartial<
ChainsConfig<N, P>
>;
export type ChainConfigOverrides<N extends Network, C extends Chain> = RecursivePartial<
ChainConfig<N, C>
>;
// Apply any overrides to the base config
export function applyWormholeConfigOverrides<N extends Network>(
network: N,
overrides?: WormholeConfigOverrides<N>,
): WormholeConfig {
let base = CONFIG[network];
if (!overrides) return base;
return override(base, overrides);
}
// Apply any overrides to the base config
export function applyChainsConfigConfigOverrides<N extends Network, P extends Platform>(
network: N,
platform: P,
overrides?: ChainsConfigOverrides<N, P>,
): ChainsConfig<N, P> {
const base = networkPlatformConfigs(network, platform);
if (!overrides) return base;
return override(base, overrides);
}
// recurse through the overrides and apply them to the base config
function override(base: any, overrides: any) {
if (!base) base = {};
for (const [key, value] of Object.entries(overrides)) {
if (typeof value === "object" && !Array.isArray(value)) {
base[key] = override(base[key], value);
} else {
base[key] = value;
}
}
return base;
}
const inNode = typeof process !== "undefined";
export const DEFAULT_NETWORK: Network =
(inNode && (process.env["NETWORK"] as Network)) || "Testnet";