forked from sturdyfi/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.
add new endpoint for pools old (DefiLlama#313)
- Loading branch information
1 parent
ddf31e2
commit 6276704
Showing
3 changed files
with
91 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
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
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,78 @@ | ||
const S3 = require('aws-sdk/clients/s3'); | ||
|
||
const AppError = require('../utils/appError'); | ||
const { lambdaResponse } = require('../utils/lambda'); | ||
const { getDataUsingS3Select } = require('./getPoolsEnriched'); | ||
|
||
// returns enriched pool data | ||
module.exports.handler = async (event) => { | ||
const response = await buildPoolsEnrichedOld(event.queryStringParameters); | ||
|
||
if (!response) { | ||
return new AppError("Couldn't retrieve data", 404); | ||
} | ||
|
||
return lambdaResponse({ | ||
status: 'success', | ||
data: response, | ||
}); | ||
}; | ||
|
||
const buildPoolsEnrichedOld = async (queryString) => { | ||
const columns = [ | ||
'chain', | ||
'project', | ||
'symbol', | ||
'tvlUsd', | ||
'apyBase', | ||
'apyReward', | ||
'apy', | ||
'rewardTokens', | ||
'pool', | ||
'pool_old', // old pool field | ||
'apyPct1D', | ||
'apyPct7D', | ||
'apyPct30D', | ||
'stablecoin', | ||
'ilRisk', | ||
'exposure', | ||
'predictions', | ||
'poolMeta', | ||
'mu', | ||
'sigma', | ||
'count', | ||
'outlier', | ||
'underlyingTokens', | ||
] | ||
.map((el) => `t."${el}"`) | ||
.join(', '); | ||
|
||
let query = `SELECT ${columns} FROM s3object[*][*] t`; | ||
|
||
if (queryString !== undefined) { | ||
query = `${query} where t.${Object.keys(queryString)[0]}='${ | ||
Object.values(queryString)[0] | ||
}'`; | ||
} | ||
|
||
const params = { | ||
Bucket: 'llama-apy-prod-data', | ||
Key: 'enriched/dataEnriched.json', | ||
ExpressionType: 'SQL', | ||
Expression: query, | ||
InputSerialization: { | ||
JSON: { | ||
Type: 'DOCUMENT', | ||
}, | ||
}, | ||
OutputSerialization: { | ||
JSON: { | ||
RecordDelimiter: ',', | ||
}, | ||
}, | ||
}; | ||
|
||
const data = await getDataUsingS3Select(params); | ||
|
||
return data; | ||
}; |