mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-25 07:07:39 +03:00
OrionUnit siblings introduced
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
) => {
|
||||
|
||||
20
src/getOrionUnitSiblings.ts
Normal file
20
src/getOrionUnitSiblings.ts
Normal file
@@ -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));
|
||||
}
|
||||
@@ -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.`);
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user