diff --git a/package.json b/package.json index 22ff98b..40b29cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.5.6", + "version": "0.5.7", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/OrionUnit/index.ts b/src/OrionUnit/index.ts index 91b77b8..b917fe0 100644 --- a/src/OrionUnit/index.ts +++ b/src/OrionUnit/index.ts @@ -1,4 +1,5 @@ import { ethers } from 'ethers'; +import getOrionUnitSiblings from '../getOrionUnitSiblings'; import { OrionAggregator } from '../services/OrionAggregator'; import OrionAnalytics from '../services/OrionAnalytics'; import { OrionBlockchain } from '../services/OrionBlockchain'; @@ -47,4 +48,8 @@ export default class OrionUnit { this.exchange = new Exchange(this); this.farmingManager = new FarmingManager(this); } + + get siblings() { + return getOrionUnitSiblings(this.chainId, this.env); + } } diff --git a/src/crypt/signCancelOrderPersonal.ts b/src/crypt/signCancelOrderPersonal.ts index 2f795e2..b06512f 100644 --- a/src/crypt/signCancelOrderPersonal.ts +++ b/src/crypt/signCancelOrderPersonal.ts @@ -2,7 +2,7 @@ import { ethers } from 'ethers'; import { arrayify, joinSignature, splitSignature } from 'ethers/lib/utils'; import { CancelOrderRequest } from '../types'; -export const signCancelOrderPersonal = async ( +const signCancelOrderPersonal = async ( cancelOrderRequest: CancelOrderRequest, signer: ethers.Signer, ) => { diff --git a/src/getOrionUnitSiblings.ts b/src/getOrionUnitSiblings.ts new file mode 100644 index 0000000..4a749ab --- /dev/null +++ b/src/getOrionUnitSiblings.ts @@ -0,0 +1,20 @@ +import initOrionUnit from './initOrionUnit'; +import { SupportedChainId } from './types'; +import { isValidChainId } from './utils'; +import { envs } from './config'; + +export default function getOrionUnitSiblings(siblingChain: SupportedChainId, env: string) { + if (!(env in envs)) throw new Error(`Env '${env}' not found. Available environments is: ${Object.keys(envs).join(', ')}`); + const envInfo = envs[env]; + const envNetworks = envInfo?.networks; + + if (!(siblingChain in envNetworks)) { + throw new Error(`Chain '${siblingChain}' not found. ` + + `Available chains in selected environment (${env}) is: ${Object.keys(envNetworks).join(', ')}`); + } + const siblingsNetworks = Object + .keys(envNetworks) + .filter(isValidChainId) + .filter((chainId) => chainId !== siblingChain); + return siblingsNetworks.map((chainId) => initOrionUnit(chainId, env)); +} diff --git a/src/initOrionUnit.ts b/src/initOrionUnit.ts index 16622d5..22adc6f 100644 --- a/src/initOrionUnit.ts +++ b/src/initOrionUnit.ts @@ -1,7 +1,6 @@ -import { config, OrionUnit } from '.'; +import OrionUnit from './OrionUnit'; import { isValidChainId } from './utils'; - -const { chains, envs } = config; +import { chains, envs } from './config'; export default function initOrionUnit(chain: string, env: string) { if (!isValidChainId(chain)) throw new Error(`Chain '${chain}' is not valid.`); diff --git a/src/services/OrionAggregator/ws/index.ts b/src/services/OrionAggregator/ws/index.ts index eba7f4f..424ddd6 100644 --- a/src/services/OrionAggregator/ws/index.ts +++ b/src/services/OrionAggregator/ws/index.ts @@ -10,8 +10,7 @@ import { assetPairsConfigSchema, addressUpdateSchema, swapInfoSchema, } from './schemas'; import UnsubscriptionType from './UnsubscriptionType'; -import { SwapInfoByAmountIn, SwapInfoByAmountOut } from '../../..'; -import { SupportedChainId } from '../../../types'; +import { SwapInfoByAmountIn, SwapInfoByAmountOut, SupportedChainId } from '../../../types'; // import errorSchema from './schemas/errorSchema'; const UNSUBSCRIBE = 'u'; diff --git a/src/services/OrionBlockchain/index.ts b/src/services/OrionBlockchain/index.ts index 11ea1a6..80398f9 100644 --- a/src/services/OrionBlockchain/index.ts +++ b/src/services/OrionBlockchain/index.ts @@ -9,7 +9,7 @@ import { import { OrionBlockchainSocketIO } from './ws'; import redeemOrderSchema from '../OrionAggregator/schemas/redeemOrderSchema'; import { sourceAtomicHistorySchema, targetAtomicHistorySchema } from './schemas/atomicHistorySchema'; -import { utils } from '../..'; +import { makePartial } from '../../utils'; interface IAdminAuthHeaders { auth: string; @@ -115,11 +115,11 @@ class OrionBlockchain { } getPrices() { - return fetchWithValidation(`https://${this.apiUrl}/api/prices`, z.record(z.string()).transform(utils.makePartial)); + return 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(utils.makePartial)); + return fetchWithValidation(`https://${this.apiUrl}/api/tokensFee`, z.record(z.string()).transform(makePartial)); } getGasPriceWei() { @@ -295,7 +295,7 @@ class OrionBlockchain { checkIfHashUsed(secretHashes: string[]) { return fetchWithValidation( `https://${this.apiUrl}/api/atomic/is-hash-used`, - z.record(z.boolean()).transform(utils.makePartial), + z.record(z.boolean()).transform(makePartial), { headers: { 'Content-Type': 'application/json',