diff --git a/app/interfaces/fiberEngineInterface.ts b/app/interfaces/fiberEngineInterface.ts index 3fb1203..049dd90 100644 --- a/app/interfaces/fiberEngineInterface.ts +++ b/app/interfaces/fiberEngineInterface.ts @@ -18,3 +18,15 @@ export interface WithdrawSignedAndSwapOneInch { signatureExpiry: number; signature: string; } + +export interface SwapOneInch { + amountIn: string; + amountOut: string; + targetChainId: string; + targetTokenAddress: string; + destinationWalletAddress: string; + sourceOneInchData: string; + sourceTokenAddress: string; + foundryTokenAddress: string; + withdrawalData: string; +} diff --git a/app/lib/middlewares/common.ts b/app/lib/middlewares/common.ts index 79195ce..cc498f2 100644 --- a/app/lib/middlewares/common.ts +++ b/app/lib/middlewares/common.ts @@ -7,7 +7,10 @@ const { ethers } = require("ethers"); const routerAbiMainnet = require("../../../artifacts/contracts/common/uniswap/IUniswapV2Router02.sol/IUniswapV2Router02.json"); const fundManagerAbiMainnet = require("../../../artifacts/contracts/upgradeable-Bridge/FundManager.sol/FundManager.json"); const fiberRouterAbiMainnet = require("../../../artifacts/contracts/upgradeable-Bridge/FiberRouter.sol/FiberRouter.json"); -import { getSlippage } from "../../lib/middlewares/helpers/configurationHelper"; +import { + getSlippage, + getNativeTokens, +} from "../../lib/middlewares/helpers/configurationHelper"; module.exports = { getHashedPassword: function (password: any) { @@ -280,4 +283,36 @@ module.exports = { (global as any).environment.PRI_KEY = this.getPrivateKey(); } catch (e) {} }, + + getWrappedNativeTokenAddress: async function ( + address: string + ): Promise { + let tokens: any = await getNativeTokens(); + for (let item of tokens || []) { + if (item?.address.toLowerCase() == address.toLowerCase()) { + return item?.wrappedAddress; + } + } + return address; + }, + + getOneInchTokenAddress: async function (address: string): Promise { + let tokens: any = await getNativeTokens(); + for (let item of tokens || []) { + if (item?.address.toLowerCase() == address.toLowerCase()) { + return item?.oneInchAddress; + } + } + return address; + }, + + isNativeToken: async function (address: string): Promise { + let tokens = await getNativeTokens(); + for (let item of tokens || []) { + if (item?.address.toLowerCase() == address.toLowerCase()) { + return true; + } + } + return false; + }, }; diff --git a/app/lib/middlewares/helpers/configurationHelper.ts b/app/lib/middlewares/helpers/configurationHelper.ts index c11014c..87191e1 100644 --- a/app/lib/middlewares/helpers/configurationHelper.ts +++ b/app/lib/middlewares/helpers/configurationHelper.ts @@ -2,3 +2,8 @@ export const getSlippage = async (): Promise => { let data = await db.Configurations.findOne(); return data?.slippage ? data?.slippage : 2; }; + +export const getNativeTokens = async (): Promise => { + let data = await db.Configurations.findOne(); + return data?.nativeTokens ? data?.nativeTokens : []; +}; diff --git a/app/lib/middlewares/helpers/fiberEngineHelper.ts b/app/lib/middlewares/helpers/fiberEngineHelper.ts index eff7992..21a9999 100644 --- a/app/lib/middlewares/helpers/fiberEngineHelper.ts +++ b/app/lib/middlewares/helpers/fiberEngineHelper.ts @@ -1,4 +1,5 @@ import { + SwapOneInch, WithdrawSigned, WithdrawSignedAndSwapOneInch, } from "../../../interfaces/fiberEngineInterface"; @@ -57,16 +58,19 @@ export const doFoundaryWithdraw = async ( obj: WithdrawSigned, targetNetwork: any, targetSigner: any, - targetChainId: any + targetChainId: any, + isDynamicGasLimit = true ): Promise => { let result; try { let gasLimit; - if (await isAllowedDynamicGasValues(targetChainId)) { + if ((await isAllowedDynamicGasValues(targetChainId)) && isDynamicGasLimit) { gasLimit = await targetNetwork.fiberRouterContract .connect(targetSigner) .estimateGas.withdrawSigned( - obj.targetTokenAddress, + await (global as any).commonFunctions.getOneInchTokenAddress( + obj.targetTokenAddress + ), obj.destinationWalletAddress, obj.destinationAmountIn, obj.salt, @@ -78,7 +82,9 @@ export const doFoundaryWithdraw = async ( result = await targetNetwork.fiberRouterContract .connect(targetSigner) .withdrawSigned( - obj.targetTokenAddress, + await (global as any).commonFunctions.getOneInchTokenAddress( + obj.targetTokenAddress + ), obj.destinationWalletAddress, obj.destinationAmountIn, obj.salt, @@ -88,6 +94,15 @@ export const doFoundaryWithdraw = async ( ); } catch (e) { console.log(e); + if (isDynamicGasLimit) { + result = await doFoundaryWithdraw( + obj, + targetNetwork, + targetSigner, + targetChainId, + false + ); + } } return result; }; @@ -96,12 +111,13 @@ export const doOneInchWithdraw = async ( obj: WithdrawSignedAndSwapOneInch, targetNetwork: any, targetSigner: any, - targetChainId: any + targetChainId: any, + isDynamicGasLimit = true ): Promise => { let result; try { let gasLimit; - if (await isAllowedDynamicGasValues(targetChainId)) { + if ((await isAllowedDynamicGasValues(targetChainId)) && isDynamicGasLimit) { gasLimit = await targetNetwork.fiberRouterContract .connect(targetSigner) .estimateGas.withdrawSignedAndSwapOneInch( @@ -109,7 +125,9 @@ export const doOneInchWithdraw = async ( obj.destinationAmountIn, obj.destinationAmountOut, obj.targetFoundryTokenAddress, - obj.targetTokenAddress, + await (global as any).commonFunctions.getOneInchTokenAddress( + obj.targetTokenAddress + ), obj.destinationOneInchData, obj.salt, obj.signatureExpiry, @@ -124,13 +142,67 @@ export const doOneInchWithdraw = async ( obj.destinationAmountIn, obj.destinationAmountOut, obj.targetFoundryTokenAddress, - obj.targetTokenAddress, + await (global as any).commonFunctions.getOneInchTokenAddress( + obj.targetTokenAddress + ), obj.destinationOneInchData, obj.salt, obj.signatureExpiry, obj.signature, await getGasForWithdraw(targetChainId, gasLimit) ); + } catch (e) { + console.log(e); + if (isDynamicGasLimit) { + result = await doOneInchWithdraw( + obj, + targetNetwork, + targetSigner, + targetChainId, + false + ); + } + } + return result; +}; + +export const doOneInchSwap = async ( + obj: SwapOneInch, + fiberRouter: any +): Promise => { + let result; + try { + if ( + await (global as any).commonFunctions.isNativeToken( + obj.sourceTokenAddress + ) + ) { + result = fiberRouter.methods.swapAndCrossOneInchETH( + obj.amountOut, + obj.targetChainId, + await (global as any).commonFunctions.getOneInchTokenAddress( + obj.targetTokenAddress + ), + obj.destinationWalletAddress, + obj.sourceOneInchData, + obj.foundryTokenAddress, + obj.withdrawalData + ); + } else { + result = fiberRouter.methods.swapAndCrossOneInch( + obj.amountIn, + obj.amountOut, + obj.targetChainId, + await (global as any).commonFunctions.getOneInchTokenAddress( + obj.targetTokenAddress + ), + obj.destinationWalletAddress, + obj.sourceOneInchData, + obj.sourceTokenAddress, + obj.foundryTokenAddress, + obj.withdrawalData + ); + } } catch (e) { console.log(e); } diff --git a/app/lib/middlewares/helpers/gasEstimationHelper.ts b/app/lib/middlewares/helpers/gasEstimationHelper.ts index c0ed4d1..6f37387 100644 --- a/app/lib/middlewares/helpers/gasEstimationHelper.ts +++ b/app/lib/middlewares/helpers/gasEstimationHelper.ts @@ -24,7 +24,7 @@ export const getGasForWithdraw = async ( Web3.utils.toWei(maxPriorityFeePerGas, "gwei") ); - data.gasLimit = item?.isAllowedDynamicGasLimit + data.gasLimit = dynamicGasLimit ? dynamicGasLimit?.toString() : staticGasLimit; } diff --git a/app/lib/middlewares/helpers/multiSwapHelper.ts b/app/lib/middlewares/helpers/multiSwapHelper.ts index 5d8e354..85ea5dc 100644 --- a/app/lib/middlewares/helpers/multiSwapHelper.ts +++ b/app/lib/middlewares/helpers/multiSwapHelper.ts @@ -55,12 +55,12 @@ module.exports = { let data: any = {}; data = await fiberEngine.swapForAbi( req.query.sourceWalletAddress, - req.query.sourceTokenContractAddress, // goerli ada - req.query.destinationTokenContractAddress, // bsc ada - req.query.sourceNetworkChainId, // source chain id (goerli) - req.query.destinationNetworkChainId, // target chain id (bsc) - req.query.sourceAmount, //source token amount - req.query.destinationWalletAddress, // destination wallet address + req.query.sourceTokenContractAddress, + req.query.destinationTokenContractAddress, + req.query.sourceNetworkChainId, + req.query.destinationNetworkChainId, + req.query.sourceAmount, + req.query.destinationWalletAddress, req.query ); return data; diff --git a/app/lib/middlewares/helpers/withdrawResponseHelper.ts b/app/lib/middlewares/helpers/withdrawResponseHelper.ts index c8ceb2d..01897d5 100644 --- a/app/lib/middlewares/helpers/withdrawResponseHelper.ts +++ b/app/lib/middlewares/helpers/withdrawResponseHelper.ts @@ -38,7 +38,7 @@ export const createEVMResponse = (tx: any): Response => { if (tx != null && tx.status != null && tx.status == true) { responseCode = CODE_200; responseMessage = SUCCESS; - } else if (tx.code == CODE_701) { + } else if (tx?.code == CODE_701) { responseCode = CODE_701; responseMessage = IN_SUFFICIENT_LIQUIDITY_ERROR; } diff --git a/app/models/configurations.ts b/app/models/configurations.ts index 32d377b..e6486d6 100644 --- a/app/models/configurations.ts +++ b/app/models/configurations.ts @@ -6,6 +6,13 @@ var collectionName = "configurations"; var schema = mongoose.Schema( { slippage: { type: Number, default: 0 }, + nativeTokens: [ + { + address: { type: String, default: "" }, + wrappedAddress: { type: String, default: "" }, + oneInchAddress: { type: String, default: "" }, + }, + ], isActive: { type: Boolean, default: true }, createdAt: { type: Date, default: new Date() }, updatedAt: { type: Date, default: new Date() }, diff --git a/artifacts/contracts/upgradeable-Bridge/FiberRouter.sol/FiberRouter.json b/artifacts/contracts/upgradeable-Bridge/FiberRouter.sol/FiberRouter.json index 1319019..741905b 100644 --- a/artifacts/contracts/upgradeable-Bridge/FiberRouter.sol/FiberRouter.json +++ b/artifacts/contracts/upgradeable-Bridge/FiberRouter.sol/FiberRouter.json @@ -3,6 +3,23 @@ "contractName": "FiberRouter", "sourceName": "contracts/upgradeable-Bridge/FiberRouterExtended.sol", "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "_wethAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "_oneInchAggregator", + "type": "address" + }, + { "internalType": "address", "name": "_poolAddress", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, { "anonymous": false, "inputs": [ @@ -342,51 +359,26 @@ "type": "event" }, { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], + "inputs": [], + "name": "WETH", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "inventory", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "string", - "name": "targetNetwork", - "type": "string" - }, - { - "internalType": "string", - "name": "targetToken", - "type": "string" - }, - { - "internalType": "string", - "name": "targetAddress", - "type": "string" - }, + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "string", "name": "targetNetwork", "type": "string" }, + { "internalType": "string", "name": "targetToken", "type": "string" }, + { "internalType": "string", "name": "targetAddress", "type": "string" }, { "internalType": "bytes32", "name": "withdrawalData", @@ -400,16 +392,8 @@ }, { "inputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, + { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, { "internalType": "string", "name": "crossTargetNetwork", @@ -425,16 +409,8 @@ "name": "crossTargetAddress", "type": "string" }, - { - "internalType": "bytes", - "name": "oneInchData", - "type": "bytes" - }, - { - "internalType": "address", - "name": "fromToken", - "type": "address" - }, + { "internalType": "bytes", "name": "oneInchData", "type": "bytes" }, + { "internalType": "address", "name": "fromToken", "type": "address" }, { "internalType": "address", "name": "foundryToken", @@ -454,39 +430,21 @@ { "inputs": [], "name": "oneInchAggregatorRouter", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "owner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "pool", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, @@ -512,11 +470,7 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "_pool", - "type": "address" - } + { "internalType": "address", "name": "_pool", "type": "address" } ], "name": "setPool", "outputs": [], @@ -525,26 +479,14 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, { "internalType": "uint256", "name": "targetNetwork", "type": "uint256" }, - { - "internalType": "address", - "name": "targetToken", - "type": "address" - }, + { "internalType": "address", "name": "targetToken", "type": "address" }, { "internalType": "address", "name": "targetAddress", @@ -563,16 +505,8 @@ }, { "inputs": [ - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, + { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, { "internalType": "uint256", "name": "crossTargetNetwork", @@ -588,16 +522,8 @@ "name": "crossTargetAddress", "type": "address" }, - { - "internalType": "bytes", - "name": "oneInchData", - "type": "bytes" - }, - { - "internalType": "address", - "name": "fromToken", - "type": "address" - }, + { "internalType": "bytes", "name": "oneInchData", "type": "bytes" }, + { "internalType": "address", "name": "fromToken", "type": "address" }, { "internalType": "address", "name": "foundryToken", @@ -616,50 +542,57 @@ }, { "inputs": [ + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, { - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ + "internalType": "uint256", + "name": "crossTargetNetwork", + "type": "uint256" + }, { "internalType": "address", - "name": "token", + "name": "crossTargetToken", "type": "address" }, { "internalType": "address", - "name": "payee", + "name": "crossTargetAddress", "type": "address" }, + { "internalType": "bytes", "name": "oneInchData", "type": "bytes" }, { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "address", + "name": "foundryToken", + "type": "address" }, { "internalType": "bytes32", - "name": "salt", + "name": "withdrawalData", "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "expiry", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "multiSignature", - "type": "bytes" } ], + "name": "swapAndCrossOneInchETH", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "token", "type": "address" }, + { "internalType": "address", "name": "payee", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" }, + { "internalType": "bytes32", "name": "salt", "type": "bytes32" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "bytes", "name": "multiSignature", "type": "bytes" } + ], "name": "withdrawSigned", "outputs": [], "stateMutability": "nonpayable", @@ -667,51 +600,19 @@ }, { "inputs": [ - { - "internalType": "address payable", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, + { "internalType": "address payable", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amountIn", "type": "uint256" }, + { "internalType": "uint256", "name": "amountOut", "type": "uint256" }, { "internalType": "address", "name": "foundryToken", "type": "address" }, - { - "internalType": "address", - "name": "targetToken", - "type": "address" - }, - { - "internalType": "bytes", - "name": "oneInchData", - "type": "bytes" - }, - { - "internalType": "bytes32", - "name": "salt", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "expiry", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "multiSignature", - "type": "bytes" - } + { "internalType": "address", "name": "targetToken", "type": "address" }, + { "internalType": "bytes", "name": "oneInchData", "type": "bytes" }, + { "internalType": "bytes32", "name": "salt", "type": "bytes32" }, + { "internalType": "uint256", "name": "expiry", "type": "uint256" }, + { "internalType": "bytes", "name": "multiSignature", "type": "bytes" } ], "name": "withdrawSignedAndSwapOneInch", "outputs": [], diff --git a/scripts/fiberEngine.ts b/scripts/fiberEngine.ts index 25a902f..5199aa5 100644 --- a/scripts/fiberEngine.ts +++ b/scripts/fiberEngine.ts @@ -32,10 +32,12 @@ import { getGasForWithdraw, } from "../app/lib/middlewares/helpers/gasEstimationHelper"; import { + doOneInchSwap, doFoundaryWithdraw, doOneInchWithdraw, } from "../app/lib/middlewares/helpers/fiberEngineHelper"; import { + SwapOneInch, WithdrawSigned, WithdrawSignedAndSwapOneInch, } from "../app/interfaces/fiberEngineInterface"; @@ -142,7 +144,9 @@ module.exports = { const targetSigner = signer.connect(targetNetwork.provider); const targetTokenContract = new ethers.Contract( - targetTokenAddress, + await (global as any).commonFunctions.getWrappedNativeTokenAddress( + targetTokenAddress + ), tokenAbi.abi, targetNetwork.provider ); @@ -282,7 +286,7 @@ module.exports = { targetSigner, targetChainId ); - const receipt = await swapResult.wait(); + const receipt = await swapResult?.wait(); destinationAmount = ( body?.destinationAmountOut / 10 ** Number(targetTokenDecimal) @@ -349,7 +353,9 @@ module.exports = { // source token contract (required to approve function) const sourceTokenContract = new ethers.Contract( - sourceTokenAddress, + await (global as any).commonFunctions.getWrappedNativeTokenAddress( + sourceTokenAddress + ), tokenAbi.abi, sourceNetwork.provider ); @@ -371,13 +377,6 @@ module.exports = { let swapResult; if (isFoundryAsset) { if (!targetNetwork.isNonEVM) { - // approve to fiber router to transfer tokens to the fund manager contract - const targetFoundryTokenAddress = - await sourceNetwork.fundManagerContract.allowedTargets( - sourceTokenAddress, - targetChainId - ); - // fiber router add foundry asset to fund manager swapResult = fiberRouter.methods.swap( sourceTokenAddress, amount, @@ -393,7 +392,6 @@ module.exports = { query?.destinationAssetType ) ); - //wait until the transaction be completed sourceBridgeAmount = amount; } else if (targetNetwork.isNonEVM) { // // approve to fiber router to transfer tokens to the fund manager contract @@ -526,24 +524,26 @@ module.exports = { } else { // 1Inch implementation if (!targetNetwork.isNonEVM) { - swapResult = fiberRouter.methods.swapAndCrossOneInch( - amount, - query?.sourceBridgeAmount, - targetChainId, - targetTokenAddress, - destinationWalletAddress, + let withdrawalData = getWithdrawalDataHashForSwap( query?.sourceOneInchData, - sourceTokenAddress, - sourceNetwork.foundryTokenAddress, - getWithdrawalDataHashForSwap( - query?.sourceOneInchData, - query?.destinationOneInchData, - query?.destinationAmountIn, - query?.destinationAmountOut, - query?.sourceAssetType, - query?.destinationAssetType - ) + query?.destinationOneInchData, + query?.destinationAmountIn, + query?.destinationAmountOut, + query?.sourceAssetType, + query?.destinationAssetType ); + let obj: SwapOneInch = { + amountIn: amount, + amountOut: query?.sourceBridgeAmount, + targetChainId: targetChainId, + targetTokenAddress: targetTokenAddress, + destinationWalletAddress: destinationWalletAddress, + sourceOneInchData: query?.sourceOneInchData, + sourceTokenAddress: sourceTokenAddress, + foundryTokenAddress: sourceNetwork.foundryTokenAddress, + withdrawalData: withdrawalData, + }; + swapResult = await doOneInchSwap(obj, fiberRouter); } else { // swapResult = fiberRouter.methods.nonEvmSwapAndCrossOneInch( // sourceNetwork?.router, @@ -569,7 +569,7 @@ module.exports = { sourceWalletAddress ); - return { + let returnData = { currency: sourceNetwork.shortName + ":" + sourceTokenAddress, from: sourceWalletAddress, amount: "0", @@ -579,6 +579,14 @@ module.exports = { description: `Swap `, ...(await getGasForSwap(sourceChainId, destinationWalletAddress)), }; + + if ( + await (global as any).commonFunctions.isNativeToken(sourceTokenAddress) + ) { + returnData = { ...returnData, value: amount }; + } + + return returnData; } catch (error) { throw { error }; } @@ -587,7 +595,7 @@ module.exports = { callEVMWithdrawAndGetReceipt: async function (data: any) { let receipt: any = { status: 0, responseMessage: "" }; try { - receipt = await data.wait(); + receipt = await data?.wait(); } catch (e) { receipt.responseMessage = e; } diff --git a/scripts/fiberNode.ts b/scripts/fiberNode.ts index 0a02023..7644cbc 100644 --- a/scripts/fiberNode.ts +++ b/scripts/fiberNode.ts @@ -41,7 +41,9 @@ module.exports = { // source if (!sourceNetwork.isNonEVM) { const sourceTokenContract = new ethers.Contract( - sourceTokenAddress, + await (global as any).commonFunctions.getWrappedNativeTokenAddress( + sourceTokenAddress + ), tokenAbi.abi, sourceNetwork.provider ); @@ -59,14 +61,15 @@ module.exports = { ); let sourceTypeResponse = await getSourceAssetTypes( sourceNetwork, - sourceTokenAddress, + await (global as any).commonFunctions.getWrappedNativeTokenAddress( + sourceTokenAddress + ), amount ); const isFoundryAsset = sourceTypeResponse.isFoundryAsset; const isRefineryAsset = sourceTypeResponse.isRefineryAsset; const isIonicAsset = sourceTypeResponse.isIonicAsset; const isOneInchAsset = sourceTypeResponse.isOneInch; - if (isFoundryAsset) { sourceAssetType = (global as any).utils.assetType.FOUNDARY; } else if (isRefineryAsset) { @@ -112,7 +115,9 @@ module.exports = { // 1Inch implementation let response = await OneInchSwap( sourceChainId, - sourceTokenAddress, + await (global as any).commonFunctions.getWrappedNativeTokenAddress( + sourceTokenAddress + ), sourceNetwork?.foundryTokenAddress, amount, sourceNetwork?.fiberRouter, @@ -149,7 +154,9 @@ module.exports = { // destination if (!targetNetwork.isNonEVM) { const targetTokenContract = new ethers.Contract( - targetTokenAddress, + await (global as any).commonFunctions.getWrappedNativeTokenAddress( + targetTokenAddress + ), tokenAbi.abi, targetNetwork.provider ); @@ -177,7 +184,9 @@ module.exports = { amountIn = parseInt(amountIn); let targetTypeResponse = await getTargetAssetTypes( targetNetwork, - targetTokenAddress, + await (global as any).commonFunctions.getWrappedNativeTokenAddress( + targetTokenAddress + ), amountIn ); @@ -195,7 +204,6 @@ module.exports = { } else { targetAssetType = (global as any).utils.assetType.ONE_INCH; } - if (isTargetTokenFoundry === true) { destinationAmountOut = sourceBridgeAmount; machineDestinationAmountIn = ( @@ -259,7 +267,9 @@ module.exports = { let response = await OneInchSwap( targetChainId, targetNetwork?.foundryTokenAddress, - targetTokenAddress, + await (global as any).commonFunctions.getOneInchTokenAddress( + targetTokenAddress + ), machineAmount, targetNetwork?.fiberRouter, destinationWalletAddress