gateway icon indicating copy to clipboard operation
gateway copied to clipboard

feat/ add ETCswap V3 and V2 connectors

Open vic-en opened this issue 1 year ago • 28 comments

Before submitting this PR, please make sure:

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

A description of the changes proposed in the pull request: https://github.com/hummingbot/hummingbot/issues/7110

Tests performed by the developer:

  • Curl tests for lp connector

Tips for QA testing:

  • Curl test, e.t.c.

vic-en avatar Jul 24 '24 05:07 vic-en

@chris-mercer Fyi, v3 connector basically adds concentrated lp functionality which is what I've done. If you're not aware, v2 and v3 swap functionality is consolidated in Gateway. As a matter of fact, the SOR(smart order router sometimes referred as auto routers) are designed to route swaps between v2 pairs and v3 pools. So it doesn't make sense to separate them for your connectors.

However, if you insist, I'll gladly make changes as requested to fulfil this bounty. Just know the connectors will most definitely have issues down the road.

vic-en avatar Jul 25 '24 04:07 vic-en

@chris-mercer Also, resolve necessary comments/requests

vic-en avatar Jul 25 '24 04:07 vic-en

@chris-mercer Fyi, v3 connector basically adds concentrated lp functionality which is what I've done. If you're not aware, v2 and v3 swap functionality is consolidated in Gateway. As a matter of fact, the SOR(smart order router sometimes referred as auto routers) are designed to route swaps between v2 pairs and v3 pools. So it doesn't make sense to separate them for your connectors.

However, if you insist, I'll gladly make changes as requested to fulfil this bounty. Just know the connectors will most definitely have issues down the road.

No i don't insist. If you followed the pattern in the repo then thats perfect. I noticed the chain was not named correctly and wanted to make sure there wouldn't be any issues on the naming. I'm not as familar with the code base as you. Thanks for addressing the issues that made sense.

chris-mercer avatar Jul 25 '24 15:07 chris-mercer

hi @vic-en Could you please check branch conflicts?

nikspz avatar Jul 31 '24 11:07 nikspz

@vic-en

Steps:

  1. Clone latest development + gwPR340
  2. set up gateway to ONLINE
  3. gateway connect etcswapLP

Actual: Failed to connect ETC wallet Unhandled error in background task: Error on POST https://localhost:15888/wallet/add

Expected: Could connect wallet

logs_hummingbot.log logs_gateway_app.log.2024-07-31.log

