/vault previously rendered nothing but two "Connect Wallet" buttons for any visitor without a browser wallet extension -- including any hackathon judge reviewing the live site headlessly. The underlying /api/vault-position route requires a `user` address and 400s without one, even though totalAssets/ totalDebtPrincipal/totalLenderShares are global contract state, not per-user. Add a server-rendered VaultPoolStatsBar (TVL, idle liquidity, outstanding debt, utilization) fetched directly on the server via a new getVaultPoolStats() helper, same no-wallet-required pattern already used by the homepage's live network/oracle data and /swap's quote box -- /vault was the one page that didn't follow it. Verified: tsc --noEmit and eslint clean; cast call against the live demo vault (0x851356...91C on the self-hosted anvil RPC) confirms the real numbers the new component will render: totalAssets=500000000000, totalDebtPrincipal= 20000000000, totalLenderShares=1000 (500,000 TUSD TVL, 20,000 TUSD debt, 4% utilization, 480,000 TUSD idle) -- matches docs/STATUS.md's documented demo position exactly.
76 lines
2.8 KiB
TypeScript
76 lines
2.8 KiB
TypeScript
import {
|
|
getVaultAddress,
|
|
getNetworkName,
|
|
getVaultCollateralSymbol,
|
|
getVaultBorrowAddress,
|
|
getVaultBorrowDecimals,
|
|
getVaultBorrowSymbol,
|
|
} from "@/lib/config";
|
|
import { getVaultPoolStats } from "@/lib/vaultStats";
|
|
import { VaultCard } from "@/components/VaultCard";
|
|
import { LendCard } from "@/components/LendCard";
|
|
import { VaultPoolStatsBar } from "@/components/VaultPoolStatsBar";
|
|
import { AlertIcon } from "@/components/icons";
|
|
import { DemoBanner } from "@/components/DemoBanner";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function VaultPage() {
|
|
const vaultAddress = getVaultAddress();
|
|
const poolStats = await getVaultPoolStats();
|
|
const collateralAddress = process.env.NEXT_PUBLIC_QIE_FORGE_VAULT_COLLATERAL_ADDRESS as
|
|
| `0x${string}`
|
|
| undefined;
|
|
const collateralDecimals = Number(process.env.NEXT_PUBLIC_QIE_FORGE_VAULT_COLLATERAL_DECIMALS ?? 18);
|
|
const collateralSymbol = getVaultCollateralSymbol();
|
|
const borrowAddress = getVaultBorrowAddress();
|
|
const borrowDecimals = getVaultBorrowDecimals();
|
|
const borrowSymbol = getVaultBorrowSymbol();
|
|
|
|
return (
|
|
<div className="mx-auto max-w-5xl px-6 py-16">
|
|
<h1 className="text-2xl font-semibold text-foreground mb-6">Lending Vault</h1>
|
|
{getNetworkName() === "demo" && <DemoBanner />}
|
|
|
|
{poolStats && borrowAddress && (
|
|
<VaultPoolStatsBar stats={poolStats} borrowDecimals={borrowDecimals} borrowSymbol={borrowSymbol} />
|
|
)}
|
|
|
|
{vaultAddress && collateralAddress ? (
|
|
<div className="flex flex-wrap gap-6">
|
|
<VaultCard
|
|
vaultAddress={vaultAddress}
|
|
collateralAddress={collateralAddress}
|
|
collateralDecimals={collateralDecimals}
|
|
collateralSymbol={collateralSymbol}
|
|
borrowAddress={borrowAddress}
|
|
borrowDecimals={borrowDecimals}
|
|
borrowSymbol={borrowSymbol}
|
|
/>
|
|
{borrowAddress && (
|
|
<LendCard
|
|
vaultAddress={vaultAddress}
|
|
borrowAddress={borrowAddress}
|
|
borrowDecimals={borrowDecimals}
|
|
borrowSymbol={borrowSymbol}
|
|
/>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<div className="card p-6 max-w-md flex items-start gap-3">
|
|
<AlertIcon className="w-5 h-5 text-muted mt-0.5" />
|
|
<p className="text-sm text-muted">
|
|
No vault configured for this network yet (
|
|
<code className="text-xs">NEXT_PUBLIC_QIE_FORGE_VAULT_ADDRESS</code>). The vault contract
|
|
itself — deposit, borrow, health factor, liquidation, lender shares — is built and tested; see{" "}
|
|
<a className="underline hover:text-foreground" href="https://github.com/caelum0x/qie-forge/blob/main/packages/contracts/src/vault/QieForgeVault.sol">
|
|
QieForgeVault.sol
|
|
</a>
|
|
.
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|