Skip to content

fix(pancakeswap): CLMM execute-swap fails with "Cannot convert ... to a BigInt" - #725

Closed
fengtality wants to merge 1 commit into
developmentfrom
fix/pancakeswap-clmm-bigint
Closed

fengtality wants to merge 1 commit into
developmentfrom
fix/pancakeswap-clmm-bigint

Conversation

@fengtality

Copy link
Copy Markdown
Contributor

Closes #713.

Cause

src/connectors/pancakeswap/clmm-routes/executeSwap.ts set sqrtPriceLimitX96 with encodeSqrtRatioX96 from @uniswap/v3-sdk, given quote.trade.executionPrice.numerator/denominator. A PancakeSwap SDK Price holds native bigint values. The Uniswap encoder calls JSBI.BigInt(arg), which accepts numbers, strings, booleans and objects, and throws TypeError: Cannot convert <value> to a BigInt for a native bigint. So every PancakeSwap CLMM swap (Ethereum and BSC) failed before it was sent. Reproduced directly:

new Price(WBNB, USDT, 10n**18n, 999429662315995114n).numerator  // typeof 'bigint'
encodeSqrtRatioX96(p.numerator, p.denominator)
// TypeError: Cannot convert 999429662315995114 to a BigInt

Fix

Pass sqrtPriceLimitX96: '0' (no limit), as the Uniswap CLMM route does since bb44ffd. Encoding the trade's average execution price as a limit is wrong too: the pool's price crosses that average partway through the swap, so it would partial-fill and revert on the min-out check. Slippage protection stays on amountOutMinimum / amountInMaximum from the quote.

The same change is inside #680 (and #647), which bundle it with the MasterChef staking work. This PR is the minimal fix for #713 alone; credit to those PRs for spotting it.

Tests

  • New test/connectors/pancakeswap/clmm-routes/execute-swap.test.ts: SELL and BUY with a real PancakeSwap SDK Price built from the issue's numerator. Both fail on development with the exact error from the issue, and pass with the fix.
  • test/connectors/pancakeswap: 14 suites, 58 tests pass.

🤖 Generated with Claude Code

The PancakeSwap CLMM execute-swap route encoded the quote's execution
price with @uniswap/v3-sdk encodeSqrtRatioX96. A PancakeSwap SDK Price
holds native bigints, and the Uniswap encoder's JSBI.BigInt rejects them,
so every swap failed before it was sent with
"Cannot convert <numerator> to a BigInt".

Pass 0 (no price limit), as the Uniswap CLMM route does since bb44ffd.
The average execution price is not a valid limit anyway: the pool price
crosses it partway through the swap. Slippage protection stays on
amountOutMinimum / amountInMaximum from the quote.
@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Critical impact] The PR appears safe to merge.

Summary

Replaces the PancakeSwap CLMM price encoder with sqrtPriceLimitX96: '0', avoiding the native-bigint conversion error.

  • PancakeSwap CLMM swaps run without a separate price limit.

Reviews (1) · Last reviewed commit: "fix(pancakeswap): send CLMM swaps with n..." · Reviewed by Greptile

@fengtality

Copy link
Copy Markdown
Contributor Author

Bundled into #735 with the other fix PRs.

@fengtality fengtality closed this Oct 20, 2026
@fengtality
fengtality deleted the fix/pancakeswap-clmm-bigint branch October 20, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant