Semantics improvements

This commit is contained in:
Aleksandr Kraiz
2023-05-16 23:21:45 +04:00
parent 188e7bb317
commit cd4eff76d3
88 changed files with 419 additions and 478 deletions

View File

@@ -0,0 +1,449 @@
import { z } from 'zod';
import {
IDOSchema, atomicHistorySchema,
poolsConfigSchema, poolsInfoSchema, infoSchema, historySchema,
type addPoolSchema, adminPoolsListSchema, adminPoolSchema,
atomicSummarySchema,
poolsLpAndStakedSchema,
userVotesSchema,
userEarnedSchema,
type PairStatusEnum,
pairStatusSchema,
cfdContractsSchema,
cfdHistorySchema,
governanceContractsSchema,
governancePoolsSchema,
governancePoolSchema,
} from './schemas/index.js';
import type redeemOrderSchema from '../Aggregator/schemas/redeemOrderSchema.js';
import { sourceAtomicHistorySchema, targetAtomicHistorySchema } from './schemas/atomicHistorySchema.js';
import { makePartial } from '../../utils/index.js';
import type { networkCodes } from '../../constants/index.js';
import { fetchWithValidation } from 'simple-typed-fetch';
type IAdminAuthHeaders = {
auth: string
[key: string]: string
}
export type IEditPool = {
tokenAIcon?: string
tokenBIcon?: string
symbol?: string
status: PairStatusEnum
minQty?: number
tokenASymbol?: string
tokenBSymbol?: string
tokensReversed?: boolean
}
type AtomicSwapHistoryBaseQuery = {
limit?: number
sender?: string
receiver?: string
used?: 0 | 1
page?: number
sourceNetworkCode?: typeof networkCodes[number]
} & Partial<Record<string, string | number>>
type AtomicSwapHistorySourceQuery = AtomicSwapHistoryBaseQuery & {
type?: 'source'
expiredLock?: 0 | 1
state?: 'LOCKED' | 'CLAIMED' | 'REFUNDED'
}
type AtomicSwapHistoryTargetQuery = AtomicSwapHistoryBaseQuery & {
type?: 'target'
expiredRedeem?: 0 | 1
state?: 'REDEEMED' | 'BEFORE-REDEEM'
}
type CfdHistoryQuery = {
instrument?: string
page?: number
limit?: number
} & Partial<Record<string, string | number>>
class BlockchainService {
private readonly apiUrl: string;
get api() {
return this.apiUrl;
}
constructor(apiUrl: string) {
this.apiUrl = apiUrl;
this.getAtomicSwapAssets = this.getAtomicSwapAssets.bind(this);
this.getAtomicSwapHistory = this.getAtomicSwapHistory.bind(this);
this.getAuthToken = this.getAuthToken.bind(this);
this.getCirculatingSupply = this.getCirculatingSupply.bind(this);
this.getInfo = this.getInfo.bind(this);
this.getPoolsConfig = this.getPoolsConfig.bind(this);
this.getPoolsInfo = this.getPoolsInfo.bind(this);
this.getPoolsLpAndStaked = this.getPoolsLpAndStaked.bind(this);
this.getUserVotes = this.getUserVotes.bind(this);
this.getUserEarned = this.getUserEarned.bind(this);
this.getHistory = this.getHistory.bind(this);
this.getPrices = this.getPrices.bind(this);
this.getTokensFee = this.getTokensFee.bind(this);
this.getGasPriceWei = this.getGasPriceWei.bind(this);
this.checkFreeRedeemAvailable = this.checkFreeRedeemAvailable.bind(this);
this.redeemAtomicSwap = this.redeemAtomicSwap.bind(this);
this.redeem2AtomicSwaps = this.redeem2AtomicSwaps.bind(this);
this.checkRedeem = this.checkRedeem.bind(this);
this.checkRedeem2Atomics = this.checkRedeem2Atomics.bind(this);
this.getIDOInfo = this.getIDOInfo.bind(this);
this.checkAuth = this.checkAuth.bind(this);
this.addPool = this.addPool.bind(this);
this.editPool = this.editPool.bind(this);
this.getPool = this.getPool.bind(this);
this.getPoolsList = this.getPoolsList.bind(this);
this.getSourceAtomicSwapHistory = this.getSourceAtomicSwapHistory.bind(this);
this.getTargetAtomicSwapHistory = this.getTargetAtomicSwapHistory.bind(this);
this.checkPoolInformation = this.checkPoolInformation.bind(this);
this.checkIfHashUsed = this.checkIfHashUsed.bind(this);
this.getBlockNumber = this.getBlockNumber.bind(this);
this.getRedeemOrderBySecretHash = this.getRedeemOrderBySecretHash.bind(this);
this.claimOrder = this.claimOrder.bind(this);
this.getCFDContracts = this.getCFDContracts.bind(this);
this.getCFDHistory = this.getCFDHistory.bind(this);
this.getGovernanceContracts = this.getGovernanceContracts.bind(this);
this.getGovernancePools = this.getGovernancePools.bind(this);
this.getGovernancePool = this.getGovernancePool.bind(this);
}
get blockchainServiceWsUrl() {
return `${this.apiUrl}/`;
}
private readonly getSummaryRedeem = (brokerAddress: string, unshifted?: 1 | 0, sourceNetworkCode?: typeof networkCodes[number]) => {
const url = new URL(`${this.apiUrl}/api/atomic/summary-redeem/${brokerAddress}`);
if (unshifted !== undefined && unshifted === 1) {
url.searchParams.append('unshifted', unshifted.toString());
}
if (sourceNetworkCode !== undefined) {
url.searchParams.append('sourceNetworkCode', sourceNetworkCode);
}
return fetchWithValidation(
url.toString(),
atomicSummarySchema,
);
};
private readonly getSummaryClaim = (brokerAddress: string) => fetchWithValidation(
`${this.apiUrl}/api/atomic/summary-claim/${brokerAddress}`,
atomicSummarySchema,
);
private readonly getQueueLength = () => fetchWithValidation(
`${this.apiUrl}/api/queueLength`,
z.number().int(),
);
get internal() {
return {
getSummaryRedeem: this.getSummaryRedeem.bind(this),
getSummaryClaim: this.getSummaryClaim.bind(this),
getQueueLength: this.getQueueLength.bind(this),
};
}
getAuthToken = () => fetchWithValidation(
`${this.apiUrl}/api/auth/token`,
z.object({ token: z.string() }),
);
getCirculatingSupply = () => fetchWithValidation(
`${this.apiUrl}/api/circulating-supply`,
z.number(),
);
getInfo = () => fetchWithValidation(`${this.apiUrl}/api/info`, infoSchema);
getPoolsConfig = () => fetchWithValidation(
`${this.apiUrl}/api/pools/config`,
poolsConfigSchema,
);
getPoolsInfo = () => fetchWithValidation(
`${this.apiUrl}/api/pools/info`,
poolsInfoSchema,
);
getPoolsLpAndStaked = (address: string) => fetchWithValidation(
`${this.apiUrl}/api/pools/user-lp/${address}`,
poolsLpAndStakedSchema,
);
getUserVotes = (address: string) => fetchWithValidation(
`${this.apiUrl}/api/pools/user-votes/${address}`,
userVotesSchema,
);
getUserEarned = (address: string) => fetchWithValidation(
`${this.apiUrl}/api/pools/user-earned/${address}`,
userEarnedSchema,
);
getHistory = (address: string) => fetchWithValidation(
`${this.apiUrl}/api/history/${address}`,
historySchema,
);
getPrices = () => fetchWithValidation(
`${this.apiUrl}/api/prices`,
z.record(z.string()).transform(makePartial),
);
getCFDPrices = () => fetchWithValidation(
`${this.apiUrl}/api/cfd/prices`,
z.record(z.string()).transform(makePartial),
);
getTokensFee = () => fetchWithValidation(
`${this.apiUrl}/api/tokensFee`,
z.record(z.string()).transform(makePartial),
);
getGasPriceWei = () => fetchWithValidation(
`${this.apiUrl}/api/gasPrice`,
z.string(),
);
checkFreeRedeemAvailable = (walletAddress: string) => fetchWithValidation(
`${this.apiUrl}/api/atomic/has-free-redeem/${walletAddress}`,
z.boolean(),
);
getRedeemOrderBySecretHash = (secretHash: string) => fetchWithValidation(
`${this.apiUrl}/api/atomic/redeem-order/${secretHash}`,
z.object({
secretHash: z.string(),
secret: z.string(),
redeemTxHash: z.string(),
}),
);
claimOrder = (
secretHash: string,
targetNetwork: typeof networkCodes[number],
redeemTxHash?: string,
) => fetchWithValidation(
`${this.apiUrl}/api/atomic/claim-order`,
z.string(),
{
method: 'POST',
body: JSON.stringify({
secretHash,
targetNetwork,
redeemTxHash,
}),
headers: {
'Content-Type': 'application/json',
},
},
);
redeemAtomicSwap = (
redeemOrder: z.infer<typeof redeemOrderSchema>,
secret: string,
sourceNetwork: typeof networkCodes[number],
) => fetchWithValidation(
`${this.apiUrl}/api/atomic/matcher-redeem`,
z.string(),
{
method: 'POST',
body: JSON.stringify({
order: redeemOrder,
secret,
sourceNetwork,
}),
headers: {
'Content-Type': 'application/json',
},
},
);
redeem2AtomicSwaps = (
redeemOrder1: z.infer<typeof redeemOrderSchema>,
secret1: string,
redeemOrder2: z.infer<typeof redeemOrderSchema>,
secret2: string,
sourceNetwork: typeof networkCodes[number],
) => fetchWithValidation(
`${this.apiUrl}/api/atomic/matcher-redeem2atomics`,
z.string(),
{
method: 'POST',
body: JSON.stringify({
order1: redeemOrder1,
secret1,
order2: redeemOrder2,
secret2,
sourceNetwork,
}),
headers: {
'Content-Type': 'application/json',
},
},
);
checkRedeem = (secretHash: string) => fetchWithValidation(
`${this.apiUrl}/api/atomic/matcher-redeem/${secretHash}`,
z.enum(['OK', 'FAIL']).nullable(),
);
checkRedeem2Atomics = (firstSecretHash: string, secondSecretHash: string) => fetchWithValidation(
`${this.apiUrl}/api/atomic/matcher-redeem/${firstSecretHash}-${secondSecretHash}`,
z.enum(['OK', 'FAIL']).nullable(),
);
getBlockNumber = () => fetchWithValidation(`${this.apiUrl}/api/blocknumber`, z.number().int());
getIDOInfo = () => fetchWithValidation(`${this.apiUrl}/api/solarflare`, IDOSchema);
checkAuth = (headers: IAdminAuthHeaders) => fetchWithValidation(`${this.apiUrl}/api/auth/check`, z.object({
auth: z.boolean(),
}), { headers });
getPool = (address: string, headers: IAdminAuthHeaders) => fetchWithValidation(
`${this.apiUrl}/api/pools/${address}`,
adminPoolSchema,
{ headers },
);
getPoolsList = (headers: IAdminAuthHeaders) => fetchWithValidation(
`${this.apiUrl}/api/pools/list`,
adminPoolsListSchema,
{ headers },
);
editPool = (address: string, data: IEditPool, headers: IAdminAuthHeaders) => fetchWithValidation(
`${this.apiUrl}/api/pools/edit/${address}`,
pairStatusSchema,
{
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
...headers,
},
},
);
addPool = (data: z.infer<typeof addPoolSchema>) => fetchWithValidation(
`${this.apiUrl}/api/pools/add`,
z.number(),
{
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
},
z.string(),
);
checkPoolInformation = (poolAddress: string) => fetchWithValidation(
`${this.apiUrl}/api/pools/check/${poolAddress}`,
pairStatusSchema,
);
getAtomicSwapAssets = () => fetchWithValidation(
`${this.apiUrl}/api/atomic/swap-assets`,
z.array(z.string()),
);
/**
* Sender is user address in source BlockchainService instance \
* Receiver is user address in target BlockchainService instance
*/
getAtomicSwapHistory = (query: AtomicSwapHistorySourceQuery | AtomicSwapHistoryTargetQuery) => {
const url = new URL(`${this.apiUrl}/api/atomic/history/`);
Object.entries(query)
.forEach(([key, value]) => {
if (value === undefined) throw new Error('Value must be defined');
url.searchParams.append(key, value.toString());
});
return fetchWithValidation(url.toString(), atomicHistorySchema);
};
getSourceAtomicSwapHistory = (query: AtomicSwapHistorySourceQuery) => {
const url = new URL(`${this.apiUrl}/api/atomic/history/`);
Object.entries(query)
.forEach(([key, value]) => {
if (value === undefined) throw new Error('Value must be defined');
url.searchParams.append(key, value.toString());
});
if (query.type === undefined) url.searchParams.append('type', 'source');
return fetchWithValidation(url.toString(), sourceAtomicHistorySchema);
};
getTargetAtomicSwapHistory = (query: AtomicSwapHistoryTargetQuery) => {
const url = new URL(`${this.apiUrl}/api/atomic/history/`);
Object.entries(query)
.forEach(([key, value]) => {
if (value === undefined) throw new Error('Value must be defined');
url.searchParams.append(key, value.toString());
});
if (query.type === undefined) url.searchParams.append('type', 'target');
return fetchWithValidation(url.toString(), targetAtomicHistorySchema);
};
checkIfHashUsed = (secretHashes: string[]) => fetchWithValidation(
`${this.apiUrl}/api/atomic/is-hash-used`,
z.record(z.boolean()).transform(makePartial),
{
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
method: 'POST',
body: JSON.stringify(secretHashes),
},
);
getCFDContracts = () => fetchWithValidation(
`${this.apiUrl}/api/cfd/contracts`,
cfdContractsSchema,
);
getCFDHistory = (address: string, query: CfdHistoryQuery = {}) => {
const url = new URL(`${this.apiUrl}/api/cfd/deposit-withdraw/${address}`);
Object.entries(query)
.forEach(([key, value]) => {
if (value === undefined) throw new Error('Value must be defined');
url.searchParams.append(key, value.toString());
});
return fetchWithValidation(url.toString(), cfdHistorySchema);
};
getGovernanceContracts = () => fetchWithValidation(
`${this.apiUrl}/api/governance/info`,
governanceContractsSchema,
);
getGovernancePools = () => fetchWithValidation(
`${this.apiUrl}/api/governance/pools`,
governancePoolsSchema,
);
getGovernancePool = (address: string) => fetchWithValidation(
`${this.apiUrl}/api/governance/pools/${address}`,
governancePoolSchema,
);
}
export * as schemas from './schemas/index.js';
export { BlockchainService };

