-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'DefiLlama:master' into master
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
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
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); |