From d4c790c8bf6da17168575fa04b9d1c9fe071f8e4 Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Thu, 12 May 2022 23:24:45 +0400 Subject: [PATCH] Bump zod version --- package-lock.json | 18 +- package.json | 4 +- src/services/OrionAggregator/index.ts | 157 ++++++++-------- src/services/OrionAnalytics/index.ts | 10 +- src/services/OrionBlockchain/index.ts | 256 +++++++++++--------------- src/services/PriceFeed/index.ts | 6 +- 6 files changed, 201 insertions(+), 250 deletions(-) diff --git a/package-lock.json b/package-lock.json index 096c54e..de0aab9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.4.0", + "version": "0.5.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.4.0", + "version": "0.5.8", "license": "ISC", "dependencies": { "@ethersproject/abstract-signer": "^5.6.0", @@ -25,7 +25,7 @@ "tiny-invariant": "^1.2.0", "uuid": "^8.3.2", "ws": "^8.5.0", - "zod": "^3.14.4" + "zod": "^3.16.0" }, "devDependencies": { "@typechain/ethers-v5": "^10.0.0", @@ -11099,9 +11099,9 @@ "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=" }, "node_modules/zod": { - "version": "3.14.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.14.4.tgz", - "integrity": "sha512-U9BFLb2GO34Sfo9IUYp0w3wJLlmcyGoMd75qU9yf+DrdGA4kEx6e+l9KOkAlyUO0PSQzZCa3TR4qVlcmwqSDuw==", + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.16.0.tgz", + "integrity": "sha512-szrIkryADbTM+xBt2a1KoS2CJQXec4f9xG78bj5MJeEH/XqmmHpnO+fG3IE115AKBJak+2HrbxLZkc9mhdbDKA==", "funding": { "url": "https://github.com/sponsors/colinhacks" } @@ -18842,9 +18842,9 @@ "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=" }, "zod": { - "version": "3.14.4", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.14.4.tgz", - "integrity": "sha512-U9BFLb2GO34Sfo9IUYp0w3wJLlmcyGoMd75qU9yf+DrdGA4kEx6e+l9KOkAlyUO0PSQzZCa3TR4qVlcmwqSDuw==" + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.16.0.tgz", + "integrity": "sha512-szrIkryADbTM+xBt2a1KoS2CJQXec4f9xG78bj5MJeEH/XqmmHpnO+fG3IE115AKBJak+2HrbxLZkc9mhdbDKA==" } } } diff --git a/package.json b/package.json index 0e656a8..e49be63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.5.8", + "version": "0.5.9", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", @@ -76,7 +76,7 @@ "tiny-invariant": "^1.2.0", "uuid": "^8.3.2", "ws": "^8.5.0", - "zod": "^3.14.4" + "zod": "^3.16.0" }, "homepage": "https://github.com/orionprotocol/sdk#readme", "files": [ diff --git a/src/services/OrionAggregator/index.ts b/src/services/OrionAggregator/index.ts index cc3f4ef..b60523d 100644 --- a/src/services/OrionAggregator/index.ts +++ b/src/services/OrionAggregator/index.ts @@ -45,14 +45,12 @@ class OrionAggregator { return `https://${this.apiUrl}/backend`; } - getPairsList() { - return fetchWithValidation( - `${this.aggregatorUrl}/api/v1/pairs/list`, - z.array(z.string()), - ); - } + getPairsList = () => fetchWithValidation( + `${this.aggregatorUrl}/api/v1/pairs/list`, + z.array(z.string()), + ); - getAggregatedOrderbook(pair: string, depth = 20) { + getAggregatedOrderbook = (pair: string, depth = 20) => { const url = new URL(`${this.aggregatorUrl}/api/v1/orderbook`); url.searchParams.append('pair', pair); url.searchParams.append('depth', depth.toString()); @@ -62,9 +60,14 @@ class OrionAggregator { undefined, errorSchema, ); - } + }; - getExchangeOrderbook(pair: string, exchange: string, depth = 20, filterByBrokerBalances: boolean | null = null) { + getExchangeOrderbook = ( + pair: string, + exchange: string, + depth = 20, + filterByBrokerBalances: boolean | null = null, + ) => { const url = new URL(`${this.aggregatorUrl}/api/v1/orderbook/${exchange}/${pair}`); url.searchParams.append('pair', pair); url.searchParams.append('depth', depth.toString()); @@ -77,40 +80,34 @@ class OrionAggregator { undefined, errorSchema, ); - } + }; - getPairConfigs() { - return fetchWithValidation( - `${this.aggregatorUrl}/api/v1/pairs/exchangeInfo`, - exchangeInfoSchema, - undefined, - errorSchema, - ); - } + getPairConfigs = () => fetchWithValidation( + `${this.aggregatorUrl}/api/v1/pairs/exchangeInfo`, + exchangeInfoSchema, + undefined, + errorSchema, + ); - getPairConfig(assetPair: string) { - return fetchWithValidation( - `${this.aggregatorUrl}/api/v1/pairs/exchangeInfo/${assetPair}`, - pairConfigSchema, - undefined, - errorSchema, - ); - } + getPairConfig = (assetPair: string) => fetchWithValidation( + `${this.aggregatorUrl}/api/v1/pairs/exchangeInfo/${assetPair}`, + pairConfigSchema, + undefined, + errorSchema, + ); - checkWhitelisted(address: string) { - return fetchWithValidation( - `${this.aggregatorUrl}/api/v1/whitelist/check?address=${address}`, - z.boolean(), - undefined, - errorSchema, - ); - } + checkWhitelisted = (address: string) => fetchWithValidation( + `${this.aggregatorUrl}/api/v1/whitelist/check?address=${address}`, + z.boolean(), + undefined, + errorSchema, + ); - placeOrder( + placeOrder = ( signedOrder: SignedOrder, isCreateInternalOrder: boolean, partnerId?: string, - ) { + ) => { const headers = { 'Content-Type': 'application/json', Accept: 'application/json', @@ -136,33 +133,31 @@ class OrionAggregator { }, errorSchema, ); - } + }; - cancelOrder(signedCancelOrderRequest: SignedCancelOrderRequest) { - return fetchWithValidation( - `${this.aggregatorUrl}/api/v1/order`, - cancelOrderSchema, - { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - body: JSON.stringify({ - ...signedCancelOrderRequest, - sender: signedCancelOrderRequest.senderAddress, - }), + cancelOrder = (signedCancelOrderRequest: SignedCancelOrderRequest) => fetchWithValidation( + `${this.aggregatorUrl}/api/v1/order`, + cancelOrderSchema, + { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', }, - errorSchema, - ); - } + body: JSON.stringify({ + ...signedCancelOrderRequest, + sender: signedCancelOrderRequest.senderAddress, + }), + }, + errorSchema, + ); - getSwapInfo( + getSwapInfo = ( type: 'exactSpend' | 'exactReceive', assetIn: string, assetOut: string, amount: string, - ) { + ) => { const url = new URL(`${this.aggregatorUrl}/api/v1/swap`); url.searchParams.append('assetIn', assetIn); url.searchParams.append('assetOut', assetOut); @@ -178,9 +173,9 @@ class OrionAggregator { undefined, errorSchema, ); - } + }; - getLockedBalance(address: string, currency: string) { + getLockedBalance = (address: string, currency: string) => { const url = new URL(`${this.aggregatorUrl}/api/v1/address/balance/reserved/${currency}`); url.searchParams.append('address', address); return fetchWithValidation( @@ -191,13 +186,13 @@ class OrionAggregator { undefined, errorSchema, ); - } + }; - getTradeProfits( + getTradeProfits = ( symbol: string, amount: BigNumber, isBuy: boolean, - ) { + ) => { const url = new URL(`${this.aggregatorUrl}/api/v1/orderBenefits`); url.searchParams.append('symbol', symbol); url.searchParams.append('amount', amount.toString()); @@ -209,7 +204,7 @@ class OrionAggregator { undefined, errorSchema, ); - } + }; /** * Placing atomic swap. Placement must take place on the target chain. @@ -217,39 +212,37 @@ class OrionAggregator { * @param sourceNetworkCode uppercase, e.g. BSC, ETH * @returns Fetch promise */ - placeAtomicSwap( + placeAtomicSwap = ( secretHash: string, sourceNetworkCode: string, - ) { - return fetchWithValidation( - `${this.aggregatorUrl}/api/v1/atomic-swap`, - placeAtomicSwapSchema, - { - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - method: 'POST', - body: JSON.stringify({ - secretHash, - sourceNetworkCode, - }), + ) => fetchWithValidation( + `${this.aggregatorUrl}/api/v1/atomic-swap`, + placeAtomicSwapSchema, + { + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', }, - errorSchema, - ); - } + method: 'POST', + body: JSON.stringify({ + secretHash, + sourceNetworkCode, + }), + }, + errorSchema, + ); /** * Get placed atomic swaps. Each atomic swap received from this list has a target chain corresponding to this Orion Aggregator * @param sender Sender address * @returns Fetch promise */ - getHistoryAtomicSwaps(sender: string, limit = 1000) { + getHistoryAtomicSwaps = (sender: string, limit = 1000) => { const url = new URL(`${this.aggregatorUrl}/api/v1/atomic-swap/history/all`); url.searchParams.append('sender', sender); url.searchParams.append('limit', limit.toString()); return fetchWithValidation(url.toString(), atomicSwapHistorySchema); - } + }; } export * as schemas from './schemas'; export * as ws from './ws'; diff --git a/src/services/OrionAnalytics/index.ts b/src/services/OrionAnalytics/index.ts index a55281e..722b1f5 100644 --- a/src/services/OrionAnalytics/index.ts +++ b/src/services/OrionAnalytics/index.ts @@ -10,10 +10,8 @@ export default class OrionAnalytics { this.getOverview = this.getOverview.bind(this); } - getOverview() { - return fetchWithValidation( - `https://${this.apiUrl}/api/stats/overview`, - overviewSchema, - ); - } + getOverview = () => fetchWithValidation( + `https://${this.apiUrl}/api/stats/overview`, + overviewSchema, + ); } diff --git a/src/services/OrionBlockchain/index.ts b/src/services/OrionBlockchain/index.ts index 77c935e..810ac93 100644 --- a/src/services/OrionBlockchain/index.ts +++ b/src/services/OrionBlockchain/index.ts @@ -114,183 +114,145 @@ class OrionBlockchain { }; } - getAuthToken() { - return fetchWithValidation(`https://${this.apiUrl}/api/auth/token`, z.object({ token: z.string() })); - } + getAuthToken = () => fetchWithValidation(`https://${this.apiUrl}/api/auth/token`, z.object({ token: z.string() })); - getCirculatingSupply() { - return fetchWithValidation(`https://${this.apiUrl}/api/circulating-supply`, z.number()); - } + getCirculatingSupply = () => fetchWithValidation(`https://${this.apiUrl}/api/circulating-supply`, z.number()); - getInfo() { - return fetchWithValidation(`https://${this.apiUrl}/api/info`, infoSchema); - } + getInfo = () => fetchWithValidation(`https://${this.apiUrl}/api/info`, infoSchema); - getPoolsConfig() { - return fetchWithValidation(`https://${this.apiUrl}/api/pools/config`, poolsConfigSchema); - } + getPoolsConfig = () => fetchWithValidation(`https://${this.apiUrl}/api/pools/config`, poolsConfigSchema); - getPoolsInfo() { - return fetchWithValidation(`https://${this.apiUrl}/api/pools/info`, poolsInfoSchema); - } + getPoolsInfo = () => fetchWithValidation(`https://${this.apiUrl}/api/pools/info`, poolsInfoSchema); - getHistory(address: string) { - return fetchWithValidation(`https://${this.apiUrl}/api/history/${address}`, historySchema); - } + getHistory = (address: string) => fetchWithValidation(`https://${this.apiUrl}/api/history/${address}`, historySchema); - getPrices() { - return fetchWithValidation(`https://${this.apiUrl}/api/prices`, z.record(z.string()).transform(makePartial)); - } + getPrices = () => fetchWithValidation(`https://${this.apiUrl}/api/prices`, z.record(z.string()).transform(makePartial)); - getTokensFee() { - return fetchWithValidation(`https://${this.apiUrl}/api/tokensFee`, z.record(z.string()).transform(makePartial)); - } + getTokensFee = () => fetchWithValidation(`https://${this.apiUrl}/api/tokensFee`, z.record(z.string()).transform(makePartial)); - getGasPriceWei() { - return fetchWithValidation(`https://${this.apiUrl}/api/gasPrice`, z.string()); - } + getGasPriceWei = () => fetchWithValidation(`https://${this.apiUrl}/api/gasPrice`, z.string()); - checkFreeRedeemAvailable(walletAddress: string) { - return fetchWithValidation(`https://${this.apiUrl}/api/atomic/has-free-redeem/${walletAddress}`, z.boolean()); - } + checkFreeRedeemAvailable = (walletAddress: string) => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/has-free-redeem/${walletAddress}`, + z.boolean(), + ); - redeemAtomicSwap( + redeemAtomicSwap = ( redeemOrder: z.infer, secret: string, sourceNetwork: string, - ) { - return fetchWithValidation( - `https://${this.apiUrl}/api/atomic/matcher-redeem`, - z.string(), - { - method: 'POST', - body: JSON.stringify({ - order: redeemOrder, - secret, - sourceNetwork, - }), - headers: { - 'Content-Type': 'application/json', - }, + ) => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/matcher-redeem`, + z.string(), + { + method: 'POST', + body: JSON.stringify({ + order: redeemOrder, + secret, + sourceNetwork, + }), + headers: { + 'Content-Type': 'application/json', }, - ); - } + }, + ); - redeem2AtomicSwaps( + redeem2AtomicSwaps = ( redeemOrder1: z.infer, secret1: string, redeemOrder2: z.infer, secret2: string, sourceNetwork: string, - ) { - return fetchWithValidation( - `https://${this.apiUrl}/api/atomic/matcher-redeem2atomics`, - z.string(), - { - method: 'POST', - body: JSON.stringify({ - order1: redeemOrder1, - secret1, - order2: redeemOrder2, - secret2, - sourceNetwork, - }), - headers: { - 'Content-Type': 'application/json', - }, + ) => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/matcher-redeem2atomics`, + z.string(), + { + method: 'POST', + body: JSON.stringify({ + order1: redeemOrder1, + secret1, + order2: redeemOrder2, + secret2, + sourceNetwork, + }), + headers: { + 'Content-Type': 'application/json', }, - ); - } + }, + ); - checkRedeem(secretHash: string) { - return fetchWithValidation( - `https://${this.apiUrl}/api/atomic/matcher-redeem/${secretHash}`, - z.enum(['OK', 'FAIL']).nullable(), - ); - } + checkRedeem = (secretHash: string) => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/matcher-redeem/${secretHash}`, + z.enum(['OK', 'FAIL']).nullable(), + ); - checkRedeem2Atomics(firstSecretHash: string, secondSecretHash: string) { - return fetchWithValidation( - `https://${this.apiUrl}/api/atomic/matcher-redeem/${firstSecretHash}-${secondSecretHash}`, - z.enum(['OK', 'FAIL']).nullable(), - ); - } + checkRedeem2Atomics = (firstSecretHash: string, secondSecretHash: string) => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/matcher-redeem/${firstSecretHash}-${secondSecretHash}`, + z.enum(['OK', 'FAIL']).nullable(), + ); - getBlockNumber() { - return fetchWithValidation(`https://${this.apiUrl}/api/blocknumber`, z.number().int()); - } + getBlockNumber = () => fetchWithValidation(`https://${this.apiUrl}/api/blocknumber`, z.number().int()); - getIDOInfo() { - return fetchWithValidation(`https://${this.apiUrl}/api/solarflare`, IDOSchema); - } + getIDOInfo = () => fetchWithValidation(`https://${this.apiUrl}/api/solarflare`, IDOSchema); - checkAuth(headers: IAdminAuthHeaders) { - return fetchWithValidation(`https://${this.apiUrl}/api/auth/check`, z.object({ - auth: z.boolean(), - }), { headers }); - } + checkAuth = (headers: IAdminAuthHeaders) => fetchWithValidation(`https://${this.apiUrl}/api/auth/check`, z.object({ + auth: z.boolean(), + }), { headers }); - getPoolsList(headers: IAdminAuthHeaders) { - return fetchWithValidation( - `https://${this.apiUrl}/api/pools/list`, - adminPoolsListSchema, - { headers }, - ); - } + getPoolsList = (headers: IAdminAuthHeaders) => fetchWithValidation( + `https://${this.apiUrl}/api/pools/list`, + adminPoolsListSchema, + { headers }, + ); - editPool(address: string, data: IEditPool, headers: IAdminAuthHeaders) { - return fetchWithValidation( - `https://${this.apiUrl}/api/pools/edit/${address}`, - pairStatusSchema, - { - method: 'POST', - body: JSON.stringify(data), - headers: { - 'Content-Type': 'application/json', - ...headers, - }, + editPool = (address: string, data: IEditPool, headers: IAdminAuthHeaders) => fetchWithValidation( + `https://${this.apiUrl}/api/pools/edit/${address}`, + pairStatusSchema, + { + method: 'POST', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json', + ...headers, }, - ); - } + }, + ); - addPool(data: z.infer) { - return fetchWithValidation( - `https://${this.apiUrl}/api/pools/add`, - z.number(), - { - method: 'POST', - body: JSON.stringify(data), - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - }, + addPool = (data: z.infer) => fetchWithValidation( + `https://${this.apiUrl}/api/pools/add`, + z.number(), + { + method: 'POST', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', }, - z.string(), - ); - } + }, + z.string(), + ); - checkPoolInformation(poolAddress: string) { - return fetchWithValidation(`https://${this.apiUrl}/api/pools/check/${poolAddress}`, pairStatusSchema); - } + checkPoolInformation = (poolAddress: string) => fetchWithValidation( + `https://${this.apiUrl}/api/pools/check/${poolAddress}`, + pairStatusSchema, + ); - getAtomicSwapAssets() { - return fetchWithValidation(`https://${this.apiUrl}/api/atomic/swap-assets`, z.array(z.string())); - } + getAtomicSwapAssets = () => fetchWithValidation(`https://${this.apiUrl}/api/atomic/swap-assets`, z.array(z.string())); /** * Sender is user address in source Orion Blockchain instance \ * Receiver is user address in target Orion Blockchain instance */ - getAtomicSwapHistory(query: AtomicSwapHistorySourceQuery | AtomicSwapHistoryTargetQuery) { + getAtomicSwapHistory = (query: AtomicSwapHistorySourceQuery | AtomicSwapHistoryTargetQuery) => { const url = new URL(`https://${this.apiUrl}/api/atomic/history/`); Object.entries(query) .forEach(([key, value]) => url.searchParams.append(key, value.toString())); return fetchWithValidation(url.toString(), atomicHistorySchema); - } + }; - getSourceAtomicSwapHistory(query: AtomicSwapHistorySourceQuery) { + getSourceAtomicSwapHistory = (query: AtomicSwapHistorySourceQuery) => { const url = new URL(`https://${this.apiUrl}/api/atomic/history/`); Object.entries(query) @@ -299,9 +261,9 @@ class OrionBlockchain { if (!query.type) url.searchParams.append('type', 'source'); return fetchWithValidation(url.toString(), sourceAtomicHistorySchema); - } + }; - getTargetAtomicSwapHistory(query: AtomicSwapHistoryTargetQuery) { + getTargetAtomicSwapHistory = (query: AtomicSwapHistoryTargetQuery) => { const url = new URL(`https://${this.apiUrl}/api/atomic/history/`); Object.entries(query) @@ -310,22 +272,20 @@ class OrionBlockchain { if (!query.type) url.searchParams.append('type', 'target'); return fetchWithValidation(url.toString(), targetAtomicHistorySchema); - } + }; - checkIfHashUsed(secretHashes: string[]) { - return fetchWithValidation( - `https://${this.apiUrl}/api/atomic/is-hash-used`, - z.record(z.boolean()).transform(makePartial), - { - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json', - }, - method: 'POST', - body: JSON.stringify(secretHashes), + checkIfHashUsed = (secretHashes: string[]) => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/is-hash-used`, + z.record(z.boolean()).transform(makePartial), + { + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', }, - ); - } + method: 'POST', + body: JSON.stringify(secretHashes), + }, + ); } export * as ws from './ws'; diff --git a/src/services/PriceFeed/index.ts b/src/services/PriceFeed/index.ts index 3dca9b4..902d382 100644 --- a/src/services/PriceFeed/index.ts +++ b/src/services/PriceFeed/index.ts @@ -10,13 +10,13 @@ class PriceFeed { this.getCandles = this.getCandles.bind(this); } - getCandles( + getCandles = ( symbol: string, timeStart: number, timeEnd: number, interval: '5m' | '30m' | '1h' | '1d', exchange: string, - ) { + ) => { const url = new URL(`https://${this.apiUrl}/candles/candles`); url.searchParams.append('symbol', symbol); url.searchParams.append('timeStart', timeStart.toString()); @@ -28,7 +28,7 @@ class PriceFeed { url.toString(), candlesSchema, ); - } + }; get candlesUrl() { return `https://${this.apiUrl}/candles/candles`; }