View File

@@ -0,0 +1,10 @@
import { z } from 'zod';
const IDOSchema = z.object({
amount: z.number().or(z.null()),
amountInWei: z.number().or(z.null()),
amountInUSDT: z.number().or(z.null()),
address: z.string(),
});
export default IDOSchema;

View File

@@ -0,0 +1,11 @@
import { z } from 'zod';
const addPoolSchema = z.object({
poolAddress: z.string(),
tokenAIcon: z.string().optional(),
tokenAName: z.string().optional(),
tokenBIcon: z.string().optional(),
tokenBName: z.string().optional(),
});
export default addPoolSchema;

View File

@@ -0,0 +1,36 @@
import { z } from 'zod';
export enum PairStatusEnum {
DOESNT_EXIST = -1,
REVIEW = 0,
ACCEPTED = 1,
REJECTED = 2,
}
export const pairStatusSchema = z.nativeEnum(PairStatusEnum);
const tokenSchema = z.object({
symbol: z.string(),
icon: z.string().optional(),
address: z.string(),
decimals: z.number().optional(),
isUser: z.boolean().optional(),
});
export const poolOnVerificationSchema = z.object({
tokenA: tokenSchema,
tokenB: tokenSchema,
_id: z.string().optional(),
address: z.string(),
symbol: z.string(),
isUser: z.boolean(),
minQty: z.number().optional(),
tokensReversed: z.boolean(),
status: pairStatusSchema,
updatedAt: z.number(),
createdAt: z.number(),
});
export type adminPoolType = z.infer<typeof poolOnVerificationSchema>;
export const adminPoolSchema = poolOnVerificationSchema;

