Skip to content

Commit

Permalink
MainnetProviderEstimatedRewards
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecot committed Jan 24, 2025
1 parent 49ce468 commit bcc6c4a
Show file tree
Hide file tree
Showing 16 changed files with 27,627 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/indexer/restrpc_agregators/AprMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as JsinfoSchema from '@jsinfo/schemas/jsinfoSchema/jsinfoSchema';
import { logger } from '@jsinfo/utils/logger';
import { RpcPeriodicEndpointCache } from '@jsinfo/restRpc/lavaRpcPeriodicEndpointCache';
import { EstimatedRewardsResponse, RpcOnDemandEndpointCache } from '@jsinfo/restRpc/lavaRpcOnDemandEndpointCache';
import { ConvertToBaseDenom, GetUSDCValue } from './CurrencyConverstionUtils';
import { ConvertToBaseDenom, GetUSDCValue } from '../../restRpc/CurrencyConverstionUtils';
import { queryJsinfo } from '@jsinfo/utils/db';
import { HashJson } from '@jsinfo/utils/fmt';
import { sql } from 'drizzle-orm';
Expand Down
2 changes: 1 addition & 1 deletion src/indexer/restrpc_agregators/DelegatorRewardsMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logger } from '@jsinfo/utils/logger';
import { RpcPeriodicEndpointCache } from '@jsinfo/restRpc/lavaRpcPeriodicEndpointCache';
import { RpcOnDemandEndpointCache } from '@jsinfo/restRpc/lavaRpcOnDemandEndpointCache';
import * as JsinfoSchema from '@jsinfo/schemas/jsinfoSchema/jsinfoSchema';
import { ConvertToBaseDenom, GetUSDCValue } from "./CurrencyConverstionUtils";
import { ConvertToBaseDenom, GetUSDCValue } from "../../restRpc/CurrencyConverstionUtils";
import { sql } from 'drizzle-orm';
import { queryJsinfo } from '@jsinfo/utils/db';
import { HashJson, JSONStringify } from '@jsinfo/utils/fmt';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { FastifyRequest, FastifyReply, RouteShorthandOptions, RouteGenericInterface } from 'fastify';
import { MainnetProviderEstimatedRewardsGetService } from '@jsinfo/redis/resources/MainnetProviderEstimatedRewards/MainnetProviderEstimatedRewardsGetResource';
import { MainnetProviderEstimatedRewardsListService } from '@jsinfo/redis/resources/MainnetProviderEstimatedRewards/MainnetProviderEstimatedRewardsListResource';
import { MainnetProviderEstimatedRewardsSpecFilterService } from '@jsinfo/redis/resources/MainnetProviderEstimatedRewards/MainnetProviderEstimatedRewardsSpecFilterResource';
import { JSONStringify } from '@jsinfo/utils/fmt';

interface QueryParams {
type?: 'list' | 'get' | 'spec';
block?: string;
spec?: string;
}

interface RouteGeneric extends RouteGenericInterface {
Querystring: QueryParams;
}

export const MainnetProviderEstimatedRewardsHandlerOpts: RouteShorthandOptions = {
schema: {
querystring: {
type: 'object',
properties: {
type: {
type: 'string',
enum: ['list', 'get', 'spec']
},
block: {
type: 'string',
pattern: '^(latest|[0-9]+)$'
},
spec: {
type: 'string'
}
}
},
response: {
200: {
type: 'string'
}
}
}
};

export async function MainnetProviderEstimatedRewardsHandler(
request: FastifyRequest<RouteGeneric>,
reply: FastifyReply
) {
try {
const { type = 'list', block = 'latest', spec } = request.query;

switch (type) {
case 'list':
const listResponse = await MainnetProviderEstimatedRewardsListService.fetch();
reply.header('Content-Type', 'application/json');
return reply.send(JSONStringify(listResponse));

case 'get':
const getResponse = await MainnetProviderEstimatedRewardsGetService.fetch({ block });
reply.header('Content-Type', 'application/json');
return reply.send(JSONStringify(getResponse));

case 'spec':
if (!spec) {
return reply.status(400).send({ error: 'Spec parameter is required for spec type' });
}
const specResponse = await MainnetProviderEstimatedRewardsSpecFilterService.fetch({ spec, block });
reply.header('Content-Type', 'application/json');
return reply.send(JSONStringify(specResponse));

default:
return reply.status(400).send({ error: 'Invalid type parameter' });
}
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
return reply.status(500).send({
error: 'Failed to fetch provider estimated rewards',
details: errorMessage
});
}
}

export default {
MainnetProviderEstimatedRewardsHandler,
MainnetProviderEstimatedRewardsHandlerOpts
};
10 changes: 10 additions & 0 deletions src/query/queryRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ import { ActiveValidatorsPaginatedHandler, ActiveValidatorsPaginatedHandlerOpts,
import { TotalLockedValueHandler, TotalLockedValueHandlerOpts } from './handlers/ajax/totalLockedValueHandler';
import { TotalLockedValuesComponentsHandler, TotalLockedValuesComponentsHandlerOpts } from './handlers/ajax/totalLockedValuesComponentsHandler';
import { AllLockedValuesHandler, AllLockedValuesHandlerOpts } from './handlers/ajax/allLockedValuesHandler';

// -- IpRpcEndpointsIndex --
import { IpRpcEndpointsIndexHandler, IpRpcEndpointsIndexHandlerOpts } from './handlers/IpRpcEndpointsIndex/IpRpcEndpointsIndexHandler';

// -- lava_mainnet_provider_estimated_rewards --
import { MainnetProviderEstimatedRewardsHandler } from './handlers/MainnetProviderEstimatedRewards/MainnetProviderEstimatedRewardsHandler';
import { MainnetProviderEstimatedRewardsHandlerOpts } from './handlers/MainnetProviderEstimatedRewards/MainnetProviderEstimatedRewardsHandler';


// -- Server status ajax --
GetServerInstance().get('/latest', LatestRawHandlerOpts, LatestRawHandler);
GetServerInstance().get('/islatest', IsLatestRawHandlerOpts, IsLatestRawHandler);
Expand Down Expand Up @@ -246,3 +253,6 @@ GetServerInstance().get("/all_locked_values", AllLockedValuesHandlerOpts, AllLoc

// lava_iprpc_endpoints
GetServerInstance().get('/lava_iprpc_endpoints', IpRpcEndpointsIndexHandlerOpts, IpRpcEndpointsIndexHandler);

// lava_mainnet_provider_estimated_rewards
GetServerInstance().get('/lava_mainnet_provider_estimated_rewards', MainnetProviderEstimatedRewardsHandlerOpts, MainnetProviderEstimatedRewardsHandler);
Loading

0 comments on commit bcc6c4a

Please sign in to comment.