xiongzhu 2 vuotta sitten
vanhempi
commit
fe38f7e42b

+ 2 - 0
src/task/enums/task-type.enum.ts

@@ -7,6 +7,8 @@ export enum TaskType {
     swapEth = 'swapEth',
     syncSwapUsdc = 'syncSwapUsdc',
     syncSwapEth = 'syncSwapEth',
+    muteSwapUsdc = 'muteSwapUsdc',
+    muteSwapEth = 'muteSwapEth',
     addLiquidity = 'addLiquidity',
     removeLiquidity = 'removeLiquidity',
     addLiquiditySyncSwap = 'addLiquiditySyncSwap',

+ 26 - 0
src/task/task.service.ts

@@ -200,6 +200,32 @@ export class TaskService implements OnModuleInit {
                                 'usdc'
                             )
                             break
+                        case TaskType.muteSwapUsdc:
+                            web3Result = await this.web3Service.muteSwap(
+                                accountId,
+                                taskItem.amountType === 'amount'
+                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
+                                    : randomBalancePercent(
+                                          await this.accountsService.getZkBalance(account),
+                                          taskItem.percent.min,
+                                          taskItem.percent.max
+                                      ),
+                                'eth'
+                            )
+                            break
+                        case TaskType.muteSwapEth:
+                            web3Result = await this.web3Service.muteSwap(
+                                accountId,
+                                taskItem.amountType === 'amount'
+                                    ? randomAmount(taskItem.amount.min, taskItem.amount.max)
+                                    : randomBalancePercent(
+                                          await this.accountsService.getUsdcBalance(account),
+                                          taskItem.percent.min,
+                                          taskItem.percent.max
+                                      ),
+                                'usdc'
+                            )
+                            break
                         case TaskType.addLiquidity:
                             web3Result = await this.web3Service.addLiquidity(
                                 accountId,

+ 0 - 0
src/web3/erc20.json → src/web3/abi/erc20Abi.json


+ 14 - 0
src/web3/abi/index.ts

@@ -0,0 +1,14 @@
+import erc20 from './erc20Abi.json'
+import mintSquareAbi from './mintSquareAbi.json'
+import SyncSwapPoolFactoryAbi from './SyncSwapClassicPoolFactory.json'
+import SyncSwapPoolAbi from './SyncSwapClassicPool.json'
+import SyncSwapRouterAbi from './SyncSwapRouter.json'
+import muteRouterAbi from './muteRouterAbi.json'
+export {
+    erc20,
+    mintSquareAbi,
+    SyncSwapPoolFactoryAbi,
+    SyncSwapPoolAbi,
+    SyncSwapRouterAbi,
+    muteRouterAbi
+}

+ 0 - 0
src/web3/mintSquareAbi.json → src/web3/abi/mintSquareAbi.json


+ 856 - 0
src/web3/abi/muteRouterAbi.json

@@ -0,0 +1,856 @@
+[
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "_factory",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "_weth",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "constructor"
+    },
+    {
+        "stateMutability": "payable",
+        "type": "fallback"
+    },
+    {
+        "inputs": [],
+        "name": "WETH",
+        "outputs": [
+            {
+                "internalType": "address",
+                "name": "",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "tokenA",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "tokenB",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountADesired",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountBDesired",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountAMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountBMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "feeType",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            }
+        ],
+        "name": "addLiquidity",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountA",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountB",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "liquidity",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "token",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountTokenDesired",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountTokenMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountETHMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "feeType",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            }
+        ],
+        "name": "addLiquidityETH",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountToken",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountETH",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "liquidity",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "payable",
+        "type": "function"
+    },
+    {
+        "inputs": [],
+        "name": "factory",
+        "outputs": [
+            {
+                "internalType": "address",
+                "name": "",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountIn",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address",
+                "name": "tokenIn",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "tokenOut",
+                "type": "address"
+            }
+        ],
+        "name": "getAmountOut",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountOut",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            },
+            {
+                "internalType": "uint256",
+                "name": "fee",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountIn",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            },
+            {
+                "internalType": "bool[]",
+                "name": "stable",
+                "type": "bool[]"
+            }
+        ],
+        "name": "getAmountsOut",
+        "outputs": [
+            {
+                "internalType": "uint256[]",
+                "name": "amounts",
+                "type": "uint256[]"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountIn",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            }
+        ],
+        "name": "getAmountsOutExpanded",
+        "outputs": [
+            {
+                "internalType": "uint256[]",
+                "name": "amounts",
+                "type": "uint256[]"
+            },
+            {
+                "internalType": "bool[]",
+                "name": "stable",
+                "type": "bool[]"
+            },
+            {
+                "internalType": "uint256[]",
+                "name": "fees",
+                "type": "uint256[]"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            }
+        ],
+        "name": "getPairInfo",
+        "outputs": [
+            {
+                "internalType": "address",
+                "name": "tokenA",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "tokenB",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "pair",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "reserveA",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "reserveB",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "fee",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "tokenA",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "tokenB",
+                "type": "address"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            }
+        ],
+        "name": "getReserves",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "reserveA",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "reserveB",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "tokenA",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "tokenB",
+                "type": "address"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            }
+        ],
+        "name": "pairFor",
+        "outputs": [
+            {
+                "internalType": "address",
+                "name": "pair",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "view",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountA",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "reserveA",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "reserveB",
+                "type": "uint256"
+            }
+        ],
+        "name": "quote",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountB",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "pure",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "tokenA",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "tokenB",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "liquidity",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountAMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountBMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            }
+        ],
+        "name": "removeLiquidity",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountA",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountB",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "token",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "liquidity",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountTokenMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountETHMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            }
+        ],
+        "name": "removeLiquidityETH",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountToken",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountETH",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "token",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "liquidity",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountTokenMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountETHMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool",
+                "name": "stable",
+                "type": "bool"
+            }
+        ],
+        "name": "removeLiquidityETHSupportingFeeOnTransferTokens",
+        "outputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountETH",
+                "type": "uint256"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "address",
+                "name": "tokenA",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "tokenB",
+                "type": "address"
+            }
+        ],
+        "name": "sortTokens",
+        "outputs": [
+            {
+                "internalType": "address",
+                "name": "token0",
+                "type": "address"
+            },
+            {
+                "internalType": "address",
+                "name": "token1",
+                "type": "address"
+            }
+        ],
+        "stateMutability": "pure",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountOutMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool[]",
+                "name": "stable",
+                "type": "bool[]"
+            }
+        ],
+        "name": "swapExactETHForTokens",
+        "outputs": [
+            {
+                "internalType": "uint256[]",
+                "name": "amounts",
+                "type": "uint256[]"
+            }
+        ],
+        "stateMutability": "payable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountOutMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool[]",
+                "name": "stable",
+                "type": "bool[]"
+            }
+        ],
+        "name": "swapExactETHForTokensSupportingFeeOnTransferTokens",
+        "outputs": [],
+        "stateMutability": "payable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountIn",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountOutMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool[]",
+                "name": "stable",
+                "type": "bool[]"
+            }
+        ],
+        "name": "swapExactTokensForETH",
+        "outputs": [
+            {
+                "internalType": "uint256[]",
+                "name": "amounts",
+                "type": "uint256[]"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountIn",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountOutMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool[]",
+                "name": "stable",
+                "type": "bool[]"
+            }
+        ],
+        "name": "swapExactTokensForETHSupportingFeeOnTransferTokens",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountIn",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountOutMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool[]",
+                "name": "stable",
+                "type": "bool[]"
+            }
+        ],
+        "name": "swapExactTokensForTokens",
+        "outputs": [
+            {
+                "internalType": "uint256[]",
+                "name": "amounts",
+                "type": "uint256[]"
+            }
+        ],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    },
+    {
+        "inputs": [
+            {
+                "internalType": "uint256",
+                "name": "amountIn",
+                "type": "uint256"
+            },
+            {
+                "internalType": "uint256",
+                "name": "amountOutMin",
+                "type": "uint256"
+            },
+            {
+                "internalType": "address[]",
+                "name": "path",
+                "type": "address[]"
+            },
+            {
+                "internalType": "address",
+                "name": "to",
+                "type": "address"
+            },
+            {
+                "internalType": "uint256",
+                "name": "deadline",
+                "type": "uint256"
+            },
+            {
+                "internalType": "bool[]",
+                "name": "stable",
+                "type": "bool[]"
+            }
+        ],
+        "name": "swapExactTokensForTokensSupportingFeeOnTransferTokens",
+        "outputs": [],
+        "stateMutability": "nonpayable",
+        "type": "function"
+    }
+]