View File

@@ -0,0 +1,5 @@
import { z } from 'zod';
import { poolOnVerificationSchema } from './adminPoolSchema.js';
export default z.array(poolOnVerificationSchema);

View File

@@ -0,0 +1,74 @@
import { ethers } from 'ethers';
import { z } from 'zod';
import getValidArrayItemsSchema from '../../../utils/getValidArrayItems.js';
const baseAtomicHistorySchema = z.object({
success: z.boolean(),
count: z.number(),
total: z.number(),
pagination: z.object({}),
});
const baseAtomicHistoryItem = z.object({
used: z.boolean(),
claimed: z.boolean(),
isAggApplied: z.boolean(),
_id: z.string(),
__v: z.number(),
asset: z.string(),
sender: z.string().refine(ethers.utils.isAddress),
secretHash: z.string().refine(ethers.utils.isHexString),
receiver: z.string().refine(ethers.utils.isAddress).optional(),
secret: z.string().optional(),
});
const sourceAtomicHistorySchemaItem = baseAtomicHistoryItem.extend({
type: z.literal('source'),
amountToReceive: z.number().optional(),
amountToSpend: z.number().optional(),
timestamp: z.object({
lock: z.number().optional(),
claim: z.number().optional(),
refund: z.number().optional(),
}).optional(),
expiration: z.object({
lock: z.number().optional(),
}).optional(),
state: z.enum(['LOCKED', 'REFUNDED', 'CLAIMED']),
targetChainId: z.number(),
transactions: z.object({
lock: z.string().optional(),
claim: z.string().optional(),
refund: z.string().optional(),
}).optional(),
});
const targetAtomicHistorySchemaItem = baseAtomicHistoryItem.extend({
type: z.literal('target'),
timestamp: z.object({
redeem: z.number().optional(),
}).optional(),
expiration: z.object({
redeem: z.number().optional(),
}).optional(),
state: z.enum(['REDEEMED', 'BEFORE-REDEEM']),
transactions: z.object({
redeem: z.string().optional(),
}).optional(),
});
export const sourceAtomicHistorySchema = baseAtomicHistorySchema.extend({
data: z.array(sourceAtomicHistorySchemaItem),
});
export const targetAtomicHistorySchema = baseAtomicHistorySchema.extend({
data: z.array(targetAtomicHistorySchemaItem),
});
const atomicHistorySchema = baseAtomicHistorySchema.extend({
data: getValidArrayItemsSchema(
z.discriminatedUnion('type', [sourceAtomicHistorySchemaItem, targetAtomicHistorySchemaItem]),
),
});
export default atomicHistorySchema;

