From fea441b4e73025c3cdee8022199e4905d262b973 Mon Sep 17 00:00:00 2001 From: surbhi Date: Tue, 11 Nov 2025 17:45:00 -0400 Subject: [PATCH] adding prices of pools --- src/components/stake-form.tsx | 22 ++++++++++++++++------ src/hooks/usePartyPlanner.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/components/stake-form.tsx b/src/components/stake-form.tsx index 84176e3..0547aee 100644 --- a/src/components/stake-form.tsx +++ b/src/components/stake-form.tsx @@ -340,9 +340,14 @@ export function StakeForm({ defaultMode = 'stake' }: StakeFormProps) { setSelectedToken(null); }} > -
- {pool.symbol} - {pool.name} +
+
+ {pool.symbol} + {pool.name} +
+ {pool.price && ( + {pool.price} + )}
)) @@ -390,9 +395,14 @@ export function StakeForm({ defaultMode = 'stake' }: StakeFormProps) { setSelectedToken(null); }} > -
- {pool.symbol} - {pool.name} +
+
+ {pool.symbol} + {pool.name} +
+ {pool.price && ( + {pool.price} + )}
)) diff --git a/src/hooks/usePartyPlanner.ts b/src/hooks/usePartyPlanner.ts index 5fe9740..5d4d322 100644 --- a/src/hooks/usePartyPlanner.ts +++ b/src/hooks/usePartyPlanner.ts @@ -333,6 +333,7 @@ export interface PoolDetails { name: string; symbol: string; tokens: readonly `0x${string}`[]; + price?: string; // Formatted price string } export function useGetAllPools(offset: number = 0, limit: number = 100) { @@ -413,11 +414,41 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) { // Only add pool if it's working if (isWorking) { + // Fetch pool price (use first token as quote, index 0) + let priceStr: string | undefined; + try { + const priceRaw = await publicClient.readContract({ + address: partyInfoAddress as `0x${string}`, + abi: IPartyInfoABI, + functionName: 'poolPrice', + args: [poolAddress, BigInt(0)], + }); + + const price = BigInt(priceRaw as bigint | number); + + if (price === 0n) { + priceStr = undefined; + } else { + // Convert Q64 format to decimal (price = priceValue / 2^64) + const Q64 = 2n ** 64n; + const isNegative = price < 0n; + const absPrice = isNegative ? -price : price; + const priceFloat = Number(absPrice) / Number(Q64); + const finalPrice = isNegative ? -priceFloat : priceFloat; + + priceStr = `$${finalPrice.toFixed(4)}`; + } + } catch (err) { + console.error(`Error fetching pool price for ${poolAddress}:`, err); + priceStr = undefined; + } + details.push({ address: poolAddress, name: name as string, symbol: symbol as string, tokens: tokens as readonly `0x${string}`[], + price: priceStr, }); } } catch (err) {