Merge branch 'main' into futures_list

# Conflicts:
#	package.json
#	src/services/OrionAggregator/ws/index.ts
#	src/types.ts
This commit is contained in:
Mikhail Gladchenko
2023-01-10 09:23:14 +00:00
8 changed files with 125 additions and 83 deletions

40
package-lock.json generated
View File

@@ -1,22 +1,22 @@
{
"name": "@orionprotocol/sdk",
"version": "0.15.21",
"version": "0.15.22",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.15.21",
"version": "0.15.22",
"license": "ISC",
"dependencies": {
"@ethersproject/abstract-signer": "^5.6.0",
"@ethersproject/providers": "^5.6.2",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@lukeed/csprng": "^1.0.1",
"@orionprotocol/contracts": "0.0.10",
"bignumber.js": "^9.0.2",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"ethers": "^5.6.2",
"ethers": "^5.7.2",
"isomorphic-unfetch": "^3.1.0",
"isomorphic-ws": "^5.0.0",
"just-clone": "^5.0.1",
@@ -24,11 +24,11 @@
"stream-browserify": "^3.0.0",
"tiny-invariant": "^1.2.0",
"uuid": "^8.3.2",
"ws": "^8.5.0",
"zod": "^3.17.3"
"ws": "^8.11.0",
"zod": "^3.20.2"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@types/node": "^18.11.15",
"@types/socket.io-client": "1.4.33",
"@types/uuid": "^8.3.4",
"@types/ws": "^8.5.3",
@@ -2343,9 +2343,9 @@
"dev": true
},
"node_modules/@types/node": {
"version": "18.11.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz",
"integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==",
"version": "18.11.15",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.15.tgz",
"integrity": "sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==",
"dev": true
},
"node_modules/@types/prettier": {
@@ -10694,9 +10694,9 @@
}
},
"node_modules/zod": {
"version": "3.19.1",
"resolved": "https://registry.npmjs.org/zod/-/zod-3.19.1.tgz",
"integrity": "sha512-LYjZsEDhCdYET9ikFu6dVPGp2YH9DegXjdJToSzD9rO6fy4qiRYFoyEYwps88OseJlPyl2NOe2iJuhEhL7IpEA==",
"version": "3.20.2",
"resolved": "https://registry.npmjs.org/zod/-/zod-3.20.2.tgz",
"integrity": "sha512-1MzNQdAvO+54H+EaK5YpyEy0T+Ejo/7YLHS93G3RnYWh5gaotGHwGeN/ZO687qEDU2y4CdStQYXVHIgrUl5UVQ==",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
@@ -12319,9 +12319,9 @@
"dev": true
},
"@types/node": {
"version": "18.11.9",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz",
"integrity": "sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==",
"version": "18.11.15",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.15.tgz",
"integrity": "sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==",
"dev": true
},
"@types/prettier": {
@@ -18611,9 +18611,9 @@
"dev": true
},
"zod": {
"version": "3.19.1",
"resolved": "https://registry.npmjs.org/zod/-/zod-3.19.1.tgz",
"integrity": "sha512-LYjZsEDhCdYET9ikFu6dVPGp2YH9DegXjdJToSzD9rO6fy4qiRYFoyEYwps88OseJlPyl2NOe2iJuhEhL7IpEA=="
"version": "3.20.2",
"resolved": "https://registry.npmjs.org/zod/-/zod-3.20.2.tgz",
"integrity": "sha512-1MzNQdAvO+54H+EaK5YpyEy0T+Ejo/7YLHS93G3RnYWh5gaotGHwGeN/ZO687qEDU2y4CdStQYXVHIgrUl5UVQ=="
}
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.16.0-rc.10",
"version": "0.16.0-rc.11",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

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

View File

