Skip to content

Commit

Permalink
Merge pull request #62 from EigenExplorer/57-add-error-handling-for-m…
Browse files Browse the repository at this point in the history
…etricstvlrestakingstrategy

57 add error handling for metricstvlrestakingstrategy
  • Loading branch information
uditdc authored May 16, 2024
2 parents 77c991b + bc22dcf commit ee81102
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
6 changes: 3 additions & 3 deletions packages/api/src/routes/avs/avsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export async function getAVS(req: Request, res: Response) {
const { withTvl } = req.query

const avs = await prisma.avs.findUniqueOrThrow({
where: { address, ...getAvsFilterQuery() },
where: { address: address.toLowerCase(), ...getAvsFilterQuery() },
include: {
curatedMetadata: true,
operators: {
Expand Down Expand Up @@ -241,7 +241,7 @@ export async function getAVSStakers(req: Request, res: Response) {
const { skip, take } = queryCheck.data

const avs = await prisma.avs.findUniqueOrThrow({
where: { address, ...getAvsFilterQuery() },
where: { address: address.toLowerCase(), ...getAvsFilterQuery() },
include: { operators: true }
})

Expand Down Expand Up @@ -314,7 +314,7 @@ export async function getAVSOperators(req: Request, res: Response) {
const { skip, take, withTvl } = queryCheck.data

const avs = await prisma.avs.findUniqueOrThrow({
where: { address, ...getAvsFilterQuery() },
where: { address: address.toLowerCase(), ...getAvsFilterQuery() },
include: {
operators: {
where: { isActive: true }
Expand Down
24 changes: 16 additions & 8 deletions packages/api/src/routes/metrics/metricController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,25 @@ export async function getTvlRestaking(req: Request, res: Response) {
export async function getTvlRestakingByStrategy(req: Request, res: Response) {
try {
const { strategy } = req.params
const strategies = Object.keys(getEigenContracts().Strategies)

if (strategy && strategies.indexOf(strategy) !== -1) {
const tvl = await doGetTvlStrategy(
getEigenContracts().Strategies[strategy].strategyContract
)
if (!strategy) {
throw new Error('Invalid strategy name.')
}

const strategies = Object.keys(getEigenContracts().Strategies)
const foundStrategy = strategies.find(s => s.toLowerCase() === strategy.toLowerCase())

res.send({
tvl
})
if (!foundStrategy) {
throw new Error('Invalid strategy.')
}

const tvl = await doGetTvlStrategy(
getEigenContracts().Strategies[foundStrategy].strategyContract
)

res.send({
tvl
})
} catch (error) {
handleAndReturnErrorResponse(req, res, error)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/routes/operators/operatorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ export async function getOperator(req: Request, res: Response) {
const { withTvl } = result.data

try {
const { id } = req.params
const { address } = req.params

const operator = await prisma.operator.findUniqueOrThrow({
where: { address: id },
where: { address: address.toLowerCase() },
include: {
shares: {
select: { strategyAddress: true, shares: true }
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/operators/operatorRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ router.get('/', routeCache.cacheSeconds(120), getAllOperators)
* type: string
* example: 'Operator not found.'
*/
router.get('/:id', routeCache.cacheSeconds(120), getOperator)
router.get('/:address', routeCache.cacheSeconds(120), getOperator)

export default router
4 changes: 2 additions & 2 deletions packages/api/src/routes/stakers/stakerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export async function getAllStakers(req: Request, res: Response) {
*/
export async function getStaker(req: Request, res: Response) {
try {
const { id } = req.params
const { address } = req.params

const staker = await prisma.staker.findUniqueOrThrow({
where: { address: id },
where: { address: address.toLowerCase() },
include: { shares: true }
})

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/stakers/stakerRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ const router = express.Router()

router.get('/', getAllStakers)

router.get('/:id', getStaker)
router.get('/:address', getStaker)

export default router

0 comments on commit ee81102

Please sign in to comment.