forked from DefiLlama/yield-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6eef61d
commit b8342f3
Showing
56 changed files
with
28,977 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
node_modules | ||
ccImages | ||
*.env | ||
.vscode/ | ||
.serverless | ||
.webpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
# yield-server | ||
# defillama-apy server | ||
|
||
### set api keys in config.env | ||
|
||
``` | ||
ETHERSCAN= | ||
FANTOMSCAN= | ||
POLYGONSCAN= | ||
SNOWTRACE= | ||
ARBISCAN= | ||
OPTIMISM= | ||
INFURA_CONNECTION= | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const path = require('path'); | ||
const dotenv = require('dotenv'); | ||
|
||
const superagent = require('superagent'); | ||
const AWS = require('aws-sdk'); | ||
const credentials = new AWS.SharedIniFileCredentials({ profile: 'defillama' }); | ||
AWS.config.credentials = credentials; | ||
|
||
dotenv.config({ path: './config.env' }); | ||
|
||
if (process.argv.length < 3) { | ||
console.error(`Missing argument, you need to provide the adaptor name a, | ||
unix timestamp in seconds and optionally the number of days you want to backfill the data | ||
Eg: node scripts/fillOld.js pangolin 1648098107 10`); | ||
process.exit(1); | ||
} | ||
|
||
const project = process.argv[2]; | ||
let timestamp = process.argv[3]; | ||
const maxDays = process.argv[4] === undefined ? 1 : process.argv[4]; | ||
// round timestamp to midnight | ||
// eg 2022-04-06T00:00:00.000Z | ||
timestamp = Math.floor(timestamp / 60 / 60 / 24) * 24 * 60 * 60; | ||
const offset = 86400; | ||
const passedFile = path.resolve( | ||
process.cwd(), | ||
`src/adaptors/${project}/index.js` | ||
); | ||
|
||
(async () => { | ||
// 1. load module | ||
const module = require(passedFile); | ||
if (!module.timetravel) | ||
return console.log(`${project} can't timetravel, exiting!`); | ||
|
||
// get bearer token for post request to db | ||
const ssm = new AWS.SSM({ region: 'eu-central-1' }); | ||
const options = { | ||
Name: '/llama-apy/serverless/sls-authenticate/bearertoken', | ||
WithDecryption: true, | ||
}; | ||
const token = await ssm.getParameter(options).promise(); | ||
|
||
// 2. run adaptor | ||
console.log(`Starting timetravel for ${project}...\n`); | ||
for (let i = 0; i < maxDays; i++) { | ||
console.log( | ||
`Unix: ${timestamp}, ISO: ${new Date( | ||
timestamp * 1000 | ||
).toISOString()}, Nb: ${i + 1}` | ||
); | ||
|
||
console.log('\trunning adaptor'); | ||
const data = await module.apy(timestamp); | ||
|
||
// filter to $1k usd tvl | ||
const tvlMinThr = 1e3; | ||
const dataDB = data.filter((el) => el.tvlUsd >= tvlMinThr); | ||
|
||
// add timestamp | ||
for (const d of dataDB) { | ||
d['timestamp'] = new Date(timestamp * 1000); | ||
} | ||
|
||
// DB update | ||
// step1: we delete all hourly samples on that particular day for that project | ||
// step2: we insert the new ones | ||
// reason instead of updateMany: if we'd just use an update operation without deleting anything, | ||
// we'd have only outdated objects for that day with the exception of the updated one. | ||
// -> confusing when looking at the historcal data and especially bad when we want to use the old data | ||
// for some analysis work as nothing would make sense | ||
const urlBase = | ||
'https://1rwmj4tky9.execute-api.eu-central-1.amazonaws.com/pools'; | ||
|
||
try { | ||
// delete | ||
const responseDelete = await superagent | ||
.delete(`${urlBase}/${project}/${timestamp}`) | ||
.set({ Authorization: `Bearer ${token.Parameter.Value}` }); | ||
console.log(`\tDeleted ${responseDelete.body.response.n} samples`); | ||
|
||
// insert | ||
const responseInsert = await superagent | ||
.post(urlBase) | ||
.send(dataDB) | ||
.set({ Authorization: `Bearer ${token.Parameter.Value}` }); | ||
console.log(`\t${responseInsert.body.response} samples\n`); | ||
} catch (err) { | ||
throw new Error(err); | ||
} | ||
// update timestamp | ||
timestamp -= offset; | ||
} | ||
console.log(`\njob finished, backfilled ${maxDays} day(s)`); | ||
|
||
process.exit(0); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
try { | ||
require('dotenv').config({ path: './config.env' }); | ||
} catch (e) {} | ||
|
||
const fs = require('fs'); | ||
module.exports = { | ||
// API keys | ||
ETHERSCAN: process.env.ETHERSCAN, | ||
FANTOMSCAN: process.env.FANTOMSCAN, | ||
POLYGONSCAN: process.env.POLYGONSCAN, | ||
SNOWTRACE: process.env.SNOWTRACE, | ||
ARBISCAN: process.env.ARBISCAN, | ||
OPTIMISM: process.env.OPTIMISM, | ||
INFURA_CONNECTION: process.env.INFURA_CONNECTION, | ||
// ADAPTOR LIST | ||
ADAPTORS: JSON.stringify( | ||
fs.readdirSync('./src/adaptors').filter((el) => !el.includes('js')) | ||
), | ||
}; |
Oops, something went wrong.