@@ -1,4 +1,5 @@
import { z } from 'zod';
import { exchanges } from '../../../constants';
const swapInfoBase = z.object({
id: z.string(),
@@ -15,11 +16,25 @@ const swapInfoBase = z.object({
amount: z.number(),
safePrice: z.number(),
}).nullable(),
exchanges: z.array(z.string()),
exchanges: z.array(z.enum(exchanges)),
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)),
path: z.object({
units: z.object({
assetPair: z.string(),
action: z.string(),
}).array(),
}),
marketAmountOut: z.number().optional(),
marketAmountIn: z.number().optional(),
marketPrice: z.number(),
availableAmountIn: z.number().optional(),
availableAmountOut: z.number().optional(),
}).array(),
});
const swapInfoByAmountIn = swapInfoBase.extend({

View File

@@ -11,10 +11,11 @@ import {
import UnsubscriptionType from './UnsubscriptionType';
import {
SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase,
FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance,
AssetPairUpdate, OrderbookItem, Balance, Exchange, CFDBalance,
} from '../../../types';
import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema';
import assetPairConfigSchema from './schemas/assetPairConfigSchema';
import { fullOrderSchema, orderUpdateSchema } from './schemas/addressUpdateSchema';
import cfdAddressUpdateSchema from "./schemas/cfdAddressUpdateSchema";
// import errorSchema from './schemas/errorSchema';
@@ -72,7 +73,7 @@ type AddressUpdateUpdate = {
Balance
>
>,
order?: OrderUpdate | FullOrder
order?: z.infer<typeof orderUpdateSchema> | z.infer<typeof fullOrderSchema>
}
type AddressUpdateInitial = {
@@ -83,7 +84,7 @@ type AddressUpdateInitial = {
Balance
>
>,
orders?: FullOrder[] // The field is not defined if the user has no orders
orders?: z.infer<typeof fullOrderSchema>[] // The field is not defined if the user has no orders
}
type CfdAddressUpdateUpdate = {
@@ -337,8 +338,8 @@ class OrionAggregatorWS {
amountOut: json.o,
price: json.p,
marketPrice: json.mp,
minAmounOut: json.mao,
minAmounIn: json.ma,
minAmountOut: json.mao,
minAmountIn: json.ma,
path: json.ps,
exchanges: json.e,
poolOptimal: json.po,
@@ -350,6 +351,15 @@ class OrionAggregatorWS {
safePrice: json.oi.sp,
},
},
alternatives: json.as.map((item) => ({
exchanges: item.e,
path: item.ps,
marketAmountOut: item.mo,
marketAmountIn: item.mi,
marketPrice: item.mp,
availableAmountIn: item.aa,
availableAmountOut: item.aao,
})),
};
switch (json.k) { // kind
@@ -503,7 +513,7 @@ class OrionAggregatorWS {
switch (json.k) { // message kind
case 'i': { // initial
const fullOrders = json.o
? json.o.reduce<FullOrder[]>((prev, o) => {
? json.o.reduce<z.infer<typeof fullOrderSchema>[]>((prev, o) => {
prev.push(o);
return prev;
@@ -520,7 +530,7 @@ class OrionAggregatorWS {
}
break;
case 'u': { // update
let orderUpdate: OrderUpdate | FullOrder | undefined;
let orderUpdate: z.infer<typeof orderUpdateSchema> | z.infer<typeof fullOrderSchema> | undefined;
if (json.o) {
const firstOrder = json.o[0];
orderUpdate = firstOrder;

View File

@@ -1,4 +1,5 @@
import { z } from 'zod';
import { exchanges } from '../../../../constants';
import orderStatuses from '../../../../constants/orderStatuses';
import subOrderStatuses from '../../../../constants/subOrderStatuses';
import MessageType from '../MessageType';
@@ -21,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.string(), // exchange
e: z.enum(exchanges), // exchange
b: z.string(), // broker address
S: z.enum(subOrderStatuses), // status
o: z.boolean(), // internal only

View File

@@ -23,6 +23,15 @@ const swapInfoSchemaBase = baseMessageSchema.extend({
a: z.number(), // amount
sp: z.number(), // safe price (with safe deviation but without slippage)
}).optional(),
as: z.object({ // execution alternatives
e: z.enum(exchanges).array(), // exchanges
ps: z.string().array(), // path
mo: z.number().optional(), // market amount out
mi: z.number().optional(), // market amount in
mp: z.number(), // market price
aa: z.number().optional(), // available amount in
aao: z.number().optional(), // available amount out
}).array(),
});
const swapInfoSchemaByAmountIn = swapInfoSchemaBase.extend({

View File

@@ -1,18 +1,6 @@
import BigNumber from 'bignumber.js';
import { z } from 'zod';
import exchanges from './constants/exchanges';
import subOrderStatuses from './constants/subOrderStatuses';
import { fullOrderSchema, orderUpdateSchema } from './services/OrionAggregator/ws/schemas/addressUpdateSchema';
export type OrderbookItem = {
price: string,
amount: string,
exchanges: string[],
vob: {
side: 'BUY' | 'SELL',
pairName: string
}[]
}
export type AssetPairUpdate = {
minQty: number,
@@ -29,9 +17,6 @@ export type SubOrder = {
side: 'BUY' | 'SELL',
subOrdQty: number
}
export type FullOrder = z.infer<typeof fullOrderSchema>;
export type OrderUpdate = z.infer<typeof orderUpdateSchema>;
export type Balance = {
tradable: string,
@@ -114,43 +99,6 @@ export interface Pair {
vol24h: string;
}
export type SwapInfoBase = {
swapRequestId: string,
assetIn: string,
assetOut: string,
amountIn: number,
amountOut: number,
minAmounIn: number,
minAmounOut: number,
path: string[],
exchanges?: string[],
poolOptimal: boolean,
price?: number,
marketPrice?: number,
orderInfo?: {
pair: string,
side: 'BUY' | 'SELL',
amount: number,
safePrice: number,
}
}
export type SwapInfoByAmountIn = SwapInfoBase & {
kind: 'exactSpend',
availableAmountIn?: number,
marketAmountOut?: number,
}
export type SwapInfoByAmountOut = SwapInfoBase & {
kind: 'exactReceive',
marketAmountIn?: number,
availableAmountOut?: number,
}
export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut;
export enum SupportedChainId {
MAINNET = '1',
ROPSTEN = '3',
@@ -213,6 +161,64 @@ export type BalanceIssue = {
export type Exchange = typeof exchanges[number];
export type OrderbookItem = {
price: string,
amount: string,
exchanges: Exchange[],
vob: {
side: 'BUY' | 'SELL',
pairName: string
}[]
}
export type SwapInfoAlternative = {
exchanges: Exchange[],
path: string[],
marketAmountOut?: number,
marketAmountIn?: number,
marketPrice: number,
availableAmountIn?: number,
availableAmountOut?: number,
}
export type SwapInfoBase = {
swapRequestId: string,
assetIn: string,
assetOut: string,
amountIn: number,
amountOut: number,
minAmountIn: number,
minAmountOut: number,
path: string[],
exchanges?: Exchange[],
poolOptimal: boolean,
price?: number,
marketPrice?: number,
orderInfo?: {
pair: string,
side: 'BUY' | 'SELL',
amount: number,
safePrice: number,
},
alternatives: SwapInfoAlternative[],
}
export type SwapInfoByAmountIn = SwapInfoBase & {
kind: 'exactSpend',
availableAmountIn?: number,
marketAmountOut?: number,
}
export type SwapInfoByAmountOut = SwapInfoBase & {
kind: 'exactReceive',
marketAmountIn?: number,
availableAmountOut?: number,
}
export type SwapInfo = SwapInfoByAmountIn | SwapInfoByAmountOut;
export enum HistoryTransactionStatus {
PENDING = 'Pending',
DONE = 'Done',