Skip to content

Conversation

vic-en
Copy link
Collaborator

@vic-en vic-en commented Sep 2, 2025

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:
Add Pancakeswap connector - [https://github.com/hummingbot/hummingbot/issues/7654]

Tests performed by the developer:

  • Tested all get endpoints
  • Test all post endpoints
  • Update unit tests

Tips for QA testing:

@fengtality
Copy link
Contributor

@vic-en note merge conflicts

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 4, 2025

@fengtality @nikspz This connector is ready. I implemented all functionalities as is in the Uniswap connector as of now. All endpoints are tested and working.

@nikspz nikspz moved this from Backlog to Under Review in Pull Request Board Sep 5, 2025
@nikspz
Copy link
Contributor

nikspz commented Sep 5, 2025

hi @vic-en could you please add pancakeswap connector to Client also

image image

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 5, 2025

@nikspz it has been updated

@fengtality
Copy link
Contributor

@nikspz No changes to the client should be needed after v2.8, since the list of connectors and chains are fetched from Gateway at initialization.

Here's what I see in Hummingbot when running Gateway with this PR:
Screenshot 2025-09-07 at 9 11 38 PM

@nikspz
Copy link
Contributor

nikspz commented Sep 9, 2025

@vic-en

Failed to approve token using gateway approve pancakeswap/clmm USDT
needed cause have 0 USDT appoval and failed to swap

Steps:

  1. Cloned latest development + gwPR
  2. connect ethereum wallet
  3. changed ethereum default to bsc
  4. changed nodeURL to infura
  5. use gateway approve pancakeswap/clmm USDT command
  6. proceed >> yes

Actual:
Got
03:50:10 - gateway_http_client - Call to http://localhost:15888/chains/ethereum/approve failed. See logs for more details. 03:50:10 - GatewayBase - Error approving USDT: Error on POST http://localhost: 15888/chains/ethereum/approve Error: Internal Server Error (See log file for s tack trace dump) 03:50:10 - hummingbot_application - Error approving token: Error on POST http: //localhost:15888/chains/ethereum/approve Error: Internal Server Error (See lo g file for stack trace dump)

logs_hummingbot.log
logs_gateway_app.log - Copy.2025-09-09.log

error |   Error approving token: network does not support ENS (operation="getResolver", network="bnb", code=UNSUPPORTED_OPERATION, version=providers/5.8.0)                                                                                                      2025-09-08 12:50:10 | error |   Unhandled error: {"error": "Cannot read properties of undefined (reading 'internalServerError')",  "url": "/chains/ethereum/approve",                  "params": {} } 
image

@nikspz
Copy link
Contributor

nikspz commented Sep 10, 2025

logs_hummingbot.log
logs_gateway_app.log - Copy.2025-09-10.log

2025-09-10 16:31:16,333 - 12180 - GatewayBase - INFO - Set native currency to: BNB for ethereum-bsc
2025-09-10 16:31:16,335 - 12180 - GatewayBase - INFO - Set native currency to: BNB for ethereum-bsc
2025-09-10 16:31:19,920 - 12180 - hummingbot.core.gateway.gateway_http_client - WARNING - Call to http://localhost:15888/connectors/pancakeswap/clmm/execute-swap failed. See logs for more details.
2025-09-10 16:31:19,920 - 12180 - GatewayBase - ERROR - Error submitting BUY swap order for WBNB-USDT on pancakeswap/clmm: Error on POST http://localhost:15888/connectors/pancakeswap/clmm/execute-swap Error: BadRequestError
Traceback (most recent call last):
  File "/home/etozhe/gwbscfix/hummingbot/connector/gateway/gateway_swap.py", line 150, in _create_order
    order_result: Dict[str, Any] = await self._get_gateway_instance().execute_swap(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/etozhe/gwbscfix/hummingbot/core/gateway/gateway_http_client.py", line 799, in execute_swap
    return await self.api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/etozhe/gwbscfix/hummingbot/core/gateway/gateway_http_client.py", line 457, in api_request
    raise e
  File "/home/etozhe/gwbscfix/hummingbot/core/gateway/gateway_http_client.py", line 443, in api_request
    raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response['error']}")
ValueError: Error on POST http://localhost:15888/connectors/pancakeswap/clmm/execute-swap Error: BadRequestError
2025-09-10 16:31:19,923 - 12180 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": NaN, "order_id": "buy-WBNB-USDT-1757496676023164", "order_type": "OrderType.AMM_SWAP", "error_message": null, "error_type": null, "event_name": "MarketOrderFailureEvent", "event_source": "pancakeswap/clmm"}
2025-09-10 16:31:19,923 - 12180 - hummingbot.connector.client_order_tracker - INFO - Order buy-WBNB-USDT-1757496676023164 has failed. Order Update: OrderUpdate(trading_pair='WBNB-USDT', update_timestamp=nan, new_state=<OrderState.FAILED: 6>, client_order_id='buy-WBNB-USDT-1757496676023164', exchange_order_id=None, misc_updates=None)

image image image image

@fengtality
Copy link
Contributor

fengtality commented Sep 11, 2025

@nikspz The PancakeSwap/CLMM approval issue is due to fact that there are 2 smart contracts for Pancakeswap and Uniswap CLMM - one used for swaps and other used for liquidity operations

  // V3 contracts
    pancakeswapV3SwapRouter02Address: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
    pancakeswapV3NftManagerAddress: '0x46A15B0b27311cedF172AB29E4f4766fbE7F4364',

The same exists for Uniswap:

    // V3 contracts - Official Uniswap addresses
    uniswapV3SwapRouter02Address: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
    uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88',

To handle this, I added handling for pancakeswap/clmm/swap and uniswap/clmm/swap in the gateway allowance and gateway approve commands:

Screenshot 2025-09-11 at 4 13 52 PM

You should only need to use pancakeswap/clmm/swap and uniswap/clmm/swap when dealing with approve and allowances.

See hummingbot/hummingbot#7772 and #508 branches

@fengtality
Copy link
Contributor

@nikspz Also, most users will likely use Router for swaps, so I suggest concentrating your tests on opening and closing LP positions for the Pancakeswap CLMM and AMM connectors

@fengtality
Copy link
Contributor

@vic-en Some minor issues found during testing. Since you are working on the Uniswap bugs PR, please include these fixes in that one.

1 - GET Quote Position for both Uniswap CLMM and Pancakeswap CLMM don't show the proper default values in Swagger, because they are using the schemas directly instead of overriding them. Adding connector-specifc schemas like the AMM routes should fix this.

Screenshot 2025-09-11 at 4 52 49 PM is.

2- The response to /clmm/pool-info seems odd because baseTokenAmount and quoteTokenAmount are identical. Uniswap may have this bug too.
Screenshot 2025-09-11 at 4 56 50 PM

@fengtality
Copy link
Contributor

When fetching an open position quote, the base and quote amounts don't match what's shown in PancakeSwap. Here, the same upper and lower price bounds results in response that says quote amount should be 0.

Screenshot 2025-09-11 at 5 06 48 PM Screenshot 2025-09-11 at 5 06 57 PM

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 12, 2025

@fengtality Noted.

@nikspz
Copy link
Contributor

nikspz commented Sep 15, 2025

hi @vic-en Could you please check clmm connector and adding liquidity price?

  • PR7772 commit d289e93e4bcc2017399d9a8f5791d983de74f9ef + gw509 commit 0103818
    • gateway connect ethereum: ok

    • gateway config ethereum update

      • defaultNetwork
        • updated to bsc
    • gateway config ethereum-bsc update

    • gateway balance: ok

    • gateway allowance pancakeswap ✅

    • image
    • image
    • image
    • gateway swap pancakeswap/router

    • gateway swap pancakeswap/amm

    • gateway swap pancakeswap/clmm

      • WBNB-USDT

        • BUY 0.01 Transaction failed ❌
          • Current allowance: 0 USDT
          • 2025-09-15 05:29:16 | info | Amount needed: 9.392882075768702 USDT
          • image
        • SELL 0.01 Transaction failed ❌
          • Current allowance: 0 WBNB
          • 2025-09-15 05:31:08 | info | Amount needed: 0.01 WBNB
          • 2025-09-15 05:31:08 | error | Insufficient allowance for WBNB
        • logs
        2025-09-15 20:29:14,021 - 6622 - GatewaySwap - INFO - Set native currency to: BNB for ethereum-bsc
        2025-09-15 20:29:14,023 - 6622 - GatewaySwap - INFO - Set native currency to: BNB for ethereum-bsc
        2025-09-15 20:29:16,547 - 6622 - hummingbot.core.gateway.gateway_http_client - WARNING - Call to http://localhost:15888/connectors/pancakeswap/clmm/execute-swap failed. See logs for more details.
        2025-09-15 20:29:16,547 - 6622 - GatewaySwap - ERROR - Error submitting BUY swap order for WBNB-USDT on pancakeswap/clmm: Error on POST http://localhost:15888/connectors/pancakeswap/clmm/execute-swap Error: BadRequestError
        Traceback (most recent call last):
          File "/home/etozhe/bscnew7772/hummingbot/connector/gateway/gateway_swap.py", line 150, in _create_order
            order_result: Dict[str, Any] = await self._get_gateway_instance().execute_swap(
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/etozhe/bscnew7772/hummingbot/core/gateway/gateway_http_client.py", line 799, in execute_swap
            return await self.api_request(
                   ^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/etozhe/bscnew7772/hummingbot/core/gateway/gateway_http_client.py", line 457, in api_request
            raise e
          File "/home/etozhe/bscnew7772/hummingbot/core/gateway/gateway_http_client.py", line 443, in api_request
            raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response['error']}")
        ValueError: Error on POST http://localhost:15888/connectors/pancakeswap/clmm/execute-swap Error: BadRequestError
        2025-09-15 20:29:16,551 - 6622 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": NaN, "order_id": "buy-WBNB-USDT-1757942953672459", "order_type": "OrderType.AMM_SWAP", "error_message": null, "error_type": null, "event_name": "MarketOrderFailureEvent", "event_source": "pancakeswap/clmm"}
        2025-09-15 20:29:16,551 - 6622 - hummingbot.connector.client_order_tracker - INFO - Order buy-WBNB-USDT-1757942953672459 has failed. Order Update: OrderUpdate(trading_pair='WBNB-USDT', update_timestamp=nan, new_state=<OrderState.FAILED: 6>, client_order_id='buy-WBNB-USDT-1757942953672459', exchange_order_id=None, misc_updates=None)
        2025-09-15 20:31:05,528 - 6622 - GatewaySwap - INFO - Set native currency to: BNB for ethereum-bsc
        2025-09-15 20:31:05,529 - 6622 - GatewaySwap - INFO - Set native currency to: BNB for ethereum-bsc
        2025-09-15 20:31:08,367 - 6622 - hummingbot.core.gateway.gateway_http_client - WARNING - Call to http://localhost:15888/connectors/pancakeswap/clmm/execute-swap failed. See logs for more details.
        2025-09-15 20:31:08,367 - 6622 - GatewaySwap - ERROR - Error submitting SELL swap order for WBNB-USDT on pancakeswap/clmm: Error on POST http://localhost:15888/connectors/pancakeswap/clmm/execute-swap Error: BadRequestError
        Traceback (most recent call last):
          File "/home/etozhe/bscnew7772/hummingbot/connector/gateway/gateway_swap.py", line 150, in _create_order
            order_result: Dict[str, Any] = await self._get_gateway_instance().execute_swap(
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/etozhe/bscnew7772/hummingbot/core/gateway/gateway_http_client.py", line 799, in execute_swap
            return await self.api_request(
                   ^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/etozhe/bscnew7772/hummingbot/core/gateway/gateway_http_client.py", line 457, in api_request
            raise e
          File "/home/etozhe/bscnew7772/hummingbot/core/gateway/gateway_http_client.py", line 443, in api_request
            raise ValueError(f"Error on {method.upper()} {url} Error: {parsed_response['error']}")
        ValueError: Error on POST http://localhost:15888/connectors/pancakeswap/clmm/execute-swap Error: BadRequestError
        2025-09-15 20:31:08,370 - 6622 - hummingbot.core.event.event_reporter - EVENT_LOG - {"timestamp": NaN, "order_id": "sell-WBNB-USDT-1757943065178630", "order_type": "OrderType.AMM_SWAP", "error_message": null, "error_type": null, "event_name": "MarketOrderFailureEvent", "event_source": "pancakeswap/clmm"}
        2025-09-15 20:31:08,370 - 6622 - hummingbot.connector.client_order_tracker - INFO - Order sell-WBNB-USDT-1757943065178630 has failed. Order Update: OrderUpdate(trading_pair='WBNB-USDT', update_timestamp=nan, new_state=<OrderState.FAILED: 6>, client_order_id='sell-WBNB-USDT-1757943065178630', exchange_order_id=None, misc_updates=None)
        2025-09-15 05:27:32 | info | 	Path: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c -> 0x55d398326f99059fF775485246999027B3197955
        2025-09-15 05:27:33 | debug | 	Token balance for WBNB: 64745357057801424
        2025-09-15 05:27:33 | debug | 	Token balance for USDT: 7852467770414788046
        2025-09-15 05:27:33 | info | 	Current allowance: 1.157920892373162e+59 WBNB
        2025-09-15 05:27:33 | info | 	Amount needed: 0.01 WBNB
        2025-09-15 05:27:33 | info | 	Sufficient allowance exists: 1.157920892373162e+59 WBNB
        2025-09-15 05:27:34 | info | 	Using legacy gas pricing: 0.1 GWEI with gasLimit: 300000
        2025-09-15 05:27:34 | info | 	Using gas options: {"gasLimit":300000,"type":0,"gasPrice":{"type":"BigNumber","hex":"0x05f5e100"}}
        2025-09-15 05:27:34 | info | 	ExactTokensForTokens params:
        2025-09-15 05:27:34 | info | 	  amountIn: 10000000000000000
        2025-09-15 05:27:34 | info | 	  amountOutMin: 8996037011729037298
        2025-09-15 05:27:34 | info | 	  path: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c,0x55d398326f99059fF775485246999027B3197955
        2025-09-15 05:27:34 | info | 	  deadline: 1757944053
        2025-09-15 05:27:35 | info | 	Transaction sent: 0xd445ec9bb77e5587c31ad2a88f91e3a11b0de3c17011135405384f0fee6f148f
        2025-09-15 05:27:36 | info | 	Transaction confirmed: 0xd445ec9bb77e5587c31ad2a88f91e3a11b0de3c17011135405384f0fee6f148f
        2025-09-15 05:27:36 | info | 	Gas used: 90887
        2025-09-15 05:27:38 | info | 	Poll ethereum, signature 0xd445ec9bb77e5587c31ad2a88f91e3a11b0de3c17011135405384f0fee6f148f, status 1.
        2025-09-15 05:28:54 | info | 	Getting available DEX connectors and networks
        2025-09-15 05:28:54 | info | 	Available connectors: jupiter, meteora, raydium, uniswap, 0x, pancakeswap
        2025-09-15 05:28:54 | info | 	Getting configuration for namespace: ethereum
        2025-09-15 05:29:06 | info | 	Getting configuration for namespace: ethereum
        2025-09-15 05:29:06 | info | 	Finding clmm pool for WBNB-USDT on bsc
        2025-09-15 05:29:06 | info | 	Resolved tokens: WBNB (0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c), USDT (0x55d398326f99059fF775485246999027B3197955)
        2025-09-15 05:29:06 | info | 	Found clmm pool at 0x36696169c63e42cd08ce11f5deebbcebae652050
        2025-09-15 05:29:06 | info | 	formatSwapQuote: poolAddress=0x36696169c63e42cd08ce11f5deebbcebae652050, baseToken=WBNB, quoteToken=USDT, amount=0.01, side=BUY, network=bsc
        2025-09-15 05:29:06 | info | 	Base token: WBNB, address=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c, decimals=18
        2025-09-15 05:29:06 | info | 	Quote token: USDT, address=0x55d398326f99059fF775485246999027B3197955, decimals=18
        2025-09-15 05:29:09 | info | 	Quote result: estimatedAmountIn=9.20869156271584, estimatedAmountOut=0.01
        2025-09-15 05:29:09 | info | 	Balance changes: baseTokenBalanceChange=0.01, quoteTokenBalanceChange=-9.20869156271584
        2025-09-15 05:29:09 | info | 	Gas price from provider: 100000000
        2025-09-15 05:29:09 | info | 	Gas cost: 0.00002 ETH
        2025-09-15 05:29:09 | info | 	Gas price in Gwei: 0.1
        2025-09-15 05:29:09 | info | 	Getting configuration for namespace: pancakeswap
        2025-09-15 05:29:10 | info | 	Estimated: 0.1 GWEI for network bsc
        2025-09-15 05:29:12 | debug | 	Token balance for WBNB: 54745357057801424
        2025-09-15 05:29:12 | debug | 	Token balance for USDT: 17028641581843581795
        2025-09-15 05:29:13 | info | 	Loading tokens for ethereum/bsc using TokenService
        2025-09-15 05:29:13 | info | 	Loaded 5 tokens for ethereum/bsc
        2025-09-15 05:29:13 | info | 	Finding clmm pool for WBNB-USDT on bsc
        2025-09-15 05:29:13 | info | 	Resolved tokens: WBNB (0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c), USDT (0x55d398326f99059fF775485246999027B3197955)
        2025-09-15 05:29:13 | info | 	Found clmm pool at 0x36696169c63e42cd08ce11f5deebbcebae652050
        2025-09-15 05:29:13 | info | 	Base token: WBNB, address=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c, decimals=18
        2025-09-15 05:29:13 | info | 	Quote token: USDT, address=0x55d398326f99059fF775485246999027B3197955, decimals=18
        2025-09-15 05:29:14 | info | 	Getting configuration for namespace: ethereum-bsc
        2025-09-15 05:29:14 | info | 	Getting configuration for namespace: ethereum-bsc
        2025-09-15 05:29:16 | info | 	Executing swap using SwapRouter02:
        2025-09-15 05:29:16 | info | 	Router address: 0x1b81D678ffb9C0263b24A97847620C99d213eB14
        2025-09-15 05:29:16 | info | 	Pool address: 0x36696169c63e42cd08ce11f5deebbcebae652050
        2025-09-15 05:29:16 | info | 	Input token: 0x55d398326f99059fF775485246999027B3197955
        2025-09-15 05:29:16 | info | 	Output token: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
        2025-09-15 05:29:16 | info | 	Side: BUY
        2025-09-15 05:29:16 | info | 	Fee tier: 500
        2025-09-15 05:29:16 | debug | 	Token balance for WBNB: 54745357057801424
        2025-09-15 05:29:16 | debug | 	Token balance for USDT: 17028641581843581795
        2025-09-15 05:29:16 | info | 	Current allowance: 0 USDT
        2025-09-15 05:29:16 | info | 	Amount needed: 9.392882075768702 USDT
        2025-09-15 05:29:16 | error | 	Insufficient allowance for USDT
        2025-09-15 05:30:49 | info | 	Getting available DEX connectors and networks
        2025-09-15 05:30:49 | info | 	Available connectors: jupiter, meteora, raydium, uniswap, 0x, pancakeswap
        2025-09-15 05:30:49 | info | 	Getting configuration for namespace: ethereum
        2025-09-15 05:30:57 | info | 	Getting configuration for namespace: ethereum
        2025-09-15 05:30:57 | info | 	Finding clmm pool for WBNB-USDT on bsc
        2025-09-15 05:30:57 | info | 	Resolved tokens: WBNB (0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c), USDT (0x55d398326f99059fF775485246999027B3197955)
        2025-09-15 05:30:57 | info | 	Found clmm pool at 0x36696169c63e42cd08ce11f5deebbcebae652050
        2025-09-15 05:30:57 | info | 	formatSwapQuote: poolAddress=0x36696169c63e42cd08ce11f5deebbcebae652050, baseToken=WBNB, quoteToken=USDT, amount=0.01, side=SELL, network=bsc
        2025-09-15 05:30:57 | info | 	Base token: WBNB, address=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c, decimals=18
        2025-09-15 05:30:57 | info | 	Quote token: USDT, address=0x55d398326f99059fF775485246999027B3197955, decimals=18
        2025-09-15 05:31:00 | info | 	Quote result: estimatedAmountIn=0.01, estimatedAmountOut=9.19941274294607
        2025-09-15 05:31:00 | info | 	Balance changes: baseTokenBalanceChange=-0.01, quoteTokenBalanceChange=9.19941274294607
        2025-09-15 05:31:00 | info | 	Gas price from provider: 100000000
        2025-09-15 05:31:00 | info | 	Gas cost: 0.00002 ETH
        2025-09-15 05:31:00 | info | 	Gas price in Gwei: 0.1
        2025-09-15 05:31:00 | info | 	Getting configuration for namespace: pancakeswap
        2025-09-15 05:31:00 | info | 	Estimated: 0.1 GWEI for network bsc
        2025-09-15 05:31:03 | debug | 	Token balance for USDT: 17028641581843581795
        2025-09-15 05:31:03 | debug | 	Token balance for WBNB: 54745357057801424
        2025-09-15 05:31:05 | info | 	Loading tokens for ethereum/bsc using TokenService
        2025-09-15 05:31:05 | info | 	Loaded 5 tokens for ethereum/bsc
        2025-09-15 05:31:05 | info | 	Finding clmm pool for WBNB-USDT on bsc
        2025-09-15 05:31:05 | info | 	Resolved tokens: WBNB (0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c), USDT (0x55d398326f99059fF775485246999027B3197955)
        2025-09-15 05:31:05 | info | 	Found clmm pool at 0x36696169c63e42cd08ce11f5deebbcebae652050
        2025-09-15 05:31:05 | info | 	Base token: WBNB, address=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c, decimals=18
        2025-09-15 05:31:05 | info | 	Quote token: USDT, address=0x55d398326f99059fF775485246999027B3197955, decimals=18
        2025-09-15 05:31:05 | info | 	Getting configuration for namespace: ethereum-bsc
        2025-09-15 05:31:05 | info | 	Getting configuration for namespace: ethereum-bsc
        2025-09-15 05:31:07 | debug | 	Token balance for WBNB: 54745357057801424
        2025-09-15 05:31:07 | debug | 	Token balance for USDT: 17028641581843581795
        2025-09-15 05:31:07 | info | 	Executing swap using SwapRouter02:
        2025-09-15 05:31:07 | info | 	Router address: 0x1b81D678ffb9C0263b24A97847620C99d213eB14
        2025-09-15 05:31:07 | info | 	Pool address: 0x36696169c63e42cd08ce11f5deebbcebae652050
        2025-09-15 05:31:07 | info | 	Input token: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
        2025-09-15 05:31:07 | info | 	Output token: 0x55d398326f99059fF775485246999027B3197955
        2025-09-15 05:31:07 | info | 	Side: SELL
        2025-09-15 05:31:07 | info | 	Fee tier: 500
        2025-09-15 05:31:08 | info | 	Current allowance: 0 WBNB
        2025-09-15 05:31:08 | info | 	Amount needed: 0.01 WBNB
        2025-09-15 05:31:08 | error | 	Insufficient allowance for WBNB
    • gateway lp pancakeswap/clmm add-liquidity

      • image
      • showing wrong price for WBNB-USDT (0.001088 instead of 920) ❌
      • added wrong amount (0.000001 instead of 9.2 USDT that was set up) ❌
    • gateway lp pancakeswap/amm add-liquidity

logs_hummingbot.log
logs_gateway_app.log - Copy.2025-09-15.log

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 15, 2025

@fengtality the issue with clmm is that the baseToken and quoteToken are specified in the swagger but not used at all.

Note that fixing this may break existing implementation on the client if the client doesn't send the baseToken and quoteToken when required.

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 15, 2025

@fengtality I've isolated changes I plan to apply to other clmm endpoints(including Uniswap's) to fix the issue with the amounts in 97c2380

Pls take a look at changes in that commit and let me know if you want me to proceed.

@fengtality
Copy link
Contributor

@vic-en I'll check the client again, but the price issue that Nikita is referring to should be unrelated to adding baseToken and quoteToken to the CLMM routes. I intended the CLMM endpoints to be called using poolAddress only, and the client is supposed to be fetching the right poolAddress using the pools dict and using that address for quoting the position and adding liquidity.

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 16, 2025

@fengtality It is the cause of inverted prices and flipped/incorrect amount.
BaseToken and quoteToken do not match with the pool's expected token0 and token1 respectively. Otherwise, every would be fine.

As it is right now, there wouldn't be an issue using a pool like https://pancakeswap.finance/info/v3/pairs/0xbe141893e4c6ad9272e8c04bab7e6a10604501a5 because the order of token is ETH-USDT which is what the client would typically use.
cc @nikspz

@fengtality
Copy link
Contributor

@vic-en

BaseToken and quoteToken do not match with the pool's expected token0 and token1 respectively. Otherwise, every would be fine.

That shouldn't be the issue, because the connector fetches the pool and determines if the baseToken provided matches the pool's token0:

        // Get pool information to determine tokens
        const poolInfo = await getPancakeswapPoolInfo(poolAddress, networkToUse, 'clmm');
        if (!poolInfo) {
          throw fastify.httpErrors.notFound(sanitizeErrorMessage('Pool not found: {}', poolAddress));
        }

        const baseTokenObj = pancakeswap.getTokenByAddress(poolInfo.baseTokenAddress);
        const quoteTokenObj = pancakeswap.getTokenByAddress(poolInfo.quoteTokenAddress);

        if (!baseTokenObj || !quoteTokenObj) {
          throw fastify.httpErrors.badRequest('Token information not found for pool');
        }

        // Get the V3 pool
        const pool = await pancakeswap.getV3Pool(baseTokenObj, quoteTokenObj, undefined, poolAddress);
        if (!pool) {
          throw fastify.httpErrors.notFound(`Pool not found for ${baseTokenObj.symbol}-${quoteTokenObj.symbol}`);
        }

        // Convert price range to ticks
        // In Pancakeswap, ticks are log base 1.0001 of price
        // We need to convert the user's desired price range to tick range
        const token0 = pool.token0;
        const token1 = pool.token1;

        // Determine if we need to invert the price depending on which token is token0
        const isBaseToken0 = baseTokenObj.address.toLowerCase() === token0.address.toLowerCase();

It's possible that we need to invert the amounts as well as the price.

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 16, 2025

@fengtality Sources of
const poolInfo = await getPancakeswapPoolInfo(poolAddress, networkToUse, 'clmm');
and
const pool = await pancakeswap.getV3Pool(baseTokenObj, quoteTokenObj, undefined, poolAddress);
are thesame and can be inconsistent with the supplied token amount order. Also it determiners if the supplied prices are inverted.

My recent fix to the quotePositionRoute endpoint on Pancakswap in this pr is proof that order of supplied token is different from the pool's for WBNB-USDT

@fengtality
Copy link
Contributor

@vic-en The functions you are referring to shouldn't be inconsistent, since the poolInfo in the first step is used to fetch the poolInfo where the baseTokenObj and quoteTokenObj come from, so they are for the pool, not what the user provided:

  if (poolType === 'amm') {
    return getV2PoolInfo(poolAddress, network);
  } else if (poolType === 'clmm') {
    return getV3PoolInfo(poolAddress, network);
  }

I agree that this code is confusing. I had AI do most of the Uniswap connector, which is why I appreciate the help in cleaning it up along with the Uniswap fixes.

What I'm saying is that adding quote and base token symbols to the add-liquidity routes in the CLMM schema shouldn't be necessary, since the symbols are used only to fetch the right pool address. Once we have the pool, we just need to track if the user's base token is token0 or token1 and carry that logic throughout the connector. I think Raydium has the correct behavior:

    // If no pool address provided, find default pool using base and quote tokens
    let poolAddressToUse = poolAddress;
    if (!poolAddressToUse) {
      if (!baseTokenSymbol || !quoteTokenSymbol) {
        throw new Error('Either poolAddress or both baseToken and quoteToken must be provided');
      }

      poolAddressToUse = await raydium.findDefaultPool(baseTokenSymbol, quoteTokenSymbol, 'clmm');
      if (!poolAddressToUse) {
        throw new Error(`No CLMM pool found for pair ${baseTokenSymbol}-${quoteTokenSymbol}`);
      }
    }

    const [poolInfo] = await raydium.getClmmPoolfromAPI(poolAddressToUse);
    const rpcData = await raydium.getClmmPoolfromRPC(poolAddressToUse);

@nikspz
Copy link
Contributor

nikspz commented Sep 16, 2025

Could you check why add liquidity gives wrong amount @vic-en?

  • PR7772 commit d289e93 + gw509 commit 97c2380
    • gateway connect ethereum: ok
    • gateway config ethereum update
      • defaultNetwork
        • updated to bsc
    • gateway config ethereum-bsc update
    • gateway balance: ok
    • gateway allowance pancakeswap: ok
    • gateway swap pancakeswap/clmm
    • ateway pool pancakeswap/clmm ETH-USDT ❌
      • Fetching pool information for ETH-USDT on pancakeswap/clmm...
      • Error fetching pool information: Error on GET http://localhost:15888/pools/ETH-USDT Error: {'message': 'Pool for ETH-USDT not found in pancakeswap clmm on bsc'}
    • gateway pool pancakeswap/clmm ETH-USDT update ❌
      • 0xbe141893e4c6ad9272e8c04bab7e6a10604501a5
      • Yes
      • Error updating pool: Error on POST http://localhost:15888/pools Error: {'message': 'Unknown connector: pancakeswap'}
      • image
    • gateway pool pancakeswap/amm ETH-USDT ❌
    • gateway approve pancakeswap/clmm ETH: ok, added when checked allowances
    • check pool using swagger: ✅
      • GET /connectors/pancakeswap/clmm/pool-info ✅
        • 0xbe141893e4c6ad9272e8c04bab7e6a10604501a5
        • {
          "address": "0xbe141893e4c6ad9272e8c04bab7e6a10604501a5",
          "baseTokenAddress": "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
          "quoteTokenAddress": "0x55d398326f99059fF775485246999027B3197955",
          "binStep": 10,
          "feePct": 0.05,
          "price": 4471.6594736797,
          "baseTokenAmount": 881622.2421005132,
          "quoteTokenAmount": 881622.2421005132,
          "activeBinId": 84059
          }
      • POST /connectors/pancakeswap/clmm/open-position ✅
        • 0xbe141893e4c6ad9272e8c04bab7e6a10604501a5
        • {
          "signature": "0x03fda83e87f2695af0e35fd3f681c6baecdb9eade9d1c6fdbc017e2d6cdd7280",
          "status": 1,
          "data": {
          "fee": 0.0000398358,
          "positionAddress": "4077031",
          "positionRent": 0,
          "baseTokenAmountAdded": 0.000437455303103683,
          "quoteTokenAmountAdded": 8.8
          }
          }
      • GET /connectors/pancakeswap/clmm/position-info: ok ✅
      • POST /connectors/pancakeswap/clmm/close-position: ok ✅
      • POST /connectors/pancakeswap/clmm/open-position: ETH-USDT ok, added correct amount ✅
        • {
          "signature": "0x54831974e28600a88971a25cbfb0cdea912968fd51939cb548226a339e3e28b4",
          "status": 1,
          "data": {
          "fee": 0.0000401524,
          "positionAddress": "4077344",
          "positionRent": 0,
          "baseTokenAmountAdded": 0.000929765489935645,
          "quoteTokenAmountAdded": 4.48
          }
          }
      • changed gas price to 5000000000
      • POST /connectors/pancakeswap/clmm/add-liquidity: ❌ showed added, but actual liquidity not changed
        • {
          "signature": "0x85ae5d5d0ae64a8e10c8aa1a821c8d451a3f17eaaa7b692dbbcc70c6342df342",
          "status": 1,
          "data": {
          "fee": 0.001010675,
          "baseTokenAmountAdded": 0.0005,
          "quoteTokenAmountAdded": 8.9169597336e-8
          }
          }
      • POST /connectors/pancakeswap/clmm/close-position: ok ✅
      • POST /connectors/pancakeswap/clmm/open-position ✅
        • image
        • image
      • POST /connectors/pancakeswap/clmm/add-liquidity

image image

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 16, 2025

@nikspz The tx showed that the add liquidity was successful for


    {
    "signature": "0x85ae5d5d0ae64a8e10c8aa1a821c8d451a3f17eaaa7b692dbbcc70c6342df342",
    "status": 1,
    "data": {
    "fee": 0.001010675,
    "baseTokenAmountAdded": 0.0005,
    "quoteTokenAmountAdded": 8.9169597336e-8
    }
    }

https://bscscan.com/tx/0x85ae5d5d0ae64a8e10c8aa1a821c8d451a3f17eaaa7b692dbbcc70c6342df342#eventlog
You can see in log event 55 that the position was first created because it didn't exist and liquidity was added in event 56.

Also note that you should ideally execute open-position before adding-liquidity

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 16, 2025

gateway pool pancakeswap/amm ETH-USDT ❌

    Fetching pool information for ETH-USDT on pancakeswap/amm...
    01:17:46 - gateway_http_client - Call to http://localhost:15888/pools/ETH-USDT Error fetching pool information: Error on GET http://localhost:15888/pools/ETH-USDT Error: {'message': 'Pool for ETH-USDT not found in pancakeswap amm on bsc'}
I'll address in https://github.com/hummingbot/hummingbot/pull/7772

@fengtality
Copy link
Contributor

@nikspz I discussed Pancakeswap with @vic-en, and we reached agreement that the CLMM and AMM schemas should be revised to address the issues raised above. See #513 for more details.

Since this is an existing issue with other connectors like Raydium and Uniswap and a larger change is needed, I think we should merge in Pancakeswap for v2.9 release. Victor will apply the fix to Pancakeswap and Uniswap for the next release, and I'll do the same for the other connectors.

@nikspz
Copy link
Contributor

nikspz commented Sep 17, 2025

Most Part of the PR merged in #508
@vic-en do you think we should create separate PR for the other issues here #513 ?

@fengtality
Copy link
Contributor

@vic-en I created #513 for the remaining changes we discussed, but I had a chance to discuss with @cardosofede today and he brought up some good points re: design.

We might be able to keep the endpoint design simpler if there are some user interface changes in the client. I'll do some testing and propose an updated design for 513 for next release. Let's keep this PR open till then.

@fengtality fengtality changed the title Feat/pancakeswap Feat/pancakeswap - remaining CLMM schema changes Sep 17, 2025
@vic-en
Copy link
Collaborator Author

vic-en commented Sep 17, 2025

@fengtality noted.

@rapcmia rapcmia moved this from Under Review to Backlog in Pull Request Board Sep 18, 2025
@vic-en
Copy link
Collaborator Author

vic-en commented Sep 22, 2025

@nikspz Am I missing something? I think the schema is already present. Let me know. Thanks.

@fengtality
Copy link
Contributor

We might be able to keep the endpoint design simpler if there are some user interface changes in the client. I'll do some testing and propose an updated design for 513 for next release. Let's keep this PR open till then

@vic-en see my comment above

@vic-en
Copy link
Collaborator Author

vic-en commented Sep 22, 2025

@fengtality Got it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants