From 4d2e006db083ef0c736f52d6c7199d1f8e7cc216 Mon Sep 17 00:00:00 2001 From: lomonoshka Date: Thu, 30 Nov 2023 14:46:52 +0400 Subject: [PATCH] dont use exchangeBalance if it's 0 --- package.json | 2 +- src/Unit/Exchange/generateSwapCalldata.ts | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 73edc35..e74467e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.26-rc1", + "version": "0.20.26-rc2", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Unit/Exchange/generateSwapCalldata.ts b/src/Unit/Exchange/generateSwapCalldata.ts index 74f08fe..73c3f4c 100644 --- a/src/Unit/Exchange/generateSwapCalldata.ts +++ b/src/Unit/Exchange/generateSwapCalldata.ts @@ -61,7 +61,9 @@ export async function generateSwapCalldataWithUnit({ } const wethAddress = safeGet(unit.contracts, "WETH"); const curveRegistryAddress = safeGet(unit.contracts, "curveRegistry"); - const { assetToAddress, swapExecutorContractAddress, exchangeContractAddress } = await simpleFetch(unit.blockchainService.getInfo)(); + const { assetToAddress, swapExecutorContractAddress, exchangeContractAddress } = await simpleFetch( + unit.blockchainService.getInfo + )(); const arrayLikePathCopy = cloneDeep(arrayLikePath); let path = SafeArray.from(arrayLikePathCopy); @@ -159,10 +161,17 @@ export async function generateSwapCalldata({ )); const calldata = generateCalls(calls); - const initiatorWalletBalance = await getWalletBalance(srcToken, initiatorAddress, provider) - const initiatorExchangeBalance = await getExchangeBalance(srcToken, initiatorAddress, exchangeContractAddress, provider, true) - const useContractBalance = srcToken === ZeroAddress || amountNativeDecimals < initiatorWalletBalance - if (useContractBalance) { + const initiatorWalletBalance = await getWalletBalance(srcToken, initiatorAddress, provider); + const initiatorExchangeBalance = await getExchangeBalance( + srcToken, + initiatorAddress, + exchangeContractAddress, + provider, + true + ); + const useExchangeBalance = + initiatorExchangeBalance !== 0n && (srcToken === ZeroAddress || amountNativeDecimals < initiatorWalletBalance); + if (useExchangeBalance) { swapDescription.flags = 1n << 255n; } let value = 0n; @@ -170,7 +179,7 @@ export async function generateSwapCalldata({ value = amountNativeDecimals - initiatorExchangeBalance; } - return { swapDescription, calldata , value}; + return { swapDescription, calldata, value }; } async function processSingleFactorySwaps(