Skip to content

Commit 1dc1dd3

Browse files
committed
dont access env variables directly
1 parent 70c5b0e commit 1dc1dd3

File tree

8 files changed

+31
-55
lines changed

8 files changed

+31
-55
lines changed

projects/SMARDEX-P2P-Lending/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
const headers = {
2-
origin: "https://subgraph.smardex.io",
3-
referer: "https://subgraph.smardex.io",
4-
"x-api-key": process.env.SMARDEX_SUBGRAPH_API_KEY,
5-
};
1+
const { getEnv } = require("../helper/env");
62

73
const subgraphUrl = "https://subgraph.smardex.io/ethereum/spro";
84

@@ -17,7 +13,11 @@ const getTokenMetrics = async () => {
1713

1814
const result = await fetch(subgraphUrl, {
1915
method: "POST",
20-
headers,
16+
headers: {
17+
origin: "https://subgraph.smardex.io",
18+
referer: "https://subgraph.smardex.io",
19+
"x-api-key": getEnv('SMARDEX_SUBGRAPH_API_KEY'),
20+
},
2121
body: JSON.stringify({
2222
query: tokenMetricsQuery,
2323
}),

projects/helper/allium.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ const rateLimited = (fn) => (...args) => _rateLimited(() => fn(...args))
99

1010
const token = {}
1111

12-
const HEADERS = {
12+
const HEADERS = () => ({
1313
"Content-Type": "application/json",
14-
"X-API-KEY": process.env.ALLIUM_API_KEY,
15-
};
14+
"X-API-KEY": getEnv('ALLIUM_API_KEY'),
15+
})
1616

1717
async function startAlliumQuery(sqlQuery) {
1818
const query = await axios.post(`https://api.allium.so/api/v1/explorer/queries/phBjLzIZ8uUIDlp0dD3N/run-async`, {
1919
parameters: {
2020
fullQuery: sqlQuery
2121
}
2222
}, {
23-
headers: HEADERS
23+
headers: HEADERS()
2424
})
2525

2626
return query.data["run_id"]
2727
}
2828

2929
async function retrieveAlliumResults(queryId) {
3030
const results = await axios.get(`https://api.allium.so/api/v1/explorer/query-runs/${queryId}/results?f=json`, {
31-
headers: HEADERS
31+
headers: HEADERS()
3232
})
3333
return results.data.data
3434
}
@@ -50,7 +50,7 @@ async function _queryAllium(sqlQuery) {
5050
}
5151

5252
const statusReq = await axios.get(`https://api.allium.so/api/v1/explorer/query-runs/${token[sqlQuery]}/status`, {
53-
headers: HEADERS
53+
headers: HEADERS()
5454
})
5555

5656
const status = statusReq.data

projects/helper/env.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const BOOL_KEYS = [
33
'HISTORICAL',
44
'LLAMA_DEBUG_MODE',
5+
'STORE_IN_R2',
6+
'IS_RUN_FROM_CUSTOM_JOB',
57
]
68

79
const _yek = "b523cf66-7a5a-4fe8-8d67-f604fd0492c2" // bifrost
@@ -60,7 +62,10 @@ const ENV_KEYS = [
6062
'RPC_PROXY_URL',
6163
'BLACKSAIL_API_KEY',
6264
'BITCOIN_CACHE_API',
63-
'DEBANK_API_KEY'
65+
'DEBANK_API_KEY',
66+
'SMARDEX_SUBGRAPH_API_KEY',
67+
'PROXY_AUTH',
68+
'ALLIUM_API_KEY',
6469
]
6570

6671
Object.keys(DEFAULTS).forEach(i => {

projects/helper/proxyRequest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const axios = require('axios');
22
const https = require('https');
3+
const { getEnv } = require('./env');
34

45
const agent = new https.Agent({
56
rejectUnauthorized: false
@@ -12,7 +13,7 @@ async function fetchThroughProxy(rawUrl) {
1213
url: `https://pr.oxylabs.io:7777${url.pathname}${url.search}`,
1314
httpsAgent: agent,
1415
headers: {
15-
'Proxy-Authorization': 'Basic ' + Buffer.from(`${process.env.PROXY_AUTH}`).toString('base64'),
16+
'Proxy-Authorization': 'Basic ' + Buffer.from(getEnv('PROXY_AUTH')).toString('base64'),
1617
Host: url.host
1718
}
1819
});

projects/helper/token.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -146,36 +146,6 @@ async function ankrGetTokens(address, { onlyWhitelisted = true, skipCacheRead =
146146
}
147147
}
148148

149-
async function getETHTokens(address, onlyWhitelisted) {
150-
const endpoint = getEnv('ETHEREUM_TOKENS_ENDPOINT')
151-
if (!endpoint) throw new Error('Missing endpoint for ethereum tokens')
152-
const url = `${endpoint}/v1/1/address/${address}/balances_v2/`
153-
const { data: { items } } = await get(url)
154-
const tokenSet = new Set()
155-
items.forEach(i => {
156-
const token = i.native_token ? ADDRESSES.null : i.contract_address
157-
if (i.is_spam && onlyWhitelisted) return;
158-
tokenSet.add(token)
159-
})
160-
return Array.from(tokenSet)
161-
}
162-
163-
async function getComplexTreasury(owners) {
164-
const networks = ["ethereum", "polygon", "optimism", "gnosis", "binance-smart-chain", "fantom", "avalanche", "arbitrum",
165-
"celo", "harmony", "moonriver", "bitcoin", "cronos", "aurora", "evmos"]
166-
const data = await axios.get(`https://api.zapper.xyz/v2/balances/apps?${owners.map(a => `addresses=${a}`).join("&")}&${networks.map(a => `networks=${a}`).join("&")}`, {
167-
headers: {
168-
Authorization: `Basic ${btoa(process.env.ZAPPER_API_KEY)}`
169-
}
170-
})
171-
let sum = 0
172-
data.data.forEach(d => {
173-
sum += d.balanceUSD
174-
})
175-
return sum
176-
}
177-
178-
179149
module.exports = {
180150
covalentGetTokens,
181151
ankrChainMapping,

projects/p2p-lending/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
const headers = {
2-
origin: "https://subgraph.smardex.io",
3-
referer: "https://subgraph.smardex.io",
4-
"x-api-key": process.env.SMARDEX_SUBGRAPH_API_KEY,
5-
};
1+
const { getEnv } = require("../helper/env");
62

73
const subgraphUrl = "https://subgraph.smardex.io/ethereum/spro";
84

@@ -17,7 +13,11 @@ const getTokenMetrics = async () => {
1713

1814
const result = await fetch(subgraphUrl, {
1915
method: "POST",
20-
headers,
16+
headers: {
17+
origin: "https://subgraph.smardex.io",
18+
referer: "https://subgraph.smardex.io",
19+
"x-api-key": getEnv('SMARDEX_SUBGRAPH_API_KEY'),
20+
},
2121
body: JSON.stringify({
2222
query: tokenMetricsQuery,
2323
}),

projects/uniswap-v4/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { sumTokens2 } = require("../helper/unwrapLPs");
22
const { getLogs2 } = require('../helper/cache/getLogs');
33
const { nullAddress } = require("../helper/tokenMapping");
4+
const { getEnv } = require("../helper/env");
45

56
// from https://docs.uniswap.org/contracts/v4/deployments
67
const config = {
@@ -25,7 +26,7 @@ Object.keys(config).forEach(chain => {
2526
const { factory, fromBlock } = config[chain]
2627
module.exports[chain] = {
2728
tvl: async (api) => {
28-
if (!process.env.IS_RUN_FROM_CUSTOM_JOB) throw new Error('This job is not meant to be run directly, please use the custom job feature')
29+
if (!getEnv('IS_RUN_FROM_CUSTOM_JOB')) throw new Error('This job is not meant to be run directly, please use the custom job feature')
2930

3031
let compressType
3132
if (chain === 'base') compressType = 'v1'

utils/scripts/checkBTCDupsv2.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
const sdk = require('@defillama/sdk')
22
const addressBook = require('../../projects/helper/bitcoin-book/index');
3+
const { getEnv } = require('../../projects/helper/env');
34
const Bucket = "tvl-adapter-cache";
45

56
console.log('project count: ', Object.keys(addressBook).length);
67
const addressProjectMap = {}
78

8-
const storeInR2 = !!process.env.STORE_IN_R2
9-
109
const projectData = {}
1110

1211
async function run() {
@@ -20,7 +19,7 @@ async function run() {
2019
if (!Array.isArray(addresses)) addresses = await addresses()
2120

2221

23-
if (storeInR2) {
22+
if (getEnv('STORE_IN_R2')) {
2423
projectData[project] = addresses
2524
return;
2625
}
@@ -43,7 +42,7 @@ async function run() {
4342

4443

4544

46-
if (storeInR2) {
45+
if (getEnv('STORE_IN_R2')) {
4746
try {
4847
await sdk.cache.writeCache(`${Bucket}/bitcoin-addresses.json`, projectData)
4948
console.log('data written to s3 bucket');

0 commit comments

Comments
 (0)