From 35ab980e4aeb0e4ed832fb35ce644791a99c5e8d Mon Sep 17 00:00:00 2001 From: Zikriya Date: Wed, 21 Feb 2024 17:34:36 +0500 Subject: [PATCH 1/2] Validation updated for doSwapAndWithdraw api. multiswapNetworkFIBERInformations and swapAndWithdrawTransactions model updated for forge --- .../multiSwapHelpers/swapTransactionHelper.ts | 8 +++-- .../multiswapNetworkFIBERInformations.ts | 33 +++++++++++-------- app/models/swapAndWithdrawTransactions.ts | 12 +++++++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/app/helpers/multiSwapHelpers/swapTransactionHelper.ts b/app/helpers/multiSwapHelpers/swapTransactionHelper.ts index 3000c472..3567710f 100755 --- a/app/helpers/multiSwapHelpers/swapTransactionHelper.ts +++ b/app/helpers/multiSwapHelpers/swapTransactionHelper.ts @@ -14,9 +14,13 @@ module.exports = { !req.query.sourceCabnId || !req.query.destinationCabnId || !req.body.sourceAssetType || - !req.body.destinationAssetType + !req.body.destinationAssetType || + !req.body.sourceGasPriceInNumber || + !req.body.sourceGasPriceInMachine || + !req.body.destinationGasPriceInNumber || + !req.body.destinationGasPriceInMachine ) { - throw "swapTxId & sourceNetworkId & destinationNetworkId & sourceCabnId & destinationCabnId & sourceAssetType & destinationAssetType are required."; + throw "swapTxId & sourceNetworkId & destinationNetworkId & sourceCabnId & destinationCabnId & sourceAssetType & destinationAssetType & sourceGasPriceInNumber & sourceGasPriceInMachine & destinationGasPriceInNumber & destinationGasPriceInMachine are required."; } if (!mongoose.Types.ObjectId.isValid(req.query.sourceNetworkId)) { diff --git a/app/models/multiswapNetworkFIBERInformations.ts b/app/models/multiswapNetworkFIBERInformations.ts index 3a03bba3..56b42cc8 100755 --- a/app/models/multiswapNetworkFIBERInformations.ts +++ b/app/models/multiswapNetworkFIBERInformations.ts @@ -1,17 +1,24 @@ -'use strict'; -var mongoose = require('mongoose'); +"use strict"; +var mongoose = require("mongoose"); -var schema = mongoose.Schema({ - rpcUrl: { type: String, default: "" }, - fundManager: { type: String, default: "" }, - fiberRouter: { type: String, default: "" }, - router: { type: String, default: "" }, - foundryTokenAddress: { type: String, default: "" }, - weth: { type: String, default: "" }, +var schema = mongoose.Schema( + { + rpcUrl: { type: String, default: "" }, + fundManager: { type: String, default: "" }, + fiberRouter: { type: String, default: "" }, + router: { type: String, default: "" }, + foundryTokenAddress: { type: String, default: "" }, + forgeContractAddress: { type: String, default: "" }, + weth: { type: String, default: "" }, - createdAt: { type: Date, default: new Date() }, - updatedAt: { type: Date, default: new Date() }, -},{ collection: 'multiswapNetworkFIBERInformations' }); + createdAt: { type: Date, default: new Date() }, + updatedAt: { type: Date, default: new Date() }, + }, + { collection: "multiswapNetworkFIBERInformations" } +); -var multiswapNetworkFIBERInformationsModel = mongoose.model("multiswapNetworkFIBERInformations",schema); +var multiswapNetworkFIBERInformationsModel = mongoose.model( + "multiswapNetworkFIBERInformations", + schema +); module.exports = multiswapNetworkFIBERInformationsModel; diff --git a/app/models/swapAndWithdrawTransactions.ts b/app/models/swapAndWithdrawTransactions.ts index 2d770d04..b557fa6a 100755 --- a/app/models/swapAndWithdrawTransactions.ts +++ b/app/models/swapAndWithdrawTransactions.ts @@ -99,6 +99,18 @@ var schema = mongoose.Schema( settledAmount: { type: String, default: "" }, sourceToken: { type: String, default: "" }, targetToken: { type: String, default: "" }, + gasPrices: { + source: { + gasPrice: { type: String, default: "" }, + gasPriceInUSD: { type: String, default: "" }, + }, + destination: { + gasPrice: { type: String, default: "" }, + gasPriceInMachine: { type: String, default: "" }, + gasPriceInUSD: { type: String, default: "" }, + gasLimit: { type: String, default: "" }, + }, + }, }, { collection: "swapAndWithdrawTransactions" } ); From a24a9473bbaa2149709f43aab5e0494adfba657d Mon Sep 17 00:00:00 2001 From: Zikriya Date: Wed, 21 Feb 2024 17:36:54 +0500 Subject: [PATCH 2/2] Modification for forge in fiberAxiosHelper and regenerateSwapAndWithdrawBySwapHash api --- .../multiSwapHelpers/swapTransactionHelper.ts | 9 +- app/helpers/web3Helpers/web3Utils.ts | 2 +- app/lib/httpCalls/fiberAxiosHelper.ts | 1 + resources/FiberRouter.json | 98 ++++++++----------- 4 files changed, 48 insertions(+), 62 deletions(-) diff --git a/app/helpers/multiSwapHelpers/swapTransactionHelper.ts b/app/helpers/multiSwapHelpers/swapTransactionHelper.ts index 3567710f..25e55411 100755 --- a/app/helpers/multiSwapHelpers/swapTransactionHelper.ts +++ b/app/helpers/multiSwapHelpers/swapTransactionHelper.ts @@ -14,13 +14,10 @@ module.exports = { !req.query.sourceCabnId || !req.query.destinationCabnId || !req.body.sourceAssetType || - !req.body.destinationAssetType || - !req.body.sourceGasPriceInNumber || - !req.body.sourceGasPriceInMachine || - !req.body.destinationGasPriceInNumber || - !req.body.destinationGasPriceInMachine + !req.body.destinationAssetType + // !req.body.gasPrices ) { - throw "swapTxId & sourceNetworkId & destinationNetworkId & sourceCabnId & destinationCabnId & sourceAssetType & destinationAssetType & sourceGasPriceInNumber & sourceGasPriceInMachine & destinationGasPriceInNumber & destinationGasPriceInMachine are required."; + throw "swapTxId & sourceNetworkId & destinationNetworkId & sourceCabnId & destinationCabnId & sourceAssetType & destinationAssetType & gasPrices are required."; } if (!mongoose.Types.ObjectId.isValid(req.query.sourceNetworkId)) { diff --git a/app/helpers/web3Helpers/web3Utils.ts b/app/helpers/web3Helpers/web3Utils.ts index 118a22ed..eee14fc5 100644 --- a/app/helpers/web3Helpers/web3Utils.ts +++ b/app/helpers/web3Helpers/web3Utils.ts @@ -67,7 +67,7 @@ export const getLogsFromTransactionReceipt = (data: any) => { const findSwapEvent = (topics: any[], data: any) => { let swapEventHash = Web3.utils.sha3( - "Swap(address,address,uint256,uint256,uint256,address,address,uint256,bytes32)" + "Swap(address,address,uint256,uint256,uint256,address,address,uint256,bytes32,uint256)" ); if (data.isDestinationNonEVM != null && data.isDestinationNonEVM) { swapEventHash = Web3.utils.sha3( diff --git a/app/lib/httpCalls/fiberAxiosHelper.ts b/app/lib/httpCalls/fiberAxiosHelper.ts index 6719adb6..253091a5 100755 --- a/app/lib/httpCalls/fiberAxiosHelper.ts +++ b/app/lib/httpCalls/fiberAxiosHelper.ts @@ -84,6 +84,7 @@ 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; diff --git a/resources/FiberRouter.json b/resources/FiberRouter.json index 0342e833..7b6493a9 100644 --- a/resources/FiberRouter.json +++ b/resources/FiberRouter.json @@ -5,17 +5,13 @@ "abi": [ { "inputs": [ + { "internalType": "address", "name": "_weth", "type": "address" }, { "internalType": "address", - "name": "_wethAddress", + "name": "_oneInchAggregatorRouter", "type": "address" }, - { - "internalType": "address", - "name": "_oneInchAggregator", - "type": "address" - }, - { "internalType": "address", "name": "_poolAddress", "type": "address" } + { "internalType": "address", "name": "_pool", "type": "address" } ], "stateMutability": "nonpayable", "type": "constructor" @@ -156,6 +152,12 @@ "internalType": "bytes32", "name": "withdrawalData", "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "gasAmount", + "type": "uint256" } ], "name": "Swap", @@ -309,49 +311,49 @@ { "indexed": false, "internalType": "address", - "name": "", + "name": "to", "type": "address" }, { "indexed": false, "internalType": "uint256", - "name": "", + "name": "amountIn", "type": "uint256" }, { "indexed": false, "internalType": "uint256", - "name": "", + "name": "amountOutOneInch", "type": "uint256" }, { "indexed": false, "internalType": "address", - "name": "", + "name": "foundryToken", "type": "address" }, { "indexed": false, "internalType": "address", - "name": "", + "name": "targetToken", "type": "address" }, { "indexed": false, "internalType": "bytes", - "name": "", + "name": "oneInchData", "type": "bytes" }, { "indexed": false, "internalType": "bytes32", - "name": "", + "name": "salt", "type": "bytes32" }, { "indexed": false, "internalType": "bytes", - "name": "", + "name": "multiSignature", "type": "bytes" } ], @@ -365,6 +367,15 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "gasWallet", + "outputs": [ + { "internalType": "address payable", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "inventory", @@ -390,43 +401,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, - { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, - { - "internalType": "string", - "name": "crossTargetNetwork", - "type": "string" - }, - { - "internalType": "string", - "name": "crossTargetToken", - "type": "string" - }, - { - "internalType": "string", - "name": "crossTargetAddress", - "type": "string" - }, - { "internalType": "bytes", "name": "oneInchData", "type": "bytes" }, - { "internalType": "address", "name": "fromToken", "type": "address" }, - { - "internalType": "address", - "name": "foundryToken", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "withdrawalData", - "type": "bytes32" - } - ], - "name": "nonEvmSwapAndCrossOneInch", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [], "name": "oneInchAggregatorRouter", @@ -455,6 +429,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "_gasWallet", + "type": "address" + } + ], + "name": "setGasWallet", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -500,7 +487,7 @@ ], "name": "swap", "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { @@ -537,7 +524,7 @@ ], "name": "swapAndCrossOneInch", "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { @@ -568,7 +555,8 @@ "internalType": "bytes32", "name": "withdrawalData", "type": "bytes32" - } + }, + { "internalType": "uint256", "name": "gasFee", "type": "uint256" } ], "name": "swapAndCrossOneInchETH", "outputs": [],