Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The this.ethereum of uniswapLP is not initialized. #228

Open
johna1203 opened this issue Nov 7, 2023 · 10 comments
Open

The this.ethereum of uniswapLP is not initialized. #228

johna1203 opened this issue Nov 7, 2023 · 10 comments
Labels
bug Something isn't working

Comments

@johna1203
Copy link

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 johna1203 added the bug Something isn't working label Nov 7, 2023
@johna1203
Copy link
Author

Hi,
The solution I wrote above is not correct. I am still researching to see if I can find the problem.

@johna1203
Copy link
Author

The problem is similar to this issue. It seems that the UniswapLPHelper is not creating the correct object when the chain is Polygon.
https://github.com/hummingbot/gateway/blob/main/src/connectors/uniswap/uniswap.ts#L61

my solution is check the chain and create a correct Object for this.ethereum

uniswap.lp.helper.ts

  constructor(chain: string, network: string) {
    if (chain === 'ethereum') {
      this.ethereum = Ethereum.getInstance(network);
    } else if (chain === 'polygon') {
      this.ethereum = Polygon.getInstance(network);
    } else {
      throw new Error('Chain not supported');
    }

@emusol
Copy link

emusol commented Nov 13, 2023

The problem is similar to this issue. It seems that the UniswapLPHelper is not creating the correct object when the chain is Polygon. https://github.com/hummingbot/gateway/blob/main/src/connectors/uniswap/uniswap.ts#L61

my solution is check the chain and create a correct Object for this.ethereum

uniswap.lp.helper.ts

  constructor(chain: string, network: string) {
    if (chain === 'ethereum') {
      this.ethereum = Ethereum.getInstance(network);
    } else if (chain === 'polygon') {
      this.ethereum = Polygon.getInstance(network);
    } else {
      throw new Error('Chain not supported');
    }

Hey, does the solution works for you?

@vic-en
Copy link
Collaborator

vic-en commented Nov 13, 2023

@johna1203 @emusol what chain and network are you trying to connect to?

@emusol
Copy link

emusol commented Nov 13, 2023

@johna1203 @emusol what chain and network are you trying to connect to?

hey the error is when I try to work with polygon, on arbitrum it work perfectly

@vic-en
Copy link
Collaborator

vic-en commented Nov 13, 2023

@emusol
I see that there has been some refactoring to some evm networks.

So reconnect to uniswapLP using ethereum as chain and polygon as network.

@emusol
Copy link

emusol commented Nov 14, 2023

image
Hey thats what I get when i try this way

@emusol I see that there has been some refactoring to some evm networks.

So reconnect to uniswapLP using ethereum as chain and polygon as network.

@johna1203
Copy link
Author

johna1203 commented Nov 16, 2023

@vic-en

@johna1203 @emusol what chain and network are you trying to connect to?

Sorry for the delay,
I was trying to connect to Polygon.

#228 (comment)

The code I wrote above worked, I had to add a check for Polygon.

@johna1203
Copy link
Author

image Hey thats what I get when i try this way

@emusol I see that there has been some refactoring to some evm networks.
So reconnect to uniswapLP using ethereum as chain and polygon as network.

This error does not happen to me. What version of the gateway are you using?

@johna1203 johna1203 reopened this Nov 16, 2023
@johna1203
Copy link
Author

image Hey thats what I get when i try this way

@emusol I see that there has been some refactoring to some evm networks.
So reconnect to uniswapLP using ethereum as chain and polygon as network.

This error does not happen to me. What version of the gateway are you using?

In fact, it is not an error... you are choosing the wrong network In the question "Which chain do you want uniswapLP...." you need to choose polygon instead of ethereum.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants