Minor fixes

This commit is contained in:
Aleksandr Kraiz
2023-04-12 15:26:37 +04:00
parent e930fd93fa
commit 438de9dba6
15 changed files with 57 additions and 117 deletions

21
package-lock.json generated
View File

@@ -1,18 +1,18 @@
{
"name": "@orionprotocol/sdk",
"version": "0.18.10",
"version": "0.18.12",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.18.10",
"version": "0.18.12",
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.21.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@orionprotocol/contracts": "0.7.0",
"@orionprotocol/contracts": "0.8.0",
"bignumber.js": "^9.1.1",
"bson-objectid": "^2.0.4",
"buffer": "^6.0.3",
@@ -40,7 +40,6 @@
"@types/express": "^4.17.17",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.11",
"@types/socket.io-client": "1.4.33",
"@types/uuid": "^9.0.1",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "^5.57.1",
@@ -58,7 +57,7 @@
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"jest": "^29.5.0",
"ts-jest": "^29.0.5",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.2",
"tsup": "^6.7.0",
"typescript": "^5.0.4"
@@ -2344,9 +2343,9 @@
}
},
"node_modules/@orionprotocol/contracts": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-0.7.0.tgz",
"integrity": "sha512-JOFfAMpw3alfvLWZORruxAKWFR6MPdz0IhSqGRHmgokg0XD42p3EhUFQujzPAY8R2bNnCw7PLlatuY90OEQ3Lw=="
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/@orionprotocol/contracts/-/contracts-0.8.0.tgz",
"integrity": "sha512-oYyP6JKDm3D71nswvA9x46hTurYetjxsn9zio/dHn0pHE2YDgziub0LeFeRjgz8RcANUOs/8qq53cNIiPseU7Q=="
},
"node_modules/@sinclair/typebox": {
"version": "0.25.23",
@@ -2616,12 +2615,6 @@
"@types/node": "*"
}
},
"node_modules/@types/socket.io-client": {
"version": "1.4.33",
"resolved": "https://registry.npmjs.org/@types/socket.io-client/-/socket.io-client-1.4.33.tgz",
"integrity": "sha512-m4LnxkljsI9fMsjwpW5QhRpMixo2BeeLpFmg0AE+sS4H1pzAd/cs/ftTiL60FLZgfFa8PFRPx5KsHu8O0bADKQ==",
"dev": true
},
"node_modules/@types/stack-utils": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz",

View File

@@ -56,7 +56,6 @@
"@types/express": "^4.17.17",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.11",
"@types/socket.io-client": "1.4.33",
"@types/uuid": "^9.0.1",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "^5.57.1",
@@ -74,7 +73,7 @@
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"jest": "^29.5.0",
"ts-jest": "^29.0.5",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.2",
"tsup": "^6.7.0",
"typescript": "^5.0.4"
@@ -83,7 +82,7 @@
"@babel/runtime": "^7.21.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@orionprotocol/contracts": "0.7.0",
"@orionprotocol/contracts": "0.8.0",
"bignumber.js": "^9.1.1",
"bson-objectid": "^2.0.4",
"buffer": "^6.0.3",

View File

