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
fix(credits): verify credit deposits on mainnet in production so devnet SOL cannot mint credits
nirholas4f8eae983aeb
diff --git a/api/_lib/credit-deposit.js b/api/_lib/credit-deposit.jsindex db31396f9..0ca2f7719 100644--- a/api/_lib/credit-deposit.js+++ b/api/_lib/credit-deposit.js@@ -113,7 +113,12 @@ function lamportsCreditedTo(tx, owner) {* @param {{ user: object, asset: 'SOL'|'THREE', txSignature: string, network?: string }} args* @returns {Promise<object>} credit result for the API response*/-export async function verifyAndCreditDeposit({ user, asset, txSignature, network = 'mainnet' }) {+export async function verifyAndCreditDeposit({ user, asset, txSignature, network: requestedNetwork = 'mainnet' }) {+ // Devnet only outside production. Credits are priced at the mainnet SOL and+ // $THREE price and spend as real USDC through /api/pay/execute, so accepting a+ // faucet-funded devnet transfer minted real money from nothing. Same rule as+ // api/payments/solana/[action].js.+ const network = requestedNetwork === 'devnet' && process.env.NODE_ENV !== 'production' ? 'devnet' : 'mainnet';const sink = depositWallet();if (!sink)throw depositError('the deposit wallet is not configured', 503, 'deposit_unavailable');diff --git a/tests/credit-deposit-network.test.js b/tests/credit-deposit-network.test.jsnew file mode 100644index 000000000..d5ca709b0--- /dev/null+++ b/tests/credit-deposit-network.test.js@@ -0,0 +1,48 @@+// Credit deposits verify on mainnet in production, whatever the client asks for.+//+// Credits are priced at the mainnet SOL / $THREE price and spend as real USDC+// through /api/pay/execute. Honouring `network: 'devnet'` let a faucet-funded+// devnet transfer to the deposit address mint real spendable credits.++import { describe, it, expect, vi, afterEach } from 'vitest';++const urls = [];+vi.mock('../api/_lib/solana/connection.js', () => ({+ solanaConnection: vi.fn(({ url }) => {+ urls.push(url);+ return { getParsedTransaction: vi.fn(async () => null) };+ }),+}));+vi.mock('../api/_lib/db.js', () => ({ sql: vi.fn(async () => []) }));+vi.mock('../api/_lib/credits.js', () => ({ creditAccount: vi.fn() }));+vi.mock('../api/_lib/token/price.js', () => ({ getTokenPriceUsd: vi.fn() }));+vi.mock('../api/_lib/balances.js', () => ({ solanaMintUsdPrice: vi.fn() }));+vi.mock('../api/_lib/token/config.js', () => ({ TOKEN_MINT: 'THREEsynthetic1111', TOKEN_DECIMALS: 6, treasuryWalletOrNull: () => null }));++const { verifyAndCreditDeposit } = await import('../api/_lib/credit-deposit.js');++const SIG = '5'.repeat(88);+const ORIGINAL_ENV = process.env.NODE_ENV;++afterEach(() => {+ process.env.NODE_ENV = ORIGINAL_ENV;+ delete process.env.CREDITS_DEPOSIT_WALLET_SOLANA;+ urls.length = 0;+});++describe('credit deposit network', () => {+ it('ignores a devnet request in production and reads mainnet', async () => {+ process.env.NODE_ENV = 'production';+ process.env.CREDITS_DEPOSIT_WALLET_SOLANA = 'So11111111111111111111111111111111111111112';+ await verifyAndCreditDeposit({ user: { id: 'u1' }, asset: 'SOL', txSignature: SIG, network: 'devnet' }).catch(() => {});+ expect(urls.length).toBeGreaterThan(0);+ expect(urls.every((u) => !/devnet/.test(u))).toBe(true);+ });++ it('still allows devnet outside production for local testing', async () => {+ process.env.NODE_ENV = 'test';+ process.env.CREDITS_DEPOSIT_WALLET_SOLANA = 'So11111111111111111111111111111111111111112';+ await verifyAndCreditDeposit({ user: { id: 'u1' }, asset: 'SOL', txSignature: SIG, network: 'devnet' }).catch(() => {});+ expect(urls.some((u) => /devnet/.test(u))).toBe(true);+ });+});