caelum0x 1775ca85b5 feat: add a liquidity provider UI for the AMM pool (/pool)
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.
2026-10-29 02:14:42 +03:00

84 lines
2.7 KiB
TypeScript

/** Minimal inline line icons — no emoji, no icon-font dependency. Matches
* this portfolio's standing mobile/web design mandate: icon-first,
* restrained, monochrome (inherits currentColor). */
type IconProps = { className?: string };
const base = "w-4 h-4";
export function WalletIcon({ className = base }: IconProps) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" className={className}>
<rect x="3" y="6" width="18" height="13" rx="2" />
<path d="M3 10h18" />
<path d="M16 14h2" />
</svg>
);
}
export function SwapIcon({ className = base }: IconProps) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" className={className}>
<path d="M7 7h11l-3-3" />
<path d="M18 7l-3 3" />
<path d="M17 17H6l3 3" />
<path d="M6 17l3-3" />
</svg>
);
}
export function ShieldIcon({ className = base }: IconProps) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" className={className}>
<path d="M12 3l7 3v6c0 5-3 7.5-7 9-4-1.5-7-4-7-9V6l7-3z" />
</svg>
);
}
export function ExternalLinkIcon({ className = base }: IconProps) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" className={className}>
<path d="M7 17L17 7" />
<path d="M9 7h8v8" />
</svg>
);
}
export function ChevronDownIcon({ className = base }: IconProps) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" className={className}>
<path d="M6 9l6 6 6-6" />
</svg>
);
}
export function CoinsIcon({ className = base }: IconProps) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" className={className}>
<ellipse cx="9" cy="7" rx="6" ry="3" />
<path d="M3 7v4c0 1.66 2.69 3 6 3s6-1.34 6-3V7" />
<path d="M3 11v4c0 1.66 2.69 3 6 3s6-1.34 6-3v-4" />
<path d="M15 10c3.31 0 6 1.34 6 3s-2.69 3-6 3" />
<path d="M21 13v4c0 1.66-2.69 3-6 3" />
</svg>
);
}
export function DropletIcon({ className = base }: IconProps) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" className={className}>
<path d="M12 3C9 7 6 10.5 6 14a6 6 0 0012 0c0-3.5-3-7-6-11z" />
</svg>
);
}
export function AlertIcon({ className = base }: IconProps) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.75" className={className}>
<path d="M12 9v4" />
<path d="M12 17h.01" />
<path d="M10.3 3.9L2.5 17a1.5 1.5 0 001.3 2.2h16.4a1.5 1.5 0 001.3-2.2L13.7 3.9a1.5 1.5 0 00-2.4 0z" />
</svg>
);
}