cred402/cli/commands/market.ts
caelum0x 2d43618725 feat: real integrations (Casper Testnet, x402/EIP-712, MCP, RealFi, cross-chain), wallet sign-in, branding
Replace the design-note docs (p1–p7) with the implemented "make it real" phase
docs (p8–p10) and wire production-grade, env-gated real integrations:

- p8 Casper Testnet: byte-exact deploys + WASM install via casper-js-sdk; live
  node reads (node.testnet.casper.network); CRED402_CHAIN=sim|testnet transport.
- p9 x402 + data + MCP: real EIP-712 typed-data digests (@casper-ecosystem/
  casper-eip-712); casper-x402 facilitator client (x402 V2); live Open-Meteo GHI;
  official @modelcontextprotocol/sdk server; casper-sidecar SSE event feed.
- p10 RealFi + cross-chain: real Stripe test-mode webhooks (HMAC-verified) and
  Plaid sandbox → privacy-preserving on-chain envelopes; Base Sepolia EVM deploy
  (Foundry); reachable via /api/realfi/* and /api/x402/facilitator routes.
- Sign-in with Casper Wallet: real extension provider + challenge/ed25519/session
  flow (/v1/auth/wallet/*), console connect + sign-in button.
- Branding: Cred402 logo mark, favicon, OG image; Vercel config for the console.

All env-gated with sim/free-API fallbacks; full suite green, all toolchains
(TS/Rust/Go/Solidity) build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 00:37:36 +03:00

76 lines
1.9 KiB
TypeScript

/**
* `market` command group: list marketplace service listings.
*/
import { type CommandContext, emit, UsageError } from "../lib/context.js";
import { color, formatBps, formatCspr, formatRatio, heading, table } from "../lib/render.js";
interface Listing {
listing_id: string;
agent_id: string;
category: string;
strategy: string;
base_price: string;
min_payment: string;
margin_bps: number;
reputation_score: number;
dispute_rate: number;
receipt_count: number;
stake: string;
supported_chains: string[];
}
const USAGE = `market — agent service marketplace
Usage:
cred402 market list`;
export async function marketCommand(ctx: CommandContext): Promise<void> {
const sub = ctx.args[0];
switch (sub) {
case "list":
case undefined:
return list(ctx);
case "--help":
case "-h":
process.stdout.write(USAGE + "\n");
return;
default:
throw new UsageError(`unknown subcommand: market ${sub}\n\n${USAGE}`);
}
}
async function list(ctx: CommandContext): Promise<void> {
const listings = await ctx.client.get<Listing[]>("/api/marketplace");
emit(ctx, listings, () => {
const rows = listings.map((l) => [
color.bold(l.listing_id),
l.agent_id,
l.category,
l.strategy,
formatCspr(l.base_price),
formatBps(l.margin_bps),
String(l.reputation_score),
formatRatio(l.dispute_rate),
l.supported_chains.join(","),
]);
return (
heading(`Marketplace Listings (${listings.length})`) +
"\n" +
table(
[
{ header: "LISTING" },
{ header: "AGENT" },
{ header: "CATEGORY" },
{ header: "STRATEGY" },
{ header: "PRICE", align: "right" },
{ header: "MARGIN", align: "right" },
{ header: "REP", align: "right" },
{ header: "DISPUTE", align: "right" },
{ header: "CHAINS" },
],
rows,
)
);
});
}