forked from d-EURO/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.config.ts
More file actions
98 lines (89 loc) · 2.81 KB
/
api.config.ts
File metadata and controls
98 lines (89 loc) · 2.81 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
import { Chain, createPublicClient, http } from 'viem';
import { Logger } from '@nestjs/common';
import { mainnet, testnet } from 'chains';
import * as dotenv from 'dotenv';
dotenv.config();
// Verify environment
const isMainnet = process.env.CONFIG_CHAIN === 'mainnet';
if (isMainnet && process.env.RPC_URL_MAINNET === undefined) throw new Error('RPC_URL_MAINNET not available');
if (!isMainnet && process.env.RPC_URL_TESTNET === undefined) throw new Error('RPC_URL_TESTNET not available');
if (process.env.COINGECKO_API_KEY === undefined) throw new Error('COINGECKO_API_KEY not available');
// Config type
export type ConfigType = {
app: string;
indexer: string;
indexerFallback: string;
coingeckoApiKey: string;
chain: Chain;
network: {
mainnet: string;
testnet: string;
};
telegram: {
botToken: string;
groupsJson: string;
imagesDir: string;
} | null;
twitter: {
accessToken: string;
accessSecret: string;
appKey: string;
appSecret: string;
imagesDir: string;
} | null;
};
// Create config
export const CONFIG: ConfigType = {
app: process.env.CONFIG_APP_URL,
indexer: process.env.CONFIG_INDEXER_URL,
indexerFallback: process.env.CONFIG_INDEXER_FALLBACK_URL,
coingeckoApiKey: process.env.COINGECKO_API_KEY,
chain: isMainnet ? mainnet : testnet,
network: {
mainnet: process.env.RPC_URL_MAINNET,
testnet: process.env.RPC_URL_TESTNET,
},
telegram: process.env.TELEGRAM_BOT_TOKEN
? {
botToken: process.env.TELEGRAM_BOT_TOKEN,
groupsJson: process.env.TELEGRAM_GROUPS_JSON,
imagesDir: process.env.TELEGRAM_IMAGES_DIR,
}
: null,
twitter: process.env.TWITTER_CLIENT_APP_KEY
? {
appKey: process.env.TWITTER_CLIENT_APP_KEY,
appSecret: process.env.TWITTER_CLIENT_APP_SECRET,
accessToken: process.env.TWITTER_ACCESS_TOKEN,
accessSecret: process.env.TWITTER_ACCESS_SECRET,
imagesDir: process.env.TWITTER_IMAGES_DIR,
}
: null,
};
export function logConfig() {
const logger = new Logger('ApiConfig');
logger.log(`Starting API with this config:`);
logger.log(JSON.stringify(CONFIG));
}
// Refer to https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files
process.env.NTBA_FIX_350 = 'true';
// VIEM CONFIG
export const VIEM_CHAIN = CONFIG.chain;
export const VIEM_CONFIG = createPublicClient({
chain: VIEM_CHAIN,
transport: http(isMainnet ? CONFIG.network.mainnet : CONFIG.network.testnet),
batch: {
multicall: {
wait: 200,
},
},
});
// COINGECKO CLIENT
export const COINGECKO_CLIENT = (query: string) => {
const hasParams = query.includes('?');
const uri: string = `https://pro-api.coingecko.com${query}`;
return fetch(`${uri}${hasParams ? '&' : '?'}x_cg_pro_api_key=${CONFIG.coingeckoApiKey}`);
};
export const PROTOCOL_STABLECOIN_SYMBOL = 'JUSD';
export const PROTOCOL_STABLECOIN_NAME = 'Juice Dollar';
export const POOL_SHARES_SYMBOL = 'JUICE';