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.

feat(terminals): share one trading-terminal link builder across the feed and copy pages

nirholas87abcfe2fbc4
diff --git a/api/_lib/crypto-trending.js b/api/_lib/crypto-trending.js
index b521fad05..c6b663a3b 100644
--- a/api/_lib/crypto-trending.js
+++ b/api/_lib/crypto-trending.js
@@ -33,6 +33,7 @@
import { scorePressure } from './x402/pump-trending-score.js';
import { summarizeWindowUsd, median } from './x402/pump-volume-anomaly.js';
import { dexScreenerTrending, gmgnSmartMoneyRank } from './gmgn-feed.js';
+import { gmgnTokenUrl } from '../../src/shared/trading-terminals.js';
const PUMP_FRONTEND_BASE = process.env.PUMP_FRONTEND_BASE || 'https://frontend-api-v3.pump.fun';
const PUMP_SWAP_BASE = process.env.PUMP_SWAP_BASE || 'https://swap-api.pump.fun';
@@ -296,7 +297,7 @@ export function mapGmgnRow(row, window) {
volumeUsd: num(row.volume ?? row.volume_24h),
buyPressure: flow > 0 ? (smartBuy ?? 0) / flow : null,
changePct,
- url: `https://gmgn.ai/sol/token/${row.address}`,
+ url: gmgnTokenUrl(row.address),
_source: 'gmgn',
};
}
diff --git a/src/dashboard-next/pages/copy.js b/src/dashboard-next/pages/copy.js
index 99ef948c8..cf38fbc7e 100644
--- a/src/dashboard-next/pages/copy.js
+++ b/src/dashboard-next/pages/copy.js
@@ -10,6 +10,7 @@
import { mountShell } from '../shell.js';
import { requireUser, get, post, del, esc, relTime } from '../api.js';
import { errorStateHTML, ensureStateKitStyles, attachRetry } from '../../shared/state-kit.js';
+import { gmgnAddressUrl } from '../../shared/trading-terminals.js';
const SKIP_LABEL = {
below_mcap_floor: 'Below your market-cap floor',
@@ -543,7 +544,7 @@ function explorerUrl(w) {
? `https://bscscan.com/address/${w.address}`
: `https://solscan.io/account/${w.address}`;
}
-function gmgnUrl(w) { return `https://gmgn.ai/${w.chain === 'bsc' ? 'bsc' : 'sol'}/address/${w.address}`; }
+function gmgnUrl(w) { return gmgnAddressUrl(w.address, w.chain); }
function initial(w) {
const ch = (w.name || w.address || '').replace(/[^a-zA-Z0-9]/g, '')[0];
return (ch || '?').toUpperCase();
diff --git a/src/shared/trading-terminals.js b/src/shared/trading-terminals.js
new file mode 100644
index 000000000..268fa6ae7
--- /dev/null
+++ b/src/shared/trading-terminals.js
@@ -0,0 +1,124 @@
+// Trading-terminal links, and the one place our referral codes live.
+//
+// Every "trade this token on X" link in the product routes through here so the
+// codes are set once instead of being pasted into each widget. Imported by both
+// the browser bundles (src/widgets, src/dashboard-next) and the API layer
+// (api/_lib/crypto-trending.js), so this file stays dependency-free.
+//
+// Which terminals accept a referral on a token deep link, per their own docs:
+//
+// GMGN yes. https://docs.gmgn.ai/index/referral-link documents
+// `gmgn.ai/{chain}/token/{code}_{contract}` and
+// `gmgn.ai/{chain}/address/{code}_{wallet}`, so the deep link and the
+// referral travel together and nothing is given up.
+// Axiom no. The documented referral form is `axiom.trade/@{handle}` only.
+// Padre no. The documented referral form is `trade.padre.gg/rk/{code}` only.
+// FOMO no. The documented referral form is `fomo.family/r/{username}` only.
+//
+// For the three that cannot combine the two, the token deep link WINS: a person
+// clicking "Padre" next to a specific coin wants that coin, not a signup page.
+// Their referral codes are surfaced through referralUrl() on signup-intent
+// surfaces instead. Do NOT "fix" this by inventing a `?ref=` query parameter.
+// None of the three document one, an undocumented guess silently earns nothing,
+// and a wrong parameter can break the destination page.
+
+/** Referral codes / handles, by terminal. Change a code here and it changes everywhere. */
+export const REFERRAL_CODES = {
+ gmgn: 'nichxbt',
+ axiom: 'nich',
+ padre: 'nichxbt',
+ fomo: 'nichxbt',
+};
+
+/** GMGN chain slug for our two supported chains. */
+function gmgnChain(chain) {
+ return chain === 'bsc' ? 'bsc' : 'sol';
+}
+
+/**
+ * GMGN token page, referral embedded per GMGN's documented
+ * `{chain}/token/{code}_{contract}` form.
+ */
+export function gmgnTokenUrl(mint, chain = 'sol') {
+ return `https://gmgn.ai/${gmgnChain(chain)}/token/${REFERRAL_CODES.gmgn}_${encodeURIComponent(mint)}`;
+}
+
+/**
+ * GMGN wallet page, referral embedded per GMGN's documented
+ * `{chain}/address/{code}_{wallet}` form.
+ */
+export function gmgnAddressUrl(address, chain = 'sol') {
+ return `https://gmgn.ai/${gmgnChain(chain)}/address/${REFERRAL_CODES.gmgn}_${encodeURIComponent(address)}`;
+}
+
+/** Axiom token page. No documented referral form for deep links (see header). */
+export function axiomTokenUrl(mint) {
+ return `https://axiom.trade/meme/${encodeURIComponent(mint)}`;
+}
+
+/** Padre token page. No documented referral form for deep links (see header). */
+export function padreTokenUrl(mint) {
+ return `https://trade.padre.gg/trade/solana/${encodeURIComponent(mint)}`;
+}
+
+/** FOMO token page. No documented referral form for deep links (see header). */
+export function fomoTokenUrl(mint) {
+ return `https://fomo.family/token/${encodeURIComponent(mint)}`;
+}
+
+/**
+ * The bare referral link for a terminal, for surfaces where signing up (not
+ * viewing one token) is the intent. Each of these gives the person who follows
+ * it a fee discount on that terminal, which is why they are worth showing.
+ *
+ * @param {'gmgn'|'axiom'|'padre'|'fomo'} platform
+ * @returns {string|null} null for an unknown platform
+ */
+export function referralUrl(platform) {
+ const code = REFERRAL_CODES[platform];
+ if (!code) return null;
+ if (platform === 'gmgn') return `https://gmgn.ai/r/${code}`;
+ if (platform === 'axiom') return `https://axiom.trade/@${code}`;
+ if (platform === 'padre') return `https://trade.padre.gg/rk/${code}`;
+ return `https://fomo.family/r/${code}`;
+}
+
+/** Display names, by terminal key. */
+export const TERMINAL_LABELS = {
+ gmgn: 'GMGN',
+ axiom: 'Axiom',
+ padre: 'Padre',
+ fomo: 'FOMO',
+};
+
+/**
+ * The terminals whose referral cannot ride along on a token deep link, so the
+ * only way to offer it is a separate signup link. GMGN is deliberately absent:
+ * gmgnTokenUrl() and gmgnAddressUrl() already carry the code, so listing it
+ * again would be a duplicate link to the same place.
+ *
+ * Following one of these earns the person who clicks it a fee discount on that
+ * terminal, which is the reason it is worth surfacing at all.
+ *
+ * @returns {{ key: string, label: string, url: string }[]}
+ */
+export function referralOffers() {
+ return ['axiom', 'padre', 'fomo'].map((key) => ({
+ key,
+ label: TERMINAL_LABELS[key],
+ url: referralUrl(key),
+ }));
+}
+
+/**
+ * Token deep links for every terminal we link, in display order.
+ * @returns {{ key: string, label: string, short: string, url: string }[]}
+ */
+export function terminalLinks(mint) {
+ return [
+ { key: 'axiom', label: 'Axiom', short: 'AXI', url: axiomTokenUrl(mint) },
+ { key: 'gmgn', label: 'GMGN', short: 'GMG', url: gmgnTokenUrl(mint) },
+ { key: 'padre', label: 'Padre', short: 'PDR', url: padreTokenUrl(mint) },
+ { key: 'fomo', label: 'FOMO', short: 'FMO', url: fomoTokenUrl(mint) },
+ ];
+}
diff --git a/src/widgets/pumpfun-feed.js b/src/widgets/pumpfun-feed.js
index ba29c4aee..08b21e5f5 100644
--- a/src/widgets/pumpfun-feed.js
+++ b/src/widgets/pumpfun-feed.js
@@ -15,6 +15,7 @@
import { applyReaction, createReactionDispatcher, mountReactionToast } from './pumpfun-reactions.js';
import { WORD_BLACKLIST } from '../profanity.js';
+import { terminalLinks, referralOffers } from '../shared/trading-terminals.js';
const FEED_PATH = '/api/agents/pumpfun-feed';
const TIER_BADGE = { mega: '🔥🔥', influencer: '🔥', notable: '⭐' };
@@ -348,15 +349,17 @@ function renderFirstGithubClaim(ev) {
if (links.length) sections.push(`<div style="margin-top:8px;display:flex;flex-direction:column;gap:2px">${links.join('')}</div>`);
if (mint) {
- const trade = [
- `<a href="https://axiom.trade/t/${encodeURIComponent(mint)}" target="_blank" rel="noopener" style="color:#6ce0c8">Axiom</a>`,
- `<a href="https://gmgn.ai/sol/token/${encodeURIComponent(mint)}" target="_blank" rel="noopener" style="color:#6ce0c8">GMGN</a>`,
- `<a href="https://padre.gg/sol/${encodeURIComponent(mint)}" target="_blank" rel="noopener" style="color:#6ce0c8">Padre</a>`,
- ].join(' | ');
+ const trade = terminalLinks(mint)
+ .map((t) => `<a href="${attrEsc(t.url)}" target="_blank" rel="noopener" style="color:#6ce0c8">${t.label}</a>`)
+ .join(' | ');
+ const offers = referralOffers()
+ .map((o) => `<a href="${attrEsc(o.url)}" target="_blank" rel="noopener" style="color:#7a7a8c">${o.label}</a>`)
+ .join(' ⋅ ');
sections.push(`
<div style="border-top:1px solid rgba(255,255,255,0.08);margin-top:10px;padding-top:8px">
<div style="font-weight:600">💹 Trade</div>
<div style="margin-top:2px">${trade}</div>
+ <div style="margin-top:4px;font-size:10px;color:#6a6a82">New account? Sign up with a fee discount: ${offers}</div>
</div>
`);
}
@@ -464,9 +467,7 @@ function renderGraduation(ev) {
: '';
const toolAbbr = mint
? [
- ['AXI', `https://axiom.trade/meme/${mint}`],
- ['GMG', `https://gmgn.ai/sol/token/${mint}`],
- ['PDR', `https://trade.padre.gg/trade/solana/${mint}`],
+ ...terminalLinks(mint).map((t) => [t.short, t.url]),
['PHO', `https://photon-sol.tinyastro.io/en/lp/${mint}`],
['BLX', `https://bullx.io/terminal?chainId=1399811149&address=${mint}`],
].map(([l, u]) => `<a href="${attrEsc(u)}" target="_blank" rel="noopener" style="color:#888888">${l}</a>`).join('⋅')
diff --git a/tests/trading-terminals.test.js b/tests/trading-terminals.test.js
new file mode 100644
index 000000000..69bf42cda
--- /dev/null
+++ b/tests/trading-terminals.test.js
@@ -0,0 +1,128 @@
+import { describe, it, expect } from 'vitest';
+import {
+ REFERRAL_CODES,
+ TERMINAL_LABELS,
+ gmgnTokenUrl,
+ gmgnAddressUrl,
+ axiomTokenUrl,
+ padreTokenUrl,
+ fomoTokenUrl,
+ referralUrl,
+ referralOffers,
+ terminalLinks,
+} from '../src/shared/trading-terminals.js';
+
+// $THREE, the platform's own coin, as the sample mint.
+const MINT = 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump';
+const WALLET = '7rpqjHdf1111111111111111111111111111111111';
+
+describe('referral codes', () => {
+ // These four strings are the whole point of the module. A silent edit here
+ // costs real referral revenue with no visible symptom, so pin them exactly.
+ it('are the configured codes', () => {
+ expect(REFERRAL_CODES).toEqual({
+ gmgn: 'nichxbt',
+ axiom: 'nich',
+ padre: 'nichxbt',
+ fomo: 'nichxbt',
+ });
+ });
+
+ it('produces the documented signup link per terminal', () => {
+ expect(referralUrl('gmgn')).toBe('https://gmgn.ai/r/nichxbt');
+ expect(referralUrl('axiom')).toBe('https://axiom.trade/@nich');
+ expect(referralUrl('padre')).toBe('https://trade.padre.gg/rk/nichxbt');
+ expect(referralUrl('fomo')).toBe('https://fomo.family/r/nichxbt');
+ });
+
+ it('returns null for a terminal it does not know', () => {
+ expect(referralUrl('bullx')).toBeNull();
+ expect(referralUrl('')).toBeNull();
+ });
+});
+
+describe('GMGN deep links carry the referral inline', () => {
+ // GMGN documents {chain}/token/{code}_{contract}, so the referral and the
+ // deep link travel together. If this stops matching, we are linking GMGN
+ // for free.
+ it('embeds the code in the token path', () => {
+ expect(gmgnTokenUrl(MINT)).toBe(`https://gmgn.ai/sol/token/nichxbt_${MINT}`);
+ });
+
+ it('embeds the code in the address path', () => {
+ expect(gmgnAddressUrl(WALLET)).toBe(`https://gmgn.ai/sol/address/nichxbt_${WALLET}`);
+ });
+
+ it('maps chains to GMGN slugs, defaulting to sol', () => {
+ expect(gmgnAddressUrl('0xabc', 'bsc')).toContain('/bsc/address/');
+ expect(gmgnAddressUrl('0xabc', 'ethereum')).toContain('/sol/address/');
+ expect(gmgnTokenUrl(MINT, 'bsc')).toContain('/bsc/token/');
+ });
+
+ it('keeps the underscore separator unescaped so GMGN can split it', () => {
+ const url = gmgnTokenUrl(MINT);
+ expect(url).toContain(`nichxbt_${MINT}`);
+ expect(url).not.toContain('%5F');
+ });
+});
+
+describe('terminals with no documented deep-link referral', () => {
+ // Axiom, Padre and FOMO document a signup-link referral only. The token deep
+ // link deliberately wins over the referral on these. Asserting the absence
+ // stops a future edit from bolting on an invented ?ref= parameter.
+ it('links straight to the token with no referral parameter', () => {
+ for (const url of [axiomTokenUrl(MINT), padreTokenUrl(MINT), fomoTokenUrl(MINT)]) {
+ expect(url).toContain(MINT);
+ expect(url).not.toContain('ref=');
+ expect(url).not.toContain('nichxbt');
+ }
+ });
+
+ it('uses the token-page host each terminal actually serves', () => {
+ expect(axiomTokenUrl(MINT)).toBe(`https://axiom.trade/meme/${MINT}`);
+ expect(padreTokenUrl(MINT)).toBe(`https://trade.padre.gg/trade/solana/${MINT}`);
+ expect(fomoTokenUrl(MINT)).toBe(`https://fomo.family/token/${MINT}`);
+ });
+});
+
+describe('referralOffers', () => {
+ it('offers exactly the terminals that cannot carry a referral inline', () => {
+ expect(referralOffers().map((o) => o.key)).toEqual(['axiom', 'padre', 'fomo']);
+ });
+
+ it('excludes GMGN, whose deep links already carry the code', () => {
+ expect(referralOffers().some((o) => o.key === 'gmgn')).toBe(false);
+ });
+
+ it('gives every offer a label and a resolvable url', () => {
+ for (const offer of referralOffers()) {
+ expect(offer.label).toBe(TERMINAL_LABELS[offer.key]);
+ expect(offer.url).toBe(referralUrl(offer.key));
+ expect(offer.url.startsWith('https://')).toBe(true);
+ }
+ });
+});
+
+describe('terminalLinks', () => {
+ it('covers every terminal with a label, short code and url', () => {
+ const links = terminalLinks(MINT);
+ expect(links.map((t) => t.key)).toEqual(['axiom', 'gmgn', 'padre', 'fomo']);
+ for (const t of links) {
+ expect(t.label).toBe(TERMINAL_LABELS[t.key]);
+ expect(t.short).toHaveLength(3);
+ expect(t.url).toContain(MINT);
+ }
+ });
+
+ it('routes only GMGN through the referral', () => {
+ const withCode = terminalLinks(MINT).filter((t) => t.url.includes('nichxbt'));
+ expect(withCode.map((t) => t.key)).toEqual(['gmgn']);
+ });
+
+ it('escapes a mint containing url-unsafe characters', () => {
+ const links = terminalLinks('abc/def?x=1');
+ for (const t of links) {
+ expect(t.url).toContain('abc%2Fdef%3Fx%3D1');
+ }
+ });
+});