View File

@@ -0,0 +1,6 @@
import { z } from 'zod';
export default z.object({
amount: z.number(),
count: z.number(),
});

View File

@@ -0,0 +1,20 @@
import { z } from 'zod';
const cfdContractsSchema = z.array(z.object({
name: z.string(),
alias: z.string(),
address: z.string(),
leverage: z.number(),
soLevel: z.number(),
shortFR: z.number(),
longFR: z.number(),
shortFRStored: z.number(),
longFRStored: z.number(),
lastFRPriceUpdateTime: z.number(),
priceIndex: z.number(),
feePercent: z.number(),
withdrawMarginLevel: z.number(),
delegateContractAddress: z.string(),
}));
export default cfdContractsSchema;

View File

@@ -0,0 +1,52 @@
import { z } from 'zod';
import { HistoryTransactionStatus } from '../../../types.js';
export enum historyTransactionType {
WITHDRAW = 'withdrawal',
DEPOSIT = 'deposit',
}
const cfdHistoryItem = z.object({
_id: z.string(),
__v: z.number(),
address: z.string(),
instrument: z.string(),
instrumentAddress: z.string(),
balance: z.string(),
amount: z.string(),
amountNumber: z.string(),
position: z.string(),
reason: z.enum(['WITHDRAW', 'DEPOSIT']),
positionPrice: z.string(),
fundingRate: z.string(),
transactionHash: z.string(),
blockNumber: z.number(),
createdAt: z.number(),
});
const cfdHistorySchema = z.object({
success: z.boolean(),
count: z.number(),
total: z.number(),
pagination: z.object({}),
data: z.array(cfdHistoryItem),
}).transform((response) => {
return response.data.map((item) => {
const {
createdAt, reason, transactionHash, amountNumber,
} = item;
const type = historyTransactionType[reason];
return {
type,
date: createdAt,
token: 'USDT',
amount: amountNumber,
status: HistoryTransactionStatus.DONE,
transactionHash,
user: item.address,
};
});
});
export default cfdHistorySchema;

