Ver código fonte

代码结构再整理

龚成明 2 anos atrás
pai
commit
d7a309f364

+ 0 - 3
libs/binance/binance-spot.js

@@ -2,9 +2,6 @@ const BinanceKit = require('./binance-kit')
 const HttpKit = require('../../kit/http-kit')
 const TimeKit = require("../../kit/time-kit");
 const HTTPRequest = require('request')
-const PrivateConfig = require("../../PrivateConfig");
-const NumKit = require("../../kit/num-kit");
-const Config = require("../../config/config");
 const assert = require("assert");
 
 const isDev = process.env.USER === 'skyfffire'

+ 4 - 5
libs/binance/test/binance-spot-test.js

@@ -1,22 +1,21 @@
 const logger = require('../../../kit/logger-kit').getLogger('binance-spot-test')
 const BinanceSpot = require('../binance-spot')
 const BinanceKit = require('../binance-kit')
-const Config = require('../../../config/config')
-const PrivateConfig = require('../../../PrivateConfig')
 const assert = require("assert");
 
 describe('binance-spot-test', () => {
   const context = {}
-  context.binanceSpot = new BinanceSpot(PrivateConfig.binanceAPIKey, PrivateConfig.binanceSecretKey)
-
   const binanceSpot = context.binanceSpot
+  const config = context.config
+
+  context.binanceSpot = new BinanceSpot(config.binanceAPIKey, config.binanceSecretKey)
 
   it('real price test', async () => {
     logger.info(await BinanceSpot.realPrice())
   })
 
   it('exchange info test', async () => {
-    const pairs = Object.values(PrivateConfig.tokenMapping).map(coin => `${coin}${Config.baseIerc20Token.symbol}` )
+    const pairs = Object.values(config.tokenMapping).map(coin => `${coin}${config.baseIerc20Token.symbol}` )
     const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
 
     assert.notEqual(exchangeInfo.symbols, undefined, 'exchangeInfo获取失败,请重试。')

+ 0 - 1
libs/one-task.js

@@ -1,5 +1,4 @@
 const OneTask = require('./task')
-const Context = require("./context");
 const BinanceSpot = require("./binance/binance-spot");
 const BinanceKit = require("./binance/binance-kit");
 const IERC20 = require("./web3/ierc20-token");

+ 4 - 4
libs/token.js

@@ -1,5 +1,3 @@
-const Config = require("../config/config");
-const PrivateConfig = require("../PrivateConfig")
 const IERC20 = require("./web3/ierc20-token");
 
 module.exports = class Token {
@@ -16,10 +14,12 @@ module.exports = class Token {
   }
 
   static async init(context, tokenHash, priceTickFilterMap, lotSizeFilterMap) {
+    const config = context.config
+
     // token初始化
     const ierc20Decimals = parseInt(await IERC20.getDecimals(tokenHash))
-    const exchangeSymbol = PrivateConfig.tokenMapping[tokenHash]
-    const exchangePair = `${exchangeSymbol}${Config.baseIerc20Token.symbol}`
+    const exchangeSymbol = config.tokenMapping[tokenHash]
+    const exchangePair = `${exchangeSymbol}${config.baseIerc20Token.symbol}`
     const exchangePriceTick = priceTickFilterMap[exchangePair]
     const exchangeLotSize = lotSizeFilterMap[exchangePair]
 

+ 80 - 80
libs/web3/1inch.js

@@ -1,13 +1,12 @@
 const HttpKit = require('../../kit/http-kit.js')
 const Config = require('../../config/config.js')
-const PrivateConfig = require('../../PrivateConfig.js')
-const SimpleWeb3 = require("./simple-web3");
+// const SimpleWeb3 = require("./simple-web3");
 
 const chainID = 56
 
 class OneInch {}
 
-OneInch.price = async function(fromTokenAddress, toTokenAddress, amount=Config.baseTokenAmount, fromTokenDecimals=Config.baseIerc20Token.decimals) {
+OneInch.price = async function(fromTokenAddress, toTokenAddress, amount, fromTokenDecimals) {
   fromTokenAddress = fromTokenAddress.toLowerCase()
   toTokenAddress = toTokenAddress.toLowerCase()
   amount = amount * (10 ** fromTokenDecimals)
@@ -31,7 +30,8 @@ OneInch.price = async function(fromTokenAddress, toTokenAddress, amount=Config.b
   return rst.price
 }
 
-OneInch.buildSwapTx = async function(fromTokenAddress = '0xe9e7cea3dedca5984780bafc599bd69add087d56', toTokenAddress = '0x111111111117dc0aa78b770fa6a738034120c302', fromTokenDecimals = 18, amount = 100, gas = Config.estimatedGas, fromAddress = PrivateConfig.address, slippage = 1) {
+OneInch.buildSwapTx = async function(fromTokenAddress, toTokenAddress, fromTokenDecimals, amount, fromAddress,
+                                     gas = Config.estimatedGas, slippage = 1) {
   amount = amount * (10 ** fromTokenDecimals)
   const url = `https://api.1inch.exchange/v3.0/${chainID}/swap?fromTokenAddress=${fromTokenAddress}&toTokenAddress=${toTokenAddress}`
       + `&amount=${amount}&fromAddress=${fromAddress}&slippage=${slippage}`
@@ -48,81 +48,81 @@ OneInch.buildSwapTx = async function(fromTokenAddress = '0xe9e7cea3dedca5984780b
   return rst
 }
 
-OneInch.swap = async function(txObject) {
-  const txCount = await SimpleWeb3.web3.eth.getTransactionCount(PrivateConfig.address)
-  txObject.nonce = SimpleWeb3.web3.utils.toHex(txCount)
-  // txObject.gasPrice = SimpleWeb3.web3.utils.toHex(txObject.gasPrice)
-  txObject.gasPrice = '0x165a0bc00'
-  txObject.gas = SimpleWeb3.web3.utils.toHex(txObject.gas)
-  txObject.value = SimpleWeb3.web3.utils.toHex(txObject.value)
-
-  await SimpleWeb3.sendTransaction(txObject)
-}
-
-OneInch.Start = async function(toToken) {
-  while (true) {
-    toToken.alive = true
-
-    // 如果BNB连续变化maxRefreshBNBTimes次,则1INCH或其他交易所可能已经出bug。
-    if (Config.refreshBNBTimes >= Config.maxRefreshBNBTimes) {
-      console.log(`机器人判定交易所可能出了bug,失败次数:${Config.refreshBNBTimes},为保护BNB,已停止交易。`)
-      break
-    }
-
-    try {
-      const tokenSymbol = toToken.symbol
-      const baseToken = Config.baseToken
-      if (!baseToken.balance) {
-        await MyKit.sleep(1000)
-
-        continue
-      }
-      const binancePairSymbol = tokenSymbol + baseToken.symbol
-      const amount = Config.baseTokenAmount < baseToken.balance ? Config.baseTokenAmount : baseToken.balance
-      const OneInchPrice = await OneInch.price(baseToken.contract, baseToken.decimals, amount, toToken.contract)
-      const binancePrice = await bs.price(binancePairSymbol)
-      let distance = MyKit._N(100 * ((binancePrice / OneInchPrice) - 1.001), 4)
-      let profit = MyKit._N(amount * distance / 100 - Config.charge, 4)
-      let time = MyKit.getTimeByMillisecond(new Date().getTime())
-
-      // debug
-      if (Config.debug && profit > 0) {
-        console.log(`[${time}, ${binancePairSymbol}] D价格: ${OneInchPrice},C价格: ${binancePrice},利润:${profit}。`)
-      }
-
-      // 一次判断
-      if (profit > Config.profitLimit) {
-        // 二次判断,并获取交易tx
-        const swapRST = await OneInch.swap(baseToken.contract, toToken.contract, baseToken.decimals, amount)
-        if (!swapRST) {
-          continue
-        }
-      
-        distance = MyKit._N(100 * ((binancePrice / swapRST.price) - 1.001), 4)
-        profit = MyKit._N(amount * distance / 100 - Config.charge, 4)
-        if (!baseToken.isSwap && profit > Config.profitLimit) {
-          time = MyKit.getTimeByMillisecond(new Date().getTime())
-
-          // gas容错
-          swapRST.tx.gas = parseInt((parseInt(swapRST.tx.gas) * 1.5)) + ''
-
-          // 如果利润大于5%,手续费*2抢单
-          if (distance > 20) {
-            console.log('[利润大于20%]手续费*1.5执行抢单逻辑.')
-            swapRST.tx.gasPrice = parseInt((parseInt(swapRST.tx.gasPrice) * 1.5)) + ''
-          }
-
-          console.log(`[${time}, ${tokenSymbol}]判定通过, 利润率:${distance}%, 预估利润:${profit}${baseToken.symbol}, 目标利润:${Config.profitLimit}${baseToken.symbol}.\n`)
-          console.log(`DEFI价格: ${swapRST.price}, CEFI价格: ${binancePrice}\n\n`)
-          await wallet.transferByTX1Inch(swapRST.tx)
-        }
-      }
-
-      await MyKit.sleep(5000)
-    } catch (e) {
-      console.log(e)
-    }
-  }
-}
+// OneInch.swap = async function(txObject) {
+//   const txCount = await SimpleWeb3.web3.eth.getTransactionCount(PrivateConfig.address)
+//   txObject.nonce = SimpleWeb3.web3.utils.toHex(txCount)
+//   // txObject.gasPrice = SimpleWeb3.web3.utils.toHex(txObject.gasPrice)
+//   txObject.gasPrice = '0x165a0bc00'
+//   txObject.gas = SimpleWeb3.web3.utils.toHex(txObject.gas)
+//   txObject.value = SimpleWeb3.web3.utils.toHex(txObject.value)
+//
+//   await SimpleWeb3.sendTransaction(txObject)
+// }
+//
+// OneInch.Start = async function(toToken) {
+//   while (true) {
+//     toToken.alive = true
+//
+//     // 如果BNB连续变化maxRefreshBNBTimes次,则1INCH或其他交易所可能已经出bug。
+//     if (Config.refreshBNBTimes >= Config.maxRefreshBNBTimes) {
+//       console.log(`机器人判定交易所可能出了bug,失败次数:${Config.refreshBNBTimes},为保护BNB,已停止交易。`)
+//       break
+//     }
+//
+//     try {
+//       const tokenSymbol = toToken.symbol
+//       const baseToken = Config.baseToken
+//       if (!baseToken.balance) {
+//         await MyKit.sleep(1000)
+//
+//         continue
+//       }
+//       const binancePairSymbol = tokenSymbol + baseToken.symbol
+//       const amount = Config.baseTokenAmount < baseToken.balance ? Config.baseTokenAmount : baseToken.balance
+//       const OneInchPrice = await OneInch.price(baseToken.contract, baseToken.decimals, amount, toToken.contract)
+//       const binancePrice = await bs.price(binancePairSymbol)
+//       let distance = MyKit._N(100 * ((binancePrice / OneInchPrice) - 1.001), 4)
+//       let profit = MyKit._N(amount * distance / 100 - Config.charge, 4)
+//       let time = MyKit.getTimeByMillisecond(new Date().getTime())
+//
+//       // debug
+//       if (Config.debug && profit > 0) {
+//         console.log(`[${time}, ${binancePairSymbol}] D价格: ${OneInchPrice},C价格: ${binancePrice},利润:${profit}。`)
+//       }
+//
+//       // 一次判断
+//       if (profit > Config.profitLimit) {
+//         // 二次判断,并获取交易tx
+//         const swapRST = await OneInch.swap(baseToken.contract, toToken.contract, baseToken.decimals, amount)
+//         if (!swapRST) {
+//           continue
+//         }
+//
+//         distance = MyKit._N(100 * ((binancePrice / swapRST.price) - 1.001), 4)
+//         profit = MyKit._N(amount * distance / 100 - Config.charge, 4)
+//         if (!baseToken.isSwap && profit > Config.profitLimit) {
+//           time = MyKit.getTimeByMillisecond(new Date().getTime())
+//
+//           // gas容错
+//           swapRST.tx.gas = parseInt((parseInt(swapRST.tx.gas) * 1.5)) + ''
+//
+//           // 如果利润大于5%,手续费*2抢单
+//           if (distance > 20) {
+//             console.log('[利润大于20%]手续费*1.5执行抢单逻辑.')
+//             swapRST.tx.gasPrice = parseInt((parseInt(swapRST.tx.gasPrice) * 1.5)) + ''
+//           }
+//
+//           console.log(`[${time}, ${tokenSymbol}]判定通过, 利润率:${distance}%, 预估利润:${profit}${baseToken.symbol}, 目标利润:${Config.profitLimit}${baseToken.symbol}.\n`)
+//           console.log(`DEFI价格: ${swapRST.price}, CEFI价格: ${binancePrice}\n\n`)
+//           await wallet.transferByTX1Inch(swapRST.tx)
+//         }
+//       }
+//
+//       await MyKit.sleep(5000)
+//     } catch (e) {
+//       console.log(e)
+//     }
+//   }
+// }
 
 module.exports = OneInch

+ 0 - 138
libs/web3/dodo.js

@@ -1,138 +0,0 @@
-const HttpKit = require('../../kit/http-kit.js')
-const Config = require('../../config/config.js')
-const PrivateConfig = require('../../PrivateConfig.js')
-const SimpleWeb3 = require("./simple-web3");
-
-const chainID = 56
-const rpc = 'https://bsc-dataseed1.binance.org'
-
-class DoDo {}
-
-DoDo.price = async function(sellToken = '0xe9e7cea3dedca5984780bafc599bd69add087d56',
-                            sellTokenDecimals = 18,
-                            sellAmount = 100,
-                            buyToken = '0xba2ae424d960c26247dd6c32edc70b295c744c43',
-                            slippagePercentage = 0.03,
-                            affiliateAddress = '0x221d5c4993297Fd95fA17743b9297E2e49FCe9D2') {
-  sellAmount = sellAmount * (10 ** sellTokenDecimals)
-  const url = `https://bsc.api.0x.org/swap/v1/quote?sellToken=${sellToken}&sellAmount=${sellAmount}&buyToken=${buyToken}`
-      + `&slippagePercentage=${slippagePercentage}&affiliateAddress=${affiliateAddress}`
-  const { data: rst } = await HttpKit.get(url)
-
-  if (!rst || !rst.price) {
-    return rst
-  }
-
-  if (sellToken === '0xe9e7cea3dedca5984780bafc599bd69add087d56') {
-    return 1 / parseFloat(rst.price)
-  } else {
-    parseFloat(rst.price)
-  }
-}
-
-DoDo.buildSwapTx = async function(fromTokenAddress = '0xe9e7cea3dedca5984780bafc599bd69add087d56',
-                                  fromTokenDecimals = 18,
-                                  toTokenAddress = '0x111111111117dc0aa78b770fa6a738034120c302',
-                                  toTokenDecimals = 18,
-                                  amount = 100,
-                                  userAddr = PrivateConfig.address,
-                                  slippage = 1) {
-  amount = amount * (10 ** fromTokenDecimals)
-  const url = `https://dodo-route.dodoex.io/dodoapi/getdodoroute?fromTokenAddress=${fromTokenAddress}&fromTokenDecimals=${fromTokenDecimals}`
-      + `&toTokenAddress=${toTokenAddress}&toTokenDecimals=${toTokenDecimals}&fromAmount=${amount}&userAddr=${userAddr}`
-      + `&slippage=${slippage}&chainId=${chainID}&rpc=${rpc}`
-  const { data: rst } = await HttpKit.get(url, {
-    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4464.0 Safari/537.36 Edg/91.0.852.0'
-  })
-  return rst
-}
-
-DoDo.swap = async function(txObject) {
-  const txCount = await SimpleWeb3.web3.eth.getTransactionCount(PrivateConfig.address)
-  txObject.nonce = SimpleWeb3.web3.utils.toHex(txCount)
-  txObject.gasPrice = SimpleWeb3.web3.utils.toHex(txObject.gasPrice)
-  txObject.gas = SimpleWeb3.web3.utils.toHex(txObject.gas)
-  txObject.gasLimit = SimpleWeb3.web3.utils.toHex(txObject.gasLimit)
-
-  await SimpleWeb3.sendTransaction(txObject)
-}
-
-DoDo.Start = async function(toToken) {
-  while (true) {
-    // 如果BNB连续变化maxRefreshBNBTimes次,则1INCH或其他交易所可能已经出bug。
-    if (Config.refreshBNBTimes >= Config.maxRefreshBNBTimes) {
-      console.log(`机器人判定交易所可能出了bug,失败次数:${Config.refreshBNBTimes},为保护BNB,已停止交易。`)
-      break
-    }
-
-    try {
-      const tokenSymbol = toToken.symbol
-      const baseToken = Config.baseToken
-      if (!baseToken.balance) {
-        await MyKit.sleep(1000)
-  
-        continue
-      }
-      const binancePairSymbol = tokenSymbol + baseToken.symbol
-      const amount = Config.baseTokenAmount < baseToken.balance ? Config.baseTokenAmount : baseToken.balance
-      const profitLimit = toToken.profitLimit ? toToken.profitLimit : Config.profitLimit
-      const binancePrice = await bs.price(binancePairSymbol)
-  
-      // 一次判断
-      let time = MyKit.getTimeByMillisecond(new Date().getTime())
-
-      // 直接判断并抢单
-      const DoDoSwapRst = await DoDo.swap(baseToken.contract, baseToken.decimals, toToken.contract, toToken.decimals, amount)
-      // 对询价结果容错
-      if (!DoDoSwapRst || !DoDoSwapRst.data) {
-        continue
-      }
-
-      // 构建交易包
-      const swapRST = DoDoSwapRst.data
-      swapRST.price = MyKit._N(swapRST.resPricePerToToken, 6)
-      swapRST.tx = {
-        gasPrice: 7 * (10 ** 9),
-        gas: '500000',
-        from: PrivateConfig.address,
-        to: swapRST.to,
-        data: swapRST.data
-      }
-
-      // 间距百分比与预估利润
-      distance = MyKit._N(100 * ((binancePrice / swapRST.price - 1.001)), 4)
-      profit = MyKit._N(amount * distance / 100 - Config.charge, 4)
-
-      // debug
-      if (Config.debug) {
-        console.log(`[${time}, ${binancePairSymbol}] D价格: ${swapRST.price},C价格: ${binancePrice},利润:${profit},源:${swapRST.useSource}。`)
-      }
-
-      // 屏蔽询价源
-      if (Config.limitSources.indexOf(swapRST.useSource) !== -1 || !swapRST.useSource) {
-        continue
-      }
-
-      if (swapRST.price && !baseToken.isSwap && profit > Config.profitLimit) {
-        if (distance > 20) {
-          console.log('[利润大于20%]手续费*1.5执行抢单逻辑.')
-          swapRST.tx.gasPrice = parseInt((parseInt(swapRST.tx.gasPrice) * 1.5)) + ''
-        }
-
-        console.log(`[${time}, ${tokenSymbol}]判定通过, 利润率:${distance}%, 预估利润:${profit}${baseToken.symbol}, 目标利润:${Config.profitLimit}${baseToken.symbol}.\n`)
-        console.log(`DEFI价格: ${swapRST.price}, CEFI价格: ${binancePrice}, 报价源: ${swapRST.useSource}\n\n`)
-        await wallet.transferByTXDoDo(swapRST.tx)
-      } 
-      // else if (profit > 0) {
-      //   console.log(`[${time}, ${tokenSymbol}]二次判定不通过, 利润率:${distance}%, 预估利润:${profit}${baseToken.symbol}, 目标利润:${profitLimit}${baseToken.symbol}.\n`)
-      //   console.log(`DEFI价格: ${swapRST.price}, CEFI价格: ${binancePrice}, 报价源: ${swapRST.useSource}\n\n`)
-      // }
-    } catch (e) {
-      console.log(e)
-    }
-
-    await MyKit.sleep(Config.delay)
-  }
-}
-
-module.exports = DoDo

+ 3 - 2
libs/web3/ierc20-token.js

@@ -1,5 +1,4 @@
 const SimpleWeb3 = require('./simple-web3')
-const Config = require('../../config/config')
 
 class IERC20 {}
 
@@ -13,8 +12,10 @@ IERC20.batchInit = async function (context, ierc20TokenAddressList) {
 }
 
 IERC20.initTokenByHash = async function (context, tokenHash) {
+  const config = context.config
+
   // 合约初始化
-  IERC20.contractMap[tokenHash] = new SimpleWeb3.web3.eth.Contract(Config.BASE_ABI, tokenHash)
+  IERC20.contractMap[tokenHash] = new SimpleWeb3.web3.eth.Contract(config.BASE_ABI, tokenHash)
 }
 
 IERC20.getTokenName = async function (tokenHash) {

+ 0 - 45
libs/web3/pancake.js

@@ -1,45 +0,0 @@
-const HttpKit = require('./kit/HttpKit')
-
-class Pancake {}
-
-Pancake.pairs = async function () {
-  const url = 'https://api.pancakeswap.info/api/v2/pairs'
-  const { data: rst } = await HttpKit.get(url)
-  return rst
-}
-
-Pancake.tokenList = async function () {
-  const url = 'https://api.pancakeswap.info/api/v2/tokens'
-  const { data: rst } = await HttpKit.get(url)
-  return rst
-}
-
-Pancake.tokenInfo = async function (symbol = 'WBNB', tokens) {
-  if (!tokens) {
-    tokens = await Pancake.tokenList()
-  }
-
-  const { data: priceList } = tokens
-
-  for (const key in priceList) {
-    const token = priceList[key]
-
-    if (symbol === token.symbol) {
-      return token
-    }
-  }
-}
-
-Pancake.priceByBNB = async function (symbol, list) {
-  const token = await Pancake.tokenInfo(symbol, list)
-
-  return token ? token.price_BNB : 0
-}
-
-Pancake.price = async function (symbol, list) {
-  const token = await Pancake.tokenInfo(symbol, list)
-
-  return token ? token.price : 0
-}
-
-module.exports = Pancake

+ 100 - 103
libs/web3/simple-web3.js

@@ -1,8 +1,5 @@
 const Config = require('../../config/config.js')
-const PrivateConfig = require('../../PrivateConfig.js')
-const TimeKit = require('../../kit/time-kit')
 const Web3 = require('web3')
-const Tx = require('ethereumjs-tx')
 
 
 class SimpleWeb3 {}
@@ -23,106 +20,106 @@ SimpleWeb3.getRealBalance = async function(address) {
   return SimpleWeb3.web3.utils.fromWei(wei, 'ether')
 }
 
-SimpleWeb3.sendTransaction = async function(txObject) {
-  const tx = new Tx(txObject)
-  tx.sign(Buffer.from(PrivateConfig.privateKey, 'hex'))
-  const serializedTx = tx.serialize()
-  const raw = '0x' + serializedTx.toString('hex')
-
-  Config.baseToken.isSwap = true
-  SimpleWeb3.web3.eth.sendSignedTransaction(raw, async (err, txHash) => {
-    if (!txHash) {
-      console.log(err.toString())
-      txObject.data = undefined
-      console.log(txObject)
-
-      Config.baseToken.isSwap = false
-    } else {
-      const time = TimeKit.getTimeByMillisecond(new Date().getTime())
-      txObject.data = undefined
-      console.log(`[发起新的交易]tx: ${JSON.stringify(txObject)}`)
-      console.log(`交易时间: ${time}, 交易回执: ${txHash}\n`)
-
-      await TimeKit.sleep(10 * 1000)
-      Config.baseToken.isSwap = false
-    }
-  })
-}
-
-SimpleWeb3.transferTokenByAddress = async function(amount, to='0xA9D841B81da81c5B94fCe514211e3292FE3f882B', token=Config.baseToken) {
-    const balance = amount
-    const BN = SimpleWeb3.web3.utils.BN
-
-    const decimals = token.decimals
-
-    if (decimals > 10) {
-      const balanceBN = new BN(parseInt(balance * (10 ** 10)))
-      const additionalBN = new BN(10 ** (decimals - 10))
-  
-      amount = balanceBN.mul(additionalBN).toString()
-    } else {
-      amount = balance * (10 ** decimals) + ''
-    }
-    amount = amount.split('.')[0]
-
-    const txCount = await SimpleWeb3.web3.eth.getTransactionCount(PrivateConfig.address)
-
-    const txObject = {
-      from: PrivateConfig.address,
-      nonce: SimpleWeb3.web3.utils.toHex(txCount),
-      gasPrice: SimpleWeb3.web3.utils.toHex(SimpleWeb3.web3.utils.toWei('7', 'gwei')),
-      gasLimit: SimpleWeb3.web3.utils.toHex(70000),
-      to: token.contract,
-      value: '0x0',
-      data: token.contractModel.methods.transfer(to, amount).encodeABI()
-    }
-
-    const tx = new Tx(txObject)
-    tx.sign(Buffer.from(PrivateConfig.privateKey, 'hex'))
-    const serializedTx = tx.serialize()
-    const raw = '0x' + serializedTx.toString('hex')
-
-    token.isTransfer = true
-    SimpleWeb3.web3.eth.sendSignedTransaction(raw, async (err, txHash) => {
-      if (!txHash) {
-        console.log(err)
-
-        token.isTransfer = false
-      } else {
-        const time = TimeKit.getTimeByMillisecond(new Date().getTime())
-        console.log(`[${time} 到交易所的转账]${token.symbol} 数额: ${balance}, 回执: ${txHash}\n`)
-
-        await TimeKit.sleep(20 * 1000)
-        token.isTransfer = false
-      }
-    })
-  }
-
-SimpleWeb3.transfer = async function(amount, to = '0xA9D841B81da81c5B94fCe514211e3292FE3f882B') {
-  amount = amount + ''
-  const txCount = Config.nonce
-
-  const txObject = {
-    nonce: SimpleWeb3.web3.utils.toHex(txCount),
-    to: to,
-    value: SimpleWeb3.web3.utils.toHex(SimpleWeb3.web3.utils.toWei(amount, 'ether')),
-    gasLimit: SimpleWeb3.web3.utils.toHex(21000),
-    gasPrice: SimpleWeb3.web3.utils.toHex(SimpleWeb3.web3.utils.toWei('10', 'gwei'))
-  }
-
-  const tx = new Tx(txObject)
-  tx.sign(Buffer.from(PrivateConfig.privateKey, 'hex'))
-  const serializedTx = tx.serialize()
-  const raw = '0x' + serializedTx.toString('hex')
-
-  SimpleWeb3.web3.eth.sendSignedTransaction(raw, (err, txHash) => {
-    if (!txHash) {
-      console.log(err)
-    } else {
-      console.log('txHash:', txHash)
-    }
-  })
-}
+// SimpleWeb3.sendTransaction = async function(txObject) {
+//   const tx = new Tx(txObject)
+//   tx.sign(Buffer.from(PrivateConfig.privateKey, 'hex'))
+//   const serializedTx = tx.serialize()
+//   const raw = '0x' + serializedTx.toString('hex')
+//
+//   Config.baseIerc20Token.isSwap = true
+//   SimpleWeb3.web3.eth.sendSignedTransaction(raw, async (err, txHash) => {
+//     if (!txHash) {
+//       console.log(err.toString())
+//       txObject.data = undefined
+//       console.log(txObject)
+//
+//       Config.baseIerc20Token.isSwap = false
+//     } else {
+//       const time = TimeKit.getTimeByMillisecond(new Date().getTime())
+//       txObject.data = undefined
+//       console.log(`[发起新的交易]tx: ${JSON.stringify(txObject)}`)
+//       console.log(`交易时间: ${time}, 交易回执: ${txHash}\n`)
+//
+//       await TimeKit.sleep(10 * 1000)
+//       Config.baseIerc20Token.isSwap = false
+//     }
+//   })
+// }
+//
+// SimpleWeb3.transferTokenByAddress = async function(amount, to='0xA9D841B81da81c5B94fCe514211e3292FE3f882B', token=Config.baseToken) {
+//     const balance = amount
+//     const BN = SimpleWeb3.web3.utils.BN
+//
+//     const decimals = token.decimals
+//
+//     if (decimals > 10) {
+//       const balanceBN = new BN(parseInt(balance * (10 ** 10)))
+//       const additionalBN = new BN(10 ** (decimals - 10))
+//
+//       amount = balanceBN.mul(additionalBN).toString()
+//     } else {
+//       amount = balance * (10 ** decimals) + ''
+//     }
+//     amount = amount.split('.')[0]
+//
+//     const txCount = await SimpleWeb3.web3.eth.getTransactionCount(PrivateConfig.address)
+//
+//     const txObject = {
+//       from: PrivateConfig.address,
+//       nonce: SimpleWeb3.web3.utils.toHex(txCount),
+//       gasPrice: SimpleWeb3.web3.utils.toHex(SimpleWeb3.web3.utils.toWei('7', 'gwei')),
+//       gasLimit: SimpleWeb3.web3.utils.toHex(70000),
+//       to: token.contract,
+//       value: '0x0',
+//       data: token.contractModel.methods.transfer(to, amount).encodeABI()
+//     }
+//
+//     const tx = new Tx(txObject)
+//     tx.sign(Buffer.from(PrivateConfig.privateKey, 'hex'))
+//     const serializedTx = tx.serialize()
+//     const raw = '0x' + serializedTx.toString('hex')
+//
+//     token.isTransfer = true
+//     SimpleWeb3.web3.eth.sendSignedTransaction(raw, async (err, txHash) => {
+//       if (!txHash) {
+//         console.log(err)
+//
+//         token.isTransfer = false
+//       } else {
+//         const time = TimeKit.getTimeByMillisecond(new Date().getTime())
+//         console.log(`[${time} 到交易所的转账]${token.symbol} 数额: ${balance}, 回执: ${txHash}\n`)
+//
+//         await TimeKit.sleep(20 * 1000)
+//         token.isTransfer = false
+//       }
+//     })
+//   }
+//
+// SimpleWeb3.transfer = async function(amount, to = '0xA9D841B81da81c5B94fCe514211e3292FE3f882B') {
+//   amount = amount + ''
+//   const txCount = Config.nonce
+//
+//   const txObject = {
+//     nonce: SimpleWeb3.web3.utils.toHex(txCount),
+//     to: to,
+//     value: SimpleWeb3.web3.utils.toHex(SimpleWeb3.web3.utils.toWei(amount, 'ether')),
+//     gasLimit: SimpleWeb3.web3.utils.toHex(21000),
+//     gasPrice: SimpleWeb3.web3.utils.toHex(SimpleWeb3.web3.utils.toWei('10', 'gwei'))
+//   }
+//
+//   const tx = new Tx(txObject)
+//   tx.sign(Buffer.from(PrivateConfig.privateKey, 'hex'))
+//   const serializedTx = tx.serialize()
+//   const raw = '0x' + serializedTx.toString('hex')
+//
+//   SimpleWeb3.web3.eth.sendSignedTransaction(raw, (err, txHash) => {
+//     if (!txHash) {
+//       console.log(err)
+//     } else {
+//       console.log('txHash:', txHash)
+//     }
+//   })
+// }
 
 SimpleWeb3.init()
 

+ 2 - 2
scripts/one-pro.js

@@ -1,10 +1,10 @@
 const OneTask = require('../libs/one-task')
 const OneInch = require('../libs/web3/1inch')
-const BinanceSpot = require('../libs/binance/binance-spot')
+const BinanceSpot = require("../libs/binance/binance-spot");
+const BinanceKit = require("../libs/binance/binance-kit");
 const NumKit = require('../kit/num-kit')
 const TimeKit = require('../kit/time-kit')
 const TableKit = require('../kit/table-kit')
-const BinanceKit = require("../libs/binance/binance-kit");
 const Context = require("../libs/context")
 const assert = require("assert");