@@ -11,7 +11,7 @@ import {
REDEEMATOMIC_GAS_LIMIT,
WITHDRAW_GAS_LIMIT
} from '../../constants/index.js';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency.js';
import getNativeCryptocurrencyName from '../../utils/getNativeCryptocurrencyName.js';
import { denormalizeNumber, generateSecret, normalizeNumber, toUpperCase } from '../../utils/index.js';
import type { SupportedChainId } from '../../types.js';
import type Orion from '../index.js';
@@ -100,7 +100,7 @@ export default async function swap({
assetToAddress: sourceAssetToAddress,
} = await simpleFetch(sourceOrionBlockchain.getInfo)();
const sourceChainNativeCryptocurrency = getNativeCryptocurrency(sourceAssetToAddress);
const sourceChainNativeCryptocurrency = getNativeCryptocurrencyName(sourceAssetToAddress);
const sourceExchangeContract = Exchange__factory.connect(sourceExchangeContractAddress, sourceProvider);
// const sourceChainGasPriceWei = await simpleFetch(sourceOrionBlockchain.getGasPriceWei)();
@@ -114,7 +114,7 @@ export default async function swap({
const targetChainAssetAddress = targetAssetToAddress[assetName];
if (targetChainAssetAddress === undefined) throw new Error(`Asset '${assetName}' not found in target chain`);
const targetChainNativeCryptocurrency = getNativeCryptocurrency(targetAssetToAddress);
const targetChainNativeCryptocurrency = getNativeCryptocurrencyName(targetAssetToAddress);
const targetExchangeContract = Exchange__factory.connect(targetExchangeContractAddress, targetProvider);
const sourceChainBalances = await getBalances(

View File

@@ -8,7 +8,7 @@ import {
DEPOSIT_ERC20_GAS_LIMIT, DEPOSIT_ETH_GAS_LIMIT, INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION,
} from '../../constants/index.js';
import { denormalizeNumber, normalizeNumber } from '../../utils/index.js';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency.js';
import getNativeCryptocurrencyName from '../../utils/getNativeCryptocurrencyName.js';
import { simpleFetch } from 'simple-typed-fetch';
export type DepositParams = {
@@ -40,7 +40,7 @@ export default async function deposit({
assetToAddress,
} = await simpleFetch(orionBlockchain.getInfo)();
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress);
const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider);
const gasPriceWei = await simpleFetch(orionBlockchain.getGasPriceWei)();

View File

@@ -5,7 +5,7 @@ import { NATIVE_CURRENCY_PRECISION, SWAP_THROUGH_ORION_POOL_GAS_LIMIT } from '..
import type { OrionAggregator } from '../../services/OrionAggregator/index.js';
import type { OrionBlockchain } from '../../services/OrionBlockchain/index.js';
import { calculateFeeInFeeAsset, denormalizeNumber, getNativeCryptocurrency } from '../../utils/index.js';
import { calculateFeeInFeeAsset, denormalizeNumber, getNativeCryptocurrencyName } from '../../utils/index.js';
export type GetSwapInfoParams = {
type: 'exactSpend' | 'exactReceive'
@@ -43,7 +43,7 @@ export default async function getSwapInfo({
const {
assetToAddress,
} = await simpleFetch(orionBlockchain.getInfo)();
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const nativeCryptocurrencyName = getNativeCryptocurrencyName(assetToAddress);
const feeAssets = await simpleFetch(orionBlockchain.getTokensFee)();
const pricesInOrn = await simpleFetch(orionBlockchain.getPrices)();
@@ -106,7 +106,7 @@ export default async function getSwapInfo({
route,
swapInfo,
fee: {
assetName: nativeCryptocurrency,
assetName: nativeCryptocurrencyName,
assetAddress: ethers.constants.AddressZero,
networkFeeInFeeAsset: denormalizedTransactionCost.toString(),
protocolFeeInFeeAsset: undefined,

View File

@@ -6,7 +6,7 @@ import BalanceGuard from '../../BalanceGuard.js';
import getAvailableSources from '../../utils/getAvailableFundsSources.js';
import type OrionUnit from '../index.js';
import { INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION, SWAP_THROUGH_ORION_POOL_GAS_LIMIT } from '../../constants/index.js';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency.js';
import getNativeCryptocurrencyName from '../../utils/getNativeCryptocurrencyName.js';
import { calculateFeeInFeeAsset, denormalizeNumber, normalizeNumber } from '../../utils/index.js';
import { signOrder } from '../../crypt/index.js';
import type orderSchema from '../../services/OrionAggregator/schemas/orderSchema.js';
@@ -86,7 +86,7 @@ export default async function swapLimit({
matcherAddress,
assetToAddress,
} = await simpleFetch(orionBlockchain.getInfo)();
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress);
const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider);
const feeAssets = await simpleFetch(orionBlockchain.getTokensFee)();

View File

@@ -5,7 +5,7 @@ import getBalances from '../../utils/getBalances.js';
import BalanceGuard from '../../BalanceGuard.js';
import getAvailableSources from '../../utils/getAvailableFundsSources.js';
import { INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION, SWAP_THROUGH_ORION_POOL_GAS_LIMIT } from '../../constants/index.js';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency.js';
import getNativeCryptocurrencyName from '../../utils/getNativeCryptocurrencyName.js';
import { calculateFeeInFeeAsset, denormalizeNumber, normalizeNumber } from '../../utils/index.js';
import { signOrder } from '../../crypt/index.js';
import type orderSchema from '../../services/OrionAggregator/schemas/orderSchema.js';
@@ -71,7 +71,7 @@ export default async function swapMarket({
matcherAddress,
assetToAddress,
} = await simpleFetch(orionBlockchain.getInfo)();
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress);
const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider);
const feeAssets = await simpleFetch(orionBlockchain.getTokensFee)();

View File

@@ -8,7 +8,7 @@ import {
INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION, WITHDRAW_GAS_LIMIT,
} from '../../constants/index.js';
import { denormalizeNumber, normalizeNumber } from '../../utils/index.js';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency.js';
import getNativeCryptocurrencyName from '../../utils/getNativeCryptocurrencyName.js';
import { simpleFetch } from 'simple-typed-fetch';
export type WithdrawParams = {
@@ -40,7 +40,7 @@ export default async function withdraw({
assetToAddress,
} = await simpleFetch(orionBlockchain.getInfo)();
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress);
const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider);
const gasPriceWei = await simpleFetch(orionBlockchain.getGasPriceWei)();

View File

@@ -7,7 +7,7 @@ import BalanceGuard from '../../BalanceGuard.js';
import { ADD_LIQUIDITY_GAS_LIMIT, INTERNAL_ORION_PRECISION, NATIVE_CURRENCY_PRECISION } from '../../constants/index.js';
import { denormalizeNumber, normalizeNumber } from '../../utils/index.js';
import getBalances from '../../utils/getBalances.js';
import getNativeCryptocurrency from '../../utils/getNativeCryptocurrency.js';
import getNativeCryptocurrencyName from '../../utils/getNativeCryptocurrencyName.js';
const ADD_LIQUIDITY_SLIPPAGE = 0.05;
@@ -66,7 +66,7 @@ export default class FarmingManager {
const assetBDecimals = assetToDecimals[assetB];
if (assetBDecimals === undefined) throw new Error(`Decimals for asset '${assetB}' not found`);
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress);
const balances = await getBalances(
{
[assetA]: assetAAddress,
@@ -248,7 +248,7 @@ export default class FarmingManager {
const exchangeContract = Exchange__factory
.connect(exchangeContractAddress, this.orionUnit.provider);
const nativeCryptocurrency = getNativeCryptocurrency(assetToAddress);
const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress);
const balances = await getBalances(
{
[assetA]: assetAAddress,

View File

@@ -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,
};
}

View File

@@ -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,
}), {});
};

View File

@@ -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;

View 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;

View File

@@ -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';

View File

@@ -1,54 +0,0 @@
const path = require("path");
module.exports = (env, argv) => {
return {
mode: "production",
entry: {
index: path.resolve(__dirname, "./lib/esm/index.js")
},
externals: [
'node:util',
'node:zlib',
'node:url',
'node:stream',
'node:stream/web',
'node:process',
'node:path',
'node:net',
'node:http',
'node:https',
'node:fs',
'node:buffer',
'worker_threads',
'unfetch'
],
output: {
path: path.resolve(__dirname, "./lib/umd"), // builds to ./lib/umd/
filename: "[name].js", // index.js
library: "orionprotocol", // aka window.myLibrary
libraryTarget: "umd", // supports commonjs, amd and web browsers
globalObject: "this"
},
module: {
rules: [{
test: /\.t|js$/,
use: {
loader: "babel-loader",
options: {
plugins: [
"@babel/plugin-syntax-import-assertions",
],
}
}
}]
},
resolve: {
extensions: ['.ts', '.js'],
fallback: {
"crypto": require.resolve("crypto-browserify"),
"buffer": require.resolve("buffer/"),
"stream": require.resolve("stream-browserify"),
}
}
};
};