Repository navigation
fix(pancakeswap): CLMM execute-swap fails with "Cannot convert ... to a BigInt" - #725
Closed
fengtality wants to merge 1 commit into
Closed
fengtality wants to merge 1 commit into
fengtality wants to merge 1 commit into
Conversation
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.
[Critical impact] The PR appears safe to merge. SummaryReplaces the PancakeSwap CLMM price encoder with
Reviews (1) · Last reviewed commit: "fix(pancakeswap): send CLMM swaps with n..." · Reviewed by Greptile |
Contributor
Author
|
Bundled into #735 with the other fix PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #713.
Cause
src/connectors/pancakeswap/clmm-routes/executeSwap.tssetsqrtPriceLimitX96withencodeSqrtRatioX96from@uniswap/v3-sdk, givenquote.trade.executionPrice.numerator/denominator. A PancakeSwap SDKPriceholds nativebigintvalues. The Uniswap encoder callsJSBI.BigInt(arg), which accepts numbers, strings, booleans and objects, and throwsTypeError: Cannot convert <value> to a BigIntfor a native bigint. So every PancakeSwap CLMM swap (Ethereum and BSC) failed before it was sent. Reproduced directly: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 onamountOutMinimum/amountInMaximumfrom 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
test/connectors/pancakeswap/clmm-routes/execute-swap.test.ts: SELL and BUY with a real PancakeSwap SDKPricebuilt from the issue's numerator. Both fail ondevelopmentwith the exact error from the issue, and pass with the fix.test/connectors/pancakeswap: 14 suites, 58 tests pass.🤖 Generated with Claude Code