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: Add SNS name resolution and bonding curve integration to agent token widget
nirholaseffd09c33d60
diff --git a/tests/pumpkit-claims.test.js b/tests/pumpkit-claims.test.jsnew file mode 100644index 000000000..be844e691--- /dev/null+++ b/tests/pumpkit-claims.test.js@@ -0,0 +1,214 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';++// Mock SOLANA_RPC so the module can be imported in Node without the full browser env.+vi.mock('../src/erc8004/solana-deploy.js', () => ({+ detectSolanaWallet: vi.fn(),+ SOLANA_RPC: { mainnet: 'https://api.mainnet-beta.solana.com', devnet: 'https://api.devnet.solana.com' },+}));++// Shared mocks for Connection methods.+const getSignaturesForAddressMock = vi.fn();+const getParsedTransactionMock = vi.fn();++vi.mock('@solana/web3.js', () => ({+ Connection: vi.fn(() => ({+ getSignaturesForAddress: getSignaturesForAddressMock,+ getParsedTransaction: getParsedTransactionMock,+ })),+ PublicKey: vi.fn((s) => ({ toString: () => s })),+}));++const { listRecentClaims, watchClaims } = await import('../src/pump/pumpkit-claims.js');++// ── Fixtures ───────────────────────────────────────────────────────────────++const CREATOR = 'CREatorWALLet111111111111111111111111111111111';+const PUMP_PROGRAM = '6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P';++function makeTx({ creator = CREATOR, programId = PUMP_PROGRAM, preBalance = 0, postBalance = 500_000_000, blockTime = 1_700_000_000, mint = 'MINT1111111111111111111111111111111111111111' } = {}) {+ return {+ transaction: {+ message: {+ instructions: [{ programId }],+ accountKeys: [{ pubkey: { toString: () => creator } }],+ },+ },+ meta: {+ innerInstructions: [],+ preBalances: [preBalance],+ postBalances: [postBalance],+ postTokenBalances: [{ mint }],+ },+ blockTime,+ };+}++// ── listRecentClaims ───────────────────────────────────────────────────────++describe('listRecentClaims', () => {+ beforeEach(() => {+ getSignaturesForAddressMock.mockReset();+ getParsedTransactionMock.mockReset();+ });++ it('returns empty array when no transactions found', async () => {+ getSignaturesForAddressMock.mockResolvedValue([]);+ const result = await listRecentClaims({ creator: CREATOR });+ expect(result).toEqual([]);+ });++ it('filters out transactions without pump.fun program involvement', async () => {+ getSignaturesForAddressMock.mockResolvedValue([{ signature: 'sig1', blockTime: 1_700_000_000 }]);+ getParsedTransactionMock.mockResolvedValue(+ makeTx({ programId: 'SomeOtherProgram111111111111111111111111111' }),+ );+ const result = await listRecentClaims({ creator: CREATOR });+ expect(result).toEqual([]);+ });++ it('filters out transactions where creator lamports did not increase', async () => {+ getSignaturesForAddressMock.mockResolvedValue([{ signature: 'sig1', blockTime: 1_700_000_000 }]);+ // preBalance > postBalance → outflow, not a claim+ getParsedTransactionMock.mockResolvedValue(+ makeTx({ preBalance: 1_000_000_000, postBalance: 500_000_000 }),+ );+ const result = await listRecentClaims({ creator: CREATOR });+ expect(result).toEqual([]);+ });++ it('returns a claim event for a matching pump.fun transaction', async () => {+ getSignaturesForAddressMock.mockResolvedValue([{ signature: 'sigABC', blockTime: 1_700_000_100 }]);+ getParsedTransactionMock.mockResolvedValue(+ makeTx({ preBalance: 0, postBalance: 500_000_000, mint: 'MINTTTT' }),+ );+ const result = await listRecentClaims({ creator: CREATOR });+ expect(result).toHaveLength(1);+ expect(result[0]).toMatchObject({+ signature: 'sigABC',+ mint: 'MINTTTT',+ lamports: 500_000_000,+ ts: 1_700_000_100,+ });+ });++ it('respects the limit and stops fetching after enough claims', async () => {+ getSignaturesForAddressMock.mockResolvedValue([+ { signature: 's1', blockTime: 100 },+ { signature: 's2', blockTime: 99 },+ { signature: 's3', blockTime: 98 },+ ]);+ getParsedTransactionMock.mockResolvedValue(makeTx());+ const result = await listRecentClaims({ creator: CREATOR, limit: 2 });+ expect(result).toHaveLength(2);+ });++ it('skips transactions where getParsedTransaction throws', async () => {+ getSignaturesForAddressMock.mockResolvedValue([+ { signature: 'bad', blockTime: 100 },+ { signature: 'good', blockTime: 99 },+ ]);+ getParsedTransactionMock+ .mockRejectedValueOnce(new Error('rpc error'))+ .mockResolvedValueOnce(makeTx());+ const result = await listRecentClaims({ creator: CREATOR });+ expect(result).toHaveLength(1);+ expect(result[0].signature).toBe('good');+ });++ it('recognises inner-instruction pump.fun program calls', async () => {+ const tx = makeTx({ programId: 'SystemProgram' });+ tx.meta.innerInstructions = [+ { instructions: [{ programId: PUMP_PROGRAM }] },+ ];+ getSignaturesForAddressMock.mockResolvedValue([{ signature: 'inner', blockTime: 1_700_000_000 }]);+ getParsedTransactionMock.mockResolvedValue(tx);+ const result = await listRecentClaims({ creator: CREATOR });+ expect(result).toHaveLength(1);+ });+});++// ── watchClaims ────────────────────────────────────────────────────────────++describe('watchClaims', () => {+ beforeEach(() => {+ getSignaturesForAddressMock.mockReset();+ getParsedTransactionMock.mockReset();+ });++ it('calls onClaim for each new claim on the initial poll', async () => {+ getSignaturesForAddressMock.mockResolvedValue([{ signature: 'sig1', blockTime: 1_700_000_100 }]);+ getParsedTransactionMock.mockResolvedValue(makeTx({ blockTime: 1_700_000_100 }));++ const received = [];+ const ctrl = new AbortController();+ ctrl.abort(); // abort immediately so no polling interval fires++ await watchClaims({+ creator: CREATOR,+ signal: ctrl.signal,+ onClaim: (c) => received.push(c),+ });++ expect(received).toHaveLength(1);+ expect(received[0].signature).toBe('sig1');+ });++ it('deduplicates: does not call onClaim twice for the same signature', async () => {+ getSignaturesForAddressMock.mockResolvedValue([{ signature: 'dup', blockTime: 1_700_000_100 }]);+ getParsedTransactionMock.mockResolvedValue(makeTx({ blockTime: 1_700_000_100 }));++ const received = [];+ const ctrl = new AbortController();+ ctrl.abort();++ await watchClaims({+ creator: CREATOR,+ signal: ctrl.signal,+ onClaim: (c) => received.push(c),+ });++ // Call again — same sig should not fire again because it's already in `seen`.+ // Re-run with a fresh watch but sinceTs set past the event ts.+ const received2 = [];+ const ctrl2 = new AbortController();+ ctrl2.abort();+ await watchClaims({+ creator: CREATOR,+ sinceTs: 1_700_000_100, // event ts == sinceTs → filtered+ signal: ctrl2.signal,+ onClaim: (c) => received2.push(c),+ });++ expect(received).toHaveLength(1);+ expect(received2).toHaveLength(0); // filtered by sinceTs+ });++ it('aborts cleanly when signal fires before polling interval', async () => {+ getSignaturesForAddressMock.mockResolvedValue([]);++ const ctrl = new AbortController();+ ctrl.abort();++ // Should not throw and should resolve quickly.+ await expect(+ watchClaims({ creator: CREATOR, signal: ctrl.signal, onClaim: vi.fn() }),+ ).resolves.toBeUndefined();+ });++ it('survives onClaim throwing without stopping the watch', async () => {+ getSignaturesForAddressMock.mockResolvedValue([{ signature: 'err', blockTime: 1_700_000_200 }]);+ getParsedTransactionMock.mockResolvedValue(makeTx({ blockTime: 1_700_000_200 }));++ const ctrl = new AbortController();+ ctrl.abort();++ // Should not propagate the error from onClaim.+ await expect(+ watchClaims({+ creator: CREATOR,+ signal: ctrl.signal,+ onClaim: () => { throw new Error('handler error'); },+ }),+ ).resolves.toBeUndefined();+ });+});diff --git a/tests/sentiment.test.js b/tests/sentiment.test.jsnew file mode 100644index 000000000..9f6cb8f84--- /dev/null+++ b/tests/sentiment.test.js@@ -0,0 +1,77 @@+import { describe, it, expect } from 'vitest';+import { scoreSentiment } from '../src/social/sentiment.js';++function posts(texts) {+ return texts.map((text, i) => ({ id: String(i), text }));+}++describe('scoreSentiment', () => {+ it('all-positive → score > 0.5', () => {+ const result = scoreSentiment(+ posts([+ '$WIF is going to the moon 🚀 bullish AF',+ 'massive gains incoming, this is a gem 💎',+ 'lfg! buy the dip, huge breakout coming 📈',+ 'rocket ship energy, 100x potential wagmi 🙌',+ 'green candles all day, ATH soon 🔥',+ ]),+ );+ expect(result.score).toBeGreaterThan(0.5);+ expect(result.posPct).toBeGreaterThan(50);+ });++ it('all-negative → score < -0.5', () => {+ const result = scoreSentiment(+ posts([+ '$WIF is a scam, total rug pull 💀',+ 'rekt again, crash incoming 📉',+ 'dump everything now, this is fraud 🐻',+ 'bearish collapse, avoid at all costs ⚠️',+ 'ponzi scheme, everyone will be liquidated',+ ]),+ );+ expect(result.score).toBeLessThan(-0.5);+ expect(result.negPct).toBeGreaterThan(50);+ });++ it('mixed → score near 0 (between -0.4 and 0.4)', () => {+ const result = scoreSentiment(+ posts([+ '$WIF to the moon 🚀',+ 'this is a rug, scam warning 💀',+ 'bullish on the long term',+ 'crash incoming, bearish 📉',+ 'just a normal day in crypto',+ ]),+ );+ expect(result.score).toBeGreaterThan(-0.4);+ expect(result.score).toBeLessThan(0.4);+ });++ it('returns correct shape', () => {+ const result = scoreSentiment(posts(['moon 🚀', 'scam 💀']));+ expect(result).toMatchObject({+ score: expect.any(Number),+ posPct: expect.any(Number),+ negPct: expect.any(Number),+ neuPct: expect.any(Number),+ count: 2,+ examples: {+ pos: expect.any(Array),+ neg: expect.any(Array),+ },+ });+ });++ it('empty input → zero score, 100% neutral', () => {+ const result = scoreSentiment([]);+ expect(result.score).toBe(0);+ expect(result.neuPct).toBe(100);+ expect(result.count).toBe(0);+ });++ it('pct values sum to 100', () => {+ const result = scoreSentiment(posts(['moon', 'crash', 'nothing']));+ expect(result.posPct + result.negPct + result.neuPct).toBeCloseTo(100, 1);+ });+});diff --git a/tests/solana-sns.test.js b/tests/solana-sns.test.jsnew file mode 100644index 000000000..59cc55571--- /dev/null+++ b/tests/solana-sns.test.js@@ -0,0 +1,94 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';++const resolveMock = vi.fn();+const getFavoriteDomainMock = vi.fn();++vi.mock('@bonfida/spl-name-service', () => ({+ resolve: (...a) => resolveMock(...a),+ getFavoriteDomain: (...a) => getFavoriteDomainMock(...a),+}));++vi.mock('@solana/web3.js', () => {+ class PublicKey {+ constructor(value) {+ this._value = String(value);+ }+ toBase58() {+ return this._value;+ }+ }+ class Connection {}+ return { Connection, PublicKey };+});++const { resolveSnsName, reverseLookupAddress } = await import('../src/solana/sns.js');++describe('resolveSnsName', () => {+ beforeEach(() => {+ resolveMock.mockReset();+ });++ it('returns base58 address for a known domain', async () => {+ const fakeKey = { toBase58: () => 'HKKp49zUBeaABFMpBWKCJPoNDLiR4AEEr8FJKuZPn6Nk' };+ resolveMock.mockResolvedValue(fakeKey);+ const result = await resolveSnsName('bonfida.sol');+ expect(result).toBe('HKKp49zUBeaABFMpBWKCJPoNDLiR4AEEr8FJKuZPn6Nk');+ expect(resolveMock).toHaveBeenCalledWith(expect.anything(), 'bonfida');+ });++ it('strips the .sol suffix before calling resolve', async () => {+ resolveMock.mockResolvedValue({ toBase58: () => 'AAA' });+ await resolveSnsName('test.sol');+ expect(resolveMock).toHaveBeenCalledWith(expect.anything(), 'test');+ });++ it('accepts a name without .sol suffix', async () => {+ resolveMock.mockResolvedValue({ toBase58: () => 'BBB' });+ await resolveSnsName('test');+ expect(resolveMock).toHaveBeenCalledWith(expect.anything(), 'test');+ });++ it('returns null for a non-existent domain', async () => {+ resolveMock.mockRejectedValue(new Error('DomainDoesNotExist'));+ const result = await resolveSnsName('nope-not-real-domain-xyz.sol');+ expect(result).toBeNull();+ });++ it('returns null on any resolution error', async () => {+ resolveMock.mockRejectedValue(new Error('network error'));+ expect(await resolveSnsName('anything.sol')).toBeNull();+ });+});++describe('reverseLookupAddress', () => {+ beforeEach(() => {+ getFavoriteDomainMock.mockReset();+ });++ it('returns .sol domain for a known address', async () => {+ getFavoriteDomainMock.mockResolvedValue({ reverse: 'bonfida', stale: false });+ const result = await reverseLookupAddress('HKKp49zUBeaABFMpBWKCJPoNDLiR4AEEr8FJKuZPn6Nk');+ expect(result).toBe('bonfida.sol');+ });++ it('appends .sol when the reverse result omits it', async () => {+ getFavoriteDomainMock.mockResolvedValue({ reverse: 'myname', stale: false });+ expect(await reverseLookupAddress('someaddr')).toBe('myname.sol');+ });++ it('does not double-append .sol when reverse already includes it', async () => {+ getFavoriteDomainMock.mockResolvedValue({ reverse: 'already.sol', stale: false });+ expect(await reverseLookupAddress('someaddr')).toBe('already.sol');+ });++ it('returns null when no favourite domain is found', async () => {+ getFavoriteDomainMock.mockRejectedValue(new Error('FavouriteDomainNotFoundError'));+ const result = await reverseLookupAddress('HKKp49zUBeaABFMpBWKCJPoNDLiR4AEEr8FJKuZPn6Nk');+ expect(result).toBeNull();+ });++ it('returns null on any reverse-lookup error', async () => {+ getFavoriteDomainMock.mockRejectedValue(new Error('network error'));+ expect(await reverseLookupAddress('someaddr')).toBeNull();+ });+});