-
Notifications
You must be signed in to change notification settings - Fork 872
/
Copy pathbeforeTests.js
44 lines (37 loc) · 1.24 KB
/
beforeTests.js
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
const path = require('path');
const axios = require('axios');
const fs = require('fs');
module.exports = async function () {
require('dotenv').config({ path: '../../config.env' });
const adapter = process.env.npm_config_adapter;
const timestamp = process.env.npm_config_timestamp;
if (!adapter) {
console.error(
`Missing argument, you need to provide the adapter name. Eg: npm run test --adapter=aave-v2`
);
process.exit(1);
}
const cwd = process.cwd();
const passedFile = cwd.includes('src/adaptors')
? path.resolve(cwd, adapter)
: path.resolve(cwd, `./src/adaptors/${adapter}`);
const module = require(passedFile);
global.adapter = adapter;
global.apy = (await module.apy(timestamp)).sort(
(a, b) => b.tvlUsd - a.tvlUsd
);
global.poolsUrl = module.url;
fs.writeFileSync(`./${adapter}_test_output.json`, JSON.stringify(global.apy));
global.protocolsSlug = [
...new Set(
(await axios.get('https://api.llama.fi/protocols')).data.map(
(protocol) => protocol.slug
)
),
];
global.uniquePoolIdentifiersDB = new Set(
(await axios.get('https://yields.llama.fi/distinctID')).data
.filter((p) => p.project !== global.apy[0].project)
.map((p) => p.pool)
);
};