mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
dont use exchangeBalance if it's 0
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user