dont use exchangeBalance if it's 0

This commit is contained in:
lomonoshka
2023-11-30 14:46:52 +04:00
parent 9d794b5428
commit 4d2e006db0
2 changed files with 16 additions and 7 deletions

View File

@@ -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",

View File

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