Skip to content

Commit

Permalink
Merge branch 'testnet' into mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecot committed Jan 24, 2025
2 parents 6649123 + 8b5b743 commit aeead0b
Show file tree
Hide file tree
Showing 18 changed files with 27,643 additions and 56 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
macos_query_port_pid \
query_endpoints_full_tests_all

bun_create_migrations:
create_migrations:
bun run generate

bun_build:
build:
bun run build --verbose

bun_clean_cache:
clean_cache:
bun pm cache rm

docker_build:
Expand Down Expand Up @@ -82,6 +82,9 @@ indexer_with_migrations:
indexer_with_debugger:
NODE_TLS_REJECT_UNAUTHORIZED=0 bun --inspect-brk run src/indexer.ts

run:
make query

query:
npx --yes nodemon --watch src --ext ts --exec "JSINFO_QUERY_IS_DEBUG_MODE=true bun run src/query.ts"

Expand Down
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);
11 changes: 10 additions & 1 deletion src/redis/classes/IndexerRedisResourceCaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { AllProviderAPRResource } from '../resources/ajax/AllProviderAprResource
import { LockedTokenValuesResource } from '../resources/ajax/LockedTokenValuesResource';
import { LockedVestingTokensService } from '../resources/global/LockedVestingTokensResource';
import { IpRpcEndpointsIndexService } from '../resources/IpRpcEndpointsIndex/IpRpcEndpointsResource';
import { MainnetProviderEstimatedRewardsListService } from '../resources/MainnetProviderEstimatedRewards/MainnetProviderEstimatedRewardsListResource';

export class IndexerRedisResourceCaller {
private static readonly REFRESH_INTERVAL = 60 * 1000; // 1 minute
Expand Down Expand Up @@ -99,7 +100,8 @@ export class IndexerRedisResourceCaller {
this.refreshAjaxResources(),
this.refreshIndexResources(),
this.refreshGlobalResources(),
this.refreshIpRpcEndpoints()
this.refreshIpRpcEndpoints(),
this.refreshMainnetProviderEstimatedRewards()
]);

const duration = Date.now() - startTime;
Expand Down Expand Up @@ -266,5 +268,12 @@ export class IndexerRedisResourceCaller {
this.currentFetches
).catch(e => logger.error('Failed to refresh ip rpc endpoints:', e));
}

private static async refreshMainnetProviderEstimatedRewards(): Promise<void> {
await this.safeFetch('MainnetProviderEstimatedRewards',
() => MainnetProviderEstimatedRewardsListService.fetch(),
this.currentFetches
).catch(e => logger.error('Failed to refresh mainnet provider estimated rewards:', e));
}
}

Loading

0 comments on commit aeead0b

Please sign in to comment.