-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
55 lines (47 loc) · 1.83 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb";
// import PagerDuty from 'pagerduty';
const TABLE_NAME = "RewardMonitorTable";
export async function handler(event) {
// Create client objects
const ddbClient = new DynamoDBClient();
const ddbDocClient = DynamoDBDocumentClient.from(ddbClient);
// const pd = new PagerDuty({
// serviceKey: process.env.PAGERDUTY_SERVICE_KEY
// });
// Determine the timestamp at the time of the run
// Used as PK in DynamoDB
const timestamp = new Date().getTime();
// Build the params object for the DynamoDB PutItem command
const exampleParams = buildPutItemParams(
timestamp, 1, "0x1234567890", "Example Contract", "EXAMPLE", "0x1234567890", 1, 100, 100, 0
);
const response = {
statusCode: 200,
body: JSON.stringify(exampleParams),
}
// Save the data to DynamoDB
await ddbDocClient.send(new PutCommand(exampleParams)).catch((err) => {
response.statusCode = 500;
response.body = `Failed to save data to DynamoDB. Error: ${err}`
});
// Return response
return response
}
function buildPutItemParams(timestamp, chainId, contractAddress, contractName, tokenTicker, tokenAddress, ratePerSecond, currentBalance, runwayInSeconds, rewardDebt) {
return {
TableName: TABLE_NAME,
Item: {
Timestamp: timestamp,
ChainId: chainId,
ContractAddress: contractAddress,
ContractName: contractName,
RewardTokenTicker: tokenTicker,
RewardTokenAddress: tokenAddress,
RatePerSecond: ratePerSecond,
CurrentBalance: currentBalance,
RunwayInSeconds: runwayInSeconds,
RewardDebt: rewardDebt
},
};
}