|
|
@@ -1,48 +0,0 @@
|
|
|
-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 {}
|
|
|
-
|
|
|
-IERC20.batchInit = async function (ierc20TokenAddressList) {
|
|
|
- IERC20.contractMap = {}
|
|
|
- IERC20.tokenMap = {}
|
|
|
-
|
|
|
- const pairs = Object.values(Config.tokenMap).map(coin => `${coin}${Config.baseToken.symbol}` )
|
|
|
- const exchangeInfo = await BinanceSpot.exchangeInfo(pairs)
|
|
|
- const lotSizeFilterMap = BinanceKit.parseLotSizeFilterMap(exchangeInfo.symbols)
|
|
|
-
|
|
|
- for (const tokenHash of ierc20TokenAddressList) {
|
|
|
- await IERC20.initTokenByHash(tokenHash, lotSizeFilterMap)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-IERC20.initTokenByHash = async function (tokenHash, lotSizeFilterMap) {
|
|
|
- // 合约初始化
|
|
|
- IERC20.contractMap[tokenHash] = new SimpleWeb3.web3.eth.Contract(Config.BASE_ABI, tokenHash)
|
|
|
-
|
|
|
- // 代币初始化
|
|
|
- const ierc20Decimals = await IERC20.getDecimals(tokenHash)
|
|
|
- const exchangeSymbol = Config.tokenMap[tokenHash]
|
|
|
- const exchangePair = `${exchangeSymbol}${Config.baseToken.symbol}`
|
|
|
- const exchangeLotSize = lotSizeFilterMap[exchangePair]
|
|
|
-
|
|
|
- // TODO 将tokenMap放到上下文中
|
|
|
- IERC20.tokenMap[tokenHash] = new Token(exchangeSymbol, exchangeLotSize, exchangePair, ierc20Decimals)
|
|
|
-}
|
|
|
-
|
|
|
-IERC20.getTokenName = async function (tokenHash) {
|
|
|
- return await IERC20.contractMap[tokenHash].methods.name().call()
|
|
|
-}
|
|
|
-
|
|
|
-IERC20.getTokenSymbol = async function (tokenHash) {
|
|
|
- return await IERC20.contractMap[tokenHash].methods.symbol().call()
|
|
|
-}
|
|
|
-
|
|
|
-IERC20.getDecimals = async function (tokenHash) {
|
|
|
- return await IERC20.contractMap[tokenHash].methods.decimals().call()
|
|
|
-}
|
|
|
-
|
|
|
-module.exports = IERC20
|