Return exchange precision in swapDescription

This commit is contained in:
lomonoshka
2023-10-30 20:07:06 +04:00
parent cdc3a78eb9
commit 31efda9969
2 changed files with 7 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.10-rc102",
"version": "0.20.10-rc103",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -91,18 +91,17 @@ export async function generateSwapCalldata({
const { factory, assetIn: srcToken } = path.first();
const dstToken = path.last().assetOut;
const amountNativeDecimals = await exchangeToNativeDecimals(srcToken, amount, provider);
const minReturnAmountNativeDecimals = await exchangeToNativeDecimals(dstToken, minReturnAmount, provider);
let swapDescription: LibValidator.SwapDescriptionStruct = {
srcToken: srcToken,
dstToken: dstToken,
srcReceiver: swapExecutorContractAddress,
dstReceiver: receiverAddress,
amount: amountNativeDecimals,
minReturnAmount: minReturnAmountNativeDecimals,
amount,
minReturnAmount,
flags: 0,
};
const amountNativeDecimals = await exchangeToNativeDecimals(srcToken, amount, provider);
path = SafeArray.from(arrayLikePath).map((singleSwap) => {
if (singleSwap.assetIn == ethers.ZeroAddress) singleSwap.assetIn = wethAddress;
if (singleSwap.assetOut == ethers.ZeroAddress) singleSwap.assetOut = wethAddress;
@@ -132,7 +131,7 @@ export async function generateSwapCalldata({
));
}
calls = wrapOrUnwrapIfNeeded(swapDescription, calls);
calls = wrapOrUnwrapIfNeeded(amountNativeDecimals, swapDescription, calls);
const calldata = generateCalls(calls);
return { swapDescription, calldata };
}
@@ -248,7 +247,7 @@ async function processMultiFactorySwaps(
return { swapDescription, calls };
}
function wrapOrUnwrapIfNeeded(swapDescription: LibValidator.SwapDescriptionStruct, calls: BytesLike[]): BytesLike[] {
function wrapOrUnwrapIfNeeded(amount: BigNumberish, swapDescription: LibValidator.SwapDescriptionStruct, calls: BytesLike[]): BytesLike[] {
if (swapDescription.srcToken === ZeroAddress) {
const wrapCall = generateWrapAndTransferCall(swapDescription.dstReceiver, { value: swapDescription.amount });
calls = ([wrapCall] as BytesLike[]).concat(calls);