@t2000/sdk 9.12.0 → 9.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1487,4 +1487,39 @@ declare function verifyJobForSeller({ client, jobId, seller, minAmountUsdc, minR
1487
1487
  minRunwayMs?: number;
1488
1488
  }): Promise<JobVerification>;
1489
1489
 
1490
- export { type TransactionRecord as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_NETWORK as D, ETH_TYPE as E, type SimulationResult as F, GAS_RESERVE_MIN as G, type StableAsset as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SuiHolding as Q, type SuiRpcTxBlock as R, STABLE_ASSETS as S, type SupportedAsset as T, type SwapRouteResult as U, T2000Error as V, type T2000ErrorCode as W, type T2000ErrorData as X, T2000_OVERLAY_FEE_WALLET as Y, TOKEN_MAP as Z, type TransactionLeg as _, A2A_ESCROW_PACKAGE_ID as a, type SuiCoreClient as a$, type TransactionSigner as a0, type TxDirection as a1, USDC_DECIMALS as a2, USDC_TYPE as a3, USDE_TYPE as a4, USDSUI_TYPE as a5, USDT_TYPE as a6, WAL_TYPE as a7, WBTC_TYPE as a8, type ZkLoginProof as a9, jobActionsFor as aA, mapMoveAbortCode as aB, mapWalletError as aC, mistToSui as aD, parseMppSuiChallenge as aE, parseSuiRpcTx as aF, payWithMpp as aG, preflightCreateJob as aH, preflightFail as aI, preflightPay as aJ, preflightSend as aK, preflightSwap as aL, rawToStable as aM, rawToUsdc as aN, refineLendingLabel as aO, resolveSymbol as aP, resolveTokenType as aQ, stableToRaw as aR, suiToMist as aS, truncateAddress as aT, usdcToRaw as aU, validateAddress as aV, verifyJobForSeller as aW, type T2000Options as aX, type SwapResult as aY, type SwapQuoteResult as aZ, type PaymentRequest as a_, ZkLoginSigner as aa, buildCreateJobTx as ab, buildDeliverJobTx as ac, buildRefundJobTx as ad, buildRejectJobTx as ae, buildReleaseJobTx as af, buildSendTx as ag, buildSwapTx as ah, checkPositiveAmount as ai, checkSuiAddress as aj, classifyAction as ak, classifyLabel as al, classifyTransaction as am, executeTx as an, extractAllUserLegs as ao, extractTransferDetails as ap, extractTxCommands as aq, extractTxSender as ar, fallbackLabel as as, findSwapRoute as at, formatAssetAmount as au, formatSui as av, formatUsd as aw, getDecimals as ax, getDecimalsForCoinType as ay, getJob as az, COIN_REGISTRY as b, type SponsoredCoinMergeCache as b0, type SendableAsset as b1, CETUS_USDC_SUI_POOL as b2, type CoinPage as b3, DEFAULT_GRPC_URL as b4, GASLESS_MIN_STABLE_AMOUNT as b5, GASLESS_STABLE_TYPES as b6, OPERATION_ASSETS as b7, type Operation as b8, SENDABLE_ASSETS as b9, type SelectAndSplitResult as ba, type SerializedCetusRoute as bb, type SerializedCetusRoutePath as bc, type SerializedRouterDataV3 as bd, addSendToTx as be, addSwapToTx as bf, assertAllowedAsset as bg, deserializeCetusRoute as bh, fetchAllCoins as bi, getCoinMeta as bj, getSuiClient as bk, getSuiGrpcClient as bl, isAllowedAsset as bm, isCetusRouteFresh as bn, isInRegistry as bo, normalizeAsset as bp, normalizeCoinType as bq, queryHistory as br, queryTransaction as bs, selectAndSplitCoin as bt, selectSuiCoin as bu, serializeCetusRoute as bv, simulateTransaction as bw, throwIfSimulationFailed as bx, verifyCetusRouteCoinMatch as by, type ClassifyBalanceChange as c, type ClassifyResult as d, type CoinMeta as e, type DepositInfo as f, type ExtractedTransfer as g, type Job as h, type JobState as i, type JobTerms as j, type JobVerification as k, KeypairSigner as l, LOFI_TYPE as m, MAX_DELIVER_HORIZON_MS as n, MAX_JOB_USDC as o, MAX_REVIEW_WINDOW_MS as p, MIST_PER_SUI as q, type OverlayFeeConfig as r, PREFLIGHT_OK as s, type PayOptions as t, type PayResult as u, type PreflightResult as v, SUI_DECIMALS as w, SUI_TYPE as x, SUPPORTED_ASSETS as y, type SendResult as z };
1490
+ declare const DEFAULT_COMMERCE_API_BASE = "https://api.t2000.ai/v1";
1491
+ /** The shape the API returns from GET /v1/offerings. */
1492
+ interface OfferingListing {
1493
+ agent: string;
1494
+ agentName: string | null;
1495
+ agentNumericId: number | null;
1496
+ slug: string;
1497
+ name: string;
1498
+ description: string;
1499
+ priceUsdc: number;
1500
+ slaMinutes: number;
1501
+ reviewWindowMinutes: number;
1502
+ rejectSplitBps: number;
1503
+ requirements: unknown;
1504
+ deliverable: string;
1505
+ retired: boolean;
1506
+ }
1507
+ /** Browse / list offerings — free-text `query` across every agent, or one
1508
+ * agent's full catalog (retired included) via `agent`. */
1509
+ declare function listOfferings(base: string, filter?: {
1510
+ agent?: string;
1511
+ query?: string;
1512
+ }): Promise<{
1513
+ total: number;
1514
+ offerings: OfferingListing[];
1515
+ }>;
1516
+ /** Fetch one agent's live offering by slug (the buy-path resolver). */
1517
+ declare function fetchOffering(base: string, agent: string, slug: string): Promise<OfferingListing>;
1518
+ /** Upload a job-spec payload to the content-addressed store; returns the
1519
+ * sha256 (no 0x) the chain pins as `spec_hash`. */
1520
+ declare function putJobSpec(base: string, content: string): Promise<string>;
1521
+ /** Fetch a job-spec payload by hash and VERIFY it (sha256(content) == hash —
1522
+ * the store is untrusted; the chain hash is the authority). */
1523
+ declare function getJobSpec(base: string, hash: string): Promise<string>;
1524
+
1525
+ export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, SUPPORTED_ASSETS as F, GAS_RESERVE_MIN as G, type SendResult as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a, validateAddress as a$, type TransactionLeg as a0, type TransactionRecord as a1, type TransactionSigner as a2, type TxDirection as a3, USDC_DECIMALS as a4, USDC_TYPE as a5, USDE_TYPE as a6, USDSUI_TYPE as a7, USDT_TYPE as a8, WAL_TYPE as a9, getDecimals as aA, getDecimalsForCoinType as aB, getJob as aC, getJobSpec as aD, jobActionsFor as aE, listOfferings as aF, mapMoveAbortCode as aG, mapWalletError as aH, mistToSui as aI, parseMppSuiChallenge as aJ, parseSuiRpcTx as aK, payWithMpp as aL, preflightCreateJob as aM, preflightFail as aN, preflightPay as aO, preflightSend as aP, preflightSwap as aQ, putJobSpec as aR, rawToStable as aS, rawToUsdc as aT, refineLendingLabel as aU, resolveSymbol as aV, resolveTokenType as aW, stableToRaw as aX, suiToMist as aY, truncateAddress as aZ, usdcToRaw as a_, WBTC_TYPE as aa, type ZkLoginProof as ab, ZkLoginSigner as ac, buildCreateJobTx as ad, buildDeliverJobTx as ae, buildRefundJobTx as af, buildRejectJobTx as ag, buildReleaseJobTx as ah, buildSendTx as ai, buildSwapTx as aj, checkPositiveAmount as ak, checkSuiAddress as al, classifyAction as am, classifyLabel as an, classifyTransaction as ao, executeTx as ap, extractAllUserLegs as aq, extractTransferDetails as ar, extractTxCommands as as, extractTxSender as at, fallbackLabel as au, fetchOffering as av, findSwapRoute as aw, formatAssetAmount as ax, formatSui as ay, formatUsd as az, COIN_REGISTRY as b, verifyJobForSeller as b0, type T2000Options as b1, type SwapResult as b2, type SwapQuoteResult as b3, type PaymentRequest as b4, type SuiCoreClient as b5, type SponsoredCoinMergeCache as b6, type SendableAsset as b7, CETUS_USDC_SUI_POOL as b8, type CoinPage as b9, selectSuiCoin as bA, serializeCetusRoute as bB, simulateTransaction as bC, throwIfSimulationFailed as bD, verifyCetusRouteCoinMatch as bE, DEFAULT_GRPC_URL as ba, GASLESS_MIN_STABLE_AMOUNT as bb, GASLESS_STABLE_TYPES as bc, OPERATION_ASSETS as bd, type Operation as be, SENDABLE_ASSETS as bf, type SelectAndSplitResult as bg, type SerializedCetusRoute as bh, type SerializedCetusRoutePath as bi, type SerializedRouterDataV3 as bj, addSendToTx as bk, addSwapToTx as bl, assertAllowedAsset as bm, deserializeCetusRoute as bn, fetchAllCoins as bo, getCoinMeta as bp, getSuiClient as bq, getSuiGrpcClient as br, isAllowedAsset as bs, isCetusRouteFresh as bt, isInRegistry as bu, normalizeAsset as bv, normalizeCoinType as bw, queryHistory as bx, queryTransaction as by, selectAndSplitCoin as bz, type ClassifyBalanceChange as c, type ClassifyResult as d, type CoinMeta as e, DEFAULT_NETWORK as f, type DepositInfo as g, type ExtractedTransfer as h, type Job as i, type JobState as j, type JobTerms as k, type JobVerification as l, KeypairSigner as m, LOFI_TYPE as n, MAX_DELIVER_HORIZON_MS as o, MAX_JOB_USDC as p, MAX_REVIEW_WINDOW_MS as q, MIST_PER_SUI as r, type OfferingListing as s, type OverlayFeeConfig as t, PREFLIGHT_OK as u, type PayOptions as v, type PayResult as w, type PreflightResult as x, SUI_DECIMALS as y, SUI_TYPE as z };
@@ -1487,4 +1487,39 @@ declare function verifyJobForSeller({ client, jobId, seller, minAmountUsdc, minR
1487
1487
  minRunwayMs?: number;
1488
1488
  }): Promise<JobVerification>;
