Skip to content

Commit

Permalink
Merge branch 'DefiLlama:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
nova577metaverse authored Jun 14, 2024
2 parents 2e8ad99 + 5e95fa2 commit 64c899b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ functions:
- http:
path: largetransactions/{chain}
method: get
lastBlocks:
handler: src/handlers/getLastBlocks.default
timeout: 120
memorySize: 2000
events:
- http:
path: lastblocks
method: get
runAdapter:
handler: src/handlers/runAdapter.default
timeout: 900
Expand Down
32 changes: 32 additions & 0 deletions src/handlers/getLastBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import wrap, { wrapScheduledLambda } from "../utils/wrap";
import bridgeNetworks from "../data/bridgeNetworkData";
import { runAdapterToCurrentBlock } from "../utils/adapter";
import { sql } from "../utils/db";
import { successResponse } from "../utils/lambda-response";

const handler = async () => {
const lastRecordedBlocks = (
await sql`SELECT jsonb_object_agg(bridge_id::text, subresult) as result
FROM (
SELECT bridge_id, jsonb_build_object('startBlock', MIN(tx_block), 'endBlock', MAX(tx_block)) as subresult
FROM bridges.transactions
GROUP BY bridge_id
) subquery;
`
)[0].result;

const bridgeConfig = await sql`SELECT * FROM bridges.config`;

const bridgeConfigById = bridgeConfig.reduce((acc: any, config: any) => {
acc[config.id] = config;
return acc;
}, {});

const lastBlocksByName = Object.keys(lastRecordedBlocks).reduce((acc: any, bridgeId: any) => {
acc[`${bridgeConfigById[bridgeId].bridge_name}-${bridgeConfigById[bridgeId].chain}`] = lastRecordedBlocks[bridgeId];
return acc;
}, {});
return successResponse(lastBlocksByName);
};

export default wrap(handler);

0 comments on commit 64c899b

Please sign in to comment.