From 40fa9d6b52898c95eb045732bc2abecff44a7d1b Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Mon, 13 Feb 2023 19:35:58 +0400 Subject: [PATCH] Bump --- package.json | 2 +- src/BalanceGuard.ts | 25 ++++++++++--------- src/Orion/index.ts | 10 ++++---- src/OrionUnit/FarmingManager/index.ts | 6 ++--- src/OrionUnit/index.ts | 2 +- src/fetchWithValidation.ts | 4 +-- src/services/OrionAggregator/ws/index.ts | 8 +++--- .../PriceFeed/ws/PriceFeedSubscription.ts | 2 +- src/utils/isNetworkCodeInEnvironment.ts | 2 +- 9 files changed, 31 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 0cbd0d4..6da9f5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.7-rc.0", + "version": "0.17.7-rc.1", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/BalanceGuard.ts b/src/BalanceGuard.ts index a09819f..ce7d1ff 100644 --- a/src/BalanceGuard.ts +++ b/src/BalanceGuard.ts @@ -11,12 +11,13 @@ import arrayEquals from './utils/arrayEquals'; export default class BalanceGuard { private readonly balances: Partial< - Record< - string, - Record< - 'exchange' | 'wallet', - BigNumber> - > + Record< + string, + Record< + 'exchange' | 'wallet', + BigNumber + > + > >; public readonly requirements: BalanceRequirement[] = []; @@ -50,7 +51,7 @@ export default class BalanceGuard { // Used for case feeAsset === assetOut setExtraBalance(assetName: string, amount: BigNumber.Value, source: Source) { const assetBalance = this.balances[assetName]; - if (assetBalance === undefined) throw Error(`Can't set extra balance. Asset ${assetName} not found`); + if (!assetBalance) throw Error(`Can't set extra balance. Asset ${assetName} not found`); assetBalance[source] = assetBalance[source].plus(amount); } @@ -86,7 +87,7 @@ export default class BalanceGuard { item.spenderAddress === curr.spenderAddress, ); - if (aggregatedBalanceRequirement !== undefined) { + if (aggregatedBalanceRequirement) { aggregatedBalanceRequirement.items = { ...aggregatedBalanceRequirement.items, [curr.reason]: curr.amount, @@ -193,7 +194,7 @@ export default class BalanceGuard { exchangeOnlyAggregatedRequirements.forEach(({ asset, items }) => { const remainingBalance = remainingBalances[asset.name]; - if (remainingBalance === undefined) throw new Error(`No ${asset.name} balance`); + if (!remainingBalance) throw new Error(`No ${asset.name} balance`); const itemsAmountSum = Object.values(items) .reduce((p, c) => (c !== undefined ? p.plus(c) : p), new BigNumber(0)); @@ -220,7 +221,7 @@ export default class BalanceGuard { await Promise.all(exchangePlusWalletAggregatedRequirements .map(async ({ asset, spenderAddress, items }) => { const remainingBalance = remainingBalances[asset.name]; - if (remainingBalance === undefined) throw new Error(`No ${asset.name} balance`); + if (!remainingBalance) throw new Error(`No ${asset.name} balance`); const itemsAmountSum = Object.values(items) .reduce((p, c) => (c !== undefined ? p.plus(c) : p), new BigNumber(0)); @@ -323,7 +324,7 @@ export default class BalanceGuard { await Promise.all(walletTokensAggregatedRequirements .map(async ({ asset, spenderAddress, items }) => { const remainingBalance = remainingBalances[asset.name]; - if (remainingBalance === undefined) throw new Error(`No ${asset.name} balance`); + if (!remainingBalance) throw new Error(`No ${asset.name} balance`); const itemsAmountSum = Object.values(items) .reduce((p, c) => (c !== undefined ? p.plus(c) : p), new BigNumber(0)); @@ -414,7 +415,7 @@ export default class BalanceGuard { walletNativeAggregatedRequirements.forEach(({ asset, items }) => { const remainingBalance = remainingBalances[asset.name]; - if (remainingBalance === undefined) throw new Error(`No ${asset.name} balance`); + if (!remainingBalance) throw new Error(`No ${asset.name} balance`); const itemsAmountSum = Object.values({ ...items, ...requiredApproves.items }) .reduce((p, c) => (c !== undefined ? p.plus(c) : p), new BigNumber(0)); diff --git a/src/Orion/index.ts b/src/Orion/index.ts index e0c15ba..3d9ce04 100644 --- a/src/Orion/index.ts +++ b/src/Orion/index.ts @@ -42,7 +42,7 @@ export default class Orion { let config: EnvConfig; if (typeof envOrConfig === 'string') { const envConfig = envs[envOrConfig]; - if (envConfig === undefined) { + if (!envConfig) { throw new Error(`Invalid environment: ${envOrConfig}. Available environments: ${Object.keys(envs).join(', ')}`); } this.env = envOrConfig; @@ -52,7 +52,7 @@ export default class Orion { networks: Object.entries(envConfig.networks).map(([chainId, networkConfig]) => { if (!isValidChainId(chainId)) throw new Error(`Invalid chainId: ${chainId}`); const chainConfig = chains[chainId]; - if (chainConfig === undefined) { + if (!chainConfig) { throw new Error(`Chain config not found: ${chainId}. Available chains: ${Object.keys(chains).join(', ')}`); } @@ -81,7 +81,7 @@ export default class Orion { }, {}), }; - if (overrides !== undefined) { + if (overrides) { // Recursive merge of config and overrides. Ignore undefined values. config = merge(config, overrides); } @@ -96,7 +96,7 @@ export default class Orion { .reduce>>((acc, [chainId, networkConfig]) => { if (!isValidChainId(chainId)) throw new Error(`Invalid chainId: ${chainId}`); const chainConfig = chains[chainId]; - if (chainConfig === undefined) throw new Error(`Invalid chainId: ${chainId}`); + if (!chainConfig) throw new Error(`Chain config not found: ${chainId}`); const orionUnit = new OrionUnit({ // env: networkConfig.env, @@ -123,7 +123,7 @@ export default class Orion { } else { unit = this.unitsArray.find((u) => u.networkCode === networkCodeOrChainId); } - if (unit === undefined) { + if (!unit) { throw new Error( `Invalid network code: ${networkCodeOrChainId}. ` + `Available network codes: ${this.unitsArray.map((u) => u.networkCode).join(', ')}`); diff --git a/src/OrionUnit/FarmingManager/index.ts b/src/OrionUnit/FarmingManager/index.ts index 958e510..5f51345 100644 --- a/src/OrionUnit/FarmingManager/index.ts +++ b/src/OrionUnit/FarmingManager/index.ts @@ -90,7 +90,7 @@ export default class FarmingManager { const poolsConfig = await simpleFetch(this.orionUnit.orionBlockchain.getPoolsConfig)(); const pool = poolsConfig.pools[poolName]; - if (pool === undefined) throw new Error(`Pool ${poolName} not found`); + if (!pool) throw new Error(`Pool ${poolName} not found`); const pairContract = IUniswapV2Pair__factory .connect(pool.lpTokenAddress, this.orionUnit.provider); @@ -183,7 +183,7 @@ export default class FarmingManager { if (assetAIsNativeCurrency || assetBIsNativeCurrency) { const contractBalance = balances[nativeCryptocurrency]?.exchange; - if (contractBalance === undefined) throw new Error(`No balance for '${nativeCryptocurrency}'`); + if (!contractBalance) throw new Error(`No balance for '${nativeCryptocurrency}'`); const nativeAssetAmount = assetBIsNativeCurrency ? assetBAmount : assetAAmount; if (nativeAssetAmount.gt(contractBalance)) { @@ -242,7 +242,7 @@ export default class FarmingManager { const poolsConfig = await simpleFetch(this.orionUnit.orionBlockchain.getPoolsConfig)(); const pool = poolsConfig.pools[poolName]; - if (pool === undefined) throw new Error(`Pool ${poolName} not found`); + if (!pool) throw new Error(`Pool ${poolName} not found`); const walletAddress = await signer.getAddress(); diff --git a/src/OrionUnit/index.ts b/src/OrionUnit/index.ts index d0d9d1b..d18bdc8 100644 --- a/src/OrionUnit/index.ts +++ b/src/OrionUnit/index.ts @@ -42,7 +42,7 @@ export default class OrionUnit { constructor(config: VerboseOrionUnitConfig) { this.config = config; const chainInfo = chains[config.chainId]; - if (chainInfo === undefined) throw new Error('Chain info is required'); + if (!chainInfo) throw new Error('Chain info is required'); // if ('env' in config) // this.env = config.env; diff --git a/src/fetchWithValidation.ts b/src/fetchWithValidation.ts index 8630573..8a68030 100644 --- a/src/fetchWithValidation.ts +++ b/src/fetchWithValidation.ts @@ -29,7 +29,7 @@ export default async function fetchWithValidation { if (e instanceof Error) { @@ -111,7 +111,7 @@ export default async function fetchWithValidation= 400) { // Client error - if (errorSchema !== undefined) { + if (errorSchema) { const serverError = errorSchema.safeParse(json); if (serverError.success) { return err({ diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index 87e89d4..44460b1 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -206,10 +206,10 @@ class OrionAggregatorWS { type: T, subscription: Subscription[T], ) { - if (this.ws === undefined) this.init(); + if (!this.ws) this.init(); const isExclusive = exclusiveSubscriptions.some((t) => t === type); const subs = this.subscriptions[type]; - if (isExclusive && (subs !== undefined) && Object.keys(subs).length > 0) { + if (isExclusive && subs && Object.keys(subs).length > 0) { throw new Error(`Subscription '${type}' already exists. Please unsubscribe first.`); } @@ -527,7 +527,7 @@ class OrionAggregatorWS { const balances = (json.b) ? Object.entries(json.b) .reduce>>((prev, [asset, assetBalances]) => { - if (assetBalances === undefined) return prev; + if (!assetBalances) return prev; const [tradable, reserved, contract, wallet, allowance] = assetBalances; prev[asset] = { @@ -539,7 +539,7 @@ class OrionAggregatorWS { : {}; switch (json.k) { // message kind case 'i': { // initial - const fullOrders = (json.o !== undefined) + const fullOrders = json.o ? json.o.reduce>>((prev, o) => { prev.push(o); diff --git a/src/services/PriceFeed/ws/PriceFeedSubscription.ts b/src/services/PriceFeed/ws/PriceFeedSubscription.ts index 1185f7c..3491f1d 100644 --- a/src/services/PriceFeed/ws/PriceFeedSubscription.ts +++ b/src/services/PriceFeed/ws/PriceFeedSubscription.ts @@ -121,7 +121,7 @@ export default class PriceFeedSubscription { - if (this.heartbeatInterval !== undefined) clearInterval(this.heartbeatInterval); + if (this.heartbeatInterval) clearInterval(this.heartbeatInterval); if (!this.isClosedIntentionally) this.init(); }; diff --git a/src/utils/isNetworkCodeInEnvironment.ts b/src/utils/isNetworkCodeInEnvironment.ts index 042bc5a..56c4a82 100644 --- a/src/utils/isNetworkCodeInEnvironment.ts +++ b/src/utils/isNetworkCodeInEnvironment.ts @@ -6,7 +6,7 @@ export default function isNetworkCodeInEnvironment(networkCode: string, env: str } const envInfo = envs[env]; const envNetworks = envInfo?.networks; - if (envNetworks === undefined) throw new Error('Env networks is undefined (isNetworkCodeInEnvironment)'); + if (!envNetworks) throw new Error('Env networks is undefined (isNetworkCodeInEnvironment)'); return Object.values(chains) .some((chain) => chain.code.toLowerCase() === networkCode.toLowerCase() &&