From 4a20b90db0afa158ff687c2a1af35f6832468d4e Mon Sep 17 00:00:00 2001 From: lambdagit Date: Tue, 5 Sep 2023 09:56:45 +0300 Subject: [PATCH 01/57] cexPrices in PF --- .../PriceFeed/ws/PriceFeedSubscription.ts | 6 +++- .../PriceFeed/ws/priceFeedSubscriptions.ts | 1 + .../PriceFeed/ws/schemas/cexPricesSchema.ts | 31 +++++++++++++++++++ src/services/PriceFeed/ws/schemas/index.ts | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/services/PriceFeed/ws/schemas/cexPricesSchema.ts diff --git a/src/services/PriceFeed/ws/PriceFeedSubscription.ts b/src/services/PriceFeed/ws/PriceFeedSubscription.ts index 4969549..ad77939 100644 --- a/src/services/PriceFeed/ws/PriceFeedSubscription.ts +++ b/src/services/PriceFeed/ws/PriceFeedSubscription.ts @@ -2,7 +2,7 @@ import WebSocket from 'isomorphic-ws'; import { z } from 'zod'; import { v4 as uuidv4 } from 'uuid'; import priceFeedSubscriptions from './priceFeedSubscriptions.js'; -import { tickerInfoSchema, candleSchema } from './schemas/index.js'; +import { tickerInfoSchema, candleSchema, cexPricesSchema } from './schemas/index.js'; import priceSchema from './schemas/priceSchema.js'; import type { Json } from '../../../types.js'; import allTickersSchema from './schemas/allTickersSchema.js'; @@ -24,6 +24,10 @@ export const subscriptions = { schema: candleSchema, payload: true as const, }, + [priceFeedSubscriptions.CEX]: { + schema: cexPricesSchema, + payload: false as const, + }, }; export type SubscriptionType = keyof typeof subscriptions; diff --git a/src/services/PriceFeed/ws/priceFeedSubscriptions.ts b/src/services/PriceFeed/ws/priceFeedSubscriptions.ts index 847700d..cdd7d88 100644 --- a/src/services/PriceFeed/ws/priceFeedSubscriptions.ts +++ b/src/services/PriceFeed/ws/priceFeedSubscriptions.ts @@ -3,6 +3,7 @@ const priceFeedSubscriptions = { ALL_TICKERS: 'allTickers', LAST_PRICE: 'lastPrice', CANDLE: 'candle', + CEX: 'cexPrices' } as const; export default priceFeedSubscriptions; diff --git a/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts b/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts new file mode 100644 index 0000000..8a895cb --- /dev/null +++ b/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts @@ -0,0 +1,31 @@ +import { z } from 'zod'; + +const cexPriceTickerInfoSchema = z.tuple([ + z.string(), // pair name + z.string(), // lastPrice +]).transform(([pairName, lastPrice]) => ({ + pairName:pairName.toUpperCase(), + lastPrice, +})); + +type CEXPriceTickerInfo = z.infer + +const cexPricesSchema = z.unknown().array() +.transform((tickers) => { + const data = [...tickers]; + data.shift(); + const parsedData = cexPriceTickerInfoSchema.array().parse(data); + return parsedData.reduce< + Partial< + Record< + string, + CEXPriceTickerInfo + > + > + >((prev, pairData) => ({ + ...prev, + [pairData.pairName]: pairData, + }), {}); +}); + +export default cexPricesSchema; \ No newline at end of file diff --git a/src/services/PriceFeed/ws/schemas/index.ts b/src/services/PriceFeed/ws/schemas/index.ts index 4ca9486..2e55e91 100644 --- a/src/services/PriceFeed/ws/schemas/index.ts +++ b/src/services/PriceFeed/ws/schemas/index.ts @@ -2,3 +2,4 @@ export { default as tickerInfoSchema } from './tickerInfoSchema.js'; export { default as candleSchema } from './candleSchema.js'; export { default as priceSchema } from './priceSchema.js'; export { default as allTickersSchema } from './allTickersSchema.js'; +export { default as cexPricesSchema } from './cexPricesSchema.js'; From 24cd59dc26fd121db2af489e486a17ec4dfdd14b Mon Sep 17 00:00:00 2001 From: lambdagit Date: Tue, 5 Sep 2023 11:16:01 +0300 Subject: [PATCH 02/57] rc-ver (0.19.80-rc) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 217796d..2bf33bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.79", + "version": "0.19.80-rc", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 9ac991ec6c63613896f712c921471d57d532282e Mon Sep 17 00:00:00 2001 From: lambdagit Date: Tue, 5 Sep 2023 16:23:14 +0300 Subject: [PATCH 03/57] fix cexPrices schema & ver up --- package.json | 2 +- src/services/PriceFeed/ws/schemas/cexPricesSchema.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2bf33bb..2606b86 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.80-rc", + "version": "0.19.80-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts b/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts index 8a895cb..a12dfa6 100644 --- a/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts +++ b/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts @@ -2,7 +2,7 @@ import { z } from 'zod'; const cexPriceTickerInfoSchema = z.tuple([ z.string(), // pair name - z.string(), // lastPrice + z.number(), // lastPrice ]).transform(([pairName, lastPrice]) => ({ pairName:pairName.toUpperCase(), lastPrice, From a4e2f5cb31921f7ccff95d5dd9297d68a05e0b70 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Tue, 27 Feb 2024 09:17:16 +0000 Subject: [PATCH 04/57] feat: added endpoint for receiving gas limits from OB --- package.json | 2 +- src/services/BlockchainService/index.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 78c11af..c2244ed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.60", + "version": "0.20.61-rc100", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/BlockchainService/index.ts b/src/services/BlockchainService/index.ts index 53ac157..0022218 100644 --- a/src/services/BlockchainService/index.ts +++ b/src/services/BlockchainService/index.ts @@ -111,6 +111,7 @@ class BlockchainService { this.getBlockNumber = this.getBlockNumber.bind(this); this.getRedeemOrderBySecretHash = this.getRedeemOrderBySecretHash.bind(this); this.claimOrder = this.claimOrder.bind(this); + this.getGasLimits = this.getGasLimits.bind(this); } get basicAuthHeaders() { @@ -484,6 +485,12 @@ class BlockchainService { body: JSON.stringify(secretHashes), }, ); + + getGasLimits = () => fetchWithValidation( + `${this.apiUrl}api/baseLimits`, + z.record(z.number()), + { headers: this.basicAuthHeaders } + ); } export * as schemas from './schemas/index.js'; From cbecf51c251aff73308ea60eb803322b4b7a2169 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Tue, 27 Feb 2024 11:49:37 +0000 Subject: [PATCH 05/57] feat: small fix --- package.json | 2 +- src/services/BlockchainService/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c2244ed..6fea188 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.61-rc100", + "version": "0.20.61-rc101", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/BlockchainService/index.ts b/src/services/BlockchainService/index.ts index 0022218..a64a358 100644 --- a/src/services/BlockchainService/index.ts +++ b/src/services/BlockchainService/index.ts @@ -487,7 +487,7 @@ class BlockchainService { ); getGasLimits = () => fetchWithValidation( - `${this.apiUrl}api/baseLimits`, + `${this.apiUrl}/api/baseLimits`, z.record(z.number()), { headers: this.basicAuthHeaders } ); From c67b35343902b4ce62e33dfbfb9b79dd62098730 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Fri, 1 Mar 2024 16:09:07 +0000 Subject: [PATCH 06/57] feat: added Line and inEVM mainnet chains --- src/config/chains.json | 26 +++++++++++++ src/config/envs.json | 72 +++++++++++++++++++++++++++++++++++ src/constants/chains.ts | 2 + src/constants/networkCodes.ts | 2 +- src/types.ts | 2 + 5 files changed, 103 insertions(+), 1 deletion(-) diff --git a/src/config/chains.json b/src/config/chains.json index 275b577..0a97c1d 100644 --- a/src/config/chains.json +++ b/src/config/chains.json @@ -192,5 +192,31 @@ "WETH": "", "curveRegistry": "" } + }, + "2525": { + "chainId": "2525", + "label": "inEVM", + "shortName": "inEVM", + "code": "inevm", + "baseCurrencyName": "INJ", + "rpc": "https://inevm.calderachain.xyz/http/", + "explorer": "https://explorer.injective.network/", + "contracts": { + "WETH": "0x4C3A213bd5e8c4BD70a8396d6F3C8302571598Cd", + "curveRegistry": "" + } + }, + "59144": { + "chainId": "59144", + "label": "Linea", + "shortName": "Linea", + "code": "linea", + "baseCurrencyName": "ETH", + "rpc": "https://rpc.linea.build/", + "explorer": "https://lineascan.build/", + "contracts": { + "WETH": "0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f", + "curveRegistry": "" + } } } diff --git a/src/config/envs.json b/src/config/envs.json index d8ba4d2..41094b3 100644 --- a/src/config/envs.json +++ b/src/config/envs.json @@ -129,6 +129,42 @@ "http": "/orion-indexer/" } } + }, + "2525": { + "api": "https://trade.orion.xyz/inevm-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } + }, + "59144": { + "api": "https://trade.orion.xyz/linea-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } } } }, @@ -376,6 +412,42 @@ "http": "/orion-indexer/" } } + }, + "2525": { + "api": "https://trade.orion.xyz/inevm-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } + }, + "59144": { + "api": "https://trade.orion.xyz/linea-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } } } }, diff --git a/src/constants/chains.ts b/src/constants/chains.ts index 74135ed..0e0b025 100644 --- a/src/constants/chains.ts +++ b/src/constants/chains.ts @@ -17,4 +17,6 @@ export const productionChains = [ SupportedChainId.OKC, SupportedChainId.ARBITRUM, SupportedChainId.OPBNB, + SupportedChainId.INEVM, + SupportedChainId.LINEA, ]; diff --git a/src/constants/networkCodes.ts b/src/constants/networkCodes.ts index d04ac04..74b0d0f 100644 --- a/src/constants/networkCodes.ts +++ b/src/constants/networkCodes.ts @@ -1 +1 @@ -export default ['ftm', 'bsc', 'eth', 'polygon', 'okc', 'arb', 'drip', 'opbnb'] as const; +export default ['ftm', 'bsc', 'eth', 'polygon', 'okc', 'arb', 'drip', 'opbnb', 'inevm', 'linea'] as const; diff --git a/src/types.ts b/src/types.ts index b5f0330..5a96d83 100644 --- a/src/types.ts +++ b/src/types.ts @@ -88,6 +88,8 @@ export enum SupportedChainId { POLYGON = '137', OKC = '66', OPBNB = '204', + INEVM = '2525', + LINEA = '59144', POLYGON_TESTNET = '80001', FANTOM_TESTNET = '4002', From 3c04a0fee63bbd4cb8acf8692408e7e0a132398a Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Fri, 1 Mar 2024 16:09:53 +0000 Subject: [PATCH 07/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 78c11af..6d978ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.60", + "version": "0.20.61", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 274807edbd69aac305ce0b2264f979e988cb9556 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Mon, 4 Mar 2024 14:52:32 +0300 Subject: [PATCH 08/57] update referralDataSchema --- package-lock.json | 4 ++-- package.json | 2 +- src/services/BlockchainService/schemas/referralDataSchema.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7353eeb..cbf62aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.60", + "version": "0.20.62", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.60", + "version": "0.20.62", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 6d978ba..a5cc917 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.61", + "version": "0.20.62", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/BlockchainService/schemas/referralDataSchema.ts b/src/services/BlockchainService/schemas/referralDataSchema.ts index 115e2a8..4b4674a 100644 --- a/src/services/BlockchainService/schemas/referralDataSchema.ts +++ b/src/services/BlockchainService/schemas/referralDataSchema.ts @@ -1,6 +1,6 @@ -import { z } from "zod"; +import { z } from 'zod'; export const referralDataSchema = z.object({ - referer: z.string(), + referer: z.string().nullable(), isReferral: z.boolean(), }); From 8b08802f556cea46871c5d723822bc70c4e5d69a Mon Sep 17 00:00:00 2001 From: Dmitry <35160421+TheJuze@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:22:55 +0300 Subject: [PATCH 09/57] add opbnb curveRegistry to chains config (#245) --- package-lock.json | 4 ++-- package.json | 2 +- src/config/chains.json | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index cbf62aa..5a4864d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.62", + "version": "0.20.63-rc0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.62", + "version": "0.20.63-rc0", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index a5cc917..f439b68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.62", + "version": "0.20.63-rc0", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/config/chains.json b/src/config/chains.json index 0a97c1d..bed5a5d 100644 --- a/src/config/chains.json +++ b/src/config/chains.json @@ -47,7 +47,8 @@ "rpc": "https://opbnb-mainnet-rpc.bnbchain.org", "baseCurrencyName": "BNB", "contracts": { - "WETH": "0x4200000000000000000000000000000000000006" + "WETH": "0x4200000000000000000000000000000000000006", + "curveRegistry": "" } }, "3": { From 0ba61a803549febbfa2136bea9a62e80cce8523e Mon Sep 17 00:00:00 2001 From: TheJuze Date: Wed, 6 Mar 2024 11:23:36 +0300 Subject: [PATCH 10/57] bump v --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5a4864d..bbd524e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.63-rc0", + "version": "0.20.63", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.63-rc0", + "version": "0.20.63", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index f439b68..03a3a32 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.63-rc0", + "version": "0.20.63", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From d26a21e526a2a69f248190d5789d713668ec08ca Mon Sep 17 00:00:00 2001 From: Dmitry <35160421+TheJuze@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:50:22 +0300 Subject: [PATCH 11/57] add opbnb network code (#244) --- src/constants/uppercasedNetworkCodes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/uppercasedNetworkCodes.ts b/src/constants/uppercasedNetworkCodes.ts index 8dc00e3..711241f 100644 --- a/src/constants/uppercasedNetworkCodes.ts +++ b/src/constants/uppercasedNetworkCodes.ts @@ -1 +1 @@ -export default ['FTM', 'BSC', 'ETH', 'POLYGON', 'OKC', 'ARB'] as const; +export default ['FTM', 'BSC', 'ETH', 'POLYGON', 'OKC', 'ARB', 'OPBNB'] as const; From 0faccd34c4dffb9a971041146fb7ddeb57ecfcf6 Mon Sep 17 00:00:00 2001 From: Dmitry <35160421+TheJuze@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:55:34 +0300 Subject: [PATCH 12/57] add inevm, linea to uppercasedNetworkCodes.ts (#246) --- src/constants/uppercasedNetworkCodes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/uppercasedNetworkCodes.ts b/src/constants/uppercasedNetworkCodes.ts index 711241f..f3c9515 100644 --- a/src/constants/uppercasedNetworkCodes.ts +++ b/src/constants/uppercasedNetworkCodes.ts @@ -1 +1 @@ -export default ['FTM', 'BSC', 'ETH', 'POLYGON', 'OKC', 'ARB', 'OPBNB'] as const; +export default ['FTM', 'BSC', 'ETH', 'POLYGON', 'OKC', 'ARB', 'OPBNB', 'INEVM', 'LINEA'] as const; From 4e7669bc2c200a45d56d6dd58737a9b21bebe3bc Mon Sep 17 00:00:00 2001 From: TheJuze Date: Wed, 6 Mar 2024 11:56:15 +0300 Subject: [PATCH 13/57] bump v --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index bbd524e..55fdb08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.63", + "version": "0.20.64", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.63", + "version": "0.20.64", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 03a3a32..4ab3e88 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.63", + "version": "0.20.64", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 184f66bf1704dd9b26b39216eb58e8995b62a08d Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Wed, 6 Mar 2024 11:39:51 +0000 Subject: [PATCH 14/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d54d0d..4c77189 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.61-rc102", + "version": "0.20.65", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 982998ea9b99ba33f9b906386793790ef2d71685 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Thu, 7 Mar 2024 16:18:28 +0300 Subject: [PATCH 15/57] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 55fdb08..a16dee8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.64", + "version": "0.20.66", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.64", + "version": "0.20.66", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index c092461..e4f1a72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.66-rc1", + "version": "0.20.66", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From beead064acfa2c46cc4072613a681831c091d5cb Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Thu, 7 Mar 2024 16:26:20 +0300 Subject: [PATCH 16/57] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a16dee8..dc8af09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.66", + "version": "0.20.67", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.66", + "version": "0.20.67", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index e4f1a72..bb563f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.66", + "version": "0.20.67", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 6f5b537c476803338bdef98f18ad026eb041ec17 Mon Sep 17 00:00:00 2001 From: KS Date: Sun, 10 Mar 2024 20:28:00 +0300 Subject: [PATCH 17/57] added PMM --- README.md | 93 ++++++++++++++++ jest.config.js | 2 +- package-lock.json | 40 +++++-- package.json | 4 +- src/Unit/Pmm/abi/OrionRFQ.ts | 63 +++++++++++ src/Unit/Pmm/index.ts | 78 +++++++++++++ src/Unit/Pmm/schemas/order.ts | 18 +++ src/Unit/index.ts | 4 + src/services/Aggregator/index.ts | 103 ++++++++++++++++++ src/services/BlockchainService/index.ts | 4 + .../BlockchainService/schemas/index.ts | 1 + .../BlockchainService/schemas/pmmSchema.ts | 7 ++ tsconfig.json | 1 + 13 files changed, 408 insertions(+), 10 deletions(-) create mode 100644 src/Unit/Pmm/abi/OrionRFQ.ts create mode 100644 src/Unit/Pmm/index.ts create mode 100644 src/Unit/Pmm/schemas/order.ts create mode 100644 src/services/BlockchainService/schemas/pmmSchema.ts diff --git a/README.md b/README.md index 05438c5..0d2fa18 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Orion’s SDK is free to use and does not require an API key or registration. Re - [Using contracts](#using-contracts) - [Utils](#utils) - [Parsing trade transactions](#parsing-trade-transactions) +- [PMM](#pmm) ## Install @@ -719,3 +720,95 @@ switch (data.type) { break; } ``` +## PMM + +PMM allows institutional traders to request RFQ orders from Orion and then fill them. + +RFQ order allows trader to fix the price for a certain time interval (up to 90 seconds, including the order settlement time interval on blockchain). + +After receiving the order (if the price of the order is satisfactory to the trader) the trader must immediately submit the transaction on behalf of his address or contract. + +For requesting RFQ-orders institutional trader should have API key and secret key. + +Please take look at code example below. + +Simple example: + +```ts +import Orion from '../Orion'; +import {Wallet} from "ethers"; +import {simpleFetch} from "simple-typed-fetch"; + +(async() => { + const apiKey = '958153f1-b8b9-3ec4-84eb-2147429105d9'; + const secretKey = 'secretKey'; + const yourWalletPrivateKey = '0x...'; + + const orion = new Orion('testing'); // Leave empty for test environment + const bsc = orion.getUnit('bsc'); + const wallet = new Wallet(yourWalletPrivateKey, bsc.provider); + + // This can be done only once, no need to repeat this every time + // assetToDecimals can also be useful for calculations + const {assetToAddress, assetToDecimals} = await simpleFetch(bsc.blockchainService.getInfo)(); + + // Also you need to allow FRQ contract to spend tokens from your address. + // This also can be done only once. + await bsc.pmm.setAllowance(assetToAddress.ORN, '1000000000000000000', wallet); + + const rfqOrder = await bsc.aggregator.RFQOrder( + assetToAddress.ORN, // Spending asset + assetToAddress.USDT, // Receiving asset + '10000000000', // Amount in "satoshi" of spending asset + apiKey, + secretKey, + '0x61Eed69c0d112C690fD6f44bB621357B89fBE67F' // Can be any address, ignored for now + ); + + if(!rfqOrder.success) { + console.log(rfqOrder.error); + return; + } + + // ... here you can check order prices, etc. + + // Send order to blockchain + try { + const tx = await bsc.pmm.FillRFQOrder(rfqOrder, wallet); + + // If tx.hash is not empty - then transaction was sent to blockchain + console.log(tx.hash); + } + catch(err) { + console.log(err); + } +})(); +``` + +RFQ order response example description (`rfqOrder` from example above): + +```json + { + quotation: { + info: '31545611720730315633520017429', + makerAsset: '0xcb2951e90d8dcf16e1fa84ac0c83f48906d6a744', + takerAsset: '0xf223eca06261145b3287a0fefd8cfad371c7eb34', + maker: '0x1ff516e5ce789085cff86d37fc27747df852a80a', + allowedSender: '0x0000000000000000000000000000000000000000', + makingAmount: '193596929', + takingAmount: '10000000000' + }, + signature: '0x8a2f9140a3c3a5734eda763a19c54c5ac909d8a03db37d9804af9115641fd1d35896b66ca6e136c1c89e0478fb7382a4b875d0f74529c1e83601f9383d310dde1b', + success: true, + error: '' + } +``` + + +* info - can be ignored +* makerAsset - your RECEIVING asset (what you expect to receive from contract, in this case USDT) +* takerAsset - your SPENDING asset (what you're giving to contract, in this case ORN) +* maker - can be ignored for now; +* allowedSender - can be ignored for now; +* makingAmount - how much you will RECEIVE (in receiving asset's precision) +* takingAmount - how much you should SPEND (in spending asset's precision) \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index 8fddee8..964bf83 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,7 +13,7 @@ export default { 'ts-jest', { isolatedModules: true, - // tsconfig: 'tsconfig.json', + // tsconfig: 'tsconfig.json', useESM: true, }, ], diff --git a/package-lock.json b/package-lock.json index 55fdb08..f7f2955 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.64", + "version": "0.20.66-rc", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.64", + "version": "0.20.66-rc", "hasInstallScript": true, "license": "ISC", "dependencies": { @@ -18,6 +18,7 @@ "bignumber.js": "^9.1.1", "bson-objectid": "^2.0.4", "buffer": "^6.0.3", + "crypto-js": "^4.2.0", "ethers": "^6.7.1", "express": "^4.18.2", "isomorphic-ws": "^5.0.0", @@ -39,6 +40,7 @@ "@babel/plugin-syntax-import-assertions": "^7.20.0", "@tsconfig/esm": "^1.0.4", "@tsconfig/strictest": "^2.0.1", + "@types/crypto-js": "^4.2.2", "@types/express": "^4.17.17", "@types/jest": "^29.5.1", "@types/node": "^20.5.1", @@ -2545,6 +2547,12 @@ "@types/node": "*" } }, + "node_modules/@types/crypto-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", + "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==", + "dev": true + }, "node_modules/@types/eslint": { "version": "8.44.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.2.tgz", @@ -2638,9 +2646,9 @@ } }, "node_modules/@types/jest": { - "version": "29.5.4", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.4.tgz", - "integrity": "sha512-PhglGmhWeD46FYOVLt3X7TiWjzwuVGW9wG/4qocPevXMjCmrIc5b6db9WjeGE4QYVpUAWMDv3v0IiBwObY289A==", + "version": "29.5.12", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.12.tgz", + "integrity": "sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==", "dev": true, "dependencies": { "expect": "^29.0.0", @@ -4397,6 +4405,11 @@ "node": ">= 8" } }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/data-uri-to-buffer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", @@ -13604,6 +13617,12 @@ "@types/node": "*" } }, + "@types/crypto-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", + "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==", + "dev": true + }, "@types/eslint": { "version": "8.44.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.2.tgz", @@ -13697,9 +13716,9 @@ } }, "@types/jest": { - "version": "29.5.4", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.4.tgz", - "integrity": "sha512-PhglGmhWeD46FYOVLt3X7TiWjzwuVGW9wG/4qocPevXMjCmrIc5b6db9WjeGE4QYVpUAWMDv3v0IiBwObY289A==", + "version": "29.5.12", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-29.5.12.tgz", + "integrity": "sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==", "dev": true, "requires": { "expect": "^29.0.0", @@ -15019,6 +15038,11 @@ "which": "^2.0.1" } }, + "crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "data-uri-to-buffer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", diff --git a/package.json b/package.json index 4c77189..5788d98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.65", + "version": "0.20.66-rc", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", @@ -57,6 +57,7 @@ "@babel/plugin-syntax-import-assertions": "^7.20.0", "@tsconfig/esm": "^1.0.4", "@tsconfig/strictest": "^2.0.1", + "@types/crypto-js": "^4.2.2", "@types/express": "^4.17.17", "@types/jest": "^29.5.1", "@types/node": "^20.5.1", @@ -93,6 +94,7 @@ "bignumber.js": "^9.1.1", "bson-objectid": "^2.0.4", "buffer": "^6.0.3", + "crypto-js": "^4.2.0", "ethers": "^6.7.1", "express": "^4.18.2", "isomorphic-ws": "^5.0.0", diff --git a/src/Unit/Pmm/abi/OrionRFQ.ts b/src/Unit/Pmm/abi/OrionRFQ.ts new file mode 100644 index 0000000..13d1761 --- /dev/null +++ b/src/Unit/Pmm/abi/OrionRFQ.ts @@ -0,0 +1,63 @@ +export const orionRFQContractABI = + [ + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "info", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + } + ], + "internalType": "struct OrderRFQLib.OrderRFQ", + "name": "order", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "flagsAndAmount", + "type": "uint256" + } + ], + "name": "fillOrderRFQ", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ]; diff --git a/src/Unit/Pmm/index.ts b/src/Unit/Pmm/index.ts new file mode 100644 index 0000000..aa35962 --- /dev/null +++ b/src/Unit/Pmm/index.ts @@ -0,0 +1,78 @@ +import type Unit from '../index'; +import { z } from 'zod'; +import {pmmOrderSchema} from "./schemas/order"; +import {simpleFetch} from "simple-typed-fetch"; +import {ethers, Wallet} from "ethers"; +import {BigNumber} from "bignumber.js"; +import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.js'; +import {orionRFQContractABI} from "./abi/OrionRFQ"; + +export default class Pmm { + private readonly unit: Unit; + private readonly provider: ethers.Provider; + private contractAddress: string; + + constructor(unit: Unit) { + this.unit = unit; + this.provider = unit.provider; + this.contractAddress = ''; + } + + private isInitialized() : boolean { + return this.contractAddress !== ''; + } + + public async init() { + if(this.isInitialized()) + return; + const { orionPMMRouterContractAddress } = await simpleFetch(this.unit.blockchainService.getPmmInfo)(); + this.contractAddress = orionPMMRouterContractAddress; + } + + public async setAllowance(token: string, amount: string, signer: Wallet) { + await this.init(); + + const bnTargetAmount = new BigNumber(amount); + const walletAddress = await signer.getAddress(); + + const tokenContract = ERC20__factory + .connect(token, this.unit.provider); + + const unsignedApproveTx = await tokenContract + .approve.populateTransaction( + this.contractAddress, + bnTargetAmount.toString() + ); + const nonce = await this.provider.getTransactionCount(walletAddress, 'pending'); + const { gasPrice, maxFeePerGas } = await this.provider.getFeeData(); + const network = await this.provider.getNetwork(); + + if (gasPrice !== null) + unsignedApproveTx.gasPrice = gasPrice; + + if(maxFeePerGas !== null) + unsignedApproveTx.maxFeePerGas = maxFeePerGas; + + unsignedApproveTx.chainId = network.chainId; + unsignedApproveTx.nonce = nonce; + unsignedApproveTx.from = walletAddress; + const gasLimit = await this.provider.estimateGas(unsignedApproveTx); + unsignedApproveTx.gasLimit = gasLimit; + + const signedTx = await signer.signTransaction(unsignedApproveTx); + const txResponse = await this.provider.broadcastTransaction(signedTx); + await txResponse.wait(); + } + + public async FillRFQOrder(order : z.infer, signer: Wallet) { + await this.init(); + + if(!order.success) + throw Error("Invalid order provided"); + + const contract = new ethers.Contract(this.contractAddress, orionRFQContractABI, signer); + + // @ts-ignore + return contract.fillOrderRFQ(order.quotation, order.signature, BigInt(0)); + } +} \ No newline at end of file diff --git a/src/Unit/Pmm/schemas/order.ts b/src/Unit/Pmm/schemas/order.ts new file mode 100644 index 0000000..2651660 --- /dev/null +++ b/src/Unit/Pmm/schemas/order.ts @@ -0,0 +1,18 @@ +import {z} from "zod"; + +export const pmmOrderQuotationSchema = z.object({ + info: z.string().default(''), + makerAsset: z.string().default(''), + takerAsset: z.string().default(''), + maker: z.string().default(''), + allowedSender: z.string().default(''), + makingAmount: z.string().default(''), + takingAmount: z.string().default(''), +}); + +export const pmmOrderSchema = z.object({ + quotation: pmmOrderQuotationSchema.default({}), + signature: z.string().default(''), + success: z.boolean().default(false), + error: z.string().default(''), +}); \ No newline at end of file diff --git a/src/Unit/index.ts b/src/Unit/index.ts index 33badc5..85d7052 100644 --- a/src/Unit/index.ts +++ b/src/Unit/index.ts @@ -11,6 +11,7 @@ import Exchange from './Exchange/index.js'; import { chains, envs } from '../config'; import type { networkCodes } from '../constants/index.js'; import { IndexerService } from '../services/Indexer'; +import Pmm from "./Pmm"; type KnownConfig = { env: KnownEnv @@ -30,6 +31,8 @@ export default class Unit { public readonly aggregator: Aggregator; + public readonly pmm: Pmm; + public readonly priceFeed: PriceFeed; public readonly exchange: Exchange; @@ -122,5 +125,6 @@ export default class Unit { this.config.basicAuth ); this.exchange = new Exchange(this); + this.pmm = new Pmm(this); } } diff --git a/src/services/Aggregator/index.ts b/src/services/Aggregator/index.ts index 64cdc45..f04e4c5 100644 --- a/src/services/Aggregator/index.ts +++ b/src/services/Aggregator/index.ts @@ -19,6 +19,9 @@ import httpToWS from '../../utils/httpToWS.js'; import { ethers } from 'ethers'; import orderSchema from './schemas/orderSchema.js'; import { fetchWithValidation } from 'simple-typed-fetch'; +import hmacSHA256 from "crypto-js/hmac-sha256"; +import Hex from "crypto-js/enc-hex"; +import {pmmOrderSchema} from "../../Unit/Pmm/schemas/order"; class Aggregator { private readonly apiUrl: string; @@ -369,6 +372,106 @@ class Aggregator { url.searchParams.append('limit', limit.toString()); return fetchWithValidation(url.toString(), atomicSwapHistorySchema, { headers: this.basicAuthHeaders }); }; + + + private encode_utf8(s : string) { + return unescape(encodeURIComponent(s)); + } + + private sign(message : string, key: string) { + return hmacSHA256( + this.encode_utf8(message), + this.encode_utf8(key) + ).toString(Hex); + } + + private generateHeaders(body : any, method : string, path : string, timestamp : number, apiKey : string, secretKey : string) { + const sortedBody = Object.keys(body) + .sort() + .map((key) => ( + `${key}=${body[key]}` + )).join('&'); + + const payload = timestamp + method.toUpperCase() + path + sortedBody; + + const signature = this.sign(payload, secretKey); + + const httpOptions = { + headers: { + 'API-KEY': apiKey, + 'ACCESS-TIMESTAMP': timestamp.toString(), + 'ACCESS-SIGN': signature + } + }; + return httpOptions; + } + + public async RFQOrder( + tokenFrom: string, + tokenTo: string, + fromTokenAmount: string, + apiKey: string, // + secretKey: string, + wallet: string + ) : Promise> { + + // Making the order structure + const + path = '/rfq' + , url = `${this.apiUrl}/api/v1/integration/pmm`+path + , headers = { + 'Content-Type': 'application/json', + } + , data = { + "baseToken":tokenFrom, // USDT + "quoteToken":tokenTo, // ORN + "amount": fromTokenAmount, // 100 + "taker": wallet, + "feeBps": 0 + } + , method = 'POST' + , timestamp = Date.now() + , signatureHeaders = this.generateHeaders(data, method, path, timestamp, apiKey, secretKey) + , compiledHeaders = {...headers, ...signatureHeaders.headers, } + , body = JSON.stringify(data) + ; + + + let res = pmmOrderSchema.parse({}); + + try { + const result = await fetch(url,{ + headers: compiledHeaders, + method, + body + }); + + const json = await result.json(); + const parseResult = pmmOrderSchema.safeParse(json); + + if(!parseResult.success) { + // Try to parse error answer + const errorSchema = z.object({error: z.object({code: z.number(), reason: z.string()})}); + + const errorParseResult = errorSchema.safeParse(json); + + if(!errorParseResult.success) + throw Error(`Unrecognized answer from aggregator: ${json}`); + + throw Error(errorParseResult.data.error.reason); + } + + res.quotation = parseResult.data.quotation; + res.signature = parseResult.data.signature; + res.error = ''; + res.success = true; + // return result; + } + catch(err) { + res.error = `${err}`; + } + return res; + } } export * as schemas from './schemas/index.js'; export * as ws from './ws/index.js'; diff --git a/src/services/BlockchainService/index.ts b/src/services/BlockchainService/index.ts index a64a358..16d5e59 100644 --- a/src/services/BlockchainService/index.ts +++ b/src/services/BlockchainService/index.ts @@ -12,6 +12,7 @@ import { pairStatusSchema, pricesWithQuoteAssetSchema, referralDataSchema, + pmmSchema } from './schemas/index.js'; import type redeemOrderSchema from '../Aggregator/schemas/redeemOrderSchema.js'; import { sourceAtomicHistorySchema, targetAtomicHistorySchema } from './schemas/atomicHistorySchema.js'; @@ -82,6 +83,7 @@ class BlockchainService { this.getAuthToken = this.getAuthToken.bind(this); this.getCirculatingSupply = this.getCirculatingSupply.bind(this); this.getInfo = this.getInfo.bind(this); + this.getPmmInfo = this.getPmmInfo.bind(this); this.getPoolsConfig = this.getPoolsConfig.bind(this); this.getPoolsInfo = this.getPoolsInfo.bind(this); this.getPoolsLpAndStaked = this.getPoolsLpAndStaked.bind(this); @@ -176,6 +178,8 @@ class BlockchainService { getInfo = () => fetchWithValidation(`${this.apiUrl}/api/info`, infoSchema); + getPmmInfo = () => fetchWithValidation(`${this.apiUrl}/api/pmm-info`, pmmSchema); + getPoolsConfig = () => fetchWithValidation( `${this.apiUrl}/api/pools/config`, poolsConfigSchema, diff --git a/src/services/BlockchainService/schemas/index.ts b/src/services/BlockchainService/schemas/index.ts index 5f76ca8..886cb3a 100644 --- a/src/services/BlockchainService/schemas/index.ts +++ b/src/services/BlockchainService/schemas/index.ts @@ -13,5 +13,6 @@ export { default as poolsLpAndStakedSchema } from './poolsLpAndStakedSchema.js'; export { default as userVotesSchema } from './userVotesSchema.js'; export { default as userEarnedSchema } from './userEarnedSchema.js'; export { default as poolsV3InfoSchema } from './poolsV3InfoSchema.js'; +export { default as pmmSchema } from './pmmSchema.js'; export { pricesWithQuoteAssetSchema } from './pricesWithQuoteAssetSchema.js'; export { referralDataSchema } from './referralDataSchema.js'; \ No newline at end of file diff --git a/src/services/BlockchainService/schemas/pmmSchema.ts b/src/services/BlockchainService/schemas/pmmSchema.ts new file mode 100644 index 0000000..e56673b --- /dev/null +++ b/src/services/BlockchainService/schemas/pmmSchema.ts @@ -0,0 +1,7 @@ +import { z } from 'zod'; + +const pmmSchema = z.object({ + orionPMMRouterContractAddress: z.string() +}); + +export default pmmSchema \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 2bbded1..8985203 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "lib" ], "compilerOptions": { + "moduleResolution": "node", "target": "esnext", "module": "ESNext", "esModuleInterop": true, From 13f6a9fa7de52b92716f2b872f3b136b4bd5b2cf Mon Sep 17 00:00:00 2001 From: KS Date: Mon, 11 Mar 2024 12:34:29 +0300 Subject: [PATCH 18/57] fixed typos, added pmm.getContractAddress() method --- README.md | 9 ++++++--- src/Unit/Pmm/index.ts | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0d2fa18..9ff3632 100644 --- a/README.md +++ b/README.md @@ -744,7 +744,7 @@ import {simpleFetch} from "simple-typed-fetch"; const secretKey = 'secretKey'; const yourWalletPrivateKey = '0x...'; - const orion = new Orion('testing'); // Leave empty for test environment + const orion = new Orion('testing'); // Leave empty for PROD environment const bsc = orion.getUnit('bsc'); const wallet = new Wallet(yourWalletPrivateKey, bsc.provider); @@ -755,6 +755,9 @@ import {simpleFetch} from "simple-typed-fetch"; // Also you need to allow FRQ contract to spend tokens from your address. // This also can be done only once. await bsc.pmm.setAllowance(assetToAddress.ORN, '1000000000000000000', wallet); + + // Just output the PMM router contract address + console.log('Router contract address: ', await bsc.pmm.getContractAddress()); const rfqOrder = await bsc.aggregator.RFQOrder( assetToAddress.ORN, // Spending asset @@ -774,7 +777,7 @@ import {simpleFetch} from "simple-typed-fetch"; // Send order to blockchain try { - const tx = await bsc.pmm.FillRFQOrder(rfqOrder, wallet); + const tx = await bsc.pmm.fillRFQOrder(rfqOrder, wallet); // If tx.hash is not empty - then transaction was sent to blockchain console.log(tx.hash); @@ -787,7 +790,7 @@ import {simpleFetch} from "simple-typed-fetch"; RFQ order response example description (`rfqOrder` from example above): -```json +``` { quotation: { info: '31545611720730315633520017429', diff --git a/src/Unit/Pmm/index.ts b/src/Unit/Pmm/index.ts index aa35962..cb41136 100644 --- a/src/Unit/Pmm/index.ts +++ b/src/Unit/Pmm/index.ts @@ -16,6 +16,7 @@ export default class Pmm { this.unit = unit; this.provider = unit.provider; this.contractAddress = ''; + // this.contractAddress = '0x89357522c0ed6e557d39dc75290859246077bdfc'; } private isInitialized() : boolean { @@ -29,6 +30,11 @@ export default class Pmm { this.contractAddress = orionPMMRouterContractAddress; } + public async getContractAddress() { + await this.init(); + return this.contractAddress; + } + public async setAllowance(token: string, amount: string, signer: Wallet) { await this.init(); @@ -64,7 +70,7 @@ export default class Pmm { await txResponse.wait(); } - public async FillRFQOrder(order : z.infer, signer: Wallet) { + public async fillRFQOrder(order : z.infer, signer: Wallet) { await this.init(); if(!order.success) From 6f5fd0339741a6569d1e8a516f2ef37d12593075 Mon Sep 17 00:00:00 2001 From: KS Date: Mon, 11 Mar 2024 15:48:45 +0300 Subject: [PATCH 19/57] fixed rc version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5788d98..5fb615b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.66-rc", + "version": "0.20.66-rc2", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 20f38f1c4afa843e43cb77591b88b9d795d9e87f Mon Sep 17 00:00:00 2001 From: KS Date: Mon, 11 Mar 2024 15:53:40 +0300 Subject: [PATCH 20/57] fixed version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fb615b..cec14eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.66-rc2", + "version": "0.20.68-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 2c26af4e36f332d3f07d76ad5a1dc837e76112c2 Mon Sep 17 00:00:00 2001 From: Ukridge <53254325+Ukridge@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:57:45 +0300 Subject: [PATCH 21/57] Update package.json (version) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cec14eb..b549948 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.68-rc1", + "version": "0.20.68", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 5cb1bfb9d93b2161bea0dbc26f4bb42f1293467d Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 12 Mar 2024 12:13:40 +0300 Subject: [PATCH 22/57] getAmountAt function --- package-lock.json | 4 ++-- package.json | 2 +- src/services/Indexer/index.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1d4e89e..26e988f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.66-rc2", + "version": "0.20.69", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.66-rc2", + "version": "0.20.69", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index b549948..3b5722a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.68", + "version": "0.20.69", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Indexer/index.ts b/src/services/Indexer/index.ts index bcdfaca..3a4bb1e 100644 --- a/src/services/Indexer/index.ts +++ b/src/services/Indexer/index.ts @@ -94,6 +94,7 @@ class IndexerService { this.veORNInfo = this.veORNInfo.bind(this); this.listAmount = this.listAmount.bind(this); this.getAmountByORN = this.getAmountByORN.bind(this); + this.getAmountAt = this.getAmountAt.bind(this); this.getAmountAtCurrent = this.getAmountAtCurrent.bind(this); this.getVotingInfo = this.getVotingInfo.bind(this); } @@ -117,6 +118,16 @@ class IndexerService { }); }; + readonly getAmountAt = (amount: number, timestamp?: number): BigNumber => { + const currentTime = Date.now() / 1000; + + // sqrt + return BigNumber(amount).dividedBy(this.getK(timestamp ?? currentTime)); + }; + + /** + * @deprecated In favor of getAmountAt + */ readonly getAmountAtCurrent = (amount: number): BigNumber => { const timestamp = Date.now() / 1000; From c814d41dc1c30eff7f11e23cc083ca05da078da3 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 12 Mar 2024 13:44:14 +0300 Subject: [PATCH 23/57] fix: timestamp --- package-lock.json | 4 ++-- package.json | 2 +- src/services/Indexer/index.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 26e988f..82eccec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.69", + "version": "0.20.70", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.69", + "version": "0.20.70", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 3b5722a..af701f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.69", + "version": "0.20.70", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Indexer/index.ts b/src/services/Indexer/index.ts index 3a4bb1e..597871e 100644 --- a/src/services/Indexer/index.ts +++ b/src/services/Indexer/index.ts @@ -119,10 +119,10 @@ class IndexerService { }; readonly getAmountAt = (amount: number, timestamp?: number): BigNumber => { - const currentTime = Date.now() / 1000; + const finalTimestamp = timestamp !== undefined ? timestamp / 1000 : Date.now() / 1000; // sqrt - return BigNumber(amount).dividedBy(this.getK(timestamp ?? currentTime)); + return BigNumber(amount).dividedBy(this.getK(finalTimestamp)); }; /** From daf45567c8826a09a4d27efbb2364d7546789356 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 12 Mar 2024 15:18:48 +0300 Subject: [PATCH 24/57] fixed getAmountAt --- package-lock.json | 4 ++-- package.json | 2 +- src/services/Indexer/index.ts | 26 ++++++++++++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 82eccec..8bb3d76 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.70", + "version": "0.20.71", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.70", + "version": "0.20.71", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index af701f3..9396db9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.70", + "version": "0.20.71", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Indexer/index.ts b/src/services/Indexer/index.ts index 597871e..2791f8a 100644 --- a/src/services/Indexer/index.ts +++ b/src/services/Indexer/index.ts @@ -9,7 +9,7 @@ import { PoolV2InfoResponseSchema, testIncrementorSchema, veORNInfoResponseSchema, - votingInfoResponseSchema + votingInfoResponseSchema, } from './schemas'; import { fetchWithValidation } from 'simple-typed-fetch'; import { BigNumber } from 'bignumber.js'; @@ -118,16 +118,23 @@ class IndexerService { }); }; - readonly getAmountAt = (amount: number, timestamp?: number): BigNumber => { - const finalTimestamp = timestamp !== undefined ? timestamp / 1000 : Date.now() / 1000; + /** + * @param {number} amount - amount + * @param {number} [timestamp = Date.now()] - timestamp, defaults to current time + */ + readonly getAmountAt = ( + amount: number, + timestamp = Date.now() + ): BigNumber => { + const finalTimestamp = timestamp / 1000; // sqrt return BigNumber(amount).dividedBy(this.getK(finalTimestamp)); }; /** - * @deprecated In favor of getAmountAt - */ + * @deprecated since version 69 in favor of getAmountAt + */ readonly getAmountAtCurrent = (amount: number): BigNumber => { const timestamp = Date.now() / 1000; @@ -145,8 +152,7 @@ class IndexerService { const multSQRT = deltaDaysBN.dividedBy(WEEK_DAYS).sqrt(); const multCUBE = deltaDaysBN.dividedBy(alpha).pow(3); - return BigNumber(amountToken) - .multipliedBy(multSQRT.plus(multCUBE)); + return BigNumber(amountToken).multipliedBy(multSQRT.plus(multCUBE)); }; readonly getVotingInfo = (userAddress?: string) => { @@ -219,7 +225,11 @@ class IndexerService { }); }; - readonly poolV2Info = (token0: string, token1: string, address: string | undefined) => { + readonly poolV2Info = ( + token0: string, + token1: string, + address: string | undefined + ) => { return fetchWithValidation(this.apiUrl, PoolV2InfoResponseSchema, { method: 'POST', body: this.makeRPCPayload({ From 14acef6d14a69c210112e5a706219ba08583d212 Mon Sep 17 00:00:00 2001 From: Ukridge <53254325+Ukridge@users.noreply.github.com> Date: Wed, 13 Mar 2024 01:34:40 +0300 Subject: [PATCH 25/57] Update README.md --- README.md | 55 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 9ff3632..b06f8c3 100644 --- a/README.md +++ b/README.md @@ -735,56 +735,63 @@ Please take look at code example below. Simple example: ```ts -import Orion from '../Orion'; +// Node.js + +import { Orion } from '@orionprotocol/sdk' import {Wallet} from "ethers"; -import {simpleFetch} from "simple-typed-fetch"; (async() => { const apiKey = '958153f1-b8b9-3ec4-84eb-2147429105d9'; const secretKey = 'secretKey'; const yourWalletPrivateKey = '0x...'; - + const orion = new Orion('testing'); // Leave empty for PROD environment const bsc = orion.getUnit('bsc'); const wallet = new Wallet(yourWalletPrivateKey, bsc.provider); - + // This can be done only once, no need to repeat this every time - // assetToDecimals can also be useful for calculations - const {assetToAddress, assetToDecimals} = await simpleFetch(bsc.blockchainService.getInfo)(); - + // assetToDecimals can also be useful for calculations + // const {assetToAddress, assetToDecimals} = await bsc.blockchainService.getInfo(); + const info = await bsc.blockchainService.getInfo(); + + if(!info.isOk()) + return; + + const {assetToAddress, assetToDecimals} = info.value.data; + // Also you need to allow FRQ contract to spend tokens from your address. // This also can be done only once. await bsc.pmm.setAllowance(assetToAddress.ORN, '1000000000000000000', wallet); - + // Just output the PMM router contract address console.log('Router contract address: ', await bsc.pmm.getContractAddress()); const rfqOrder = await bsc.aggregator.RFQOrder( - assetToAddress.ORN, // Spending asset - assetToAddress.USDT, // Receiving asset - '10000000000', // Amount in "satoshi" of spending asset - apiKey, - secretKey, - '0x61Eed69c0d112C690fD6f44bB621357B89fBE67F' // Can be any address, ignored for now + assetToAddress.ORN, // Spending asset + assetToAddress.USDT, // Receiving asset + '1000000000', // Amount in "satoshi" of spending asset + apiKey, + secretKey, + '0x61Eed69c0d112C690fD6f44bB621357B89fBE67F' // Can be any address, ignored for now ); - + if(!rfqOrder.success) { console.log(rfqOrder.error); return; } - + // ... here you can check order prices, etc. - + // Send order to blockchain try { - const tx = await bsc.pmm.fillRFQOrder(rfqOrder, wallet); - - // If tx.hash is not empty - then transaction was sent to blockchain - console.log(tx.hash); + const tx = await bsc.pmm.fillRFQOrder(rfqOrder, wallet); + + // If tx.hash is not empty - then transaction was sent to blockchain + console.log(tx.hash); } catch(err) { - console.log(err); - } + console.log(err); + } })(); ``` @@ -814,4 +821,4 @@ RFQ order response example description (`rfqOrder` from example above): * maker - can be ignored for now; * allowedSender - can be ignored for now; * makingAmount - how much you will RECEIVE (in receiving asset's precision) -* takingAmount - how much you should SPEND (in spending asset's precision) \ No newline at end of file +* takingAmount - how much you should SPEND (in spending asset's precision) From 8dedc46cb58e7bc709ceaa01402c3bc4f90992f3 Mon Sep 17 00:00:00 2001 From: TheJuze Date: Wed, 13 Mar 2024 13:34:18 +0300 Subject: [PATCH 26/57] Remove analyticsAPI from config --- ADVANCED.md | 2 -- package-lock.json | 4 ++-- package.json | 2 +- src/Orion/index.ts | 1 - src/__tests__/basic.test.ts | 2 -- src/config/envs.json | 5 ----- src/config/schemas/pureEnvSchema.ts | 1 - src/types.ts | 1 - 8 files changed, 3 insertions(+), 15 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index f4b1267..8f3fd9b 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -2,7 +2,6 @@ ```ts const orion = new Orion({ - analyticsAPI: "https://analytics-api.orionprotocol.io", referralAPI: "https://referral-api.orionprotocol.io", networks: { 1: { @@ -26,7 +25,6 @@ const orion = new Orion({ // Also you can set some config as default and override it for some params const orion = new Orion("testing", { - analyticsAPI: "https://asdasd.orionprotocol.io", networks: { [SupportedChainId.BSC_TESTNET]: { nodeJsonRpc: "https://data-seed-prebsc-1-s1.binance.org:8545/", diff --git a/package-lock.json b/package-lock.json index 8bb3d76..98ae352 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.71", + "version": "0.20.72", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.71", + "version": "0.20.72", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 9396db9..e94746e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.71", + "version": "0.20.72", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Orion/index.ts b/src/Orion/index.ts index 02ccd5c..fd73418 100644 --- a/src/Orion/index.ts +++ b/src/Orion/index.ts @@ -33,7 +33,6 @@ export default class Orion { } this.env = envOrConfig; config = { - analyticsAPI: envConfig.analyticsAPI, referralAPI: envConfig.referralAPI, networks: Object.entries(envConfig.networks).map(([chainId, networkConfig]) => { if (!isValidChainId(chainId)) throw new Error(`Invalid chainId: ${chainId}`); diff --git a/src/__tests__/basic.test.ts b/src/__tests__/basic.test.ts index d4de381..f64386b 100644 --- a/src/__tests__/basic.test.ts +++ b/src/__tests__/basic.test.ts @@ -159,7 +159,6 @@ describe('Orion', () => { const orionPriceFeedAPI = `http://localhost:${server2.port}`; const orion = new Orion({ - analyticsAPI: 'https://analytics-api.orionprotocol.io', referralAPI: 'https://referral-api.orionprotocol.io', networks: { 1: { @@ -239,7 +238,6 @@ describe('Orion', () => { test('Init Orion testing with overrides', () => { const orion = new Orion('testing', { - analyticsAPI: 'https://asdasd.orionprotocol.io', referralAPI: 'https://zxczxc.orionprotocol.io', networks: { [SupportedChainId.BSC_TESTNET]: { diff --git a/src/config/envs.json b/src/config/envs.json index 41094b3..6628b38 100644 --- a/src/config/envs.json +++ b/src/config/envs.json @@ -1,6 +1,5 @@ { "production": { - "analyticsAPI": "https://trade.orion.xyz/api/stats", "referralAPI": "https://trade.orion.xyz/referral-api", "networks": { "1": { @@ -169,7 +168,6 @@ } }, "testing": { - "analyticsAPI": "https://trade.orion.xyz/api/stats", "referralAPI": "https://testing.orion.xyz/referral-api", "networks": { "97": { @@ -284,7 +282,6 @@ } }, "staging": { - "analyticsAPI": "https://trade.orion.xyz/api/stats", "referralAPI": "https://staging.orion.xyz/referral-api", "networks": { "1": { @@ -452,7 +449,6 @@ } }, "experimental": { - "analyticsAPI": "https://trade.orion.xyz/api/stats", "referralAPI": "https://testing.orion.xyz/referral-api", "networks": { "97": { @@ -494,7 +490,6 @@ } }, "kucoin-production": { - "analyticsAPI": "https://trade.orion.xyz/api/stats", "referralAPI": "https://trade.orion.xyz/referral-api", "networks": { "1": { diff --git a/src/config/schemas/pureEnvSchema.ts b/src/config/schemas/pureEnvSchema.ts index 642dd0b..26ab7ce 100644 --- a/src/config/schemas/pureEnvSchema.ts +++ b/src/config/schemas/pureEnvSchema.ts @@ -23,7 +23,6 @@ export const pureEnvNetworksSchema = z.object({ }); export const pureEnvPayloadSchema = z.object({ - analyticsAPI: z.string().url(), referralAPI: z.string().url(), networks: z.record( z.nativeEnum(SupportedChainId), diff --git a/src/types.ts b/src/types.ts index 5a96d83..712316b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -279,7 +279,6 @@ export type KnownEnv = typeof knownEnvs[number]; export type Json = string | number | boolean | null | Json[] | { [key: string]: Json }; export type EnvConfig = { - analyticsAPI: string referralAPI: string networks: Partial< Record< From cf2fd889a057064590116c8a5525ca519e4c2135 Mon Sep 17 00:00:00 2001 From: TheJuze Date: Wed, 13 Mar 2024 14:07:36 +0300 Subject: [PATCH 27/57] return analyticsAPI and make it optional --- ADVANCED.md | 2 ++ package.json | 2 +- src/Orion/index.ts | 1 + src/__tests__/basic.test.ts | 2 ++ src/config/schemas/pureEnvSchema.ts | 1 + src/types.ts | 1 + 6 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ADVANCED.md b/ADVANCED.md index 8f3fd9b..d28f801 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -2,6 +2,7 @@ ```ts const orion = new Orion({ + analyticsAPI: "https://analytics-api.orionprotocol.io", referralAPI: "https://referral-api.orionprotocol.io", networks: { 1: { @@ -25,6 +26,7 @@ const orion = new Orion({ // Also you can set some config as default and override it for some params const orion = new Orion("testing", { + analyticsAPI: "https://analytics-api.orionprotocol.io", networks: { [SupportedChainId.BSC_TESTNET]: { nodeJsonRpc: "https://data-seed-prebsc-1-s1.binance.org:8545/", diff --git a/package.json b/package.json index e94746e..8d2b156 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.72", + "version": "0.20.73", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Orion/index.ts b/src/Orion/index.ts index fd73418..7245c00 100644 --- a/src/Orion/index.ts +++ b/src/Orion/index.ts @@ -33,6 +33,7 @@ export default class Orion { } this.env = envOrConfig; config = { + analyticsAPI: envConfig?.analyticsAPI, referralAPI: envConfig.referralAPI, networks: Object.entries(envConfig.networks).map(([chainId, networkConfig]) => { if (!isValidChainId(chainId)) throw new Error(`Invalid chainId: ${chainId}`); diff --git a/src/__tests__/basic.test.ts b/src/__tests__/basic.test.ts index f64386b..d4de381 100644 --- a/src/__tests__/basic.test.ts +++ b/src/__tests__/basic.test.ts @@ -159,6 +159,7 @@ describe('Orion', () => { const orionPriceFeedAPI = `http://localhost:${server2.port}`; const orion = new Orion({ + analyticsAPI: 'https://analytics-api.orionprotocol.io', referralAPI: 'https://referral-api.orionprotocol.io', networks: { 1: { @@ -238,6 +239,7 @@ describe('Orion', () => { test('Init Orion testing with overrides', () => { const orion = new Orion('testing', { + analyticsAPI: 'https://asdasd.orionprotocol.io', referralAPI: 'https://zxczxc.orionprotocol.io', networks: { [SupportedChainId.BSC_TESTNET]: { diff --git a/src/config/schemas/pureEnvSchema.ts b/src/config/schemas/pureEnvSchema.ts index 26ab7ce..9c799c4 100644 --- a/src/config/schemas/pureEnvSchema.ts +++ b/src/config/schemas/pureEnvSchema.ts @@ -23,6 +23,7 @@ export const pureEnvNetworksSchema = z.object({ }); export const pureEnvPayloadSchema = z.object({ + analyticsAPI: z.string().url().optional(), referralAPI: z.string().url(), networks: z.record( z.nativeEnum(SupportedChainId), diff --git a/src/types.ts b/src/types.ts index 712316b..0f1bbb3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -279,6 +279,7 @@ export type KnownEnv = typeof knownEnvs[number]; export type Json = string | number | boolean | null | Json[] | { [key: string]: Json }; export type EnvConfig = { + analyticsAPI: string | undefined referralAPI: string networks: Partial< Record< From b2a340683684a5579d0d5dd67e6c1ec8c76419ee Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Tue, 19 Mar 2024 09:09:03 +0000 Subject: [PATCH 28/57] feat: added new method getExchangeContractWalletBalance --- package.json | 2 +- src/services/BlockchainService/index.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 8d2b156..471d681 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.73", + "version": "0.20.74-rc0", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/BlockchainService/index.ts b/src/services/BlockchainService/index.ts index 16d5e59..ceacbcb 100644 --- a/src/services/BlockchainService/index.ts +++ b/src/services/BlockchainService/index.ts @@ -114,6 +114,7 @@ class BlockchainService { this.getRedeemOrderBySecretHash = this.getRedeemOrderBySecretHash.bind(this); this.claimOrder = this.claimOrder.bind(this); this.getGasLimits = this.getGasLimits.bind(this); + this.getExchangeContractWalletBalance = this.getExchangeContractWalletBalance.bind(this); } get basicAuthHeaders() { @@ -495,6 +496,12 @@ class BlockchainService { z.record(z.number()), { headers: this.basicAuthHeaders } ); + + getExchangeContractWalletBalance = (exchangeContractAddress: string) => fetchWithValidation( + `${this.apiUrl}/api/broker/getWalletBalance/${exchangeContractAddress}`, + z.record(z.string()), + { headers: this.basicAuthHeaders } + ); } export * as schemas from './schemas/index.js'; From d97e5267f0dc4d715d39756ca1f0dd02e45305d6 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Wed, 20 Mar 2024 11:27:39 +0000 Subject: [PATCH 29/57] feat: updated contracts --- package-lock.json | 18 +++++++++--------- package.json | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 98ae352..9cc7fbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,19 +1,19 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.72", + "version": "0.20.73", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.72", + "version": "0.20.73", "hasInstallScript": true, "license": "ISC", "dependencies": { "@babel/runtime": "^7.21.0", "@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@orionprotocol/contracts": "1.22.10", + "@orionprotocol/contracts": "1.23.3", "@types/lodash.clonedeep": "^4.5.9", "bignumber.js": "^9.1.1", "bson-objectid": "^2.0.4", @@ -2423,9 +2423,9 @@ } }, "node_modules/@orionprotocol/contracts": { - "version": "1.22.10", - "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.22.10.tgz", - "integrity": "sha512-c9cUkXs1Nv8p+EVTybwJqeXhecwm7xeycAVauhl6jYAqvKOx7PDCUjzE3Nh0tpi4xP3CLeABgNy8JAFYyvN1VA==" + "version": "1.23.3", + "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.3.tgz", + "integrity": "sha512-3PBnuiUe//v7COArcm/dzFx71vxW+a9emU4PHi1zBdow+OUAa4WNb+NmNZ3AOjnx2AZKK+gWJY+zKo1zSfAOHQ==" }, "node_modules/@sinclair/typebox": { "version": "0.27.8", @@ -13493,9 +13493,9 @@ } }, "@orionprotocol/contracts": { - "version": "1.22.10", - "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.22.10.tgz", - "integrity": "sha512-c9cUkXs1Nv8p+EVTybwJqeXhecwm7xeycAVauhl6jYAqvKOx7PDCUjzE3Nh0tpi4xP3CLeABgNy8JAFYyvN1VA==" + "version": "1.23.3", + "resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-1.23.3.tgz", + "integrity": "sha512-3PBnuiUe//v7COArcm/dzFx71vxW+a9emU4PHi1zBdow+OUAa4WNb+NmNZ3AOjnx2AZKK+gWJY+zKo1zSfAOHQ==" }, "@sinclair/typebox": { "version": "0.27.8", diff --git a/package.json b/package.json index 8d2b156..93c9440 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "@babel/runtime": "^7.21.0", "@ethersproject/abstract-signer": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@orionprotocol/contracts": "1.22.10", + "@orionprotocol/contracts": "1.23.3", "@types/lodash.clonedeep": "^4.5.9", "bignumber.js": "^9.1.1", "bson-objectid": "^2.0.4", From 712c0d45a21cdc14c24038a7f17e42bcbed906d0 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Wed, 20 Mar 2024 11:28:25 +0000 Subject: [PATCH 30/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 93c9440..b92b6e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.73", + "version": "0.20.74", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 555e26f842cf22294659c7103908e2d7f40d70a2 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Wed, 20 Mar 2024 13:47:40 +0000 Subject: [PATCH 31/57] feat: get from wallet first fix --- package.json | 2 +- src/Unit/Exchange/generateSwapCalldata.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b92b6e2..01262dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.74", + "version": "0.20.75-rc0", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Unit/Exchange/generateSwapCalldata.ts b/src/Unit/Exchange/generateSwapCalldata.ts index 91f3fe6..fd7fe08 100644 --- a/src/Unit/Exchange/generateSwapCalldata.ts +++ b/src/Unit/Exchange/generateSwapCalldata.ts @@ -397,7 +397,7 @@ async function shouldUseExchangeBalance( let useExchangeBalance = true; let additionalTransferAmount = 0n; - if (exchangeBalance == 0n) { + if (walletBalance >= amount || exchangeBalance == 0n) { useExchangeBalance = false; additionalTransferAmount = amount; } else { From e2549932b24bde82be49d7f9b20316af5131378a Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Wed, 20 Mar 2024 14:02:27 +0000 Subject: [PATCH 32/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 01262dc..563e1fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.75-rc0", + "version": "0.20.75", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From a6d40294647ce14ba2df30159d85673673b8e739 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 25 Mar 2024 08:34:12 +0000 Subject: [PATCH 33/57] feat: added new AVAX network --- src/config/chains.json | 13 +++++++++ src/config/envs.json | 36 +++++++++++++++++++++++++ src/constants/chains.ts | 1 + src/constants/networkCodes.ts | 2 +- src/constants/uppercasedNetworkCodes.ts | 2 +- src/types.ts | 1 + 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/config/chains.json b/src/config/chains.json index bed5a5d..9d21aae 100644 --- a/src/config/chains.json +++ b/src/config/chains.json @@ -219,5 +219,18 @@ "WETH": "0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f", "curveRegistry": "" } + }, + "43114": { + "chainId": "43114", + "label": "Avalanche Network", + "shortName": "Avax", + "code": "avax", + "baseCurrencyName": "AVAX", + "rpc": "https://api.avax.network/ext/bc/C/rpc/", + "explorer": "https://snowtrace.io/", + "contracts": { + "WETH": "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", + "curveRegistry": "" + } } } diff --git a/src/config/envs.json b/src/config/envs.json index 6628b38..0dddc93 100644 --- a/src/config/envs.json +++ b/src/config/envs.json @@ -164,6 +164,24 @@ "http": "/orion-indexer/" } } + }, + "43114": { + "api": "https://trade.orion.xyz/avax-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } } } }, @@ -445,6 +463,24 @@ "http": "/orion-indexer/" } } + }, + "43114": { + "api": "https://trade.orion.xyz/avax-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } } } }, diff --git a/src/constants/chains.ts b/src/constants/chains.ts index 0e0b025..aac8213 100644 --- a/src/constants/chains.ts +++ b/src/constants/chains.ts @@ -19,4 +19,5 @@ export const productionChains = [ SupportedChainId.OPBNB, SupportedChainId.INEVM, SupportedChainId.LINEA, + SupportedChainId.AVAX, ]; diff --git a/src/constants/networkCodes.ts b/src/constants/networkCodes.ts index 74b0d0f..c3a5dad 100644 --- a/src/constants/networkCodes.ts +++ b/src/constants/networkCodes.ts @@ -1 +1 @@ -export default ['ftm', 'bsc', 'eth', 'polygon', 'okc', 'arb', 'drip', 'opbnb', 'inevm', 'linea'] as const; +export default ['ftm', 'bsc', 'eth', 'polygon', 'okc', 'arb', 'drip', 'opbnb', 'inevm', 'linea', 'avax'] as const; diff --git a/src/constants/uppercasedNetworkCodes.ts b/src/constants/uppercasedNetworkCodes.ts index f3c9515..6b8e312 100644 --- a/src/constants/uppercasedNetworkCodes.ts +++ b/src/constants/uppercasedNetworkCodes.ts @@ -1 +1 @@ -export default ['FTM', 'BSC', 'ETH', 'POLYGON', 'OKC', 'ARB', 'OPBNB', 'INEVM', 'LINEA'] as const; +export default ['FTM', 'BSC', 'ETH', 'POLYGON', 'OKC', 'ARB', 'OPBNB', 'INEVM', 'LINEA', 'AVAX'] as const; diff --git a/src/types.ts b/src/types.ts index 0f1bbb3..5828296 100644 --- a/src/types.ts +++ b/src/types.ts @@ -90,6 +90,7 @@ export enum SupportedChainId { OPBNB = '204', INEVM = '2525', LINEA = '59144', + AVAX = '43114', POLYGON_TESTNET = '80001', FANTOM_TESTNET = '4002', From 18f6805bf738e0f059c5dba77c7766e8a26185c5 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 25 Mar 2024 08:34:47 +0000 Subject: [PATCH 34/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 563e1fb..f4be77f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.75", + "version": "0.20.76", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 8be6ff9c0309d5c9055ea117c482d49a6621aced Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 25 Mar 2024 09:26:48 +0000 Subject: [PATCH 35/57] feat: updated api url for AVAX network --- src/config/envs.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/envs.json b/src/config/envs.json index 0dddc93..a6c3988 100644 --- a/src/config/envs.json +++ b/src/config/envs.json @@ -166,7 +166,7 @@ } }, "43114": { - "api": "https://trade.orion.xyz/avax-mainnet", + "api": "https://trade.orion.xyz/avalanche-c-chain", "services": { "aggregator": { "http": "/backend", @@ -465,7 +465,7 @@ } }, "43114": { - "api": "https://trade.orion.xyz/avax-mainnet", + "api": "https://trade.orion.xyz/avalanche-c-chain", "services": { "aggregator": { "http": "/backend", From 42c7f929ddedc31d4ef22780e976c2ea69120cd9 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Mon, 25 Mar 2024 09:27:18 +0000 Subject: [PATCH 36/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f4be77f..9266080 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.76", + "version": "0.20.77", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 1e45222a43e3dd400a44e690c6c278fb18e1da66 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Thu, 28 Mar 2024 12:04:29 +0000 Subject: [PATCH 37/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 690319a..cb7a74f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.74-rc0", + "version": "0.20.74-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From d17fed1e9e0005b6512427b05faf4c8f64c0def8 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Thu, 28 Mar 2024 12:09:01 +0000 Subject: [PATCH 38/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb7a74f..ee8c258 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.74-rc1", + "version": "0.20.78", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From b0873ab04c7b570426a97d5d9141fea2434b8018 Mon Sep 17 00:00:00 2001 From: KS Date: Fri, 29 Mar 2024 07:26:15 +0300 Subject: [PATCH 39/57] added PMM-sample.md , fixed order schema --- PMM-sample.md | 288 +++++++++++++++++++++++++++++++ package.json | 2 +- src/Unit/Pmm/index.ts | 2 +- src/Unit/Pmm/schemas/order.ts | 2 +- src/services/Aggregator/index.ts | 3 +- 5 files changed, 292 insertions(+), 5 deletions(-) create mode 100644 PMM-sample.md diff --git a/PMM-sample.md b/PMM-sample.md new file mode 100644 index 0000000..ad1eb45 --- /dev/null +++ b/PMM-sample.md @@ -0,0 +1,288 @@ + + +
+ Orion Protocol SDK logo +

PMM example

+
+ +## Overview + +This is special example which shows how to use PMM liquidity without using SDK, only using few libraries + +```ts +import {ethers, Wallet} from "ethers"; +import {z} from "zod"; +import hmacSHA256 from "crypto-js/hmac-sha256"; +import Hex from "crypto-js/enc-hex"; + +/////////////////////////////// +/////////////////////////////// +const pmmOrderQuotationSchema = z.object({ + info: z.string().default(''), + makerAsset: z.string().default(''), + takerAsset: z.string().default(''), + maker: z.string().default(''), + allowedSender: z.string().default(''), + makingAmount: z.string().default(''), + takingAmount: z.string().default(''), +}); + +const pmmOrderSchema = z.object({ + order: pmmOrderQuotationSchema.default({}), + signature: z.string().default(''), + success: z.boolean().default(false), + error: z.string().default(''), +}); + +const orionRFQContractABI = + [ + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "info", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + } + ], + "internalType": "struct OrderRFQLib.OrderRFQ", + "name": "order", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "flagsAndAmount", + "type": "uint256" + } + ], + "name": "fillOrderRFQ", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ]; + +function encode_utf8(s : string) { + return unescape(encodeURIComponent(s)); +} +function sign(message : string, key: string) { + return hmacSHA256( + encode_utf8(message), + encode_utf8(key) + ).toString(Hex); +} + +function generateHeaders(body : any, method : string, path : string, timestamp : number, apiKey : string, secretKey : string) { + const sortedBody = Object.keys(body) + .sort() + .map((key) => ( + `${key}=${body[key]}` + )).join('&'); + + const payload = timestamp + method.toUpperCase() + path + sortedBody; + + const signature = sign(payload, secretKey); + + const httpOptions = { + headers: { + 'API-KEY': apiKey, + 'ACCESS-TIMESTAMP': timestamp.toString(), + 'ACCESS-SIGN': signature + } + }; + return httpOptions; +} + +// +async function RFQOrder( + tokenFrom: string, + tokenTo: string, + fromTokenAmount: string, + apiKey: string, // + secretKey: string, + wallet: string +) : Promise> { + + // NB: replace with correct URL for networks + const apiUrl = 'https://testing.orion.xyz/bsc-testnet/backend' + // const apiUrl = 'https://trade.orion.xyz/bsc-mainnet/backend' + , path = '/rfq' + , url = `${apiUrl}/api/v1/integration/pmm`+path + , headers = { + 'Content-Type': 'application/json', + } + , data = { + "baseToken":tokenFrom, // USDT + "quoteToken":tokenTo, // ORN + "amount": fromTokenAmount, // 100 + "taker": wallet, + "feeBps": 0 + } + , method = 'POST' + , timestamp = Date.now() + , signatureHeaders = generateHeaders(data, method, path, timestamp, apiKey, secretKey) + , compiledHeaders = {...headers, ...signatureHeaders.headers, } + , body = JSON.stringify(data) + ; + + let res = pmmOrderSchema.parse({}); + + try { + const result = await fetch(url,{ + headers: compiledHeaders, + method, + body + }); + + // const data = await result.text(); + // console.log(data); + + const json = await result.json(); + console.log(json); + const parseResult = pmmOrderSchema.safeParse(json); + + if(!parseResult.success) { + // Try to parse error answer + const errorSchema = z.object({error: z.object({code: z.number(), reason: z.string()})}); + + const errorParseResult = errorSchema.safeParse(json); + + if(!errorParseResult.success) + throw Error(`Unrecognized answer from aggregator: ${json}`); + + throw Error(errorParseResult.data.error.reason); + } + + res.order = parseResult.data.order; + res.signature = parseResult.data.signature; + res.error = ''; + res.success = true; + } + catch(err) { + res.error = `${err}`; + } + return res; +} + + +(async() => { + const apiKey = '958153f1-b8b9-3ec4-84eb-2147429105d9'; + const secretKey = 'secretKey'; + + // BNB testnet tokens and router + const assetORN = '0xf223eca06261145b3287a0fefd8cfad371c7eb34'; + const assetUSDT = '0xcb2951e90d8dcf16e1fa84ac0c83f48906d6a744'; + const router = '0x89357522C0ed6E557D39dC75290859246077bdfC'; + + // BNB mainnet tokens and router + // const assetORN = '0xe4ca1f75eca6214393fce1c1b316c237664eaa8e'; + // const assetUSDT = '0x55d398326f99059ff775485246999027b3197955'; + // const router = '0xcb2D40EabC4f4c92Ee993Eb3D67f7717bE476E76'; + + const rfqOrder = await RFQOrder( + assetORN, // Spending asset + assetUSDT, // Receiving asset + '1000000000', // Amount in "satoshi" of spending asset + apiKey, + secretKey, + '0x61Eed69c0d112C690fD6f44bB621357B89fBE67F' // Can be any address, ignored for now + ); + + if(!rfqOrder.success) { + console.log(rfqOrder.error); + return; + } + + // ... here you can check order prices, etc. + console.log(rfqOrder); + + // Calldata according to provided rfqOrder + const contractInterface = new ethers.Interface(orionRFQContractABI); + const calldata = contractInterface.encodeFunctionData("fillOrderRFQ", [rfqOrder.order, rfqOrder.signature, 0]); + console.log('Calldata = ', calldata); + + // Call router with this data + // Replace with your private key + const yourWalletPrivateKey = '0xf1.......'; + + const tx = { + to: router, + data: calldata + } + + const provider = new ethers.JsonRpcProvider("https://data-seed-prebsc-1-s1.binance.org:8545/"); + const signer = new ethers.Wallet(yourWalletPrivateKey, provider); + console.log('Address = ', signer.address); + const transactionResponse = await signer.sendTransaction(tx); + console.log("Transaction hash:", transactionResponse.hash); + await transactionResponse.wait(); +})(); +``` + +RFQ order response example description (`rfqOrder` from example above): + +``` + { + quotation: { + info: '31545611720730315633520017429', + makerAsset: '0xcb2951e90d8dcf16e1fa84ac0c83f48906d6a744', + takerAsset: '0xf223eca06261145b3287a0fefd8cfad371c7eb34', + maker: '0x1ff516e5ce789085cff86d37fc27747df852a80a', + allowedSender: '0x0000000000000000000000000000000000000000', + makingAmount: '193596929', + takingAmount: '10000000000' + }, + signature: '0x8a2f9140a3c3a5734eda763a19c54c5ac909d8a03db37d9804af9115641fd1d35896b66ca6e136c1c89e0478fb7382a4b875d0f74529c1e83601f9383d310dde1b', + success: true, + error: '' + } +``` + + +* info - can be ignored +* makerAsset - your RECEIVING asset (what you expect to receive from contract, in this case USDT) +* takerAsset - your SPENDING asset (what you're giving to contract, in this case ORN) +* maker - can be ignored for now; +* allowedSender - can be ignored for now; +* makingAmount - how much you will RECEIVE (in receiving asset's precision) +* takingAmount - how much you should SPEND (in spending asset's precision) \ No newline at end of file diff --git a/package.json b/package.json index cec14eb..a307337 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.68-rc1", + "version": "0.20.79-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Unit/Pmm/index.ts b/src/Unit/Pmm/index.ts index cb41136..d4f1c57 100644 --- a/src/Unit/Pmm/index.ts +++ b/src/Unit/Pmm/index.ts @@ -79,6 +79,6 @@ export default class Pmm { const contract = new ethers.Contract(this.contractAddress, orionRFQContractABI, signer); // @ts-ignore - return contract.fillOrderRFQ(order.quotation, order.signature, BigInt(0)); + return contract.fillOrderRFQ(order.order, order.signature, BigInt(0)); } } \ No newline at end of file diff --git a/src/Unit/Pmm/schemas/order.ts b/src/Unit/Pmm/schemas/order.ts index 2651660..a9727e4 100644 --- a/src/Unit/Pmm/schemas/order.ts +++ b/src/Unit/Pmm/schemas/order.ts @@ -11,7 +11,7 @@ export const pmmOrderQuotationSchema = z.object({ }); export const pmmOrderSchema = z.object({ - quotation: pmmOrderQuotationSchema.default({}), + order: pmmOrderQuotationSchema.default({}), signature: z.string().default(''), success: z.boolean().default(false), error: z.string().default(''), diff --git a/src/services/Aggregator/index.ts b/src/services/Aggregator/index.ts index f04e4c5..1077a53 100644 --- a/src/services/Aggregator/index.ts +++ b/src/services/Aggregator/index.ts @@ -461,11 +461,10 @@ class Aggregator { throw Error(errorParseResult.data.error.reason); } - res.quotation = parseResult.data.quotation; + res.order = parseResult.data.order; res.signature = parseResult.data.signature; res.error = ''; res.success = true; - // return result; } catch(err) { res.error = `${err}`; From ddc8acde7ca6004da69e94cc3ffcabc9d0bb1137 Mon Sep 17 00:00:00 2001 From: KS Date: Fri, 29 Mar 2024 07:27:52 +0300 Subject: [PATCH 40/57] fixed PMM-sample.md --- PMM-sample.md | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/PMM-sample.md b/PMM-sample.md index ad1eb45..344788e 100644 --- a/PMM-sample.md +++ b/PMM-sample.md @@ -257,32 +257,4 @@ async function RFQOrder( console.log("Transaction hash:", transactionResponse.hash); await transactionResponse.wait(); })(); -``` - -RFQ order response example description (`rfqOrder` from example above): - -``` - { - quotation: { - info: '31545611720730315633520017429', - makerAsset: '0xcb2951e90d8dcf16e1fa84ac0c83f48906d6a744', - takerAsset: '0xf223eca06261145b3287a0fefd8cfad371c7eb34', - maker: '0x1ff516e5ce789085cff86d37fc27747df852a80a', - allowedSender: '0x0000000000000000000000000000000000000000', - makingAmount: '193596929', - takingAmount: '10000000000' - }, - signature: '0x8a2f9140a3c3a5734eda763a19c54c5ac909d8a03db37d9804af9115641fd1d35896b66ca6e136c1c89e0478fb7382a4b875d0f74529c1e83601f9383d310dde1b', - success: true, - error: '' - } -``` - - -* info - can be ignored -* makerAsset - your RECEIVING asset (what you expect to receive from contract, in this case USDT) -* takerAsset - your SPENDING asset (what you're giving to contract, in this case ORN) -* maker - can be ignored for now; -* allowedSender - can be ignored for now; -* makingAmount - how much you will RECEIVE (in receiving asset's precision) -* takingAmount - how much you should SPEND (in spending asset's precision) \ No newline at end of file +``` \ No newline at end of file From 9e493457715ed3cc45d02202b05e2d0178fe4881 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 2 Apr 2024 15:07:26 +0300 Subject: [PATCH 41/57] 0.20.79-rc1 --- package-lock.json | 4 +- package.json | 2 +- src/Orion/index.ts | 9 ++- src/Unit/index.ts | 8 ++- src/services/Aggregator/index.ts | 98 ++++++++++++++--------------- src/services/Aggregator/ws/index.ts | 26 +++++--- 6 files changed, 83 insertions(+), 64 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9cc7fbb..f02c880 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.73", + "version": "0.20.79-rc1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.73", + "version": "0.20.79-rc1", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index ee8c258..48979e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.78", + "version": "0.20.79-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Orion/index.ts b/src/Orion/index.ts index 7245c00..8ddf534 100644 --- a/src/Orion/index.ts +++ b/src/Orion/index.ts @@ -21,10 +21,15 @@ export default class Orion { // TODO: get tradable pairs (aggregated) + public logger: ((message: string) => void) | undefined; + constructor( envOrConfig: KnownEnv | EnvConfig = 'production', - overrides?: DeepPartial + overrides?: DeepPartial, + logger?: ((message: string) => void) | undefined ) { + this.logger = logger; + let config: EnvConfig; if (typeof envOrConfig === 'string') { const envConfig = envs[envOrConfig]; @@ -92,7 +97,7 @@ export default class Orion { // api: networkConfig.api, nodeJsonRpc: networkConfig.nodeJsonRpc, services: networkConfig.services, - }); + }, logger); return { ...acc, [chainId]: unit, diff --git a/src/Unit/index.ts b/src/Unit/index.ts index 85d7052..9b504cc 100644 --- a/src/Unit/index.ts +++ b/src/Unit/index.ts @@ -41,7 +41,10 @@ export default class Unit { public readonly contracts: Record; - constructor(config: KnownConfig | VerboseUnitConfig) { + public logger: ((message: string) => void) | undefined; + + constructor(config: KnownConfig | VerboseUnitConfig, logger?: ((message: string) => void) | undefined) { + this.logger = logger; if ('env' in config) { const staticConfig = envs[config.env]; if (!staticConfig) { @@ -118,7 +121,8 @@ export default class Unit { this.aggregator = new Aggregator( this.config.services.aggregator.http, this.config.services.aggregator.ws, - this.config.basicAuth + this.config.basicAuth, + logger, ); this.priceFeed = new PriceFeed( this.config.services.priceFeed.api, diff --git a/src/services/Aggregator/index.ts b/src/services/Aggregator/index.ts index f04e4c5..2cbc6c5 100644 --- a/src/services/Aggregator/index.ts +++ b/src/services/Aggregator/index.ts @@ -19,9 +19,9 @@ import httpToWS from '../../utils/httpToWS.js'; import { ethers } from 'ethers'; import orderSchema from './schemas/orderSchema.js'; import { fetchWithValidation } from 'simple-typed-fetch'; -import hmacSHA256 from "crypto-js/hmac-sha256"; -import Hex from "crypto-js/enc-hex"; -import {pmmOrderSchema} from "../../Unit/Pmm/schemas/order"; +import hmacSHA256 from 'crypto-js/hmac-sha256'; +import Hex from 'crypto-js/enc-hex'; +import { pmmOrderSchema } from '../../Unit/Pmm/schemas/order'; class Aggregator { private readonly apiUrl: string; @@ -34,11 +34,16 @@ class Aggregator { return this.apiUrl; } + public logger: ((message: string) => void) | undefined; + constructor( httpAPIUrl: string, wsAPIUrl: string, - basicAuth?: BasicAuthCredentials + basicAuth?: BasicAuthCredentials, + logger?: ((message: string) => void) | undefined ) { + this.logger = logger; + // const oaUrl = new URL(apiUrl); // const oaWsProtocol = oaUrl.protocol === 'https:' ? 'wss' : 'ws'; // const aggregatorWsUrl = `${oaWsProtocol}://${oaUrl.host + (oaUrl.pathname === '/' @@ -46,7 +51,7 @@ class Aggregator { // : oaUrl.pathname)}/v1`; this.apiUrl = httpAPIUrl; - this.ws = new AggregatorWS(httpToWS(wsAPIUrl)); + this.ws = new AggregatorWS(httpToWS(wsAPIUrl), undefined, logger); this.basicAuth = basicAuth; this.getHistoryAtomicSwaps = this.getHistoryAtomicSwaps.bind(this); @@ -373,24 +378,23 @@ class Aggregator { return fetchWithValidation(url.toString(), atomicSwapHistorySchema, { headers: this.basicAuthHeaders }); }; - - private encode_utf8(s : string) { + private encode_utf8(s: string) { return unescape(encodeURIComponent(s)); } - private sign(message : string, key: string) { + private sign(message: string, key: string) { return hmacSHA256( - this.encode_utf8(message), - this.encode_utf8(key) + this.encode_utf8(message), + this.encode_utf8(key) ).toString(Hex); } - private generateHeaders(body : any, method : string, path : string, timestamp : number, apiKey : string, secretKey : string) { + private generateHeaders(body: any, method: string, path: string, timestamp: number, apiKey: string, secretKey: string) { const sortedBody = Object.keys(body) - .sort() - .map((key) => ( - `${key}=${body[key]}` - )).join('&'); + .sort() + .map((key) => ( + `${key}=${body[key]}` + )).join('&'); const payload = timestamp + method.toUpperCase() + path + sortedBody; @@ -407,40 +411,38 @@ class Aggregator { } public async RFQOrder( - tokenFrom: string, - tokenTo: string, - fromTokenAmount: string, - apiKey: string, // - secretKey: string, - wallet: string - ) : Promise> { - + tokenFrom: string, + tokenTo: string, + fromTokenAmount: string, + apiKey: string, // + secretKey: string, + wallet: string + ): Promise> { // Making the order structure const - path = '/rfq' - , url = `${this.apiUrl}/api/v1/integration/pmm`+path - , headers = { - 'Content-Type': 'application/json', - } - , data = { - "baseToken":tokenFrom, // USDT - "quoteToken":tokenTo, // ORN - "amount": fromTokenAmount, // 100 - "taker": wallet, - "feeBps": 0 - } - , method = 'POST' - , timestamp = Date.now() - , signatureHeaders = this.generateHeaders(data, method, path, timestamp, apiKey, secretKey) - , compiledHeaders = {...headers, ...signatureHeaders.headers, } - , body = JSON.stringify(data) + path = '/rfq'; + const url = `${this.apiUrl}/api/v1/integration/pmm` + path; + const headers = { + 'Content-Type': 'application/json', + }; + const data = { + baseToken: tokenFrom, // USDT + quoteToken: tokenTo, // ORN + amount: fromTokenAmount, // 100 + taker: wallet, + feeBps: 0 + }; + const method = 'POST'; + const timestamp = Date.now(); + const signatureHeaders = this.generateHeaders(data, method, path, timestamp, apiKey, secretKey); + const compiledHeaders = { ...headers, ...signatureHeaders.headers, }; + const body = JSON.stringify(data) ; - - let res = pmmOrderSchema.parse({}); + const res = pmmOrderSchema.parse({}); try { - const result = await fetch(url,{ + const result = await fetch(url, { headers: compiledHeaders, method, body @@ -449,14 +451,13 @@ class Aggregator { const json = await result.json(); const parseResult = pmmOrderSchema.safeParse(json); - if(!parseResult.success) { + if (!parseResult.success) { // Try to parse error answer - const errorSchema = z.object({error: z.object({code: z.number(), reason: z.string()})}); + const errorSchema = z.object({ error: z.object({ code: z.number(), reason: z.string() }) }); const errorParseResult = errorSchema.safeParse(json); - if(!errorParseResult.success) - throw Error(`Unrecognized answer from aggregator: ${json}`); + if (!errorParseResult.success) { throw Error(`Unrecognized answer from aggregator: ${json}`); } throw Error(errorParseResult.data.error.reason); } @@ -466,8 +467,7 @@ class Aggregator { res.error = ''; res.success = true; // return result; - } - catch(err) { + } catch (err) { res.error = `${err}`; } return res; diff --git a/src/services/Aggregator/ws/index.ts b/src/services/Aggregator/ws/index.ts index 69d214c..ab6f6c5 100644 --- a/src/services/Aggregator/ws/index.ts +++ b/src/services/Aggregator/ws/index.ts @@ -66,10 +66,11 @@ type PairConfigSubscription = { type AggregatedOrderbookSubscription = { payload: string + dc?: number callback: ( asks: OrderbookItem[], bids: OrderbookItem[], - pair: string + pair: string, ) => void errorCb?: (message: string) => void } @@ -195,9 +196,10 @@ class AggregatorWS { readonly basicAuth?: BasicAuthCredentials | undefined; - constructor(wsUrl: string, basicAuth?: BasicAuthCredentials) { + constructor(wsUrl: string, basicAuth?: BasicAuthCredentials, logger?: ((message: string) => void) | undefined) { this.wsUrl = wsUrl; this.basicAuth = basicAuth; + this.logger = logger; } private messageQueue: BufferLike[] = []; @@ -252,7 +254,7 @@ class AggregatorWS { subscription: Subscription[T], prevSubscriptionId?: string ) { - const id = type === 'aobus' + const id = type === SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE ? ((subscription as any).payload as string) // TODO: Refactor!!! : uuidv4(); @@ -261,6 +263,14 @@ class AggregatorWS { const subRequest: Json = {}; subRequest['T'] = type; subRequest['id'] = id; + // test + if ('dc' in subscription) { + if (typeof subscription.dc === 'number') { + subRequest['dc'] = subscription.dc; + } + } + + this.logger?.('test'); if ('payload' in subscription) { if (typeof subscription.payload === 'string') { @@ -369,11 +379,11 @@ class AggregatorWS { delete this.subscriptions[SubscriptionType.ASSET_PAIR_CONFIG_UPDATES_SUBSCRIBE]?.[newestSubId]; // !!! swap info subscription is uuid that contains hyphen } else if (isOrderBooksSubscription(newestSubId)) { // is pair name(AGGREGATED_ORDER_BOOK_UPDATE) - const aobSubscriptions = this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE]; - if (aobSubscriptions) { - const targetAobSub = Object.entries(aobSubscriptions).find(([, value]) => value?.payload === newestSubId); - if (targetAobSub) { - const [key] = targetAobSub; + const aobusSubscriptions = this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE]; + if (aobusSubscriptions) { + const targetAobusSub = Object.entries(aobusSubscriptions).find(([, value]) => value?.payload === newestSubId); + if (targetAobusSub) { + const [key] = targetAobusSub; delete this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE]?.[key]; } } From 57cffe5eff92d976ef9a5e169eed93f7c3bee645 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 2 Apr 2024 15:09:57 +0300 Subject: [PATCH 42/57] 0.20.80-rc1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 48979e1..14d3066 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.79-rc1", + "version": "0.20.80-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 84a0fe7a86fb9646a65602b507f0a53c3482df37 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 2 Apr 2024 15:18:35 +0300 Subject: [PATCH 43/57] fix: remove test logger --- package.json | 2 +- src/services/Aggregator/ws/index.ts | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index 14d3066..d19b27e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.80-rc1", + "version": "0.20.80-rc2", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Aggregator/ws/index.ts b/src/services/Aggregator/ws/index.ts index ab6f6c5..55c875e 100644 --- a/src/services/Aggregator/ws/index.ts +++ b/src/services/Aggregator/ws/index.ts @@ -263,15 +263,12 @@ class AggregatorWS { const subRequest: Json = {}; subRequest['T'] = type; subRequest['id'] = id; - // test if ('dc' in subscription) { if (typeof subscription.dc === 'number') { subRequest['dc'] = subscription.dc; } } - this.logger?.('test'); - if ('payload' in subscription) { if (typeof subscription.payload === 'string') { subRequest['S'] = subscription.payload; From c204ebf0b3c6ce3487822ad2ce7cd2586c37e2ac Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 2 Apr 2024 16:19:36 +0300 Subject: [PATCH 44/57] fix: space --- src/services/Aggregator/ws/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/Aggregator/ws/index.ts b/src/services/Aggregator/ws/index.ts index 55c875e..f0f0e8f 100644 --- a/src/services/Aggregator/ws/index.ts +++ b/src/services/Aggregator/ws/index.ts @@ -263,6 +263,7 @@ class AggregatorWS { const subRequest: Json = {}; subRequest['T'] = type; subRequest['id'] = id; + if ('dc' in subscription) { if (typeof subscription.dc === 'number') { subRequest['dc'] = subscription.dc; From 6b95e76a83c8a49b867f5f936c69f6ad018c2177 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 2 Apr 2024 16:29:23 +0300 Subject: [PATCH 45/57] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f02c880..9e4bc27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.79-rc1", + "version": "0.20.79", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.79-rc1", + "version": "0.20.79", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index d19b27e..b9093ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.80-rc2", + "version": "0.20.80-rc3", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 201a177938f98eb709c4aaa847ca04d145b77ce2 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 2 Apr 2024 16:30:24 +0300 Subject: [PATCH 46/57] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b9093ae..986ea3e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.80-rc3", + "version": "0.20.79", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 8f840aede201d641e9ef7228edad726739a8e85e Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Tue, 2 Apr 2024 15:10:28 +0100 Subject: [PATCH 47/57] feat: updated readme file --- README.md | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index b06f8c3..0fec57d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,8 @@ +[//]: # ( Orion Protocol SDK logo)
- Orion Protocol SDK logo -

Orion Protocol SDK

+

Lumia Stream SDK

Use CEX and DEX liquidity without KYC.

@@ -14,16 +10,15 @@ ![npm bundle size (version)](https://img.shields.io/bundlephobia/minzip/@orionprotocol/sdk) [![Downloads](https://img.shields.io/npm/dm/@orionprotocol/sdk.svg)](https://www.npmjs.com/package/@orionprotocol/sdk) -Do you want to integrate the Orion protocol into your application? See [integration guide](./docs/INTEGRATION.md) +Do you want to integrate the Lumia Stream protocol into your application? See [integration guide](./docs/INTEGRATION.md) ## Overview -Orion Software Developer Kit is a set of functions and methods that allow dApp developers connect to the superior aggregated liquidity of Orion Protocol which combines orderbooks of centralized exchanges as well decentralized automatic market makers such as Uniswap or Spookyswap across several supported blockchains. -Through this connection, developers using the SDK can perform a wide range of actions, including swapping selected tokens using Orion’s aggregated liquidity, obtaining relevant market information through subscriptions, add and remove liquidity to Orion’s pools. +Lumia Stream Developer Kit, natively built into Lumia, is a set of functions and methods that allow dApp developers to connect to the superior aggregated liquidity of Lumia Stream which combines orderbooks of centralized exchanges as well as decentralized Automatic Market Makers (AMMs) such as Uniswap, PancakeSwap, and Curve, across several supported blockchains. Through this connection, developers using the SDK can perform a wide range of actions, including swapping selected tokens, obtaining relevant market information through subscriptions, and more. ## API Key -Orion’s SDK is free to use and does not require an API key or registration. Refer to integration examples for more detailed information. +Lumia Stream’s SDK is free to use and does not require an API key or registration. Refer to integration examples for more detailed information. - [Overview](#overview) - [API Key](#api-key) @@ -33,7 +28,7 @@ Orion’s SDK is free to use and does not require an API key or registration. Re - [High level methods](#high-level-methods) - [Get assets](#get-assets) - [Get pairs](#get-pairs) - - [Get Orion Bridge history](#get-orion-bridge-history) + - [Get Lumia Stream Bridge history](#get-lumia-stream-bridge-history) - [Bridge swap](#bridge-swap) - [Withdraw](#withdraw) - [Deposit](#deposit) @@ -145,7 +140,7 @@ const pairs = await orion.getPairs("spot"); // 'spot' // } ``` -### Get Orion Bridge history +### Get Lumia Stream Bridge history ```ts const bridgeHistory = await orion.bridge.getHistory( @@ -722,7 +717,7 @@ switch (data.type) { ``` ## PMM -PMM allows institutional traders to request RFQ orders from Orion and then fill them. +PMM allows institutional traders to request RFQ orders from Lumia Stream and then fill them. RFQ order allows trader to fix the price for a certain time interval (up to 90 seconds, including the order settlement time interval on blockchain). From 9afda4260b5d88d33db063039f8ed01e9480e972 Mon Sep 17 00:00:00 2001 From: KS Date: Thu, 4 Apr 2024 17:32:37 +0300 Subject: [PATCH 48/57] removed crypto-js dependency --- src/services/Aggregator/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/services/Aggregator/index.ts b/src/services/Aggregator/index.ts index 1077a53..09966bf 100644 --- a/src/services/Aggregator/index.ts +++ b/src/services/Aggregator/index.ts @@ -19,8 +19,9 @@ import httpToWS from '../../utils/httpToWS.js'; import { ethers } from 'ethers'; import orderSchema from './schemas/orderSchema.js'; import { fetchWithValidation } from 'simple-typed-fetch'; -import hmacSHA256 from "crypto-js/hmac-sha256"; -import Hex from "crypto-js/enc-hex"; +// import hmacSHA256 from "crypto-js/hmac-sha256"; +// import Hex from "crypto-js/enc-hex"; +const crypto = require('crypto') import {pmmOrderSchema} from "../../Unit/Pmm/schemas/order"; class Aggregator { @@ -379,10 +380,9 @@ class Aggregator { } private sign(message : string, key: string) { - return hmacSHA256( - this.encode_utf8(message), - this.encode_utf8(key) - ).toString(Hex); + return crypto.createHmac('sha256', this.encode_utf8(key)) + .update(this.encode_utf8(message)) + .digest('hex'); } private generateHeaders(body : any, method : string, path : string, timestamp : number, apiKey : string, secretKey : string) { From b6370c97aa569f2b36227053db7bb46d255637d6 Mon Sep 17 00:00:00 2001 From: KS Date: Thu, 4 Apr 2024 17:34:53 +0300 Subject: [PATCH 49/57] increased version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a307337..ace8c14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.79-rc1", + "version": "0.20.80-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 7b463dc82346e0b95d3cc4ba303a0417f0e93643 Mon Sep 17 00:00:00 2001 From: kigastu Date: Thu, 4 Apr 2024 17:58:03 +0300 Subject: [PATCH 50/57] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 910785d..7b806e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.80-rc1", + "version": "0.20.80", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 5e1922411489bd3292fbb3e38f07173d3e60600a Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Thu, 4 Apr 2024 18:54:33 +0300 Subject: [PATCH 51/57] fix: build --- package-lock.json | 17 ++--------------- package.json | 2 +- src/services/Aggregator/index.ts | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9e4bc27..3e9a96b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.79", + "version": "0.20.81", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.79", + "version": "0.20.81", "hasInstallScript": true, "license": "ISC", "dependencies": { @@ -40,7 +40,6 @@ "@babel/plugin-syntax-import-assertions": "^7.20.0", "@tsconfig/esm": "^1.0.4", "@tsconfig/strictest": "^2.0.1", - "@types/crypto-js": "^4.2.2", "@types/express": "^4.17.17", "@types/jest": "^29.5.1", "@types/node": "^20.5.1", @@ -2547,12 +2546,6 @@ "@types/node": "*" } }, - "node_modules/@types/crypto-js": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", - "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==", - "dev": true - }, "node_modules/@types/eslint": { "version": "8.44.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.2.tgz", @@ -13617,12 +13610,6 @@ "@types/node": "*" } }, - "@types/crypto-js": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", - "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==", - "dev": true - }, "@types/eslint": { "version": "8.44.2", "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.44.2.tgz", diff --git a/package.json b/package.json index 7b806e5..bf41f6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.80", + "version": "0.20.81", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Aggregator/index.ts b/src/services/Aggregator/index.ts index dd8416f..0e505c6 100644 --- a/src/services/Aggregator/index.ts +++ b/src/services/Aggregator/index.ts @@ -19,10 +19,10 @@ import httpToWS from '../../utils/httpToWS.js'; import { ethers } from 'ethers'; import orderSchema from './schemas/orderSchema.js'; import { fetchWithValidation } from 'simple-typed-fetch'; +import { pmmOrderSchema } from '../../Unit/Pmm/schemas/order'; // import hmacSHA256 from "crypto-js/hmac-sha256"; // import Hex from "crypto-js/enc-hex"; -const crypto = require('crypto') -import {pmmOrderSchema} from "../../Unit/Pmm/schemas/order"; +// const crypto = require('crypto') class Aggregator { private readonly apiUrl: string; @@ -379,14 +379,16 @@ class Aggregator { return fetchWithValidation(url.toString(), atomicSwapHistorySchema, { headers: this.basicAuthHeaders }); }; - private encode_utf8(s: string) { - return unescape(encodeURIComponent(s)); - } + // private encode_utf8(s: string) { + // return unescape(encodeURIComponent(s)); + // } - private sign(message : string, key: string) { - return crypto.createHmac('sha256', this.encode_utf8(key)) - .update(this.encode_utf8(message)) - .digest('hex'); + // @ts-expect-error: TODO: please remove this line! + private sign(message: string, key: string) { + // return crypto.createHmac('sha256', this.encode_utf8(key)) + // .update(this.encode_utf8(message)) + // .digest('hex'); + return ''; } private generateHeaders(body: any, method: string, path: string, timestamp: number, apiKey: string, secretKey: string) { From 515888a268b594e6ace470d57301724eb46f3e90 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Mon, 8 Apr 2024 15:33:45 +0300 Subject: [PATCH 52/57] getStableCoins --- package-lock.json | 4 ++-- package.json | 2 +- src/services/Aggregator/index.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3e9a96b..239694a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.81", + "version": "0.20.82", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.81", + "version": "0.20.82", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index bf41f6f..15ace9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.81", + "version": "0.20.82-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Aggregator/index.ts b/src/services/Aggregator/index.ts index 0e505c6..fd7fec8 100644 --- a/src/services/Aggregator/index.ts +++ b/src/services/Aggregator/index.ts @@ -61,6 +61,7 @@ class Aggregator { this.getPairsList = this.getPairsList.bind(this); this.getSwapInfo = this.getSwapInfo.bind(this); this.getTradeProfits = this.getTradeProfits.bind(this); + this.getStableCoins = this.getStableCoins.bind(this); this.placeAtomicSwap = this.placeAtomicSwap.bind(this); this.placeOrder = this.placeOrder.bind(this); this.cancelOrder = this.cancelOrder.bind(this); @@ -340,6 +341,16 @@ class Aggregator { ); }; + getStableCoins = () => { + const url = new URL(`${this.apiUrl}/api/v1/tokens/stable/`); + return fetchWithValidation( + url.toString(), + z.array(z.string()), + { headers: this.basicAuthHeaders }, + errorSchema, + ); + }; + /** * Placing atomic swap. Placement must take place on the target chain. * @param secretHash Secret hash From b1920c91b9b8d1165775e454d4a3e1678b10a97e Mon Sep 17 00:00:00 2001 From: kigastu Date: Mon, 8 Apr 2024 15:52:32 +0300 Subject: [PATCH 53/57] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 15ace9e..e2cb3dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.82-rc1", + "version": "0.20.82", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 96d7216939c814bcabac02793adc61e62c074af9 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Fri, 19 Apr 2024 10:15:15 +0100 Subject: [PATCH 54/57] feat: added new base chain --- src/config/chains.json | 13 ++++++++ src/config/envs.json | 42 +++++++++++++++++++++++-- src/constants/chains.ts | 1 + src/constants/networkCodes.ts | 2 +- src/constants/uppercasedNetworkCodes.ts | 2 +- src/types.ts | 3 +- 6 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/config/chains.json b/src/config/chains.json index 9d21aae..3fecfd8 100644 --- a/src/config/chains.json +++ b/src/config/chains.json @@ -232,5 +232,18 @@ "WETH": "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7", "curveRegistry": "" } + }, + "8453": { + "chainId": "8453", + "label": "Base", + "shortName": "BASE", + "code": "base", + "baseCurrencyName": "ETH", + "rpc": "https://mainnet.base.org/", + "explorer": "https://basescan.org/", + "contracts": { + "WETH": "0x4200000000000000000000000000000000000006", + "curveRegistry": "" + } } } diff --git a/src/config/envs.json b/src/config/envs.json index a6c3988..12e87f9 100644 --- a/src/config/envs.json +++ b/src/config/envs.json @@ -182,6 +182,24 @@ "http": "/orion-indexer/" } } + }, + "8453": { + "api": "https://trade.orion.xyz/base-mainnet", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } } } }, @@ -429,7 +447,7 @@ } }, "2525": { - "api": "https://trade.orion.xyz/inevm-mainnet", + "api": "https://staging.orion.xyz/inevm-mainnet", "services": { "aggregator": { "http": "/backend", @@ -447,7 +465,7 @@ } }, "59144": { - "api": "https://trade.orion.xyz/linea-mainnet", + "api": "https://staging.orion.xyz/linea-mainnet", "services": { "aggregator": { "http": "/backend", @@ -465,7 +483,25 @@ } }, "43114": { - "api": "https://trade.orion.xyz/avalanche-c-chain", + "api": "https://staging.orion.xyz/avalanche-c-chain", + "services": { + "aggregator": { + "http": "/backend", + "ws": "/v1" + }, + "blockchain": { + "http": "" + }, + "priceFeed": { + "all": "/price-feed" + }, + "indexer": { + "http": "/orion-indexer/" + } + } + }, + "8453": { + "api": "https://staging.orion.xyz/base-mainnet", "services": { "aggregator": { "http": "/backend", diff --git a/src/constants/chains.ts b/src/constants/chains.ts index aac8213..1fb8ff3 100644 --- a/src/constants/chains.ts +++ b/src/constants/chains.ts @@ -20,4 +20,5 @@ export const productionChains = [ SupportedChainId.INEVM, SupportedChainId.LINEA, SupportedChainId.AVAX, + SupportedChainId.BASE, ]; diff --git a/src/constants/networkCodes.ts b/src/constants/networkCodes.ts index c3a5dad..498e149 100644 --- a/src/constants/networkCodes.ts +++ b/src/constants/networkCodes.ts @@ -1 +1 @@ -export default ['ftm', 'bsc', 'eth', 'polygon', 'okc', 'arb', 'drip', 'opbnb', 'inevm', 'linea', 'avax'] as const; +export default ['ftm', 'bsc', 'eth', 'polygon', 'okc', 'arb', 'drip', 'opbnb', 'inevm', 'linea', 'avax', 'base'] as const; diff --git a/src/constants/uppercasedNetworkCodes.ts b/src/constants/uppercasedNetworkCodes.ts index 6b8e312..e69605f 100644 --- a/src/constants/uppercasedNetworkCodes.ts +++ b/src/constants/uppercasedNetworkCodes.ts @@ -1 +1 @@ -export default ['FTM', 'BSC', 'ETH', 'POLYGON', 'OKC', 'ARB', 'OPBNB', 'INEVM', 'LINEA', 'AVAX'] as const; +export default ['FTM', 'BSC', 'ETH', 'POLYGON', 'OKC', 'ARB', 'OPBNB', 'INEVM', 'LINEA', 'AVAX', 'BASE'] as const; diff --git a/src/types.ts b/src/types.ts index 5828296..eacf494 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,7 +3,7 @@ import type factories from './constants/factories.js'; import type { BigNumber } from 'bignumber.js'; import type subOrderStatuses from './constants/subOrderStatuses.js'; import type positionStatuses from './constants/positionStatuses.js'; -import type { knownEnvs } from './config/schemas/index.js'; +import type { knownEnvs } from './config/schemas'; import type getHistory from './Orion/bridge/getHistory.js'; export type DeepPartial = T extends object ? { @@ -91,6 +91,7 @@ export enum SupportedChainId { INEVM = '2525', LINEA = '59144', AVAX = '43114', + BASE = '8453', POLYGON_TESTNET = '80001', FANTOM_TESTNET = '4002', From 6ddfbafb27e71b9c3b352d6643d012f4aaa18556 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Fri, 19 Apr 2024 10:15:49 +0100 Subject: [PATCH 55/57] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e2cb3dc..4b51774 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.82", + "version": "0.20.83", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 5e73e853ca2b7b86d259adb90e5f7c1797312a35 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Fri, 19 Apr 2024 17:07:44 +0300 Subject: [PATCH 56/57] auto slippage --- package.json | 2 +- src/services/Aggregator/schemas/swapInfoSchema.ts | 1 + src/services/Aggregator/ws/index.ts | 1 + src/services/Aggregator/ws/schemas/swapInfoSchema.ts | 1 + src/types.ts | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b51774..e643eea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.83", + "version": "0.20.84-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Aggregator/schemas/swapInfoSchema.ts b/src/services/Aggregator/schemas/swapInfoSchema.ts index ecbd440..aed6d09 100644 --- a/src/services/Aggregator/schemas/swapInfoSchema.ts +++ b/src/services/Aggregator/schemas/swapInfoSchema.ts @@ -49,6 +49,7 @@ const swapInfoBase = z.object({ mi: z.number().optional(), // market amount in, USD d: z.string().optional(), // difference in available amount in/out (USD) and market amount out/in (USD) in percentage }).optional(), + autoSlippage: z.number().optional(), }); const swapInfoByAmountIn = swapInfoBase.extend({ diff --git a/src/services/Aggregator/ws/index.ts b/src/services/Aggregator/ws/index.ts index f0f0e8f..fb1f88a 100644 --- a/src/services/Aggregator/ws/index.ts +++ b/src/services/Aggregator/ws/index.ts @@ -541,6 +541,7 @@ class AggregatorWS { marketAmountIn: json.usd.mi, difference: json.usd.d, }, + autoSlippage: json.sl, }; switch (json.k) { // kind diff --git a/src/services/Aggregator/ws/schemas/swapInfoSchema.ts b/src/services/Aggregator/ws/schemas/swapInfoSchema.ts index 3c8a5d4..eb23200 100644 --- a/src/services/Aggregator/ws/schemas/swapInfoSchema.ts +++ b/src/services/Aggregator/ws/schemas/swapInfoSchema.ts @@ -48,6 +48,7 @@ const swapInfoSchemaBase = baseMessageSchema.extend({ mi: z.number().optional(), // market amount in, USD d: z.string().optional(), // difference in available amount in/out (USD) and market amount out/in (USD) in percentage }).optional(), + sl: z.number().optional(), }); const swapInfoSchemaByAmountIn = swapInfoSchemaBase.extend({ diff --git a/src/types.ts b/src/types.ts index eacf494..6a3513a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -210,6 +210,7 @@ export type SwapInfoBase = { marketAmountIn: number | undefined difference: string | undefined } | undefined + autoSlippage: number | undefined } export type SwapInfoByAmountIn = SwapInfoBase & { From 1a7bbb5b164fc300a6b368d47ef3394271965ce8 Mon Sep 17 00:00:00 2001 From: kigastu Date: Fri, 19 Apr 2024 17:31:57 +0300 Subject: [PATCH 57/57] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e643eea..1249c89 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.84-rc1", + "version": "0.20.84", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js",