|
@@ -1,14 +1,34 @@
|
|
|
const SimpleWeb3 = require('./simple-web3')
|
|
const SimpleWeb3 = require('./simple-web3')
|
|
|
const Config = require('../../config/config')
|
|
const Config = require('../../config/config')
|
|
|
|
|
+const BinanceSpot = require('../binance/binance-spot')
|
|
|
|
|
+const BinanceKit = require('../binance/binance-kit')
|
|
|
|
|
|
|
|
class IERC20 {}
|
|
class IERC20 {}
|
|
|
|
|
|
|
|
-IERC20.batchInit = function (ierc20TokenAddressList) {
|
|
|
|
|
|
|
+IERC20.batchInit = async function (ierc20TokenAddressList) {
|
|
|
IERC20.contractMap = {}
|
|
IERC20.contractMap = {}
|
|
|
|
|
+ IERC20.tokenMap = {}
|
|
|
|
|
|
|
|
- ierc20TokenAddressList.forEach(function (tokenHash) {
|
|
|
|
|
- IERC20.contractMap[tokenHash] = new SimpleWeb3.web3.eth.Contract(Config.BASE_ABI, tokenHash)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ 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 tokenDecimals = await IERC20.getDecimals(tokenHash)
|
|
|
|
|
+ const exchangeSymbol = Config.tokenMap[tokenHash]
|
|
|
|
|
+ const exchangePair = `${exchangeSymbol}${Config.baseToken.symbol}`
|
|
|
|
|
+ const lotSize = lotSizeFilterMap[exchangePair]
|
|
|
|
|
+
|
|
|
|
|
+ IERC20.tokenMap[tokenHash] = { decimals: tokenDecimals, symbol: exchangeSymbol, pair: exchangePair, lotSize: lotSize }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
IERC20.getTokenName = async function (tokenHash) {
|
|
IERC20.getTokenName = async function (tokenHash) {
|
|
@@ -19,4 +39,8 @@ IERC20.getTokenSymbol = async function (tokenHash) {
|
|
|
return await IERC20.contractMap[tokenHash].methods.symbol().call()
|
|
return await IERC20.contractMap[tokenHash].methods.symbol().call()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+IERC20.getDecimals = async function (tokenHash) {
|
|
|
|
|
+ return await IERC20.contractMap[tokenHash].methods.decimals().call()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
module.exports = IERC20
|
|
module.exports = IERC20
|