@arcenpay/node 0.0.1 → 0.0.2

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.
package/dist/index.js CHANGED
@@ -30,6 +30,65 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
+ // src/internal/sdk-core/chains.ts
34
+ function getChain(chainId) {
35
+ const chainMap = {
36
+ 11155111: sepolia,
37
+ 84532: baseSepolia,
38
+ 8453: baseMainnet
39
+ };
40
+ const chain = chainMap[chainId];
41
+ if (!chain) {
42
+ throw new Error(
43
+ `[getChain] Unsupported chainId: ${chainId}. Supported: ${Object.keys(chainMap).join(", ")}`
44
+ );
45
+ }
46
+ return chain;
47
+ }
48
+ var import_viem, sepolia, baseSepolia, baseMainnet, DEFAULT_CHAIN_ID;
49
+ var init_chains = __esm({
50
+ "src/internal/sdk-core/chains.ts"() {
51
+ "use strict";
52
+ import_viem = require("viem");
53
+ sepolia = (0, import_viem.defineChain)({
54
+ id: 11155111,
55
+ name: "Sepolia",
56
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
57
+ rpcUrls: {
58
+ default: { http: ["https://ethereum-sepolia-rpc.publicnode.com"] }
59
+ },
60
+ blockExplorers: {
61
+ default: { name: "Etherscan", url: "https://sepolia.etherscan.io" }
62
+ },
63
+ testnet: true
64
+ });
65
+ baseSepolia = (0, import_viem.defineChain)({
66
+ id: 84532,
67
+ name: "Base Sepolia",
68
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
69
+ rpcUrls: {
70
+ default: { http: ["https://sepolia.base.org"] }
71
+ },
72
+ blockExplorers: {
73
+ default: { name: "BaseScan", url: "https://sepolia.basescan.org" }
74
+ },
75
+ testnet: true
76
+ });
77
+ baseMainnet = (0, import_viem.defineChain)({
78
+ id: 8453,
79
+ name: "Base",
80
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
81
+ rpcUrls: {
82
+ default: { http: ["https://mainnet.base.org"] }
83
+ },
84
+ blockExplorers: {
85
+ default: { name: "BaseScan", url: "https://basescan.org" }
86
+ }
87
+ });
88
+ DEFAULT_CHAIN_ID = 84532;
89
+ }
90
+ });
91
+
33
92
  // src/services/nonce-store.ts
34
93
  var nonce_store_exports = {};
