mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
Merge branch 'main' into OP-2812-show-order-route-path-and-benefits
# Conflicts: # package.json
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.15.15",
|
||||
"version": "0.15.21",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.15.15",
|
||||
"version": "0.15.21",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@ethersproject/abstract-signer": "^5.6.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.15.22-rc.2",
|
||||
"version": "0.15.22",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/esm/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
|
||||
@@ -15,4 +15,5 @@ export default [
|
||||
'CHERRYSWAP',
|
||||
'OKXSWAP',
|
||||
'CURVE',
|
||||
'CURVE_FACTORY',
|
||||
] as const;
|
||||
|
||||
26
src/constants/exchangesMap.ts
Normal file
26
src/constants/exchangesMap.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import exchanges from './exchanges';
|
||||
|
||||
const mapping: Record<
|
||||
typeof exchanges[number],
|
||||
string
|
||||
> = {
|
||||
// CEXes
|
||||
ASCENDEX: 'AscendEx',
|
||||
OKX: 'OKX',
|
||||
BINANCE: 'Binance',
|
||||
KUCOIN: 'KuCoin',
|
||||
ORION: 'Orion', // Internal
|
||||
|
||||
// DEXes
|
||||
SPOOKYSWAP: 'SpookySwap',
|
||||
PANCAKESWAP: 'PancakeSwap',
|
||||
UNISWAP: 'Uniswap',
|
||||
QUICKSWAP: 'QuickSwap',
|
||||
ORION_POOL: 'Orion Pool',
|
||||
CHERRYSWAP: 'CherrySwap',
|
||||
OKXSWAP: 'OKXSwap',
|
||||
CURVE: 'Curve',
|
||||
CURVE_FACTORY: 'Curve Factory',
|
||||
} as const;
|
||||
|
||||
export default mapping;
|
||||
@@ -3,6 +3,8 @@ export { default as orderStatuses } from './orderStatuses';
|
||||
export { default as orderTypes } from './orderTypes';
|
||||
export { default as subOrderStatuses } from './subOrderStatuses';
|
||||
export { default as networkCodes } from './networkCodes';
|
||||
export { default as exchanges } from './exchanges';
|
||||
export { default as exchangesMap } from './exchangesMap';
|
||||
|
||||
export * from './chains';
|
||||
export * from './precisions';
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { z } from 'zod';
|
||||
import exchanges from '../../../../constants/exchanges';
|
||||
import MessageType from '../MessageType';
|
||||
import baseMessageSchema from './baseMessageSchema';
|
||||
|
||||
export const orderBookItemSchema = z.tuple([
|
||||
z.string(), // price
|
||||
z.string(), // size
|
||||
z.array(z.string()), // exchanges
|
||||
z.array(
|
||||
z.enum(exchanges),
|
||||
), // exchanges
|
||||
z.array(z.tuple([
|
||||
z.enum(['SELL', 'BUY']), // side
|
||||
z.string(), // pairname
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import exchanges from '../../../../constants/exchanges';
|
||||
import MessageType from '../MessageType';
|
||||
import baseMessageSchema from './baseMessageSchema';
|
||||
|
||||
@@ -13,7 +14,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.string().array().optional(), // Exchanges
|
||||
e: z.enum(exchanges).array().optional(), // Exchanges
|
||||
p: z.number().optional(), // price
|
||||
mp: z.number().optional(), // market price
|
||||
oi: z.object({ // info about order equivalent to this swap
|
||||
|
||||
27
src/types.ts
27
src/types.ts
@@ -1,7 +1,8 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { z } from 'zod';
|
||||
import exchanges from './constants/exchanges';
|
||||
import orderStatuses from './constants/orderStatuses';
|
||||
import subOrderStatuses from './constants/subOrderStatuses';
|
||||
import { fullOrderSchema, orderUpdateSchema } from './services/OrionAggregator/ws/schemas/addressUpdateSchema';
|
||||
|
||||
export type OrderbookItem = {
|
||||
price: string,
|
||||
@@ -28,29 +29,9 @@ export type SubOrder = {
|
||||
side: 'BUY' | 'SELL',
|
||||
subOrdQty: number
|
||||
}
|
||||
export type FullOrder = {
|
||||
kind: 'full',
|
||||
id: string,
|
||||
settledAmount: number,
|
||||
feeAsset: string,
|
||||
fee: number,
|
||||
status: typeof orderStatuses[number],
|
||||
date: number,
|
||||
clientOrdId: string,
|
||||
type: 'BUY' | 'SELL',
|
||||
pair: string,
|
||||
amount: number,
|
||||
price: number,
|
||||
subOrders: SubOrder[]
|
||||
}
|
||||
export type FullOrder = z.infer<typeof fullOrderSchema>;
|
||||
|
||||
export type OrderUpdate = {
|
||||
kind: 'update',
|
||||
id: string,
|
||||
settledAmount: number,
|
||||
status: typeof orderStatuses[number],
|
||||
subOrders: SubOrder[]
|
||||
}
|
||||
export type OrderUpdate = z.infer<typeof orderUpdateSchema>;
|
||||
|
||||
export type Balance = {
|
||||
tradable: string,
|
||||
|
||||
17
src/utils/objectKeys.ts
Normal file
17
src/utils/objectKeys.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
|
||||
|
||||
/**
|
||||
A strongly-typed version of `Object.keys()`.
|
||||
This is useful since `Object.keys()` always returns an array of strings. This function returns a strongly-typed array of the keys of the given object.
|
||||
- [Explanation](https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript)
|
||||
- [TypeScript issues about this](https://github.com/microsoft/TypeScript/issues/45390)
|
||||
@example
|
||||
```
|
||||
const stronglyTypedItems = objectKeys({a: 1, b: 2, c: 3}); // => Array<'a' | 'b' | 'c'>
|
||||
const untypedItems = Object.keys(items); // => Array<string>
|
||||
```
|
||||
@category Improved builtin
|
||||
@category Type guard
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
export const objectKeys = Object.keys as <Type extends object>(value: Type) => ObjectKeys<Type>[];
|
||||
Reference in New Issue
Block a user