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.

fix(bazaar): 400 on a decimal maxPrice instead of 500, and match assets by symbol

nirholas9f61d7fe54e9
diff --git a/api/_lib/x402/bazaar-client.js b/api/_lib/x402/bazaar-client.js
index 356f7ab65..9d094fb61 100644
--- a/api/_lib/x402/bazaar-client.js
+++ b/api/_lib/x402/bazaar-client.js
@@ -316,12 +316,34 @@ function scoreItem(it, terms) {
// ---- Filtering helpers ----
+// Parse an atomic-unit price cap (a non-negative integer in the asset's smallest
+// unit, e.g. 10000 = 0.01 USDC). Returns null when the value is not one, so an
+// HTTP boundary can answer 400 instead of letting BigInt's raw SyntaxError blow
+// up the request: a user-supplied `maxPrice=0.01` used to 500 /api/bazaar/list,
+// /api/bazaar/search and /api/agenc/x402-services, and to silently empty the
+// whole services lane of /api/agora/board.
+export function parseAtomicAmount(value) {
+ const s = String(value ?? '').trim();
+ if (!/^\d+$/.test(s)) return null;
+ return BigInt(s);
+}
+
export function filterByMaxPrice(items, atomicMax, asset = null) {
- const max = BigInt(atomicMax);
+ const max = parseAtomicAmount(atomicMax);
+ if (max === null) {
+ throw new TypeError(`maxPrice must be an atomic (integer) amount, got "${atomicMax}"`);
+ }
+ // `a.asset` is the raw on-chain identifier (a contract address on EVM, a mint
+ // on Solana). Every caller's docs tell users to pass a SYMBOL ("USDC"), which
+ // would have matched nothing, so accept either form.
const wantAsset = asset ? String(asset).toLowerCase() : null;
return items.filter((it) =>
it.accepts.some((a) => {
- if (wantAsset && String(a.asset || '').toLowerCase() !== wantAsset) return false;
+ if (wantAsset) {
+ const raw = String(a.asset || '').toLowerCase();
+ const symbol = assetInfo(a.asset).symbol.toLowerCase();
+ if (raw !== wantAsset && symbol !== wantAsset) return false;
+ }
try {
return BigInt(a.amountAtomic || 0) <= max;
} catch {
diff --git a/api/bazaar/list.js b/api/bazaar/list.js
index 1c334bba3..cd6aa3e30 100644
--- a/api/bazaar/list.js
+++ b/api/bazaar/list.js
@@ -11,6 +11,7 @@ import {
filterByMaxPrice,
filterByNetwork,
filterByTag,
+ parseAtomicAmount,
sortByPriceAsc,
} from '../_lib/x402/bazaar-client.js';
@@ -25,6 +26,11 @@ async function handler(req, res) {
}
const network = url.searchParams.get('network') || null;
const maxPrice = url.searchParams.get('maxPrice');
+ // Atomic units, not decimals: `maxPrice=0.01` is a user error, and answering
+ // 400 beats the SyntaxError BigInt used to throw straight into a 500.
+ if (maxPrice != null && parseAtomicAmount(maxPrice) === null) {
+ return error(res, 400, 'bad_request', 'maxPrice must be an atomic integer amount (e.g. 10000 = 0.01 USDC)');
+ }
const asset = url.searchParams.get('asset');
const extension = url.searchParams.get('extension');
const tag = url.searchParams.get('tag');
diff --git a/api/bazaar/search.js b/api/bazaar/search.js
index d370f372e..4ec9f8cd0 100644
--- a/api/bazaar/search.js
+++ b/api/bazaar/search.js
@@ -11,6 +11,7 @@ import {
filterByMaxPrice,
filterByNetwork,
filterByTag,
+ parseAtomicAmount,
} from '../_lib/x402/bazaar-client.js';
async function handler(req, res) {
@@ -25,6 +26,10 @@ async function handler(req, res) {
}
const network = url.searchParams.get('network') || null;
const maxPrice = url.searchParams.get('maxPrice');
+ // Atomic units, not decimals (see /api/bazaar/list): a malformed cap is a 400.
+ if (maxPrice != null && parseAtomicAmount(maxPrice) === null) {
+ return error(res, 400, 'bad_request', 'maxPrice must be an atomic integer amount (e.g. 10000 = 0.01 USDC)');
+ }
const asset = url.searchParams.get('asset');
const extension = url.searchParams.get('extension');
const tag = url.searchParams.get('tag');
diff --git a/packages/agenc-mcp/README.md b/packages/agenc-mcp/README.md
index de17cd26e..1d17990de 100644
--- a/packages/agenc-mcp/README.md
+++ b/packages/agenc-mcp/README.md
@@ -83,7 +83,7 @@ All five tools read live on-chain / directory data: task sets, registry state, a
**`link_agent`** — one of `erc8004AgentId` | `mplCoreAsset` | `handle` (required), `baseUrl` (optional, default `https://three.ws`), `cluster` (default `mainnet`).
-**`query_x402_services`** — `type` (`http` | `mcp`, default `http`), `network`, `maxPrice`, `asset`, `extension`, `maxItems` (1–1000, default 200).
+**`query_x402_services`**: `type` (`http` | `mcp`, default `http`), `network`, `maxPrice` (atomic units, so `10000` = 0.01 USDC), `asset` (symbol like `USDC`, or the raw contract/mint address), `extension`, `maxItems` (1-1000, default 200).
## Example
diff --git a/packages/agenc-mcp/src/tools/query-x402-services.js b/packages/agenc-mcp/src/tools/query-x402-services.js
index 5c12f546b..307380ca7 100644
--- a/packages/agenc-mcp/src/tools/query-x402-services.js
+++ b/packages/agenc-mcp/src/tools/query-x402-services.js
@@ -29,7 +29,7 @@ export const def = {
maxPrice: z
.string()
.optional()
- .describe('Maximum price to include, expressed in `asset` units (e.g. "0.01").'),
+ .describe('Maximum price to include, in ATOMIC units of `asset` (USDC has 6 decimals, so "10000" = 0.01 USDC). Decimals are rejected.'),
asset: z
.string()
.optional()
diff --git a/packages/agora-mcp/README.md b/packages/agora-mcp/README.md
index c533076bf..9082e6eee 100644
--- a/packages/agora-mcp/README.md
+++ b/packages/agora-mcp/README.md
@@ -100,7 +100,7 @@ The five read tools query live on-chain / projection data (the board, pulse, pop
### Input parameters
-**`agora_board`** — `profession` (one of the profession keys), `minReward` (atomic units), `network`, `maxPrice`, `asset`, `maxItems` (1–500, default 60). All optional.
+**`agora_board`**: `profession` (one of the profession keys), `minReward` (atomic units), `network`, `maxPrice` (atomic units, so `10000` = 0.01 USDC), `asset` (symbol like `USDC`, or the raw contract/mint address), `maxItems` (1-500, default 60). All optional.
**`agora_pulse`** — no inputs.
diff --git a/packages/agora-mcp/src/tools/board.js b/packages/agora-mcp/src/tools/board.js
index 68ccd66b1..156808cbe 100644
--- a/packages/agora-mcp/src/tools/board.js
+++ b/packages/agora-mcp/src/tools/board.js
@@ -44,7 +44,7 @@ export const def = {
maxPrice: z
.string()
.optional()
- .describe('Maximum x402 service price to include, expressed in `asset` units (e.g. "0.01").'),
+ .describe('Maximum x402 service price to include, in ATOMIC units of `asset` (USDC has 6 decimals, so "10000" = 0.01 USDC). Decimals are rejected.'),
asset: z
.string()
.optional()