| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- const {web3} = require("hardhat");
- const ierc20abi = require("../../abi/IERC20_ABI.json");
- module.exports = class TokenLib {
- async handleToken(pool, zero) {
- const token = {
- 'address': zero ? pool.token0 : pool.token1,
- 'symbol': zero ? pool.symbol0 : pool.symbol1,
- 'decimals': zero ? pool.decimals0 : pool.decimals1,
- 'name': 'xxxxxxxx'
- }
- let tokenObj = this.tokenInstance[token.address]
- if (!tokenObj) {
- tokenObj = new web3.eth.Contract(ierc20abi, token.address)
- this.tokenInstance[token.address] = tokenObj
- }
- token.name = await tokenObj.methods.name().call()
- token.name = token.name.replace(/[^A-Za-z0-9 ]+/g, '').substring(0, 37)
- return token
- }
- async saveToken(lp, type = 'token') {
- try {
- const token = await this.handleToken(lp, true)
- // token的hash不同时为lp的情况才更新
- if (!this.lpInstance[token.address.toLowerCase()]) {
- await history.appendOrUpdate(type, token.address, token)
- }
- } catch (e) {
- }
- try {
- const token = await this.handleToken(lp, false)
- // token的hash不同时为lp的情况才更新
- if (!this.lpInstance[token.address.toLowerCase()]) {
- await history.appendOrUpdate(type, token.address, token)
- }
- } catch (e) {
- }
- }
- }
|