Skip to content

Commit f2dff68

Browse files
authored
fix: pancake pool price (#2901)
* fix: pancake pool price * fix version
1 parent 02a43c1 commit f2dff68

File tree

5 files changed

+44
-39
lines changed

5 files changed

+44
-39
lines changed

packages/pancake-liquidity-widgets/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kyberswap/pancake-liquidity-widgets",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"license": "MIT",
55
"type": "module",
66
"exports": {

packages/pancake-liquidity-widgets/src/components/Content/EstLiqValue.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
import { useMemo } from "react";
3232
import { NetworkInfo } from "@/constants";
3333
import defaultTokenLogo from "@/assets/question.svg?url";
34-
import { tickToPrice } from "@kyber/utils/uniswapv3";
34+
import { sqrtToPrice } from "@kyber/utils/uniswapv3";
3535

3636
export default function EstLiqValue() {
3737
const { zapInfo, source, marketPrice, revertPrice, tokensIn } = useZapState();
@@ -249,8 +249,8 @@ export default function EstLiqValue() {
249249
newPool &&
250250
Math.abs(
251251
marketPrice /
252-
+tickToPrice(
253-
newPool.tickCurrent,
252+
+sqrtToPrice(
253+
BigInt(newPool.sqrtRatioX96 || 0),
254254
newPool.token0.decimals,
255255
newPool.token1.decimals,
256256
false
@@ -265,8 +265,8 @@ export default function EstLiqValue() {
265265
: false;
266266

267267
const price = newPool
268-
? tickToPrice(
269-
newPool.tickCurrent,
268+
? sqrtToPrice(
269+
BigInt(newPool.sqrtRatioX96 || 0),
270270
newPool.token0.decimals,
271271
newPool.token1.decimals,
272272
revertPrice

packages/pancake-liquidity-widgets/src/components/Content/PriceInfo.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useWidgetInfo } from "@/hooks/useWidgetInfo";
22
import { useZapState } from "@/hooks/useZapInState";
33
import { formatNumber } from "@/utils";
44
import SwitchIcon from "@/assets/switch.svg";
5-
import { tickToPrice } from "@kyber/utils/uniswapv3";
5+
import { sqrtToPrice } from "@kyber/utils/uniswapv3";
66
import { formatDisplayNumber } from "@kyber/utils/number";
77

88
export default function PriceInfo() {
@@ -12,8 +12,8 @@ export default function PriceInfo() {
1212
if (loading) return <div className="text-textSecondary">Loading...</div>;
1313

1414
const poolPrice = pool
15-
? tickToPrice(
16-
pool.tickCurrent,
15+
? sqrtToPrice(
16+
BigInt(pool.sqrtRatioX96 || 0),
1717
pool.token0?.decimals,
1818
pool.token1?.decimals,
1919
revertPrice
@@ -25,8 +25,8 @@ export default function PriceInfo() {
2525
pool &&
2626
Math.abs(
2727
marketPrice /
28-
+tickToPrice(
29-
pool.tickCurrent,
28+
+sqrtToPrice(
29+
BigInt(pool.sqrtRatioX96 || 0),
3030
pool.token0.decimals,
3131
pool.token1.decimals,
3232
false

packages/pancake-liquidity-widgets/src/components/Content/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
POSITION_MANAGER_CONTRACT,
3636
CoreProtocol,
3737
} from "@/constants";
38-
import { tickToPrice } from "@kyber/utils/uniswapv3";
38+
import { sqrtToPrice } from "@kyber/utils/uniswapv3";
3939
import { useNftApproval } from "@/hooks/useNftApproval";
4040

4141
export default function Content({
@@ -275,8 +275,8 @@ export default function Content({
275275
}, [snapshotState, onTogglePreview]);
276276

277277
const currentPoolPrice = pool
278-
? tickToPrice(
279-
pool.tickCurrent,
278+
? sqrtToPrice(
279+
BigInt(pool.sqrtRatioX96 || 0),
280280
pool.token0.decimals,
281281
pool.token1.decimals,
282282
revertPrice

packages/pancake-liquidity-widgets/src/components/Preview/index.tsx

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {
4444
AccordionTrigger,
4545
} from "@kyber/ui";
4646
import defaultTokenLogo from "@/assets/question.svg?url";
47-
import { tickToPrice } from "@kyber/utils/uniswapv3";
47+
import { sqrtToPrice } from "@kyber/utils/uniswapv3";
4848
import { formatDisplayNumber } from "@kyber/utils/number";
4949
import { fetchTokenPrice } from "@kyber/utils";
5050

@@ -183,8 +183,8 @@ export default function Preview({
183183
0;
184184

185185
const price = pool
186-
? tickToPrice(
187-
pool.tickCurrent,
186+
? sqrtToPrice(
187+
BigInt(pool.sqrtRatioX96 || 0),
188188
pool.token0.decimals,
189189
pool.token1.decimals,
190190
revert
@@ -623,29 +623,34 @@ export default function Preview({
623623
<div className="pcs-lw-card mt-4 border border-inputBorder bg-inputBackground">
624624
<div>Zap-in Amount</div>
625625

626-
{tokensIn.map((token: PancakeTokenAdvanced, index: number) => (
627-
<div
628-
className="flex items-center gap-3 text-sm text-textSecondary mt-2"
629-
key={index}
630-
>
631-
<img
632-
src={token.logoURI}
633-
className="w-[18px] h-[18px]"
634-
onError={({ currentTarget }) => {
635-
currentTarget.onerror = null;
636-
currentTarget.src = defaultTokenLogo;
637-
}}
638-
/>
639-
<div className="text-textPrimary text-base">
640-
{formatNumber(+listAmountsIn[index])} {token.symbol}
641-
<span className="text-textSecondary font-normal text-sm ml-2">
642-
{formatCurrency(
643-
(token.price || 0) * parseFloat(listAmountsIn[index])
644-
)}
645-
</span>
626+
{tokensIn.map((token: PancakeTokenAdvanced, index: number) => {
627+
const amount = listAmountsIn[index];
628+
if (!amount) return null;
629+
630+
return (
631+
<div
632+
className="flex items-center gap-3 text-sm text-textSecondary mt-2"
633+
key={index}
634+
>
635+
<img
636+
src={token.logoURI}
637+
className="w-[18px] h-[18px] rounded-full"
638+
onError={({ currentTarget }) => {
639+
currentTarget.onerror = null;
640+
currentTarget.src = defaultTokenLogo;
641+
}}
642+
/>
643+
<div className="text-textPrimary text-base">
644+
{formatNumber(+listAmountsIn[index])} {token.symbol}
645+
<span className="text-textSecondary font-normal text-sm ml-2">
646+
{formatCurrency(
647+
(token.price || 0) * parseFloat(listAmountsIn[index])
648+
)}
649+
</span>
650+
</div>
646651
</div>
647-
</div>
648-
))}
652+
);
653+
})}
649654
</div>
650655

651656
<div className="pcs-lw-card mt-3 text-sm">

0 commit comments

Comments
 (0)