forked from DefiLlama/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboostrapMedianTable.js
49 lines (42 loc) · 1.53 KB
/
boostrapMedianTable.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
45
46
47
48
49
const fs = require('fs');
const AWS = require('aws-sdk');
const ss = require('simple-statistics');
const { confirm } = require('../src/utils/confirm');
const { boundaries } = require('../src/utils/exclude');
const { insertMedian } = require('../src/handlers/triggerMedian');
// set config (we run this script locally)
const credentials = new AWS.SharedIniFileCredentials({ profile: 'defillama' });
AWS.config.credentials = credentials;
AWS.config.update({ region: 'eu-central-1' });
process.env['SSM_PATH'] = '/llama-apy/serverless/sls-authenticate';
(async () => {
await confirm(
`Confirm with 'yes' if you want to start the ${process.argv[1]
.split('/')
.slice(-1)} script: `
);
// pools.json is a full database snapshot of daily values only (the last value per pool per day)
// containing pool and the total apy fields
let data = JSON.parse(fs.readFileSync(process.argv[2]));
// keeping positive values only
data = data.filter(
(p) =>
p.apy !== null && p.apy >= boundaries.apy.lb && p.apy <= boundaries.apy.ub
);
const payload = [];
for (const [i, timestamp] of [
...new Set(data.map((el) => el.timestamp)),
].entries()) {
console.log(i, timestamp);
// filter to day
let X = data.filter((el) => el.timestamp === timestamp);
payload.push({
timestamp: new Date(timestamp),
medianAPY: ss.median(X.map((p) => p.apy)),
uniquePools: new Set(X.map((p) => p.pool)).size,
});
}
const response = await insertMedian(payload);
console.log(response);
process.exit(0);
})();