This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
/
config.ts
73 lines (65 loc) · 2.49 KB
/
config.ts
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
import * as dotenv from "dotenv";
import type { ContractsConfig, ContractsConfigMap } from "./types";
import { goerliConfig } from "./goerli";
import { mainnetConfig } from "./mainnet";
import { localhostConfig } from "./localhost";
import { arbitrumConfig } from "./arbitrum";
import { arbitrumGoerliConfig } from "./arbitrumGoerli";
import { avalancheInsti1Testnet } from "./avalancheInsti1Testnet";
import { avalancheFujiConfig } from "./avalancheFuji";
import { avalancheConfig } from "./avalanche";
dotenv.config();
function duplicateExists(arr: string[]) {
return new Set(arr).size !== arr.length;
}
const config: ContractsConfigMap = {
goerli: goerliConfig,
// localhost: mainnetConfig, // Uncomment if testing against a fork of an existing mainnet system
localhost: localhostConfig,
mainnet: mainnetConfig,
arbitrum: arbitrumConfig,
arbitrumGoerli: arbitrumGoerliConfig,
avalanche: avalancheConfig,
avalancheFuji: avalancheFujiConfig,
avalancheInsti1Testnet: avalancheInsti1Testnet,
// hardhat: { ...mainnetConfig, skipFactoryDeploy: false, }, // uncomment if deploying a new system against a mainnet fork
hardhat: process.env.FORK_MAINNET
? { ...mainnetConfig, skipFactoryDeploy: false }
: localhostConfig,
};
// This function must be used to access config because it performs runtime checks on config consistency
export const getConfig = (_networkName: string): ContractsConfig => {
if (!config[_networkName]) {
throw Error(`No deploy config found for network ${_networkName}`);
}
const _config = config[_networkName];
const compoundTokens = _config.compoundConfig?.compoundTokens;
const aaveTokens = _config.compoundConfig?.compoundTokens;
if (
compoundTokens &&
// check for borrow token duplicates
(duplicateExists(
compoundTokens?.filter((t) => t.borrow).map((t) => t.name)
) ||
// check for non-borrow token duplicates
duplicateExists(
compoundTokens?.filter((t) => !t.borrow).map((t) => t.name)
))
) {
throw Error(
`Duplicate token names configured for Compound on network ${_networkName}`
);
}
if (
aaveTokens &&
// check for borrow token duplicates
(duplicateExists(aaveTokens?.filter((t) => t.borrow).map((t) => t.name)) ||
// check for non-borrow token duplicates
duplicateExists(aaveTokens?.filter((t) => !t.borrow).map((t) => t.name)))
) {
throw Error(
`Duplicate token names configured for Aave on network ${_networkName}`
);
}
return config[_networkName];
};