Relax Exchange type

This commit is contained in:
Aleksandr Kraiz
2023-08-03 14:09:56 +04:00
parent ea426c10c1
commit dec0e82b07
11 changed files with 24 additions and 31 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.19.42",
"version": "0.19.43",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",
@@ -108,4 +108,4 @@
"overrides": {
"tsconfig-paths": "^4.0.0"
}
}
}

View File

@@ -8,7 +8,7 @@ import errorSchema from './schemas/errorSchema.js';
import placeAtomicSwapSchema from './schemas/placeAtomicSwapSchema.js';
import { AggregatorWS } from './ws/index.js';
import { atomicSwapHistorySchema } from './schemas/atomicSwapHistorySchema.js';
import type { BasicAuthCredentials, Exchange, SignedCancelOrderRequest, SignedOrder } from '../../types.js';
import type { BasicAuthCredentials, SignedCancelOrderRequest, SignedOrder } from '../../types.js';
import {
pairConfigSchema, aggregatedOrderbookSchema,
exchangeOrderbookSchema, poolReservesSchema,
@@ -18,7 +18,6 @@ import toUpperCase from '../../utils/toUpperCase.js';
import httpToWS from '../../utils/httpToWS.js';
import { ethers } from 'ethers';
import orderSchema from './schemas/orderSchema.js';
import { exchanges } from '../../constants/index.js';
import { fetchWithValidation } from 'simple-typed-fetch';
class Aggregator {
@@ -119,12 +118,12 @@ class Aggregator {
getAvailableExchanges = () => fetchWithValidation(
`${this.apiUrl}/api/v1/exchange/list`,
z.enum(exchanges).array(),
z.string().array(),
);
getExchangeOrderbook = (
pair: string,
exchange: Exchange,
exchange: string,
depth = 20,
filterByBrokerBalances: boolean | null = null,
) => {
@@ -156,7 +155,7 @@ class Aggregator {
getPoolReserves = (
pair: string,
exchange: Exchange,
exchange: string,
) => {
const url = new URL(`${this.apiUrl}/api/v1/pools/reserves/${exchange}/${pair}`);
return fetchWithValidation(
@@ -255,7 +254,7 @@ class Aggregator {
assetOut: string,
amount: string,
instantSettlement?: boolean,
exchanges?: Exchange[] | 'cex' | 'pools',
exchanges?: string[] | 'cex' | 'pools',
) => {
const url = new URL(`${this.apiUrl}/api/v1/swap`);
url.searchParams.append('assetIn', assetIn);

View File

@@ -1,5 +1,4 @@
import { z } from 'zod';
import { exchanges } from '../../../constants/index.js';
const orderbookElementSchema = z.object({
price: z.number(),
@@ -12,7 +11,7 @@ const orderbookElementSchema = z.object({
const aggregatedOrderbookElementSchema = orderbookElementSchema
.extend({
exchanges: z.enum(exchanges).array(),
exchanges: z.string().array(),
});
export const aggregatedOrderbookSchema = z.object({

View File

@@ -86,7 +86,7 @@ const subOrderSchema = baseOrderSchema.extend({
parentOrderId: z.string().refine(ethers.utils.isHexString, (value) => ({
message: `subOrder.parentOrderId must be a hex string, got ${value}`,
})),
exchange: z.enum(exchanges),
exchange: z.string(),
brokerAddress: brokerAddressSchema,
tradesInfo: z.record(
z.string().uuid(),

View File

@@ -1,5 +1,4 @@
import { z } from 'zod';
import { exchanges } from '../../../constants/index.js';
const orderInfoSchema = z.object({
assetPair: z.string().toUpperCase(),
@@ -18,13 +17,13 @@ const swapInfoBase = z.object({
// isThroughPoolOptimal: z.boolean(), // deprecated
executionInfo: z.string(),
orderInfo: orderInfoSchema,
exchanges: z.array(z.enum(exchanges)),
exchanges: z.array(z.string()),
price: z.number().nullable(), // spending asset price
minAmountOut: z.number(),
minAmountIn: z.number(),
marketPrice: z.number().nullable(), // spending asset market price
alternatives: z.object({ // execution alternatives
exchanges: z.array(z.enum(exchanges)),
exchanges: z.array(z.string()),
path: z.object({
units: z.object({
assetPair: z.string().toUpperCase(),

View File

@@ -11,7 +11,7 @@ import {
import UnsubscriptionType from './UnsubscriptionType.js';
import type {
SwapInfoBase, AssetPairUpdate, OrderbookItem,
Balance, Exchange, SwapInfo, Json, BasicAuthCredentials,
Balance, SwapInfo, Json, BasicAuthCredentials,
} from '../../../types.js';
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema.js';
import assetPairConfigSchema from './schemas/assetPairConfigSchema.js';
@@ -42,7 +42,7 @@ type SwapInfoSubscriptionPayload = {
i: string // asset in
o: string // asset out
a: number // amount IN/OUT
es?: Exchange[] | 'cex' | 'pools' // exchange list of all cex or all pools (ORION_POOL, UNISWAP, PANCAKESWAP etc)
es?: string[] | 'cex' | 'pools' // exchange list of all cex or all pools (ORION_POOL, UNISWAP, PANCAKESWAP etc)
e?: boolean // is amount IN? Value `false` means a = amount OUT, `true` if omitted
is?: boolean // instant settlement
}

View File

@@ -1,5 +1,4 @@
import { z } from 'zod';
import { exchanges } from '../../../../constants/index.js';
import orderStatuses from '../../../../constants/orderStatuses.js';
import executionTypes from '../../../../constants/executionTypes.js';
import subOrderStatuses from '../../../../constants/subOrderStatuses.js';
@@ -23,7 +22,7 @@ const subOrderSchema = z.object({
a: z.number(), // amount
A: z.number(), // settled amount
p: z.number(), // avg weighed settlement price
e: z.enum(exchanges), // exchange
e: z.string(), // exchange
b: z.string(), // broker address
S: z.enum(subOrderStatuses), // status
o: z.boolean(), // internal only

View File

@@ -1,5 +1,4 @@
import { z } from 'zod';
import exchanges from '../../../../constants/exchanges.js';
import MessageType from '../MessageType.js';
import baseMessageSchema from './baseMessageSchema.js';
@@ -7,7 +6,7 @@ export const orderBookItemSchema = z.tuple([
z.string(), // price
z.string(), // size
z.array(
z.enum(exchanges),
z.string(),
), // exchanges
z.array(z.tuple([
z.enum(['SELL', 'BUY']), // side

View File

@@ -1,10 +1,9 @@
import { z } from 'zod';
import exchanges from '../../../../constants/exchanges.js';
import MessageType from '../MessageType.js';
import baseMessageSchema from './baseMessageSchema.js';
const alternativeSchema = z.object({ // execution alternatives
e: z.enum(exchanges).array(), // exchanges
e: z.string().array(), // exchanges
ps: z.string().array(), // path
mo: z.number().optional(), // market amount out
mi: z.number().optional(), // market amount in
@@ -23,7 +22,7 @@ const swapInfoSchemaBase = baseMessageSchema.extend({
mao: z.number(), // min amount out
ps: z.string().array(), // path
po: z.boolean(), // is swap through pool optimal
e: z.enum(exchanges).array().optional(), // Exchanges
e: z.string().array().optional(), // Exchanges
p: z.number().optional(), // price
mp: z.number().optional(), // market price
oi: z.object({ // info about order equivalent to this swap

View File

@@ -1,5 +1,5 @@
import { fetchWithValidation } from 'simple-typed-fetch';
import type { BasicAuthCredentials, Exchange } from '../../types.js';
import type { BasicAuthCredentials } from '../../types.js';
import { allTickersSchema, statisticsOverviewSchema, topPairsStatisticsSchema } from './schemas/index.js';
import candlesSchema from './schemas/candlesSchema.js';
import { PriceFeedWS } from './ws/index.js';
@@ -56,7 +56,7 @@ class PriceFeed {
);
};
getStatisticsOverview = (exchange: Exchange | 'ALL' = 'ALL') => {
getStatisticsOverview = (exchange: string | 'ALL' = 'ALL') => {
const url = new URL(`${this.statisticsUrl}/overview`);
url.searchParams.append('exchange', exchange);
@@ -67,7 +67,7 @@ class PriceFeed {
);
}
getTopPairStatistics = (exchange: Exchange | 'ALL' = 'ALL') => {
getTopPairStatistics = (exchange: string | 'ALL' = 'ALL') => {
const url = new URL(`${this.statisticsUrl}/top-pairs`);
url.searchParams.append('exchange', exchange);

View File

@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */
import type { BigNumber } from 'bignumber.js';
import type exchanges from './constants/exchanges.js';
import type subOrderStatuses from './constants/subOrderStatuses.js';
import type positionStatuses from './constants/positionStatuses.js';
import type { knownEnvs } from './config/schemas/index.js';
@@ -143,12 +142,12 @@ export type BalanceIssue = {
readonly fixes?: Fix[]
}
export type Exchange = typeof exchanges[number];
// export type Exchange = typeof exchanges[number];
export type OrderbookItem = {
price: string
amount: string
exchanges: Exchange[]
exchanges: string[]
vob: Array<{
side: 'BUY' | 'SELL'
pairName: string
@@ -156,7 +155,7 @@ export type OrderbookItem = {
}
export type SwapInfoAlternative = {
exchanges: Exchange[]
exchanges: string[]
path: string[]
marketAmountOut?: number | undefined
marketAmountIn?: number | undefined
@@ -175,7 +174,7 @@ export type SwapInfoBase = {
minAmountOut: number
path: string[]
exchanges?: Exchange[] | undefined
exchanges?: string[] | undefined
poolOptimal: boolean
price?: number | undefined