View File

@@ -0,0 +1,9 @@
import { z } from 'zod';
const checkRedeemOrderSchema = z.object({
redeemTxHash: z.string(),
secret: z.string().nullable(),
secretHash: z.string(),
});
export default checkRedeemOrderSchema;

View File

@@ -0,0 +1,20 @@
import { z } from 'zod';
const governanceContractsSchema = z.object({
controllerAddress: z.string(),
veORNAddress: z.string(),
veORNYieldDistributorV4Address: z.string(),
orionGaugeORNRewardsDistributorAddress: z.string(),
time_total: z.string(),
absolute_ve_orn_in_voting: z.string(),
info: z.record(
z.string(),
z.object({
gaugeAddress: z.string(),
gaugeType: z.number(),
gaugeName: z.string(),
})
),
});
export default governanceContractsSchema;

View File

@@ -0,0 +1,18 @@
import { z } from 'zod';
const governancePoolSchema = z.object({
min_apr: z.string(),
max_apr: z.string(),
tvl: z.string(),
lp_supply: z.string(),
lp_staked: z.string(),
lp_staked_with_boost: z.string(),
lp_price_in_usd: z.string(),
reward_per_period: z.string(),
lock_time_for_max_multiplier: z.string(),
lock_max_multiplier: z.string(),
veorn_max_multiplier: z.string(),
veorn_boost_scale_factor: z.string(),
});
export default governancePoolSchema;

