mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
OP-4504 Fix Governance and Pools (#197)
This commit is contained in:
committed by
GitHub
parent
8fe0c4314c
commit
b5d6dd937b
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.20.16",
|
||||
"version": "0.20.10-rc31",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.20.16",
|
||||
"version": "0.20.10-rc31",
|
||||
"hasInstallScript": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.20.18",
|
||||
"version": "0.20.10-rc31",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./lib/index.js",
|
||||
|
||||
@@ -4,13 +4,16 @@ import {
|
||||
listAmountResponseSchema,
|
||||
listNFTOrderResponseSchema,
|
||||
listPoolResponseSchema,
|
||||
listPoolV2ResponseSchema,
|
||||
listPoolV3ResponseSchema,
|
||||
PoolV2InfoResponseSchema,
|
||||
testIncrementorSchema,
|
||||
veORNInfoResponseSchema,
|
||||
votingInfoResponseSchema
|
||||
} from './schemas';
|
||||
import { fetchWithValidation } from 'simple-typed-fetch';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import { DAY, WEEK_DAYS, YEAR } from '../../constants';
|
||||
import { WEEK_DAYS, YEAR } from '../../constants';
|
||||
import { LOCK_START_TIME } from './constants';
|
||||
|
||||
type BasePayload = {
|
||||
@@ -31,7 +34,7 @@ type ListNFTOrderPayload = BasePayload & {
|
||||
};
|
||||
|
||||
type GetPoolInfoPayload = BasePayload & {
|
||||
model: 'OrionV3Factory'
|
||||
model: 'OrionV3Factory' | 'OrionV2Factory'
|
||||
method: 'getPoolInfo'
|
||||
params: [string, string, string]
|
||||
};
|
||||
@@ -84,7 +87,10 @@ class IndexerService {
|
||||
this.getEnvironment = this.getEnvironment.bind(this);
|
||||
this.listNFTOrder = this.listNFTOrder.bind(this);
|
||||
this.getPoolInfo = this.getPoolInfo.bind(this);
|
||||
this.listPool = this.listPool.bind(this);
|
||||
this.getListPool = this.getListPool.bind(this);
|
||||
this.listPoolV2 = this.listPoolV2.bind(this);
|
||||
this.poolV2Info = this.poolV2Info.bind(this);
|
||||
this.listPoolV3 = this.listPoolV3.bind(this);
|
||||
this.veORNInfo = this.veORNInfo.bind(this);
|
||||
this.listAmount = this.listAmount.bind(this);
|
||||
this.getAmountByORN = this.getAmountByORN.bind(this);
|
||||
@@ -118,16 +124,18 @@ class IndexerService {
|
||||
return BigNumber(amount).dividedBy(this.getK(timestamp));
|
||||
};
|
||||
|
||||
readonly getAmountByORN = (amountToken: number, timeLock: number) => {
|
||||
const timestamp = Date.now() / 1000;
|
||||
readonly getAmountByORN = (amountToken: string, lockingDays: number) => {
|
||||
const alpha = 730 / (30 - Math.sqrt(730 / 7)) ** (1 / 3);
|
||||
|
||||
const deltaDaysBN = BigNumber(timeLock).minus(timestamp).dividedBy(DAY);
|
||||
const deltaDaysBN = BigNumber(lockingDays);
|
||||
|
||||
if (deltaDaysBN.lte(0)) return 0;
|
||||
if (deltaDaysBN.lte(0)) return BigNumber(0);
|
||||
|
||||
const multSQRT = deltaDaysBN.dividedBy(WEEK_DAYS).sqrt();
|
||||
const multCUBE = deltaDaysBN.dividedBy(alpha).pow(3);
|
||||
|
||||
return BigNumber(amountToken)
|
||||
.multipliedBy(deltaDaysBN.sqrt())
|
||||
.dividedBy(BigNumber(WEEK_DAYS).sqrt());
|
||||
.multipliedBy(multSQRT.plus(multCUBE));
|
||||
};
|
||||
|
||||
readonly getVotingInfo = (userAddress?: string) => {
|
||||
@@ -163,6 +171,17 @@ class IndexerService {
|
||||
});
|
||||
};
|
||||
|
||||
readonly getListPool = (userAddress?: string) => {
|
||||
return fetchWithValidation(this.apiUrl, listPoolResponseSchema, {
|
||||
method: 'POST',
|
||||
body: this.makeRPCPayload({
|
||||
model: 'OrionVoting',
|
||||
method: 'listPool',
|
||||
params: [userAddress],
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
readonly getPoolInfo = (
|
||||
token0: string,
|
||||
token1: string,
|
||||
@@ -178,8 +197,30 @@ class IndexerService {
|
||||
});
|
||||
};
|
||||
|
||||
readonly listPool = (address?: string) => {
|
||||
return fetchWithValidation(this.apiUrl, listPoolResponseSchema, {
|
||||
readonly listPoolV2 = (address?: string) => {
|
||||
return fetchWithValidation(this.apiUrl, listPoolV2ResponseSchema, {
|
||||
method: 'POST',
|
||||
body: this.makeRPCPayload({
|
||||
model: 'OrionFarmV2',
|
||||
method: 'listPool',
|
||||
params: [address],
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
readonly poolV2Info = (token0: string, token1: string, address: string) => {
|
||||
return fetchWithValidation(this.apiUrl, PoolV2InfoResponseSchema, {
|
||||
method: 'POST',
|
||||
body: this.makeRPCPayload({
|
||||
model: 'OrionV2Factory',
|
||||
method: 'getPoolInfo',
|
||||
params: [token0, token1, address],
|
||||
}),
|
||||
});
|
||||
};
|
||||
|
||||
readonly listPoolV3 = (address?: string) => {
|
||||
return fetchWithValidation(this.apiUrl, listPoolV3ResponseSchema, {
|
||||
method: 'POST',
|
||||
body: this.makeRPCPayload({
|
||||
model: 'OrionFarmV3',
|
||||
|
||||
@@ -5,7 +5,7 @@ const basicPoolInfo = z.object({
|
||||
poolAddress: evmAddressSchema,
|
||||
isInitialized: z.boolean(),
|
||||
liquidity: z.number().nonnegative(),
|
||||
liquidityInUsd: z.number().nonnegative(),
|
||||
liquidityInUSD: z.number().nonnegative(),
|
||||
liquidityShare: z.number().nonnegative(),
|
||||
isFarming: z.boolean(),
|
||||
rewardsTotal: z.number().nonnegative(),
|
||||
|
||||
@@ -7,11 +7,15 @@ const environmentResponseSchema = z.object({
|
||||
chainId: z.number().int().nonnegative(),
|
||||
nativeToken: z.string(),
|
||||
OrionV3Factory: evmAddressSchema,
|
||||
OrionV2Factory: evmAddressSchema,
|
||||
OrionV3NFTManager: evmAddressSchema,
|
||||
SwapRouter: evmAddressSchema,
|
||||
SwapRouterV3: evmAddressSchema,
|
||||
OrionFarmV3: evmAddressSchema,
|
||||
OrionFarmV2: evmAddressSchema,
|
||||
OrionVoting: evmAddressSchema,
|
||||
veORN: evmAddressSchema,
|
||||
ORN: evmAddressSchema,
|
||||
WETH9: evmAddressSchema,
|
||||
}),
|
||||
info: infoSchema,
|
||||
});
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
export { default as environmentResponseSchema } from './environment-response-schema.js';
|
||||
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 veORNInfoResponseSchema } from './veORN-info-schema.js';
|
||||
export { default as listAmountResponseSchema } from './list-amount-schema.js';
|
||||
export { default as votingInfoResponseSchema } from './voting-info-schema.js';
|
||||
export { default as testIncrementorSchema } from './test-incrementor-schema.js';
|
||||
export { default as environmentResponseSchema } from './environment-response-schema';
|
||||
export { default as listNFTOrderResponseSchema } from './list-nft-order-response-schema';
|
||||
export { default as getPoolResponseSchema } from './get-pool-response-schema';
|
||||
export { default as listPoolResponseSchema } from './list-pool-schema';
|
||||
export { default as listPoolV2ResponseSchema } from './list-pool-v2-response-schema';
|
||||
export { default as PoolV2InfoResponseSchema } from './pool-v2-info-schema';
|
||||
export { default as listPoolV3ResponseSchema } from './list-pool-v3-response-schema';
|
||||
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';
|
||||
|
||||
11
src/services/Indexer/schemas/list-pool-schema.ts
Normal file
11
src/services/Indexer/schemas/list-pool-schema.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { z } from 'zod';
|
||||
import infoSchema from './info-schema';
|
||||
import { listPoolV2Schema } from './list-pool-v2-response-schema';
|
||||
import { listPoolV3Schema } from './list-pool-v3-response-schema';
|
||||
|
||||
const listPoolResponseSchema = z.object({
|
||||
result: z.array(listPoolV2Schema.or(listPoolV3Schema)),
|
||||
info: infoSchema,
|
||||
});
|
||||
|
||||
export default listPoolResponseSchema;
|
||||
62
src/services/Indexer/schemas/list-pool-v2-response-schema.ts
Normal file
62
src/services/Indexer/schemas/list-pool-v2-response-schema.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { z } from 'zod';
|
||||
import { evmAddressSchema } from './util-schemas.js';
|
||||
import basicPoolInfo from './basic-pool-info-schema.js';
|
||||
import infoSchema from './info-schema.js';
|
||||
|
||||
export const listPoolV2Schema = z.object({
|
||||
pair: z.string(),
|
||||
token0: z.string().nonempty(),
|
||||
token1: z.string().nonempty(),
|
||||
name: z.string(),
|
||||
name0: z.string(),
|
||||
name1: z.string(),
|
||||
token0Address: evmAddressSchema,
|
||||
token1Address: evmAddressSchema,
|
||||
token0Decimals: z.number().int().nonnegative().max(18),
|
||||
token1Decimals: z.number().int().nonnegative().max(18),
|
||||
WETH9: evmAddressSchema,
|
||||
farmAddress: z.string(),
|
||||
weight: z.number(),
|
||||
liquidity0: z.number(),
|
||||
liquidity1: z.number(),
|
||||
token0Price: z.number(),
|
||||
token1Price: z.number(),
|
||||
totalLPSupply: z.number(),
|
||||
totalLPStake: z.number(),
|
||||
totalLPStakeInUSD: z.number(),
|
||||
userLPStaked: z.number(),
|
||||
userLPStakedInUSD: z.number(),
|
||||
lpPriceInUSD: z.number(),
|
||||
lpPriceInORN: z.number(),
|
||||
userReward: z.number(),
|
||||
weeklyReward: z.number(),
|
||||
userAPR: z.number(),
|
||||
lockMaxMultiplier: z.number(),
|
||||
veornMaxMultiplier: z.number(),
|
||||
veornBoostScaleFactor: z.number(),
|
||||
lockTimeForMaxMultiplier: z.number(),
|
||||
userBoost: z.number(),
|
||||
userTimeDeposit: z.number(),
|
||||
userLockTimeStart: z.number(),
|
||||
userLockTimePeriod: z.number(),
|
||||
userVeORN: z.number(),
|
||||
userORN: z.number(),
|
||||
userRewardToPool: z.number(),
|
||||
boostTotalVeORN: z.number(),
|
||||
boostCurrentPoolReward: z.number(),
|
||||
boostTotalLiquidity: z.number(),
|
||||
boostCurrentLiquidity: z.number(),
|
||||
boostCurrentVeORN: z.number(),
|
||||
boostTotalReward: z.number(),
|
||||
|
||||
...basicPoolInfo.shape,
|
||||
|
||||
type: z.string().nonempty(),
|
||||
});
|
||||
|
||||
const listPoolV2ResponseSchema = z.object({
|
||||
result: z.array(listPoolV2Schema),
|
||||
info: infoSchema,
|
||||
});
|
||||
|
||||
export default listPoolV2ResponseSchema;
|
||||
@@ -3,24 +3,30 @@ import { evmAddressSchema } from './util-schemas.js';
|
||||
import basicPoolInfo from './basic-pool-info-schema.js';
|
||||
import infoSchema from './info-schema.js';
|
||||
|
||||
const poolOfListPoolSchema = z.object({
|
||||
export const listPoolV3Schema = z.object({
|
||||
token0: z.string().nonempty(),
|
||||
token1: z.string().nonempty(),
|
||||
name: z.string(),
|
||||
name0: z.string(),
|
||||
name1: z.string(),
|
||||
token0Address: evmAddressSchema,
|
||||
token1Address: evmAddressSchema,
|
||||
|
||||
token0Decimals: z.number().int().nonnegative().max(18),
|
||||
token1Decimals: z.number().int().nonnegative().max(18),
|
||||
WETH9: evmAddressSchema,
|
||||
poolFee: z.number(),
|
||||
weeklyReward: z.number(),
|
||||
weight: z.number(),
|
||||
totalLPStakeInUSD: z.number(),
|
||||
|
||||
...basicPoolInfo.shape,
|
||||
|
||||
type: z.string().nonempty(),
|
||||
type: z.literal('v3'),
|
||||
});
|
||||
|
||||
const listPoolResponseSchema = z.object({
|
||||
result: z.array(poolOfListPoolSchema),
|
||||
const listPoolV3ResponseSchema = z.object({
|
||||
result: z.array(listPoolV3Schema),
|
||||
info: infoSchema,
|
||||
});
|
||||
|
||||
export default listPoolResponseSchema;
|
||||
export default listPoolV3ResponseSchema;
|
||||
63
src/services/Indexer/schemas/pool-v2-info-schema.ts
Normal file
63
src/services/Indexer/schemas/pool-v2-info-schema.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { z } from 'zod';
|
||||
import { evmAddressSchema } from './util-schemas.js';
|
||||
import basicPoolInfo from './basic-pool-info-schema';
|
||||
import infoSchema from './info-schema.js';
|
||||
|
||||
const poolInfoSchema = z.object({
|
||||
pair: z.string(),
|
||||
name: z.string(),
|
||||
token0: z.string(),
|
||||
token1: z.string(),
|
||||
name0: z.string(),
|
||||
name1: z.string(),
|
||||
token0Address: evmAddressSchema,
|
||||
token1Address: evmAddressSchema,
|
||||
token0Decimals: z.number().int().nonnegative().max(18),
|
||||
token1Decimals: z.number().int().nonnegative().max(18),
|
||||
WETH9: z.string(),
|
||||
farmAddress: z.string(),
|
||||
weight: z.number(),
|
||||
liquidity0: z.number(),
|
||||
liquidity1: z.number(),
|
||||
token0Price: z.number(),
|
||||
token1Price: z.number(),
|
||||
userLPBalance: z.number(),
|
||||
totalLPSupply: z.number(),
|
||||
totalLPStake: z.number(),
|
||||
totalLPStakeInUSD: z.number(),
|
||||
userLPStaked: z.number(),
|
||||
userLPStakedInUSD: z.number(),
|
||||
lpPriceInUSD: z.number(),
|
||||
lpPriceInORN: z.number(),
|
||||
userReward: z.number(),
|
||||
userWeeklyReward: z.number(),
|
||||
userRewardToPool: z.number(),
|
||||
weeklyReward: z.number(),
|
||||
userAPR: z.number(),
|
||||
lockMaxMultiplier: z.number(),
|
||||
veornMaxMultiplier: z.number(),
|
||||
veornBoostScaleFactor: z.number(),
|
||||
lockTimeForMaxMultiplier: z.number(),
|
||||
userBoost: z.number(),
|
||||
userTimeDeposit: z.number(),
|
||||
userLockTimeStart: z.number(),
|
||||
userLockTimePeriod: z.number(),
|
||||
userVeORN: z.number(),
|
||||
userORN: z.number(),
|
||||
boostTotalVeORN: z.number(),
|
||||
boostCurrentPoolReward: z.number(),
|
||||
boostTotalLiquidity: z.number(),
|
||||
boostCurrentLiquidity: z.number(),
|
||||
boostCurrentVeORN: z.number(),
|
||||
boostTotalReward: z.number(),
|
||||
type: z.literal('v2'),
|
||||
|
||||
...basicPoolInfo.shape,
|
||||
});
|
||||
|
||||
const PoolV2InfoResponseSchema = z.object({
|
||||
result: poolInfoSchema,
|
||||
info: infoSchema,
|
||||
});
|
||||
|
||||
export default PoolV2InfoResponseSchema;
|
||||
@@ -15,7 +15,8 @@ const veORNResultSchema = z.object({
|
||||
userORNLocked: z.number(),
|
||||
userLockEndDate: z.number(),
|
||||
userReward: z.number(),
|
||||
userWeeklyReward: z.number()
|
||||
userWeeklyReward: z.number(),
|
||||
userMinLockPeriod: z.number(),
|
||||
});
|
||||
|
||||
const veORNInfoSchema = z.object({
|
||||
|
||||
@@ -12,6 +12,7 @@ const poolSchema = z.object({
|
||||
name0: z.string(),
|
||||
name1: z.string(),
|
||||
poolFee: z.number(),
|
||||
userWeight: z.number(),
|
||||
weight: z.number(),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user