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

Feat / Add Uniswap on chains BSC, Avalanche, and Celo #342

Merged
merged 69 commits into from
Jul 31, 2024

Conversation

fengtality
Copy link
Sponsor Contributor

@fengtality fengtality commented Jul 25, 2024

Before submitting this PR, please make sure:

  • Your code builds clean without any errors or warnings
  • You are using approved title ("feat/", "fix/", "docs/", "refactor/")

A description of the changes proposed in the pull request:

  • Adds Uniswap support for Binance Smart Chain, Avalanche, and Celo, refactored from community PRs
  • Fixes tests

Tests performed by the developer:

Tips for QA testing:

@fengtality
Copy link
Sponsor Contributor Author

@nikspz Can you test executing a Uniswap swap on development branch on:

  • Polygon Mainnet
  • Ethereum Arbitrum
  • Ethereum Optimism

I think this swaps issue exists on other networks on development branch as well. Still investigating.

@nikspz
Copy link
Contributor

nikspz commented Jul 26, 2024

test executing a Uniswap swap on development branch on:

  • Polygon Mainnet
  • Ethereum Arbitrum
  • Ethereum Optimism

@fengtality

Development branch CLient + dev branch gateway:

(uniswap) Arbitrum:

  • amm/price: ok
  • amm/ trade: ok

(uniswap) Polygon:

  • amm/ trade: ok

(uniswap) Optimism

  • amm/ trade: ok

trades:
https://arbiscan.io/tx/0xdfca5bbceb780424e98462ae361ffaa5c2837de642843552d0f17ec20340be2e
https://optimistic.etherscan.io/tx/0xc35dcfe900d85a599685e9b04b67f921826aafd2f002266080a8ad049d9f0ba1
https://polygonscan.com/tx/0xc347c427eab9786b15955a1c2584acf5bc5d357ede3f2a437287ddcd90341b85

arbitrum

image
image

polygon

image

optimism

image

@fengtality
Copy link
Sponsor Contributor Author

The issue is that upgrading Uniswap swap order router above 3 breaks swaps on all Uniswap connectors.

However, not upgrading it results in the following error when fetching price on BSC:

"stack": "Error: No address for Uniswap Multicall Contract on chain id: 56\n    at new UniswapMulticallProvider (/Users/feng/gateway/node_modules/@uniswap/smart-order-router/build/main/providers/multicall-uniswap-provider.js:30:19)\n    at new AlphaRouter (/Users/feng/gateway/node_modules/@uniswap/smart-order-router/build/main/routers/alpha-router/alpha-router.js:47:97)\n    at new Uniswap (/Users/feng/gateway/dist/src/connectors/uniswap/uniswap.js:64:33)\n    at Uniswap.getInstance (/Users/feng/gateway/dist/src/connectors/uniswap/uniswap.js:90:51)\n    at /Users/feng/gateway/dist/src/services/connection-manager.js:134:51\n    at Generator.next (<anonymous>)\n    at /Users/feng/gateway/dist/src/services/connection-manager.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/Users/feng/gateway/dist/src/services/connection-manager.js:4:12)\n    at getConnector (/Users/feng/gateway/dist/src/services/connection-manager.js:131:12)"

I think this PR needs more work to figure out how to add support for Uniswap on other chains. Perhaps upgrading from using Swap Router 2 to Universal Router is needed.

@fengtality fengtality changed the title Harjas27 feat/uniswap BSC, Avalanche, and Celo feat/uniswap BSC, Avalanche, and Celo Jul 26, 2024
@fengtality fengtality changed the title feat/uniswap BSC, Avalanche, and Celo Feat / Add Uniswap on chains BSC, Avalanche, and Celo Jul 26, 2024
@fengtality
Copy link
Sponsor Contributor Author

@nikspz I added a hacky fix, so I think Uniswap swaps should now work on BSC, Avalanche, and Celo.

@fengtality fengtality mentioned this pull request Jul 26, 2024
@nikspz
Copy link
Contributor

nikspz commented Jul 29, 2024

@nikspz
Copy link
Contributor

nikspz commented Jul 29, 2024

Failed to add uniswapLP for BSC mainnet, avalanche avalanche, connector (works for Celo)

Steps:

  1. start the client with gateway set up
  2. connect uniswapLP avalanche
  3. failed to connect for connected and for new wallet

logs_hummingbot.log

