From 0a17972783b084fc5c90de2830b1f6fd5f6cca1a Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Fri, 22 Apr 2022 18:40:14 +0400 Subject: [PATCH] Removed unnecessary balance requirement --- package.json | 2 +- src/OrionUnit/Exchange/swapMarket.ts | 31 ++++++++++++++++------------ src/index.ts | 4 ++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 241cd1b..cc9c83b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.2.3", + "version": "0.2.4", "description": "Orion Protocol SDK", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/OrionUnit/Exchange/swapMarket.ts b/src/OrionUnit/Exchange/swapMarket.ts index 7647256..dbfd532 100644 --- a/src/OrionUnit/Exchange/swapMarket.ts +++ b/src/OrionUnit/Exchange/swapMarket.ts @@ -19,7 +19,7 @@ export type SwapMarketParams = { orionUnit: OrionUnit, options?: { logger?: (message: string) => void, - // route?: 'pool' | 'aggregator', + route?: 'pool' | 'aggregator', autoApprove?: boolean, } } @@ -47,6 +47,7 @@ export default async function swapMarket({ orionUnit, options, }: SwapMarketParams): Promise { + if (options?.route) options?.logger?.('Warning! You specified route in options. Please use only if you know what you are doing.'); if (amount === '') throw new Error('Amount can not be empty'); if (assetIn === '') throw new Error('AssetIn can not be empty'); if (assetOut === '') throw new Error('AssetOut can not be empty'); @@ -134,7 +135,11 @@ export default async function swapMarket({ const percent = new BigNumber(slippagePercent).div(100); - if (swapInfo.isThroughPoolOptimal) { + const isThroughPoolOptimal = options?.route + ? options?.route === 'pool' + : swapInfo.isThroughPoolOptimal; + + if (isThroughPoolOptimal) { options?.logger?.('Swap through pool'); const pathAddresses = swapInfo.path.map((name) => { const assetAddress = assetToAddress?.[name]; @@ -206,17 +211,17 @@ export default async function swapMarket({ sources: getAvailableSources('network_fee', ethers.constants.AddressZero, 'orion_pool'), }); - if (value.gt(0)) { - balanceGuard.registerRequirement({ - reason: 'Transaction value (extra amount)', - asset: { - name: nativeCryptocurrency, - address: ethers.constants.AddressZero, - }, - amount: value.toString(), - sources: getAvailableSources('amount', ethers.constants.AddressZero, 'orion_pool'), - }); - } + // if (value.gt(0)) { + // balanceGuard.registerRequirement({ + // reason: 'Transaction value (extra amount)', + // asset: { + // name: nativeCryptocurrency, + // address: ethers.constants.AddressZero, + // }, + // amount: value.toString(), + // sources: getAvailableSources('amount', ethers.constants.AddressZero, 'orion_pool'), + // }); + // } await balanceGuard.check(options?.autoApprove); diff --git a/src/index.ts b/src/index.ts index 797487b..8f75e6b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,7 @@ +import BigNumber from 'bignumber.js'; + +BigNumber.config({ EXPONENTIAL_AT: 1e9 }); + export * as config from './config'; // export * from './entities'; export { default as OrionUnit } from './OrionUnit';