token.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const IERC20 = require("./web3/ierc20-token");
  2. module.exports = class Token {
  3. exchange = {}
  4. ierc20 = {}
  5. constructor(exchangeSymbol, exchangePriceTick, exchangeLotSize, exchangePair, ierc20Decimals) {
  6. this.exchange.symbol = exchangeSymbol
  7. this.exchange.priceTick = exchangePriceTick
  8. this.exchange.lotSize = exchangeLotSize
  9. this.exchange.pair = exchangePair
  10. this.ierc20.decimals = ierc20Decimals
  11. }
  12. static async init(context, tokenHash, priceTickFilterMap, lotSizeFilterMap) {
  13. const config = context.config
  14. // token初始化
  15. const ierc20Decimals = parseInt(await IERC20.getDecimals(tokenHash))
  16. const exchangeSymbol = config.tokenMapping[tokenHash]
  17. const exchangePair = `${exchangeSymbol}${config.baseIerc20Token.symbol}`
  18. const exchangePriceTick = priceTickFilterMap[exchangePair]
  19. const exchangeLotSize = lotSizeFilterMap[exchangePair]
  20. context.tokenMap[tokenHash] = new Token(exchangeSymbol, exchangePriceTick, exchangeLotSize, exchangePair, ierc20Decimals)
  21. }
  22. static async batchInit(context, ierc20TokenAddressList, priceTickFilterMap, lotSizeFilterMap) {
  23. context.tokenMap = {}
  24. for (const tokenHash of ierc20TokenAddressList) {
  25. // 初始化token
  26. await Token.init(context, tokenHash, priceTickFilterMap, lotSizeFilterMap)
  27. }
  28. }
  29. }