tenjin-cli 0.1.0-alpha.17 → 0.1.0-alpha.18

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.
Files changed (61) hide show
  1. package/README.md +3 -0
  2. package/dist/chunk-3KKKB2AQ.js +40 -0
  3. package/dist/chunk-3KKKB2AQ.js.map +1 -0
  4. package/dist/{chunk-56MOAIP5.js → chunk-BTX2QE2Y.js} +9 -6
  5. package/dist/chunk-BTX2QE2Y.js.map +1 -0
  6. package/dist/{chunk-2JGT3KDW.js → chunk-EPCOMXLF.js} +2 -2
  7. package/dist/{chunk-O4ZNKFRU.js → chunk-F3FUGWPZ.js} +5 -5
  8. package/dist/{chunk-LJ4DMVFI.js → chunk-FGR734LZ.js} +2 -2
  9. package/dist/{chunk-QDD2RN7G.js → chunk-N44H5TFB.js} +55 -33
  10. package/dist/chunk-N44H5TFB.js.map +1 -0
  11. package/dist/{chunk-5UDD5VSY.js → chunk-NRQMOVKM.js} +2 -2
  12. package/dist/{chunk-5UDD5VSY.js.map → chunk-NRQMOVKM.js.map} +1 -1
  13. package/dist/{chunk-KK4YGYTV.js → chunk-ON6C6WOX.js} +2 -2
  14. package/dist/{chunk-XZOEUYMX.js → chunk-TJMCBIZU.js} +2 -2
  15. package/dist/{chunk-5QHHRMRA.js → chunk-WUHY2AXD.js} +2 -2
  16. package/dist/{chunk-WGQVJM56.js → chunk-YPQSMIDH.js} +2 -2
  17. package/dist/{chunk-MRGADYDD.js → chunk-ZG7SFI34.js} +2 -2
  18. package/dist/{cli-VHYYYYXM.js → cli-MP3RAYHL.js} +19 -19
  19. package/dist/{config-5ADBAAXU.js → config-BJK6U5VY.js} +4 -4
  20. package/dist/{doctor-Q35VQW3S.js → doctor-KJROWE5V.js} +8 -8
  21. package/dist/{fund-GDDPL2BB.js → fund-I5COXPEJ.js} +5 -4
  22. package/dist/{fund-GDDPL2BB.js.map → fund-I5COXPEJ.js.map} +1 -1
  23. package/dist/{hook-command-PBERPRE3.js → hook-command-EJO2564A.js} +77 -19
  24. package/dist/hook-command-EJO2564A.js.map +1 -0
  25. package/dist/index.js +1 -1
  26. package/dist/{install-OKDKGUXM.js → install-NUQLLHS2.js} +6 -6
  27. package/dist/{install-wallet-SI4LZ73K.js → install-wallet-JPFTEC6H.js} +4 -3
  28. package/dist/{install-wallet-SI4LZ73K.js.map → install-wallet-JPFTEC6H.js.map} +1 -1
  29. package/dist/{mcp-XX3WRQEZ.js → mcp-I5XMVE64.js} +19 -8
  30. package/dist/{mcp-XX3WRQEZ.js.map → mcp-I5XMVE64.js.map} +1 -1
  31. package/dist/{pay-3SYKHKWJ.js → pay-WA3JSCNB.js} +10 -5
  32. package/dist/{send-LQRKTEJT.js → send-KVUH5WDO.js} +3 -2
  33. package/dist/{send-LQRKTEJT.js.map → send-KVUH5WDO.js.map} +1 -1
  34. package/dist/{status-line-wiring-L2WYIYBM.js → status-line-wiring-DQZCWIUO.js} +4 -4
  35. package/dist/tenjin-daemon.mjs +1 -1
  36. package/dist/{uninstall-OACH27UV.js → uninstall-SWICHBTF.js} +29 -9
  37. package/dist/uninstall-SWICHBTF.js.map +1 -0
  38. package/dist/{update-4W6EKLGZ.js → update-W572AMXG.js} +3 -3
  39. package/dist/{wallet-BMEXRR3P.js → wallet-L2YLAJFN.js} +4 -3
  40. package/docs/agent-permissions.md +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-56MOAIP5.js.map +0 -1
  43. package/dist/chunk-QDD2RN7G.js.map +0 -1
  44. package/dist/hook-command-PBERPRE3.js.map +0 -1
  45. package/dist/uninstall-OACH27UV.js.map +0 -1
  46. /package/dist/{chunk-2JGT3KDW.js.map → chunk-EPCOMXLF.js.map} +0 -0
  47. /package/dist/{chunk-O4ZNKFRU.js.map → chunk-F3FUGWPZ.js.map} +0 -0
  48. /package/dist/{chunk-LJ4DMVFI.js.map → chunk-FGR734LZ.js.map} +0 -0
  49. /package/dist/{chunk-KK4YGYTV.js.map → chunk-ON6C6WOX.js.map} +0 -0
  50. /package/dist/{chunk-XZOEUYMX.js.map → chunk-TJMCBIZU.js.map} +0 -0
  51. /package/dist/{chunk-5QHHRMRA.js.map → chunk-WUHY2AXD.js.map} +0 -0
  52. /package/dist/{chunk-WGQVJM56.js.map → chunk-YPQSMIDH.js.map} +0 -0
  53. /package/dist/{chunk-MRGADYDD.js.map → chunk-ZG7SFI34.js.map} +0 -0
  54. /package/dist/{cli-VHYYYYXM.js.map → cli-MP3RAYHL.js.map} +0 -0
  55. /package/dist/{config-5ADBAAXU.js.map → config-BJK6U5VY.js.map} +0 -0
  56. /package/dist/{doctor-Q35VQW3S.js.map → doctor-KJROWE5V.js.map} +0 -0
  57. /package/dist/{install-OKDKGUXM.js.map → install-NUQLLHS2.js.map} +0 -0
  58. /package/dist/{pay-3SYKHKWJ.js.map → pay-WA3JSCNB.js.map} +0 -0
  59. /package/dist/{status-line-wiring-L2WYIYBM.js.map → status-line-wiring-DQZCWIUO.js.map} +0 -0
  60. /package/dist/{update-4W6EKLGZ.js.map → update-W572AMXG.js.map} +0 -0
  61. /package/dist/{wallet-BMEXRR3P.js.map → wallet-L2YLAJFN.js.map} +0 -0
