Skip to content

Commit

Permalink
add borrow history controller
Browse files Browse the repository at this point in the history
  • Loading branch information
slasher125 committed Oct 3, 2022
1 parent 2ce68b2 commit 308c049
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
9 changes: 9 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ functions:
method: get
path: /lendBorrow

getHistoryLendBorrow:
handler: src/handlers/getHistoryLendBorrow.handler
description: Lambda for retrieving chart data for a particular pool
timeout: 20
events:
- httpApi:
method: get
path: /chartLendBorrow/{configID}

resources:
Resources:
# QUEUES
Expand Down
50 changes: 50 additions & 0 deletions src/controllers/yieldController.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,55 @@ const getYieldLendBorrow = async () => {
return response;
};

// get full history of given configID
const getYieldLendBorrowHistory = async (configID) => {
const conn = await connect();

const query = minify(
`
SELECT
timestamp,
"totalSupplyUsd",
"totalBorrowUsd",
"apyBase",
"apyReward",
"apyBaseBorrow",
"apyRewardBorrow"
FROM
$<table:name>
WHERE
timestamp IN (
SELECT
max(timestamp)
FROM
$<table:name>
WHERE
"configID" = $<configIDValue>
GROUP BY
(timestamp :: date)
)
AND "configID" = $<configIDValue>
ORDER BY
timestamp ASC
`,
{ compress: true }
);

const response = await conn.query(query, {
configIDValue: configID,
table: tableName,
});

if (!response) {
return new AppError(`Couldn't get ${tableName} history data`, 404);
}

return lambdaResponse({
status: 'success',
data: response,
});
};

// multi row insert query generator
const buildInsertYieldQuery = (payload) => {
// note: even though apyBase and apyReward are optional fields
Expand Down Expand Up @@ -313,5 +362,6 @@ module.exports = {
getYieldOffset,
getYieldProject,
getYieldLendBorrow,
getYieldLendBorrowHistory,
buildInsertYieldQuery,
};
6 changes: 6 additions & 0 deletions src/handlers/getHistoryLendBorrow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { getYieldLendBorrowHistory } = require('../controllers/yieldController');

module.exports.handler = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
return await getYieldLendBorrowHistory(event.pathParameters.configID);
};

0 comments on commit 308c049

Please sign in to comment.