// A tiny in memory stand in for the LAX registry write routes, used to test the fee gate end to end.
import { createFeeGate, type Quote } from "../src/index.js";
export function createRegistry(opts: { mint: string; payee: string }) {
const quotes = new Map<string, Quote>();
const seen = new Set<string>();
const offers: unknown[] = [];
const bids: unknown[] = [];
const gate = createFeeGate({ mint: opts.mint, payee: opts.payee, store: { getQuote: (id) => quotes.get(id), seen } });
function handle(method: string, path: string, body: any): { status: number; body: any } {
if (method !== "POST") return { status: 405, body: { error: "method" } };
const isOffer = path === "/offers";
const isBid = /^\/jobs\/[^/]+\/bids$/.test(path);
if (!isOffer && !isBid) return { status: 404, body: { error: "not_found" } };
const fee = gate(body?.fee);
if (!fee.ok) return { status: 402, body: { error: "fee_required", reason: fee.reason } };
(isOffer ? offers : bids).push(body.item);
return { status: 201, body: { accepted: true, signature: fee.signature } };
}
return { quotes, seen, offers, bids, handle };
}
agentgate-source: code mirror on Cloudflare Pages. All repos