gateway icon indicating copy to clipboard operation
gateway copied to clipboard

The this.ethereum of uniswapLP is not initialized.

Open johna1203 opened this issue 1 year ago • 10 comments

When I use uniswapLP in a script, this.ethereum.storedTokenList is always empty. I researched the reason and found a possibility of a bug.

It appears that this.ethereum.init() is not being called, meaning it is not being initialized. This prevents it from loading tokens.

I changed 3 lines in uniswap.lp.helper.ts and it worked for me.

Steps To Reproduce

1, create a Script with markets = {"uniswapLP_polygon_mainnet": "XXXX-XXX"} 2, then, call the await self.connectors["uniswapLP_polygon_mainnet"].get_price(trading_pair, fee_tier)

Screenshots

uniswap.lp.helper.ts

  public getTokenByAddress(address: string): Token {
    console.log('getTokenByAddress', {
      'this.tokenList': this.tokenList,
    });

    return this.tokenList[getAddress(address)];
  }

  public async init() {
    if (this._chain == 'ethereum' && !this.ethereum.ready())
      throw new InitializationError(
        SERVICE_UNITIALIZED_ERROR_MESSAGE('ETH'),
        SERVICE_UNITIALIZED_ERROR_CODE
      );
    for (const token of this.ethereum.storedTokenList) {
      this.tokenList[token.address] = new Token(
        this.chainId,
        token.address,
        token.decimals,
        token.symbol,
        token.name
      );
    }
    this._ready = true;
  }

image

Release version { "name": "hummingbot-gateway", "version": "1.21.0", }

uniswap.lp.helper.ts

Here is a solution that is working for me. I am calling await this.ethereum.init(); if ethereum is not ready.

  public async init() {
    if (!this.ethereum.ready()) {
      await this.ethereum.init();
    }

    if (this._chain == 'ethereum' && !this.ethereum.ready())
      throw new InitializationError(
        SERVICE_UNITIALIZED_ERROR_MESSAGE('ETH'),
        SERVICE_UNITIALIZED_ERROR_CODE
      );
    for (const token of this.ethereum.storedTokenList) {
      this.tokenList[token.address] = new Token(
        this.chainId,
        token.address,
        token.decimals,
        token.symbol,
        token.name
      );
    }
    this._ready = true;
  }

Optional: your discord username:johna1203

johna1203 avatar Nov 07 '23 17:11 johna1203