2024-07-29 19:14:20,877 - 145951 - hummingbot.core.gateway.gateway_http_client - WARNING - Call to https://localhost:15888/chain/balances failed. See logs for more details.
2024-07-29 19:14:20,878 - 145951 - hummingbot.core.utils.async_utils - ERROR - Unhandled error in background task: Error on POST https://localhost:15888/chain/balances Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: No address for Uniswap Multicall Contract on chain id: 43114\n    at new UniswapMulticallProvider (/home/hummingbot/gwbsc/node_modules/@uniswap/smart-order-router/build/main/providers/multicall-uniswap-provider.js:30:19)\n    at new AlphaRouter (/home/hummingbot/gwbsc/node_modules/@uniswap/smart-order-router/build/main/routers/alpha-router/alpha-router.js:47:97)\n    at new UniswapLPHelper (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:76:33)\n    at new UniswapLP (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.js:44:9)\n    at UniswapLP.getInstance (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.js:52:53)\n    at /home/hummingbot/gwbsc/dist/src/services/connection-manager.js:137:56\n    at Generator.next (<anonymous>)\n    at /home/hummingbot/gwbsc/dist/src/services/connection-manager.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/home/hummingbot/gwbsc/dist/src/services/connection-manager.js:4:12)'}
Traceback (most recent call last):
  File "/home/hummingbot/dev2/hummingbot/core/utils/async_utils.py", line 9, in safe_wrapper
    return await c
  File "/home/hummingbot/dev2/hummingbot/client/command/gateway_command.py", line 369, in _gateway_connect
    balances: Dict[str, Any] = await self._get_gateway_instance().get_balances(
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 293, in get_balances
    return await self.api_request(
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 222, in api_request
    raise e
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 210, in api_request
    raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response}")
ValueError: Error on POST https://localhost:15888/chain/balances Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: No address for Uniswap Multicall Contract on chain id: 43114\n    at new UniswapMulticallProvider (/home/hummingbot/gwbsc/node_modules/@uniswap/smart-order-router/build/main/providers/multicall-uniswap-provider.js:30:19)\n    at new AlphaRouter (/home/hummingbot/gwbsc/node_modules/@uniswap/smart-order-router/build/main/routers/alpha-router/alpha-router.js:47:97)\n    at new UniswapLPHelper (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:76:33)\n    at new UniswapLP (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.js:44:9)\n    at UniswapLP.getInstance (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.js:52:53)\n    at /home/hummingbot/gwbsc/dist/src/services/connection-manager.js:137:56\n    at Generator.next (<anonymous>)\n    at /home/hummingbot/gwbsc/dist/src/services/connection-manager.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/home/hummingbot/gwbsc/dist/src/services/connection-manager.js:4:12)'}


image
image

Works for arbitrum:

image

0cac4ea

@fengtality
Copy link
Sponsor Contributor Author

@nikspz thanks - i fixed the uniswaplp bug

@nikspz
Copy link
Contributor

nikspz commented Jul 30, 2024

7e565d4
Test performed:

  • Amm_arb strategy works for avalanche and BSC
  • Curl:
    • arbitrum
      • amm/price: ok
      • amm/trade: ok
    • BSC mainnet
      • amm/price: ok
      • amm/trade: ok
      • amm/liquidity/add: ok
      • amm/liquidity/remove: ok
    • Avalanche
      • amm/price: ok
      • amm/trade: ok
      • amm/liquidity/add: ok
      • amm/liquidity/remove: ok
    • Celo
      • amm/price: ok
      • amm/trade: ok
  • Amm_LP: created LP position succesffully:
    • Unable to fetch pool state (avalanche, BSC)

Celo:

add position: ok
image
Remove: ok

BSC
add position - ok, position added, however Unable to fetch status

logs_conf_amm_v3_lp_2.log

2024-07-30 10:54:57,404 - 154436 - hummingbot.core.gateway.gateway_http_client - WARNING - Call to https://localhost:15888/amm/liquidity/position failed. See logs for more details.
2024-07-30 10:54:57,405 - 154436 - GatewayEVMAMMLP - ERROR - Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}
Traceback (most recent call last):
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 1097, in _status_polling_loop
    await safe_gather(
  File "/home/hummingbot/dev2/hummingbot/core/utils/async_utils.py", line 22, in safe_gather
    return await asyncio.gather(*args, **kwargs)
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 970, in update_nft
    raise nft_update_result
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 818, in amm_lp_position
    return await self.api_request("post", "amm/liquidity/position", request_payload)
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 222, in api_request
    raise e
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 210, in api_request
    raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response}")
