Skip to content

Commit

Permalink
add new endpoint for pools old (DefiLlama#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
slasher125 authored Sep 8, 2022
1 parent ddf31e2 commit 6276704
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
10 changes: 10 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ functions:
method: get
path: /pools

# includes old pool values
getPoolsEnrichedOld:
handler: src/handlers/getPoolsEnrichedOld.handler
description: Lambda for retrieving the latest enriched data for each unique pool (includes old pool values)
timeout: 20
events:
- httpApi:
method: get
path: /poolsOld

getChart:
handler: src/handlers/getChart.handler
description: Lambda for retrieving chart data for a particular pool
Expand Down
4 changes: 3 additions & 1 deletion src/handlers/getPoolsEnriched.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const buildPoolsEnriched = async (queryString) => {

return data;
};
module.exports.buildPoolsEnriched = buildPoolsEnriched;

const getDataUsingS3Select = async (params) => {
const s3 = new S3();
Expand Down Expand Up @@ -130,3 +129,6 @@ const getDataUsingS3Select = async (params) => {
});
});
};

module.exports.buildPoolsEnriched = buildPoolsEnriched;
module.exports.getDataUsingS3Select = getDataUsingS3Select;
78 changes: 78 additions & 0 deletions src/handlers/getPoolsEnrichedOld.js
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;
};

0 comments on commit 6276704

Please sign in to comment.