View File

@@ -0,0 +1,28 @@
import { z } from 'zod';
const governancePoolsSchema = z.array(
z.object({
slug: z.string(),
identifier: z.string(),
chain: z.string(),
platform: z.string(),
logo: z.string(),
pair: z.string(),
lp_address: z.string(),
lp_staked: z.string(),
lp_staked_with_boost: z.string(),
lp_supply: z.string(),
lp_price_in_usd: z.string(),
farm_address: z.string(),
pool_tokens: z.tuple([z.string(), z.string()]),
pool_rewards: z.array(z.string()),
tvl: z.string(),
min_apr: z.string(),
max_apr: z.string(),
reward_per_period: z.array(z.string()),
weight: z.string(),
liquidity: z.string(),
})
);
export default governancePoolsSchema;

View File

@@ -0,0 +1,34 @@
import { z } from 'zod';
import { HistoryTransactionStatus } from '../../../types.js';
const historySchema = z.array(z.object(
{
amount: z.string(),
amountNumber: z.string(),
asset: z.string(),
assetAddress: z.string(),
contractBalance: z.string().nullable().optional(),
createdAt: z.number(),
transactionHash: z.string(),
type: z.enum(['deposit', 'withdrawal']),
user: z.string(),
walletBalance: z.string().nullable().optional(),
},
)).transform((response) => {
return response.map((item) => {
const {
type, createdAt, transactionHash, user,
} = item;
return {
type,
date: createdAt * 1000,
token: item.asset,
amount: item.amountNumber,
status: HistoryTransactionStatus.DONE,
transactionHash,
user,
};
});
});
export default historySchema;

View File