package/README.md CHANGED
@@ -82,6 +82,9 @@ To keep it installed and stop it, `tenjin config set router.enabled false` stops
82
82
 
83
83
  ## Developing
84
84
 
85
+ Before submitting a contribution, read [CONTRIBUTING.md](./CONTRIBUTING.md) for the
86
+ contributor agreement and acceptance instructions.
87
+
85
88
  ```bash
86
89
  pnpm install
87
90
  pnpm run githooks # once, to use the repo's git hooks
@@ -0,0 +1,40 @@
1
+ import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+
3
+ // src/lib/usdc-balance.ts
4
+ var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
5
+ var BALANCE_OF_SELECTOR = "0x70a08231";
6
+ var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
7
+ var WORD_RE = /^0x[0-9a-fA-F]{64}$/;
8
+ async function readUsdcBalance(address, rpcUrl, opts) {
9
+ if (!ADDRESS_RE.test(address) || opts.timeoutMs <= 0) return null;
10
+ try {
11
+ const res = await (opts.fetchImpl ?? fetch)(rpcUrl, {
12
+ method: "POST",
13
+ headers: { "content-type": "application/json" },
14
+ body: JSON.stringify({
15
+ jsonrpc: "2.0",
16
+ id: 1,
17
+ method: "eth_call",
18
+ params: [
19
+ {
20
+ to: USDC_ADDRESS,
21
+ data: `${BALANCE_OF_SELECTOR}${address.slice(2).toLowerCase().padStart(64, "0")}`
22
+ },
23
+ "latest"
24
+ ]
25
+ }),
26
+ signal: AbortSignal.timeout(opts.timeoutMs)
27
+ });
28
+ if (!res.ok) return null;
29
+ const result = (await res.json())?.result;
30
+ return typeof result === "string" && WORD_RE.test(result) ? BigInt(result) : null;
31
+ } catch {
32
+ return null;
33
+ }
34
+ }
35
+
36
+ export {
37
+ USDC_ADDRESS,
38
+ readUsdcBalance
39
+ };
40
+ //# sourceMappingURL=chunk-3KKKB2AQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/usdc-balance.ts"],"sourcesContent":["/**\n * Base USDC's address and one `balanceOf` over plain JSON-RPC. No viem on\n * purpose: the router hooks read a balance before they redirect a call, and\n * their chunk graph must stay free of it (`src/router/dist-chunks.test.ts`).\n * One `eth_call` needs nothing viem adds. `usdc.ts` keeps the viem client for\n * the send path and re-exports the address from here.\n */\n\n// Values mirror the app's lib/chain.ts Base mainnet entry (chain 8453).\nexport const USDC_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';\n\n/** `balanceOf(address)`: the first four bytes of its keccak-256. */\nconst BALANCE_OF_SELECTOR = '0x70a08231';\nconst ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n/** One ABI word: what `balanceOf` returns. */\nconst WORD_RE = /^0x[0-9a-fA-F]{64}$/;\n\n/**\n * The address's USDC balance in atomic units, or null when it could not be\n * read inside `timeoutMs`: a transport failure, a non-2xx, an RPC error, or an\n * answer that is not one word. Never throws, so the caller picks which way an\n * unreadable balance falls.\n */\nexport async function readUsdcBalance(\n address: string,\n rpcUrl: string,\n opts: { timeoutMs: number; fetchImpl?: typeof fetch },\n): Promise<bigint | null> {\n if (!ADDRESS_RE.test(address) || opts.timeoutMs <= 0) return null;\n try {\n const res = await (opts.fetchImpl ?? fetch)(rpcUrl, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'eth_call',\n params: [\n {\n to: USDC_ADDRESS,\n data: `${BALANCE_OF_SELECTOR}${address.slice(2).toLowerCase().padStart(64, '0')}`,\n },\n 'latest',\n ],\n }),\n signal: AbortSignal.timeout(opts.timeoutMs),\n });\n if (!res.ok) return null;\n const result = ((await res.json()) as { result?: unknown } | null)?.result;\n return typeof result === 'string' && WORD_RE.test(result) ? BigInt(result) : null;\n } catch {\n return null;\n }\n}\n"],"mappings":";;;AASO,IAAM,eAAe;AAG5B,IAAM,sBAAsB;AAC5B,IAAM,aAAa;AAEnB,IAAM,UAAU;AAQhB,eAAsB,gBACpB,SACA,QACA,MACwB;AACxB,MAAI,CAAC,WAAW,KAAK,OAAO,KAAK,KAAK,aAAa,EAAG,QAAO;AAC7D,MAAI;AACF,UAAM,MAAM,OAAO,KAAK,aAAa,OAAO,QAAQ;AAAA,MAClD,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU;AAAA,QACnB,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,QAAQ;AAAA,QACR,QAAQ;AAAA,UACN;AAAA,YACE,IAAI;AAAA,YACJ,MAAM,GAAG,mBAAmB,GAAG,QAAQ,MAAM,CAAC,EAAE,YAAY,EAAE,SAAS,IAAI,GAAG,CAAC;AAAA,UACjF;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,MACD,QAAQ,YAAY,QAAQ,KAAK,SAAS;AAAA,IAC5C,CAAC;AACD,QAAI,CAAC,IAAI,GAAI,QAAO;AACpB,UAAM,UAAW,MAAM,IAAI,KAAK,IAAoC;AACpE,WAAO,OAAO,WAAW,YAAY,QAAQ,KAAK,MAAM,IAAI,OAAO,MAAM,IAAI;AAAA,EAC/E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,4 +1,7 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
+ import {
3
+ USDC_ADDRESS
4
+ } from "./chunk-3KKKB2AQ.js";
2
5
  import {
3
6
  createPublicClient,
4
7
  defineBlock,
@@ -199,11 +202,11 @@ var basePreconf = /* @__PURE__ */ defineChain({
199
202
  });
200
203
 
201
204
  // src/lib/usdc.ts
202
- var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
205
+ var USDC_ADDRESS2 = USDC_ADDRESS;
203
206
  async function getUsdcBalance(address, rpcUrl) {
204
207
  const client = createPublicClient({ chain: base, transport: http(rpcUrl) });
205
208
  return client.readContract({
206
- address: USDC_ADDRESS,
209
+ address: USDC_ADDRESS2,
207
210
  abi: erc20Abi,
208
211
  functionName: "balanceOf",
209
212
  args: [address]
@@ -248,7 +251,7 @@ async function prepareUsdcSend({
248
251
  });
249
252
  const [nonce, gas, fees, ethBalanceWei] = await Promise.all([
250
253
  client.getTransactionCount({ address: from, blockTag: "pending" }),
251
- client.estimateGas({ account: from, to: USDC_ADDRESS, data }),
254
+ client.estimateGas({ account: from, to: USDC_ADDRESS2, data }),
252
255
  client.estimateFeesPerGas(),
253
256
  client.getBalance({ address: from })
254
257
  ]);
@@ -283,7 +286,7 @@ async function broadcastUsdcSend({
283
286
  const serializedTransaction = await signer.signTransaction({
284
287
  type: "eip1559",
285
288
  chainId: base.id,
286
- to: USDC_ADDRESS,
289
+ to: USDC_ADDRESS2,
287
290
  // Explicitly zero: an ERC-20 transfer carries no native value (test-pinned).
288
291
  value: 0n,
289
292
  data: prepared.data,
@@ -307,7 +310,7 @@ function assertUnderCap(field, value, cap) {
307
310
  }
308
311
 
309
312
  export {
310
- USDC_ADDRESS,
313
+ USDC_ADDRESS2 as USDC_ADDRESS,
311
314
  getUsdcBalance,
312
315
  FeeCapExceededError,
313
316
  SendRevertedError,
@@ -315,4 +318,4 @@ export {
315
318
  prepareUsdcSend,
316
319
  broadcastUsdcSend
317
320
  };
318
- //# sourceMappingURL=chunk-56MOAIP5.js.map
321
+ //# sourceMappingURL=chunk-BTX2QE2Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/contracts.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/formatters.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/serializers.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/chainConfig.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/chains/definitions/base.ts","../src/lib/usdc.ts"],"sourcesContent":["import type { Chain } from '../types/chain.js'\n\n/**\n * Predeploy contracts for OP Stack.\n * @see https://github.com/ethereum-optimism/optimism/blob/develop/specs/predeploys.md\n */\nexport const contracts = {\n gasPriceOracle: { address: '0x420000000000000000000000000000000000000F' },\n l1Block: { address: '0x4200000000000000000000000000000000000015' },\n l2CrossDomainMessenger: {\n address: '0x4200000000000000000000000000000000000007',\n },\n l2Erc721Bridge: { address: '0x4200000000000000000000000000000000000014' },\n l2StandardBridge: { address: '0x4200000000000000000000000000000000000010' },\n l2ToL1MessagePasser: {\n address: '0x4200000000000000000000000000000000000016',\n },\n} as const satisfies Chain['contracts']\n","import type { ChainFormatters } from '../types/chain.js'\nimport type { RpcTransaction } from '../types/rpc.js'\nimport { hexToBigInt, hexToNumber } from '../utils/encoding/fromHex.js'\nimport { defineBlock } from '../utils/formatters/block.js'\nimport {\n defineTransaction,\n formatTransaction,\n} from '../utils/formatters/transaction.js'\nimport { defineTransactionReceipt } from '../utils/formatters/transactionReceipt.js'\nimport type { OpStackBlock, OpStackRpcBlock } from './types/block.js'\nimport type {\n OpStackRpcTransaction,\n OpStackRpcTransactionReceipt,\n OpStackTransaction,\n OpStackTransactionReceipt,\n} from './types/transaction.js'\n\nexport const formatters = {\n block: /*#__PURE__*/ defineBlock({\n format(args: OpStackRpcBlock): OpStackBlock {\n const transactions = args.transactions?.map((transaction) => {\n if (typeof transaction === 'string') return transaction\n const formatted = formatTransaction(\n transaction as RpcTransaction,\n ) as OpStackTransaction\n if (formatted.typeHex === '0x7e') {\n formatted.isSystemTx = transaction.isSystemTx\n formatted.mint = transaction.mint\n ? hexToBigInt(transaction.mint)\n : undefined\n formatted.sourceHash = transaction.sourceHash\n formatted.type = 'deposit'\n }\n return formatted\n })\n return {\n transactions,\n stateRoot: args.stateRoot,\n } as OpStackBlock\n },\n }),\n transaction: /*#__PURE__*/ defineTransaction({\n format(args: OpStackRpcTransaction): OpStackTransaction {\n const transaction = {} as OpStackTransaction\n if (args.type === '0x7e') {\n transaction.isSystemTx = args.isSystemTx\n transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined\n transaction.sourceHash = args.sourceHash\n transaction.type = 'deposit'\n }\n return transaction\n },\n }),\n transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({\n format(args: OpStackRpcTransactionReceipt): OpStackTransactionReceipt {\n return {\n ...(args.depositNonce\n ? { depositNonce: hexToBigInt(args.depositNonce) }\n : {}),\n ...(args.depositReceiptVersion\n ? { depositReceiptVersion: hexToNumber(args.depositReceiptVersion) }\n : {}),\n l1GasPrice: args.l1GasPrice ? hexToBigInt(args.l1GasPrice) : null,\n l1GasUsed: args.l1GasUsed ? hexToBigInt(args.l1GasUsed) : null,\n l1Fee: args.l1Fee ? hexToBigInt(args.l1Fee) : null,\n l1FeeScalar: args.l1FeeScalar ? Number(args.l1FeeScalar) : null,\n } as OpStackTransactionReceipt\n },\n }),\n} as const satisfies ChainFormatters\n","import { InvalidAddressError } from '../errors/address.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport type { ChainSerializers } from '../types/chain.js'\nimport type { Hex, Signature } from '../types/misc.js'\nimport type { TransactionSerializable } from '../types/transaction.js'\nimport type { RequiredBy } from '../types/utils.js'\nimport { isAddress } from '../utils/address/isAddress.js'\nimport { concatHex } from '../utils/data/concat.js'\nimport { toHex } from '../utils/encoding/toHex.js'\nimport { toRlp } from '../utils/encoding/toRlp.js'\nimport {\n type SerializeTransactionErrorType as SerializeTransactionErrorType_,\n serializeTransaction as serializeTransaction_,\n} from '../utils/transaction/serializeTransaction.js'\nimport type {\n OpStackTransactionSerializable,\n TransactionSerializableDeposit,\n TransactionSerializedDeposit,\n} from './types/transaction.js'\n\nexport type SerializeTransactionReturnType = ReturnType<\n typeof serializeTransaction\n>\n\nexport type SerializeTransactionErrorType =\n | SerializeTransactionErrorType_\n | ErrorType\n\nexport function serializeTransaction(\n transaction: OpStackTransactionSerializable,\n signature?: Signature,\n) {\n if (isDeposit(transaction)) return serializeTransactionDeposit(transaction)\n return serializeTransaction_(\n transaction as TransactionSerializable,\n signature,\n )\n}\n\nexport const serializers = {\n transaction: serializeTransaction,\n} as const satisfies ChainSerializers\n\n//////////////////////////////////////////////////////////////////////////////\n// Serializers\n\nexport type SerializeTransactionDepositReturnType = TransactionSerializedDeposit\n\nfunction serializeTransactionDeposit(\n transaction: TransactionSerializableDeposit,\n): SerializeTransactionDepositReturnType {\n assertTransactionDeposit(transaction)\n\n const { sourceHash, data, from, gas, isSystemTx, mint, to, value } =\n transaction\n\n const serializedTransaction: Hex[] = [\n sourceHash,\n from,\n to ?? '0x',\n mint ? toHex(mint) : '0x',\n value ? toHex(value) : '0x',\n gas ? toHex(gas) : '0x',\n isSystemTx ? '0x1' : '0x',\n data ?? '0x',\n ]\n\n return concatHex([\n '0x7e',\n toRlp(serializedTransaction),\n ]) as SerializeTransactionDepositReturnType\n}\n\nfunction isDeposit(\n transaction: OpStackTransactionSerializable,\n): transaction is RequiredBy<TransactionSerializableDeposit, 'type'> {\n if (transaction.type === 'deposit') return true\n if (typeof transaction.sourceHash !== 'undefined') return true\n return false\n}\n\nexport function assertTransactionDeposit(\n transaction: TransactionSerializableDeposit,\n) {\n const { from, to } = transaction\n if (from && !isAddress(from)) throw new InvalidAddressError({ address: from })\n if (to && !isAddress(to)) throw new InvalidAddressError({ address: to })\n}\n","import { contracts } from './contracts.js'\nimport { formatters } from './formatters.js'\nimport { serializers } from './serializers.js'\n\nexport const chainConfig = {\n blockTime: 2_000,\n contracts,\n formatters,\n serializers,\n} as const\n","import { chainConfig } from '../../op-stack/chainConfig.js'\nimport { defineChain } from '../../utils/chain/defineChain.js'\n\nconst sourceId = 1 // mainnet\n\nexport const base = /*#__PURE__*/ defineChain({\n ...chainConfig,\n id: 8453,\n name: 'Base',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: {\n http: ['https://mainnet.base.org'],\n },\n },\n blockExplorers: {\n default: {\n name: 'Basescan',\n url: 'https://basescan.org',\n apiUrl: 'https://api.basescan.org/api',\n },\n },\n contracts: {\n ...chainConfig.contracts,\n disputeGameFactory: {\n [sourceId]: {\n address: '0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e',\n },\n },\n l2OutputOracle: {\n [sourceId]: {\n address: '0x56315b90c40730925ec5485cf004d835058518A0',\n },\n },\n multicall3: {\n address: '0xca11bde05977b3631167028862be2a173976ca11',\n blockCreated: 5022,\n },\n portal: {\n [sourceId]: {\n address: '0x49048044D57e1C92A77f79988d21Fa8fAF74E97e',\n blockCreated: 17482143,\n },\n },\n l1StandardBridge: {\n [sourceId]: {\n address: '0x3154Cf16ccdb4C6d922629664174b904d80F2C35',\n blockCreated: 17482143,\n },\n },\n },\n sourceId,\n})\n\nexport const basePreconf = /*#__PURE__*/ defineChain({\n ...base,\n experimental_preconfirmationTime: 200,\n rpcUrls: {\n default: {\n http: ['https://mainnet-preconf.base.org'],\n },\n },\n})\n","import {\n createPublicClient,\n decodeFunctionData,\n encodeFunctionData,\n erc20Abi,\n http,\n type Address,\n type Hex,\n} from 'viem';\nimport { base } from 'viem/chains';\nimport { USDC_ADDRESS as USDC } from './usdc-balance';\nimport type { TenjinSigner } from './wallet/provider';\n\n/** Lives in `usdc-balance.ts`, which the viem-free hooks can load. */\nexport const USDC_ADDRESS: Address = USDC;\nexport const USDC_DECIMALS = 6;\n\nexport async function getUsdcBalance(address: Address, rpcUrl: string): Promise<bigint> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n return client.readContract({\n address: USDC_ADDRESS,\n abi: erc20Abi,\n functionName: 'balanceOf',\n args: [address],\n });\n}\n\n// The chain boundary for `tenjin wallet send`, two-phase around the human confirm:\n// prepareUsdcSend (read-only: encode, nonce, gas, fees, ETH-for-gas balance)\n// runs BEFORE the confirm so the prompt can show the fee, broadcastUsdcSend\n// (sign via the TenjinSigner seam, broadcast, wait for the receipt) runs after.\n// Command tests mock this whole module, so no test can ever reach a real chain.\n\n/**\n * Ceilings on the RPC-supplied gas and fee fields. The RPC endpoint is\n * config-controlled and its estimates go straight into the signed transaction; a\n * hostile or broken endpoint returning huge values would burn the wallet's ETH\n * as fees. An ERC-20 transfer is ~65k gas and Base fees run well under a gwei,\n * so estimates past these bounds mean something is wrong: refuse, never clamp\n * (a clamped maxFeePerGas below the real base fee would just strand the tx).\n * A genuine extreme fee spike on Base trips the same refusal; that is intended\n * — waiting it out beats signing an irreversible transfer at panic prices.\n */\nexport const SEND_GAS_CAP = 150_000n;\nexport const SEND_MAX_FEE_PER_GAS_CAP = 10_000_000_000n; // 10 gwei\nexport const SEND_MAX_PRIORITY_FEE_CAP = 2_000_000_000n; // 2 gwei\n\n/** An RPC gas/fee estimate exceeded the send ceilings; nothing was signed. */\nexport class FeeCapExceededError extends Error {\n constructor(field: string, value: bigint, cap: bigint) {\n super(`${field} estimate ${value} exceeds the send ceiling ${cap}`);\n this.name = 'FeeCapExceededError';\n }\n}\n\n/** The transfer was mined but reverted; the fee was spent, the USDC did not move. */\nexport class SendRevertedError extends Error {\n constructor(readonly txHash: Hex) {\n super(`Transaction ${txHash} reverted`);\n this.name = 'SendRevertedError';\n }\n}\n\n/** Broadcast succeeded but no receipt arrived in time; the tx may still mine. */\nexport class SendPendingError extends Error {\n constructor(readonly txHash: Hex) {\n super(`Transaction ${txHash} was broadcast but not confirmed in time`);\n this.name = 'SendPendingError';\n }\n}\n\nexport interface PrepareUsdcSendArgs {\n from: Address;\n to: Address;\n amountAtomic: bigint;\n rpcUrl: string;\n}\n\n/**\n * Everything signed later, fixed at prepare time, plus the gas-cost preview.\n * The nonce is pinned here, BEFORE the human confirm, so anything else spending\n * from this key during that window makes the later broadcast fail nonce-stale\n * (an RPC_ERROR from the node; nothing double-spends — re-run to re-prepare).\n * `to` and `amountAtomic` are the previewed intent; broadcastUsdcSend re-decodes\n * `data` against them before signing.\n */\nexport interface PreparedUsdcSend {\n to: Address;\n amountAtomic: bigint;\n data: Hex;\n nonce: number;\n gas: bigint;\n maxFeePerGas: bigint;\n maxPriorityFeePerGas: bigint;\n /** Worst-case fee (gas * maxFeePerGas), for the confirm prompt and gas check. */\n feeWei: bigint;\n /** The sender's native ETH balance, for the has-gas pre-check. */\n ethBalanceWei: bigint;\n}\n\nexport async function prepareUsdcSend({\n from,\n to,\n amountAtomic,\n rpcUrl,\n}: PrepareUsdcSendArgs): Promise<PreparedUsdcSend> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n const data = encodeFunctionData({\n abi: erc20Abi,\n functionName: 'transfer',\n args: [to, amountAtomic],\n });\n const [nonce, gas, fees, ethBalanceWei] = await Promise.all([\n client.getTransactionCount({ address: from, blockTag: 'pending' }),\n client.estimateGas({ account: from, to: USDC_ADDRESS, data }),\n client.estimateFeesPerGas(),\n client.getBalance({ address: from }),\n ]);\n assertUnderCap('gas', gas, SEND_GAS_CAP);\n assertUnderCap('maxFeePerGas', fees.maxFeePerGas, SEND_MAX_FEE_PER_GAS_CAP);\n assertUnderCap('maxPriorityFeePerGas', fees.maxPriorityFeePerGas, SEND_MAX_PRIORITY_FEE_CAP);\n return {\n to,\n amountAtomic,\n data,\n nonce,\n gas,\n maxFeePerGas: fees.maxFeePerGas,\n maxPriorityFeePerGas: fees.maxPriorityFeePerGas,\n feeWei: gas * fees.maxFeePerGas,\n ethBalanceWei,\n };\n}\n\nexport interface BroadcastUsdcSendArgs {\n signer: TenjinSigner;\n prepared: PreparedUsdcSend;\n rpcUrl: string;\n /** Receipt wait bound in ms; Base blocks are ~2s, so the default is generous. */\n receiptTimeoutMs?: number;\n}\n\n/**\n * Sign the prepared transfer through the TenjinSigner seam (never a raw key),\n * broadcast it, and wait for the receipt so \"sent\" means mined. Throws\n * SendRevertedError (mined but failed) or SendPendingError (no receipt in time);\n * both carry the hash so the caller can report it either way.\n */\nexport async function broadcastUsdcSend({\n signer,\n prepared,\n rpcUrl,\n receiptTimeoutMs = 120_000,\n}: BroadcastUsdcSendArgs): Promise<Hex> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n // Pre-sign cross-check, the calldata twin of send.ts's signer/preview match:\n // the bytes about to be signed must still decode to the previewed recipient\n // and amount. Unreachable unless prepare-time state was corrupted; refusing\n // here means nothing is signed against a preview it does not match.\n const decoded = decodeFunctionData({ abi: erc20Abi, data: prepared.data });\n if (\n decoded.functionName !== 'transfer' ||\n decoded.args[0].toLowerCase() !== prepared.to.toLowerCase() ||\n decoded.args[1] !== prepared.amountAtomic\n ) {\n throw new Error(\n 'Prepared calldata does not decode to the previewed recipient and amount; nothing was signed.',\n );\n }\n const serializedTransaction = await signer.signTransaction({\n type: 'eip1559',\n chainId: base.id,\n to: USDC_ADDRESS,\n // Explicitly zero: an ERC-20 transfer carries no native value (test-pinned).\n value: 0n,\n data: prepared.data,\n nonce: prepared.nonce,\n gas: prepared.gas,\n maxFeePerGas: prepared.maxFeePerGas,\n maxPriorityFeePerGas: prepared.maxPriorityFeePerGas,\n });\n const txHash = await client.sendRawTransaction({ serializedTransaction });\n let receipt;\n try {\n receipt = await client.waitForTransactionReceipt({ hash: txHash, timeout: receiptTimeoutMs });\n } catch {\n throw new SendPendingError(txHash);\n }\n if (receipt.status !== 'success') throw new SendRevertedError(txHash);\n return txHash;\n}\n\nfunction assertUnderCap(field: string, value: bigint, cap: bigint): void {\n if (value > cap) throw new FeeCapExceededError(field, value, cap);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,IAAM,YAAY;EACvB,gBAAgB,EAAE,SAAS,6CAA4C;EACvE,SAAS,EAAE,SAAS,6CAA4C;EAChE,wBAAwB;IACtB,SAAS;;EAEX,gBAAgB,EAAE,SAAS,6CAA4C;EACvE,kBAAkB,EAAE,SAAS,6CAA4C;EACzE,qBAAqB;IACnB,SAAS;;;;;ACEN,IAAM,aAAa;EACxB,OAAqB,4BAAY;IAC/B,OAAO,MAAqB;AAC1B,YAAM,eAAe,KAAK,cAAc,IAAI,CAAC,gBAAe;AAC1D,YAAI,OAAO,gBAAgB;AAAU,iBAAO;AAC5C,cAAM,YAAY,kBAChB,WAA6B;AAE/B,YAAI,UAAU,YAAY,QAAQ;AAChC,oBAAU,aAAa,YAAY;AACnC,oBAAU,OAAO,YAAY,OACzB,YAAY,YAAY,IAAI,IAC5B;AACJ,oBAAU,aAAa,YAAY;AACnC,oBAAU,OAAO;QACnB;AACA,eAAO;MACT,CAAC;AACD,aAAO;QACL;QACA,WAAW,KAAK;;IAEpB;GACD;EACD,aAA2B,kCAAkB;IAC3C,OAAO,MAA2B;AAChC,YAAM,cAAc,CAAA;AACpB,UAAI,KAAK,SAAS,QAAQ;AACxB,oBAAY,aAAa,KAAK;AAC9B,oBAAY,OAAO,KAAK,OAAO,YAAY,KAAK,IAAI,IAAI;AACxD,oBAAY,a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,eAAsB,kBAAkB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAmB;AACrB,GAAwC;AACtC,QAAM,SAAS,mBAAmB,EAAE,OAAO,MAAM,WAAW,KAAK,MAAM,EAAE,CAAC;AAK1E,QAAM,UAAU,mBAAmB,EAAE,KAAK,UAAU,MAAM,SAAS,KAAK,CAAC;AACzE,MACE,QAAQ,iBAAiB,cACzB,QAAQ,KAAK,CAAC,EAAE,YAAY,MAAM,SAAS,GAAG,YAAY,KAC1D,QAAQ,KAAK,CAAC,MAAM,SAAS,cAC7B;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,QAAM,wBAAwB,MAAM,OAAO,gBAAgB;AAAA,IACzD,MAAM;AAAA,IACN,SAAS,KAAK;AAAA,IACd,IAAIA;AAAA;AAAA,IAEJ,OAAO;AAAA,IACP,MAAM,SAAS;AAAA,IACf,OAAO,SAAS;AAAA,IAChB,KAAK,SAAS;AAAA,IACd,cAAc,SAAS;AAAA,IACvB,sBAAsB,SAAS;AAAA,EACjC,CAAC;AACD,QAAM,SAAS,MAAM,OAAO,mBAAmB,EAAE,sBAAsB,CAAC;AACxE,MAAI;AACJ,MAAI;AACF,cAAU,MAAM,OAAO,0BAA0B,EAAE,MAAM,QAAQ,SAAS,iBAAiB,CAAC;AAAA,EAC9F,QAAQ;AACN,UAAM,IAAI,iBAAiB,MAAM;AAAA,EACnC;AACA,MAAI,QAAQ,WAAW,UAAW,OAAM,IAAI,kBAAkB,MAAM;AACpE,SAAO;AACT;AAEA,SAAS,eAAe,OAAe,OAAe,KAAmB;AACvE,MAAI,QAAQ,IAAK,OAAM,IAAI,oBAAoB,OAAO,OAAO,GAAG;AAClE;","names":["serializeTransaction","USDC_ADDRESS","USDC_ADDRESS"]}
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
3
  inspectHooksFile
4
- } from "./chunk-XZOEUYMX.js";
4
+ } from "./chunk-TJMCBIZU.js";
5
5
  import {
6
6
  CliError,
7
7
  writeFileAtomic
@@ -169,4 +169,4 @@ export {
169
169
  removeStatusLine,
170
170
  inspectStatusLine
171
171
  };
172
- //# sourceMappingURL=chunk-2JGT3KDW.js.map
172
+ //# sourceMappingURL=chunk-EPCOMXLF.js.map
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-WLMJE3GJ.js";
9
9
  import {
10
10
  persistRouterDefaults
11
- } from "./chunk-KK4YGYTV.js";
11
+ } from "./chunk-ON6C6WOX.js";
12
12
  import {
13
13
  onPath
14
14
  } from "./chunk-WS4JA6TC.js";
@@ -20,7 +20,7 @@ import {
20
20
  } from "./chunk-U2DZISAH.js";
21
21
  import {
22
22
  ensureStatusLine
23
- } from "./chunk-2JGT3KDW.js";
23
+ } from "./chunk-EPCOMXLF.js";
24
24
  import {
25
25
  appendAllowlistRules,
26
26
  claudeAdapter,
@@ -28,7 +28,7 @@ import {
28
28
  inspectHooksFile,
29
29
  ownsHookEntry,
30
30
  writeHooks
31
- } from "./chunk-XZOEUYMX.js";
31
+ } from "./chunk-TJMCBIZU.js";
32
32
  import {
33
33
  CliError
34
34
  } from "./chunk-JLEF5WHM.js";
@@ -145,7 +145,7 @@ async function runRouterInstall(args, ctx, deps = {}) {
145
145
  };
146
146
  }
147
147
  const spend = await persistRouterDefaults(ctx.dataDir);
148
- const { resolveWallet } = await import("./install-wallet-SI4LZ73K.js");
148
+ const { resolveWallet } = await import("./install-wallet-JPFTEC6H.js");
149
149
  const wallet = await resolveWallet(ctx, deps, args.noWallet === true ? "flag" : void 0, false);
150
150
  const effective = await resolveContextSettings(ctx);
151
151
  const data = {
@@ -363,4 +363,4 @@ export {
363
363
  readMcpEntry,
364
364
  statusLineProblems
365
365
  };
366
- //# sourceMappingURL=chunk-O4ZNKFRU.js.map
366
+ //# sourceMappingURL=chunk-F3FUGWPZ.js.map
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
3
  getUsdcBalance
4
- } from "./chunk-56MOAIP5.js";
4
+ } from "./chunk-BTX2QE2Y.js";
5
5
  import {
6
6
  commitLocalWallet,
7
7
  createLocalWallet,
@@ -239,4 +239,4 @@ export {
239
239
  runWalletShow,
240
240
  runWalletBalance
241
241
  };
242
- //# sourceMappingURL=chunk-LJ4DMVFI.js.map
242
+ //# sourceMappingURL=chunk-FGR734LZ.js.map
@@ -19,7 +19,7 @@ import {
19
19
  import {
20
20
  fetchFailureToCliError,
21
21
  httpRequest
22
- } from "./chunk-5QHHRMRA.js";
22
+ } from "./chunk-WUHY2AXD.js";
23
23
  import {
24
24
  encodeFunctionData,
25
25
  getAddress as getAddress2,
@@ -33,7 +33,7 @@ import {
33
33
  } from "./chunk-LHHMV4GU.js";
34
34
  import {
35
35
  USDC_ADDRESS
36
- } from "./chunk-56MOAIP5.js";
36
+ } from "./chunk-BTX2QE2Y.js";
37
37
  import {
38
38
  describeWallet,
39
39
  resolveSpendAuthorizer,
@@ -8278,6 +8278,7 @@ function withBazaar(client2) {
8278
8278
 
8279
8279
  // src/lib/bazaar.ts
8280
8280
  var PAGE_LIMIT = 100;
8281
+ var SEARCH_LIMIT = 20;
8281
8282
  function client(registry) {
8282
8283
  return withBazaar(new HTTPFacilitatorClient({ url: registry }));
8283
8284
  }
@@ -8325,17 +8326,36 @@ async function storedListingsFor(dataDir, url, now) {
8325
8326
  });
8326
8327
  }
8327
8328
  function sameResourceUrl(listed, requested) {
8328
- const identity = (u) => {
8329
- try {
8330
- const parsed = new URL(u);
8331
- const path = parsed.pathname.endsWith("/") ? parsed.pathname.slice(0, -1) : parsed.pathname;
8332
- return `${parsed.origin}${path}`;
8333
- } catch {
8334
- return null;
8335
- }
8336
- };
8337
- const a = identity(listed);
8338
- return a !== null && a === identity(requested);
8329
+ const a = resourceIdentity(listed);
8330
+ return a !== null && a === resourceIdentity(requested);
8331
+ }
8332
+ function resourceIdentity(u) {
8333
+ try {
8334
+ const parsed = new URL(u);
8335
+ const path = parsed.pathname.endsWith("/") ? parsed.pathname.slice(0, -1) : parsed.pathname;
8336
+ return `${parsed.origin}${path}`;
8337
+ } catch {
8338
+ return null;
8339
+ }
8340
+ }
8341
+ async function listingsFor(registry, url, payTo, timeoutMs) {
8342
+ const params = new URLSearchParams({
8343
+ payTo,
8344
+ urlSubstring: resourceIdentity(url) ?? url,
8345
+ limit: String(SEARCH_LIMIT)
8346
+ });
8347
+ const res = await fetch(`${registry.replace(/\/+$/, "")}/discovery/search?${params.toString()}`, {
8348
+ headers: { accept: "application/json" },
8349
+ signal: AbortSignal.timeout(timeoutMs)
8350
+ });
8351
+ if (res.ok) {
8352
+ const found = (await res.json())?.resources;
8353
+ if (Array.isArray(found)) return found;
8354
+ } else if (res.status !== 400 && res.status !== 404) {
8355
+ throw new Error(`search on ${registry} answered ${res.status}`);
8356
+ }
8357
+ const bazaar = client(registry).extensions.bazaar;
8358
+ return (await bazaar.listResources({ type: "http", payTo, limit: PAGE_LIMIT })).items;
8339
8359
  }
8340
8360
  async function verifyAgainstRegistries(registries, url, live, timeoutMs, opts = {}) {
8341
8361
  const errors = [];
@@ -8350,13 +8370,12 @@ async function verifyAgainstRegistries(registries, url, live, timeoutMs, opts =
8350
8370
  }
8351
8371
  for (const registry of registries) {
8352
8372
  try {
8353
- const bazaar = client(registry).extensions.bazaar;
8354
8373
  const listed = await withTimeout(
8355
- bazaar.listResources({ type: "http", payTo: live.payTo, limit: PAGE_LIMIT }),
8374
+ listingsFor(registry, url, live.payTo, timeoutMs),
8356
8375
  timeoutMs,
8357
- `listing ${registry}`
8376
+ `looking up this resource on ${registry}`
8358
8377
  );
8359
- const matches = listed.items.filter(
8378
+ const matches = listed.filter(
8360
8379
  (item) => item.type === "http" && sameResourceUrl(item.resource, url)
8361
8380
  );
8362
8381
  if (matches.length === 0) continue;
@@ -9937,6 +9956,7 @@ async function runPay(args, ctx, deps = {}) {
9937
9956
  }
9938
9957
  const paid = await httpRequest(url, {
9939
9958
  ...fetchOpts,
9959
+ timeoutMs: paidLegTimeoutMs(effectiveRequirement, ctx.flags.timeout),
9940
9960
  headers: { ...headers, ...payment.headers }
9941
9961
  });
9942
9962
  await authorizer.commit(reservationId, payment.amountAtomic);
@@ -9951,18 +9971,7 @@ async function runPay(args, ctx, deps = {}) {
9951
9971
  if (args.resultSchema !== void 0) {
9952
9972
  const check = validateResultBody(args.resultSchema, paid.text);
9953
9973
  if (check.unvalidated === true) caveat = unvalidatedCaveat(check);
9954
- else if (!check.valid) {
9955
- throw new CliError("CONTRACT_MISMATCH", `The paid response is not a usable result.`, {
9956
- fix: "The payment has already settled and is counted against the session budget. Do not retry blind: the endpoint answered 2xx with a body that fails the success rule it was paid under.",
9957
- details: {
9958
- status: paid.status,
9959
- reason: check.reason,
9960
- ...check.diagnosis !== void 0 ? { diagnosis: check.diagnosis } : {},
9961
- amountAtomic: payment.amountAtomic.toString(),
9962
- settlement: "reported"
9963
- }
9964
- });
9965
- }
9974
+ else if (!check.valid) caveat = failedRuleCaveat(check);
9966
9975
  }
9967
9976
  return deliver(url, lane, paid, {
9968
9977
  paid: true,
@@ -9989,6 +9998,14 @@ async function runPay(args, ctx, deps = {}) {
9989
9998
  }
9990
9999
  );
9991
10000
  }
10001
+ var MAX_PAID_LEG_TIMEOUT_MS = 12e4;
10002
+ function paidLegTimeoutMs(requirement, cliTimeoutMs) {
10003
+ const advertised = requirement.maxTimeoutSeconds;
10004
+ if (typeof advertised !== "number" || !Number.isFinite(advertised) || advertised <= 0) {
10005
+ return cliTimeoutMs;
10006
+ }
10007
+ return Math.max(cliTimeoutMs, Math.min(advertised * 1e3, MAX_PAID_LEG_TIMEOUT_MS));
10008
+ }
9992
10009
  function resolveLane(url, settings) {
9993
10010
  let target;
9994
10011
  try {
@@ -10100,6 +10117,9 @@ function assertUsableResult(schema, body, status, how) {
10100
10117
  function unvalidatedCaveat(check) {
10101
10118
  return `${check.reason ?? "The result could not be validated."} The body is delivered unverified: its shape was never checked against the success rule.`;
10102
10119
  }
10120
+ function failedRuleCaveat(check) {
10121
+ return `${check.reason ?? "The result does not satisfy its success schema."} The payment settled, so the body is delivered as received, unverified: treat it as possibly not the answer that was paid for.`;
10122
+ }
10103
10123
  function legFix(failure) {
10104
10124
  return failure.kind === "oversized-header" ? "Raising `--max-http-header-size` on the node process that runs this CLI would let the header be read; that is an operator decision, not a default this build changes." : "";
10105
10125
  }
@@ -10155,13 +10175,13 @@ async function assertRegistryVerified(settings, url, requirement, timeoutMs, ctx
10155
10175
  "REGISTRY_MISMATCH",
10156
10176
  `The live 402 does not match what ${verification.registry} advertises for this resource (${verification.detail}).`,
10157
10177
  {
10158
- fix: "Nothing was signed. Re-run `tenjin discover` to see the advertised terms; if the seller changed them, the registry will catch up.",
10178
+ fix: `Nothing was signed. The seller's live terms differ from its listing on ${verification.registry}; check that listing, and pay once it matches or the seller corrects the endpoint.`,
10159
10179
  details: { registry: verification.registry, detail: verification.detail }
10160
10180
  }
10161
10181
  );
10162
10182
  case "unlisted":
10163
10183
  throw new CliError("USAGE", "No configured registry is known to list this resource.", {
10164
- fix: "The Bazaar lane pays publicly listed deals only, and pay-time lookup leans on the local `discover` cache: run `tenjin discover [query]` so a sweep can surface this endpoint, then re-run pay."
10184
+ fix: "Nothing was signed. The Bazaar lane pays only a URL a configured registry lists under the seller's payTo address. Check the registries in `tenjin config get bazaarRegistries` for this exact URL; if it is listed elsewhere, add that registry with `tenjin config set bazaarRegistries`."
10165
10185
  });
10166
10186
  case "unavailable":
10167
10187
  throw new CliError(
@@ -10233,6 +10253,8 @@ export {
10233
10253
  require_dist,
10234
10254
  canonicalHash,
10235
10255
  assertResultSchema,
10236
- runPay
10256
+ runPay,
10257
+ MAX_PAID_LEG_TIMEOUT_MS,
10258
+ paidLegTimeoutMs
10237
10259
  };
10238
- //# sourceMappingURL=chunk-QDD2RN7G.js.map
10260
+ //# sourceMappingURL=chunk-N44H5TFB.js.map