ValueError: Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}
2024-07-30 10:55:08,615 - 154436 - hummingbot.core.gateway.gateway_http_client - WARNING - Call to https://localhost:15888/amm/liquidity/position failed. See logs for more details.
2024-07-30 10:55:08,615 - 154436 - GatewayEVMAMMLP - ERROR - Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}
Traceback (most recent call last):
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 1097, in _status_polling_loop
    await safe_gather(
  File "/home/hummingbot/dev2/hummingbot/core/utils/async_utils.py", line 22, in safe_gather
    return await asyncio.gather(*args, **kwargs)
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 970, in update_nft
    raise nft_update_result
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 818, in amm_lp_position
    return await self.api_request("post", "amm/liquidity/position", request_payload)
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 222, in api_request
    raise e
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 210, in api_request
    raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response}")
ValueError: Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}

https://bscscan.com/tx/0xf5fc4964726d7d02338413f8626a31d84350971bbd859a276d97028ef0b55f4e
image
image
image

remove position: ok
image

avalanche_avalanche

add position: ok Position created
issue on amm_v3_LP, not sure if related to node.

logs_conf_amm_v3_lp_1.log

2024-07-30 09:11:37,189 - 152703 - GatewayEVMAMMLP - ERROR - Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}
Traceback (most recent call last):
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 1097, in _status_polling_loop
    await safe_gather(
  File "/home/hummingbot/dev2/hummingbot/core/utils/async_utils.py", line 22, in safe_gather
    return await asyncio.gather(*args, **kwargs)
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 970, in update_nft
    raise nft_update_result
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 818, in amm_lp_position
    return await self.api_request("post", "amm/liquidity/position", request_payload)
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 222, in api_request
    raise e
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 210, in api_request
    raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response}")
ValueError: Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}
2024-07-30 09:11:38,529 - 152703 - GatewayEVMAMMLP - ERROR - Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}
Traceback (most recent call last):
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 1097, in _status_polling_loop
    await safe_gather(
  File "/home/hummingbot/dev2/hummingbot/core/utils/async_utils.py", line 22, in safe_gather
    return await asyncio.gather(*args, **kwargs)
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 970, in update_nft
    raise nft_update_result
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 818, in amm_lp_position
    return await self.api_request("post", "amm/liquidity/position", request_payload)
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 222, in api_request
    raise e
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 210, in api_request
    raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response}")
ValueError: Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}
2024-07-30 09:11:39,186 - 152703 - GatewayEVMAMMLP - ERROR - Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}
Traceback (most recent call last):
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 1097, in _status_polling_loop
    await safe_gather(
  File "/home/hummingbot/dev2/hummingbot/core/utils/async_utils.py", line 22, in safe_gather
    return await asyncio.gather(*args, **kwargs)
  File "/home/hummingbot/dev2/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 970, in update_nft
    raise nft_update_result
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 818, in amm_lp_position
    return await self.api_request("post", "amm/liquidity/position", request_payload)
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 222, in api_request
    raise e
  File "/home/hummingbot/dev2/hummingbot/core/gateway/gateway_http_client.py", line 210, in api_request
    raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response}")
ValueError: Error on POST https://localhost:15888/amm/liquidity/position Error: {'message': 'Unknown error.', 'httpErrorCode': 503, 'errorCode': 1099, 'stack': 'Error: Unable to fetch pool state\n    at UniswapLP.<anonymous> (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:179:23)\n    at Generator.next (<anonymous>)\n    at fulfilled (/home/hummingbot/gwbsc/dist/src/connectors/uniswap/uniswap.lp.helper.js:28:58)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'}

image

Remove position: ok
image

nikspz
nikspz previously approved these changes Jul 30, 2024
@nikspz nikspz dismissed their stale review July 30, 2024 18:34

amm/liquidity/position failed on curl as well, could be fixed in the next PR

@nikspz
Copy link
Contributor

nikspz commented Jul 30, 2024

amm/liquidity/position failed on curl as well, could be fixed in the next PR

image
image
image

@fengtality
Copy link
Sponsor Contributor Author

@nikspz I took a quick look at the /amm/liquidity/position issue but it requires more investigation. Looks like the position is successfully created but doing the tokenID lookup fails for some reason.

I suggest that we merge this PR in, and then I'll look at the LP functionality separately.

Copy link
Contributor

@nikspz nikspz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge this PR in, to look at the LP functionality separately.

@nikspz nikspz merged commit bd5573e into development Jul 31, 2024
4 of 5 checks passed
@nikspz nikspz deleted the harjas27-feat/uniswap_bsc branch July 31, 2024 04:03
@nikspz nikspz mentioned this pull request Aug 12, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Release 2.0.1
Development

Successfully merging this pull request may close these issues.

5 participants