create_pool refactor; test pool deployed; etc

This commit is contained in:
2026-05-10 17:57:45 -04:00
parent d31f99d330
commit e1d2acea0d
13 changed files with 2359 additions and 444 deletions

View File

@@ -8,6 +8,7 @@ import IPartyPoolABI from '@/contracts/IPartyPoolABI';
import IPartyPoolViewerABI from '@/contracts/IPartyPoolViewerABI';
import IPartyInfoABI from '@/contracts/IPartyInfoABI';
import { ERC20ABI } from '@/contracts/ERC20ABI';
import { fetchPoolMetrics } from '@/lib/poolMetricsCache';
// Helper function to format large numbers with K, M, B suffixes
function formatTVL(value: number): string {
@@ -444,6 +445,7 @@ export interface PoolDetails {
tokens: readonly `0x${string}`[];
price?: string; // Formatted price string
tvl?: string; // Formatted TVL string (e.g., "$1.2M")
apy?: string; // Formatted APY string (e.g., "3.25%")
isKilled: boolean; // Whether the pool has been killed
}
@@ -495,6 +497,9 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) {
setPools(result);
// Fetch Substreams pool metrics (cached for 1 hour)
const poolMetricsData = await fetchPoolMetrics();
// Fetch details for each pool and check if it's working
const details: PoolDetails[] = [];
for (const poolAddress of result) {
@@ -526,6 +531,7 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) {
// Fetch pool price and TVL (only for working pools)
let priceStr: string | undefined;
let tvlStr: string | undefined;
let apyStr: string | undefined;
if (isWorking) {
// Fetch token decimals and balance first (needed for both price and TVL)
@@ -567,10 +573,21 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) {
priceStr = `$${finalPrice.toFixed(4)}`;
}
// Calculate TVL (approximate by getting first token balance and multiplying by number of tokens)
const tokenBalance = Number(balance) / Math.pow(10, decimals);
const approximateTVL = tokenBalance * tokens.length;
tvlStr = formatTVL(approximateTVL);
// Use Substreams TVL + APY if available; fall back to on-chain estimate
const metricKey = poolAddress.toLowerCase().replace('0x', '');
const metric = poolMetricsData[metricKey];
if (metric) {
const tvlAdjusted = Number(BigInt(metric.quoteTvl)) / Math.pow(10, decimals);
tvlStr = formatTVL(tvlAdjusted);
if (metric.quoteApyBps > 0) {
apyStr = `${(metric.quoteApyBps / 100).toFixed(2)}%`;
}
} else {
// Fall back to on-chain estimate
const tokenBalance = Number(balance) / Math.pow(10, decimals);
const approximateTVL = tokenBalance * tokens.length;
tvlStr = formatTVL(approximateTVL);
}
}
} catch (err) {
console.error(`Error fetching pool price/TVL for ${poolAddress}:`, err);
@@ -587,6 +604,7 @@ export function useGetAllPools(offset: number = 0, limit: number = 100) {
tokens: tokens as readonly `0x${string}`[],
price: priceStr,
tvl: tvlStr,
apy: apyStr,
isKilled: !isWorking,
});
} catch (err) {