mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-16 16:21:32 +03:00
add more methods to integrator
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.19.89-rc8",
|
||||
"version": "0.19.89-rc9",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.19.89-rc8",
|
||||
"version": "0.19.89-rc9",
|
||||
"hasInstallScript": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.19.89-rc8",
|
||||
"version": "0.19.89-rc9",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./lib/index.js",
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import {
|
||||
environmentResponseSchema,
|
||||
getPoolResponseSchema,
|
||||
listAmountResponseSchema,
|
||||
listNFTOrderResponseSchema,
|
||||
listPoolResponseSchema,
|
||||
veORNInfoSchema,
|
||||
veORNInfoResponseSchema,
|
||||
votingInfoResponseSchema
|
||||
} from './schemas/index.js';
|
||||
import { fetchWithValidation } from 'simple-typed-fetch';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
|
||||
type BasePayload = {
|
||||
chainId: number
|
||||
@@ -42,12 +45,29 @@ type VeORNInfoPayload = BasePayload & {
|
||||
params: [string]
|
||||
}
|
||||
|
||||
type ListAmountPayload = BasePayload & {
|
||||
model: string
|
||||
method: 'listAmount'
|
||||
params: []
|
||||
}
|
||||
|
||||
type GetAmountByORNPayload = BasePayload & {
|
||||
amountToken: number
|
||||
timeLock: number
|
||||
}
|
||||
|
||||
type Payload =
|
||||
| GetEnvironmentPayload
|
||||
| ListNFTOrderPayload
|
||||
| GetPoolInfoPayload
|
||||
| ListPoolPayload
|
||||
| VeORNInfoPayload;
|
||||
| VeORNInfoPayload
|
||||
| ListAmountPayload
|
||||
| GetAmountByORNPayload;
|
||||
|
||||
const START_TIME = 1690848000;// Aug 01 2023 00:00:00 UTC
|
||||
const DAY = 86400
|
||||
const YEAR = 365 * DAY
|
||||
|
||||
class IntegratorService {
|
||||
private readonly apiUrl: string;
|
||||
@@ -67,6 +87,10 @@ class IntegratorService {
|
||||
this.getPoolInfo = this.getPoolInfo.bind(this);
|
||||
this.listPool = this.listPool.bind(this);
|
||||
this.veORNInfo = this.veORNInfo.bind(this);
|
||||
this.listAmount = this.listAmount.bind(this);
|
||||
this.getAmountByORN = this.getAmountByORN.bind(this);
|
||||
this.getAmountAtCurrent = this.getAmountAtCurrent.bind(this);
|
||||
this.getVotingInfo = this.getVotingInfo.bind(this);
|
||||
}
|
||||
|
||||
makeRPCPayload = (payload: Omit<Payload, 'chainId' | 'jsonrpc'>) => {
|
||||
@@ -78,7 +102,7 @@ class IntegratorService {
|
||||
};
|
||||
|
||||
veORNInfo = (address: string) => {
|
||||
return fetchWithValidation(this.apiUrl, veORNInfoSchema, {
|
||||
return fetchWithValidation(this.apiUrl, veORNInfoResponseSchema, {
|
||||
method: 'POST',
|
||||
body: this.makeRPCPayload({
|
||||
model: 'veORN',
|
||||
@@ -88,6 +112,13 @@ class IntegratorService {
|
||||
})
|
||||
}
|
||||
|
||||
getAmountAtCurrent = (amount: number) => {
|
||||
const timestamp = Date.now() / 1000;
|
||||
|
||||
// sqrt
|
||||
return BigNumber(amount).dividedBy(this.getK(timestamp));
|
||||
}
|
||||
|
||||
private readonly getEnvironment = () => {
|
||||
return fetchWithValidation(this.apiUrl, environmentResponseSchema, {
|
||||
method: 'POST',
|
||||
@@ -135,6 +166,47 @@ class IntegratorService {
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
private readonly listAmount = (poolKey: string) => {
|
||||
return fetchWithValidation(this.apiUrl, listAmountResponseSchema, {
|
||||
method: 'POST',
|
||||
body: this.makeRPCPayload({
|
||||
model: poolKey,
|
||||
method: 'listAmount',
|
||||
params: [],
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
private readonly getK = (time: number) => {
|
||||
const currentTime = time < START_TIME ? START_TIME : time;
|
||||
|
||||
const deltaYears = BigNumber(currentTime).minus(START_TIME).dividedBy(YEAR);
|
||||
return BigNumber(2).pow(BigNumber(deltaYears).pow(2));
|
||||
}
|
||||
|
||||
private readonly getAmountByORN = (amountToken: number, timeLock: number) => {
|
||||
const timestamp = Date.now() / 1000;
|
||||
|
||||
const deltaDays = BigNumber(timeLock).minus(timestamp).dividedBy(DAY);
|
||||
if (deltaDays.lt(0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// sqrt
|
||||
return BigNumber(amountToken).multipliedBy(BigNumber(deltaDays).sqrt()).dividedBy(5);
|
||||
}
|
||||
|
||||
private readonly getVotingInfo = (userAddress: number) => {
|
||||
return fetchWithValidation(this.apiUrl, votingInfoResponseSchema, {
|
||||
method: 'POST',
|
||||
body: this.makeRPCPayload({
|
||||
model: 'OrionVoting',
|
||||
method: 'info',
|
||||
params: [userAddress],
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export * as schemas from './schemas/index.js';
|
||||
|
||||
@@ -2,4 +2,6 @@ export { default as environmentResponseSchema } from './environment-response-sch
|
||||
export { default as listNFTOrderResponseSchema } from './list-nft-order-response-schema.js';
|
||||
export { default as getPoolResponseSchema } from './get-pool-response-schema.js';
|
||||
export { default as listPoolResponseSchema } from './list-pool-response-schema.js';
|
||||
export { default as veORNInfoSchema } from './veORN-info-schema.js';
|
||||
export { default as veORNInfoResponseSchema } from './veORN-info-schema.js';
|
||||
export { default as listAmountResponseSchema } from './list-amount-schema.js';
|
||||
export { default as votingInfoResponseSchema } from './voting-info-schema.js';
|
||||
|
||||
5
src/services/Integrator/schemas/list-amount-schema.ts
Normal file
5
src/services/Integrator/schemas/list-amount-schema.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const listAmountSchema = z.record(z.number(), z.number())
|
||||
|
||||
export default listAmountSchema;
|
||||
21
src/services/Integrator/schemas/voting-info-schema.ts
Normal file
21
src/services/Integrator/schemas/voting-info-schema.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const poolSchema = z.object({
|
||||
allVote: z.number(),
|
||||
name: z.string(),
|
||||
poolAddress: z.string(),
|
||||
type: z.string(),
|
||||
userVote: z.number()
|
||||
})
|
||||
|
||||
const votingInfoSchema = z.object({
|
||||
absoluteVeTokenInVoting: z.number(),
|
||||
pools: z.array(poolSchema),
|
||||
userVeTokenBalance: z.number(),
|
||||
userVeTokenInVoting: z.number(),
|
||||
veTokenAddress: z.string(),
|
||||
votingAddress: z.string(),
|
||||
weeklyReward: z.number()
|
||||
})
|
||||
|
||||
export default votingInfoSchema;
|
||||
Reference in New Issue
Block a user