35
94
  __export(nonce_store_exports, {
@@ -139,8 +198,1020 @@ __export(index_exports, {
139
198
  });
140
199
  module.exports = __toCommonJS(index_exports);
141
200
 
201
+ // src/internal/sdk-core/index.ts
202
+ init_chains();
203
+
204
+ // src/internal/sdk-core/addresses.ts
205
+ var ADDRESSES = {
206
+ // Ethereum Sepolia (Testnet) — Deployed 2026-03-19
207
+ 11155111: {
208
+ subscriptionRegistry: "0xE206C519076535A9d24c852093860CFD780908C1",
209
+ autopayModule: "0xc82417e378b23AD9Ae73229EF08a4BA7896a4351",
210
+ planFactory: "0x4F97E0c2Ac053b735640fEb164a08Cb45ba83db1",
211
+ feeCollector: "0xa8A0D3007e5680D387A50C1a1E2Eb0AD092ca396",
212
+ sessionVault: "0xd68b9C0a34d61CC3b3F982A5EC6Cc5a5739e46D9",
213
+ zkUsageVerifier: "0x1f75d66692416cE880d51Baf6CdcBeE98E5837c0",
214
+ mirrorRegistry: "0xC187CD32d569ec0E84B9b378f8E63f3a74afac74"
215
+ },
216
+ // Base Sepolia (Testnet) — Deployed 2026-04-23
217
+ 84532: {
218
+ subscriptionRegistry: "0xF9610c064FFD64255A1d509d17b2Af8733084e50",
219
+ autopayModule: "0x69Ac04bFdC045A99A2D31bb141A74da354a94c19",
220
+ planFactory: "0x66775Af13C63781AAd28203CC5d3E9eE5d5eB83d",
221
+ feeCollector: "0x5F32fBfF19385A78c3F721007758E9924FAD4133",
222
+ sessionVault: "0x96BcE2d49e3e4EddBBF3aa07354E66615BC2623c",
223
+ zkUsageVerifier: "0x03290b6988F87925A4939d974895bC30981aA90D",
224
+ mirrorRegistry: "0xe7E0dFfa82596ee6Ba1755bc25c29376a07236dE"
225
+ },
226
+ // Base Mainnet — set ARCENPAY_CONTRACT_8453_* env vars after audit + deployment
227
+ 8453: {
228
+ subscriptionRegistry: "0x0000000000000000000000000000000000000000",
229
+ autopayModule: "0x0000000000000000000000000000000000000000",
230
+ planFactory: "0x0000000000000000000000000000000000000000",
231
+ feeCollector: "0x0000000000000000000000000000000000000000",
232
+ sessionVault: "0x0000000000000000000000000000000000000000",
233
+ zkUsageVerifier: "0x0000000000000000000000000000000000000000",
234
+ mirrorRegistry: "0x0000000000000000000000000000000000000000"
235
+ }
236
+ };
237
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
238
+ var CONTRACT_KEYS = [
239
+ "subscriptionRegistry",
240
+ "autopayModule",
241
+ "planFactory",
242
+ "feeCollector",
243
+ "sessionVault",
244
+ "zkUsageVerifier"
245
+ ];
246
+ function applyEnvOverrides(chainId, base9) {
247
+ if (typeof process === "undefined") return base9;
248
+ const result = { ...base9 };
249
+ for (const key of CONTRACT_KEYS) {
250
+ const envKey = `ARCENPAY_CONTRACT_${chainId}_${key}`;
251
+ const legacyKey = `MEAP_CONTRACT_${chainId}_${key}`;
252
+ const override = process.env[envKey] ?? process.env[legacyKey];
253
+ if (override && override.startsWith("0x")) {
254
+ result[key] = override;
255
+ }
256
+ }
257
+ const mirrorOverride = process.env[`ARCENPAY_CONTRACT_${chainId}_mirrorRegistry`] ?? process.env[`MEAP_CONTRACT_${chainId}_mirrorRegistry`];
258
+ if (mirrorOverride && mirrorOverride.startsWith("0x")) {
259
+ result.mirrorRegistry = mirrorOverride;
260
+ }
261
+ const yieldOverride = process.env[`ARCENPAY_CONTRACT_${chainId}_yieldSessionVault`] ?? process.env[`MEAP_CONTRACT_${chainId}_yieldSessionVault`];
262
+ if (yieldOverride && yieldOverride.startsWith("0x")) {
263
+ result.yieldSessionVault = yieldOverride;
264
+ }
265
+ return result;
266
+ }
267
+ function getContractAddresses(chainId) {
268
+ const base9 = ADDRESSES[chainId];
269
+ if (!base9) {
270
+ throw new Error(`No contract addresses configured for chain ${chainId}`);
271
+ }
272
+ const addresses = applyEnvOverrides(chainId, base9);
273
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
274
+ const allZero = CONTRACT_KEYS.every(
275
+ (k) => addresses[k] === ZERO_ADDRESS
276
+ );
277
+ if (allZero) {
278
+ throw new Error(
279
+ `[getContractAddresses] Chain ${chainId} has no deployed contracts. Set ARCENPAY_CONTRACT_${chainId}_<key> env vars or deploy contracts before using this chain in production.`
280
+ );
281
+ }
282
+ }
283
+ return addresses;
284
+ }
285
+
286
+ // src/internal/sdk-core/environment.ts
287
+ init_chains();
288
+ var DEFAULT_SERVICES = {
289
+ 11155111: {
290
+ rpcUrl: "https://ethereum-sepolia-rpc.publicnode.com"
291
+ },
292
+ 84532: {
293
+ rpcUrl: "https://sepolia.base.org"
294
+ },
295
+ 8453: {
296
+ rpcUrl: "https://mainnet.base.org"
297
+ }
298
+ };
299
+ var LEGACY_RPC_ENV_KEYS = {
300
+ 11155111: ["SEPOLIA_RPC_URL"],
301
+ 84532: ["BASE_SEPOLIA_RPC_URL"],
302
+ 8453: ["BASE_MAINNET_RPC_URL"]
303
+ };
304
+ var SERVICE_ENV_KEYS = {
305
+ rpcUrl: (chainId) => [
306
+ `ARCENPAY_RPC_URL_${chainId}`,
307
+ `MEAP_RPC_URL_${chainId}`,
308
+ `RPC_URL_${chainId}`,
309
+ `NEXT_PUBLIC_RPC_URL_${chainId}`,
310
+ ...LEGACY_RPC_ENV_KEYS[chainId] || [],
311
+ "ARCENPAY_RPC_URL",
312
+ "MEAP_RPC_URL",
313
+ "RPC_URL",
314
+ "NEXT_PUBLIC_RPC_URL"
315
+ ],
316
+ subgraphUrl: (chainId) => [
317
+ `ARCENPAY_SUBGRAPH_URL_${chainId}`,
318
+ `MEAP_SUBGRAPH_URL_${chainId}`,
319
+ `NEXT_PUBLIC_GRAPH_URL_${chainId}`,
320
+ "ARCENPAY_SUBGRAPH_URL",
321
+ "MEAP_SUBGRAPH_URL",
322
+ "NEXT_PUBLIC_GRAPH_URL"
323
+ ],
324
+ facilitatorUrl: (chainId) => [
325
+ `ARCENPAY_FACILITATOR_URL_${chainId}`,
326
+ `MEAP_FACILITATOR_URL_${chainId}`,
327
+ `FACILITATOR_BASE_URL_${chainId}`,
328
+ `FACILITATOR_URL_${chainId}`,
329
+ `NEXT_PUBLIC_FACILITATOR_BASE_URL_${chainId}`,
330
+ `NEXT_PUBLIC_FACILITATOR_URL_${chainId}`,
331
+ "ARCENPAY_FACILITATOR_URL",
332
+ "MEAP_FACILITATOR_URL",
333
+ "FACILITATOR_BASE_URL",
334
+ "FACILITATOR_URL",
335
+ "NEXT_PUBLIC_FACILITATOR_BASE_URL",
336
+ "NEXT_PUBLIC_FACILITATOR_URL"
337
+ ]
338
+ };
339
+ function getEnv(keys) {
340
+ if (typeof process === "undefined") return void 0;
341
+ for (const key of keys) {
342
+ const value = process.env[key]?.trim();
343
+ if (value) return value;
344
+ }
345
+ return void 0;
346
+ }
347
+ function resolveServiceUrl(chainId, service, fallback) {
348
+ return getEnv(SERVICE_ENV_KEYS[service](chainId)) || fallback || "";
349
+ }
350
+ function getChainEnvironment(chainId) {
351
+ const chain = getChain(chainId);
352
+ const defaults = DEFAULT_SERVICES[chainId] || {
353
+ rpcUrl: chain.rpcUrls.default.http[0] || ""
354
+ };
355
+ return {
356
+ chainId,
357
+ chainName: chain.name,
358
+ isTestnet: Boolean(chain.testnet),
359
+ contracts: getContractAddresses(chainId),
360
+ services: {
361
+ rpcUrl: resolveServiceUrl(chainId, "rpcUrl", defaults.rpcUrl),
362
+ subgraphUrl: resolveServiceUrl(chainId, "subgraphUrl", defaults.subgraphUrl),
363
+ facilitatorUrl: resolveServiceUrl(
364
+ chainId,
365
+ "facilitatorUrl",
366
+ defaults.facilitatorUrl
367
+ )
368
+ }
369
+ };
370
+ }
371
+
372
+ // src/internal/sdk-core/runtime-profile.ts
373
+ init_chains();
374
+
375
+ // src/internal/sdk-core/app-origin.ts
376
+ var ARCENPAY_LOCAL_APP_URL = "http://localhost:3000";
377
+ var ARCENPAY_PRODUCTION_APP_URL = "https://app.arcenpay.com";
378
+ var DEFAULT_ENV_KEYS = [
379
+ "ARCENPAY_BASE_URL",
380
+ "NEXT_PUBLIC_ARCENPAY_BASE_URL"
381
+ ];
382
+ function trimTrailingSlash(value) {
383
+ return value.replace(/\/$/, "");
384
+ }
385
+ function getRuntimeEnv() {
386
+ if (typeof process === "undefined") return void 0;
387
+ return process.env;
388
+ }
389
+ function readEnvValue(env, keys) {
390
+ if (!env) return void 0;
391
+ for (const key of keys) {
392
+ const value = env[key]?.trim();
393
+ if (value) return value;
394
+ }
395
+ return void 0;
396
+ }
397
+ function resolveArcenPayBaseUrl(options = {}) {
398
+ if (options.explicit?.trim()) {
399
+ return trimTrailingSlash(options.explicit.trim());
400
+ }
401
+ const env = options.env ?? getRuntimeEnv();
402
+ const envOverride = readEnvValue(env, options.envKeys ?? DEFAULT_ENV_KEYS);
403
+ if (envOverride) {
404
+ return trimTrailingSlash(envOverride);
405
+ }
406
+ const localDevUrl = options.localDevUrl ?? ARCENPAY_LOCAL_APP_URL;
407
+ const productionUrl = options.productionUrl ?? ARCENPAY_PRODUCTION_APP_URL;
408
+ const nodeEnv = env?.NODE_ENV;
409
+ if (nodeEnv && nodeEnv !== "production") {
410
+ return localDevUrl;
411
+ }
412
+ return productionUrl;
413
+ }
414
+
415
+ // src/internal/sdk-core/abis.ts
416
+ var SubscriptionRegistryABI = [
417
+ // Core functions
418
+ {
419
+ type: "function",
420
+ name: "mint",
421
+ inputs: [
422
+ { name: "to", type: "address" },
423
+ { name: "planId", type: "uint256" },
424
+ { name: "duration", type: "uint64" }
425
+ ],
426
+ outputs: [{ name: "tokenId", type: "uint256" }],
427
+ stateMutability: "nonpayable"
428
+ },
429
+ {
430
+ type: "function",
431
+ name: "renew",
432
+ inputs: [
433
+ { name: "tokenId", type: "uint256" },
434
+ { name: "extension", type: "uint64" }
435
+ ],
436
+ outputs: [],
437
+ stateMutability: "nonpayable"
438
+ },
439
+ {
440
+ type: "function",
441
+ name: "cancel",
442
+ inputs: [{ name: "tokenId", type: "uint256" }],
443
+ outputs: [],
444
+ stateMutability: "nonpayable"
445
+ },
446
+ {
447
+ type: "function",
448
+ name: "changePlan",
449
+ inputs: [
450
+ { name: "tokenId", type: "uint256" },
451
+ { name: "newPlanId", type: "uint256" }
452
+ ],
453
+ outputs: [],
454
+ stateMutability: "nonpayable"
455
+ },
456
+ {
457
+ type: "function",
458
+ name: "isValid",
459
+ inputs: [{ name: "tokenId", type: "uint256" }],
460
+ outputs: [{ name: "", type: "bool" }],
461
+ stateMutability: "view"
462
+ },
463
+ {
464
+ type: "function",
465
+ name: "expiresAt",
466
+ inputs: [{ name: "tokenId", type: "uint256" }],
467
+ outputs: [{ name: "", type: "uint64" }],
468
+ stateMutability: "view"
469
+ },
470
+ {
471
+ type: "function",
472
+ name: "getPlanFeatures",
473
+ inputs: [{ name: "tokenId", type: "uint256" }],
474
+ outputs: [
475
+ { name: "planId", type: "uint256" },
476
+ { name: "planTier", type: "string" }
477
+ ],
478
+ stateMutability: "view"
479
+ },
480
+ {
481
+ type: "function",
482
+ name: "getWalletSubscription",
483
+ inputs: [{ name: "wallet", type: "address" }],
484
+ outputs: [{ name: "", type: "uint256" }],
485
+ stateMutability: "view"
486
+ },
487
+ {
488
+ type: "function",
489
+ name: "importSubscription",
490
+ inputs: [
491
+ { name: "to", type: "address" },
492
+ { name: "tokenId", type: "uint256" },
493
+ { name: "planId", type: "uint256" },
494
+ { name: "expiration", type: "uint64" }
495
+ ],
496
+ outputs: [],
497
+ stateMutability: "nonpayable"
498
+ },
499
+ {
500
+ type: "function",
501
+ name: "finalizeMigration",
502
+ inputs: [],
503
+ outputs: [],
504
+ stateMutability: "nonpayable"
505
+ },
506
+ {
507
+ type: "function",
508
+ name: "hasActiveSubscription",
509
+ inputs: [{ name: "wallet", type: "address" }],
510
+ outputs: [{ name: "", type: "bool" }],
511
+ stateMutability: "view"
512
+ },
513
+ {
514
+ type: "function",
515
+ name: "authorizedBillers",
516
+ inputs: [{ name: "biller", type: "address" }],
517
+ outputs: [{ name: "isAuthorized", type: "bool" }],
518
+ stateMutability: "view"
519
+ },
520
+ {
521
+ type: "function",
522
+ name: "setCrossChainTransports",
523
+ inputs: [
524
+ { name: "axelarTransport", type: "address" },
525
+ { name: "ccipTransport", type: "address" }
526
+ ],
527
+ outputs: [],
528
+ stateMutability: "nonpayable"
529
+ },
530
+ {
531
+ type: "function",
532
+ name: "dispatchCrossChainUpdate",
533
+ inputs: [
534
+ { name: "tokenId", type: "uint256" },
535
+ { name: "destinationChainId", type: "uint256" },
536
+ { name: "refundAddress", type: "address" }
537
+ ],
538
+ outputs: [
539
+ { name: "messageId", type: "bytes32" },
540
+ { name: "routeUsed", type: "uint8" }
541
+ ],
542
+ stateMutability: "payable"
543
+ },
544
+ // Events
545
+ {
546
+ type: "event",
547
+ name: "SubscriptionMinted",
548
+ inputs: [
549
+ { name: "subscriber", type: "address", indexed: true },
550
+ { name: "tokenId", type: "uint256", indexed: true },
551
+ { name: "planId", type: "uint256", indexed: true },
552
+ { name: "expiration", type: "uint64", indexed: false }
553
+ ]
554
+ },
555
+ {
556
+ type: "event",
557
+ name: "SubscriptionRenewed",
558
+ inputs: [
559
+ { name: "tokenId", type: "uint256", indexed: true },
560
+ { name: "newExpiration", type: "uint64", indexed: false },
561
+ { name: "amountPaid", type: "uint256", indexed: false }
562
+ ]
563
+ },
564
+ {
565
+ type: "event",
566
+ name: "SubscriptionCancelled",
567
+ inputs: [{ name: "tokenId", type: "uint256", indexed: true }]
568
+ },
569
+ {
570
+ type: "event",
571
+ name: "SubscriptionPlanChanged",
572
+ inputs: [
573
+ { name: "tokenId", type: "uint256", indexed: true },
574
+ { name: "previousPlanId", type: "uint256", indexed: true },
575
+ { name: "newPlanId", type: "uint256", indexed: true },
576
+ { name: "expiration", type: "uint64", indexed: false }
577
+ ]
578
+ },
579
+ {
580
+ type: "event",
581
+ name: "BillingSuccess",
582
+ inputs: [
583
+ { name: "tokenId", type: "uint256", indexed: true },
584
+ { name: "planId", type: "uint256", indexed: true },
585
+ { name: "amount", type: "uint256", indexed: false },
586
+ { name: "timestamp", type: "uint256", indexed: false }
587
+ ]
588
+ },
589
+ {
590
+ type: "event",
591
+ name: "CrossChainDispatchRequested",
592
+ inputs: [
593
+ { name: "tokenId", type: "uint256", indexed: true },
594
+ { name: "destinationChainId", type: "uint256", indexed: true },
595
+ { name: "route", type: "uint8", indexed: true },
596
+ { name: "messageId", type: "bytes32", indexed: false }
597
+ ]
598
+ },
599
+ {
600
+ type: "event",
601
+ name: "CrossChainFallbackTriggered",
602
+ inputs: [
603
+ { name: "tokenId", type: "uint256", indexed: true },
604
+ { name: "destinationChainId", type: "uint256", indexed: true },
605
+ { name: "primaryError", type: "bytes", indexed: false }
606
+ ]
607
+ },
608
+ {
609
+ type: "event",
610
+ name: "SubscriptionImported",
611
+ inputs: [
612
+ { name: "subscriber", type: "address", indexed: true },
613
+ { name: "tokenId", type: "uint256", indexed: true },
614
+ { name: "planId", type: "uint256", indexed: true },
615
+ { name: "expiration", type: "uint64", indexed: false }
616
+ ]
617
+ },
618
+ {
619
+ type: "event",
620
+ name: "RegistryMigrationFinalized",
621
+ inputs: []
622
+ },
623
+ {
624
+ type: "event",
625
+ name: "Transfer",
626
+ inputs: [
627
+ { name: "from", type: "address", indexed: true },
628
+ { name: "to", type: "address", indexed: true },
629
+ { name: "tokenId", type: "uint256", indexed: true }
630
+ ]
631
+ }
632
+ ];
633
+ var ERC7579AutopayModuleABI = [
634
+ {
635
+ type: "function",
636
+ name: "onInstall",
637
+ inputs: [{ name: "data", type: "bytes" }],
638
+ outputs: [],
639
+ stateMutability: "nonpayable"
640
+ },
641
+ {
642
+ type: "function",
643
+ name: "onUninstall",
644
+ inputs: [{ name: "data", type: "bytes" }],
645
+ outputs: [],
646
+ stateMutability: "nonpayable"
647
+ },
648
+ {
649
+ type: "function",
650
+ name: "execute",
651
+ inputs: [
652
+ { name: "account", type: "address" },
653
+ { name: "amount", type: "uint256" }
654
+ ],
655
+ outputs: [],
656
+ stateMutability: "nonpayable"
657
+ },
658
+ {
659
+ type: "function",
660
+ name: "isInitialized",
661
+ inputs: [{ name: "smartAccount", type: "address" }],
662
+ outputs: [{ name: "", type: "bool" }],
663
+ stateMutability: "view"
664
+ },
665
+ {
666
+ type: "function",
667
+ name: "getConfig",
668
+ inputs: [{ name: "account", type: "address" }],
669
+ outputs: [
670
+ {
671
+ name: "config",
672
+ type: "tuple",
673
+ components: [
674
+ { name: "merchant", type: "address" },
675
+ { name: "maxAmount", type: "uint256" },
676
+ { name: "token", type: "address" },
677
+ { name: "interval", type: "uint32" },
678
+ { name: "startTime", type: "uint64" },
679
+ { name: "planId", type: "uint256" },
680
+ { name: "maxTotalAmount", type: "uint256" }
681
+ ]
682
+ }
683
+ ],
684
+ stateMutability: "view"
685
+ },
686
+ {
687
+ type: "function",
688
+ name: "updateConfig",
689
+ inputs: [
690
+ {
691
+ name: "config",
692
+ type: "tuple",
693
+ components: [
694
+ { name: "merchant", type: "address" },
695
+ { name: "maxAmount", type: "uint256" },
696
+ { name: "token", type: "address" },
697
+ { name: "interval", type: "uint32" },
698
+ { name: "startTime", type: "uint64" },
699
+ { name: "planId", type: "uint256" },
700
+ { name: "maxTotalAmount", type: "uint256" }
701
+ ]
702
+ }
703
+ ],
704
+ outputs: [],
705
+ stateMutability: "nonpayable"
706
+ },
707
+ {
708
+ type: "function",
709
+ name: "canExecute",
710
+ inputs: [{ name: "account", type: "address" }],
711
+ outputs: [{ name: "", type: "bool" }],
712
+ stateMutability: "view"
713
+ },
714
+ {
715
+ type: "function",
716
+ name: "lastPullTime",
717
+ inputs: [{ name: "account", type: "address" }],
718
+ outputs: [{ name: "", type: "uint64" }],
719
+ stateMutability: "view"
720
+ },
721
+ {
722
+ type: "function",
723
+ name: "mirrorDestinationChainId",
724
+ inputs: [{ name: "account", type: "address" }],
725
+ outputs: [{ name: "", type: "uint256" }],
726
+ stateMutability: "view"
727
+ },
728
+ {
729
+ type: "function",
730
+ name: "isAccountPaused",
731
+ inputs: [{ name: "account", type: "address" }],
732
+ outputs: [{ name: "", type: "bool" }],
733
+ stateMutability: "view"
734
+ },
735
+ {
736
+ type: "function",
737
+ name: "importAccountState",
738
+ inputs: [
739
+ { name: "account", type: "address" },
740
+ {
741
+ name: "config",
742
+ type: "tuple",
743
+ components: [
744
+ { name: "merchant", type: "address" },
745
+ { name: "maxAmount", type: "uint256" },
746
+ { name: "token", type: "address" },
747
+ { name: "interval", type: "uint32" },
748
+ { name: "startTime", type: "uint64" },
749
+ { name: "planId", type: "uint256" },
750
+ { name: "maxTotalAmount", type: "uint256" }
751
+ ]
752
+ },
753
+ { name: "lastPullTime_", type: "uint64" },
754
+ { name: "totalPulled_", type: "uint256" },
755
+ { name: "mirrorDestinationChainId_", type: "uint256" },
756
+ { name: "accountPaused_", type: "bool" }
757
+ ],
758
+ outputs: [],
759
+ stateMutability: "nonpayable"
760
+ },
761
+ {
762
+ type: "function",
763
+ name: "finalizeMigration",
764
+ inputs: [],
765
+ outputs: [],
766
+ stateMutability: "nonpayable"
767
+ },
768
+ {
769
+ type: "event",
770
+ name: "AutopayConfigured",
771
+ inputs: [
772
+ { name: "account", type: "address", indexed: true },
773
+ { name: "merchant", type: "address", indexed: true },
774
+ { name: "maxAmount", type: "uint256", indexed: false },
775
+ { name: "token", type: "address", indexed: false },
776
+ { name: "interval", type: "uint32", indexed: false }
777
+ ]
778
+ },
779
+ {
780
+ type: "event",
781
+ name: "AutopayConfigUpdated",
782
+ inputs: [
783
+ { name: "account", type: "address", indexed: true },
784
+ { name: "previousPlanId", type: "uint256", indexed: true },
785
+ { name: "newPlanId", type: "uint256", indexed: true },
786
+ { name: "maxAmount", type: "uint256", indexed: false },
787
+ { name: "interval", type: "uint32", indexed: false }
788
+ ]
789
+ },
790
+ {
791
+ type: "event",
792
+ name: "PaymentExecuted",
793
+ inputs: [
794
+ { name: "account", type: "address", indexed: true },
795
+ { name: "merchant", type: "address", indexed: true },
796
+ { name: "amount", type: "uint256", indexed: false },
797
+ { name: "timestamp", type: "uint256", indexed: false }
798
+ ]
799
+ },
800
+ {
801
+ type: "event",
802
+ name: "BillingExecuted",
803
+ inputs: [
804
+ { name: "account", type: "address", indexed: true },
805
+ { name: "merchant", type: "address", indexed: true },
806
+ { name: "tokenId", type: "uint256", indexed: true },
807
+ { name: "planId", type: "uint256", indexed: false },
808
+ { name: "reason", type: "uint8", indexed: false },
809
+ { name: "grossAmount", type: "uint256", indexed: false },
810
+ { name: "merchantAmount", type: "uint256", indexed: false },
811
+ { name: "protocolFee", type: "uint256", indexed: false },
812
+ { name: "timestamp", type: "uint256", indexed: false }
813
+ ]
814
+ },
815
+ {
816
+ type: "event",
817
+ name: "AutopayRevoked",
818
+ inputs: [{ name: "account", type: "address", indexed: true }]
819
+ },
820
+ {
821
+ type: "event",
822
+ name: "AccountStateImported",
823
+ inputs: [
824
+ { name: "account", type: "address", indexed: true },
825
+ { name: "planId", type: "uint256", indexed: true },
826
+ { name: "lastPullTime", type: "uint64", indexed: false }
827
+ ]
828
+ },
829
+ {
830
+ type: "event",
831
+ name: "MigrationFinalized",
832
+ inputs: []
833
+ }
834
+ ];
835
+ var SessionVaultABI = [
836
+ {
837
+ type: "function",
838
+ name: "fundSession",
839
+ inputs: [
840
+ { name: "amount", type: "uint256" },
841
+ { name: "token", type: "address" }
842
+ ],
843
+ outputs: [{ name: "sessionId", type: "bytes32" }],
844
+ stateMutability: "nonpayable"
845
+ },
846
+ {
847
+ type: "function",
848
+ name: "topUp",
849
+ inputs: [
850
+ { name: "sessionId", type: "bytes32" },
851
+ { name: "amount", type: "uint256" }
852
+ ],
853
+ outputs: [],
854
+ stateMutability: "nonpayable"
855
+ },
856
+ {
857
+ type: "function",
858
+ name: "settle",
859
+ inputs: [
860
+ { name: "sessionId", type: "bytes32" },
861
+ { name: "amount", type: "uint256" },
862
+ { name: "provider", type: "address" }
863
+ ],
864
+ outputs: [],
865
+ stateMutability: "nonpayable"
866
+ },
867
+ {
868
+ type: "function",
869
+ name: "withdraw",
870
+ inputs: [{ name: "sessionId", type: "bytes32" }],
871
+ outputs: [],
872
+ stateMutability: "nonpayable"
873
+ },
874
+ {
875
+ type: "function",
876
+ name: "getBalance",
877
+ inputs: [{ name: "sessionId", type: "bytes32" }],
878
+ outputs: [{ name: "", type: "uint256" }],
879
+ stateMutability: "view"
880
+ },
881
+ {
882
+ type: "function",
883
+ name: "getAgentBalance",
884
+ inputs: [{ name: "agent", type: "address" }],
885
+ outputs: [{ name: "", type: "uint256" }],
886
+ stateMutability: "view"
887
+ },
888
+ {
889
+ type: "function",
890
+ name: "getSession",
891
+ inputs: [{ name: "sessionId", type: "bytes32" }],
892
+ outputs: [
893
+ {
894
+ name: "",
895
+ type: "tuple",
896
+ components: [
897
+ { name: "agent", type: "address" },
898
+ { name: "token", type: "address" },
899
+ { name: "balance", type: "uint256" },
900
+ { name: "totalFunded", type: "uint256" },
901
+ { name: "totalSettled", type: "uint256" },
902
+ { name: "active", type: "bool" },
903
+ { name: "createdAt", type: "uint64" }
904
+ ]
905
+ }
906
+ ],
907
+ stateMutability: "view"
908
+ },
909
+ {
910
+ type: "function",
911
+ name: "getAgentSessions",
912
+ inputs: [{ name: "agent", type: "address" }],
913
+ outputs: [{ name: "", type: "bytes32[]" }],
914
+ stateMutability: "view"
915
+ },
916
+ {
917
+ type: "function",
918
+ name: "authorizedSettlers",
919
+ inputs: [{ name: "", type: "address" }],
920
+ outputs: [{ name: "", type: "bool" }],
921
+ stateMutability: "view"
922
+ },
923
+ {
924
+ type: "event",
925
+ name: "SessionFunded",
926
+ inputs: [
927
+ { name: "agent", type: "address", indexed: true },
928
+ { name: "sessionId", type: "bytes32", indexed: true },
929
+ { name: "amount", type: "uint256", indexed: false },
930
+ { name: "token", type: "address", indexed: false }
931
+ ]
932
+ },
933
+ {
934
+ type: "event",
935
+ name: "SessionSettled",
936
+ inputs: [
937
+ { name: "sessionId", type: "bytes32", indexed: true },
938
+ { name: "amount", type: "uint256", indexed: false },
939
+ { name: "provider", type: "address", indexed: true }
940
+ ]
941
+ },
942
+ {
943
+ type: "event",
944
+ name: "SessionWithdrawn",
945
+ inputs: [
946
+ { name: "sessionId", type: "bytes32", indexed: true },
947
+ { name: "amount", type: "uint256", indexed: false },
948
+ { name: "agent", type: "address", indexed: true }
949
+ ]
950
+ }
951
+ ];
952
+ var ZKUsageVerifierABI = [
953
+ {
954
+ type: "function",
955
+ name: "setGroth16Verifier",
956
+ inputs: [{ name: "verifier", type: "address" }],
957
+ outputs: [],
958
+ stateMutability: "nonpayable"
959
+ },
960
+ {
961
+ type: "function",
962
+ name: "groth16Verifier",
963
+ inputs: [],
964
+ outputs: [{ name: "", type: "address" }],
965
+ stateMutability: "view"
966
+ },
967
+ {
968
+ type: "function",
969
+ name: "submitProof",
970
+ inputs: [
971
+ {
972
+ name: "proof",
973
+ type: "tuple",
974
+ components: [
975
+ { name: "a", type: "uint256[2]" },
976
+ { name: "b", type: "uint256[2][2]" },
977
+ { name: "c", type: "uint256[2]" }
978
+ ]
979
+ },
980
+ {
981
+ name: "inputs",
982
+ type: "tuple",
983
+ components: [
984
+ { name: "agentAddress", type: "bytes32" },
985
+ { name: "sessionId", type: "bytes32" },
986
+ { name: "callCount", type: "uint256" },
987
+ { name: "windowStart", type: "uint64" },
988
+ { name: "windowEnd", type: "uint64" },
989
+ { name: "merkleRoot", type: "bytes32" },
990
+ { name: "nullifier", type: "bytes32" }
991
+ ]
992
+ }
993
+ ],
994
+ outputs: [],
995
+ stateMutability: "nonpayable"
996
+ },
997
+ {
998
+ type: "function",
999
+ name: "isNullifierUsed",
1000
+ inputs: [{ name: "nullifier", type: "bytes32" }],
1001
+ outputs: [{ name: "", type: "bool" }],
1002
+ stateMutability: "view"
1003
+ },
1004
+ {
1005
+ type: "function",
1006
+ name: "getRateSchedule",
1007
+ inputs: [{ name: "planId", type: "uint256" }],
1008
+ outputs: [{ name: "ratePerCall", type: "uint256" }],
1009
+ stateMutability: "view"
1010
+ },
1011
+ {
1012
+ type: "function",
1013
+ name: "getPendingBalance",
1014
+ inputs: [{ name: "agent", type: "address" }],
1015
+ outputs: [{ name: "", type: "uint256" }],
1016
+ stateMutability: "view"
1017
+ },
1018
+ {
1019
+ type: "event",
1020
+ name: "BillingSettled",
1021
+ inputs: [
1022
+ { name: "sessionId", type: "bytes32", indexed: true },
1023
+ { name: "agentAddress", type: "bytes32", indexed: true },
1024
+ { name: "callCount", type: "uint256", indexed: false },
1025
+ { name: "settlementAmount", type: "uint256", indexed: false },
1026
+ { name: "windowStart", type: "uint64", indexed: false },
1027
+ { name: "windowEnd", type: "uint64", indexed: false }
1028
+ ]
1029
+ },
1030
+ {
1031
+ type: "event",
1032
+ name: "Groth16VerifierSet",
1033
+ inputs: [{ name: "verifier", type: "address", indexed: true }]
1034
+ }
1035
+ ];
1036
+ var FeeCollectorABI = [
1037
+ // ── Core fee collection ──
1038
+ {
1039
+ type: "function",
1040
+ name: "collectSubscriptionFee",
1041
+ inputs: [{ name: "amount", type: "uint256" }],
1042
+ outputs: [{ name: "feeAmount", type: "uint256" }],
1043
+ stateMutability: "nonpayable"
1044
+ },
1045
+ {
1046
+ type: "function",
1047
+ name: "collectSettlementFee",
1048
+ inputs: [{ name: "amount", type: "uint256" }],
1049
+ outputs: [{ name: "feeAmount", type: "uint256" }],
1050
+ stateMutability: "nonpayable"
1051
+ },
1052
+ // ── Provider-specific fee collection ──
1053
+ {
1054
+ type: "function",
1055
+ name: "collectSubscriptionFeeFor",
1056
+ inputs: [
1057
+ { name: "amount", type: "uint256" },
1058
+ { name: "provider", type: "address" }
1059
+ ],
1060
+ outputs: [{ name: "feeAmount", type: "uint256" }],
1061
+ stateMutability: "nonpayable"
1062
+ },
1063
+ {
1064
+ type: "function",
1065
+ name: "collectSettlementFeeFor",
1066
+ inputs: [
1067
+ { name: "amount", type: "uint256" },
1068
+ { name: "provider", type: "address" }
1069
+ ],
1070
+ outputs: [{ name: "feeAmount", type: "uint256" }],
1071
+ stateMutability: "nonpayable"
1072
+ },
1073
+ // ── Fee rate queries ──
1074
+ {
1075
+ type: "function",
1076
+ name: "subscriptionFeeRate",
1077
+ inputs: [],
1078
+ outputs: [{ name: "", type: "uint256" }],
1079
+ stateMutability: "view"
1080
+ },
1081
+ {
1082
+ type: "function",
1083
+ name: "settlementFeeRate",
1084
+ inputs: [],
1085
+ outputs: [{ name: "", type: "uint256" }],
1086
+ stateMutability: "view"
1087
+ },
1088
+ {
1089
+ type: "function",
1090
+ name: "getProviderSubFeeBps",
1091
+ inputs: [{ name: "provider", type: "address" }],
1092
+ outputs: [{ name: "", type: "uint256" }],
1093
+ stateMutability: "view"
1094
+ },
1095
+ {
1096
+ type: "function",
1097
+ name: "getProviderSettleFeeBps",
1098
+ inputs: [{ name: "provider", type: "address" }],
1099
+ outputs: [{ name: "", type: "uint256" }],
1100
+ stateMutability: "view"
1101
+ },
1102
+ // ── Tier management ──
1103
+ {
1104
+ type: "function",
1105
+ name: "syncProviderTier",
1106
+ inputs: [
1107
+ { name: "provider", type: "address" },
1108
+ { name: "tier", type: "uint8" }
1109
+ ],
1110
+ outputs: [],
1111
+ stateMutability: "nonpayable"
1112
+ },
1113
+ {
1114
+ type: "function",
1115
+ name: "setTierFeeRates",
1116
+ inputs: [
1117
+ { name: "tier", type: "uint8" },
1118
+ { name: "subFeeBps", type: "uint256" },
1119
+ { name: "settleFeeBps", type: "uint256" }
1120
+ ],
1121
+ outputs: [],
1122
+ stateMutability: "nonpayable"
1123
+ },
1124
+ {
1125
+ type: "function",
1126
+ name: "setProviderFeeRates",
1127
+ inputs: [
1128
+ { name: "provider", type: "address" },
1129
+ { name: "subFeeBps", type: "uint256" },
1130
+ { name: "settleFeeBps", type: "uint256" }
1131
+ ],
1132
+ outputs: [],
1133
+ stateMutability: "nonpayable"
1134
+ },
1135
+ {
1136
+ type: "function",
1137
+ name: "tierSubFeeBps",
1138
+ inputs: [{ name: "tier", type: "uint8" }],
1139
+ outputs: [{ name: "", type: "uint256" }],
1140
+ stateMutability: "view"
1141
+ },
1142
+ {
1143
+ type: "function",
1144
+ name: "tierSettleFeeBps",
1145
+ inputs: [{ name: "tier", type: "uint8" }],
1146
+ outputs: [{ name: "", type: "uint256" }],
1147
+ stateMutability: "view"
1148
+ },
1149
+ // ── Treasury ──
1150
+ {
1151
+ type: "function",
1152
+ name: "accumulatedFees",
1153
+ inputs: [{ name: "token", type: "address" }],
1154
+ outputs: [{ name: "", type: "uint256" }],
1155
+ stateMutability: "view"
1156
+ },
1157
+ {
1158
+ type: "function",
1159
+ name: "withdrawFees",
1160
+ inputs: [{ name: "token", type: "address" }],
1161
+ outputs: [],
1162
+ stateMutability: "nonpayable"
1163
+ },
1164
+ // ── Events ──
1165
+ {
1166
+ type: "event",
1167
+ name: "FeeCollected",
1168
+ inputs: [
1169
+ { name: "from", type: "address", indexed: true },
1170
+ { name: "amount", type: "uint256", indexed: false },
1171
+ { name: "feeAmount", type: "uint256", indexed: false },
1172
+ { name: "feeType", type: "string", indexed: false }
1173
+ ]
1174
+ },
1175
+ {
1176
+ type: "event",
1177
+ name: "FeesWithdrawn",
1178
+ inputs: [
1179
+ { name: "treasury", type: "address", indexed: true },
1180
+ { name: "amount", type: "uint256", indexed: false }
1181
+ ]
1182
+ },
1183
+ {
1184
+ type: "event",
1185
+ name: "ProviderFeeRateSet",
1186
+ inputs: [
1187
+ { name: "provider", type: "address", indexed: true },
1188
+ { name: "subFeeBps", type: "uint256", indexed: false },
1189
+ { name: "settleFeeBps", type: "uint256", indexed: false }
1190
+ ]
1191
+ },
1192
+ {
1193
+ type: "event",
1194
+ name: "ProviderTierSynced",
1195
+ inputs: [
1196
+ { name: "provider", type: "address", indexed: true },
1197
+ { name: "tier", type: "uint8", indexed: false },
1198
+ { name: "subFeeBps", type: "uint256", indexed: false },
1199
+ { name: "settleFeeBps", type: "uint256", indexed: false }
1200
+ ]
1201
+ }
1202
+ ];
1203
+
1204
+ // src/internal/sdk-core/constants.ts
1205
+ var X402_VERSION = "1";
1206
+ var X402_SCHEME = "exact";
1207
+
1208
+ // src/internal/sdk-core/accounts.ts
1209
+ var import_viem2 = require("viem");
1210
+
1211
+ // src/internal/sdk-core/index.ts
1212
+ init_chains();
1213
+
142
1214
  // src/client.ts
143
- var import_sdk = require("@arcenpay/sdk");
144
1215
  var ArcenClient = class {
145
1216
  apiKey;
146
1217
  baseUrl;
@@ -151,7 +1222,7 @@ var ArcenClient = class {
151
1222
  throw new Error('ArcenClient: apiKey must start with "api_"');
152
1223
  }
153
1224
  this.apiKey = config.apiKey;
154
- this.baseUrl = (0, import_sdk.resolveArcenPayBaseUrl)({ explicit: config.baseUrl });
1225
+ this.baseUrl = resolveArcenPayBaseUrl({ explicit: config.baseUrl });
155
1226
  this.timeoutMs = config.timeoutMs ?? 1e4;
156
1227
  }
157
1228
  buildAuthHeader() {
@@ -386,9 +1457,8 @@ var ArcenApiError = class extends Error {
386
1457
  };
387
1458
 
388
1459
  // src/middleware/x402.ts
389
- var import_sdk2 = require("@arcenpay/sdk");
390
- var import_viem = require("viem");
391
- var import_chains = require("viem/chains");
1460
+ var import_viem3 = require("viem");
1461
+ var import_chains5 = require("viem/chains");
392
1462
  var PAYMENT_DOMAIN = {
393
1463
  name: "MEAP x402 Payment",
394
1464
  version: "1"
@@ -404,9 +1474,9 @@ var PAYMENT_TYPES = {
404
1474
  ]
405
1475
  };
406
1476
  var CHAIN_MAP = {
407
- 11155111: import_chains.sepolia,
408
- 84532: import_chains.baseSepolia,
409
- 8453: import_chains.base
1477
+ 11155111: import_chains5.sepolia,
1478
+ 84532: import_chains5.baseSepolia,
1479
+ 8453: import_chains5.base
410
1480
  };
411
1481
  var CHAIN_ID_TO_NETWORK = {
412
1482
  11155111: "ethereum-sepolia",
@@ -501,24 +1571,26 @@ function x402Middleware(options) {
501
1571
  const { InMemoryNonceStore: InMemoryNonceStore2 } = (init_nonce_store(), __toCommonJS(nonce_store_exports));
502
1572
  nonceStore = new InMemoryNonceStore2();
503
1573
  }
504
- const rateAtomicUnits = (0, import_viem.parseUnits)(ratePerCall, 6);
505
- const chainEnv = (0, import_sdk2.getChainEnvironment)(chainId);
1574
+ const rateAtomicUnits = (0, import_viem3.parseUnits)(ratePerCall, 6);
1575
+ const chainEnv = getChainEnvironment(chainId);
506
1576
  const contracts = chainEnv.contracts;
507
1577
  const payToAddress = payTo || contracts.feeCollector || "0x0000000000000000000000000000000000000000";
508
- const chain = CHAIN_MAP[chainId] || import_chains.sepolia;
509
- const publicClient = (0, import_viem.createPublicClient)({
1578
+ const chain = CHAIN_MAP[chainId] || import_chains5.sepolia;
1579
+ const publicClient = (0, import_viem3.createPublicClient)({
510
1580
  chain,
511
- transport: (0, import_viem.http)(rpcUrl || chainEnv.services.rpcUrl || chain.rpcUrls.default.http[0])
1581
+ transport: (0, import_viem3.http)(
1582
+ rpcUrl || chainEnv.services.rpcUrl || chain.rpcUrls.default.http[0]
1583
+ )
512
1584
  });
513
1585
  return async (req, res, next) => {
514
1586
  const paymentHeader = req.headers["x-payment"];
515
1587
  if (!paymentHeader) {
516
1588
  const x402Response = {
517
1589
  ok: false,
518
- version: import_sdk2.X402_VERSION,
1590
+ version: X402_VERSION,
519
1591
  accepts: [
520
1592
  {
521
- scheme: import_sdk2.X402_SCHEME,
1593
+ scheme: X402_SCHEME,
522
1594
  network: resolvedNetwork,
523
1595
  maxAmountRequired: rateAtomicUnits.toString(),
524
1596
  resource: `${req.protocol}://${req.get("host")}${req.originalUrl}`,
@@ -580,7 +1652,7 @@ function x402Middleware(options) {
580
1652
  return;
581
1653
  }
582
1654
  const signerClaimed = typeof payload.from === "string" ? payload.from : "";
583
- if (!(0, import_viem.isAddress)(signerClaimed)) {
1655
+ if (!(0, import_viem3.isAddress)(signerClaimed)) {
584
1656
  sendRejection(
585
1657
  res,
586
1658
  "MALFORMED_PAYMENT_PAYLOAD",
@@ -619,7 +1691,7 @@ function x402Middleware(options) {
619
1691
  }
620
1692
  let recoveredSigner;
621
1693
  try {
622
- recoveredSigner = await (0, import_viem.recoverTypedDataAddress)({
1694
+ recoveredSigner = await (0, import_viem3.recoverTypedDataAddress)({
623
1695
  domain: { ...PAYMENT_DOMAIN, chainId: BigInt(chainId) },
624
1696
  types: PAYMENT_TYPES,
625
1697
  primaryType: "Payment",
@@ -681,7 +1753,7 @@ function x402Middleware(options) {
681
1753
  try {
682
1754
  const balance = await publicClient.readContract({
683
1755
  address: contracts.sessionVault,
684
- abi: import_sdk2.SessionVaultABI,
1756
+ abi: SessionVaultABI,
685
1757
  functionName: "getAgentBalance",
686
1758
  args: [verifiedSigner]
687
1759
  });
@@ -771,10 +1843,9 @@ var import_crypto = require("crypto");
771
1843
  var import_fs = __toESM(require("fs"));
772
1844
  var import_path = __toESM(require("path"));
773
1845
  var import_url = require("url");
774
- var import_viem2 = require("viem");
775
- var import_accounts = require("viem/accounts");
776
- var import_chains2 = require("viem/chains");
777
- var import_sdk3 = require("@arcenpay/sdk");
1846
+ var import_viem4 = require("viem");
1847
+ var import_accounts2 = require("viem/accounts");
1848
+ var import_chains6 = require("viem/chains");
778
1849
  var UsageProofErrorCodes = {
779
1850
  TOOLING_UNAVAILABLE: "TOOLING_UNAVAILABLE",
780
1851
  ARTIFACTS_MISSING: "ARTIFACTS_MISSING",
@@ -795,12 +1866,12 @@ var UsageProofError = class extends Error {
795
1866
  }
796
1867
  };
797
1868
  var CHAIN_MAP2 = {
798
- 11155111: import_chains2.sepolia,
799
- 84532: import_chains2.baseSepolia,
800
- 8453: import_chains2.base
1869
+ 11155111: import_chains6.sepolia,
1870
+ 84532: import_chains6.baseSepolia,
1871
+ 8453: import_chains6.base
801
1872
  };
802
1873
  var MAX_ENTRIES = 128;
803
- var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
1874
+ var ZERO_ADDRESS3 = "0x0000000000000000000000000000000000000000";
804
1875
  var UsageService = class {
805
1876
  logs = /* @__PURE__ */ new Map();
806
1877
  config;
@@ -809,8 +1880,8 @@ var UsageService = class {
809
1880
  walletClient;
810
1881
  runtimeValidated = false;
811
1882
  constructor(config = {}) {
812
- const chainId = config.chainId ?? import_sdk3.DEFAULT_CHAIN_ID;
813
- const chain = CHAIN_MAP2[chainId] || import_chains2.baseSepolia;
1883
+ const chainId = config.chainId ?? DEFAULT_CHAIN_ID;
1884
+ const chain = CHAIN_MAP2[chainId] || import_chains6.baseSepolia;
814
1885
  const rpcUrl = config.rpcUrl || chain.rpcUrls.default.http[0];
815
1886
  const proofMode = config.proofMode ?? (process.env.NODE_ENV === "development" ? "dev" : "strict");
816
1887
  const circuitsRootDir = this.resolveCircuitsRoot(config.circuitsRootDir);
@@ -831,19 +1902,19 @@ var UsageService = class {
831
1902
  };
832
1903
  if (config.signerPrivateKey) {
833
1904
  const key = config.signerPrivateKey.startsWith("0x") ? config.signerPrivateKey : `0x${config.signerPrivateKey}`;
834
- this.signerAccount = (0, import_accounts.privateKeyToAccount)(key);
1905
+ this.signerAccount = (0, import_accounts2.privateKeyToAccount)(key);
835
1906
  } else {
836
1907
  this.signerAccount = null;
837
1908
  }
838
- this.publicClient = (0, import_viem2.createPublicClient)({
1909
+ this.publicClient = (0, import_viem4.createPublicClient)({
839
1910
  chain,
840
- transport: (0, import_viem2.http)(rpcUrl)
1911
+ transport: (0, import_viem4.http)(rpcUrl)
841
1912
  });
842
1913
  if (this.signerAccount) {
843
- this.walletClient = (0, import_viem2.createWalletClient)({
1914
+ this.walletClient = (0, import_viem4.createWalletClient)({
844
1915
  account: this.signerAccount,
845
1916
  chain,
846
- transport: (0, import_viem2.http)(rpcUrl)
1917
+ transport: (0, import_viem4.http)(rpcUrl)
847
1918
  });
848
1919
  } else {
849
1920
  this.walletClient = null;
@@ -904,7 +1975,9 @@ var UsageService = class {
904
1975
  }
905
1976
  aggregateUsage(sessionId, windowEnd) {
906
1977
  const logs = this.logs.get(sessionId) || [];
907
- const windowLogs = logs.filter((entry) => entry.callData.timestamp <= windowEnd);
1978
+ const windowLogs = logs.filter(
1979
+ (entry) => entry.callData.timestamp <= windowEnd
1980
+ );
908
1981
  const windowStart = windowLogs.length > 0 ? Math.min(...windowLogs.map((entry) => entry.callData.timestamp)) : 0;
909
1982
  return {
910
1983
  sessionId,
@@ -935,7 +2008,7 @@ var UsageService = class {
935
2008
  );
936
2009
  }
937
2010
  const sessionIdBytes32 = this.normalizeBytes32(sessionId);
938
- const agentAddress = this.signerAccount?.address || ZERO_ADDRESS;
2011
+ const agentAddress = this.signerAccount?.address || ZERO_ADDRESS3;
939
2012
  const agentAddressBytes32 = this.addressToBytes32(agentAddress);
940
2013
  const logHashes = aggregation.logs.map((log) => this.hashUsageLog(log));
941
2014
  const logTimestamps = aggregation.logs.map(
@@ -957,7 +2030,13 @@ var UsageService = class {
957
2030
  const prover = await this.loadCircuitProver();
958
2031
  proofResult = await prover.prove(circuitInput);
959
2032
  publicSignals = proofResult.publicSignals;
960
- this.assertPublicSignals(publicSignals, aggregation, agentAddress, sessionIdBytes32, prover);
2033
+ this.assertPublicSignals(
2034
+ publicSignals,
2035
+ aggregation,
2036
+ agentAddress,
2037
+ sessionIdBytes32,
2038
+ prover
2039
+ );
961
2040
  } catch (err) {
962
2041
  if (this.config.proofMode === "strict") {
963
2042
  throw this.wrapProofError(err);
@@ -1023,8 +2102,8 @@ var UsageService = class {
1023
2102
  "UsageService: Cannot submit proof \u2014 no signer private key configured. Set signerPrivateKey in UsageServiceConfig."
1024
2103
  );
1025
2104
  }
1026
- const chainId = this.config.chainId ?? import_sdk3.DEFAULT_CHAIN_ID;
1027
- const contracts = (0, import_sdk3.getContractAddresses)(chainId);
2105
+ const chainId = this.config.chainId ?? DEFAULT_CHAIN_ID;
2106
+ const contracts = getContractAddresses(chainId);
1028
2107
  const verifierAddress = contracts.zkUsageVerifier;
1029
2108
  if (!verifierAddress || verifierAddress === "0x0000000000000000000000000000000000000000") {
1030
2109
  throw new Error(
@@ -1047,7 +2126,7 @@ var UsageService = class {
1047
2126
  };
1048
2127
  const txHash = await this.walletClient.writeContract({
1049
2128
  address: verifierAddress,
1050
- abi: import_sdk3.ZKUsageVerifierABI,
2129
+ abi: ZKUsageVerifierABI,
1051
2130
  functionName: "submitProof",
1052
2131
  args: [onChainProof, onChainInputs]
1053
2132
  });
@@ -1100,7 +2179,9 @@ var UsageService = class {
1100
2179
  this.config.zkeyPath,
1101
2180
  this.config.verificationKeyPath
1102
2181
  ];
1103
- const missing = required.filter((artifactPath) => !import_fs.default.existsSync(artifactPath));
2182
+ const missing = required.filter(
2183
+ (artifactPath) => !import_fs.default.existsSync(artifactPath)
2184
+ );
1104
2185
  if (missing.length > 0) {
1105
2186
  throw new UsageProofError(
1106
2187
  UsageProofErrorCodes.ARTIFACTS_MISSING,
@@ -1146,7 +2227,9 @@ var UsageService = class {
1146
2227
  const raw = import_fs.default.readFileSync(this.config.verificationKeyPath, "utf8");
1147
2228
  const vkey = JSON.parse(raw);
1148
2229
  if (vkey.protocol !== "groth16") {
1149
- throw new Error(`Unsupported protocol: ${String(vkey.protocol || "unknown")}`);
2230
+ throw new Error(
2231
+ `Unsupported protocol: ${String(vkey.protocol || "unknown")}`
2232
+ );
1150
2233
  }
1151
2234
  if (typeof vkey.nPublic === "number" && vkey.nPublic !== 7) {
1152
2235
  throw new Error(`Expected 7 public inputs, received ${vkey.nPublic}`);
@@ -1259,13 +2342,12 @@ var UsageService = class {
1259
2342
  };
1260
2343
 
1261
2344
  // src/services/settlement.ts
1262
- var import_viem3 = require("viem");
1263
- var import_chains3 = require("viem/chains");
1264
- var import_sdk4 = require("@arcenpay/sdk");
2345
+ var import_viem5 = require("viem");
2346
+ var import_chains7 = require("viem/chains");
1265
2347
  var CHAIN_MAP3 = {
1266
- 11155111: import_chains3.sepolia,
1267
- 84532: import_chains3.baseSepolia,
1268
- 8453: import_chains3.base
2348
+ 11155111: import_chains7.sepolia,
2349
+ 84532: import_chains7.baseSepolia,
2350
+ 8453: import_chains7.base
1269
2351
  };
1270
2352
  var SettlementService = class {
1271
2353
  rpcUrl;
@@ -1278,14 +2360,14 @@ var SettlementService = class {
1278
2360
  publicClient;
1279
2361
  constructor(config) {
1280
2362
  this.rpcUrl = config.rpcUrl;
1281
- this.chainId = config.chainId ?? import_sdk4.DEFAULT_CHAIN_ID;
1282
- const contracts = (0, import_sdk4.getContractAddresses)(this.chainId);
2363
+ this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
2364
+ const contracts = getContractAddresses(this.chainId);
1283
2365
  this.zkVerifierAddress = config.zkVerifierAddress || contracts.zkUsageVerifier;
1284
2366
  this.sessionVaultAddress = config.sessionVaultAddress || contracts.sessionVault;
1285
- const chain = CHAIN_MAP3[this.chainId] || import_chains3.baseSepolia;
1286
- this.publicClient = (0, import_viem3.createPublicClient)({
2367
+ const chain = CHAIN_MAP3[this.chainId] || import_chains7.baseSepolia;
2368
+ this.publicClient = (0, import_viem5.createPublicClient)({
1287
2369
  chain,
1288
- transport: (0, import_viem3.http)(this.rpcUrl)
2370
+ transport: (0, import_viem5.http)(this.rpcUrl)
1289
2371
  });
1290
2372
  }
1291
2373
  /**
@@ -1295,7 +2377,7 @@ var SettlementService = class {
1295
2377
  try {
1296
2378
  const balance = await this.publicClient.readContract({
1297
2379
  address: this.sessionVaultAddress,
1298
- abi: import_sdk4.SessionVaultABI,
2380
+ abi: SessionVaultABI,
1299
2381
  functionName: "getAgentBalance",
1300
2382
  args: [agentAddress]
1301
2383
  });
@@ -1312,7 +2394,7 @@ var SettlementService = class {
1312
2394
  try {
1313
2395
  const session = await this.publicClient.readContract({
1314
2396
  address: this.sessionVaultAddress,
1315
- abi: import_sdk4.SessionVaultABI,
2397
+ abi: SessionVaultABI,
1316
2398
  functionName: "getSession",
1317
2399
  args: [sessionId]
1318
2400
  });
@@ -1406,14 +2488,13 @@ var SettlementService = class {
1406
2488
  };
1407
2489
 
1408
2490
  // src/services/settlement-writer.ts
1409
- var import_viem4 = require("viem");
1410
- var import_accounts2 = require("viem/accounts");
1411
- var import_chains4 = require("viem/chains");
1412
- var import_sdk5 = require("@arcenpay/sdk");
2491
+ var import_viem6 = require("viem");
2492
+ var import_accounts3 = require("viem/accounts");
2493
+ var import_chains8 = require("viem/chains");
1413
2494
  var CHAIN_MAP4 = {
1414
- 11155111: import_chains4.sepolia,
1415
- 84532: import_chains4.baseSepolia,
1416
- 8453: import_chains4.base
2495
+ 11155111: import_chains8.sepolia,
2496
+ 84532: import_chains8.baseSepolia,
2497
+ 8453: import_chains8.base
1417
2498
  };
1418
2499
  function isBytes32(value) {
1419
2500
  return /^0x[a-fA-F0-9]{64}$/.test(value);
@@ -1422,11 +2503,19 @@ function normalizeSession(raw) {
1422
2503
  const value = raw;
1423
2504
  const agent = value?.agent ?? value?.[0] ?? "0x0000000000000000000000000000000000000000";
1424
2505
  const token = value?.token ?? value?.[1] ?? "0x0000000000000000000000000000000000000000";
1425
- const balance = BigInt(value?.balance ?? value?.[2] ?? 0n);
1426
- const totalFunded = BigInt(value?.totalFunded ?? value?.[3] ?? 0n);
1427
- const totalSettled = BigInt(value?.totalSettled ?? value?.[4] ?? 0n);
2506
+ const balance = BigInt(
2507
+ value?.balance ?? value?.[2] ?? 0n
2508
+ );
2509
+ const totalFunded = BigInt(
2510
+ value?.totalFunded ?? value?.[3] ?? 0n
2511
+ );
2512
+ const totalSettled = BigInt(
2513
+ value?.totalSettled ?? value?.[4] ?? 0n
2514
+ );
1428
2515
  const active = Boolean(value?.active ?? value?.[5] ?? false);
1429
- const createdAt = BigInt(value?.createdAt ?? value?.[6] ?? 0n);
2516
+ const createdAt = BigInt(
2517
+ value?.createdAt ?? value?.[6] ?? 0n
2518
+ );
1430
2519
  return {
1431
2520
  agent,
1432
2521
  token,
@@ -1447,29 +2536,31 @@ var SettlementWriterService = class {
1447
2536
  publicClient;
1448
2537
  walletClient;
1449
2538
  constructor(config) {
1450
- this.chainId = config.chainId ?? import_sdk5.DEFAULT_CHAIN_ID;
1451
- const chain = CHAIN_MAP4[this.chainId] || import_chains4.baseSepolia;
1452
- const contracts = (0, import_sdk5.getContractAddresses)(this.chainId);
2539
+ this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
2540
+ const chain = CHAIN_MAP4[this.chainId] || import_chains8.baseSepolia;
2541
+ const contracts = getContractAddresses(this.chainId);
1453
2542
  this.sessionVaultAddress = config.sessionVaultAddress || contracts.sessionVault;
1454
2543
  this.feeCollectorAddress = config.feeCollectorAddress || contracts.feeCollector;
1455
- const account = (0, import_accounts2.privateKeyToAccount)(config.privateKey);
2544
+ const account = (0, import_accounts3.privateKeyToAccount)(config.privateKey);
1456
2545
  this.signerAddress = account.address;
1457
2546
  this.providerAddress = config.providerAddress || account.address;
1458
2547
  this.waitForReceipt = config.waitForReceipt ?? true;
1459
- if (!(0, import_viem4.isAddress)(this.sessionVaultAddress)) {
1460
- throw new Error("Invalid SessionVault address for SettlementWriterService");
2548
+ if (!(0, import_viem6.isAddress)(this.sessionVaultAddress)) {
2549
+ throw new Error(
2550
+ "Invalid SessionVault address for SettlementWriterService"
2551
+ );
1461
2552
  }
1462
- if (!(0, import_viem4.isAddress)(this.providerAddress)) {
2553
+ if (!(0, import_viem6.isAddress)(this.providerAddress)) {
1463
2554
  throw new Error("Invalid provider address for SettlementWriterService");
1464
2555
  }
1465
- this.publicClient = (0, import_viem4.createPublicClient)({
2556
+ this.publicClient = (0, import_viem6.createPublicClient)({
1466
2557
  chain,
1467
- transport: (0, import_viem4.http)(config.rpcUrl || chain.rpcUrls.default.http[0])
2558
+ transport: (0, import_viem6.http)(config.rpcUrl || chain.rpcUrls.default.http[0])
1468
2559
  });
1469
- this.walletClient = (0, import_viem4.createWalletClient)({
2560
+ this.walletClient = (0, import_viem6.createWalletClient)({
1470
2561
  account,
1471
2562
  chain,
1472
- transport: (0, import_viem4.http)(config.rpcUrl || chain.rpcUrls.default.http[0])
2563
+ transport: (0, import_viem6.http)(config.rpcUrl || chain.rpcUrls.default.http[0])
1473
2564
  });
1474
2565
  }
1475
2566
  getSignerAddress() {
@@ -1479,12 +2570,12 @@ var SettlementWriterService = class {
1479
2570
  return this.sessionVaultAddress;
1480
2571
  }
1481
2572
  async isSignerAuthorized(address = this.signerAddress) {
1482
- if (!(0, import_viem4.isAddress)(address)) {
2573
+ if (!(0, import_viem6.isAddress)(address)) {
1483
2574
  return false;
1484
2575
  }
1485
2576
  const authorized = await this.publicClient.readContract({
1486
2577
  address: this.sessionVaultAddress,
1487
- abi: import_sdk5.SessionVaultABI,
2578
+ abi: SessionVaultABI,
1488
2579
  functionName: "authorizedSettlers",
1489
2580
  args: [address]
1490
2581
  });
@@ -1493,7 +2584,7 @@ var SettlementWriterService = class {
1493
2584
  async getSession(sessionId) {
1494
2585
  const rawSession = await this.publicClient.readContract({
1495
2586
  address: this.sessionVaultAddress,
1496
- abi: import_sdk5.SessionVaultABI,
2587
+ abi: SessionVaultABI,
1497
2588
  functionName: "getSession",
1498
2589
  args: [sessionId]
1499
2590
  });
@@ -1506,7 +2597,7 @@ var SettlementWriterService = class {
1506
2597
  }
1507
2598
  const sessionIds = await this.publicClient.readContract({
1508
2599
  address: this.sessionVaultAddress,
1509
- abi: import_sdk5.SessionVaultABI,
2600
+ abi: SessionVaultABI,
1510
2601
  functionName: "getAgentSessions",
1511
2602
  args: [signer]
1512
2603
  });
@@ -1523,13 +2614,16 @@ var SettlementWriterService = class {
1523
2614
  throw new Error("No active billing session found for signer");
1524
2615
  }
1525
2616
  async settleForSigner(input) {
1526
- if (!(0, import_viem4.isAddress)(input.signer)) {
2617
+ if (!(0, import_viem6.isAddress)(input.signer)) {
1527
2618
  throw new Error("Invalid signer address for settlement");
1528
2619
  }
1529
2620
  if (input.amount <= 0n) {
1530
2621
  throw new Error("Settlement amount must be greater than zero");
1531
2622
  }
1532
- const resolvedSessionId = await this.resolveSessionId(input.sessionIdHint, input.signer);
2623
+ const resolvedSessionId = await this.resolveSessionId(
2624
+ input.sessionIdHint,
2625
+ input.signer
2626
+ );
1533
2627
  const session = await this.getSession(resolvedSessionId);
1534
2628
  if (!session.active) {
1535
2629
  throw new Error("Session is not active");
@@ -1543,31 +2637,36 @@ var SettlementWriterService = class {
1543
2637
  );
1544
2638
  }
1545
2639
  const providerAddress = input.providerAddress || this.providerAddress;
1546
- if (!(0, import_viem4.isAddress)(providerAddress)) {
2640
+ if (!(0, import_viem6.isAddress)(providerAddress)) {
1547
2641
  throw new Error("Invalid settlement provider address");
1548
2642
  }
1549
2643
  const txHash = await this.walletClient.writeContract({
1550
2644
  address: this.sessionVaultAddress,
1551
- abi: import_sdk5.SessionVaultABI,
2645
+ abi: SessionVaultABI,
1552
2646
  functionName: "settle",
1553
2647
  args: [resolvedSessionId, input.amount, providerAddress]
1554
2648
  });
1555
2649
  if (this.waitForReceipt) {
1556
2650
  await this.publicClient.waitForTransactionReceipt({ hash: txHash });
1557
2651
  }
1558
- if ((0, import_viem4.isAddress)(this.feeCollectorAddress)) {
2652
+ if ((0, import_viem6.isAddress)(this.feeCollectorAddress)) {
1559
2653
  try {
1560
2654
  const feeTxHash = await this.walletClient.writeContract({
1561
2655
  address: this.feeCollectorAddress,
1562
- abi: import_sdk5.FeeCollectorABI,
2656
+ abi: FeeCollectorABI,
1563
2657
  functionName: "collectSettlementFeeFor",
1564
2658
  args: [input.amount, providerAddress]
1565
2659
  });
1566
2660
  if (this.waitForReceipt) {
1567
- await this.publicClient.waitForTransactionReceipt({ hash: feeTxHash });
2661
+ await this.publicClient.waitForTransactionReceipt({
2662
+ hash: feeTxHash
2663
+ });
1568
2664
  }
1569
2665
  } catch (err) {
1570
- console.warn("[SettlementWriter] Fee collection failed (non-fatal):", err);
2666
+ console.warn(
2667
+ "[SettlementWriter] Fee collection failed (non-fatal):",
2668
+ err
2669
+ );
1571
2670
  }
1572
2671
  }
1573
2672
  return {
@@ -1580,13 +2679,12 @@ var SettlementWriterService = class {
1580
2679
  };
1581
2680
 
1582
2681
  // src/services/events.ts
1583
- var import_viem5 = require("viem");
1584
- var import_chains5 = require("viem/chains");
1585
- var import_sdk6 = require("@arcenpay/sdk");
2682
+ var import_viem7 = require("viem");
2683
+ var import_chains9 = require("viem/chains");
1586
2684
  var CHAIN_MAP5 = {
1587
- 11155111: import_chains5.sepolia,
1588
- 84532: import_chains5.baseSepolia,
1589
- 8453: import_chains5.base
2685
+ 11155111: import_chains9.sepolia,
2686
+ 84532: import_chains9.baseSepolia,
2687
+ 8453: import_chains9.base
1590
2688
  };
1591
2689
  var EventListenerService = class {
1592
2690
  publicClient;
@@ -1596,14 +2694,14 @@ var EventListenerService = class {
1596
2694
  pollInterval = null;
1597
2695
  lastBlock = 0n;
1598
2696
  constructor(config) {
1599
- const chainId = config.chainId ?? import_sdk6.DEFAULT_CHAIN_ID;
1600
- const chain = CHAIN_MAP5[chainId] || import_chains5.baseSepolia;
1601
- const contracts = (0, import_sdk6.getContractAddresses)(chainId);
2697
+ const chainId = config.chainId ?? DEFAULT_CHAIN_ID;
2698
+ const chain = CHAIN_MAP5[chainId] || import_chains9.baseSepolia;
2699
+ const contracts = getContractAddresses(chainId);
1602
2700
  this.registryAddress = config.registryAddress || contracts.subscriptionRegistry;
1603
2701
  this.autopayModuleAddress = contracts.autopayModule;
1604
- this.publicClient = (0, import_viem5.createPublicClient)({
2702
+ this.publicClient = (0, import_viem7.createPublicClient)({
1605
2703
  chain,
1606
- transport: (0, import_viem5.http)(config.rpcUrl)
2704
+ transport: (0, import_viem7.http)(config.rpcUrl)
1607
2705
  });
1608
2706
  }
1609
2707
  /**
@@ -1615,7 +2713,10 @@ var EventListenerService = class {
1615
2713
  this.callbacks.set(eventType, existing);
1616
2714
  return () => {
1617
2715
  const cbs = this.callbacks.get(eventType) || [];
1618
- this.callbacks.set(eventType, cbs.filter((cb) => cb !== callback));
2716
+ this.callbacks.set(
2717
+ eventType,
2718
+ cbs.filter((cb) => cb !== callback)
2719
+ );
1619
2720
  };
1620
2721
  }
1621
2722
  /**
@@ -1627,7 +2728,9 @@ var EventListenerService = class {
1627
2728
  } catch {
1628
2729
  this.lastBlock = 0n;
1629
2730
  }
1630
- console.log(`[EventListener] Watching SubscriptionRegistry at ${this.registryAddress} from block ${this.lastBlock}`);
2731
+ console.log(
2732
+ `[EventListener] Watching SubscriptionRegistry at ${this.registryAddress} from block ${this.lastBlock}`
2733
+ );
1631
2734
  this.pollInterval = setInterval(async () => {
1632
2735
  await this.poll();
1633
2736
  }, intervalMs);
@@ -1651,7 +2754,13 @@ var EventListenerService = class {
1651
2754
  if (currentBlock <= this.lastBlock) return;
1652
2755
  const addr = this.registryAddress;
1653
2756
  const from = this.lastBlock + 1n;
1654
- const [mintedLogs, renewedLogs, cancelledLogs, planChangedLogs, billingLogs] = await Promise.all([
2757
+ const [
2758
+ mintedLogs,
2759
+ renewedLogs,
2760
+ cancelledLogs,
2761
+ planChangedLogs,
2762
+ billingLogs
2763
+ ] = await Promise.all([
1655
2764
  this.publicClient.getLogs({
1656
2765
  address: addr,
1657
2766
  event: {
@@ -1686,9 +2795,7 @@ var EventListenerService = class {
1686
2795
  event: {
1687
2796
  type: "event",
1688
2797
  name: "SubscriptionCancelled",
1689
- inputs: [
1690
- { name: "tokenId", type: "uint256", indexed: true }
1691
- ]
2798
+ inputs: [{ name: "tokenId", type: "uint256", indexed: true }]
1692
2799
  },
1693
2800
  fromBlock: from,
1694
2801
  toBlock: currentBlock
@@ -1798,7 +2905,9 @@ var EventListenerService = class {
1798
2905
  * Dispatch event to registered callbacks
1799
2906
  */
1800
2907
  async emit(event) {
1801
- console.log(`[EventListener] ${event.type} \u2014 tokenId=${event.tokenId} tx=${event.transactionHash}`);
2908
+ console.log(
2909
+ `[EventListener] ${event.type} \u2014 tokenId=${event.tokenId} tx=${event.transactionHash}`
2910
+ );
1802
2911
  const typeCallbacks = this.callbacks.get(event.type) || [];
1803
2912
  const wildcardCallbacks = this.callbacks.get("*") || [];
1804
2913
  for (const cb of [...typeCallbacks, ...wildcardCallbacks]) {
@@ -1872,7 +2981,10 @@ var WebhookService = class {
1872
2981
  deliveredAt: Date.now(),
1873
2982
  success: response.ok
1874
2983
  });
1875
- await this.persistDelivery(this.deliveryLog[this.deliveryLog.length - 1], payload);
2984
+ await this.persistDelivery(
2985
+ this.deliveryLog[this.deliveryLog.length - 1],
2986
+ payload
2987
+ );
1876
2988
  if (!response.ok && attempt < this.config.maxRetries) {
1877
2989
  await this.scheduleRetry(payload, attempt);
1878
2990
  }
@@ -1887,7 +2999,10 @@ var WebhookService = class {
1887
2999
  success: false,
1888
3000
  error: err.message
1889
3001
  });
1890
- await this.persistDelivery(this.deliveryLog[this.deliveryLog.length - 1], payload);
3002
+ await this.persistDelivery(
3003
+ this.deliveryLog[this.deliveryLog.length - 1],
3004
+ payload
3005
+ );
1891
3006
  if (attempt < this.config.maxRetries) {
1892
3007
  await this.scheduleRetry(payload, attempt);
1893
3008
  }
@@ -1905,7 +3020,9 @@ var WebhookService = class {
1905
3020
  async scheduleRetry(payload, currentAttempt) {
1906
3021
  const delay = this.config.retryDelays[currentAttempt - 1] || 18e5;
1907
3022
  const retryId = `retry-${payload.event}-${currentAttempt}`;
1908
- console.log(`[Webhook] Scheduling retry ${currentAttempt + 1} in ${delay}ms for ${payload.event}`);
3023
+ console.log(
3024
+ `[Webhook] Scheduling retry ${currentAttempt + 1} in ${delay}ms for ${payload.event}`
3025
+ );
1909
3026
  const timer = setTimeout(() => {
1910
3027
  this.deliver(payload, currentAttempt + 1);
1911
3028
  this.pendingRetries.delete(retryId);
@@ -1920,7 +3037,9 @@ var WebhookService = class {
1920
3037
  if (this.deliveryLog.length > 1e3) {
1921
3038
  this.deliveryLog = this.deliveryLog.slice(-500);
1922
3039
  }
1923
- console.log(`[Webhook] ${entry.success ? "\u2705" : "\u274C"} ${entry.event} \u2192 ${entry.statusCode} (attempt ${entry.attemptNumber})`);
3040
+ console.log(
3041
+ `[Webhook] ${entry.success ? "\u2705" : "\u274C"} ${entry.event} \u2192 ${entry.statusCode} (attempt ${entry.attemptNumber})`
3042
+ );
1924
3043
  }
1925
3044
  async persistDelivery(entry, payload) {
1926
3045
  if (!entry || !this.config.onDelivery) return;
@@ -2005,7 +3124,9 @@ var EmailService = class {
2005
3124
  return { success: false, error: err };
2006
3125
  }
2007
3126
  const result = await response.json();
2008
- console.log(`[Email] \u2705 Sent ${template} to ${recipient.email} (${result.id})`);
3127
+ console.log(
3128
+ `[Email] \u2705 Sent ${template} to ${recipient.email} (${result.id})`
3129
+ );
2009
3130
  return { success: true, messageId: result.id };
2010
3131
  } catch (err) {
2011
3132
  console.error(`[Email] Error sending ${template}:`, err.message);
@@ -2336,7 +3457,9 @@ var TablelandService = class {
2336
3457
  }
2337
3458
  ensureInitialized() {
2338
3459
  if (!this.initialized || !this.dbRead) {
2339
- throw new Error("[Tableland] Service not initialized. Call initialize() first.");
3460
+ throw new Error(
3461
+ "[Tableland] Service not initialized. Call initialize() first."
3462
+ );
2340
3463
  }
2341
3464
  }
2342
3465
  ensureWritable() {
@@ -2356,7 +3479,7 @@ var TablelandService = class {
2356
3479
  };
2357
3480
 
2358
3481
  // src/services/lit.ts
2359
- var import_constants = require("@lit-protocol/constants");
3482
+ var import_constants2 = require("@lit-protocol/constants");
2360
3483
  var import_encryption = require("@lit-protocol/encryption");
2361
3484
  var import_lit_node_client = require("@lit-protocol/lit-node-client");
2362
3485
  var LitProtocolService = class {
@@ -2370,13 +3493,13 @@ var LitProtocolService = class {
2370
3493
  switch (this.config.network) {
2371
3494
  case "habanero":
2372
3495
  case "datil":
2373
- return import_constants.LIT_NETWORK.Datil;
3496
+ return import_constants2.LIT_NETWORK.Datil;
2374
3497
  case "datil-test":
2375
3498
  case "manzano":
2376
- return import_constants.LIT_NETWORK.DatilTest;
3499
+ return import_constants2.LIT_NETWORK.DatilTest;
2377
3500
  case "datil-dev":
2378
3501
  default:
2379
- return import_constants.LIT_NETWORK.DatilDev;
3502
+ return import_constants2.LIT_NETWORK.DatilDev;
2380
3503
  }
2381
3504
  })();
2382
3505
  this.litClient = new import_lit_node_client.LitNodeClient({
@@ -2496,7 +3619,9 @@ var AggregatorService = class {
2496
3619
  this.logs.set(entry.sessionId, existing);
2497
3620
  const thresholdReached = existing.length >= this.settlementThreshold;
2498
3621
  if (thresholdReached) {
2499
- console.log(`[Aggregator] Threshold reached for session ${entry.sessionId} (${existing.length} entries)`);
3622
+ console.log(
3623
+ `[Aggregator] Threshold reached for session ${entry.sessionId} (${existing.length} entries)`
3624
+ );
2500
3625
  }
2501
3626
  return { totalEntries: existing.length, thresholdReached };
2502
3627
  }
@@ -2507,12 +3632,12 @@ var AggregatorService = class {
2507
3632
  buildMerkleTree(sessionId) {
2508
3633
  const entries = this.logs.get(sessionId) || [];
2509
3634
  if (entries.length === 0) return "0x" + "0".repeat(64);
2510
- const leaves = entries.map(
2511
- (entry) => this.hashEntry(entry)
2512
- );
3635
+ const leaves = entries.map((entry) => this.hashEntry(entry));
2513
3636
  const root = this.computeMerkleRoot(leaves);
2514
3637
  this.merkleRoots.set(sessionId, root);
2515
- console.log(`[Aggregator] Merkle root for ${sessionId}: ${root} (${entries.length} leaves)`);
3638
+ console.log(
3639
+ `[Aggregator] Merkle root for ${sessionId}: ${root} (${entries.length} leaves)`
3640
+ );
2516
3641
  return root;
2517
3642
  }
2518
3643
  /**
@@ -2543,7 +3668,9 @@ var AggregatorService = class {
2543
3668
  entries.filter((e) => e.timestamp > windowEnd)
2544
3669
  );
2545
3670
  this.merkleRoots.delete(sessionId);
2546
- console.log(`[Aggregator] Cleared entries for ${sessionId} before ${windowEnd}`);
3671
+ console.log(
3672
+ `[Aggregator] Cleared entries for ${sessionId} before ${windowEnd}`
3673
+ );
2547
3674
  }
2548
3675
  /**
2549
3676
  * Get aggregation stats for monitoring
@@ -2584,7 +3711,9 @@ var AggregatorService = class {
2584
3711
  const nextLevel = [];
2585
3712
  for (let i = 0; i < currentLevel.length; i += 2) {
2586
3713
  const combined = currentLevel[i] + currentLevel[i + 1].slice(2);
2587
- nextLevel.push("0x" + (0, import_crypto3.createHash)("sha256").update(combined).digest("hex"));
3714
+ nextLevel.push(
3715
+ "0x" + (0, import_crypto3.createHash)("sha256").update(combined).digest("hex")
3716
+ );
2588
3717
  }
2589
3718
  currentLevel = nextLevel;
2590
3719
  }
@@ -2639,7 +3768,11 @@ var RedisUsageStore = class {
2639
3768
  await this.connect();
2640
3769
  }
2641
3770
  const upper = Math.max(0, limit - 1);
2642
- const values = await this.client.lRange(sessionKey(this.config.keyPrefix, sessionId), 0, upper);
3771
+ const values = await this.client.lRange(
3772
+ sessionKey(this.config.keyPrefix, sessionId),
3773
+ 0,
3774
+ upper
3775
+ );
2643
3776
  return values.map((value) => {
2644
3777
  try {
2645
3778
  return JSON.parse(value);
@@ -2652,14 +3785,24 @@ var RedisUsageStore = class {
2652
3785
  if (!this.connected) {
2653
3786
  await this.connect();
2654
3787
  }
2655
- await this.client.hSet(settlementKey(this.config.keyPrefix), sessionId, txHash);
2656
- await this.client.expire(settlementKey(this.config.keyPrefix), this.config.ttlSeconds);
3788
+ await this.client.hSet(
3789
+ settlementKey(this.config.keyPrefix),
3790
+ sessionId,
3791
+ txHash
3792
+ );
3793
+ await this.client.expire(
3794
+ settlementKey(this.config.keyPrefix),
3795
+ this.config.ttlSeconds
3796
+ );
2657
3797
  }
2658
3798
  async getLatestSettlementTx(sessionId) {
2659
3799
  if (!this.connected) {
2660
3800
  await this.connect();
2661
3801
  }
2662
- const txHash = await this.client.hGet(settlementKey(this.config.keyPrefix), sessionId);
3802
+ const txHash = await this.client.hGet(
3803
+ settlementKey(this.config.keyPrefix),
3804
+ sessionId
3805
+ );
2663
3806
  return txHash ?? null;
2664
3807
  }
2665
3808
  async stop() {
@@ -2886,14 +4029,13 @@ var ProofOrchestrator = class {
2886
4029
  };
2887
4030
 
2888
4031
  // src/services/transport-axelar.ts
2889
- var import_viem6 = require("viem");
2890
- var import_accounts3 = require("viem/accounts");
2891
- var import_chains6 = require("viem/chains");
2892
- var import_sdk8 = require("@arcenpay/sdk");
4032
+ var import_viem8 = require("viem");
4033
+ var import_accounts4 = require("viem/accounts");
4034
+ var import_chains10 = require("viem/chains");
2893
4035
  var CHAIN_MAP6 = {
2894
- 11155111: import_chains6.sepolia,
2895
- 84532: import_chains6.baseSepolia,
2896
- 8453: import_chains6.base
4036
+ 11155111: import_chains10.sepolia,
4037
+ 84532: import_chains10.baseSepolia,
4038
+ 8453: import_chains10.base
2897
4039
  };
2898
4040
  var AXELAR_CHAIN_NAMES = {
2899
4041
  1: "ethereum",
@@ -2952,18 +4094,18 @@ var AxelarTransport = class {
2952
4094
  signerAddress;
2953
4095
  constructor(config) {
2954
4096
  this.config = config;
2955
- this.chainId = config.chainId ?? import_sdk8.DEFAULT_CHAIN_ID;
2956
- const chain = CHAIN_MAP6[this.chainId] || import_chains6.baseSepolia;
2957
- const account = (0, import_accounts3.privateKeyToAccount)(config.privateKey);
4097
+ this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
4098
+ const chain = CHAIN_MAP6[this.chainId] || import_chains10.baseSepolia;
4099
+ const account = (0, import_accounts4.privateKeyToAccount)(config.privateKey);
2958
4100
  this.signerAddress = account.address;
2959
- this.publicClient = (0, import_viem6.createPublicClient)({
4101
+ this.publicClient = (0, import_viem8.createPublicClient)({
2960
4102
  chain,
2961
- transport: (0, import_viem6.http)(config.rpcUrl)
4103
+ transport: (0, import_viem8.http)(config.rpcUrl)
2962
4104
  });
2963
- this.walletClient = (0, import_viem6.createWalletClient)({
4105
+ this.walletClient = (0, import_viem8.createWalletClient)({
2964
4106
  account,
2965
4107
  chain,
2966
- transport: (0, import_viem6.http)(config.rpcUrl)
4108
+ transport: (0, import_viem8.http)(config.rpcUrl)
2967
4109
  });
2968
4110
  }
2969
4111
  /**
@@ -3050,14 +4192,13 @@ var AxelarTransport = class {
3050
4192
  };
3051
4193
 
3052
4194
  // src/services/transport-ccip.ts
3053
- var import_viem7 = require("viem");
3054
- var import_accounts4 = require("viem/accounts");
3055
- var import_chains7 = require("viem/chains");
3056
- var import_sdk9 = require("@arcenpay/sdk");
4195
+ var import_viem9 = require("viem");
4196
+ var import_accounts5 = require("viem/accounts");
4197
+ var import_chains11 = require("viem/chains");
3057
4198
  var CHAIN_MAP7 = {
3058
- 11155111: import_chains7.sepolia,
3059
- 84532: import_chains7.baseSepolia,
3060
- 8453: import_chains7.base
4199
+ 11155111: import_chains11.sepolia,
4200
+ 84532: import_chains11.baseSepolia,
4201
+ 8453: import_chains11.base
3061
4202
  };
3062
4203
  var CCIP_CHAIN_SELECTORS = {
3063
4204
  1: 5009297550715157269n,
@@ -3142,19 +4283,19 @@ var CCIPTransport = class {
3142
4283
  gasLimit;
3143
4284
  constructor(config) {
3144
4285
  this.config = config;
3145
- this.chainId = config.chainId ?? import_sdk9.DEFAULT_CHAIN_ID;
4286
+ this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
3146
4287
  this.gasLimit = config.gasLimit || 200000n;
3147
- const chain = CHAIN_MAP7[this.chainId] || import_chains7.baseSepolia;
3148
- const account = (0, import_accounts4.privateKeyToAccount)(config.privateKey);
4288
+ const chain = CHAIN_MAP7[this.chainId] || import_chains11.baseSepolia;
4289
+ const account = (0, import_accounts5.privateKeyToAccount)(config.privateKey);
3149
4290
  this.signerAddress = account.address;
3150
- this.publicClient = (0, import_viem7.createPublicClient)({
4291
+ this.publicClient = (0, import_viem9.createPublicClient)({
3151
4292
  chain,
3152
- transport: (0, import_viem7.http)(config.rpcUrl)
4293
+ transport: (0, import_viem9.http)(config.rpcUrl)
3153
4294
  });
3154
- this.walletClient = (0, import_viem7.createWalletClient)({
4295
+ this.walletClient = (0, import_viem9.createWalletClient)({
3155
4296
  account,
3156
4297
  chain,
3157
- transport: (0, import_viem7.http)(config.rpcUrl)
4298
+ transport: (0, import_viem9.http)(config.rpcUrl)
3158
4299
  });
3159
4300
  }
3160
4301
  /**
@@ -3226,7 +4367,10 @@ var CCIPTransport = class {
3226
4367
  address: this.config.routerAddress,
3227
4368
  abi: CCIP_ROUTER_ABI,
3228
4369
  functionName: "getFee",
3229
- args: [destSelector, this.buildMessage(payload, destinationAddressOverride)]
4370
+ args: [
4371
+ destSelector,
4372
+ this.buildMessage(payload, destinationAddressOverride)
4373
+ ]
3230
4374
  });
3231
4375
  } catch {
3232
4376
  return 5000000000000000n;
@@ -3241,14 +4385,13 @@ var CCIPTransport = class {
3241
4385
  };
3242
4386
 
3243
4387
  // src/services/keeper.ts
3244
- var import_viem8 = require("viem");
3245
- var import_accounts5 = require("viem/accounts");
3246
- var import_chains8 = require("viem/chains");
3247
- var import_sdk10 = require("@arcenpay/sdk");
4388
+ var import_viem10 = require("viem");
4389
+ var import_accounts6 = require("viem/accounts");
4390
+ var import_chains12 = require("viem/chains");
3248
4391
  var CHAIN_MAP8 = {
3249
- 11155111: import_chains8.sepolia,
3250
- 84532: import_chains8.baseSepolia,
3251
- 8453: import_chains8.base
4392
+ 11155111: import_chains12.sepolia,
4393
+ 84532: import_chains12.baseSepolia,
4394
+ 8453: import_chains12.base
3252
4395
  };
3253
4396
  var BillingKeeper = class {
3254
4397
  chainId;
@@ -3265,24 +4408,24 @@ var BillingKeeper = class {
3265
4408
  renewalLog = [];
3266
4409
  callbacks = [];
3267
4410
  constructor(config) {
3268
- this.chainId = config.chainId ?? import_sdk10.DEFAULT_CHAIN_ID;
3269
- const chain = CHAIN_MAP8[this.chainId] || import_chains8.baseSepolia;
3270
- const contracts = (0, import_sdk10.getContractAddresses)(this.chainId);
4411
+ this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
4412
+ const chain = CHAIN_MAP8[this.chainId] || import_chains12.baseSepolia;
4413
+ const contracts = getContractAddresses(this.chainId);
3271
4414
  this.registryAddress = contracts.subscriptionRegistry;
3272
4415
  this.autopayModuleAddress = contracts.autopayModule;
3273
4416
  this.intervalMs = config.intervalMs || 6e4;
3274
4417
  this.batchSize = config.batchSize || 20;
3275
4418
  this.renewalBufferSeconds = config.renewalBufferSeconds || 86400;
3276
- const account = (0, import_accounts5.privateKeyToAccount)(config.privateKey);
4419
+ const account = (0, import_accounts6.privateKeyToAccount)(config.privateKey);
3277
4420
  this.signerAddress = account.address;
3278
- this.publicClient = (0, import_viem8.createPublicClient)({
4421
+ this.publicClient = (0, import_viem10.createPublicClient)({
3279
4422
  chain,
3280
- transport: (0, import_viem8.http)(config.rpcUrl)
4423
+ transport: (0, import_viem10.http)(config.rpcUrl)
3281
4424
  });
3282
- this.walletClient = (0, import_viem8.createWalletClient)({
4425
+ this.walletClient = (0, import_viem10.createWalletClient)({
3283
4426
  account,
3284
4427
  chain,
3285
- transport: (0, import_viem8.http)(config.rpcUrl)
4428
+ transport: (0, import_viem10.http)(config.rpcUrl)
3286
4429
  });
3287
4430
  }
3288
4431
  /**
@@ -3372,7 +4515,7 @@ var BillingKeeper = class {
3372
4515
  try {
3373
4516
  const totalSupply = await this.publicClient.readContract({
3374
4517
  address: this.registryAddress,
3375
- abi: import_sdk10.SubscriptionRegistryABI,
4518
+ abi: SubscriptionRegistryABI,
3376
4519
  functionName: "totalSupply"
3377
4520
  });
3378
4521
  const tokenIds = [];
@@ -3380,13 +4523,13 @@ var BillingKeeper = class {
3380
4523
  try {
3381
4524
  const tokenId = await this.publicClient.readContract({
3382
4525
  address: this.registryAddress,
3383
- abi: import_sdk10.SubscriptionRegistryABI,
4526
+ abi: SubscriptionRegistryABI,
3384
4527
  functionName: "tokenByIndex",
3385
4528
  args: [index]
3386
4529
  });
3387
4530
  const expiresAt = await this.publicClient.readContract({
3388
4531
  address: this.registryAddress,
3389
- abi: import_sdk10.SubscriptionRegistryABI,
4532
+ abi: SubscriptionRegistryABI,
3390
4533
  functionName: "expiresAt",
3391
4534
  args: [tokenId]
3392
4535
  });
@@ -3402,7 +4545,10 @@ var BillingKeeper = class {
3402
4545
  }
3403
4546
  return tokenIds;
3404
4547
  } catch (err) {
3405
- console.error("[BillingKeeper] Error finding expiring subscriptions:", err);
4548
+ console.error(
4549
+ "[BillingKeeper] Error finding expiring subscriptions:",
4550
+ err
4551
+ );
3406
4552
  return [];
3407
4553
  }
3408
4554
  }
@@ -3413,7 +4559,7 @@ var BillingKeeper = class {
3413
4559
  try {
3414
4560
  const subscriber = await this.publicClient.readContract({
3415
4561
  address: this.registryAddress,
3416
- abi: import_sdk10.SubscriptionRegistryABI,
4562
+ abi: SubscriptionRegistryABI,
3417
4563
  functionName: "ownerOf",
3418
4564
  args: [tokenId]
3419
4565
  });
@@ -3426,11 +4572,13 @@ var BillingKeeper = class {
3426
4572
  }
3427
4573
  const config = await this.publicClient.readContract({
3428
4574
  address: this.autopayModuleAddress,
3429
- abi: import_sdk10.ERC7579AutopayModuleABI,
4575
+ abi: ERC7579AutopayModuleABI,
3430
4576
  functionName: "getConfig",
3431
4577
  args: [subscriber]
3432
4578
  });
3433
- const merchant = String(config?.merchant ?? config?.[0] ?? "").toLowerCase();
4579
+ const merchant = String(
4580
+ config?.merchant ?? config?.[0] ?? ""
4581
+ ).toLowerCase();
3434
4582
  const amount = BigInt(config?.maxAmount ?? config?.[1] ?? 0);
3435
4583
  if (amount <= 0n) {
3436
4584
  console.log(
@@ -3445,7 +4593,7 @@ var BillingKeeper = class {
3445
4593
  }
3446
4594
  const txHash = await this.walletClient.writeContract({
3447
4595
  address: this.autopayModuleAddress,
3448
- abi: import_sdk10.ERC7579AutopayModuleABI,
4596
+ abi: ERC7579AutopayModuleABI,
3449
4597
  functionName: "execute",
3450
4598
  args: [subscriber, amount]
3451
4599
  });
@@ -3482,7 +4630,7 @@ var BillingKeeper = class {
3482
4630
  try {
3483
4631
  const config = await this.publicClient.readContract({
3484
4632
  address: this.autopayModuleAddress,
3485
- abi: import_sdk10.ERC7579AutopayModuleABI,
4633
+ abi: ERC7579AutopayModuleABI,
3486
4634
  functionName: "getConfig",
3487
4635
  args: [subscriber]
3488
4636
  });