From 2a0c602dc0d170e5a879ef8074cd4e6d79499d02 Mon Sep 17 00:00:00 2001 From: Zikriya Date: Thu, 2 May 2024 21:05:14 +0500 Subject: [PATCH] router selector updates --- src/constants/FiberRouter.json | 512 ++++++++++++++++-------------- src/constants/constants.ts | 15 +- src/services/signature.service.ts | 27 +- src/services/web3.service.ts | 8 +- 4 files changed, 318 insertions(+), 244 deletions(-) diff --git a/src/constants/FiberRouter.json b/src/constants/FiberRouter.json index 376d71f..cbb6daf 100644 --- a/src/constants/FiberRouter.json +++ b/src/constants/FiberRouter.json @@ -3,25 +3,20 @@ "contractName": "FiberRouter", "sourceName": "contracts/upgradeable-Bridge/FiberRouter.sol", "abi": [ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, { "anonymous": false, "inputs": [ { - "indexed": false, + "indexed": true, "internalType": "address", - "name": "sourceToken", + "name": "burnToken", "type": "address" }, { "indexed": false, - "internalType": "string", - "name": "targetToken", - "type": "string" + "internalType": "uint256", + "name": "sourceAmount", + "type": "uint256" }, { "indexed": false, @@ -29,16 +24,10 @@ "name": "sourceChainId", "type": "uint256" }, - { - "indexed": false, - "internalType": "string", - "name": "targetChainId", - "type": "string" - }, { "indexed": false, "internalType": "uint256", - "name": "sourceAmount", + "name": "targetChainId", "type": "uint256" }, { @@ -49,24 +38,18 @@ }, { "indexed": false, - "internalType": "string", + "internalType": "address", "name": "targetAddress", - "type": "string" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "settledAmount", - "type": "uint256" + "type": "address" }, { "indexed": false, - "internalType": "bytes32", - "name": "withdrawalData", - "type": "bytes32" + "internalType": "uint64", + "name": "depositNonce", + "type": "uint64" } ], - "name": "NonEvmSwap", + "name": "CCTPSwap", "type": "event" }, { @@ -88,6 +71,44 @@ "name": "OwnershipTransferred", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "selector", + "type": "bytes" + } + ], + "name": "RouterAndSelectorRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes", + "name": "selector", + "type": "bytes" + } + ], + "name": "RouterAndSelectorWhitelisted", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -155,43 +176,6 @@ "name": "Swap", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "swapRouter", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "fromToken", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - } - ], - "name": "SwapHandled", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -235,74 +219,6 @@ "name": "SwapSameNetwork", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "swapRouter", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - } - ], - "name": "UniswapV3SwapHandled", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "swapRouter", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "fromToken", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amountIn", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - } - ], - "name": "UnoSwapHandled", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -358,7 +274,7 @@ { "indexed": false, "internalType": "uint256", - "name": "amountOutOneInch", + "name": "amountOut", "type": "uint256" }, { @@ -373,10 +289,16 @@ "name": "targetToken", "type": "address" }, + { + "indexed": false, + "internalType": "address", + "name": "router", + "type": "address" + }, { "indexed": false, "internalType": "bytes", - "name": "oneInchData", + "name": "routerCalldata", "type": "bytes" }, { @@ -392,12 +314,30 @@ "type": "bytes" } ], - "name": "WithdrawOneInch", + "name": "WithdrawRouter", "type": "event" }, + { + "inputs": [ + { + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "internalType": "bytes", + "name": "selector", + "type": "bytes" + } + ], + "name": "addRouterAndSelector", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], - "name": "WETH", + "name": "cctpTokenMessenger", "outputs": [ { "internalType": "address", @@ -421,6 +361,29 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "_cctpTokenMessenger", + "type": "address" + }, + { + "internalType": "address", + "name": "_usdcToken", + "type": "address" + }, + { + "internalType": "address", + "name": "_sourceCCTPFundManager", + "type": "address" + } + ], + "name": "initCCTP", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -444,43 +407,29 @@ "inputs": [ { "internalType": "address", - "name": "token", + "name": "router", "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": "bytes", + "name": "selector", + "type": "bytes" + } + ], + "name": "isAllowListed", + "outputs": [ { - "internalType": "bytes32", - "name": "withdrawalData", - "type": "bytes32" + "internalType": "bool", + "name": "", + "type": "bool" } ], - "name": "nonEvmSwap", - "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [], - "name": "oneInchAggregatorRouter", + "name": "owner", "outputs": [ { "internalType": "address", @@ -493,7 +442,7 @@ }, { "inputs": [], - "name": "owner", + "name": "pool", "outputs": [ { "internalType": "address", @@ -505,16 +454,21 @@ "type": "function" }, { - "inputs": [], - "name": "pool", - "outputs": [ + "inputs": [ { "internalType": "address", - "name": "", + "name": "router", "type": "address" + }, + { + "internalType": "bytes", + "name": "selector", + "type": "bytes" } ], - "stateMutability": "view", + "name": "removeRouterAndSelector", + "outputs": [], + "stateMutability": "nonpayable", "type": "function" }, { @@ -541,24 +495,34 @@ "inputs": [ { "internalType": "address", - "name": "_newRouterAddress", + "name": "_pool", "type": "address" } ], - "name": "setOneInchAggregatorRouter", + "name": "setPool", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ + { + "internalType": "uint256", + "name": "_chainID", + "type": "uint256" + }, + { + "internalType": "uint32", + "name": "_targetNetworkDomain", + "type": "uint32" + }, { "internalType": "address", - "name": "_pool", + "name": "_targetCCTPFundManager", "type": "address" } ], - "name": "setPool", + "name": "setTargetCCTPNetwork", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -571,11 +535,24 @@ "type": "address" } ], - "name": "setWETH", + "name": "setWeth", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "sourceCCTPFundManager", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -607,6 +584,11 @@ "internalType": "bytes32", "name": "withdrawalData", "type": "bytes32" + }, + { + "internalType": "bool", + "name": "cctpType", + "type": "bool" } ], "name": "swap", @@ -623,37 +605,42 @@ }, { "internalType": "uint256", - "name": "amountOut", + "name": "minAmountOut", "type": "uint256" }, { - "internalType": "uint256", - "name": "crossTargetNetwork", - "type": "uint256" + "internalType": "address", + "name": "fromToken", + "type": "address" }, { "internalType": "address", - "name": "crossTargetToken", + "name": "foundryToken", "type": "address" }, { "internalType": "address", - "name": "crossTargetAddress", + "name": "router", "type": "address" }, { "internalType": "bytes", - "name": "oneInchData", + "name": "routerCalldata", "type": "bytes" }, + { + "internalType": "uint256", + "name": "crossTargetNetwork", + "type": "uint256" + }, { "internalType": "address", - "name": "fromToken", + "name": "crossTargetToken", "type": "address" }, { "internalType": "address", - "name": "foundryToken", + "name": "crossTargetAddress", "type": "address" }, { @@ -662,12 +649,12 @@ "type": "bytes32" }, { - "internalType": "enum FiberRouter.OneInchFunction", - "name": "funcSelector", - "type": "uint8" + "internalType": "bool", + "name": "cctpType", + "type": "bool" } ], - "name": "swapAndCrossOneInch", + "name": "swapAndCrossRouter", "outputs": [], "stateMutability": "payable", "type": "function" @@ -676,32 +663,42 @@ "inputs": [ { "internalType": "uint256", - "name": "amountOut", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "crossTargetNetwork", + "name": "minAmountOut", "type": "uint256" }, { "internalType": "address", - "name": "crossTargetToken", + "name": "foundryToken", "type": "address" }, + { + "internalType": "uint256", + "name": "gasFee", + "type": "uint256" + }, { "internalType": "address", - "name": "crossTargetAddress", + "name": "router", "type": "address" }, { "internalType": "bytes", - "name": "oneInchData", + "name": "routerCalldata", "type": "bytes" }, + { + "internalType": "uint256", + "name": "crossTargetNetwork", + "type": "uint256" + }, { "internalType": "address", - "name": "foundryToken", + "name": "crossTargetToken", + "type": "address" + }, + { + "internalType": "address", + "name": "crossTargetAddress", "type": "address" }, { @@ -710,17 +707,12 @@ "type": "bytes32" }, { - "internalType": "uint256", - "name": "gasFee", - "type": "uint256" - }, - { - "internalType": "enum FiberRouter.OneInchFunction", - "name": "funcSelector", - "type": "uint8" + "internalType": "bool", + "name": "cctpType", + "type": "bool" } ], - "name": "swapAndCrossOneInchETH", + "name": "swapAndCrossRouterETH", "outputs": [], "stateMutability": "payable", "type": "function" @@ -734,7 +726,7 @@ }, { "internalType": "uint256", - "name": "amountOut", + "name": "minAmountOut", "type": "uint256" }, { @@ -753,14 +745,14 @@ "type": "address" }, { - "internalType": "bytes", - "name": "oneInchData", - "type": "bytes" + "internalType": "address", + "name": "router", + "type": "address" }, { - "internalType": "enum FiberRouter.OneInchFunction", - "name": "funcSelector", - "type": "uint8" + "internalType": "bytes", + "name": "routerCalldata", + "type": "bytes" } ], "name": "swapOnSameNetwork", @@ -772,7 +764,7 @@ "inputs": [ { "internalType": "uint256", - "name": "amountOut", + "name": "minAmountOut", "type": "uint256" }, { @@ -786,14 +778,14 @@ "type": "address" }, { - "internalType": "bytes", - "name": "oneInchData", - "type": "bytes" + "internalType": "address", + "name": "router", + "type": "address" }, { - "internalType": "enum FiberRouter.OneInchFunction", - "name": "funcSelector", - "type": "uint8" + "internalType": "bytes", + "name": "routerCalldata", + "type": "bytes" } ], "name": "swapOnSameNetworkETH", @@ -801,6 +793,30 @@ "stateMutability": "payable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "targetNetworks", + "outputs": [ + { + "internalType": "uint32", + "name": "targetNetworkDomain", + "type": "uint32" + }, + { + "internalType": "address", + "name": "targetCCTPFundManager", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -814,6 +830,32 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "usdcToken", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "weth", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -845,6 +887,11 @@ "internalType": "bytes", "name": "multiSignature", "type": "bytes" + }, + { + "internalType": "bool", + "name": "cctpType", + "type": "bool" } ], "name": "withdrawSigned", @@ -866,7 +913,7 @@ }, { "internalType": "uint256", - "name": "amountOut", + "name": "minAmountOut", "type": "uint256" }, { @@ -880,14 +927,14 @@ "type": "address" }, { - "internalType": "bytes", - "name": "oneInchData", - "type": "bytes" + "internalType": "address", + "name": "router", + "type": "address" }, { - "internalType": "enum FiberRouter.OneInchFunction", - "name": "funcSelector", - "type": "uint8" + "internalType": "bytes", + "name": "routerCalldata", + "type": "bytes" }, { "internalType": "bytes32", @@ -903,9 +950,14 @@ "internalType": "bytes", "name": "multiSignature", "type": "bytes" + }, + { + "internalType": "bool", + "name": "cctpType", + "type": "bool" } ], - "name": "withdrawSignedAndSwapOneInch", + "name": "withdrawSignedAndSwapRouter", "outputs": [], "stateMutability": "nonpayable", "type": "function" diff --git a/src/constants/constants.ts b/src/constants/constants.ts index 70ebb27..d510f0d 100644 --- a/src/constants/constants.ts +++ b/src/constants/constants.ts @@ -14,30 +14,37 @@ export const NETWORKS = [ fundManagerAddress: "0x5eBeF0bD015e4fAfe64172Ae00b9bB46a05906a7", fiberRouterAddress: "0x4B87Ab46B56990Aff03dAD1caFEb33e760879d97", foundaryTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", + aggregateRouterContractAddress: "", }, { chainId: "56", - fundManagerAddress: "0xBFE96b3524a5d31B803BA133844C002Beaa79373", - fiberRouterAddress: "0x4B87Ab46B56990Aff03dAD1caFEb33e760879d97", + fundManagerAddress: "0xB4A5D95BFEC6AFd359e05aA982718C11bF04a7Ff", + fiberRouterAddress: "0xbB1886FA834917716049094090387DEa0680BFFc", foundaryTokenAddress: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d", + aggregateRouterContractAddress: + "0x111111125421ca6dc452d289314280a0f8842a65", }, { chainId: "42161", - fundManagerAddress: "0x4Ba81924a6D7DaF6Dba27783168E5b6345D6A896", - fiberRouterAddress: "0xb73A2a6cd7297844B1CbfcFfEb2884bEaf4C22B1", + fundManagerAddress: "0x2AB6D6c328978D0DCC5a9ac0BA04E45e358e3B9a", + fiberRouterAddress: "0x8d8559221D55338369C1B305A58eb86fdcE3B8b9", foundaryTokenAddress: "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", + aggregateRouterContractAddress: + "0x111111125421ca6dc452d289314280a0f8842a65", }, { chainId: "10", fundManagerAddress: "0x7655eE1bd794b0Fe4b9B4D477B0F5cCABD78137c", fiberRouterAddress: "0x6a34da798839964e14850F585187f3d28079a500", foundaryTokenAddress: "0x0b2c639c533813f4aa9d7837caf62653d097ff85", + aggregateRouterContractAddress: "", }, { chainId: "43114", fundManagerAddress: "0x41eFd89cbeaCeCdf72d3fD8321C53A69A132CC1a", fiberRouterAddress: "0x9cc84e262E3A2A6b8C257d493E3d3487495fb5a2", foundaryTokenAddress: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E", + aggregateRouterContractAddress: "", }, ]; diff --git a/src/services/signature.service.ts b/src/services/signature.service.ts index e7c3569..20f4342 100644 --- a/src/services/signature.service.ts +++ b/src/services/signature.service.ts @@ -19,6 +19,7 @@ import { bufferToHex, } from "ethereumjs-util"; import { decimals, decimalsIntoNumber, withSlippage } from "../constants/utils"; +import { getAggregateRouterTokenAddress } from "./web3.service"; export const getDataForSignature = async ( job: any, @@ -57,6 +58,9 @@ export const getDataForSignature = async ( destinationOneInchData: withdrawalData?.destinationOneInchData, settledAmount: withdrawalData?.settledAmount, expiry: job.data.expiry, + aggregateRouterContractAddress: getAggregateRouterTokenAddress( + decodedData.targetChainId + ), }; return txData; }; @@ -142,9 +146,10 @@ export const createSignedPayment = ( amountIn: string, amountOut: string, targetFoundaryToken: string, - oneInchData: string, + routerCalldata: string, expiry: number, - web3: Web3 + web3: Web3, + aggregateRouterContractAddress: string ) => { let hash; if (destinationAssetType == FOUNDARY) { @@ -168,9 +173,10 @@ export const createSignedPayment = ( amountOut, targetFoundaryToken, targetToken, - oneInchData, + routerCalldata, salt, - expiry + expiry, + aggregateRouterContractAddress ); } const privateKey = getPrivateKey(); @@ -228,13 +234,14 @@ export const produceOneInchHash = ( amountOut: string, foundryToken: string, targetToken: string, - oneInchData: string, + routerCalldata: string, salt: string, - expiry: number + expiry: number, + aggregateRouterContractAddress: string ): any => { const methodHash = Web3.utils.keccak256( Web3.utils.utf8ToHex( - "WithdrawSignedOneInch(address to,uint256 amountIn,uint256 amountOut,address foundryToken,address targetToken,bytes oneInchData,bytes32 salt,uint256 expiry)" + "withdrawSignedAndSwapRouter(address to,uint256 amountIn,uint256 minAmountOut,address foundryToken,address targetToken,address router,bytes32 routerCalldata,bytes32 salt,uint256 expiry)" ) ); const params = [ @@ -244,7 +251,8 @@ export const produceOneInchHash = ( "uint256", "address", "address", - "bytes", + "address", + "bytes32", "bytes32", "uint256", ]; @@ -255,7 +263,8 @@ export const produceOneInchHash = ( amountOut, foundryToken, targetToken, - oneInchData, + aggregateRouterContractAddress, + Web3.utils.keccak256(routerCalldata), salt, expiry, ]); diff --git a/src/services/web3.service.ts b/src/services/web3.service.ts index 3ff3027..6a4ea44 100644 --- a/src/services/web3.service.ts +++ b/src/services/web3.service.ts @@ -75,7 +75,8 @@ export const signedTransaction = async ( txData.targetFoundaryToken, txData.destinationOneInchData, txData.expiry, - web3 + web3, + txData.aggregateRouterContractAddress ); return { @@ -169,6 +170,11 @@ export const getFoundaryTokenAddress = (chainId: string) => { return item ? item.foundaryTokenAddress : ""; }; +export const getAggregateRouterTokenAddress = (chainId: string) => { + let item = NETWORKS.find((item: any) => item.chainId === chainId); + return item ? item.aggregateRouterContractAddress : ""; +}; + const getDestinationAmount = async (data: any) => { return data.swapBridgeAmount; };