mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 22:52:36 +03:00
Fix
This commit is contained in:
18
.eslintrc.js
18
.eslintrc.js
@@ -28,6 +28,24 @@ module.exports = {
|
||||
'@typescript-eslint',
|
||||
],
|
||||
rules: {
|
||||
"@typescript-eslint/strict-boolean-expressions": [
|
||||
"error",
|
||||
{
|
||||
"allowNullableObject": true,
|
||||
"allowString": false,
|
||||
"allowNumber": false,
|
||||
"allowNullableBoolean": false,
|
||||
"allowNullableString": false,
|
||||
"allowNullableNumber": false,
|
||||
"allowAny": false,
|
||||
"allowNullableEnum": false
|
||||
}
|
||||
],
|
||||
"eqeqeq": "error",
|
||||
"@typescript-eslint/consistent-type-definitions": [
|
||||
"warn",
|
||||
"type"
|
||||
],
|
||||
"@typescript-eslint/indent": [
|
||||
"error",
|
||||
2,
|
||||
|
||||
@@ -51,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 == null) throw Error(`Can't set extra balance. Asset ${assetName} not found`);
|
||||
if (assetBalance === undefined) throw Error(`Can't set extra balance. Asset ${assetName} not found`);
|
||||
assetBalance[source] = assetBalance[source].plus(amount);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export default class BalanceGuard {
|
||||
item.spenderAddress === curr.spenderAddress,
|
||||
);
|
||||
|
||||
if (aggregatedBalanceRequirement != null) {
|
||||
if (aggregatedBalanceRequirement !== undefined) {
|
||||
aggregatedBalanceRequirement.items = {
|
||||
...aggregatedBalanceRequirement.items,
|
||||
[curr.reason]: curr.amount,
|
||||
@@ -194,7 +194,7 @@ export default class BalanceGuard {
|
||||
|
||||
exchangeOnlyAggregatedRequirements.forEach(({ asset, items }) => {
|
||||
const remainingBalance = remainingBalances[asset.name];
|
||||
if (remainingBalance == null) throw new Error(`No ${asset.name} balance`);
|
||||
if (remainingBalance === undefined) throw new Error(`No ${asset.name} balance`);
|
||||
const itemsAmountSum = Object.values(items)
|
||||
.reduce<BigNumber>((p, c) => (c !== undefined ? p.plus(c) : p), new BigNumber(0));
|
||||
|
||||
@@ -221,7 +221,7 @@ export default class BalanceGuard {
|
||||
await Promise.all(exchangePlusWalletAggregatedRequirements
|
||||
.map(async ({ asset, spenderAddress, items }) => {
|
||||
const remainingBalance = remainingBalances[asset.name];
|
||||
if (remainingBalance == null) throw new Error(`No ${asset.name} balance`);
|
||||
if (remainingBalance === undefined) throw new Error(`No ${asset.name} balance`);
|
||||
const itemsAmountSum = Object.values(items)
|
||||
.reduce<BigNumber>((p, c) => (c !== undefined ? p.plus(c) : p), new BigNumber(0));
|
||||
|
||||
@@ -322,7 +322,7 @@ export default class BalanceGuard {
|
||||
await Promise.all(walletTokensAggregatedRequirements
|
||||
.map(async ({ asset, spenderAddress, items }) => {
|
||||
const remainingBalance = remainingBalances[asset.name];
|
||||
if (remainingBalance == null) throw new Error(`No ${asset.name} balance`);
|
||||
if (remainingBalance === undefined) throw new Error(`No ${asset.name} balance`);
|
||||
const itemsAmountSum = Object.values(items)
|
||||
.reduce<BigNumber>((p, c) => (c !== undefined ? p.plus(c) : p), new BigNumber(0));
|
||||
|
||||
@@ -411,7 +411,7 @@ export default class BalanceGuard {
|
||||
|
||||
walletNativeAggregatedRequirements.forEach(({ asset, items }) => {
|
||||
const remainingBalance = remainingBalances[asset.name];
|
||||
if (remainingBalance == null) throw new Error(`No ${asset.name} balance`);
|
||||
if (remainingBalance === undefined) throw new Error(`No ${asset.name} balance`);
|
||||
|
||||
const itemsAmountSum = Object.values({ ...items, ...requiredApproves.items })
|
||||
.reduce<BigNumber>((p, c) => (c !== undefined ? p.plus(c) : p), new BigNumber(0));
|
||||
|
||||
@@ -7,7 +7,7 @@ import { ReferralSystem } from '../services/ReferralSystem';
|
||||
import { type DeepPartial, type SupportedChainId, type VerboseOrionUnitConfig } from '../types';
|
||||
import { isValidChainId } from '../utils';
|
||||
|
||||
interface EnvConfig {
|
||||
type EnvConfig = {
|
||||
analyticsAPI: string
|
||||
referralAPI: string
|
||||
networks: Partial<
|
||||
@@ -96,7 +96,7 @@ export default class Orion {
|
||||
.reduce<Partial<Record<SupportedChainId, OrionUnit>>>((acc, [chainId, networkConfig]) => {
|
||||
if (!isValidChainId(chainId)) throw new Error(`Invalid chainId: ${chainId}`);
|
||||
const chainConfig = chains[chainId];
|
||||
if (chainConfig == null) throw new Error(`Invalid chainId: ${chainId}`);
|
||||
if (chainConfig === undefined) throw new Error(`Invalid chainId: ${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 == null) {
|
||||
if (unit === undefined) {
|
||||
throw new Error(
|
||||
`Invalid network code: ${networkCodeOrChainId}. ` +
|
||||
`Available network codes: ${this.unitsArray.map((u) => u.networkCode).join(', ')}`);
|
||||
|
||||
@@ -13,7 +13,7 @@ import { normalizeNumber } from '../../utils';
|
||||
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
|
||||
import simpleFetch from '../../simpleFetch';
|
||||
|
||||
export interface DepositParams {
|
||||
export type DepositParams = {
|
||||
asset: string
|
||||
amount: BigNumber.Value
|
||||
signer: ethers.Signer
|
||||
|
||||
@@ -8,7 +8,7 @@ import { type OrionBlockchain } from '../../services/OrionBlockchain';
|
||||
import simpleFetch from '../../simpleFetch';
|
||||
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
|
||||
|
||||
export interface GetSwapInfoParams {
|
||||
export type GetSwapInfoParams = {
|
||||
type: 'exactSpend' | 'exactReceive'
|
||||
assetIn: string
|
||||
assetOut: string
|
||||
@@ -115,7 +115,7 @@ export default async function getSwapInfo({
|
||||
};
|
||||
}
|
||||
|
||||
if (swapInfo.orderInfo != null) {
|
||||
if (swapInfo.orderInfo !== null) {
|
||||
const [baseAssetName] = swapInfo.orderInfo.assetPair.split('-');
|
||||
if (baseAssetName === undefined) throw new Error('Base asset name is undefined');
|
||||
const baseAssetAddress = assetToAddress[baseAssetName];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type OrionUnit from '..';
|
||||
import deposit, { type DepositParams } from './deposit';
|
||||
import getSwapInfo, { type GetSwapInfoParams } from './getSwapInfo';
|
||||
import swapMarket, { type Swap, type SwapMarketParams } from './swapMarket';
|
||||
import swapMarket, { type SwapMarketParams } from './swapMarket';
|
||||
import withdraw, { type WithdrawParams } from './withdraw';
|
||||
|
||||
type PureSwapMarketParams = Omit<SwapMarketParams, 'orionUnit'>
|
||||
@@ -16,7 +16,7 @@ export default class Exchange {
|
||||
this.orionUnit = orionUnit;
|
||||
}
|
||||
|
||||
public swapMarket(params: PureSwapMarketParams): Promise<Swap> {
|
||||
public swapMarket(params: PureSwapMarketParams) {
|
||||
return swapMarket({
|
||||
...params,
|
||||
orionUnit: this.orionUnit,
|
||||
|
||||
@@ -11,7 +11,7 @@ import { INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION, SWAP_THROUGH_ORION
|
||||
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
|
||||
import simpleFetch from '../../simpleFetch';
|
||||
|
||||
export interface SwapMarketParams {
|
||||
export type SwapMarketParams = {
|
||||
type: 'exactSpend' | 'exactReceive'
|
||||
assetIn: string
|
||||
assetOut: string
|
||||
@@ -31,12 +31,12 @@ export interface SwapMarketParams {
|
||||
}
|
||||
}
|
||||
|
||||
interface AggregatorOrder {
|
||||
type AggregatorOrder = {
|
||||
through: 'aggregator'
|
||||
id: string
|
||||
}
|
||||
|
||||
interface PoolSwap {
|
||||
type PoolSwap = {
|
||||
through: 'orion_pool'
|
||||
txHash: string
|
||||
}
|
||||
@@ -54,7 +54,7 @@ export default async function swapMarket({
|
||||
orionUnit,
|
||||
options,
|
||||
}: SwapMarketParams): Promise<Swap> {
|
||||
if ((options?.developer) != null) options.logger?.('YOU SPECIFIED A DEVELOPER OPTIONS. BE CAREFUL!');
|
||||
if (options?.developer) options.logger?.('YOU SPECIFIED A DEVELOPER OPTIONS. BE CAREFUL!');
|
||||
if (amount === '') throw new Error('Amount can not be empty');
|
||||
if (assetIn === '') throw new Error('AssetIn can not be empty');
|
||||
if (assetOut === '') throw new Error('AssetOut can not be empty');
|
||||
@@ -183,7 +183,7 @@ export default async function swapMarket({
|
||||
|
||||
if (route === 'pool') {
|
||||
let factoryAddress: string | undefined;
|
||||
if ((factories != null) && firstSwapExchange !== undefined) {
|
||||
if (factories && firstSwapExchange !== undefined) {
|
||||
factoryAddress = factories[firstSwapExchange];
|
||||
if (factoryAddress !== undefined) options?.logger?.(`Factory address is ${factoryAddress}. Exchange is ${firstSwapExchange}`);
|
||||
}
|
||||
@@ -242,7 +242,7 @@ export default async function swapMarket({
|
||||
|
||||
let value = new BigNumber(0);
|
||||
const denormalizedAssetInExchangeBalance = balances[assetIn]?.exchange;
|
||||
if (denormalizedAssetInExchangeBalance == null) throw new Error(`Asset '${assetIn}' exchange balance is not found`);
|
||||
if (denormalizedAssetInExchangeBalance === undefined) throw new Error(`Asset '${assetIn}' exchange balance is not found`);
|
||||
if (assetIn === nativeCryptocurrency && amountSpendBN.gt(denormalizedAssetInExchangeBalance)) {
|
||||
value = amountSpendBN.minus(denormalizedAssetInExchangeBalance);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { normalizeNumber } from '../../utils';
|
||||
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
|
||||
import simpleFetch from '../../simpleFetch';
|
||||
|
||||
export interface WithdrawParams {
|
||||
export type WithdrawParams = {
|
||||
asset: string
|
||||
amount: BigNumber.Value
|
||||
signer: ethers.Signer
|
||||
|
||||
@@ -11,14 +11,14 @@ import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
|
||||
|
||||
const ADD_LIQUIDITY_SLIPPAGE = 0.05;
|
||||
|
||||
export interface AddLiquidityParams {
|
||||
export type AddLiquidityParams = {
|
||||
poolName: string
|
||||
amountAsset: string
|
||||
amount: BigNumber.Value
|
||||
signer: ethers.Signer
|
||||
}
|
||||
|
||||
export interface RemoveAllLiquidityParams {
|
||||
export type RemoveAllLiquidityParams = {
|
||||
poolName: string
|
||||
signer: ethers.Signer
|
||||
}
|
||||
@@ -90,7 +90,7 @@ export default class FarmingManager {
|
||||
|
||||
const poolsConfig = await simpleFetch(this.orionUnit.orionBlockchain.getPoolsConfig)();
|
||||
const pool = poolsConfig.pools[poolName];
|
||||
if (pool == null) throw new Error(`Pool ${poolName} not found`);
|
||||
if (pool === undefined) 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 == null) throw new Error(`No balance for '${nativeCryptocurrency}'`);
|
||||
if (contractBalance === undefined) 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 == null) throw new Error(`Pool ${poolName} not found`);
|
||||
if (pool === undefined) throw new Error(`Pool ${poolName} not found`);
|
||||
|
||||
const walletAddress = await signer.getAddress();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import cfdAddressUpdateSchema from './schemas/cfdAddressUpdateSchema';
|
||||
const UNSUBSCRIBE = 'u';
|
||||
|
||||
// https://github.com/orionprotocol/orion-aggregator/tree/feature/OP-1752-symmetric-swap#swap-info-subscribe
|
||||
interface SwapSubscriptionRequest {
|
||||
type SwapSubscriptionRequest = {
|
||||
// d: string, // swap request UUID, set by client side
|
||||
i: string // asset in
|
||||
o: string // asset out
|
||||
@@ -32,18 +32,18 @@ interface SwapSubscriptionRequest {
|
||||
is?: boolean // instant settlement
|
||||
}
|
||||
|
||||
interface BrokerTradableAtomicSwapBalanceSubscription {
|
||||
type BrokerTradableAtomicSwapBalanceSubscription = {
|
||||
callback: (balances: Partial<Record<string, number>>) => void
|
||||
}
|
||||
|
||||
interface PairsConfigSubscription {
|
||||
type PairsConfigSubscription = {
|
||||
callback: ({ kind, data }: {
|
||||
kind: 'initial' | 'update'
|
||||
data: Partial<Record<string, AssetPairUpdate>>
|
||||
}) => void
|
||||
}
|
||||
|
||||
interface PairConfigSubscription {
|
||||
type PairConfigSubscription = {
|
||||
payload: string
|
||||
callback: ({ kind, data }: {
|
||||
kind: 'initial' | 'update'
|
||||
@@ -51,7 +51,7 @@ interface PairConfigSubscription {
|
||||
}) => void
|
||||
}
|
||||
|
||||
interface AggregatedOrderbookSubscription {
|
||||
type AggregatedOrderbookSubscription = {
|
||||
payload: string
|
||||
callback: (
|
||||
asks: OrderbookItem[],
|
||||
@@ -60,12 +60,12 @@ interface AggregatedOrderbookSubscription {
|
||||
) => void
|
||||
}
|
||||
|
||||
interface SwapInfoSubscription {
|
||||
type SwapInfoSubscription = {
|
||||
payload: SwapSubscriptionRequest
|
||||
callback: (swapInfo: SwapInfoByAmountIn | SwapInfoByAmountOut) => void
|
||||
}
|
||||
|
||||
interface AddressUpdateUpdate {
|
||||
type AddressUpdateUpdate = {
|
||||
kind: 'update'
|
||||
balances: Partial<
|
||||
Record<
|
||||
@@ -76,7 +76,7 @@ interface AddressUpdateUpdate {
|
||||
order?: z.infer<typeof orderUpdateSchema> | z.infer<typeof fullOrderSchema>
|
||||
}
|
||||
|
||||
interface AddressUpdateInitial {
|
||||
type AddressUpdateInitial = {
|
||||
kind: 'initial'
|
||||
balances: Partial<
|
||||
Record<
|
||||
@@ -87,29 +87,29 @@ interface AddressUpdateInitial {
|
||||
orders?: Array<z.infer<typeof fullOrderSchema>> // The field is not defined if the user has no orders
|
||||
}
|
||||
|
||||
interface CfdAddressUpdateUpdate {
|
||||
type CfdAddressUpdateUpdate = {
|
||||
kind: 'update'
|
||||
balances?: CFDBalance[]
|
||||
order?: z.infer<typeof orderUpdateSchema> | z.infer<typeof fullOrderSchema>
|
||||
}
|
||||
|
||||
interface CfdAddressUpdateInitial {
|
||||
type CfdAddressUpdateInitial = {
|
||||
kind: 'initial'
|
||||
balances: CFDBalance[]
|
||||
orders?: Array<z.infer<typeof fullOrderSchema>> // The field is not defined if the user has no orders
|
||||
}
|
||||
|
||||
interface AddressUpdateSubscription {
|
||||
type AddressUpdateSubscription = {
|
||||
payload: string
|
||||
callback: (data: AddressUpdateUpdate | AddressUpdateInitial) => void
|
||||
}
|
||||
|
||||
interface CfdAddressUpdateSubscription {
|
||||
type CfdAddressUpdateSubscription = {
|
||||
payload: string
|
||||
callback: (data: CfdAddressUpdateUpdate | CfdAddressUpdateInitial) => void
|
||||
}
|
||||
|
||||
interface Subscription {
|
||||
type Subscription = {
|
||||
[SubscriptionType.ADDRESS_UPDATES_SUBSCRIBE]: AddressUpdateSubscription
|
||||
[SubscriptionType.CFD_ADDRESS_UPDATES_SUBSCRIBE]: CfdAddressUpdateSubscription
|
||||
[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE]: AggregatedOrderbookSubscription
|
||||
@@ -206,10 +206,10 @@ class OrionAggregatorWS {
|
||||
type: T,
|
||||
subscription: Subscription[T],
|
||||
) {
|
||||
if (this.ws == null) this.init();
|
||||
if (this.ws === undefined) this.init();
|
||||
const isExclusive = exclusiveSubscriptions.some((t) => t === type);
|
||||
const subs = this.subscriptions[type];
|
||||
if (isExclusive && (subs != null) && Object.keys(subs).length > 0) {
|
||||
if (isExclusive && (subs !== undefined) && Object.keys(subs).length > 0) {
|
||||
throw new Error(`Subscription '${type}' already exists. Please unsubscribe first.`);
|
||||
}
|
||||
|
||||
@@ -252,18 +252,18 @@ class OrionAggregatorWS {
|
||||
|
||||
if (subscription.includes('0x')) { // is wallet address (ADDRESS_UPDATE)
|
||||
const auSubscriptions = this.subscriptions[SubscriptionType.ADDRESS_UPDATES_SUBSCRIBE];
|
||||
if (auSubscriptions != null) {
|
||||
if (auSubscriptions) {
|
||||
const targetAuSub = Object.entries(auSubscriptions).find(([, value]) => value?.payload === subscription);
|
||||
if (targetAuSub != null) {
|
||||
if (targetAuSub) {
|
||||
const [key] = targetAuSub;
|
||||
delete this.subscriptions[SubscriptionType.ADDRESS_UPDATES_SUBSCRIBE]?.[key];
|
||||
}
|
||||
}
|
||||
|
||||
const aufSubscriptions = this.subscriptions[SubscriptionType.CFD_ADDRESS_UPDATES_SUBSCRIBE];
|
||||
if (aufSubscriptions != null) {
|
||||
if (aufSubscriptions) {
|
||||
const targetAufSub = Object.entries(aufSubscriptions).find(([, value]) => value?.payload === subscription);
|
||||
if (targetAufSub != null) {
|
||||
if (targetAufSub) {
|
||||
const [key] = targetAufSub;
|
||||
delete this.subscriptions[SubscriptionType.CFD_ADDRESS_UPDATES_SUBSCRIBE]?.[key];
|
||||
}
|
||||
@@ -275,9 +275,9 @@ class OrionAggregatorWS {
|
||||
// !!! swap info subscription is uuid that contains hyphen
|
||||
} else if (subscription.includes('-') && subscription.split('-').length === 2) { // is pair name(AGGREGATED_ORDER_BOOK_UPDATE)
|
||||
const aobSubscriptions = this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE];
|
||||
if (aobSubscriptions != null) {
|
||||
if (aobSubscriptions) {
|
||||
const targetAobSub = Object.entries(aobSubscriptions).find(([, value]) => value?.payload === subscription);
|
||||
if (targetAobSub != null) {
|
||||
if (targetAobSub) {
|
||||
const [key] = targetAobSub;
|
||||
delete this.subscriptions[SubscriptionType.AGGREGATED_ORDER_BOOK_UPDATES_SUBSCRIBE]?.[key];
|
||||
}
|
||||
@@ -314,10 +314,10 @@ class OrionAggregatorWS {
|
||||
.filter(isSubType)
|
||||
.forEach((subType) => {
|
||||
const subscriptions = subscriptionsToReconnect[subType];
|
||||
if (subscriptions != null) {
|
||||
if (subscriptions) {
|
||||
Object.keys(subscriptions).forEach((subKey) => {
|
||||
const sub = subscriptions[subKey];
|
||||
if (sub != null) this.subscribe(subType, sub);
|
||||
if (sub) this.subscribe(subType, sub);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -372,7 +372,7 @@ class OrionAggregatorWS {
|
||||
path: json.ps,
|
||||
exchanges: json.e,
|
||||
poolOptimal: json.po,
|
||||
...(json.oi != null) && {
|
||||
...(json.oi) && {
|
||||
orderInfo: {
|
||||
pair: json.oi.p,
|
||||
side: json.oi.s,
|
||||
@@ -486,7 +486,7 @@ class OrionAggregatorWS {
|
||||
case MessageType.CFD_ADDRESS_UPDATE:
|
||||
switch (json.k) { // message kind
|
||||
case 'i': { // initial
|
||||
const fullOrders = (json.o != null)
|
||||
const fullOrders = (json.o)
|
||||
? json.o.reduce<Array<z.infer<typeof fullOrderSchema>>>((prev, o) => {
|
||||
prev.push(o);
|
||||
|
||||
@@ -505,7 +505,7 @@ class OrionAggregatorWS {
|
||||
break;
|
||||
case 'u': { // update
|
||||
let orderUpdate: z.infer<typeof orderUpdateSchema> | z.infer<typeof fullOrderSchema> | undefined;
|
||||
if (json.o != null) {
|
||||
if (json.o) {
|
||||
const firstOrder = json.o[0];
|
||||
orderUpdate = firstOrder;
|
||||
}
|
||||
@@ -524,22 +524,22 @@ class OrionAggregatorWS {
|
||||
}
|
||||
break;
|
||||
case MessageType.ADDRESS_UPDATE: {
|
||||
const balances = (json.b != null)
|
||||
const balances = (json.b)
|
||||
? Object.entries(json.b)
|
||||
.reduce<Partial<Record<string, Balance>>>((prev, [asset, assetBalances]) => {
|
||||
if (assetBalances == null) return prev;
|
||||
const [tradable, reserved, contract, wallet, allowance] = assetBalances;
|
||||
if (assetBalances === undefined) return prev;
|
||||
const [tradable, reserved, contract, wallet, allowance] = assetBalances;
|
||||
|
||||
prev[asset] = {
|
||||
tradable, reserved, contract, wallet, allowance,
|
||||
};
|
||||
prev[asset] = {
|
||||
tradable, reserved, contract, wallet, allowance,
|
||||
};
|
||||
|
||||
return prev;
|
||||
}, {})
|
||||
return prev;
|
||||
}, {})
|
||||
: {};
|
||||
switch (json.k) { // message kind
|
||||
case 'i': { // initial
|
||||
const fullOrders = (json.o != null)
|
||||
const fullOrders = (json.o !== undefined)
|
||||
? json.o.reduce<Array<z.infer<typeof fullOrderSchema>>>((prev, o) => {
|
||||
prev.push(o);
|
||||
|
||||
@@ -558,7 +558,7 @@ class OrionAggregatorWS {
|
||||
break;
|
||||
case 'u': { // update
|
||||
let orderUpdate: z.infer<typeof orderUpdateSchema> | z.infer<typeof fullOrderSchema> | undefined;
|
||||
if (json.o != null) {
|
||||
if (json.o) {
|
||||
const firstOrder = json.o[0];
|
||||
orderUpdate = firstOrder;
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@ import { sourceAtomicHistorySchema, targetAtomicHistorySchema } from './schemas/
|
||||
import { makePartial } from '../../utils';
|
||||
import { type networkCodes } from '../../constants';
|
||||
|
||||
interface IAdminAuthHeaders {
|
||||
type IAdminAuthHeaders = {
|
||||
auth: string
|
||||
[key: string]: string
|
||||
}
|
||||
|
||||
export interface IEditPool {
|
||||
export type IEditPool = {
|
||||
tokenAIcon?: string
|
||||
tokenBIcon?: string
|
||||
symbol?: string
|
||||
@@ -34,14 +34,14 @@ export interface IEditPool {
|
||||
tokensReversed?: boolean
|
||||
}
|
||||
|
||||
interface AtomicSwapHistoryBaseQuery extends Partial<Record<string, string | number>> {
|
||||
type AtomicSwapHistoryBaseQuery = {
|
||||
limit?: number
|
||||
sender?: string
|
||||
receiver?: string
|
||||
used?: 0 | 1
|
||||
page?: number
|
||||
sourceNetworkCode?: typeof networkCodes[number]
|
||||
}
|
||||
} & Partial<Record<string, string | number>>
|
||||
|
||||
type AtomicSwapHistorySourceQuery = AtomicSwapHistoryBaseQuery & {
|
||||
type?: 'source'
|
||||
@@ -55,11 +55,11 @@ type AtomicSwapHistoryTargetQuery = AtomicSwapHistoryBaseQuery & {
|
||||
state?: 'REDEEMED' | 'BEFORE-REDEEM'
|
||||
}
|
||||
|
||||
interface CfdHistoryQuery extends Partial<Record<string, string | number>> {
|
||||
type CfdHistoryQuery = {
|
||||
instrument?: string
|
||||
page?: number
|
||||
limit?: number
|
||||
}
|
||||
} & Partial<Record<string, string | number>>
|
||||
class OrionBlockchain {
|
||||
private readonly apiUrl: string;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import priceFeedSubscriptions from './priceFeedSubscriptions';
|
||||
import { tickerInfoSchema, candleSchema } from './schemas';
|
||||
import priceSchema from './schemas/priceSchema';
|
||||
|
||||
interface TickerInfo {
|
||||
type TickerInfo = {
|
||||
pairName: string
|
||||
lastPrice: string
|
||||
openPrice: string
|
||||
@@ -121,7 +121,7 @@ export default class PriceFeedSubscription<T extends SubscriptionType = Subscrip
|
||||
};
|
||||
|
||||
this.ws.onclose = () => {
|
||||
if (this.heartbeatInterval != null) clearInterval(this.heartbeatInterval);
|
||||
if (this.heartbeatInterval !== undefined) clearInterval(this.heartbeatInterval);
|
||||
if (!this.isClosedIntentionally) this.init();
|
||||
};
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@ import distinctAnalyticsSchema from './schemas/distinctAnalyticsSchema';
|
||||
import globalAnalyticsSchema from './schemas/globalAnalyticsSchema';
|
||||
import linkSchema from './schemas/linkSchema';
|
||||
|
||||
interface CreateLinkPayloadType {
|
||||
type CreateLinkPayloadType = {
|
||||
referer: string
|
||||
link_option: number
|
||||
}
|
||||
|
||||
interface SubscribePayloadType {
|
||||
type SubscribePayloadType = {
|
||||
ref_target: string
|
||||
referral: string
|
||||
}
|
||||
|
||||
interface SignatureType {
|
||||
type SignatureType = {
|
||||
signature: string
|
||||
}
|
||||
|
||||
|
||||
48
src/types.ts
48
src/types.ts
@@ -7,11 +7,11 @@ export type DeepPartial<T> = T extends object ? {
|
||||
[P in keyof T]?: DeepPartial<T[P]>;
|
||||
} : T;
|
||||
|
||||
export interface AssetPairUpdate {
|
||||
export type AssetPairUpdate = {
|
||||
minQty: number
|
||||
pricePrecision: number
|
||||
}
|
||||
export interface SubOrder {
|
||||
export type SubOrder = {
|
||||
pair: string
|
||||
exchange: string
|
||||
id: number
|
||||
@@ -23,7 +23,7 @@ export interface SubOrder {
|
||||
subOrdQty: number
|
||||
}
|
||||
|
||||
export interface Balance {
|
||||
export type Balance = {
|
||||
tradable: string
|
||||
reserved: string
|
||||
contract: string
|
||||
@@ -33,7 +33,7 @@ export interface Balance {
|
||||
|
||||
export type PositionStatus = typeof positionStatuses[number];
|
||||
|
||||
export interface CFDBalance {
|
||||
export type CFDBalance = {
|
||||
instrument: string
|
||||
balance: string
|
||||
profitLoss: string
|
||||
@@ -53,7 +53,7 @@ export interface CFDBalance {
|
||||
status: PositionStatus
|
||||
}
|
||||
|
||||
export interface Order {
|
||||
export type Order = {
|
||||
senderAddress: string // address
|
||||
matcherAddress: string // address
|
||||
baseAsset: string // address
|
||||
@@ -68,7 +68,7 @@ export interface Order {
|
||||
isPersonalSign: boolean // bool
|
||||
}
|
||||
|
||||
export interface CFDOrder {
|
||||
export type CFDOrder = {
|
||||
senderAddress: string // address
|
||||
matcherAddress: string // address
|
||||
instrumentAddress: string // address
|
||||
@@ -81,30 +81,30 @@ export interface CFDOrder {
|
||||
isPersonalSign: boolean // bool
|
||||
}
|
||||
|
||||
export interface SignedCFDOrder extends CFDOrder {
|
||||
export type SignedCFDOrder = {
|
||||
id: string // hash of Order (it's not part of order structure in smart-contract)
|
||||
signature: string // bytes
|
||||
}
|
||||
} & CFDOrder
|
||||
|
||||
export interface SignedOrder extends Order {
|
||||
export type SignedOrder = {
|
||||
id: string // hash of Order (it's not part of order structure in smart-contract)
|
||||
signature: string // bytes
|
||||
needWithdraw?: boolean // bool (not supported yet by smart-contract)
|
||||
}
|
||||
} & Order
|
||||
|
||||
export interface CancelOrderRequest {
|
||||
export type CancelOrderRequest = {
|
||||
id: number | string
|
||||
senderAddress: string
|
||||
isPersonalSign: boolean
|
||||
}
|
||||
|
||||
export interface SignedCancelOrderRequest extends CancelOrderRequest {
|
||||
export type SignedCancelOrderRequest = {
|
||||
id: number | string
|
||||
senderAddress: string
|
||||
signature: string
|
||||
}
|
||||
} & CancelOrderRequest
|
||||
|
||||
export interface Pair {
|
||||
export type Pair = {
|
||||
name: string
|
||||
baseCurrency: string
|
||||
quoteCurrency: string
|
||||
@@ -136,11 +136,11 @@ export enum SupportedChainId {
|
||||
const balanceTypes = ['exchange', 'wallet'] as const;
|
||||
|
||||
export type Source = typeof balanceTypes[number];
|
||||
export interface Asset {
|
||||
export type Asset = {
|
||||
name: string
|
||||
address: string
|
||||
}
|
||||
export interface BalanceRequirement {
|
||||
export type BalanceRequirement = {
|
||||
readonly reason: string
|
||||
readonly asset: Asset
|
||||
readonly amount: string
|
||||
@@ -148,20 +148,20 @@ export interface BalanceRequirement {
|
||||
readonly spenderAddress?: string
|
||||
}
|
||||
|
||||
export interface AggregatedBalanceRequirement {
|
||||
export type AggregatedBalanceRequirement = {
|
||||
readonly asset: Asset
|
||||
readonly sources: Source[]
|
||||
readonly spenderAddress?: string
|
||||
items: Partial<Record<string, string>>
|
||||
}
|
||||
|
||||
export interface ApproveFix {
|
||||
export type ApproveFix = {
|
||||
readonly type: 'byApprove'
|
||||
readonly targetAmount: BigNumber.Value
|
||||
readonly spenderAddress: string
|
||||
}
|
||||
|
||||
export interface DepositFix {
|
||||
export type DepositFix = {
|
||||
readonly type: 'byDeposit'
|
||||
readonly amount: BigNumber.Value
|
||||
readonly asset: string
|
||||
@@ -169,7 +169,7 @@ export interface DepositFix {
|
||||
|
||||
type Fix = ApproveFix | DepositFix;
|
||||
|
||||
export interface BalanceIssue {
|
||||
export type BalanceIssue = {
|
||||
readonly asset: Asset
|
||||
readonly message: string
|
||||
readonly sources: Source[]
|
||||
@@ -178,7 +178,7 @@ export interface BalanceIssue {
|
||||
|
||||
export type Exchange = typeof exchanges[number];
|
||||
|
||||
export interface OrderbookItem {
|
||||
export type OrderbookItem = {
|
||||
price: string
|
||||
amount: string
|
||||
exchanges: Exchange[]
|
||||
@@ -188,7 +188,7 @@ export interface OrderbookItem {
|
||||
}>
|
||||
}
|
||||
|
||||
export interface SwapInfoAlternative {
|
||||
export type SwapInfoAlternative = {
|
||||
exchanges: Exchange[]
|
||||
path: string[]
|
||||
marketAmountOut?: number
|
||||
@@ -198,7 +198,7 @@ export interface SwapInfoAlternative {
|
||||
availableAmountOut?: number
|
||||
}
|
||||
|
||||
export interface SwapInfoBase {
|
||||
export type SwapInfoBase = {
|
||||
swapRequestId: string
|
||||
assetIn: string
|
||||
assetOut: string
|
||||
@@ -243,7 +243,7 @@ export enum HistoryTransactionStatus {
|
||||
CANCELLED = 'Cancelled',
|
||||
}
|
||||
|
||||
export interface VerboseOrionUnitConfig {
|
||||
export type VerboseOrionUnitConfig = {
|
||||
// env?: string;
|
||||
// api: string;
|
||||
chainId: SupportedChainId
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
interface WithReason {
|
||||
type WithReason = {
|
||||
reason: string
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ type WithCodeError = Error & {
|
||||
code: number | string
|
||||
}
|
||||
|
||||
interface WithMessage {
|
||||
type WithMessage = {
|
||||
message: string
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ type WithDataError = Error & {
|
||||
data: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface WithError {
|
||||
type WithError = {
|
||||
error: Record<string | number | symbol, unknown>
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user