1489
1489
 
1490
- export { type TransactionRecord as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_NETWORK as D, ETH_TYPE as E, type SimulationResult as F, GAS_RESERVE_MIN as G, type StableAsset as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SuiHolding as Q, type SuiRpcTxBlock as R, STABLE_ASSETS as S, type SupportedAsset as T, type SwapRouteResult as U, T2000Error as V, type T2000ErrorCode as W, type T2000ErrorData as X, T2000_OVERLAY_FEE_WALLET as Y, TOKEN_MAP as Z, type TransactionLeg as _, A2A_ESCROW_PACKAGE_ID as a, type SuiCoreClient as a$, type TransactionSigner as a0, type TxDirection as a1, USDC_DECIMALS as a2, USDC_TYPE as a3, USDE_TYPE as a4, USDSUI_TYPE as a5, USDT_TYPE as a6, WAL_TYPE as a7, WBTC_TYPE as a8, type ZkLoginProof as a9, jobActionsFor as aA, mapMoveAbortCode as aB, mapWalletError as aC, mistToSui as aD, parseMppSuiChallenge as aE, parseSuiRpcTx as aF, payWithMpp as aG, preflightCreateJob as aH, preflightFail as aI, preflightPay as aJ, preflightSend as aK, preflightSwap as aL, rawToStable as aM, rawToUsdc as aN, refineLendingLabel as aO, resolveSymbol as aP, resolveTokenType as aQ, stableToRaw as aR, suiToMist as aS, truncateAddress as aT, usdcToRaw as aU, validateAddress as aV, verifyJobForSeller as aW, type T2000Options as aX, type SwapResult as aY, type SwapQuoteResult as aZ, type PaymentRequest as a_, ZkLoginSigner as aa, buildCreateJobTx as ab, buildDeliverJobTx as ac, buildRefundJobTx as ad, buildRejectJobTx as ae, buildReleaseJobTx as af, buildSendTx as ag, buildSwapTx as ah, checkPositiveAmount as ai, checkSuiAddress as aj, classifyAction as ak, classifyLabel as al, classifyTransaction as am, executeTx as an, extractAllUserLegs as ao, extractTransferDetails as ap, extractTxCommands as aq, extractTxSender as ar, fallbackLabel as as, findSwapRoute as at, formatAssetAmount as au, formatSui as av, formatUsd as aw, getDecimals as ax, getDecimalsForCoinType as ay, getJob as az, COIN_REGISTRY as b, type SponsoredCoinMergeCache as b0, type SendableAsset as b1, CETUS_USDC_SUI_POOL as b2, type CoinPage as b3, DEFAULT_GRPC_URL as b4, GASLESS_MIN_STABLE_AMOUNT as b5, GASLESS_STABLE_TYPES as b6, OPERATION_ASSETS as b7, type Operation as b8, SENDABLE_ASSETS as b9, type SelectAndSplitResult as ba, type SerializedCetusRoute as bb, type SerializedCetusRoutePath as bc, type SerializedRouterDataV3 as bd, addSendToTx as be, addSwapToTx as bf, assertAllowedAsset as bg, deserializeCetusRoute as bh, fetchAllCoins as bi, getCoinMeta as bj, getSuiClient as bk, getSuiGrpcClient as bl, isAllowedAsset as bm, isCetusRouteFresh as bn, isInRegistry as bo, normalizeAsset as bp, normalizeCoinType as bq, queryHistory as br, queryTransaction as bs, selectAndSplitCoin as bt, selectSuiCoin as bu, serializeCetusRoute as bv, simulateTransaction as bw, throwIfSimulationFailed as bx, verifyCetusRouteCoinMatch as by, type ClassifyBalanceChange as c, type ClassifyResult as d, type CoinMeta as e, type DepositInfo as f, type ExtractedTransfer as g, type Job as h, type JobState as i, type JobTerms as j, type JobVerification as k, KeypairSigner as l, LOFI_TYPE as m, MAX_DELIVER_HORIZON_MS as n, MAX_JOB_USDC as o, MAX_REVIEW_WINDOW_MS as p, MIST_PER_SUI as q, type OverlayFeeConfig as r, PREFLIGHT_OK as s, type PayOptions as t, type PayResult as u, type PreflightResult as v, SUI_DECIMALS as w, SUI_TYPE as x, SUPPORTED_ASSETS as y, type SendResult as z };
1490
+ declare const DEFAULT_COMMERCE_API_BASE = "https://api.t2000.ai/v1";
1491
+ /** The shape the API returns from GET /v1/offerings. */
1492
+ interface OfferingListing {
1493
+ agent: string;
1494
+ agentName: string | null;
1495
+ agentNumericId: number | null;
1496
+ slug: string;
1497
+ name: string;
1498
+ description: string;
1499
+ priceUsdc: number;
1500
+ slaMinutes: number;
1501
+ reviewWindowMinutes: number;
1502
+ rejectSplitBps: number;
1503
+ requirements: unknown;
1504
+ deliverable: string;
1505
+ retired: boolean;
1506
+ }
1507
+ /** Browse / list offerings — free-text `query` across every agent, or one
1508
+ * agent's full catalog (retired included) via `agent`. */
1509
+ declare function listOfferings(base: string, filter?: {
1510
+ agent?: string;
1511
+ query?: string;
1512
+ }): Promise<{
1513
+ total: number;
1514
+ offerings: OfferingListing[];
1515
+ }>;
1516
+ /** Fetch one agent's live offering by slug (the buy-path resolver). */
1517
+ declare function fetchOffering(base: string, agent: string, slug: string): Promise<OfferingListing>;
1518
+ /** Upload a job-spec payload to the content-addressed store; returns the
1519
+ * sha256 (no 0x) the chain pins as `spec_hash`. */
1520
+ declare function putJobSpec(base: string, content: string): Promise<string>;
1521
+ /** Fetch a job-spec payload by hash and VERIFY it (sha256(content) == hash —
1522
+ * the store is untrusted; the chain hash is the authority). */
1523
+ declare function getJobSpec(base: string, hash: string): Promise<string>;
1524
+
1525
+ export { TOKEN_MAP as $, A2A_ESCROW_FEE_CONFIG_ID as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_COMMERCE_API_BASE as D, ETH_TYPE as E, SUPPORTED_ASSETS as F, GAS_RESERVE_MIN as G, type SendResult as H, IKA_TYPE as I, JOB_STATES as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type SimulationResult as Q, type StableAsset as R, STABLE_ASSETS as S, type SuiHolding as T, type SuiRpcTxBlock as U, type SupportedAsset as V, type SwapRouteResult as W, T2000Error as X, type T2000ErrorCode as Y, type T2000ErrorData as Z, T2000_OVERLAY_FEE_WALLET as _, A2A_ESCROW_PACKAGE_ID as a, validateAddress as a$, type TransactionLeg as a0, type TransactionRecord as a1, type TransactionSigner as a2, type TxDirection as a3, USDC_DECIMALS as a4, USDC_TYPE as a5, USDE_TYPE as a6, USDSUI_TYPE as a7, USDT_TYPE as a8, WAL_TYPE as a9, getDecimals as aA, getDecimalsForCoinType as aB, getJob as aC, getJobSpec as aD, jobActionsFor as aE, listOfferings as aF, mapMoveAbortCode as aG, mapWalletError as aH, mistToSui as aI, parseMppSuiChallenge as aJ, parseSuiRpcTx as aK, payWithMpp as aL, preflightCreateJob as aM, preflightFail as aN, preflightPay as aO, preflightSend as aP, preflightSwap as aQ, putJobSpec as aR, rawToStable as aS, rawToUsdc as aT, refineLendingLabel as aU, resolveSymbol as aV, resolveTokenType as aW, stableToRaw as aX, suiToMist as aY, truncateAddress as aZ, usdcToRaw as a_, WBTC_TYPE as aa, type ZkLoginProof as ab, ZkLoginSigner as ac, buildCreateJobTx as ad, buildDeliverJobTx as ae, buildRefundJobTx as af, buildRejectJobTx as ag, buildReleaseJobTx as ah, buildSendTx as ai, buildSwapTx as aj, checkPositiveAmount as ak, checkSuiAddress as al, classifyAction as am, classifyLabel as an, classifyTransaction as ao, executeTx as ap, extractAllUserLegs as aq, extractTransferDetails as ar, extractTxCommands as as, extractTxSender as at, fallbackLabel as au, fetchOffering as av, findSwapRoute as aw, formatAssetAmount as ax, formatSui as ay, formatUsd as az, COIN_REGISTRY as b, verifyJobForSeller as b0, type T2000Options as b1, type SwapResult as b2, type SwapQuoteResult as b3, type PaymentRequest as b4, type SuiCoreClient as b5, type SponsoredCoinMergeCache as b6, type SendableAsset as b7, CETUS_USDC_SUI_POOL as b8, type CoinPage as b9, selectSuiCoin as bA, serializeCetusRoute as bB, simulateTransaction as bC, throwIfSimulationFailed as bD, verifyCetusRouteCoinMatch as bE, DEFAULT_GRPC_URL as ba, GASLESS_MIN_STABLE_AMOUNT as bb, GASLESS_STABLE_TYPES as bc, OPERATION_ASSETS as bd, type Operation as be, SENDABLE_ASSETS as bf, type SelectAndSplitResult as bg, type SerializedCetusRoute as bh, type SerializedCetusRoutePath as bi, type SerializedRouterDataV3 as bj, addSendToTx as bk, addSwapToTx as bl, assertAllowedAsset as bm, deserializeCetusRoute as bn, fetchAllCoins as bo, getCoinMeta as bp, getSuiClient as bq, getSuiGrpcClient as br, isAllowedAsset as bs, isCetusRouteFresh as bt, isInRegistry as bu, normalizeAsset as bv, normalizeCoinType as bw, queryHistory as bx, queryTransaction as by, selectAndSplitCoin as bz, type ClassifyBalanceChange as c, type ClassifyResult as d, type CoinMeta as e, DEFAULT_NETWORK as f, type DepositInfo as g, type ExtractedTransfer as h, type Job as i, type JobState as j, type JobTerms as k, type JobVerification as l, KeypairSigner as m, LOFI_TYPE as n, MAX_DELIVER_HORIZON_MS as o, MAX_JOB_USDC as p, MAX_REVIEW_WINDOW_MS as q, MIST_PER_SUI as r, type OfferingListing as s, type OverlayFeeConfig as t, PREFLIGHT_OK as u, type PayOptions as v, type PayResult as w, type PreflightResult as x, SUI_DECIMALS as y, SUI_TYPE as z };
package/dist/index.cjs CHANGED
@@ -1540,6 +1540,18 @@ async function buildSendTx({
1540
1540
  required: amount
1541
1541
  });