ERROR - Unhandled error in background task: Error on POST https://localhost:15888/wallet/add Error: {'message': 'No validator exists for ethereum-classic., chain must be "ethereum", "avalanche", "near", "harmony", "cosmos", "osmosis", "binance-smart-chain", or "kujira"', 'httpErrorCode': 404, 'errorCode': -1, 'stack': 'Error: No validator exists for ethereum-classic., chain must be "ethereum", "avalanche", "near", "harmony", "cosmos", "osmosis", "binance-smart-chain", or "kujira"\n    at throwIfErrorsExist (/home/hummingbot/gwetc340/dist/src/services/validators.js:38:15)\n    at /home/hummingbot/gwetc340/dist/src/services/validators.js:103:40\n    at /home/hummingbot/gwetc340/dist/src/services/wallet/wallet.routes.js:25:58\n    at Generator.next (<anonymous>)\n    at /home/hummingbot/gwetc340/dist/src/services/wallet/wallet.routes.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/home/hummingbot/gwetc340/dist/src/services/wallet/wallet.routes.js:4:12)\n    at /home/hummingbot/gwetc340/dist/src/services/wallet/wallet.routes.js:24:86\n    at /home/hummingbot/gwetc340/dist/src/services/error-handler.js:38:28\n    at Layer.handle [as handle_request] (/home/hummingbot/gwetc340/node_modules/express/lib/router/layer.js:95:5)'}
Traceback (most recent call last):
  File "/home/hummingbot/development1/hummingbot/core/utils/async_utils.py", line 9, in safe_wrapper
    return await c
  File "/home/hummingbot/development1/hummingbot/client/command/gateway_command.py", line 303, in _gateway_connect
    wallet_address, additional_prompt_values = await self._prompt_for_wallet_address(
  File "/home/hummingbot/development1/hummingbot/client/command/gateway_command.py", line 438, in _prompt_for_wallet_address
    response: Dict[str, Any] = await self._get_gateway_instance().add_wallet(
  File "/home/hummingbot/development1/hummingbot/core/gateway/gateway_http_client.py", line 269, in add_wallet
    return await self.api_request(method="post", path_url="wallet/add", params=request)
  File "/home/hummingbot/development1/hummingbot/core/gateway/gateway_http_client.py", line 222, in api_request
    raise e
  File "/home/hummingbot/development1/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/wallet/add Error: {'message': 'No validator exists for ethereum-classic., chain must be "ethereum", "avalanche", "near", "harmony", "cosmos", "osmosis", "binance-smart-chain", or "kujira"', 'httpErrorCode': 404, 'errorCode': -1, 'stack': 'Error: No validator exists for ethereum-classic., chain must be "ethereum", "avalanche", "near", "harmony", "cosmos", "osmosis", "binance-smart-chain", or "kujira"\n    at throwIfErrorsExist (/home/hummingbot/gwetc340/dist/src/services/validators.js:38:15)\n    at /home/hummingbot/gwetc340/dist/src/services/validators.js:103:40\n    at /home/hummingbot/gwetc340/dist/src/services/wallet/wallet.routes.js:25:58\n    at Generator.next (<anonymous>)\n    at /home/hummingbot/gwetc340/dist/src/services/wallet/wallet.routes.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/home/hummingbot/gwetc340/dist/src/services/wallet/wallet.routes.js:4:12)\n    at /home/hummingbot/gwetc340/dist/src/services/wallet/wallet.routes.js:24:86\n    at /home/hummingbot/gwetc340/dist/src/services/error-handler.js:38:28\n    at Layer.handle [as handle_request] (/home/hummingbot/gwetc340/node_modules/express/lib/router/layer.js:95:5)'}

image

nikspz avatar Jul 31 '24 12:07 nikspz

@nikspz All updated.

vic-en avatar Aug 05 '24 15:08 vic-en

bd9a268

@vic-en please create PR to add "ethereum-classic": "ETC", line

2024-08-06 16:12:05,738 - 270114 - hummingbot.core.gateway.gateway_status_monitor - INFO - Gateway Service is ONLINE.
2024-08-06 16:18:25,957 - 270114 - hummingbot.core.utils.async_utils - ERROR - Unhandled error in background task: 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "/home/hummingbot/development1/hummingbot/core/utils/async_utils.py", line 9, in safe_wrapper
    return await c
  File "/home/hummingbot/development1/hummingbot/client/command/gateway_command.py", line 524, in _get_balances
    bal_resp = await asyncio.wait_for(
  File "/home/hummingbot/miniconda3/envs/hummingbot/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/home/hummingbot/development1/hummingbot/client/command/gateway_command.py", line 718, in all_balances_all_exc
    await self.update_exchange(client_config_map)
  File "/home/hummingbot/development1/hummingbot/client/command/gateway_command.py", line 713, in update_exchange
    results = await safe_gather(*tasks)
  File "/home/hummingbot/development1/hummingbot/core/utils/async_utils.py", line 22, in safe_gather
    return await asyncio.gather(*args, **kwargs)
  File "/home/hummingbot/development1/hummingbot/client/command/gateway_command.py", line 673, in update_exchange_balances
    return await self.add_gateway_exchange(exchange_name, client_config_map, **api_keys)
  File "/home/hummingbot/development1/hummingbot/client/command/gateway_command.py", line 649, in add_gateway_exchange
    market = GatewayCommand.connect_markets(
  File "/home/hummingbot/development1/hummingbot/client/command/gateway_command.py", line 602, in connect_markets
    connector_class = get_connector_class(exchange)
  File "/home/hummingbot/development1/hummingbot/client/config/config_helpers.py", line 563, in get_connector_class
    mod = __import__(conn_setting.module_path(),
  File "/home/hummingbot/development1/hummingbot/client/settings.py", line 213, in module_path
    return f"hummingbot.connector.{self.module_name()}"
  File "/home/hummingbot/development1/hummingbot/client/settings.py", line 203, in module_name
    return f"gateway.{self.type.name.lower()}.gateway_{connector_spec['chain_type'].lower()}_{self._get_module_package()}"
TypeError: 'NoneType' object is not subscriptable

image

Test performed:

  • cloned latest development Client + gwPR340
  • added "ethereum-classic": "ETC", line to Client
  • started Client and gateway connect etcswapLP successfully
  • added gateway connector-tokens etcswapLP_ethereum-classic_mainnet tokens
  • Review tokens added to gateway balance
  • Created amm_v3_lp strategy using etcswapLP_ethereum-classic_mainnet, WETC-USC pair
  • started amm_v3_lp startegy
  • Review error and the bot stuck on connector is not ready https://etcerscan.com/address/0x930a6f15DA31912c0D0f3819D932E3397Cc1d410

logs_conf_amm_v3_lp_1.log

2024-08-06 17:23:11,377 - 284316 - hummingbot.core.utils.async_utils - ERROR - Unhandled error in background task: Error on POST https://localhost:15888/chain/allowances Error: {'message': 'The spender param is not a valid Ethereum address (0x followed by 40 hexidecimal characters).', 'httpErrorCode': 404, 'errorCode': -1, 'stack': 'Error: The spender param is not a valid Ethereum address (0x followed by 40 hexidecimal characters).\n    at throwIfErrorsExist (/home/hummingbot/gwetc340/dist/src/services/validators.js:38:15)\n    at /home/hummingbot/gwetc340/dist/src/services/validators.js:103:40\n    at EVMController.<anonymous> (/home/hummingbot/gwetc340/dist/src/chains/ethereum/evm.controllers.js:155:65)\n    at Generator.next (<anonymous>)\n    at /home/hummingbot/gwetc340/dist/src/chains/ethereum/evm.controllers.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/home/hummingbot/gwetc340/dist/src/chains/ethereum/evm.controllers.js:4:12)\n    at EVMController.allowances (/home/hummingbot/gwetc340/dist/src/chains/ethereum/evm.controllers.js:154:16)\n    at /home/hummingbot/gwetc340/dist/src/chains/chain.controller.js:49:51\n    at Generator.next (<anonymous>)'}
Traceback (most recent call last):
  File "/home/hummingbot/development1/hummingbot/core/utils/async_utils.py", line 9, in safe_wrapper
    return await c
  File "/home/hummingbot/development1/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 288, in auto_approve
    await self.update_allowances()
  File "/home/hummingbot/development1/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 328, in update_allowances
    self._allowances = await self.get_allowances()
  File "/home/hummingbot/development1/hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py", line 336, in get_allowances
    approval_lists: List[str] = await safe_gather(*[
  File "/home/hummingbot/development1/hummingbot/core/utils/async_utils.py", line 22, in safe_gather
    return await asyncio.gather(*args, **kwargs)
  File "/home/hummingbot/development1/hummingbot/core/gateway/gateway_http_client.py", line 374, in get_allowances
    return await self.api_request("post", "chain/allowances", {
  File "/home/hummingbot/development1/hummingbot/core/gateway/gateway_http_client.py", line 222, in api_request
    raise e
  File "/home/hummingbot/development1/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/allowances Error: {'message': 'The spender param is not a valid Ethereum address (0x followed by 40 hexidecimal characters).', 'httpErrorCode': 404, 'errorCode': -1, 'stack': 'Error: The spender param is not a valid Ethereum address (0x followed by 40 hexidecimal characters).\n    at throwIfErrorsExist (/home/hummingbot/gwetc340/dist/src/services/validators.js:38:15)\n    at /home/hummingbot/gwetc340/dist/src/services/validators.js:103:40\n    at EVMController.<anonymous> (/home/hummingbot/gwetc340/dist/src/chains/ethereum/evm.controllers.js:155:65)\n    at Generator.next (<anonymous>)\n    at /home/hummingbot/gwetc340/dist/src/chains/ethereum/evm.controllers.js:8:71\n    at new Promise (<anonymous>)\n    at __awaiter (/home/hummingbot/gwetc340/dist/src/chains/ethereum/evm.controllers.js:4:12)\n    at EVMController.allowances (/home/hummingbot/gwetc340/dist/src/chains/ethereum/evm.controllers.js:154:16)\n    at /home/hummingbot/gwetc340/dist/src/chains/chain.controller.js:49:51\n    at Generator.next (<anonymous>)'}
2024-08-06 17:23:12,001 - 284316 - hummingbot.strategy.amm_v3_lp.amm_v3_lp - WARNING - etcswapLP_ethereum-classic_mainnet connector is not ready. Please wait...
2024-08-06 17:23:13,001 - 284316 - hummingbot.strategy.amm_v3_lp.amm_v3_lp - WARNING - etcswapLP_ethereum-classic_mainnet connector is not ready. Please wait...

image

nikspz avatar Aug 06 '24 17:08 nikspz

@nikspz https://github.com/hummingbot/hummingbot/pull/7159 The reason it was stuck was because it was attempting to check allowance for etcSwap which is yet to be added. It should work now.

vic-en avatar Aug 06 '24 21:08 vic-en

Test performed:

  • cloned latest development Client + gwPR340
  • added "ethereum-classic": "ETC", line to Client
  • started Client and gateway connect etcswapLP successfully
  • Created amm_v3_lp strategy using etcswapLP_ethereum-classic_mainnet, WETC-USC pair
  • started amm_v3_lp startegy
  • Review tokens approved but Client strategy not started to creating position

https://etcerscan.com/address/0x930a6f15DA31912c0D0f3819D932E3397Cc1d410

logs_conf_amm_v3_lp_1.log

logs_gateway_app.log.2024-08-07.log

image image

nikspz avatar Aug 07 '24 20:08 nikspz

@nikspz The price says 0. What fee tier are you using?

vic-en avatar Aug 07 '24 20:08 vic-en

@nikspz The price says 0. What fee tier are you using?

image

nikspz avatar Aug 07 '24 20:08 nikspz

@nikspz There are just 2 pools for that pair. LOWEST and MEDIUM

vic-en avatar Aug 07 '24 22:08 vic-en

@nikspz There are just 2 pools for that pair. LOWEST and MEDIUM

LOWEST: Failed to add liquidity, Client stuck on WARNING - etcswapLP_ethereum-classic_mainnet connector is not ready. Please wait...

logs_conf_amm_v3_lp_2.log

image image

MEDIUM: Created successffully ✅ Amount is correct ✅ No message in logs about position was created ❌ logs_conf_amm_v3_lp_3.log

image image

nikspz avatar Aug 08 '24 13:08 nikspz

Upd: retested LOWEST, created position ✅ status reported correct amount and ID ✅ No message in logs about position was created ❌

image image

Remove liquidity: ok image

nikspz avatar Aug 08 '24 14:08 nikspz

For any block explorer links, please use the primary funded explorer: https://etc.blockscout.com/

chris-mercer avatar Aug 08 '24 18:08 chris-mercer

Apologies- info.etcswap.org analytics UI page had its archival node corrupt due to bad SSD this past week. it is currently resyncing and should functional once synced.

8/11 update: 50% through the resync. 8/13: Can review the progress of resync here: https://explorer-expedition.etc-network.info/?network=Ethereum%20Classic%20at%20etc-network.info%20GETH%20-%20AT 8/22: Node resync complete and https://info.etcswap.org service is restored.

chris-mercer avatar Aug 08 '24 18:08 chris-mercer

@nikspz I guess the node issue may have affected it. I tested over the weekend and it worked fine.

vic-en avatar Aug 12 '24 14:08 vic-en

@vic-en Could you please check failing tests? https://github.com/hummingbot/gateway/actions/runs/10273924216/job/28696060192?pr=340

nikspz avatar Aug 13 '24 10:08 nikspz

@nikspz I guess the node issue may have affected it. I tested over the weekend and it worked fine.

If you're using etc.rivet.link as the rpc endpoint, nothing should be affected in your work. The v3.etcswap.org app does not interact with the archival node/subgraph at all.

The info.etcswap.org archival node is messing with the subgraphs ability to read new events. This is entirely different and simply related to that display app of activity (charts, volume, recent trades). I mentioned this in case you are using that for visibility into your actions. Again, ETCswap V3 is entirely functional: v3.etcswap.org

chris-mercer avatar Aug 13 '24 16:08 chris-mercer

@nikspz I fixed the failling test. The workflow was failing as a result of recent refactor to the Uniswap connector.

Failing workflow in https://github.com/hummingbot/gateway/pull/345 will pass as well when this pr is merged.

vic-en avatar Aug 14 '24 15:08 vic-en

@nikspz @fengtality I'm kind of confused on where we are on this bounty.

What are all the blockers here and what are the steps to get our network participants able to build the ETC/USC market for V3 with HB?

I noticed this is open too: https://github.com/hummingbot/hummingbot/pull/7159

chris-mercer avatar Aug 26 '24 22:08 chris-mercer

NCP is submitted: https://snapshot.org/#/hbot-ncp.eth/proposal/0x5face44f80c3c0d3d290da1a6973ec0c030a483023a4647ff91e4339af085770

chris-mercer avatar Sep 11 '24 04:09 chris-mercer

@vic-en Could you please fix branch conflicts? I think could be related to this PR: https://github.com/hummingbot/gateway/pull/362

nikspz avatar Sep 25 '24 09:09 nikspz

Please test ETCswap V2 and ETCswap V3 protocols as @vic-en mentioned this PR addressed both bounties. You can find charts for WETC/USC markets in GeckoTerminal now.

https://www.geckoterminal.com/ethereum_classic/etcswap-v2/pools https://www.geckoterminal.com/ethereum_classic/etcswap-v3/pools

chris-mercer avatar Sep 25 '24 19:09 chris-mercer

@nikspz I've resolved conflict.

vic-en avatar Sep 26 '24 16:09 vic-en

@vic-en

Steps:

  1. Cloned latest PR7159 + gwPR340 (fb11f32)
  2. Installed Client and gateway PR
  3. Reviewed gateway ONLINE
  4. created/started amm_arb strategy using etcswap_ethereum-classic_mainnet

Actual: review rate oracle issue related to USC token not available on rate oracle sources (binance and etc.)

logs_etc.log

image

image

nikspz avatar Oct 07 '24 14:10 nikspz

@nikspz I changed them to USDT. They should work now.

vic-en avatar Oct 07 '24 17:10 vic-en

Tests performed:

  • Cloned latest PR7159 + gwPR340 (fb11f32)
  • Installed Client and gateway PR
  • Reviewed gateway ONLINE
  • created/started amm_arb strategy using etcswap_ethereum-classic_mainnet and binance successfully
  • Reviewed forced USDT-USC 1 Rate oracle ✔

Pending: Curl tests

image

nikspz avatar Oct 08 '24 19:10 nikspz

Hi @vic-en Can you add the docs for the connector to our site - https://github.com/hummingbot/hummingbot-site Thanks!

david-hummingbot avatar Oct 15 '24 21:10 david-hummingbot

Hi @vic-en Can you add the docs for the connector to our site - https://github.com/hummingbot/hummingbot-site Thanks!

@david-hummingbot https://github.com/hummingbot/hummingbot-site/pull/408

vic-en avatar Oct 18 '24 04:10 vic-en