Files
DefiLlama-yield-server/scripts/createMedian.js
slasher125 8d55fe9f93 Pg migration (#303)
* migration

* remove balancer pools from exclusion list

* bug fix serverless

* remove timestamp from median, update for tests

* update get distinct id controller

* update distinctID controller, remove dep

* move confirm into scripts

* testing url

* remove Pg suffix from lambda names

* change to existing api host

* add comments

* revert service name, bucketsg

* put pack fantom rpc

* update package.lock
2022-09-06 15:27:30 -07:00

46 lines
1.3 KiB
JavaScript

const fs = require('fs');
const ss = require('simple-statistics');
const { confirm } = require('./confirm');
const exclude = require('../src/utils/exclude');
const { insertMedian } = require('../src/controllers/medianController');
(async () => {
await confirm(
`Confirm with 'yes' if you want to start the ${process.argv[1]
.split('/')
.slice(-1)} script: `
);
// load yield table snapshot of daily values only
let data = JSON.parse(fs.readFileSync('./yield_snapshot_daily.json'));
// we filter further on tvl (10k) cause this is what we do on retrieval from db for frontend
data = data.filter(
(p) =>
p.tvlUsd >= 1e4 &&
!exclude.excludePools.includes(p.pool) &&
!exclude.excludeAdaptors.includes(p.project)
);
let 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: parseFloat(ss.median(X.map((p) => p.apy)).toFixed(5)),
uniquePools: new Set(X.map((p) => p.pool)).size,
});
}
payload = payload.sort((a, b) => b.timestamp - a.timestamp);
const response = await insertMedian(payload);
console.log(response);
process.exit(0);
})();