From 205ff9cda33f5ed8d735826dee5c9a67e7160b11 Mon Sep 17 00:00:00 2001 From: Zikriya Date: Tue, 19 Mar 2024 04:00:07 +0500 Subject: [PATCH 1/5] gasLimit removed while withdraw request to fiber engine --- app/lib/httpCalls/fiberAxiosHelper.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/lib/httpCalls/fiberAxiosHelper.ts b/app/lib/httpCalls/fiberAxiosHelper.ts index 253091a..6719adb 100755 --- a/app/lib/httpCalls/fiberAxiosHelper.ts +++ b/app/lib/httpCalls/fiberAxiosHelper.ts @@ -84,7 +84,6 @@ module.exports = { body.sourceBridgeAmount = model.sourceBridgeAmount; body.sourceAssetType = model.sourceAssetType; body.destinationAssetType = model.destinationAssetType; - body.gasLimit = model.gasPrices?.destination?.gasLimit; console.log("getWithdrawBody body", body); return body; From 19b71c15b5762095364e9495441c43aec5fa22c7 Mon Sep 17 00:00:00 2001 From: Arslan Kibria Date: Thu, 28 Mar 2024 14:14:48 +0500 Subject: [PATCH 2/5] Slipagge split into source and destination --- .../api/v1/super-admin/currencies.ts | 20 +++++++++++++++++++ app/models/currencyAddressesByNetwork.ts | 2 ++ 2 files changed, 22 insertions(+) diff --git a/app/controllers/api/v1/super-admin/currencies.ts b/app/controllers/api/v1/super-admin/currencies.ts index 470891b..83e3a52 100755 --- a/app/controllers/api/v1/super-admin/currencies.ts +++ b/app/controllers/api/v1/super-admin/currencies.ts @@ -563,6 +563,26 @@ module.exports = function (router: any) { }); }); + router.put("/cabn/update/slippage/:id", async (req: any, res: any) => { + let body: any = {}; + let filters: any = { _id: req.params.id }; + if (req.body.sourceSlippage) { + body.sourceSlippage = req.body.sourceSlippage; + } + if (req.body.destinationSlippage) { + body.destinationSlippage = req.body.destinationSlippage; + } + let cabn = await db.CurrencyAddressesByNetwork.findOneAndUpdate( + filters, + body, + { new: true } + ); + + return res.http200({ + cabn: cabn, + }); + }); + router.post( "/create/bulk/cabns", asyncMiddleware(async (req: any, res: any) => { diff --git a/app/models/currencyAddressesByNetwork.ts b/app/models/currencyAddressesByNetwork.ts index c63df2d..001afe6 100755 --- a/app/models/currencyAddressesByNetwork.ts +++ b/app/models/currencyAddressesByNetwork.ts @@ -35,6 +35,8 @@ var schema = mongoose.Schema( symbol: { type: String, default: "" }, }, isCreatedFromBulk: { type: Boolean, default: false }, + sourceSlippage: { type: Number, default: 2 }, + destinationSlippage: { type: Number, default: 2 }, createdAt: { type: Date, default: new Date() }, updatedAt: { type: Date, default: new Date() }, }, From 182d11daa8071c9074f4b2f307e5437e4424a470 Mon Sep 17 00:00:00 2001 From: Arslan Kibria Date: Thu, 28 Mar 2024 14:23:25 +0500 Subject: [PATCH 3/5] sourceSlippage and destinationSlippage sent with getBulkCabns api --- app/controllers/api/v1/currencies.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v1/currencies.ts b/app/controllers/api/v1/currencies.ts index 84d246e..a00d0f1 100644 --- a/app/controllers/api/v1/currencies.ts +++ b/app/controllers/api/v1/currencies.ts @@ -515,6 +515,8 @@ module.exports = function (router: any) { isDefault: 1, nonDefaultCurrencyInformation: 1, createdByusers: 1, + sourceSlippage: 1, + destinationSlippage: 1, "network._id": 1, "network.name": 1, "network.nameInLower": 1, From b3db7b303c00a320474d9789ffe56144a9abbf24 Mon Sep 17 00:00:00 2001 From: Zikriya Date: Thu, 28 Mar 2024 15:14:36 +0500 Subject: [PATCH 4/5] swapAndWithdrawTransactions updated --- app/models/swapAndWithdrawTransactions.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/swapAndWithdrawTransactions.ts b/app/models/swapAndWithdrawTransactions.ts index b557fa6..eb004e8 100755 --- a/app/models/swapAndWithdrawTransactions.ts +++ b/app/models/swapAndWithdrawTransactions.ts @@ -95,7 +95,8 @@ var schema = mongoose.Schema( signatureExpiry: { type: Number, default: null }, responseCode: { type: Number, default: "" }, responseMessage: {}, - slippage: { type: Number, default: 2 }, + sourceSlippage: { type: Number, default: 2 }, + destinationSlippage: { type: Number, default: 2 }, settledAmount: { type: String, default: "" }, sourceToken: { type: String, default: "" }, targetToken: { type: String, default: "" }, From 864c8b3188e5bf3bef148593848011712c72f819 Mon Sep 17 00:00:00 2001 From: Zikriya Date: Mon, 29 Apr 2024 14:32:25 +0500 Subject: [PATCH 5/5] Same network swap --- .../multiSwapHelpers/generatorNodeHelper.ts | 58 +++++++++++++++++-- .../multiSwapHelpers/swapTransactionHelper.ts | 3 + app/models/swapAndWithdrawTransactions.ts | 1 + 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/app/helpers/multiSwapHelpers/generatorNodeHelper.ts b/app/helpers/multiSwapHelpers/generatorNodeHelper.ts index 59d3e2f..8483d94 100644 --- a/app/helpers/multiSwapHelpers/generatorNodeHelper.ts +++ b/app/helpers/multiSwapHelpers/generatorNodeHelper.ts @@ -1,3 +1,5 @@ +import { handleFiberRequest } from "../../helpers/multiSwapHelpers/fiberHelper"; + export const handleGeneratorRequest = async (data: any, swapTxHash: string) => { try { let filter: any = { @@ -19,10 +21,18 @@ export const handleGeneratorRequest = async (data: any, swapTxHash: string) => { transactionReceipt?.status == true && data?.signedData ) { - transaction = getGeneratorSignedData(transaction, data?.signedData); - transaction = await getTransactionDetail(transaction, data?.signedData); - transaction.status = - utils.swapAndWithdrawTransactionStatuses.generatorSignatureCreated; + if (data?.signedData?.isSameNetworkSwap) { + await handleSameNetworkSwap(transaction, data?.signedData); + return; + } else { + transaction = getGeneratorSignedData(transaction, data?.signedData); + transaction = await getTransactionDetail( + transaction, + data?.signedData + ); + transaction.status = + utils.swapAndWithdrawTransactionStatuses.generatorSignatureCreated; + } } else { transaction.status = utils.swapAndWithdrawTransactionStatuses.generatorSignatureFailed; @@ -96,3 +106,43 @@ async function getAmount(transaction: any) { return amount; } + +async function getSettledAmount(transaction: any, settledAmount: any) { + let amount; + try { + amount = await swapUtilsHelper.amountToHuman_( + transaction.destinationNetwork, + transaction.destinationCabn, + settledAmount + ); + } catch (e) { + console.log("for nativ tokens"); + amount = await swapUtilsHelper.amountToHuman( + settledAmount, + transaction.destinationCabn.decimals + ); + } + + return amount; +} + +async function handleSameNetworkSwap(transaction: any, signedData: any) { + try { + if (signedData.settledAmount) { + let destinationAmount = await getSettledAmount( + transaction, + signedData.settledAmount + ); + let data = { + data: transaction?.receiveTransactionId, + withdraw: { destinationAmount: destinationAmount }, + responseCode: 200, + responseMessage: "", + }; + await handleFiberRequest(data, data?.data); + } + } catch (e) { + console.log(e); + } + return transaction; +} diff --git a/app/helpers/multiSwapHelpers/swapTransactionHelper.ts b/app/helpers/multiSwapHelpers/swapTransactionHelper.ts index 96da147..b7ff956 100755 --- a/app/helpers/multiSwapHelpers/swapTransactionHelper.ts +++ b/app/helpers/multiSwapHelpers/swapTransactionHelper.ts @@ -80,6 +80,9 @@ module.exports = { : ""; let body: any = {}; + if (sourceNetwork._id == destinationNetwork._id) { + body.isSameNetworkSwap = true; + } body.receiveTransactionId = req.params.swapTxId; body.version = "v3"; body.createdByUser = req.user._id; diff --git a/app/models/swapAndWithdrawTransactions.ts b/app/models/swapAndWithdrawTransactions.ts index 702087d..e4e248d 100755 --- a/app/models/swapAndWithdrawTransactions.ts +++ b/app/models/swapAndWithdrawTransactions.ts @@ -114,6 +114,7 @@ var schema = mongoose.Schema( }, sourceOneInchSelector: { type: String, default: "" }, destinationOneInchSelector: { type: String, default: "" }, + isSameNetworkSwap: { type: Boolean, default: false }, }, { collection: "swapAndWithdrawTransactions" } );