|  | @@ -1,17 +1,10 @@
 | 
	
		
			
				|  |  |  import express from "express";
 | 
	
		
			
				|  |  |  import CommonUtil from "../../utils/commonUtil.js";
 | 
	
		
			
				|  |  | -import {Contract, ethers, utils} from "ethers";
 | 
	
		
			
				|  |  | +import {BigNumber, Contract, ethers, utils} from "ethers";
 | 
	
		
			
				|  |  |  import RouterEthAbi from './contract/routerEth.js'
 | 
	
		
			
				|  |  |  import mathUtil from "../../utils/mathUtil.js";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  const router = express.Router();
 | 
	
		
			
				|  |  | -// const ethChainId = 101;
 | 
	
		
			
				|  |  | -// const wrapperEth = "0x72E2F4830b9E45d52F80aC08CB2bEC0FeF72eD9c";
 | 
	
		
			
				|  |  | -// const routerAddress = "0x8731d54E9D02c286767d56ac03e8037C07e01e98";
 | 
	
		
			
				|  |  | -// const routerEthAddress = "0x150f94B44927F078737562f0fcF3C95c01Cc2376";
 | 
	
		
			
				|  |  | -// const network = "https://eth-mainnet.g.alchemy.com/v2/I0grWRjLbj_Rf1WP3QMJ-z3mKp71Hb4L";
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  const networks = {
 | 
	
		
			
				|  |  |      eth: {
 | 
	
		
			
				|  |  |          chain_id: 101,
 | 
	
	
		
			
				|  | @@ -34,39 +27,27 @@ const networks = {
 | 
	
		
			
				|  |  |          router_eth_address: "0xB49c4e680174E331CB0A7fF3Ab58afC9738d5F8b",
 | 
	
		
			
				|  |  |          network: "https://opt-mainnet.g.alchemy.com/v2/-JQnqchpVew7O9KBdK_lkbXl_iHtfrwS"
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  | -    base:{
 | 
	
		
			
				|  |  | -        chain_id:184,
 | 
	
		
			
				|  |  | -        wrapper_eth:"0x224d8fd7ab6ad4c6eb4611ce56ef35dec2277f03",
 | 
	
		
			
				|  |  | -        router_address:"0x45f1A95A4D3f3836523F5c83673c797f4d4d263B",
 | 
	
		
			
				|  |  | -        router_eth_address:"0x50B6EbC2103BFEc165949CC946d739d5650d7ae4",
 | 
	
		
			
				|  |  | -        network:"https://base-mainnet.g.alchemy.com/v2/AmI0yZYNAaRMljIwlj_CFQV4MZw5XVvf"
 | 
	
		
			
				|  |  | +    base: {
 | 
	
		
			
				|  |  | +        chain_id: 184,
 | 
	
		
			
				|  |  | +        wrapper_eth: "0x224d8fd7ab6ad4c6eb4611ce56ef35dec2277f03",
 | 
	
		
			
				|  |  | +        router_address: "0x45f1A95A4D3f3836523F5c83673c797f4d4d263B",
 | 
	
		
			
				|  |  | +        router_eth_address: "0x50B6EbC2103BFEc165949CC946d739d5650d7ae4",
 | 
	
		
			
				|  |  | +        network: "https://base-mainnet.g.alchemy.com/v2/AmI0yZYNAaRMljIwlj_CFQV4MZw5XVvf"
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -// const arbChainId = 110;
 | 
	
		
			
				|  |  | -// const wrapperArbEthAddress = "0x82cbecf39bee528b5476fe6d1550af59a9db6fc0";
 | 
	
		
			
				|  |  | -// const routerArbAddress = "0x53bf833a5d6c4dda888f69c22c88c9f356a41614";
 | 
	
		
			
				|  |  | -// const routerArbEthAddress = "0xbf22f0f184bCcbeA268dF387a49fF5238dD23E40";
 | 
	
		
			
				|  |  | -// const arbNetwork = "https://arb-mainnet.g.alchemy.com/v2/8hbABA2L3eaR7VWGY8yk-5p16Aeurf2Z";
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  router.post("/", async (req, res) => {
 | 
	
		
			
				|  |  |      let {wallet, params} = CommonUtil.getParamsAndWallet(req);
 | 
	
		
			
				|  |  |      let dist_chain_id = networks[params.dist_chain].chain_id;
 | 
	
		
			
				|  |  | -    let source_chain_id = networks[params.source_chain].chain_id;
 | 
	
		
			
				|  |  | -    let wrap_addr = networks[params.source_chain].wrapper_eth;
 | 
	
		
			
				|  |  | -    let rt_addr = networks[params.source_chain].router_address;
 | 
	
		
			
				|  |  |      let rt_eth_addr = networks[params.source_chain].router_eth_address;
 | 
	
		
			
				|  |  |      let net_work = networks[params.source_chain].network;
 | 
	
		
			
				|  |  |      const provider = ethers.getDefaultProvider(net_work);
 | 
	
		
			
				|  |  |      const signer = new ethers.Wallet(wallet.privateKey, provider);
 | 
	
		
			
				|  |  | -    // const router = new Contract(rt_addr, RouterAbi, signer);
 | 
	
		
			
				|  |  |      const routerEth = new Contract(rt_eth_addr, RouterEthAbi, signer);
 | 
	
		
			
				|  |  |      let amountNumber = mathUtil.getRandomNumber(params.minAmount, params.maxAmount, params.accuracy);
 | 
	
		
			
				|  |  |      amountNumber = utils.parseEther(`${amountNumber}`);
 | 
	
		
			
				|  |  |      let crossGas = utils.parseEther(params.crossGas);
 | 
	
		
			
				|  |  |      const amountOut = amountNumber.mul(995).div(1000);
 | 
	
		
			
				|  |  | -    let tx = await routerEth.swapETH(
 | 
	
		
			
				|  |  | +    let gasLimit = (await routerEth.estimateGas.swapETH(
 | 
	
		
			
				|  |  |          dist_chain_id,
 | 
	
		
			
				|  |  |          wallet.address,
 | 
	
		
			
				|  |  |          wallet.address,
 | 
	
	
		
			
				|  | @@ -75,11 +56,27 @@ router.post("/", async (req, res) => {
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              value: amountNumber.add(crossGas)
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +    )).mul(6).div(5)
 | 
	
		
			
				|  |  | +    let gasPrice = await provider.getGasPrice()
 | 
	
		
			
				|  |  | +    console.log("gas-price:", gasPrice.toString())
 | 
	
		
			
				|  |  | +    console.log("gas-limit:", gasLimit.toString())
 | 
	
		
			
				|  |  | +    console.log("max-gas:", utils.formatEther(gasPrice.mul(gasLimit)))
 | 
	
		
			
				|  |  | +    const _tx = await routerEth.swapETH(
 | 
	
		
			
				|  |  | +        dist_chain_id,
 | 
	
		
			
				|  |  | +        wallet.address,
 | 
	
		
			
				|  |  | +        wallet.address,
 | 
	
		
			
				|  |  | +        amountNumber,
 | 
	
		
			
				|  |  | +        amountOut,
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            value: amountNumber.add(crossGas),
 | 
	
		
			
				|  |  | +            gasLimit,
 | 
	
		
			
				|  |  | +            gasPrice
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      )
 | 
	
		
			
				|  |  | -    await tx.wait();
 | 
	
		
			
				|  |  | -    tx = await provider.getTransaction(tx.hash);
 | 
	
		
			
				|  |  | +    await _tx.wait();
 | 
	
		
			
				|  |  | +    const tx = await provider.getTransaction(_tx.hash);
 | 
	
		
			
				|  |  |      const txReceipt = await provider.getTransactionReceipt(tx.hash);
 | 
	
		
			
				|  |  | -    const gas = utils.formatEther((txReceipt.gasUsed * tx.gasPrice).toFixed(0));
 | 
	
		
			
				|  |  | +    const gas = utils.formatEther((txReceipt.gasUsed * gasPrice).toFixed(0));
 | 
	
		
			
				|  |  |      const balance = await signer.getBalance()
 | 
	
		
			
				|  |  |      const balanceStr = utils.formatEther(balance);
 | 
	
		
			
				|  |  |      const value = utils.formatEther(tx.value)
 |