Add liquidity / remove liquidity / balancee guard improvements

This commit is contained in:
Aleksandr Kraiz
2022-04-22 23:11:14 +04:00
parent 0a17972783
commit 0804b592d8
11 changed files with 467 additions and 61 deletions

View File

@@ -9,6 +9,7 @@ import {
DEPOSIT_ERC20_GAS_LIMIT, DEPOSIT_ETH_GAS_LIMIT, INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION,
} from '../../constants';
import { normalizeNumber } from '../../utils';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
export type DepositParams = {
asset: string,
@@ -38,18 +39,8 @@ export default async function deposit({
exchangeContractAddress,
assetToAddress,
} = await orionBlockchain.getInfo();
const addressToAsset = Object
.entries(assetToAddress)
.reduce<Partial<Record<string, string>>>((prev, [assetName, address]) => {
if (!address) return prev;
return {
...prev,
[address]: assetName,
};
}, {});
const nativeCryptocurrency = addressToAsset[ethers.constants.AddressZero];
if (!nativeCryptocurrency) throw new Error('Native cryptocurrency asset is not found');
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const exchangeContract = contracts.Exchange__factory.connect(exchangeContractAddress, provider);
const gasPriceWei = await orionBlockchain.getGasPriceWei();

View File

@@ -7,6 +7,7 @@ import getAvailableSources from '../../utils/getAvailableFundsSources';
import OrionUnit from '..';
import { contracts, crypt, utils } from '../..';
import { INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION, SWAP_THROUGH_ORION_POOL_GAS_LIMIT } from '../../constants';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
export type SwapMarketParams = {
type: 'exactSpend' | 'exactReceive',
@@ -74,18 +75,7 @@ export default async function swapMarket({
matcherAddress,
assetToAddress,
} = await orionBlockchain.getInfo();
const addressToAsset = Object
.entries(assetToAddress)
.reduce<Partial<Record<string, string>>>((prev, [asset, address]) => {
if (!address) return prev;
return {
...prev,
[address]: asset,
};
}, {});
const nativeCryptocurrency = addressToAsset[ethers.constants.AddressZero];
if (!nativeCryptocurrency) throw new Error('Native cryptocurrency asset is not found');
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const exchangeContract = contracts.Exchange__factory.connect(exchangeContractAddress, provider);
const feeAssets = await orionBlockchain.getTokensFee();

View File

@@ -9,6 +9,7 @@ import {
INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION, WITHDRAW_GAS_LIMIT,
} from '../../constants';
import { normalizeNumber } from '../../utils';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency';
export type WithdrawParams = {
asset: string,
@@ -39,19 +40,7 @@ export default async function withdraw({
assetToAddress,
} = await orionBlockchain.getInfo();
const addressToAsset = Object
.entries(assetToAddress)
.reduce<Partial<Record<string, string>>>((prev, [assetName, address]) => {
if (!address) return prev;
return {
...prev,
[address]: assetName,
};
}, {});
const nativeCryptocurrency = addressToAsset[ethers.constants.AddressZero];
if (!nativeCryptocurrency) throw new Error('Native cryptocurrency asset is not found');
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const exchangeContract = contracts.Exchange__factory.connect(exchangeContractAddress, provider);
const gasPriceWei = await orionBlockchain.getGasPriceWei();