token.js 1.4 KB

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