indexer update

This commit is contained in:
Kirill Litvinov
2024-06-19 10:33:19 +03:00
parent 0cc989b413
commit b5d0e3f6c6
5 changed files with 85 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.22.9",
"version": "0.22.10-rc1",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -1,5 +1,7 @@
import {
environmentResponseSchema,
getPointsAtResponseSchema,
getPointsInfoResponseSchema,
getPoolResponseSchema,
listAmountResponseSchema,
listNFTOrderResponseSchema,
@@ -51,6 +53,18 @@ type VeORNInfoPayload = BasePayload & {
params: [string]
};
type GetPointsInfoPayload = BasePayload & {
model: 'veORN'
method: 'pointsInfo'
params: [string]
};
type GetPointsAtPayload = BasePayload & {
model: 'veORN'
method: 'pointsInfo'
params: [number, number, number]
};
type ListAmountPayload = BasePayload & {
model: string
method: 'listAmount'
@@ -68,6 +82,8 @@ type Payload =
| GetPoolInfoPayload
| ListPoolPayload
| VeORNInfoPayload
| GetPointsInfoPayload
| GetPointsAtPayload
| ListAmountPayload
| GetAmountByORNPayload;
@@ -92,6 +108,8 @@ class IndexerService {
this.poolV2Info = this.poolV2Info.bind(this);
this.listPoolV3 = this.listPoolV3.bind(this);
this.veORNInfo = this.veORNInfo.bind(this);
this.getPointsInfo = this.getPointsInfo.bind(this);
this.getPointsAt = this.getPointsAt.bind(this);
this.listAmount = this.listAmount.bind(this);
this.getAmountByORN = this.getAmountByORN.bind(this);
this.getAmountAt = this.getAmountAt.bind(this);
@@ -118,6 +136,28 @@ class IndexerService {
});
};
readonly getPointsInfo = (address: string) => {
return fetchWithValidation(this.apiUrl, getPointsInfoResponseSchema, {
method: 'POST',
body: this.makeRPCPayload({
model: 'veORN',
method: 'pointsInfo',
params: [address],
}),
});
};
readonly getPointsAt = (timestamp = Date.now(), page?: number, pageSize?: number) => {
return fetchWithValidation(this.apiUrl, getPointsAtResponseSchema, {
method: 'POST',
body: this.makeRPCPayload({
model: 'veORN',
method: 'pointsAt',
params: [timestamp, page, pageSize],
}),
});
};
/**
* @param {number} amount - amount
* @param {number} [timestamp = Date.now()] - timestamp, defaults to current time

View File

@@ -0,0 +1,15 @@
import { z } from 'zod';
import infoSchema from './info-schema.js';
const getPointsAtResultSchema = z.object({
points: z.record(z.string(), z.number()),
pageSize: z.number(),
totalElements: z.number(),
});
const getPointsAtSchema = z.object({
result: getPointsAtResultSchema,
info: infoSchema,
}).nullable();
export default getPointsAtSchema;

View File

@@ -0,0 +1,27 @@
import { z } from 'zod';
import { evmAddressSchema } from './util-schemas.js';
import infoSchema from './info-schema.js';
const getPointsResultSchema = z.object({
avgAPR: z.number(),
minAPR: z.number(),
maxAPR: z.number(),
veTokenAddress: evmAddressSchema,
totalPointsLocked: z.number(),
totalPoints: z.number(),
weeklyReward: z.number(),
userAPR: z.number(),
userPoints: z.number(),
userPointsLocked: z.number(),
userLockEndDate: z.number(),
userReward: z.number(),
userWeeklyReward: z.number(),
userMinLockPeriod: z.number(),
});
const getPointsInfoSchema = z.object({
result: getPointsResultSchema,
info: infoSchema,
}).nullable();
export default getPointsInfoSchema;

View File

@@ -9,3 +9,5 @@ export { default as veORNInfoResponseSchema } from './veORN-info-schema';
export { default as listAmountResponseSchema } from './list-amount-schema';
export { default as votingInfoResponseSchema } from './voting-info-schema';
export { default as testIncrementorSchema } from './test-incrementor-schema';
export { default as getPointsInfoResponseSchema } from './get-points-info-schema';
export { default as getPointsAtResponseSchema } from './get-points-at-schema';