Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

3.7 KB
Raw Blame
/**
 * pump/first-claims.js
 * ---------------------
 * First-time creator fee claim data.
 *
 * Exports:
 *   filterFirstClaims(allClaims, sinceTs, limit) — pure dedupe, no I/O
 *   fetchFirstClaims({ sinceTs, limit })          — browser fetch → API
 *
 * "First-time" means the creator has no observed claim before sinceTs.
 * allClaims must span a wider lookback window so prior claimers are visible.
 */

const API_PATH = '/api/pump/first-claims';

/**
 * Pure dedupe: from a flat list of claims spanning a wide lookback window,
 * return only first-time claimers — creators whose earliest observed claim
 * falls at or after sinceTs (i.e. they have no prior claim in the dataset).
 *
 * @param {Array<{creator:string, mint:string, signature:string, lamports:number, ts:number}>} allClaims
 * @param {number} sinceTs  Unix seconds — boundary for "prior claim"
 * @param {number} [limit]
 * @returns {Array<{creator, mint, signature, lamports, ts}>} newest first
 */
export function filterFirstClaims(allClaims, sinceTs, limit = 50) {
	// Find each creator's earliest observed claim across the full dataset.
	const earliest = new Map();
	for (const c of allClaims) {
		const prev = earliest.get(c.creator);
		if (!prev || c.ts < prev.ts) earliest.set(c.creator, c);
	}

	const result = [];
	for (const firstClaim of earliest.values()) {
		// Exclude if the earliest claim predates sinceTs — they've claimed before.
		if (firstClaim.ts >= sinceTs) result.push(firstClaim);
	}

	return result.sort((a, b) => b.ts - a.ts).slice(0, limit);
}

/**
 * Browser entry point. Calls GET /api/pump/first-claims and returns
 * { items: [...] }.
 *
 * @param {{ sinceTs: number, limit?: number }} opts
 */
export async function fetchFirstClaims({ sinceTs, limit = 50 }) {
	const params = new URLSearchParams({
		sinceTs: String(sinceTs),
		limit: String(Math.min(50, Math.max(1, limit))),
	});
	const r = await fetch(`${API_PATH}?${params}`, { credentials: 'include' });
	if (!r.ok) throw new Error(`first-claims: ${r.status}`);
	return r.json();
}

/**
 * Pure view model for one claim card: a celebratory card for an ordinary or
 * attributed claim, a "held for review" card for one `pump-claims.js` flagged
 * as suspected impersonation. Consumed by the Telegram formatter
 * (`pump-claims-push.js`) and by any future rendered feed page, so the two
 * never drift on what a held claim looks like.
 *
 * @param {{creator:string, mint:string, signature:string, lamports:number, ts:number,
 *   githubUserId?:string, githubLogin?:string|null,
 *   attribution?:{label:string, headline:string, explanation:string},
 *   held?:boolean, heldReasons?:string[]}} claim
 * @returns {{
 *   state: 'held'|'attributed'|'claimed',
 *   title: string,
 *   subtitle: string,
 *   label: string|null,
 *   explanation: string|null,
 *   heldReasons: string[],
 * }}
 */
export function buildClaimCard(claim) {
	const isGithubClaim = Boolean(claim.githubUserId);
	if (isGithubClaim && claim.held) {
		return {
			state: 'held',
			title: 'Held for review',
			subtitle: claim.githubLogin ? `github.com/${claim.githubLogin}` : `GitHub id ${claim.githubUserId}`,
			label: claim.attribution?.label ?? null,
			explanation: claim.attribution?.explanation ?? null,
			heldReasons: claim.heldReasons || [],
		};
	}
	if (isGithubClaim) {
		return {
			state: 'attributed',
			title: claim.attribution?.headline || 'GitHub fee claim',
			subtitle: claim.githubLogin ? `github.com/${claim.githubLogin}` : `GitHub id ${claim.githubUserId}`,
			label: claim.attribution?.label ?? null,
			explanation: claim.attribution?.explanation ?? null,
			heldReasons: [],
		};
	}
	return {
		state: 'claimed',
		title: 'First creator fee claim',
		subtitle: claim.creator,
		label: null,
		explanation: null,
		heldReasons: [],
	};
}