Skip to content

Commit

Permalink
fix: Invalid variable assignment in maxLiquidityForAmounts (#10196)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirname authored Jul 15, 2024
1 parent 3e1fa25 commit 911d107
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-flowers-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pancakeswap/v3-sdk': patch
---

Fix invalid assignment in max liquidity for amounts
12 changes: 4 additions & 8 deletions packages/v3-sdk/src/utils/maxLiquidityForAmounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { Q96 } from '../internalConstants'
*/
function maxLiquidityForAmount0Imprecise(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount0: BigintIsh): bigint {
if (sqrtRatioAX96 > sqrtRatioBX96) {
sqrtRatioAX96 = sqrtRatioBX96
sqrtRatioBX96 = sqrtRatioAX96
;[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96]
}
const intermediate = (sqrtRatioAX96 * sqrtRatioBX96) / Q96
return (BigInt(amount0) * intermediate) / (sqrtRatioBX96 - sqrtRatioAX96)
Expand All @@ -31,8 +30,7 @@ function maxLiquidityForAmount0Imprecise(sqrtRatioAX96: bigint, sqrtRatioBX96: b
*/
function maxLiquidityForAmount0Precise(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount0: BigintIsh): bigint {
if (sqrtRatioAX96 > sqrtRatioBX96) {
sqrtRatioAX96 = sqrtRatioBX96
sqrtRatioBX96 = sqrtRatioAX96
;[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96]
}

const numerator = BigInt(amount0) * sqrtRatioAX96 * sqrtRatioBX96
Expand All @@ -50,8 +48,7 @@ function maxLiquidityForAmount0Precise(sqrtRatioAX96: bigint, sqrtRatioBX96: big
*/
function maxLiquidityForAmount1(sqrtRatioAX96: bigint, sqrtRatioBX96: bigint, amount1: BigintIsh): bigint {
if (sqrtRatioAX96 > sqrtRatioBX96) {
sqrtRatioAX96 = sqrtRatioBX96
sqrtRatioBX96 = sqrtRatioAX96
;[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96]
}
return (BigInt(amount1) * Q96) / (sqrtRatioBX96 - sqrtRatioAX96)
}
Expand All @@ -76,8 +73,7 @@ export function maxLiquidityForAmounts(
useFullPrecision: boolean
): bigint {
if (sqrtRatioAX96 > sqrtRatioBX96) {
sqrtRatioAX96 = sqrtRatioBX96
sqrtRatioBX96 = sqrtRatioAX96
;[sqrtRatioAX96, sqrtRatioBX96] = [sqrtRatioBX96, sqrtRatioAX96]
}

const maxLiquidityForAmount0 = useFullPrecision ? maxLiquidityForAmount0Precise : maxLiquidityForAmount0Imprecise
Expand Down

0 comments on commit 911d107

Please sign in to comment.