mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 14:42:38 +03:00
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable camelcase */
|
||||
import { ERC20__factory } from '@orionprotocol/contracts';
|
||||
import { ethers } from 'ethers';
|
||||
import invariant from 'tiny-invariant';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { type ethers } from 'ethers';
|
||||
|
||||
/**
|
||||
* Converts normalized blockchain ("machine-readable") number to denormalized ("human-readable") number.
|
||||
@@ -9,6 +9,6 @@ import { ethers } from 'ethers';
|
||||
*/
|
||||
export default function denormalizeNumber(input: ethers.BigNumber, decimals: BigNumber.Value) {
|
||||
const decimalsBN = new BigNumber(decimals);
|
||||
if (!decimalsBN.isInteger()) throw new Error(`Decimals '${decimals.toString()}' is not an integer`);
|
||||
if (!decimalsBN.isInteger()) throw new Error(`Decimals '${decimalsBN.toString()}' is not an integer`);
|
||||
return new BigNumber(input.toString()).div(new BigNumber(10).pow(decimalsBN));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ethers } from 'ethers';
|
||||
import { Source } from '../types';
|
||||
import { type Source } from '../types';
|
||||
|
||||
export default function getAvailableFundsSources(
|
||||
expenseType: 'amount' | 'network_fee' | 'orion_fee',
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ERC20__factory, Exchange } from '@orionprotocol/contracts';
|
||||
import { ERC20__factory, type Exchange } from '@orionprotocol/contracts';
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
import type BigNumber from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { utils } from '..';
|
||||
import { INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION } from '../constants';
|
||||
import { OrionAggregator } from '../services/OrionAggregator';
|
||||
import { type OrionAggregator } from '../services/OrionAggregator';
|
||||
import denormalizeNumber from './denormalizeNumber';
|
||||
|
||||
export default async function getBalance(
|
||||
orionAggregator: OrionAggregator,
|
||||
@@ -25,13 +25,13 @@ export default async function getBalance(
|
||||
const assetDecimals = await assetContract.decimals();
|
||||
assetWalletBalance = await assetContract.balanceOf(walletAddress);
|
||||
|
||||
denormalizedAssetInWalletBalance = utils.denormalizeNumber(assetWalletBalance, assetDecimals);
|
||||
denormalizedAssetInWalletBalance = denormalizeNumber(assetWalletBalance, assetDecimals);
|
||||
} else {
|
||||
assetWalletBalance = await provider.getBalance(walletAddress);
|
||||
denormalizedAssetInWalletBalance = utils.denormalizeNumber(assetWalletBalance, NATIVE_CURRENCY_PRECISION);
|
||||
denormalizedAssetInWalletBalance = denormalizeNumber(assetWalletBalance, NATIVE_CURRENCY_PRECISION);
|
||||
}
|
||||
const assetContractBalance = await exchangeContract.getBalance(assetAddress, walletAddress);
|
||||
const denormalizedAssetInContractBalance = utils.denormalizeNumber(assetContractBalance, INTERNAL_ORION_PRECISION);
|
||||
const denormalizedAssetInContractBalance = denormalizeNumber(assetContractBalance, INTERNAL_ORION_PRECISION);
|
||||
const denormalizedAssetLockedBalanceResult = await orionAggregator.getLockedBalance(walletAddress, asset);
|
||||
if (denormalizedAssetLockedBalanceResult.isErr()) {
|
||||
throw new Error(denormalizedAssetLockedBalanceResult.error.message);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Exchange } from '@orionprotocol/contracts';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { OrionAggregator } from '../services/OrionAggregator';
|
||||
import { type Exchange } from '@orionprotocol/contracts';
|
||||
import type BigNumber from 'bignumber.js';
|
||||
import { type ethers } from 'ethers';
|
||||
import { type OrionAggregator } from '../services/OrionAggregator';
|
||||
import getBalance from './getBalance';
|
||||
|
||||
export default async (
|
||||
@@ -14,7 +14,7 @@ export default async (
|
||||
const balances = await Promise.all(
|
||||
Object.entries(balancesRequired)
|
||||
.map(async ([asset, assetAddress]) => {
|
||||
if (!assetAddress) throw new Error(`Asset address of ${asset} not found`);
|
||||
if (assetAddress === undefined) throw new Error(`Asset address of ${asset} not found`);
|
||||
const balance = await getBalance(
|
||||
orionAggregator,
|
||||
asset,
|
||||
@@ -31,8 +31,8 @@ export default async (
|
||||
);
|
||||
|
||||
return balances.reduce<Partial<Record<string, {
|
||||
exchange: BigNumber,
|
||||
wallet: BigNumber,
|
||||
exchange: BigNumber
|
||||
wallet: BigNumber
|
||||
}>>>((prev, curr) => ({
|
||||
...prev,
|
||||
[curr.asset]: curr.amount,
|
||||
|
||||
@@ -4,7 +4,7 @@ const getNativeCryptocurrency = (assetToAddress: Partial<Record<string, string>>
|
||||
const addressToAsset = Object
|
||||
.entries(assetToAddress)
|
||||
.reduce<Partial<Record<string, string>>>((prev, [asset, address]) => {
|
||||
if (!address) return prev;
|
||||
if (address === undefined) return prev;
|
||||
return {
|
||||
...prev,
|
||||
[address]: asset,
|
||||
@@ -12,7 +12,7 @@ const getNativeCryptocurrency = (assetToAddress: Partial<Record<string, string>>
|
||||
}, {});
|
||||
|
||||
const nativeCryptocurrency = addressToAsset[ethers.constants.AddressZero];
|
||||
if (!nativeCryptocurrency) throw new Error('Native cryptocurrency asset is not found');
|
||||
if (nativeCryptocurrency === undefined) throw new Error('Native cryptocurrency asset is not found');
|
||||
return nativeCryptocurrency;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
export default class HttpError extends Error {
|
||||
public code: number;
|
||||
|
||||
public errorMessage: string |null;
|
||||
public errorMessage: string | null;
|
||||
|
||||
public statusText: string;
|
||||
|
||||
public type: string;
|
||||
|
||||
constructor(code:number, message:string|null, type: string, statusText:string) {
|
||||
super(message || '');
|
||||
constructor(code: number, message: string | null, type: string, statusText: string) {
|
||||
super(message ?? '');
|
||||
this.errorMessage = message;
|
||||
this.type = type;
|
||||
this.statusText = statusText;
|
||||
|
||||
@@ -12,6 +12,7 @@ export { default as parseExchangeTradeTransaction } from './parseExchangeTradeTr
|
||||
export { default as toUpperCase } from './toUpperCase';
|
||||
export { default as toLowerCase } from './toLowerCase';
|
||||
export { default as isUppercasedNetworkCode } from './isUppercasedNetworkCode';
|
||||
export { default as getNativeCryptocurrency } from './getNativeCryptocurrency';
|
||||
|
||||
// export { default as HttpError } from './httpError';
|
||||
|
||||
|
||||
@@ -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() &&
|
||||
|
||||
@@ -14,7 +14,7 @@ export default function normalizeNumber(
|
||||
roundingMode: BigNumber.RoundingMode,
|
||||
) {
|
||||
const decimalsBN = new BigNumber(decimals);
|
||||
if (!decimalsBN.isInteger()) throw new Error(`Decimals '${decimals.toString()}' is not an integer`);
|
||||
if (!decimalsBN.isInteger()) throw new Error(`Decimals '${decimalsBN.toString()}' is not an integer`);
|
||||
const inputBN = new BigNumber(input);
|
||||
return ethers.BigNumber.from(
|
||||
inputBN
|
||||
|
||||
@@ -14,4 +14,4 @@ const untypedItems = Object.keys(items); // => Array<string>
|
||||
@category Type guard
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
export const objectKeys = Object.keys as <Type extends object>(value: Type) => ObjectKeys<Type>[];
|
||||
export const objectKeys = Object.keys as <Type extends object>(value: Type) => Array<ObjectKeys<Type>>;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
type WithReason = {
|
||||
reason: string;
|
||||
reason: string
|
||||
}
|
||||
|
||||
type WithCodeError = Error & {
|
||||
code: number | string;
|
||||
code: number | string
|
||||
}
|
||||
|
||||
type WithMessage = {
|
||||
message: string;
|
||||
message: string
|
||||
}
|
||||
|
||||
type WithDataError = Error & {
|
||||
data: Record<string, unknown>;
|
||||
data: Record<string, unknown>
|
||||
}
|
||||
|
||||
type WithError ={
|
||||
error: Record<string | number | symbol, unknown>;
|
||||
type WithError = {
|
||||
error: Record<string | number | symbol, unknown>
|
||||
}
|
||||
|
||||
export const makePartial = <Key extends string | number | symbol, Value>(value: Record<Key, Value>): Partial<Record<Key, Value>> => value;
|
||||
|
||||
Reference in New Issue
Block a user