token.js 1.1 KB

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