1542
1542
  }
1543
+ if (asset === "USDC" || asset === "USDsui") {
1544
+ const rawFloor = displayToRaw(GASLESS_MIN_STABLE_AMOUNT, assetInfo.decimals);
1545
+ const remainder = totalBalance - rawAmount;
1546
+ if (remainder > 0n && remainder < rawFloor) {
1547
+ const total = Number(totalBalance) / 10 ** assetInfo.decimals;
1548
+ throw new exports.T2000Error(
1549
+ "INVALID_AMOUNT",
1550
+ `Gasless ${asset} transfers must send the entire balance or leave at least ${GASLESS_MIN_STABLE_AMOUNT} ${asset}. Sending ${amount} of ${total} leaves ${(total - amount).toFixed(assetInfo.decimals)}. Send ${total} (everything) or at most ${(total - GASLESS_MIN_STABLE_AMOUNT).toFixed(assetInfo.decimals)}.`,
1551
+ { available: total, required: amount }
1552
+ );
1553
+ }
1554
+ }
1543
1555
  if (asset === "SUI") {
1544
1556
  const [sendCoin] = tx.splitCoins(tx.gas, [rawAmount]);
1545
1557
  tx.transferObjects([sendCoin], recipient);
@@ -3366,6 +3378,81 @@ async function verifyJobForSeller({
3366
3378
  return { ok: problems.length === 0, job, problems };
3367
3379
  }
3368
3380
 
3381
+ // src/commerce.ts
3382
+ var DEFAULT_COMMERCE_API_BASE = "https://api.t2000.ai/v1";
3383
+ async function commerceFetchJson(url, init) {
3384
+ const res = await fetch(url, {
3385
+ method: init?.method ?? "GET",
3386
+ headers: init?.body ? { "Content-Type": "application/json" } : void 0,
3387
+ body: init?.body ? JSON.stringify(init.body) : void 0
3388
+ });
3389
+ const json = await res.json().catch(() => ({}));
3390
+ if (!res.ok) {
3391
+ const err = json.error;
3392
+ const msg = typeof err === "string" ? err : err?.message ?? `HTTP ${res.status}`;
3393
+ throw new Error(msg);
3394
+ }
3395
+ return json;
3396
+ }
3397
+ async function listOfferings(base, filter = {}) {
3398
+ const params = new URLSearchParams();
3399
+ if (filter.agent) params.set("agent", filter.agent);
3400
+ if (filter.query) params.set("q", filter.query);
3401
+ const qs = params.size > 0 ? `?${params.toString()}` : "";
3402
+ const json = await commerceFetchJson(`${base}/offerings${qs}`);
3403
+ const offerings = json.offerings ?? [];
3404
+ return { total: json.total ?? offerings.length, offerings };
3405
+ }
3406
+ async function fetchOffering(base, agent, slug) {
3407
+ const { offerings: rows } = await listOfferings(base, { agent });
3408
+ const match = rows.find((o) => o.slug === slug.trim().toLowerCase());
3409
+ if (!match) {
3410
+ const live = rows.filter((o) => !o.retired).map((o) => o.slug);
3411
+ throw new Error(
3412
+ `Agent ${truncateAddress(agent)} has no offering "${slug}".` + (live.length > 0 ? ` Live offerings: ${live.join(", ")}` : "")
3413
+ );
3414
+ }
3415
+ if (match.retired) {
3416
+ throw new Error(
3417
+ `Offering "${slug}" is retired \u2014 the seller no longer sells it.`
3418
+ );
3419
+ }
3420
+ return match;
3421
+ }
3422
+ async function sha256Hex(content) {
3423
+ const digest = await crypto.subtle.digest(
3424
+ "SHA-256",
3425
+ new TextEncoder().encode(content)
3426
+ );
3427
+ return Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
3428
+ }
3429
+ async function putJobSpec(base, content) {
3430
+ const json = await commerceFetchJson(`${base}/job/spec`, {
3431
+ method: "POST",
3432
+ body: { content }
3433
+ });
3434
+ const hash = json.hash;
3435
+ if (!hash) {
3436
+ throw new Error("Failed to store the job spec.");
3437
+ }
3438
+ return hash;
3439
+ }
3440
+ async function getJobSpec(base, hash) {
3441
+ const clean = hash.trim().toLowerCase().replace(/^0x/, "");
3442
+ const json = await commerceFetchJson(`${base}/job/spec/${clean}`);
3443
+ const content = json.content;
3444
+ if (content === void 0) {
3445
+ throw new Error("No spec stored for this hash.");
3446
+ }
3447
+ const actual = await sha256Hex(content);
3448
+ if (actual !== clean) {
3449
+ throw new Error(
3450
+ "Spec content does NOT match its hash \u2014 the store returned tampered data. Do not trust it."
3451
+ );
3452
+ }
3453
+ return content;
3454
+ }
3455
+
3369
3456
  // src/index.ts
3370
3457
  init_coinSelection();
3371
3458
 
@@ -3801,6 +3888,7 @@ exports.AUDRIC_PARENT_NFT_ID = AUDRIC_PARENT_NFT_ID;
3801
3888
  exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
3802
3889
  exports.CLOCK_ID = CLOCK_ID;
3803
3890
  exports.DEFAULT_API_BASE = DEFAULT_API_BASE;
3891
+ exports.DEFAULT_COMMERCE_API_BASE = DEFAULT_COMMERCE_API_BASE;
3804
3892
  exports.DEFAULT_GRPC_URL = DEFAULT_GRPC_URL;
3805
3893
  exports.DEFAULT_NETWORK = DEFAULT_NETWORK;
3806
3894
  exports.GASLESS_MIN_STABLE_AMOUNT = GASLESS_MIN_STABLE_AMOUNT;
@@ -3868,6 +3956,7 @@ exports.extractTxCommands = extractTxCommands;
3868
3956
  exports.extractTxSender = extractTxSender;
3869
3957
  exports.fallbackLabel = fallbackLabel;
3870
3958
  exports.fetchAllCoins = fetchAllCoins;
3959
+ exports.fetchOffering = fetchOffering;
3871
3960
  exports.findSwapRoute = findSwapRoute;
3872
3961
  exports.formatAssetAmount = formatAssetAmount;
3873
3962
  exports.formatSui = formatSui;
@@ -3879,6 +3968,7 @@ exports.getCoinMeta = getCoinMeta;
3879
3968
  exports.getDecimals = getDecimals;
3880
3969
  exports.getDecimalsForCoinType = getDecimalsForCoinType;
3881
3970
  exports.getJob = getJob;
3971
+ exports.getJobSpec = getJobSpec;
3882
3972
  exports.getLimits = getLimits;
3883
3973
  exports.getSponsoredSwapProviders = getSponsoredSwapProviders;
3884
3974
  exports.getSuiClient = getSuiClient;
@@ -3891,6 +3981,7 @@ exports.isInRegistry = isInRegistry;
3891
3981
  exports.jobActionsFor = jobActionsFor;
3892
3982
  exports.keypairFromPrivateKey = keypairFromPrivateKey;
3893
3983
  exports.listModels = listModels;
3984
+ exports.listOfferings = listOfferings;
3894
3985
  exports.loadKey = loadKey;
3895
3986
  exports.looksLikeSuiNs = looksLikeSuiNs;
3896
3987
  exports.mapMoveAbortCode = mapMoveAbortCode;
@@ -3907,6 +3998,7 @@ exports.preflightFail = preflightFail;
3907
3998
  exports.preflightPay = preflightPay;
3908
3999
  exports.preflightSend = preflightSend;
3909
4000
  exports.preflightSwap = preflightSwap;
4001
+ exports.putJobSpec = putJobSpec;
3910
4002
  exports.queryBalance = queryBalance;
3911
4003
  exports.queryHistory = queryHistory;
3912
4004
  exports.queryTransaction = queryTransaction;