mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-25 15:17:40 +03:00
Minor fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ERC20__factory, type Exchange } from '@orionprotocol/contracts';
|
||||
|
||||
import type { BigNumber } from 'bignumber.js';
|
||||
import type { BigNumber } from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION } from '../constants/index.js';
|
||||
import type { OrionAggregator } from '../services/OrionAggregator/index.js';
|
||||
@@ -8,7 +8,7 @@ import denormalizeNumber from './denormalizeNumber.js';
|
||||
|
||||
export default async function getBalance(
|
||||
orionAggregator: OrionAggregator,
|
||||
asset: string,
|
||||
assetName: string,
|
||||
assetAddress: string,
|
||||
walletAddress: string,
|
||||
exchangeContract: Exchange,
|
||||
@@ -32,13 +32,13 @@ export default async function getBalance(
|
||||
}
|
||||
const assetContractBalance = await exchangeContract.getBalance(assetAddress, walletAddress);
|
||||
const denormalizedAssetInContractBalance = denormalizeNumber(assetContractBalance, INTERNAL_ORION_PRECISION);
|
||||
const denormalizedAssetLockedBalanceResult = await orionAggregator.getLockedBalance(walletAddress, asset);
|
||||
const denormalizedAssetLockedBalanceResult = await orionAggregator.getLockedBalance(walletAddress, assetName);
|
||||
if (denormalizedAssetLockedBalanceResult.isErr()) {
|
||||
throw new Error(denormalizedAssetLockedBalanceResult.error.message);
|
||||
}
|
||||
|
||||
return {
|
||||
exchange: denormalizedAssetInContractBalance.minus(denormalizedAssetLockedBalanceResult.value[asset] ?? 0),
|
||||
exchange: denormalizedAssetInContractBalance.minus(denormalizedAssetLockedBalanceResult.value[assetName] ?? 0),
|
||||
wallet: denormalizedAssetInWalletBalance,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,18 +13,18 @@ export default async (
|
||||
) => {
|
||||
const balances = await Promise.all(
|
||||
Object.entries(balancesRequired)
|
||||
.map(async ([asset, assetAddress]) => {
|
||||
if (assetAddress === undefined) throw new Error(`Asset address of ${asset} not found`);
|
||||
.map(async ([assetName, assetAddress]) => {
|
||||
if (assetAddress === undefined) throw new Error(`Asset address of ${assetName} not found`);
|
||||
const balance = await getBalance(
|
||||
orionAggregator,
|
||||
asset,
|
||||
assetName,
|
||||
assetAddress,
|
||||
walletAddress,
|
||||
exchangeContract,
|
||||
provider,
|
||||
);
|
||||
return {
|
||||
asset,
|
||||
assetName,
|
||||
amount: balance,
|
||||
};
|
||||
}),
|
||||
@@ -35,6 +35,6 @@ export default async (
|
||||
wallet: BigNumber
|
||||
}>>>((prev, curr) => ({
|
||||
...prev,
|
||||
[curr.asset]: curr.amount,
|
||||
[curr.assetName]: curr.amount,
|
||||
}), {});
|
||||
};
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { ethers } from 'ethers';
|
||||
|
||||
const getNativeCryptocurrency = (assetToAddress: Partial<Record<string, string>>) => {
|
||||
const addressToAsset = Object
|
||||
.entries(assetToAddress)
|
||||
.reduce<Partial<Record<string, string>>>((prev, [asset, address]) => {
|
||||
if (address === undefined) return prev;
|
||||
return {
|
||||
...prev,
|
||||
[address]: asset,
|
||||
};
|
||||
}, {});
|
||||
|
||||
const nativeCryptocurrency = addressToAsset[ethers.constants.AddressZero];
|
||||
if (nativeCryptocurrency === undefined) throw new Error('Native cryptocurrency asset is not found');
|
||||
return nativeCryptocurrency;
|
||||
};
|
||||
|
||||
export default getNativeCryptocurrency;
|
||||
21
src/utils/getNativeCryptocurrencyName.ts
Normal file
21
src/utils/getNativeCryptocurrencyName.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ethers } from 'ethers';
|
||||
|
||||
const getNativeCryptocurrencyName = (assetToAddress: Partial<Record<string, string>>) => {
|
||||
const addressToAssetName = Object
|
||||
.entries(assetToAddress)
|
||||
.reduce<Partial<Record<string, string>>>((prev, [assetName, address]) => {
|
||||
if (address === undefined) return prev;
|
||||
return {
|
||||
...prev,
|
||||
[address]: assetName,
|
||||
};
|
||||
}, {});
|
||||
|
||||
const nativeCryptocurrencyName = addressToAssetName[ethers.constants.AddressZero];
|
||||
if (nativeCryptocurrencyName === undefined) {
|
||||
throw new Error('Native cryptocurrency asset name is not found');
|
||||
}
|
||||
return nativeCryptocurrencyName;
|
||||
};
|
||||
|
||||
export default getNativeCryptocurrencyName;
|
||||
@@ -11,7 +11,7 @@ export { default as parseExchangeTradeTransaction } from './parseExchangeTradeTr
|
||||
export { default as toUpperCase } from './toUpperCase.js';
|
||||
export { default as toLowerCase } from './toLowerCase.js';
|
||||
export { default as isUppercasedNetworkCode } from './isUppercasedNetworkCode.js';
|
||||
export { default as getNativeCryptocurrency } from './getNativeCryptocurrency.js';
|
||||
export { default as getNativeCryptocurrencyName } from './getNativeCryptocurrencyName.js';
|
||||
|
||||
export { default as isValidChainId } from './isValidChainId.js';
|
||||
export { default as isKnownEnv } from './isKnownEnv.js';
|
||||
|
||||
Reference in New Issue
Block a user