Skip to content

Commit

Permalink
Merge branch 'dev' into 235-feat-operator-event-history
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhit14 authored Oct 18, 2024
2 parents 2d7eefb + 864ac7c commit 758a85e
Show file tree
Hide file tree
Showing 27 changed files with 1,002 additions and 1,260 deletions.
50 changes: 22 additions & 28 deletions packages/api/src/routes/auxiliary/auxiliaryController.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Request, Response } from 'express'
import { cacheStore } from 'route-cache'
import { eigenContracts } from '../../data/address/eigenMainnetContracts'
import { handleAndReturnErrorResponse } from '../../schema/errors'
import { fetchStrategyTokenPrices } from '../../utils/tokenPrices'
import { fetchTokenPrices } from '../../utils/tokenPrices'
import { getPrismaClient } from '../../utils/prismaClient'

/**
Expand All @@ -13,32 +11,9 @@ import { getPrismaClient } from '../../utils/prismaClient'
*/
export async function getCachedPrices(req: Request, res: Response) {
try {
const CMC_TOKEN_IDS = [
8100, 21535, 27566, 23782, 29035, 24277, 28476, 15060, 23177, 8085, 25147, 24760, 2396
]
const keysStr = CMC_TOKEN_IDS.join(',')
let cachedPrices = await cacheStore.get(`price_${keysStr}`)
const tokenPrices = await fetchTokenPrices()

if (!cachedPrices) {
cachedPrices = await fetchStrategyTokenPrices()
}

const priceData = Object.values(cachedPrices).map(
(cachedPrice: {
symbol: string
strategyAddress: string
eth: number
tokenAddress?: string
}) => {
const strategy = eigenContracts.Strategies[cachedPrice.symbol]
return {
...cachedPrice,
tokenAddress: strategy?.tokenContract || null
}
}
)

res.status(200).send(priceData)
res.status(200).send(tokenPrices)
} catch (error) {
handleAndReturnErrorResponse(req, res, error)
}
Expand All @@ -65,3 +40,22 @@ export async function getLastSyncBlocks(req: Request, res: Response) {
handleAndReturnErrorResponse(req, res, error)
}
}

/**
* Route to fetch and display all strategies and tokens
*
* @param req
* @param res
*/
export async function getStrategies(req: Request, res: Response) {
try {
const prismaClient = getPrismaClient()

const strategies = await prismaClient.strategies.findMany()
const tokens = await prismaClient.tokens.findMany()

res.status(200).send({ strategies, tokens })
} catch (error) {
handleAndReturnErrorResponse(req, res, error)
}
}
3 changes: 2 additions & 1 deletion packages/api/src/routes/auxiliary/auxiliaryRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import express from 'express'
import { getCachedPrices, getLastSyncBlocks } from './auxiliaryController'
import { getCachedPrices, getLastSyncBlocks, getStrategies } from './auxiliaryController'

const router = express.Router()

router.get('/prices', getCachedPrices)
router.get('/sync-status', getLastSyncBlocks)
router.get('/strategies', getStrategies)

export default router
Loading

0 comments on commit 758a85e

Please sign in to comment.