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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(stake): implement Solana stake transaction helper and update reputation handling
nirholasd7a29fd134dc
diff --git a/api/agents/solana/_handlers.js b/api/agents/solana/_handlers.jsindex 772960631..66475c6f6 100644--- a/api/agents/solana/_handlers.js+++ b/api/agents/solana/_handlers.js@@ -440,6 +440,28 @@ export const handleReputation = wrap(async (req, res) => {const [cursor] = await sql`select last_indexed_at from solana_attestations_cursor where agent_asset = ${asset} limit 1`;+ const [stakeAgg] = await sql`+ select+ coalesce(sum((payload->>'lamports')::numeric), 0)::text as total_lamports,+ count(*)::int as stake_count,+ count(distinct attester)::int as unique_stakers+ from solana_attestations+ where agent_asset = ${asset} and network = ${network}+ and kind = 'threews.stake.v1' and verified = true and revoked = false+ `;++ const topStakers = await sql`+ select attester,+ sum((payload->>'lamports')::numeric)::text as lamports,+ max((payload->>'score')::int) as score+ from solana_attestations+ where agent_asset = ${asset} and network = ${network}+ and kind = 'threews.stake.v1' and verified = true and revoked = false+ group by attester+ order by sum((payload->>'lamports')::numeric) desc+ limit 5+ `;+const pumpfunRows = await sql`select kind, count(*)::int as n, coalesce(sum(weight), 0)::float as w from pumpfun_signals where agent_asset = ${asset} group by kind`;const pumpfunByKind = {};let pumpfunTotal = 0, pumpfunWeight = 0;@@ -468,6 +490,16 @@ export const handleReputation = wrap(async (req, res) => {validation: { self_passed: val.passed, self_failed: val.failed, event_passed: val.event_passed, event_failed: val.event_failed, audited_passed: auditedVal.passed, audited_failed: auditedVal.failed },tasks: { offered: counts.tasks_offered, accepted: counts.tasks_accepted },disputes_filed: counts.disputes_filed, revoked_count: counts.revoked_count,+ stake: {+ total_lamports: stakeAgg?.total_lamports || '0',+ count: stakeAgg?.stake_count || 0,+ unique_stakers: stakeAgg?.unique_stakers || 0,+ top_stakers: topStakers.map((r) => ({+ attester: r.attester,+ lamports: r.lamports,+ score: r.score,+ })),+ },last_indexed_at: cursor?.last_indexed_at || null,});});diff --git a/public/agent-passport.html b/public/agent-passport.htmlindex 61ab88312..f8a11949a 100644--- a/public/agent-passport.html+++ b/public/agent-passport.html@@ -943,6 +943,22 @@...(r.revoked_count? [{ cls: 'danger', value: r.revoked_count, label: 'revoked' }]: []),+ ...(r.stake && Number(r.stake.total_lamports) > 0+ ? [+ {+ cls: 'tier-credentialed',+ value: (Number(r.stake.total_lamports) / 1e9).toFixed(4) + ' SOL',+ label: 'total staked',+ tooltip:+ 'Sum of SOL transferred alongside threews.stake.v1 attestations. Economically backed reputation.',+ },+ {+ cls: 'tier-credentialed',+ value: `${r.stake.unique_stakers}<small>/${r.stake.count}</small>`,+ label: 'unique stakers / stakes',+ },+ ]+ : []),];$('reputation').innerHTML = `<div class="grid">${cardsdiff --git a/src/solana-stake.js b/src/solana-stake.jsnew file mode 100644index 000000000..f3495cb9c--- /dev/null+++ b/src/solana-stake.js@@ -0,0 +1,94 @@+/**+ * Solana stake helper — builds a single tx that+ * 1. transfers SOL from the staker to the agent's wallet+ * 2. attaches an SPL Memo with kind='threews.stake.v1', score, comment+ * The memo is then indexed by the solana-attestations-crawl cron, which folds+ * the lamports delta into the row's payload.+ */++import {+ Connection,+ PublicKey,+ SystemProgram,+ Transaction,+ TransactionInstruction,+} from '@solana/web3.js';++const MEMO_PROGRAM_ID = new PublicKey('MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr');+export const MIN_STAKE_LAMPORTS = 1_000_000n; // 0.001 SOL+export const SOL_PER_LAMPORT = 1e-9;++const RPC = {+ mainnet: 'https://api.mainnet-beta.solana.com',+ devnet: 'https://api.devnet.solana.com',+};++/**+ * Submit a stake-and-memo transaction via the connected Solana wallet adapter.+ *+ * @param {object} opts+ * @param {string} opts.agentAsset Base58 SPL mint or wallet that identifies the agent+ * @param {string} opts.recipient Base58 wallet that receives the staked SOL+ * @param {bigint} opts.lamports Stake amount in lamports (>= MIN_STAKE_LAMPORTS)+ * @param {number} opts.score 1–5+ * @param {string} [opts.comment='']+ * @param {'mainnet'|'devnet'} [opts.network='devnet']+ * @param {object} opts.wallet Solana wallet adapter (must expose publicKey + signTransaction)+ * @returns {Promise<string>} signature+ */+export async function stakeOnSolana({+ agentAsset,+ recipient,+ lamports,+ score,+ comment = '',+ network = 'devnet',+ wallet,+}) {+ if (!wallet?.publicKey || typeof wallet.signTransaction !== 'function') {+ throw new Error('Solana wallet not connected');+ }+ if (!Number.isInteger(score) || score < 1 || score > 5) {+ throw new Error('score must be 1-5');+ }+ if (lamports < MIN_STAKE_LAMPORTS) {+ throw new Error(`min stake is ${Number(MIN_STAKE_LAMPORTS) * SOL_PER_LAMPORT} SOL`);+ }++ const conn = new Connection(RPC[network] || RPC.devnet, 'confirmed');+ const fromPk = wallet.publicKey;+ const toPk = new PublicKey(recipient);++ const memoPayload = {+ v: 1,+ kind: 'threews.stake.v1',+ agent: agentAsset,+ score,+ comment: comment.slice(0, 280),+ };+ const memoIx = new TransactionInstruction({+ keys: [{ pubkey: fromPk, isSigner: true, isWritable: false }],+ programId: MEMO_PROGRAM_ID,+ data: Buffer.from(JSON.stringify(memoPayload), 'utf8'),+ });++ const transferIx = SystemProgram.transfer({+ fromPubkey: fromPk,+ toPubkey: toPk,+ lamports: Number(lamports),+ });++ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();+ const tx = new Transaction({+ feePayer: fromPk,+ blockhash,+ lastValidBlockHeight,+ }).add(transferIx, memoIx);++ const signed = await wallet.signTransaction(tx);+ const sig = await conn.sendRawTransaction(signed.serialize(), {+ skipPreflight: false,+ });+ await conn.confirmTransaction({ signature: sig, blockhash, lastValidBlockHeight }, 'confirmed');+ return sig;+}