adding prices of pools

This commit is contained in:
2025-11-11 17:45:00 -04:00
parent 732dfd7780
commit fea441b4e7
2 changed files with 47 additions and 6 deletions

View File

@@ -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) {