mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 06:32:37 +03:00
Semantics improvements
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import { FILL_ORDERS_GAS_LIMIT } from '../constants/index.js';
|
||||
import calculateNetworkFeeInFeeAsset from './calculateNetworkFeeInFeeAsset.js';
|
||||
import calculateOrionFeeInFeeAsset from './calculateOrionFeeInFeeAsset.js';
|
||||
import calculateServiceFeeInFeeAsset from './calculateServiceFeeInFeeAsset.js';
|
||||
|
||||
const calculateFeeInFeeAsset = (
|
||||
amount: BigNumber.Value,
|
||||
@@ -11,7 +11,7 @@ const calculateFeeInFeeAsset = (
|
||||
gasPriceGwei: BigNumber.Value,
|
||||
feePercent: BigNumber.Value,
|
||||
) => {
|
||||
const orionFeeInFeeAsset = calculateOrionFeeInFeeAsset(
|
||||
const serviceFeeInFeeAsset = calculateServiceFeeInFeeAsset(
|
||||
amount,
|
||||
feeAssetPriceInOrn,
|
||||
baseAssetPriceInOrn,
|
||||
@@ -25,9 +25,9 @@ const calculateFeeInFeeAsset = (
|
||||
);
|
||||
|
||||
return {
|
||||
orionFeeInFeeAsset,
|
||||
serviceFeeInFeeAsset,
|
||||
networkFeeInFeeAsset,
|
||||
totalFeeInFeeAsset: new BigNumber(orionFeeInFeeAsset)
|
||||
totalFeeInFeeAsset: new BigNumber(serviceFeeInFeeAsset)
|
||||
.plus(networkFeeInFeeAsset)
|
||||
.toString(),
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
|
||||
export default function calculateOrionFeeInFeeAsset(
|
||||
export default function calculateServiceFeeInFeeAsset(
|
||||
amount: BigNumber.Value,
|
||||
feeAssetPriceInOrn: BigNumber.Value,
|
||||
baseAssetPriceInOrn: BigNumber.Value,
|
||||
@@ -2,17 +2,17 @@ import { ethers } from 'ethers';
|
||||
import type { Source } from '../types.js';
|
||||
|
||||
export default function getAvailableFundsSources(
|
||||
expenseType: 'amount' | 'network_fee' | 'orion_fee',
|
||||
expenseType: 'amount' | 'network_fee' | 'service_fee',
|
||||
assetAddress: string,
|
||||
route: 'aggregator' | 'orion_pool',
|
||||
route: 'aggregator' | 'pool',
|
||||
): Source[] {
|
||||
switch (route) {
|
||||
case 'aggregator':
|
||||
if (assetAddress === ethers.constants.AddressZero) return ['exchange']; // We can't take native crypto from wallet
|
||||
return ['exchange', 'wallet']; // We can take any token amount from exchange + wallet. Order is important!
|
||||
case 'orion_pool':
|
||||
case 'pool':
|
||||
if (expenseType === 'network_fee') return ['wallet']; // Network fee is always taken from wallet
|
||||
return ['exchange', 'wallet']; // We can take any token amount from exchange + wallet (specify 'value' for 'orion_pool'). Order is important!
|
||||
return ['exchange', 'wallet']; // We can take any token amount from exchange + wallet (specify 'value' for 'pool'). Order is important!
|
||||
default:
|
||||
throw new Error('Unknown route item');
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ import type { Exchange } from '@orionprotocol/contracts/lib/ethers-v5/index.js';
|
||||
import { ERC20__factory } from '@orionprotocol/contracts/lib/ethers-v5/index.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';
|
||||
import { INTERNAL_PROTOCOL_PRECISION, NATIVE_CURRENCY_PRECISION } from '../constants/index.js';
|
||||
import type { Aggregator } from '../services/Aggregator/index.js';
|
||||
import denormalizeNumber from './denormalizeNumber.js';
|
||||
|
||||
export default async function getBalance(
|
||||
orionAggregator: OrionAggregator,
|
||||
aggregator: Aggregator,
|
||||
assetName: string,
|
||||
assetAddress: string,
|
||||
walletAddress: string,
|
||||
@@ -31,8 +31,8 @@ export default async function getBalance(
|
||||
denormalizedAssetInWalletBalance = denormalizeNumber(assetWalletBalance, NATIVE_CURRENCY_PRECISION);
|
||||
}
|
||||
const assetContractBalance = await exchangeContract.getBalance(assetAddress, walletAddress);
|
||||
const denormalizedAssetInContractBalance = denormalizeNumber(assetContractBalance, INTERNAL_ORION_PRECISION);
|
||||
const denormalizedAssetLockedBalanceResult = await orionAggregator.getLockedBalance(walletAddress, assetName);
|
||||
const denormalizedAssetInContractBalance = denormalizeNumber(assetContractBalance, INTERNAL_PROTOCOL_PRECISION);
|
||||
const denormalizedAssetLockedBalanceResult = await aggregator.getLockedBalance(walletAddress, assetName);
|
||||
if (denormalizedAssetLockedBalanceResult.isErr()) {
|
||||
throw new Error(denormalizedAssetLockedBalanceResult.error.message);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { Exchange } from '@orionprotocol/contracts/lib/ethers-v5/index.js';
|
||||
import type { BigNumber } from 'bignumber.js';
|
||||
import type { ethers } from 'ethers';
|
||||
import type { OrionAggregator } from '../services/OrionAggregator/index.js';
|
||||
import type { Aggregator } from '../services/Aggregator/index.js';
|
||||
import getBalance from './getBalance.js';
|
||||
|
||||
export default async (
|
||||
balancesRequired: Partial<Record<string, string>>,
|
||||
orionAggregator: OrionAggregator,
|
||||
aggregator: Aggregator,
|
||||
walletAddress: string,
|
||||
exchangeContract: Exchange,
|
||||
provider: ethers.providers.Provider,
|
||||
@@ -16,7 +16,7 @@ export default async (
|
||||
.map(async ([assetName, assetAddress]) => {
|
||||
if (assetAddress === undefined) throw new Error(`Asset address of ${assetName} not found`);
|
||||
const balance = await getBalance(
|
||||
orionAggregator,
|
||||
aggregator,
|
||||
assetName,
|
||||
assetAddress,
|
||||
walletAddress,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export { default as calculateFeeInFeeAsset } from './calculateFeeInFeeAsset.js';
|
||||
export { default as calculateNetworkFee } from './calculateNetworkFee.js';
|
||||
export { default as calculateNetworkFeeInFeeAsset } from './calculateNetworkFeeInFeeAsset.js';
|
||||
export { default as calculateOrionFeeInFeeAsset } from './calculateOrionFeeInFeeAsset.js';
|
||||
export { default as calculateOrionFeeInFeeAsset } from './calculateServiceFeeInFeeAsset.js';
|
||||
export { default as checkIsToken } from './checkIsToken.js';
|
||||
export { default as generateSecret } from './generateSecret.js';
|
||||
export { default as denormalizeNumber } from './denormalizeNumber.js';
|
||||
|
||||
Reference in New Issue
Block a user