Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"morgan": "~1.9.1",
"node-cache": "^5.1.2",
"node-cron": "^3.0.3",
"p-limit": "^6.2.0",
"route-cache": "^0.7.0",
"viem": "^2.8.14",
"zod": "^3.23.4",
Expand All @@ -37,8 +38,8 @@
"@types/debug": "^4.1.12",
"@types/express": "^4.17.21",
"@types/morgan": "^1.9.9",
"@types/node-cron": "^3.0.11",
"@types/node": "^20.12.2",
"@types/node-cron": "^3.0.11",
"@types/route-cache": "^0.5.5",
"prisma": "^5.11.0",
"tsx": "^4.7.1",
Expand Down
66 changes: 45 additions & 21 deletions packages/api/src/routes/avs/avsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { SortByQuerySchema } from '../../schema/zod/schemas/sortByQuery'
import { SearchByTextQuerySchema } from '../../schema/zod/schemas/searchByTextQuery'
import { WithRewardsQuerySchema } from '../../schema/zod/schemas/withRewardsQuery'
import { getOperatorSearchQuery } from '../operators/operatorController'
import { LegacyQuerySchema } from '../../schema/zod/schemas/legacyQuery'
import { EigenExplorerApiError, handleAndReturnErrorResponse } from '../../schema/errors'
import {
getStrategiesWithShareUnderlying,
Expand Down Expand Up @@ -49,6 +50,7 @@ export async function getAllAVS(req: Request, res: Response) {
.and(SortByQuerySchema)
.and(WithCuratedMetadata)
.and(SearchByTextQuerySchema)
.and(LegacyQuerySchema)
.safeParse(req.query)

if (!queryCheck.success) {
Expand All @@ -67,8 +69,10 @@ export async function getAllAVS(req: Request, res: Response) {
sortByTotalOperators,
sortByApy,
searchByText,
searchMode
searchMode,
legacy
} = queryCheck.data
const isLegacy = legacy === 'true'

// Setup sort if applicable
const sortConfig = sortByTotalStakers
Expand All @@ -87,7 +91,7 @@ export async function getAllAVS(req: Request, res: Response) {
// Fetch records and apply search/sort
const avsRecords = await prisma.avs.findMany({
where: {
...getAvsFilterQuery(true),
...getAvsFilterQuery(true, isLegacy),
...searchFilterQuery,
...(minTvl ? { tvlEth: { gte: minTvl } } : {})
},
Expand Down Expand Up @@ -117,7 +121,7 @@ export async function getAllAVS(req: Request, res: Response) {
// Fetch count
const avsCount = await prisma.avs.count({
where: {
...getAvsFilterQuery(true),
...getAvsFilterQuery(true, isLegacy),
...searchFilterQuery,
...(minTvl ? { tvlEth: { gte: minTvl } } : {})
}
Expand Down Expand Up @@ -171,7 +175,9 @@ export async function getAllAVS(req: Request, res: Response) {
*/
export async function getAllAVSAddresses(req: Request, res: Response) {
// Validate pagination query
const queryCheck = PaginationQuerySchema.and(SearchByTextQuerySchema).safeParse(req.query)
const queryCheck = PaginationQuerySchema.and(SearchByTextQuerySchema)
.and(LegacyQuerySchema)
.safeParse(req.query)
if (!queryCheck.success) {
return handleAndReturnErrorResponse(req, res, queryCheck.error)
}
Expand Down Expand Up @@ -223,7 +229,7 @@ export async function getAllAVSAddresses(req: Request, res: Response) {
// Determine count
const avsCount = await prisma.avs.count({
where: {
...getAvsFilterQuery(true),
...getAvsFilterQuery(true, isLegacy),
...searchFilterQuery
}
})
Expand Down Expand Up @@ -336,6 +342,7 @@ export async function getAVS(req: Request, res: Response) {
const queryCheck = WithTvlQuerySchema.and(WithCuratedMetadata)
.and(WithRewardsQuerySchema)
.and(WithTrailingApySchema)
.and(LegacyQuerySchema)
.safeParse(req.query)
if (!queryCheck.success) {
return handleAndReturnErrorResponse(req, res, queryCheck.error)
Expand All @@ -348,10 +355,10 @@ export async function getAVS(req: Request, res: Response) {

try {
const { address } = req.params
const { withTvl, withCuratedMetadata, withRewards, withTrailingApy } = queryCheck.data
const { withTvl, withCuratedMetadata, withRewards, withTrailingApy, legacy } = queryCheck.data

const avs = await prisma.avs.findUniqueOrThrow({
where: { address: address.toLowerCase(), ...getAvsFilterQuery() },
where: { address: address.toLowerCase(), ...getAvsFilterQuery(false, legacy === 'true') },
include: {
curatedMetadata: withCuratedMetadata,
additionalInfo: withCuratedMetadata,
Expand All @@ -369,9 +376,12 @@ export async function getAVS(req: Request, res: Response) {
}
})

const shares = withOperatorShares(avs.operators).filter((s) => true)
// TODO: Add back with operator set strategies
// (s) => avs.restakeableStrategies.indexOf(s.strategyAddress.toLowerCase()) !== -1
// TODO: Select whether to use operator set strategies or all strategies
// const shares = withOperatorShares(avs.operators).filter((s) => true)
const shares = withOperatorShares(avs.operators).filter(
(s) => avs.restakeableStrategies.indexOf(s.strategyAddress.toLowerCase()) !== -1
)

const strategiesWithSharesUnderlying = withTvl ? await getStrategiesWithShareUnderlying() : []

Expand Down Expand Up @@ -427,6 +437,7 @@ export async function getAVSStakers(req: Request, res: Response) {
// Validate query and params
const queryCheck = PaginationQuerySchema.and(WithTvlQuerySchema)
.and(UpdatedSinceQuerySchema)
.and(LegacyQuerySchema)
.safeParse(req.query)

if (!queryCheck.success) {
Expand All @@ -440,10 +451,10 @@ export async function getAVSStakers(req: Request, res: Response) {

try {
const { address } = req.params
const { skip, take, withTvl, updatedSince } = queryCheck.data
const { skip, take, withTvl, updatedSince, legacy } = queryCheck.data

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

Expand Down Expand Up @@ -525,6 +536,7 @@ export async function getAVSOperators(req: Request, res: Response) {
.and(MinTvlQuerySchema)
.and(SortByQuerySchema)
.and(SearchByTextQuerySchema)
.and(LegacyQuerySchema)
.safeParse(req.query)
if (!queryCheck.success) {
return handleAndReturnErrorResponse(req, res, queryCheck.error)
Expand All @@ -537,12 +549,12 @@ export async function getAVSOperators(req: Request, res: Response) {

try {
const { address } = req.params
const { skip, take, withTvl, minTvl, sortOperatorsByTvl, searchByText, searchMode } =
const { skip, take, withTvl, minTvl, sortOperatorsByTvl, searchByText, searchMode, legacy } =
queryCheck.data
const searchFilterQuery = getOperatorSearchQuery(searchByText, searchMode, 'partial')

const avs = await prisma.avs.findUniqueOrThrow({
where: { address: address.toLowerCase(), ...getAvsFilterQuery() },
where: { address: address.toLowerCase(), ...getAvsFilterQuery(false, legacy === 'true') },
include: {
operators: {
where: { isActive: true }
Expand Down Expand Up @@ -1304,21 +1316,33 @@ export function getAvsFilterQuery(filterName?: boolean, isLegacy = true) {
}
}

// After introduction of area-internal-dashboard, `isVisible` checks move to `AvsAdditionalInfo` with `CuratedMetadata` only as fallback
// Currently, this is only accessible by setting the flag `legacy=false` when using full text search
// After introduction of area-internal-dashboard, validity checks move to `AvsAdditionalInfo` with `CuratedMetadata` only as fallback
// Currently, this is only accessible by setting the flag `legacy=false`, on routes where `LegacyQuerySchema` enabled
return {
AND: [
queryWithName,
{
OR: [
// Check if `additionalInfo.isVisible` is true
// Check `additionalInfo.isVisible` && `additionalInfo.isVerified` is true
{
additionalInfo: {
some: {
metadataKey: 'isVisible',
metadataContent: 'true'
AND: [
{
additionalInfo: {
some: {
metadataKey: 'isVisible',
metadataContent: 'true'
}
}
},
{
additionalInfo: {
some: {
metadataKey: 'isVerified',
metadataContent: 'true'
}
}
}
}
]
},
// If `additionalInfo.isVisible` does not exist, check `curatedMetadata.isVisible` is true
{
Expand Down
Loading