@@ -0,0 +1,19 @@
export * from './adminPoolSchema.js';
export { default as adminPoolsListSchema } from './adminPoolsListSchema.js';
export { default as addPoolSchema } from './addPoolSchema.js';
export { default as atomicHistorySchema } from './atomicHistorySchema.js';
export { default as checkRedeemOrderSchema } from './checkRedeemOrderSchema.js';
export { default as historySchema } from './historySchema.js';
export { default as IDOSchema } from './IDOSchema.js';
export { default as infoSchema } from './infoSchema.js';
export { default as poolsConfigSchema } from './poolsConfigSchema.js';
export { default as poolsInfoSchema } from './poolsInfoSchema.js';
export { default as atomicSummarySchema } from './atomicSummarySchema.js';
export { default as poolsLpAndStakedSchema } from './poolsLpAndStakedSchema.js';
export { default as userVotesSchema } from './userVotesSchema.js';
export { default as userEarnedSchema } from './userEarnedSchema.js';
export { default as cfdContractsSchema } from './cfdContractsSchema.js';
export { default as cfdHistorySchema } from './cfdHistorySchema.js';
export { default as governanceContractsSchema } from './governanceContractsSchema.js';
export { default as governancePoolsSchema } from './governancePoolsSchema.js';
export { default as governancePoolSchema } from './governancePoolSchema.js';

View File

@@ -0,0 +1,24 @@
import { z } from 'zod';
import { makePartial } from '../../../utils/index.js';
const internalFeeAssetSchema = z.object({
type: z.enum(['percent', 'plain']),
value: z.number(),
asset: z.string(),
});
const infoSchema = z.object({
chainId: z.number(),
chainName: z.string(),
exchangeContractAddress: z.string(),
oracleContractAddress: z.string(),
matcherAddress: z.string(),
orderFeePercent: z.number(),
assetToAddress: z.record(z.string()).transform(makePartial),
assetToDecimals: z.record(z.number()).transform(makePartial),
assetToIcons: z.record(z.string()).transform(makePartial).optional(),
cexTokens: z.string().array(),
internalFeeAssets: internalFeeAssetSchema.array().optional(),
});
export default infoSchema;

View File

@@ -0,0 +1,33 @@
import { z } from 'zod';
import addressSchema from '../../../addressSchema.js';
import { makePartial } from '../../../utils/index.js';
const poolsConfigSchema = z.object({
WETHAddress: addressSchema.optional(),
factoryAddress: addressSchema,
governanceAddress: addressSchema.optional(),
routerAddress: addressSchema,
votingAddress: addressSchema.optional(),
factories: z.record(
z.string(),
addressSchema,
)
.transform(makePartial)
.optional(),
pools: z.record(
z.string(),
z.object({
lpTokenAddress: addressSchema,
minQty: z.number().optional(),
reverted: z.boolean().optional(),
rewardToken: z.string().nullable().optional(),
state: z.number().int().optional(),
rewardTokenDecimals: z.number().int().optional(),
stakingRewardFinish: z.number().optional(),
stakingRewardAddress: addressSchema,
vote_rewards_disabled: z.boolean().optional(),
}),
).transform(makePartial),
});
export default poolsConfigSchema;

View File

@@ -0,0 +1,26 @@
import { z } from 'zod';
const poolsInfoSchema = z.object({
governance: z.object({
apr: z.string(),
rewardRate: z.string(),
totalBalance: z.string(),
}),
totalRewardRatePerWeek: z.string(),
pools: z.record(
z.object({
currentAPR: z.string(),
isUser: z.boolean().optional(),
price: z.string(),
reserves: z.record(z.string()),
totalLiquidityInDollars: z.string(),
totalRewardRatePerWeek: z.string(),
totalStakedAmountInDollars: z.string(),
totalSupply: z.string(),
totalVoted: z.string(),
weight: z.string(),
}),
),
});
export default poolsInfoSchema;

View File

@@ -0,0 +1,10 @@
import { z } from 'zod';
const poolsLpAndStakedSchema = z.record(
z.object({
unstakedLPBalance: z.string(),
stakedLPBalance: z.string(),
}),
);
export default poolsLpAndStakedSchema;

View File

@@ -0,0 +1,7 @@
import { z } from 'zod';
const userEarnedSchema = z.record(
z.string(),
);
export default userEarnedSchema;

View File

@@ -0,0 +1,7 @@
import { z } from 'zod';
const userVotesSchema = z.record(
z.string(),
);
export default userVotesSchema;