diff --git a/package-lock.json b/package-lock.json index 10d8fe5..6922d82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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==" } } } diff --git a/package.json b/package.json index 8ffaa3e..522503e 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "url": "https://github.com/orionprotocol/sdk/issues" }, "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", @@ -57,14 +57,14 @@ "webpack-cli": "^4.9.2" }, "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", @@ -72,8 +72,8 @@ "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" }, "homepage": "https://github.com/orionprotocol/sdk#readme", "files": [ diff --git a/src/services/OrionAggregator/schemas/aggregatedOrderbookSchema.ts b/src/services/OrionAggregator/schemas/aggregatedOrderbookSchema.ts index 8b781f8..0cd610b 100644 --- a/src/services/OrionAggregator/schemas/aggregatedOrderbookSchema.ts +++ b/src/services/OrionAggregator/schemas/aggregatedOrderbookSchema.ts @@ -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({ diff --git a/src/services/OrionAggregator/schemas/swapInfoSchema.ts b/src/services/OrionAggregator/schemas/swapInfoSchema.ts index 8ecabdc..649b57a 100644 --- a/src/services/OrionAggregator/schemas/swapInfoSchema.ts +++ b/src/services/OrionAggregator/schemas/swapInfoSchema.ts @@ -1,4 +1,5 @@ import { z } from 'zod'; +import { exchanges } from '../../../constants'; const swapInfoBase = z.object({ id: z.string(), @@ -15,13 +16,13 @@ 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.string().array(), + exchanges: z.array(z.enum(exchanges)), path: z.object({ units: z.object({ assetPair: z.string(), diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index b14f3c9..284445f 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -11,7 +11,7 @@ import { import UnsubscriptionType from './UnsubscriptionType'; import { SwapInfoByAmountIn, SwapInfoByAmountOut, SwapInfoBase, - FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange, SwapInfoAlternative, + FullOrder, OrderUpdate, AssetPairUpdate, OrderbookItem, Balance, Exchange, } from '../../../types'; import unsubscriptionDoneSchema from './schemas/unsubscriptionDoneSchema'; import assetPairConfigSchema from './schemas/assetPairConfigSchema'; @@ -300,20 +300,6 @@ class OrionAggregatorWS { // To implement break; case MessageType.SWAP_INFO: { - let alternatives: SwapInfoAlternative[] = []; - - if (json.as) { - 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, - })); - } - const baseSwapInfo: SwapInfoBase = { swapRequestId: json.S, assetIn: json.ai, @@ -322,8 +308,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, @@ -335,7 +321,15 @@ class OrionAggregatorWS { safePrice: json.oi.sp, }, }, - alternatives, + 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 diff --git a/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts b/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts index 9404c4a..715aeb7 100644 --- a/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/addressUpdateSchema.ts @@ -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 diff --git a/src/services/OrionAggregator/ws/schemas/swapInfoSchema.ts b/src/services/OrionAggregator/ws/schemas/swapInfoSchema.ts index 05cb2d3..4a4088f 100644 --- a/src/services/OrionAggregator/ws/schemas/swapInfoSchema.ts +++ b/src/services/OrionAggregator/ws/schemas/swapInfoSchema.ts @@ -24,7 +24,7 @@ const swapInfoSchemaBase = baseMessageSchema.extend({ sp: z.number(), // safe price (with safe deviation but without slippage) }).optional(), as: z.object({ // execution alternatives - e: z.string().array(), // exchanges + 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 diff --git a/src/types.ts b/src/types.ts index 2fb4a78..78b72ae 100644 --- a/src/types.ts +++ b/src/types.ts @@ -100,8 +100,8 @@ export type SwapInfoBase = { assetOut: string, amountIn: number, amountOut: number, - minAmounIn: number, - minAmounOut: number, + minAmountIn: number, + minAmountOut: number, path: string[], exchanges?: string[],