Преглед на файлове

token封装完毕,上下文未封装

龚成明 преди 2 години
родител
ревизия
e77521b650
променени са 2 файла, в които са добавени 17 реда и са изтрити 3 реда
  1. 12 0
      src/libs/token.js
  2. 5 3
      src/libs/web3/simple-ierc20.js

+ 12 - 0
src/libs/token.js

@@ -0,0 +1,12 @@
+module.exports = class Token {
+  exchange = {}
+  ierc20 = {}
+
+  constructor(exchangeSymbol, exchangeLotSize, exchangePair, ierc20Decimals) {
+    this.exchange.symbol = exchangeSymbol
+    this.exchange.lotSize = exchangeLotSize
+    this.exchange.pair = exchangePair
+
+    this.ierc20.decimals = ierc20Decimals
+  }
+}

+ 5 - 3
src/libs/web3/simple-ierc20.js

@@ -2,6 +2,7 @@ const SimpleWeb3 = require('./simple-web3')
 const Config = require('../../config/config')
 const BinanceSpot = require('../binance/binance-spot')
 const BinanceKit = require('../binance/binance-kit')
+const Token = require('../token')
 
 class IERC20 {}
 
@@ -23,12 +24,13 @@ IERC20.initTokenByHash = async function (tokenHash, lotSizeFilterMap) {
   IERC20.contractMap[tokenHash] = new SimpleWeb3.web3.eth.Contract(Config.BASE_ABI, tokenHash)
 
   // 代币初始化
-  const tokenDecimals = await IERC20.getDecimals(tokenHash)
+  const ierc20Decimals = await IERC20.getDecimals(tokenHash)
   const exchangeSymbol = Config.tokenMap[tokenHash]
   const exchangePair = `${exchangeSymbol}${Config.baseToken.symbol}`
-  const lotSize = lotSizeFilterMap[exchangePair]
+  const exchangeLotSize = lotSizeFilterMap[exchangePair]
 
-  IERC20.tokenMap[tokenHash] = { decimals: tokenDecimals, symbol: exchangeSymbol, pair: exchangePair, lotSize: lotSize }
+  // TODO 将tokenMap放到上下文中
+  IERC20.tokenMap[tokenHash] = new Token(exchangeSymbol, exchangeLotSize, exchangePair, ierc20Decimals)
 }
 
 IERC20.getTokenName = async function (tokenHash) {