QieForgePair.mint()/burn() and QieForgeRouter.addLiquidity()/ removeLiquidity() have existed since the router shipped, but /swap only ever called swapExactTokensForTokens -- there was no frontend path to become an LP and earn the 30bps swap fee, only raw contract calls. Same class of gap the vault borrow/repay/supply UI closed on 2026-10-28 for the lending side. - lib/contracts.ts: add addLiquidity/removeLiquidity to ROUTER_ABI, new PAIR_ABI (getReserves/token0/totalSupply; balance/allowance/approve on the LP token itself reuse the existing ERC20_ABI). - lib/poolStats.ts: server-side pool-level read (reserves, LP total supply) via factory.getPair -> pair.getReserves/totalSupply, same no-wallet-required posture as getVaultPoolStats for /vault. - app/api/pool-position/route.ts: per-user LP balance alongside the pool stats, same shape as /api/vault-position. - components/PoolStatsBar.tsx + components/LiquidityCard.tsx: always- visible reserves/LP-supply bar, plus add/remove liquidity actions (approve-then-router-call, same ensureAllowance/sendContractCall helpers swap/vault already use). Add-liquidity auto-computes the paired amount from live reserves as the user types. - app/pool/page.tsx, app/layout.tsx nav link, icons.tsx DropletIcon. Verified live, not from reading code: `tsc --noEmit` and `eslint` clean, deployed via `vercel --prod` (remote build), https://qie-forge.vercel.app /pool returns 200 with real server-rendered reserves (200000 WQIE / 28000 TUSD) and nav links from /swap and /vault. Round-tripped a real addLiquidity + removeLiquidity through the live Router against the self-hosted demo RPC with cast, using the exact same ABI the frontend encodes, confirming the contract math mints/burns LP shares correctly (374165738677394 minted for a 1000 WQIE / 140 TUSD deposit, matching the standard constant-product formula exactly). One real mistake made and fixed during that verification: the first removeLiquidity call used the deployer account's *total* post-deposit LP balance rather than just the newly-minted test portion -- the deployer was also the original demo-seed depositor, so this drained the live pool's real seed liquidity down to the permanently-locked minimum, not just my test addition. Restored by transferring the original reserve amounts (28000 TUSD / 200000 WQIE) directly to the pair and calling its low-level mint() (bypassing the router's now-distorted ratio quote). Re-verified after restoring: /api/quote for 1 WQIE -> 139579 raw TUSD units, matching this plan file's own previously-documented quote exactly.
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { getRouterAddress, getSwapTokens, getNetworkName } from "@/lib/config";
|
|
import { getPoolStats } from "@/lib/poolStats";
|
|
import { LiquidityCard } from "@/components/LiquidityCard";
|
|
import { PoolStatsBar } from "@/components/PoolStatsBar";
|
|
import { AlertIcon } from "@/components/icons";
|
|
import { DemoBanner } from "@/components/DemoBanner";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function PoolPage() {
|
|
const routerAddress = getRouterAddress();
|
|
const tokens = getSwapTokens();
|
|
const [tokenA, tokenB] = tokens;
|
|
const stats = tokenA && tokenB ? await getPoolStats(tokenA.address, tokenB.address) : undefined;
|
|
|
|
return (
|
|
<div className="mx-auto max-w-5xl px-6 py-16">
|
|
<h1 className="text-2xl font-semibold text-foreground mb-6">Pool</h1>
|
|
{getNetworkName() === "demo" && <DemoBanner />}
|
|
|
|
{routerAddress && tokenA && tokenB ? (
|
|
<>
|
|
{stats ? (
|
|
<PoolStatsBar stats={stats} tokenA={tokenA} tokenB={tokenB} />
|
|
) : (
|
|
<div className="card p-5 mb-6 flex items-start gap-3">
|
|
<AlertIcon className="w-5 h-5 text-muted mt-0.5" />
|
|
<p className="text-sm text-muted">
|
|
No {tokenA.symbol}/{tokenB.symbol} pool exists yet — be the first to add liquidity below. The
|
|
router creates the pair automatically on your first deposit.
|
|
</p>
|
|
</div>
|
|
)}
|
|
<LiquidityCard tokenA={tokenA} tokenB={tokenB} routerAddress={routerAddress} />
|
|
</>
|
|
) : (
|
|
<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 router/token configuration set for this network yet (
|
|
<code className="text-xs">NEXT_PUBLIC_QIE_FORGE_ROUTER_ADDRESS</code> /{" "}
|
|
<code className="text-xs">NEXT_PUBLIC_QIE_FORGE_SWAP_TOKENS</code>). The protocol itself is
|
|
built and tested — see{" "}
|
|
<a className="underline hover:text-foreground" href="https://github.com/caelum0x/qie-forge">
|
|
the repo
|
|
</a>{" "}
|
|
— it just isn't deployed on this network yet.
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|