+ 2 - 1
src/web3/types.ts

@@ -18,5 +18,6 @@ declare interface Web3Config {
     orbiterIdCodeEth: number,
     syncSwapPoolFactoryAddress: string,
     syncSwapRouterAddress: string,
-    syncSwapWethAddress: string
+    syncSwapWethAddress: string,
+    muteRouterAddress: string
 }

+ 59 - 10
src/web3/web3.service.ts

@@ -1,9 +1,7 @@
 import { Inject, Injectable, InternalServerErrorException, Logger } from '@nestjs/common'
 import { ethers } from 'ethers'
 import { Wallet, Provider, utils } from 'zksync-web3'
-import { ConfigType } from '@nestjs/config'
 import { AccountsService } from '../accounts/accounts.service'
-import erc20 from './erc20.json'
 import { web3Config } from './web3config'
 import {
     ChainId,
@@ -40,17 +38,13 @@ import {
     quoterSwapChainWithExactInput
 } from 'iziswap-sdk/lib/quoter'
 import { getSwapContract, getSwapChainWithExactOutputCall, getSwapChainWithExactInputCall } from 'iziswap-sdk/lib/swap'
-import mintSquareAbi from './mintSquareAbi.json'
 import { Network } from './network.enum'
-import { Cron } from '@nestjs/schedule'
 import { Web3Result } from './model/web3-result'
 import { FileService } from 'src/file/file.service'
 import axios from 'axios'
 import * as randomString from 'randomstring'
 import { Account } from '../accounts/entities/account.entity'
-import SyncSwapPoolFactoryAbi from './abi/SyncSwapClassicPoolFactory.json'
-import SyncSwapPoolAbi from './abi/SyncSwapClassicPool.json'
-import SyncSwapRouterAbi from './abi/SyncSwapRouter.json'
+import { erc20, mintSquareAbi, SyncSwapPoolFactoryAbi, SyncSwapPoolAbi, SyncSwapRouterAbi, muteRouterAbi } from './abi'
 
 @Injectable()
 export class Web3Service {
@@ -470,9 +464,9 @@ export class Web3Service {
         const web3 = new Web3(new Web3.providers.HttpProvider(web3Config[network].zksyncRpcUrl))
         const tokenAContract = new web3.eth.Contract(erc20, tokenAddress)
         // @ts-ignore
-        const approveCalling = tokenAContract.methods.approve(spender, '0xffffffffffffffffffffffffffffffff')
+        const approveCalling = tokenAContract.methods.approve(spender, ethers.constants.MaxUint256.toHexString())
         let gasLimit = await approveCalling.estimateGas({ from: wallet.address })
-        console.log('approve gas limit: ', gasLimit)
+        Logger.log(`gasLimit: ${gasLimit}`, 'approveToken')
 
         const tx0 = await wallet.sendTransaction({
             from: wallet.address,
@@ -480,7 +474,7 @@ export class Web3Service {
             data: approveCalling.encodeABI(),
             gasLimit
         })
-        console.log('approve tx: ', JSON.stringify(tx0, null, 4))
+        console.log(`tx: ${JSON.stringify(tx0, null, 4)}`, 'approveToken')
     }
 
     async swapWithExactOutput(accountId, amount, outputToken: 'eth' | 'usdc' = 'usdc') {
@@ -710,6 +704,61 @@ export class Web3Service {
         return new Web3Result(account.address, tx.hash, config, true)
     }
 
+    async muteSwap(accountId, amount, inputToken: 'eth' | 'usdc' = 'usdc') {
+        const account = await this.accountService.findById(accountId)
+        const config = web3Config[account.network]
+        const provider = new Provider(config.zksyncRpcUrl)
+        const zkWallet = new Wallet(account.privateKey).connect(provider)
+        const web3 = new Web3(new Web3.providers.HttpProvider(config.zksyncRpcUrl))
+
+        const value = ethers.utils.parseUnits(amount, inputToken === 'eth' ? 18 : 6)
+        const muteRouter = new web3.eth.Contract(muteRouterAbi, config.muteRouterAddress)
+        const wethAddress = await muteRouter.methods.WETH().call()
+
+        if (inputToken === 'usdc') {
+            await this.approve(config.zkUsdcAddress, config.muteRouterAddress, zkWallet, account.network)
+        }
+        let swap
+        if (inputToken === 'eth') {
+            swap = muteRouter.methods.swapExactETHForTokens(
+                // @ts-ignore
+                '0',
+                [wethAddress, config.zkUsdcAddress],
+                zkWallet.address,
+                Math.floor(new Date().getTime() / 1000 + 60 * 30) + '',
+                [false]
+            )
+        } else {
+            swap = muteRouter.methods.swapExactTokensForETH(
+                // @ts-ignore
+                value.toHexString(),
+                '0',
+                [config.zkUsdcAddress, wethAddress],
+                zkWallet.address,
+                Math.floor(new Date().getTime() / 1000 + 60 * 30) + '',
+                [false]
+            )
+        }
+        const gasLimit = await swap.estimateGas({
+            from: zkWallet.address,
+            value: inputToken === 'eth' ? value.toHexString() : '0x0'
+        })
+        Logger.log(`gasLimit: ${gasLimit}`, 'muteSwap')
+        const tx = await zkWallet.sendTransaction({
+            // from: wallet.address,
+            to: config.muteRouterAddress,
+            data: swap.encodeABI(),
+            value: inputToken === 'eth' ? value.toHexString() : '0x0',
+            gasLimit
+        })
+
+        Logger.log(`transaction sent: ${tx.hash}`, 'muteSwap')
+        account.swapNum = (account.swapNum || 0) + 1
+        account.lastSwap = new Date()
+        await this.accountService.save([account])
+        return new Web3Result(account.address, tx.hash, config, true)
+    }
+
     async mint(accountId) {
         // const { data: buffer } = await axios.get('https://cataas.com/cat', {
         //     responseType: 'arraybuffer'

+ 4 - 2
src/web3/web3config.ts

@@ -17,7 +17,8 @@ const web3Config: { [key: string]: Web3Config } = {
         orbiterIdCodeEth: 9005,
         syncSwapPoolFactoryAddress: '0xf2FD2bc2fBC12842aAb6FbB8b1159a6a83E72006',
         syncSwapRouterAddress: '0xB3b7fCbb8Db37bC6f572634299A58f51622A847e',
-        syncSwapWethAddress: '0x20b28b1e4665fff290650586ad76e977eab90c5d'
+        syncSwapWethAddress: '0x20b28b1e4665fff290650586ad76e977eab90c5d',
+        muteRouterAddress: '0x96c2Cf9edbEA24ce659EfBC9a6e3942b7895b5e8'
     },
     mainnet: {
         ethereumNetwork: 'mainnet',
@@ -37,7 +38,8 @@ const web3Config: { [key: string]: Web3Config } = {
         orbiterIdCodeEth: 9001,
         syncSwapPoolFactoryAddress: '0xf2DAd89f2788a8CD54625C60b55cD3d2D0ACa7Cb',
         syncSwapRouterAddress: '0x2da10A1e27bF85cEdD8FFb1AbBe97e53391C0295',
-        syncSwapWethAddress: '0x5aea5775959fbc2557cc8789bc1bf90a239d9a91'
+        syncSwapWethAddress: '0x5aea5775959fbc2557cc8789bc1bf90a239d9a91',
+        muteRouterAddress: '0x8B791913eB07C32779a16750e3868aA8495F5964'
     }
 }
 export { web3Config }