@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/_esm-H6IRXC3A.mjs +804 -0
- package/dist/_esm-HVKNJV5D.mjs +127 -0
- package/dist/chains-3R75GF4L.mjs +21 -0
- package/dist/{chunk-SKFD6TSD.mjs → chunk-5CPGRELK.mjs} +3 -25
- package/dist/chunk-E2J5KZ6E.mjs +41 -0
- package/dist/chunk-GY2HMODH.mjs +94 -0
- package/dist/chunk-XHLV6BIG.mjs +10224 -0
- package/dist/index.d.mts +9 -10
- package/dist/index.d.ts +9 -10
- package/dist/index.js +1328 -180
- package/dist/index.mjs +1218 -153
- package/dist/tableland-gyl7O0n6.d.mts +191 -0
- package/dist/tableland-gyl7O0n6.d.ts +191 -0
- package/dist/tableland.d.mts +1 -46
- package/dist/tableland.d.ts +1 -46
- package/dist/tableland.js +3 -1
- package/dist/tableland.mjs +2 -1
- package/package.json +6 -2
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
TablelandService
|
|
2
|
+
TablelandService
|
|
3
|
+
} from "./chunk-5CPGRELK.mjs";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_CHAIN_ID,
|
|
6
|
+
getChain
|
|
7
|
+
} from "./chunk-GY2HMODH.mjs";
|
|
8
|
+
import {
|
|
3
9
|
__esm,
|
|
4
10
|
__export,
|
|
5
11
|
__toCommonJS
|
|
6
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-E2J5KZ6E.mjs";
|
|
7
13
|
|
|
8
14
|
// src/services/nonce-store.ts
|
|
9
15
|
var nonce_store_exports = {};
|
|
@@ -82,8 +88,1010 @@ var init_nonce_store = __esm({
|
|
|
82
88
|
}
|
|
83
89
|
});
|
|
84
90
|
|
|
91
|
+
// src/internal/sdk-core/addresses.ts
|
|
92
|
+
var ADDRESSES = {
|
|
93
|
+
// Ethereum Sepolia (Testnet) — Deployed 2026-03-19
|
|
94
|
+
11155111: {
|
|
95
|
+
subscriptionRegistry: "0xE206C519076535A9d24c852093860CFD780908C1",
|
|
96
|
+
autopayModule: "0xc82417e378b23AD9Ae73229EF08a4BA7896a4351",
|
|
97
|
+
planFactory: "0x4F97E0c2Ac053b735640fEb164a08Cb45ba83db1",
|
|
98
|
+
feeCollector: "0xa8A0D3007e5680D387A50C1a1E2Eb0AD092ca396",
|
|
99
|
+
sessionVault: "0xd68b9C0a34d61CC3b3F982A5EC6Cc5a5739e46D9",
|
|
100
|
+
zkUsageVerifier: "0x1f75d66692416cE880d51Baf6CdcBeE98E5837c0",
|
|
101
|
+
mirrorRegistry: "0xC187CD32d569ec0E84B9b378f8E63f3a74afac74"
|
|
102
|
+
},
|
|
103
|
+
// Base Sepolia (Testnet) — Deployed 2026-04-23
|
|
104
|
+
84532: {
|
|
105
|
+
subscriptionRegistry: "0xF9610c064FFD64255A1d509d17b2Af8733084e50",
|
|
106
|
+
autopayModule: "0x69Ac04bFdC045A99A2D31bb141A74da354a94c19",
|
|
107
|
+
planFactory: "0x66775Af13C63781AAd28203CC5d3E9eE5d5eB83d",
|
|
108
|
+
feeCollector: "0x5F32fBfF19385A78c3F721007758E9924FAD4133",
|
|
109
|
+
sessionVault: "0x96BcE2d49e3e4EddBBF3aa07354E66615BC2623c",
|
|
110
|
+
zkUsageVerifier: "0x03290b6988F87925A4939d974895bC30981aA90D",
|
|
111
|
+
mirrorRegistry: "0xe7E0dFfa82596ee6Ba1755bc25c29376a07236dE"
|
|
112
|
+
},
|
|
113
|
+
// Base Mainnet — set ARCENPAY_CONTRACT_8453_* env vars after audit + deployment
|
|
114
|
+
8453: {
|
|
115
|
+
subscriptionRegistry: "0x0000000000000000000000000000000000000000",
|
|
116
|
+
autopayModule: "0x0000000000000000000000000000000000000000",
|
|
117
|
+
planFactory: "0x0000000000000000000000000000000000000000",
|
|
118
|
+
feeCollector: "0x0000000000000000000000000000000000000000",
|
|
119
|
+
sessionVault: "0x0000000000000000000000000000000000000000",
|
|
120
|
+
zkUsageVerifier: "0x0000000000000000000000000000000000000000",
|
|
121
|
+
mirrorRegistry: "0x0000000000000000000000000000000000000000"
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
125
|
+
var CONTRACT_KEYS = [
|
|
126
|
+
"subscriptionRegistry",
|
|
127
|
+
"autopayModule",
|
|
128
|
+
"planFactory",
|
|
129
|
+
"feeCollector",
|
|
130
|
+
"sessionVault",
|
|
131
|
+
"zkUsageVerifier"
|
|
132
|
+
];
|
|
133
|
+
function applyEnvOverrides(chainId, base9) {
|
|
134
|
+
if (typeof process === "undefined") return base9;
|
|
135
|
+
const result = { ...base9 };
|
|
136
|
+
for (const key of CONTRACT_KEYS) {
|
|
137
|
+
const envKey = `ARCENPAY_CONTRACT_${chainId}_${key}`;
|
|
138
|
+
const legacyKey = `MEAP_CONTRACT_${chainId}_${key}`;
|
|
139
|
+
const override = process.env[envKey] ?? process.env[legacyKey];
|
|
140
|
+
if (override && override.startsWith("0x")) {
|
|
141
|
+
result[key] = override;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const mirrorOverride = process.env[`ARCENPAY_CONTRACT_${chainId}_mirrorRegistry`] ?? process.env[`MEAP_CONTRACT_${chainId}_mirrorRegistry`];
|
|
145
|
+
if (mirrorOverride && mirrorOverride.startsWith("0x")) {
|
|
146
|
+
result.mirrorRegistry = mirrorOverride;
|
|
147
|
+
}
|
|
148
|
+
const yieldOverride = process.env[`ARCENPAY_CONTRACT_${chainId}_yieldSessionVault`] ?? process.env[`MEAP_CONTRACT_${chainId}_yieldSessionVault`];
|
|
149
|
+
if (yieldOverride && yieldOverride.startsWith("0x")) {
|
|
150
|
+
result.yieldSessionVault = yieldOverride;
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
function getContractAddresses(chainId) {
|
|
155
|
+
const base9 = ADDRESSES[chainId];
|
|
156
|
+
if (!base9) {
|
|
157
|
+
throw new Error(`No contract addresses configured for chain ${chainId}`);
|
|
158
|
+
}
|
|
159
|
+
const addresses = applyEnvOverrides(chainId, base9);
|
|
160
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
|
|
161
|
+
const allZero = CONTRACT_KEYS.every(
|
|
162
|
+
(k) => addresses[k] === ZERO_ADDRESS
|
|
163
|
+
);
|
|
164
|
+
if (allZero) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
`[getContractAddresses] Chain ${chainId} has no deployed contracts. Set ARCENPAY_CONTRACT_${chainId}_<key> env vars or deploy contracts before using this chain in production.`
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return addresses;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/internal/sdk-core/environment.ts
|
|
174
|
+
var DEFAULT_SERVICES = {
|
|
175
|
+
11155111: {
|
|
176
|
+
rpcUrl: "https://ethereum-sepolia-rpc.publicnode.com"
|
|
177
|
+
},
|
|
178
|
+
84532: {
|
|
179
|
+
rpcUrl: "https://sepolia.base.org"
|
|
180
|
+
},
|
|
181
|
+
8453: {
|
|
182
|
+
rpcUrl: "https://mainnet.base.org"
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var LEGACY_RPC_ENV_KEYS = {
|
|
186
|
+
11155111: ["SEPOLIA_RPC_URL"],
|
|
187
|
+
84532: ["BASE_SEPOLIA_RPC_URL"],
|
|
188
|
+
8453: ["BASE_MAINNET_RPC_URL"]
|
|
189
|
+
};
|
|
190
|
+
var SERVICE_ENV_KEYS = {
|
|
191
|
+
rpcUrl: (chainId) => [
|
|
192
|
+
`ARCENPAY_RPC_URL_${chainId}`,
|
|
193
|
+
`MEAP_RPC_URL_${chainId}`,
|
|
194
|
+
`RPC_URL_${chainId}`,
|
|
195
|
+
`NEXT_PUBLIC_RPC_URL_${chainId}`,
|
|
196
|
+
...LEGACY_RPC_ENV_KEYS[chainId] || [],
|
|
197
|
+
"ARCENPAY_RPC_URL",
|
|
198
|
+
"MEAP_RPC_URL",
|
|
199
|
+
"RPC_URL",
|
|
200
|
+
"NEXT_PUBLIC_RPC_URL"
|
|
201
|
+
],
|
|
202
|
+
subgraphUrl: (chainId) => [
|
|
203
|
+
`ARCENPAY_SUBGRAPH_URL_${chainId}`,
|
|
204
|
+
`MEAP_SUBGRAPH_URL_${chainId}`,
|
|
205
|
+
`NEXT_PUBLIC_GRAPH_URL_${chainId}`,
|
|
206
|
+
"ARCENPAY_SUBGRAPH_URL",
|
|
207
|
+
"MEAP_SUBGRAPH_URL",
|
|
208
|
+
"NEXT_PUBLIC_GRAPH_URL"
|
|
209
|
+
],
|
|
210
|
+
facilitatorUrl: (chainId) => [
|
|
211
|
+
`ARCENPAY_FACILITATOR_URL_${chainId}`,
|
|
212
|
+
`MEAP_FACILITATOR_URL_${chainId}`,
|
|
213
|
+
`FACILITATOR_BASE_URL_${chainId}`,
|
|
214
|
+
`FACILITATOR_URL_${chainId}`,
|
|
215
|
+
`NEXT_PUBLIC_FACILITATOR_BASE_URL_${chainId}`,
|
|
216
|
+
`NEXT_PUBLIC_FACILITATOR_URL_${chainId}`,
|
|
217
|
+
"ARCENPAY_FACILITATOR_URL",
|
|
218
|
+
"MEAP_FACILITATOR_URL",
|
|
219
|
+
"FACILITATOR_BASE_URL",
|
|
220
|
+
"FACILITATOR_URL",
|
|
221
|
+
"NEXT_PUBLIC_FACILITATOR_BASE_URL",
|
|
222
|
+
"NEXT_PUBLIC_FACILITATOR_URL"
|
|
223
|
+
]
|
|
224
|
+
};
|
|
225
|
+
function getEnv(keys) {
|
|
226
|
+
if (typeof process === "undefined") return void 0;
|
|
227
|
+
for (const key of keys) {
|
|
228
|
+
const value = process.env[key]?.trim();
|
|
229
|
+
if (value) return value;
|
|
230
|
+
}
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
233
|
+
function resolveServiceUrl(chainId, service, fallback) {
|
|
234
|
+
return getEnv(SERVICE_ENV_KEYS[service](chainId)) || fallback || "";
|
|
235
|
+
}
|
|
236
|
+
function getChainEnvironment(chainId) {
|
|
237
|
+
const chain = getChain(chainId);
|
|
238
|
+
const defaults = DEFAULT_SERVICES[chainId] || {
|
|
239
|
+
rpcUrl: chain.rpcUrls.default.http[0] || ""
|
|
240
|
+
};
|
|
241
|
+
return {
|
|
242
|
+
chainId,
|
|
243
|
+
chainName: chain.name,
|
|
244
|
+
isTestnet: Boolean(chain.testnet),
|
|
245
|
+
contracts: getContractAddresses(chainId),
|
|
246
|
+
services: {
|
|
247
|
+
rpcUrl: resolveServiceUrl(chainId, "rpcUrl", defaults.rpcUrl),
|
|
248
|
+
subgraphUrl: resolveServiceUrl(chainId, "subgraphUrl", defaults.subgraphUrl),
|
|
249
|
+
facilitatorUrl: resolveServiceUrl(
|
|
250
|
+
chainId,
|
|
251
|
+
"facilitatorUrl",
|
|
252
|
+
defaults.facilitatorUrl
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// src/internal/sdk-core/app-origin.ts
|
|
259
|
+
var ARCENPAY_LOCAL_APP_URL = "http://localhost:3000";
|
|
260
|
+
var ARCENPAY_PRODUCTION_APP_URL = "https://app.arcenpay.com";
|
|
261
|
+
var DEFAULT_ENV_KEYS = [
|
|
262
|
+
"ARCENPAY_BASE_URL",
|
|
263
|
+
"NEXT_PUBLIC_ARCENPAY_BASE_URL"
|
|
264
|
+
];
|
|
265
|
+
function trimTrailingSlash(value) {
|
|
266
|
+
return value.replace(/\/$/, "");
|
|
267
|
+
}
|
|
268
|
+
function getRuntimeEnv() {
|
|
269
|
+
if (typeof process === "undefined") return void 0;
|
|
270
|
+
return process.env;
|
|
271
|
+
}
|
|
272
|
+
function readEnvValue(env, keys) {
|
|
273
|
+
if (!env) return void 0;
|
|
274
|
+
for (const key of keys) {
|
|
275
|
+
const value = env[key]?.trim();
|
|
276
|
+
if (value) return value;
|
|
277
|
+
}
|
|
278
|
+
return void 0;
|
|
279
|
+
}
|
|
280
|
+
function resolveArcenPayBaseUrl(options = {}) {
|
|
281
|
+
if (options.explicit?.trim()) {
|
|
282
|
+
return trimTrailingSlash(options.explicit.trim());
|
|
283
|
+
}
|
|
284
|
+
const env = options.env ?? getRuntimeEnv();
|
|
285
|
+
const envOverride = readEnvValue(env, options.envKeys ?? DEFAULT_ENV_KEYS);
|
|
286
|
+
if (envOverride) {
|
|
287
|
+
return trimTrailingSlash(envOverride);
|
|
288
|
+
}
|
|
289
|
+
const localDevUrl = options.localDevUrl ?? ARCENPAY_LOCAL_APP_URL;
|
|
290
|
+
const productionUrl = options.productionUrl ?? ARCENPAY_PRODUCTION_APP_URL;
|
|
291
|
+
const nodeEnv = env?.NODE_ENV;
|
|
292
|
+
if (nodeEnv && nodeEnv !== "production") {
|
|
293
|
+
return localDevUrl;
|
|
294
|
+
}
|
|
295
|
+
return productionUrl;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// src/internal/sdk-core/abis.ts
|
|
299
|
+
var SubscriptionRegistryABI = [
|
|
300
|
+
// Core functions
|
|
301
|
+
{
|
|
302
|
+
type: "function",
|
|
303
|
+
name: "mint",
|
|
304
|
+
inputs: [
|
|
305
|
+
{ name: "to", type: "address" },
|
|
306
|
+
{ name: "planId", type: "uint256" },
|
|
307
|
+
{ name: "duration", type: "uint64" }
|
|
308
|
+
],
|
|
309
|
+
outputs: [{ name: "tokenId", type: "uint256" }],
|
|
310
|
+
stateMutability: "nonpayable"
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
type: "function",
|
|
314
|
+
name: "renew",
|
|
315
|
+
inputs: [
|
|
316
|
+
{ name: "tokenId", type: "uint256" },
|
|
317
|
+
{ name: "extension", type: "uint64" }
|
|
318
|
+
],
|
|
319
|
+
outputs: [],
|
|
320
|
+
stateMutability: "nonpayable"
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
type: "function",
|
|
324
|
+
name: "cancel",
|
|
325
|
+
inputs: [{ name: "tokenId", type: "uint256" }],
|
|
326
|
+
outputs: [],
|
|
327
|
+
stateMutability: "nonpayable"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
type: "function",
|
|
331
|
+
name: "changePlan",
|
|
332
|
+
inputs: [
|
|
333
|
+
{ name: "tokenId", type: "uint256" },
|
|
334
|
+
{ name: "newPlanId", type: "uint256" }
|
|
335
|
+
],
|
|
336
|
+
outputs: [],
|
|
337
|
+
stateMutability: "nonpayable"
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
type: "function",
|
|
341
|
+
name: "isValid",
|
|
342
|
+
inputs: [{ name: "tokenId", type: "uint256" }],
|
|
343
|
+
outputs: [{ name: "", type: "bool" }],
|
|
344
|
+
stateMutability: "view"
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
type: "function",
|
|
348
|
+
name: "expiresAt",
|
|
349
|
+
inputs: [{ name: "tokenId", type: "uint256" }],
|
|
350
|
+
outputs: [{ name: "", type: "uint64" }],
|
|
351
|
+
stateMutability: "view"
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
type: "function",
|
|
355
|
+
name: "getPlanFeatures",
|
|
356
|
+
inputs: [{ name: "tokenId", type: "uint256" }],
|
|
357
|
+
outputs: [
|
|
358
|
+
{ name: "planId", type: "uint256" },
|
|
359
|
+
{ name: "planTier", type: "string" }
|
|
360
|
+
],
|
|
361
|
+
stateMutability: "view"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
type: "function",
|
|
365
|
+
name: "getWalletSubscription",
|
|
366
|
+
inputs: [{ name: "wallet", type: "address" }],
|
|
367
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
368
|
+
stateMutability: "view"
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
type: "function",
|
|
372
|
+
name: "importSubscription",
|
|
373
|
+
inputs: [
|
|
374
|
+
{ name: "to", type: "address" },
|
|
375
|
+
{ name: "tokenId", type: "uint256" },
|
|
376
|
+
{ name: "planId", type: "uint256" },
|
|
377
|
+
{ name: "expiration", type: "uint64" }
|
|
378
|
+
],
|
|
379
|
+
outputs: [],
|
|
380
|
+
stateMutability: "nonpayable"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
type: "function",
|
|
384
|
+
name: "finalizeMigration",
|
|
385
|
+
inputs: [],
|
|
386
|
+
outputs: [],
|
|
387
|
+
stateMutability: "nonpayable"
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
type: "function",
|
|
391
|
+
name: "hasActiveSubscription",
|
|
392
|
+
inputs: [{ name: "wallet", type: "address" }],
|
|
393
|
+
outputs: [{ name: "", type: "bool" }],
|
|
394
|
+
stateMutability: "view"
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
type: "function",
|
|
398
|
+
name: "authorizedBillers",
|
|
399
|
+
inputs: [{ name: "biller", type: "address" }],
|
|
400
|
+
outputs: [{ name: "isAuthorized", type: "bool" }],
|
|
401
|
+
stateMutability: "view"
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
type: "function",
|
|
405
|
+
name: "setCrossChainTransports",
|
|
406
|
+
inputs: [
|
|
407
|
+
{ name: "axelarTransport", type: "address" },
|
|
408
|
+
{ name: "ccipTransport", type: "address" }
|
|
409
|
+
],
|
|
410
|
+
outputs: [],
|
|
411
|
+
stateMutability: "nonpayable"
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
type: "function",
|
|
415
|
+
name: "dispatchCrossChainUpdate",
|
|
416
|
+
inputs: [
|
|
417
|
+
{ name: "tokenId", type: "uint256" },
|
|
418
|
+
{ name: "destinationChainId", type: "uint256" },
|
|
419
|
+
{ name: "refundAddress", type: "address" }
|
|
420
|
+
],
|
|
421
|
+
outputs: [
|
|
422
|
+
{ name: "messageId", type: "bytes32" },
|
|
423
|
+
{ name: "routeUsed", type: "uint8" }
|
|
424
|
+
],
|
|
425
|
+
stateMutability: "payable"
|
|
426
|
+
},
|
|
427
|
+
// Events
|
|
428
|
+
{
|
|
429
|
+
type: "event",
|
|
430
|
+
name: "SubscriptionMinted",
|
|
431
|
+
inputs: [
|
|
432
|
+
{ name: "subscriber", type: "address", indexed: true },
|
|
433
|
+
{ name: "tokenId", type: "uint256", indexed: true },
|
|
434
|
+
{ name: "planId", type: "uint256", indexed: true },
|
|
435
|
+
{ name: "expiration", type: "uint64", indexed: false }
|
|
436
|
+
]
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
type: "event",
|
|
440
|
+
name: "SubscriptionRenewed",
|
|
441
|
+
inputs: [
|
|
442
|
+
{ name: "tokenId", type: "uint256", indexed: true },
|
|
443
|
+
{ name: "newExpiration", type: "uint64", indexed: false },
|
|
444
|
+
{ name: "amountPaid", type: "uint256", indexed: false }
|
|
445
|
+
]
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
type: "event",
|
|
449
|
+
name: "SubscriptionCancelled",
|
|
450
|
+
inputs: [{ name: "tokenId", type: "uint256", indexed: true }]
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
type: "event",
|
|
454
|
+
name: "SubscriptionPlanChanged",
|
|
455
|
+
inputs: [
|
|
456
|
+
{ name: "tokenId", type: "uint256", indexed: true },
|
|
457
|
+
{ name: "previousPlanId", type: "uint256", indexed: true },
|
|
458
|
+
{ name: "newPlanId", type: "uint256", indexed: true },
|
|
459
|
+
{ name: "expiration", type: "uint64", indexed: false }
|
|
460
|
+
]
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
type: "event",
|
|
464
|
+
name: "BillingSuccess",
|
|
465
|
+
inputs: [
|
|
466
|
+
{ name: "tokenId", type: "uint256", indexed: true },
|
|
467
|
+
{ name: "planId", type: "uint256", indexed: true },
|
|
468
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
469
|
+
{ name: "timestamp", type: "uint256", indexed: false }
|
|
470
|
+
]
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
type: "event",
|
|
474
|
+
name: "CrossChainDispatchRequested",
|
|
475
|
+
inputs: [
|
|
476
|
+
{ name: "tokenId", type: "uint256", indexed: true },
|
|
477
|
+
{ name: "destinationChainId", type: "uint256", indexed: true },
|
|
478
|
+
{ name: "route", type: "uint8", indexed: true },
|
|
479
|
+
{ name: "messageId", type: "bytes32", indexed: false }
|
|
480
|
+
]
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
type: "event",
|
|
484
|
+
name: "CrossChainFallbackTriggered",
|
|
485
|
+
inputs: [
|
|
486
|
+
{ name: "tokenId", type: "uint256", indexed: true },
|
|
487
|
+
{ name: "destinationChainId", type: "uint256", indexed: true },
|
|
488
|
+
{ name: "primaryError", type: "bytes", indexed: false }
|
|
489
|
+
]
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
type: "event",
|
|
493
|
+
name: "SubscriptionImported",
|
|
494
|
+
inputs: [
|
|
495
|
+
{ name: "subscriber", type: "address", indexed: true },
|
|
496
|
+
{ name: "tokenId", type: "uint256", indexed: true },
|
|
497
|
+
{ name: "planId", type: "uint256", indexed: true },
|
|
498
|
+
{ name: "expiration", type: "uint64", indexed: false }
|
|
499
|
+
]
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
type: "event",
|
|
503
|
+
name: "RegistryMigrationFinalized",
|
|
504
|
+
inputs: []
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
type: "event",
|
|
508
|
+
name: "Transfer",
|
|
509
|
+
inputs: [
|
|
510
|
+
{ name: "from", type: "address", indexed: true },
|
|
511
|
+
{ name: "to", type: "address", indexed: true },
|
|
512
|
+
{ name: "tokenId", type: "uint256", indexed: true }
|
|
513
|
+
]
|
|
514
|
+
}
|
|
515
|
+
];
|
|
516
|
+
var ERC7579AutopayModuleABI = [
|
|
517
|
+
{
|
|
518
|
+
type: "function",
|
|
519
|
+
name: "onInstall",
|
|
520
|
+
inputs: [{ name: "data", type: "bytes" }],
|
|
521
|
+
outputs: [],
|
|
522
|
+
stateMutability: "nonpayable"
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
type: "function",
|
|
526
|
+
name: "onUninstall",
|
|
527
|
+
inputs: [{ name: "data", type: "bytes" }],
|
|
528
|
+
outputs: [],
|
|
529
|
+
stateMutability: "nonpayable"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
type: "function",
|
|
533
|
+
name: "execute",
|
|
534
|
+
inputs: [
|
|
535
|
+
{ name: "account", type: "address" },
|
|
536
|
+
{ name: "amount", type: "uint256" }
|
|
537
|
+
],
|
|
538
|
+
outputs: [],
|
|
539
|
+
stateMutability: "nonpayable"
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
type: "function",
|
|
543
|
+
name: "isInitialized",
|
|
544
|
+
inputs: [{ name: "smartAccount", type: "address" }],
|
|
545
|
+
outputs: [{ name: "", type: "bool" }],
|
|
546
|
+
stateMutability: "view"
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
type: "function",
|
|
550
|
+
name: "getConfig",
|
|
551
|
+
inputs: [{ name: "account", type: "address" }],
|
|
552
|
+
outputs: [
|
|
553
|
+
{
|
|
554
|
+
name: "config",
|
|
555
|
+
type: "tuple",
|
|
556
|
+
components: [
|
|
557
|
+
{ name: "merchant", type: "address" },
|
|
558
|
+
{ name: "maxAmount", type: "uint256" },
|
|
559
|
+
{ name: "token", type: "address" },
|
|
560
|
+
{ name: "interval", type: "uint32" },
|
|
561
|
+
{ name: "startTime", type: "uint64" },
|
|
562
|
+
{ name: "planId", type: "uint256" },
|
|
563
|
+
{ name: "maxTotalAmount", type: "uint256" }
|
|
564
|
+
]
|
|
565
|
+
}
|
|
566
|
+
],
|
|
567
|
+
stateMutability: "view"
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
type: "function",
|
|
571
|
+
name: "updateConfig",
|
|
572
|
+
inputs: [
|
|
573
|
+
{
|
|
574
|
+
name: "config",
|
|
575
|
+
type: "tuple",
|
|
576
|
+
components: [
|
|
577
|
+
{ name: "merchant", type: "address" },
|
|
578
|
+
{ name: "maxAmount", type: "uint256" },
|
|
579
|
+
{ name: "token", type: "address" },
|
|
580
|
+
{ name: "interval", type: "uint32" },
|
|
581
|
+
{ name: "startTime", type: "uint64" },
|
|
582
|
+
{ name: "planId", type: "uint256" },
|
|
583
|
+
{ name: "maxTotalAmount", type: "uint256" }
|
|
584
|
+
]
|
|
585
|
+
}
|
|
586
|
+
],
|
|
587
|
+
outputs: [],
|
|
588
|
+
stateMutability: "nonpayable"
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
type: "function",
|
|
592
|
+
name: "canExecute",
|
|
593
|
+
inputs: [{ name: "account", type: "address" }],
|
|
594
|
+
outputs: [{ name: "", type: "bool" }],
|
|
595
|
+
stateMutability: "view"
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
type: "function",
|
|
599
|
+
name: "lastPullTime",
|
|
600
|
+
inputs: [{ name: "account", type: "address" }],
|
|
601
|
+
outputs: [{ name: "", type: "uint64" }],
|
|
602
|
+
stateMutability: "view"
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
type: "function",
|
|
606
|
+
name: "mirrorDestinationChainId",
|
|
607
|
+
inputs: [{ name: "account", type: "address" }],
|
|
608
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
609
|
+
stateMutability: "view"
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
type: "function",
|
|
613
|
+
name: "isAccountPaused",
|
|
614
|
+
inputs: [{ name: "account", type: "address" }],
|
|
615
|
+
outputs: [{ name: "", type: "bool" }],
|
|
616
|
+
stateMutability: "view"
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
type: "function",
|
|
620
|
+
name: "importAccountState",
|
|
621
|
+
inputs: [
|
|
622
|
+
{ name: "account", type: "address" },
|
|
623
|
+
{
|
|
624
|
+
name: "config",
|
|
625
|
+
type: "tuple",
|
|
626
|
+
components: [
|
|
627
|
+
{ name: "merchant", type: "address" },
|
|
628
|
+
{ name: "maxAmount", type: "uint256" },
|
|
629
|
+
{ name: "token", type: "address" },
|
|
630
|
+
{ name: "interval", type: "uint32" },
|
|
631
|
+
{ name: "startTime", type: "uint64" },
|
|
632
|
+
{ name: "planId", type: "uint256" },
|
|
633
|
+
{ name: "maxTotalAmount", type: "uint256" }
|
|
634
|
+
]
|
|
635
|
+
},
|
|
636
|
+
{ name: "lastPullTime_", type: "uint64" },
|
|
637
|
+
{ name: "totalPulled_", type: "uint256" },
|
|
638
|
+
{ name: "mirrorDestinationChainId_", type: "uint256" },
|
|
639
|
+
{ name: "accountPaused_", type: "bool" }
|
|
640
|
+
],
|
|
641
|
+
outputs: [],
|
|
642
|
+
stateMutability: "nonpayable"
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
type: "function",
|
|
646
|
+
name: "finalizeMigration",
|
|
647
|
+
inputs: [],
|
|
648
|
+
outputs: [],
|
|
649
|
+
stateMutability: "nonpayable"
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
type: "event",
|
|
653
|
+
name: "AutopayConfigured",
|
|
654
|
+
inputs: [
|
|
655
|
+
{ name: "account", type: "address", indexed: true },
|
|
656
|
+
{ name: "merchant", type: "address", indexed: true },
|
|
657
|
+
{ name: "maxAmount", type: "uint256", indexed: false },
|
|
658
|
+
{ name: "token", type: "address", indexed: false },
|
|
659
|
+
{ name: "interval", type: "uint32", indexed: false }
|
|
660
|
+
]
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
type: "event",
|
|
664
|
+
name: "AutopayConfigUpdated",
|
|
665
|
+
inputs: [
|
|
666
|
+
{ name: "account", type: "address", indexed: true },
|
|
667
|
+
{ name: "previousPlanId", type: "uint256", indexed: true },
|
|
668
|
+
{ name: "newPlanId", type: "uint256", indexed: true },
|
|
669
|
+
{ name: "maxAmount", type: "uint256", indexed: false },
|
|
670
|
+
{ name: "interval", type: "uint32", indexed: false }
|
|
671
|
+
]
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
type: "event",
|
|
675
|
+
name: "PaymentExecuted",
|
|
676
|
+
inputs: [
|
|
677
|
+
{ name: "account", type: "address", indexed: true },
|
|
678
|
+
{ name: "merchant", type: "address", indexed: true },
|
|
679
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
680
|
+
{ name: "timestamp", type: "uint256", indexed: false }
|
|
681
|
+
]
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
type: "event",
|
|
685
|
+
name: "BillingExecuted",
|
|
686
|
+
inputs: [
|
|
687
|
+
{ name: "account", type: "address", indexed: true },
|
|
688
|
+
{ name: "merchant", type: "address", indexed: true },
|
|
689
|
+
{ name: "tokenId", type: "uint256", indexed: true },
|
|
690
|
+
{ name: "planId", type: "uint256", indexed: false },
|
|
691
|
+
{ name: "reason", type: "uint8", indexed: false },
|
|
692
|
+
{ name: "grossAmount", type: "uint256", indexed: false },
|
|
693
|
+
{ name: "merchantAmount", type: "uint256", indexed: false },
|
|
694
|
+
{ name: "protocolFee", type: "uint256", indexed: false },
|
|
695
|
+
{ name: "timestamp", type: "uint256", indexed: false }
|
|
696
|
+
]
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
type: "event",
|
|
700
|
+
name: "AutopayRevoked",
|
|
701
|
+
inputs: [{ name: "account", type: "address", indexed: true }]
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
type: "event",
|
|
705
|
+
name: "AccountStateImported",
|
|
706
|
+
inputs: [
|
|
707
|
+
{ name: "account", type: "address", indexed: true },
|
|
708
|
+
{ name: "planId", type: "uint256", indexed: true },
|
|
709
|
+
{ name: "lastPullTime", type: "uint64", indexed: false }
|
|
710
|
+
]
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
type: "event",
|
|
714
|
+
name: "MigrationFinalized",
|
|
715
|
+
inputs: []
|
|
716
|
+
}
|
|
717
|
+
];
|
|
718
|
+
var SessionVaultABI = [
|
|
719
|
+
{
|
|
720
|
+
type: "function",
|
|
721
|
+
name: "fundSession",
|
|
722
|
+
inputs: [
|
|
723
|
+
{ name: "amount", type: "uint256" },
|
|
724
|
+
{ name: "token", type: "address" }
|
|
725
|
+
],
|
|
726
|
+
outputs: [{ name: "sessionId", type: "bytes32" }],
|
|
727
|
+
stateMutability: "nonpayable"
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
type: "function",
|
|
731
|
+
name: "topUp",
|
|
732
|
+
inputs: [
|
|
733
|
+
{ name: "sessionId", type: "bytes32" },
|
|
734
|
+
{ name: "amount", type: "uint256" }
|
|
735
|
+
],
|
|
736
|
+
outputs: [],
|
|
737
|
+
stateMutability: "nonpayable"
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
type: "function",
|
|
741
|
+
name: "settle",
|
|
742
|
+
inputs: [
|
|
743
|
+
{ name: "sessionId", type: "bytes32" },
|
|
744
|
+
{ name: "amount", type: "uint256" },
|
|
745
|
+
{ name: "provider", type: "address" }
|
|
746
|
+
],
|
|
747
|
+
outputs: [],
|
|
748
|
+
stateMutability: "nonpayable"
|
|
749
|
+
},
|
|
750
|
+
{
|
|
751
|
+
type: "function",
|
|
752
|
+
name: "withdraw",
|
|
753
|
+
inputs: [{ name: "sessionId", type: "bytes32" }],
|
|
754
|
+
outputs: [],
|
|
755
|
+
stateMutability: "nonpayable"
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
type: "function",
|
|
759
|
+
name: "getBalance",
|
|
760
|
+
inputs: [{ name: "sessionId", type: "bytes32" }],
|
|
761
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
762
|
+
stateMutability: "view"
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
type: "function",
|
|
766
|
+
name: "getAgentBalance",
|
|
767
|
+
inputs: [{ name: "agent", type: "address" }],
|
|
768
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
769
|
+
stateMutability: "view"
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
type: "function",
|
|
773
|
+
name: "getSession",
|
|
774
|
+
inputs: [{ name: "sessionId", type: "bytes32" }],
|
|
775
|
+
outputs: [
|
|
776
|
+
{
|
|
777
|
+
name: "",
|
|
778
|
+
type: "tuple",
|
|
779
|
+
components: [
|
|
780
|
+
{ name: "agent", type: "address" },
|
|
781
|
+
{ name: "token", type: "address" },
|
|
782
|
+
{ name: "balance", type: "uint256" },
|
|
783
|
+
{ name: "totalFunded", type: "uint256" },
|
|
784
|
+
{ name: "totalSettled", type: "uint256" },
|
|
785
|
+
{ name: "active", type: "bool" },
|
|
786
|
+
{ name: "createdAt", type: "uint64" }
|
|
787
|
+
]
|
|
788
|
+
}
|
|
789
|
+
],
|
|
790
|
+
stateMutability: "view"
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
type: "function",
|
|
794
|
+
name: "getAgentSessions",
|
|
795
|
+
inputs: [{ name: "agent", type: "address" }],
|
|
796
|
+
outputs: [{ name: "", type: "bytes32[]" }],
|
|
797
|
+
stateMutability: "view"
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
type: "function",
|
|
801
|
+
name: "authorizedSettlers",
|
|
802
|
+
inputs: [{ name: "", type: "address" }],
|
|
803
|
+
outputs: [{ name: "", type: "bool" }],
|
|
804
|
+
stateMutability: "view"
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
type: "event",
|
|
808
|
+
name: "SessionFunded",
|
|
809
|
+
inputs: [
|
|
810
|
+
{ name: "agent", type: "address", indexed: true },
|
|
811
|
+
{ name: "sessionId", type: "bytes32", indexed: true },
|
|
812
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
813
|
+
{ name: "token", type: "address", indexed: false }
|
|
814
|
+
]
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
type: "event",
|
|
818
|
+
name: "SessionSettled",
|
|
819
|
+
inputs: [
|
|
820
|
+
{ name: "sessionId", type: "bytes32", indexed: true },
|
|
821
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
822
|
+
{ name: "provider", type: "address", indexed: true }
|
|
823
|
+
]
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
type: "event",
|
|
827
|
+
name: "SessionWithdrawn",
|
|
828
|
+
inputs: [
|
|
829
|
+
{ name: "sessionId", type: "bytes32", indexed: true },
|
|
830
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
831
|
+
{ name: "agent", type: "address", indexed: true }
|
|
832
|
+
]
|
|
833
|
+
}
|
|
834
|
+
];
|
|
835
|
+
var ZKUsageVerifierABI = [
|
|
836
|
+
{
|
|
837
|
+
type: "function",
|
|
838
|
+
name: "setGroth16Verifier",
|
|
839
|
+
inputs: [{ name: "verifier", type: "address" }],
|
|
840
|
+
outputs: [],
|
|
841
|
+
stateMutability: "nonpayable"
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
type: "function",
|
|
845
|
+
name: "groth16Verifier",
|
|
846
|
+
inputs: [],
|
|
847
|
+
outputs: [{ name: "", type: "address" }],
|
|
848
|
+
stateMutability: "view"
|
|
849
|
+
},
|
|
850
|
+
{
|
|
851
|
+
type: "function",
|
|
852
|
+
name: "submitProof",
|
|
853
|
+
inputs: [
|
|
854
|
+
{
|
|
855
|
+
name: "proof",
|
|
856
|
+
type: "tuple",
|
|
857
|
+
components: [
|
|
858
|
+
{ name: "a", type: "uint256[2]" },
|
|
859
|
+
{ name: "b", type: "uint256[2][2]" },
|
|
860
|
+
{ name: "c", type: "uint256[2]" }
|
|
861
|
+
]
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
name: "inputs",
|
|
865
|
+
type: "tuple",
|
|
866
|
+
components: [
|
|
867
|
+
{ name: "agentAddress", type: "bytes32" },
|
|
868
|
+
{ name: "sessionId", type: "bytes32" },
|
|
869
|
+
{ name: "callCount", type: "uint256" },
|
|
870
|
+
{ name: "windowStart", type: "uint64" },
|
|
871
|
+
{ name: "windowEnd", type: "uint64" },
|
|
872
|
+
{ name: "merkleRoot", type: "bytes32" },
|
|
873
|
+
{ name: "nullifier", type: "bytes32" }
|
|
874
|
+
]
|
|
875
|
+
}
|
|
876
|
+
],
|
|
877
|
+
outputs: [],
|
|
878
|
+
stateMutability: "nonpayable"
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
type: "function",
|
|
882
|
+
name: "isNullifierUsed",
|
|
883
|
+
inputs: [{ name: "nullifier", type: "bytes32" }],
|
|
884
|
+
outputs: [{ name: "", type: "bool" }],
|
|
885
|
+
stateMutability: "view"
|
|
886
|
+
},
|
|
887
|
+
{
|
|
888
|
+
type: "function",
|
|
889
|
+
name: "getRateSchedule",
|
|
890
|
+
inputs: [{ name: "planId", type: "uint256" }],
|
|
891
|
+
outputs: [{ name: "ratePerCall", type: "uint256" }],
|
|
892
|
+
stateMutability: "view"
|
|
893
|
+
},
|
|
894
|
+
{
|
|
895
|
+
type: "function",
|
|
896
|
+
name: "getPendingBalance",
|
|
897
|
+
inputs: [{ name: "agent", type: "address" }],
|
|
898
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
899
|
+
stateMutability: "view"
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
type: "event",
|
|
903
|
+
name: "BillingSettled",
|
|
904
|
+
inputs: [
|
|
905
|
+
{ name: "sessionId", type: "bytes32", indexed: true },
|
|
906
|
+
{ name: "agentAddress", type: "bytes32", indexed: true },
|
|
907
|
+
{ name: "callCount", type: "uint256", indexed: false },
|
|
908
|
+
{ name: "settlementAmount", type: "uint256", indexed: false },
|
|
909
|
+
{ name: "windowStart", type: "uint64", indexed: false },
|
|
910
|
+
{ name: "windowEnd", type: "uint64", indexed: false }
|
|
911
|
+
]
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
type: "event",
|
|
915
|
+
name: "Groth16VerifierSet",
|
|
916
|
+
inputs: [{ name: "verifier", type: "address", indexed: true }]
|
|
917
|
+
}
|
|
918
|
+
];
|
|
919
|
+
var FeeCollectorABI = [
|
|
920
|
+
// ── Core fee collection ──
|
|
921
|
+
{
|
|
922
|
+
type: "function",
|
|
923
|
+
name: "collectSubscriptionFee",
|
|
924
|
+
inputs: [{ name: "amount", type: "uint256" }],
|
|
925
|
+
outputs: [{ name: "feeAmount", type: "uint256" }],
|
|
926
|
+
stateMutability: "nonpayable"
|
|
927
|
+
},
|
|
928
|
+
{
|
|
929
|
+
type: "function",
|
|
930
|
+
name: "collectSettlementFee",
|
|
931
|
+
inputs: [{ name: "amount", type: "uint256" }],
|
|
932
|
+
outputs: [{ name: "feeAmount", type: "uint256" }],
|
|
933
|
+
stateMutability: "nonpayable"
|
|
934
|
+
},
|
|
935
|
+
// ── Provider-specific fee collection ──
|
|
936
|
+
{
|
|
937
|
+
type: "function",
|
|
938
|
+
name: "collectSubscriptionFeeFor",
|
|
939
|
+
inputs: [
|
|
940
|
+
{ name: "amount", type: "uint256" },
|
|
941
|
+
{ name: "provider", type: "address" }
|
|
942
|
+
],
|
|
943
|
+
outputs: [{ name: "feeAmount", type: "uint256" }],
|
|
944
|
+
stateMutability: "nonpayable"
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
type: "function",
|
|
948
|
+
name: "collectSettlementFeeFor",
|
|
949
|
+
inputs: [
|
|
950
|
+
{ name: "amount", type: "uint256" },
|
|
951
|
+
{ name: "provider", type: "address" }
|
|
952
|
+
],
|
|
953
|
+
outputs: [{ name: "feeAmount", type: "uint256" }],
|
|
954
|
+
stateMutability: "nonpayable"
|
|
955
|
+
},
|
|
956
|
+
// ── Fee rate queries ──
|
|
957
|
+
{
|
|
958
|
+
type: "function",
|
|
959
|
+
name: "subscriptionFeeRate",
|
|
960
|
+
inputs: [],
|
|
961
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
962
|
+
stateMutability: "view"
|
|
963
|
+
},
|
|
964
|
+
{
|
|
965
|
+
type: "function",
|
|
966
|
+
name: "settlementFeeRate",
|
|
967
|
+
inputs: [],
|
|
968
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
969
|
+
stateMutability: "view"
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
type: "function",
|
|
973
|
+
name: "getProviderSubFeeBps",
|
|
974
|
+
inputs: [{ name: "provider", type: "address" }],
|
|
975
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
976
|
+
stateMutability: "view"
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
type: "function",
|
|
980
|
+
name: "getProviderSettleFeeBps",
|
|
981
|
+
inputs: [{ name: "provider", type: "address" }],
|
|
982
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
983
|
+
stateMutability: "view"
|
|
984
|
+
},
|
|
985
|
+
// ── Tier management ──
|
|
986
|
+
{
|
|
987
|
+
type: "function",
|
|
988
|
+
name: "syncProviderTier",
|
|
989
|
+
inputs: [
|
|
990
|
+
{ name: "provider", type: "address" },
|
|
991
|
+
{ name: "tier", type: "uint8" }
|
|
992
|
+
],
|
|
993
|
+
outputs: [],
|
|
994
|
+
stateMutability: "nonpayable"
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
type: "function",
|
|
998
|
+
name: "setTierFeeRates",
|
|
999
|
+
inputs: [
|
|
1000
|
+
{ name: "tier", type: "uint8" },
|
|
1001
|
+
{ name: "subFeeBps", type: "uint256" },
|
|
1002
|
+
{ name: "settleFeeBps", type: "uint256" }
|
|
1003
|
+
],
|
|
1004
|
+
outputs: [],
|
|
1005
|
+
stateMutability: "nonpayable"
|
|
1006
|
+
},
|
|
1007
|
+
{
|
|
1008
|
+
type: "function",
|
|
1009
|
+
name: "setProviderFeeRates",
|
|
1010
|
+
inputs: [
|
|
1011
|
+
{ name: "provider", type: "address" },
|
|
1012
|
+
{ name: "subFeeBps", type: "uint256" },
|
|
1013
|
+
{ name: "settleFeeBps", type: "uint256" }
|
|
1014
|
+
],
|
|
1015
|
+
outputs: [],
|
|
1016
|
+
stateMutability: "nonpayable"
|
|
1017
|
+
},
|
|
1018
|
+
{
|
|
1019
|
+
type: "function",
|
|
1020
|
+
name: "tierSubFeeBps",
|
|
1021
|
+
inputs: [{ name: "tier", type: "uint8" }],
|
|
1022
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1023
|
+
stateMutability: "view"
|
|
1024
|
+
},
|
|
1025
|
+
{
|
|
1026
|
+
type: "function",
|
|
1027
|
+
name: "tierSettleFeeBps",
|
|
1028
|
+
inputs: [{ name: "tier", type: "uint8" }],
|
|
1029
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1030
|
+
stateMutability: "view"
|
|
1031
|
+
},
|
|
1032
|
+
// ── Treasury ──
|
|
1033
|
+
{
|
|
1034
|
+
type: "function",
|
|
1035
|
+
name: "accumulatedFees",
|
|
1036
|
+
inputs: [{ name: "token", type: "address" }],
|
|
1037
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1038
|
+
stateMutability: "view"
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
type: "function",
|
|
1042
|
+
name: "withdrawFees",
|
|
1043
|
+
inputs: [{ name: "token", type: "address" }],
|
|
1044
|
+
outputs: [],
|
|
1045
|
+
stateMutability: "nonpayable"
|
|
1046
|
+
},
|
|
1047
|
+
// ── Events ──
|
|
1048
|
+
{
|
|
1049
|
+
type: "event",
|
|
1050
|
+
name: "FeeCollected",
|
|
1051
|
+
inputs: [
|
|
1052
|
+
{ name: "from", type: "address", indexed: true },
|
|
1053
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
1054
|
+
{ name: "feeAmount", type: "uint256", indexed: false },
|
|
1055
|
+
{ name: "feeType", type: "string", indexed: false }
|
|
1056
|
+
]
|
|
1057
|
+
},
|
|
1058
|
+
{
|
|
1059
|
+
type: "event",
|
|
1060
|
+
name: "FeesWithdrawn",
|
|
1061
|
+
inputs: [
|
|
1062
|
+
{ name: "treasury", type: "address", indexed: true },
|
|
1063
|
+
{ name: "amount", type: "uint256", indexed: false }
|
|
1064
|
+
]
|
|
1065
|
+
},
|
|
1066
|
+
{
|
|
1067
|
+
type: "event",
|
|
1068
|
+
name: "ProviderFeeRateSet",
|
|
1069
|
+
inputs: [
|
|
1070
|
+
{ name: "provider", type: "address", indexed: true },
|
|
1071
|
+
{ name: "subFeeBps", type: "uint256", indexed: false },
|
|
1072
|
+
{ name: "settleFeeBps", type: "uint256", indexed: false }
|
|
1073
|
+
]
|
|
1074
|
+
},
|
|
1075
|
+
{
|
|
1076
|
+
type: "event",
|
|
1077
|
+
name: "ProviderTierSynced",
|
|
1078
|
+
inputs: [
|
|
1079
|
+
{ name: "provider", type: "address", indexed: true },
|
|
1080
|
+
{ name: "tier", type: "uint8", indexed: false },
|
|
1081
|
+
{ name: "subFeeBps", type: "uint256", indexed: false },
|
|
1082
|
+
{ name: "settleFeeBps", type: "uint256", indexed: false }
|
|
1083
|
+
]
|
|
1084
|
+
}
|
|
1085
|
+
];
|
|
1086
|
+
|
|
1087
|
+
// src/internal/sdk-core/constants.ts
|
|
1088
|
+
var X402_VERSION = "1";
|
|
1089
|
+
var X402_SCHEME = "exact";
|
|
1090
|
+
|
|
1091
|
+
// src/internal/sdk-core/accounts.ts
|
|
1092
|
+
import { createPublicClient, http } from "viem";
|
|
1093
|
+
|
|
85
1094
|
// src/client.ts
|
|
86
|
-
import { resolveArcenPayBaseUrl } from "@arcenpay/sdk";
|
|
87
1095
|
var ArcenClient = class {
|
|
88
1096
|
apiKey;
|
|
89
1097
|
baseUrl;
|
|
@@ -330,19 +1338,13 @@ var ArcenApiError = class extends Error {
|
|
|
330
1338
|
|
|
331
1339
|
// src/middleware/x402.ts
|
|
332
1340
|
import {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
SessionVaultABI,
|
|
336
|
-
getChainEnvironment
|
|
337
|
-
} from "@arcenpay/sdk";
|
|
338
|
-
import {
|
|
339
|
-
createPublicClient,
|
|
340
|
-
http,
|
|
1341
|
+
createPublicClient as createPublicClient2,
|
|
1342
|
+
http as http2,
|
|
341
1343
|
recoverTypedDataAddress,
|
|
342
1344
|
isAddress,
|
|
343
1345
|
parseUnits
|
|
344
1346
|
} from "viem";
|
|
345
|
-
import { sepolia, baseSepolia, base } from "viem/chains";
|
|
1347
|
+
import { sepolia as sepolia2, baseSepolia as baseSepolia2, base } from "viem/chains";
|
|
346
1348
|
var PAYMENT_DOMAIN = {
|
|
347
1349
|
name: "MEAP x402 Payment",
|
|
348
1350
|
version: "1"
|
|
@@ -358,8 +1360,8 @@ var PAYMENT_TYPES = {
|
|
|
358
1360
|
]
|
|
359
1361
|
};
|
|
360
1362
|
var CHAIN_MAP = {
|
|
361
|
-
11155111:
|
|
362
|
-
84532:
|
|
1363
|
+
11155111: sepolia2,
|
|
1364
|
+
84532: baseSepolia2,
|
|
363
1365
|
8453: base
|
|
364
1366
|
};
|
|
365
1367
|
var CHAIN_ID_TO_NETWORK = {
|
|
@@ -459,10 +1461,12 @@ function x402Middleware(options) {
|
|
|
459
1461
|
const chainEnv = getChainEnvironment(chainId);
|
|
460
1462
|
const contracts = chainEnv.contracts;
|
|
461
1463
|
const payToAddress = payTo || contracts.feeCollector || "0x0000000000000000000000000000000000000000";
|
|
462
|
-
const chain = CHAIN_MAP[chainId] ||
|
|
463
|
-
const publicClient =
|
|
1464
|
+
const chain = CHAIN_MAP[chainId] || sepolia2;
|
|
1465
|
+
const publicClient = createPublicClient2({
|
|
464
1466
|
chain,
|
|
465
|
-
transport:
|
|
1467
|
+
transport: http2(
|
|
1468
|
+
rpcUrl || chainEnv.services.rpcUrl || chain.rpcUrls.default.http[0]
|
|
1469
|
+
)
|
|
466
1470
|
});
|
|
467
1471
|
return async (req, res, next) => {
|
|
468
1472
|
const paymentHeader = req.headers["x-payment"];
|
|
@@ -725,14 +1729,9 @@ import { createHash } from "crypto";
|
|
|
725
1729
|
import fs from "fs";
|
|
726
1730
|
import path from "path";
|
|
727
1731
|
import { pathToFileURL } from "url";
|
|
728
|
-
import { createPublicClient as
|
|
1732
|
+
import { createPublicClient as createPublicClient3, createWalletClient, http as http3 } from "viem";
|
|
729
1733
|
import { privateKeyToAccount } from "viem/accounts";
|
|
730
|
-
import { sepolia as
|
|
731
|
-
import {
|
|
732
|
-
DEFAULT_CHAIN_ID,
|
|
733
|
-
ZKUsageVerifierABI,
|
|
734
|
-
getContractAddresses
|
|
735
|
-
} from "@arcenpay/sdk";
|
|
1734
|
+
import { sepolia as sepolia3, baseSepolia as baseSepolia3, base as base2 } from "viem/chains";
|
|
736
1735
|
var UsageProofErrorCodes = {
|
|
737
1736
|
TOOLING_UNAVAILABLE: "TOOLING_UNAVAILABLE",
|
|
738
1737
|
ARTIFACTS_MISSING: "ARTIFACTS_MISSING",
|
|
@@ -753,12 +1752,12 @@ var UsageProofError = class extends Error {
|
|
|
753
1752
|
}
|
|
754
1753
|
};
|
|
755
1754
|
var CHAIN_MAP2 = {
|
|
756
|
-
11155111:
|
|
757
|
-
84532:
|
|
1755
|
+
11155111: sepolia3,
|
|
1756
|
+
84532: baseSepolia3,
|
|
758
1757
|
8453: base2
|
|
759
1758
|
};
|
|
760
1759
|
var MAX_ENTRIES = 128;
|
|
761
|
-
var
|
|
1760
|
+
var ZERO_ADDRESS3 = "0x0000000000000000000000000000000000000000";
|
|
762
1761
|
var UsageService = class {
|
|
763
1762
|
logs = /* @__PURE__ */ new Map();
|
|
764
1763
|
config;
|
|
@@ -768,7 +1767,7 @@ var UsageService = class {
|
|
|
768
1767
|
runtimeValidated = false;
|
|
769
1768
|
constructor(config = {}) {
|
|
770
1769
|
const chainId = config.chainId ?? DEFAULT_CHAIN_ID;
|
|
771
|
-
const chain = CHAIN_MAP2[chainId] ||
|
|
1770
|
+
const chain = CHAIN_MAP2[chainId] || baseSepolia3;
|
|
772
1771
|
const rpcUrl = config.rpcUrl || chain.rpcUrls.default.http[0];
|
|
773
1772
|
const proofMode = config.proofMode ?? (process.env.NODE_ENV === "development" ? "dev" : "strict");
|
|
774
1773
|
const circuitsRootDir = this.resolveCircuitsRoot(config.circuitsRootDir);
|
|
@@ -793,15 +1792,15 @@ var UsageService = class {
|
|
|
793
1792
|
} else {
|
|
794
1793
|
this.signerAccount = null;
|
|
795
1794
|
}
|
|
796
|
-
this.publicClient =
|
|
1795
|
+
this.publicClient = createPublicClient3({
|
|
797
1796
|
chain,
|
|
798
|
-
transport:
|
|
1797
|
+
transport: http3(rpcUrl)
|
|
799
1798
|
});
|
|
800
1799
|
if (this.signerAccount) {
|
|
801
1800
|
this.walletClient = createWalletClient({
|
|
802
1801
|
account: this.signerAccount,
|
|
803
1802
|
chain,
|
|
804
|
-
transport:
|
|
1803
|
+
transport: http3(rpcUrl)
|
|
805
1804
|
});
|
|
806
1805
|
} else {
|
|
807
1806
|
this.walletClient = null;
|
|
@@ -862,7 +1861,9 @@ var UsageService = class {
|
|
|
862
1861
|
}
|
|
863
1862
|
aggregateUsage(sessionId, windowEnd) {
|
|
864
1863
|
const logs = this.logs.get(sessionId) || [];
|
|
865
|
-
const windowLogs = logs.filter(
|
|
1864
|
+
const windowLogs = logs.filter(
|
|
1865
|
+
(entry) => entry.callData.timestamp <= windowEnd
|
|
1866
|
+
);
|
|
866
1867
|
const windowStart = windowLogs.length > 0 ? Math.min(...windowLogs.map((entry) => entry.callData.timestamp)) : 0;
|
|
867
1868
|
return {
|
|
868
1869
|
sessionId,
|
|
@@ -893,7 +1894,7 @@ var UsageService = class {
|
|
|
893
1894
|
);
|
|
894
1895
|
}
|
|
895
1896
|
const sessionIdBytes32 = this.normalizeBytes32(sessionId);
|
|
896
|
-
const agentAddress = this.signerAccount?.address ||
|
|
1897
|
+
const agentAddress = this.signerAccount?.address || ZERO_ADDRESS3;
|
|
897
1898
|
const agentAddressBytes32 = this.addressToBytes32(agentAddress);
|
|
898
1899
|
const logHashes = aggregation.logs.map((log) => this.hashUsageLog(log));
|
|
899
1900
|
const logTimestamps = aggregation.logs.map(
|
|
@@ -915,7 +1916,13 @@ var UsageService = class {
|
|
|
915
1916
|
const prover = await this.loadCircuitProver();
|
|
916
1917
|
proofResult = await prover.prove(circuitInput);
|
|
917
1918
|
publicSignals = proofResult.publicSignals;
|
|
918
|
-
this.assertPublicSignals(
|
|
1919
|
+
this.assertPublicSignals(
|
|
1920
|
+
publicSignals,
|
|
1921
|
+
aggregation,
|
|
1922
|
+
agentAddress,
|
|
1923
|
+
sessionIdBytes32,
|
|
1924
|
+
prover
|
|
1925
|
+
);
|
|
919
1926
|
} catch (err) {
|
|
920
1927
|
if (this.config.proofMode === "strict") {
|
|
921
1928
|
throw this.wrapProofError(err);
|
|
@@ -1058,7 +2065,9 @@ var UsageService = class {
|
|
|
1058
2065
|
this.config.zkeyPath,
|
|
1059
2066
|
this.config.verificationKeyPath
|
|
1060
2067
|
];
|
|
1061
|
-
const missing = required.filter(
|
|
2068
|
+
const missing = required.filter(
|
|
2069
|
+
(artifactPath) => !fs.existsSync(artifactPath)
|
|
2070
|
+
);
|
|
1062
2071
|
if (missing.length > 0) {
|
|
1063
2072
|
throw new UsageProofError(
|
|
1064
2073
|
UsageProofErrorCodes.ARTIFACTS_MISSING,
|
|
@@ -1104,7 +2113,9 @@ var UsageService = class {
|
|
|
1104
2113
|
const raw = fs.readFileSync(this.config.verificationKeyPath, "utf8");
|
|
1105
2114
|
const vkey = JSON.parse(raw);
|
|
1106
2115
|
if (vkey.protocol !== "groth16") {
|
|
1107
|
-
throw new Error(
|
|
2116
|
+
throw new Error(
|
|
2117
|
+
`Unsupported protocol: ${String(vkey.protocol || "unknown")}`
|
|
2118
|
+
);
|
|
1108
2119
|
}
|
|
1109
2120
|
if (typeof vkey.nPublic === "number" && vkey.nPublic !== 7) {
|
|
1110
2121
|
throw new Error(`Expected 7 public inputs, received ${vkey.nPublic}`);
|
|
@@ -1217,16 +2228,11 @@ var UsageService = class {
|
|
|
1217
2228
|
};
|
|
1218
2229
|
|
|
1219
2230
|
// src/services/settlement.ts
|
|
1220
|
-
import { createPublicClient as
|
|
1221
|
-
import { sepolia as
|
|
1222
|
-
import {
|
|
1223
|
-
DEFAULT_CHAIN_ID as DEFAULT_CHAIN_ID2,
|
|
1224
|
-
SessionVaultABI as SessionVaultABI2,
|
|
1225
|
-
getContractAddresses as getContractAddresses2
|
|
1226
|
-
} from "@arcenpay/sdk";
|
|
2231
|
+
import { createPublicClient as createPublicClient4, http as http4 } from "viem";
|
|
2232
|
+
import { sepolia as sepolia4, baseSepolia as baseSepolia4, base as base3 } from "viem/chains";
|
|
1227
2233
|
var CHAIN_MAP3 = {
|
|
1228
|
-
11155111:
|
|
1229
|
-
84532:
|
|
2234
|
+
11155111: sepolia4,
|
|
2235
|
+
84532: baseSepolia4,
|
|
1230
2236
|
8453: base3
|
|
1231
2237
|
};
|
|
1232
2238
|
var SettlementService = class {
|
|
@@ -1240,14 +2246,14 @@ var SettlementService = class {
|
|
|
1240
2246
|
publicClient;
|
|
1241
2247
|
constructor(config) {
|
|
1242
2248
|
this.rpcUrl = config.rpcUrl;
|
|
1243
|
-
this.chainId = config.chainId ??
|
|
1244
|
-
const contracts =
|
|
2249
|
+
this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
|
|
2250
|
+
const contracts = getContractAddresses(this.chainId);
|
|
1245
2251
|
this.zkVerifierAddress = config.zkVerifierAddress || contracts.zkUsageVerifier;
|
|
1246
2252
|
this.sessionVaultAddress = config.sessionVaultAddress || contracts.sessionVault;
|
|
1247
|
-
const chain = CHAIN_MAP3[this.chainId] ||
|
|
1248
|
-
this.publicClient =
|
|
2253
|
+
const chain = CHAIN_MAP3[this.chainId] || baseSepolia4;
|
|
2254
|
+
this.publicClient = createPublicClient4({
|
|
1249
2255
|
chain,
|
|
1250
|
-
transport:
|
|
2256
|
+
transport: http4(this.rpcUrl)
|
|
1251
2257
|
});
|
|
1252
2258
|
}
|
|
1253
2259
|
/**
|
|
@@ -1257,7 +2263,7 @@ var SettlementService = class {
|
|
|
1257
2263
|
try {
|
|
1258
2264
|
const balance = await this.publicClient.readContract({
|
|
1259
2265
|
address: this.sessionVaultAddress,
|
|
1260
|
-
abi:
|
|
2266
|
+
abi: SessionVaultABI,
|
|
1261
2267
|
functionName: "getAgentBalance",
|
|
1262
2268
|
args: [agentAddress]
|
|
1263
2269
|
});
|
|
@@ -1274,7 +2280,7 @@ var SettlementService = class {
|
|
|
1274
2280
|
try {
|
|
1275
2281
|
const session = await this.publicClient.readContract({
|
|
1276
2282
|
address: this.sessionVaultAddress,
|
|
1277
|
-
abi:
|
|
2283
|
+
abi: SessionVaultABI,
|
|
1278
2284
|
functionName: "getSession",
|
|
1279
2285
|
args: [sessionId]
|
|
1280
2286
|
});
|
|
@@ -1368,18 +2374,17 @@ var SettlementService = class {
|
|
|
1368
2374
|
};
|
|
1369
2375
|
|
|
1370
2376
|
// src/services/settlement-writer.ts
|
|
1371
|
-
import { createPublicClient as createPublicClient4, createWalletClient as createWalletClient2, http as http4, isAddress as isAddress2 } from "viem";
|
|
1372
|
-
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
1373
|
-
import { sepolia as sepolia4, baseSepolia as baseSepolia4, base as base4 } from "viem/chains";
|
|
1374
2377
|
import {
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
} from "
|
|
2378
|
+
createPublicClient as createPublicClient5,
|
|
2379
|
+
createWalletClient as createWalletClient2,
|
|
2380
|
+
http as http5,
|
|
2381
|
+
isAddress as isAddress2
|
|
2382
|
+
} from "viem";
|
|
2383
|
+
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
2384
|
+
import { sepolia as sepolia5, baseSepolia as baseSepolia5, base as base4 } from "viem/chains";
|
|
1380
2385
|
var CHAIN_MAP4 = {
|
|
1381
|
-
11155111:
|
|
1382
|
-
84532:
|
|
2386
|
+
11155111: sepolia5,
|
|
2387
|
+
84532: baseSepolia5,
|
|
1383
2388
|
8453: base4
|
|
1384
2389
|
};
|
|
1385
2390
|
function isBytes32(value) {
|
|
@@ -1389,11 +2394,19 @@ function normalizeSession(raw) {
|
|
|
1389
2394
|
const value = raw;
|
|
1390
2395
|
const agent = value?.agent ?? value?.[0] ?? "0x0000000000000000000000000000000000000000";
|
|
1391
2396
|
const token = value?.token ?? value?.[1] ?? "0x0000000000000000000000000000000000000000";
|
|
1392
|
-
const balance = BigInt(
|
|
1393
|
-
|
|
1394
|
-
|
|
2397
|
+
const balance = BigInt(
|
|
2398
|
+
value?.balance ?? value?.[2] ?? 0n
|
|
2399
|
+
);
|
|
2400
|
+
const totalFunded = BigInt(
|
|
2401
|
+
value?.totalFunded ?? value?.[3] ?? 0n
|
|
2402
|
+
);
|
|
2403
|
+
const totalSettled = BigInt(
|
|
2404
|
+
value?.totalSettled ?? value?.[4] ?? 0n
|
|
2405
|
+
);
|
|
1395
2406
|
const active = Boolean(value?.active ?? value?.[5] ?? false);
|
|
1396
|
-
const createdAt = BigInt(
|
|
2407
|
+
const createdAt = BigInt(
|
|
2408
|
+
value?.createdAt ?? value?.[6] ?? 0n
|
|
2409
|
+
);
|
|
1397
2410
|
return {
|
|
1398
2411
|
agent,
|
|
1399
2412
|
token,
|
|
@@ -1414,9 +2427,9 @@ var SettlementWriterService = class {
|
|
|
1414
2427
|
publicClient;
|
|
1415
2428
|
walletClient;
|
|
1416
2429
|
constructor(config) {
|
|
1417
|
-
this.chainId = config.chainId ??
|
|
1418
|
-
const chain = CHAIN_MAP4[this.chainId] ||
|
|
1419
|
-
const contracts =
|
|
2430
|
+
this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
|
|
2431
|
+
const chain = CHAIN_MAP4[this.chainId] || baseSepolia5;
|
|
2432
|
+
const contracts = getContractAddresses(this.chainId);
|
|
1420
2433
|
this.sessionVaultAddress = config.sessionVaultAddress || contracts.sessionVault;
|
|
1421
2434
|
this.feeCollectorAddress = config.feeCollectorAddress || contracts.feeCollector;
|
|
1422
2435
|
const account = privateKeyToAccount2(config.privateKey);
|
|
@@ -1424,19 +2437,21 @@ var SettlementWriterService = class {
|
|
|
1424
2437
|
this.providerAddress = config.providerAddress || account.address;
|
|
1425
2438
|
this.waitForReceipt = config.waitForReceipt ?? true;
|
|
1426
2439
|
if (!isAddress2(this.sessionVaultAddress)) {
|
|
1427
|
-
throw new Error(
|
|
2440
|
+
throw new Error(
|
|
2441
|
+
"Invalid SessionVault address for SettlementWriterService"
|
|
2442
|
+
);
|
|
1428
2443
|
}
|
|
1429
2444
|
if (!isAddress2(this.providerAddress)) {
|
|
1430
2445
|
throw new Error("Invalid provider address for SettlementWriterService");
|
|
1431
2446
|
}
|
|
1432
|
-
this.publicClient =
|
|
2447
|
+
this.publicClient = createPublicClient5({
|
|
1433
2448
|
chain,
|
|
1434
|
-
transport:
|
|
2449
|
+
transport: http5(config.rpcUrl || chain.rpcUrls.default.http[0])
|
|
1435
2450
|
});
|
|
1436
2451
|
this.walletClient = createWalletClient2({
|
|
1437
2452
|
account,
|
|
1438
2453
|
chain,
|
|
1439
|
-
transport:
|
|
2454
|
+
transport: http5(config.rpcUrl || chain.rpcUrls.default.http[0])
|
|
1440
2455
|
});
|
|
1441
2456
|
}
|
|
1442
2457
|
getSignerAddress() {
|
|
@@ -1451,7 +2466,7 @@ var SettlementWriterService = class {
|
|
|
1451
2466
|
}
|
|
1452
2467
|
const authorized = await this.publicClient.readContract({
|
|
1453
2468
|
address: this.sessionVaultAddress,
|
|
1454
|
-
abi:
|
|
2469
|
+
abi: SessionVaultABI,
|
|
1455
2470
|
functionName: "authorizedSettlers",
|
|
1456
2471
|
args: [address]
|
|
1457
2472
|
});
|
|
@@ -1460,7 +2475,7 @@ var SettlementWriterService = class {
|
|
|
1460
2475
|
async getSession(sessionId) {
|
|
1461
2476
|
const rawSession = await this.publicClient.readContract({
|
|
1462
2477
|
address: this.sessionVaultAddress,
|
|
1463
|
-
abi:
|
|
2478
|
+
abi: SessionVaultABI,
|
|
1464
2479
|
functionName: "getSession",
|
|
1465
2480
|
args: [sessionId]
|
|
1466
2481
|
});
|
|
@@ -1473,7 +2488,7 @@ var SettlementWriterService = class {
|
|
|
1473
2488
|
}
|
|
1474
2489
|
const sessionIds = await this.publicClient.readContract({
|
|
1475
2490
|
address: this.sessionVaultAddress,
|
|
1476
|
-
abi:
|
|
2491
|
+
abi: SessionVaultABI,
|
|
1477
2492
|
functionName: "getAgentSessions",
|
|
1478
2493
|
args: [signer]
|
|
1479
2494
|
});
|
|
@@ -1496,7 +2511,10 @@ var SettlementWriterService = class {
|
|
|
1496
2511
|
if (input.amount <= 0n) {
|
|
1497
2512
|
throw new Error("Settlement amount must be greater than zero");
|
|
1498
2513
|
}
|
|
1499
|
-
const resolvedSessionId = await this.resolveSessionId(
|
|
2514
|
+
const resolvedSessionId = await this.resolveSessionId(
|
|
2515
|
+
input.sessionIdHint,
|
|
2516
|
+
input.signer
|
|
2517
|
+
);
|
|
1500
2518
|
const session = await this.getSession(resolvedSessionId);
|
|
1501
2519
|
if (!session.active) {
|
|
1502
2520
|
throw new Error("Session is not active");
|
|
@@ -1515,7 +2533,7 @@ var SettlementWriterService = class {
|
|
|
1515
2533
|
}
|
|
1516
2534
|
const txHash = await this.walletClient.writeContract({
|
|
1517
2535
|
address: this.sessionVaultAddress,
|
|
1518
|
-
abi:
|
|
2536
|
+
abi: SessionVaultABI,
|
|
1519
2537
|
functionName: "settle",
|
|
1520
2538
|
args: [resolvedSessionId, input.amount, providerAddress]
|
|
1521
2539
|
});
|
|
@@ -1531,10 +2549,15 @@ var SettlementWriterService = class {
|
|
|
1531
2549
|
args: [input.amount, providerAddress]
|
|
1532
2550
|
});
|
|
1533
2551
|
if (this.waitForReceipt) {
|
|
1534
|
-
await this.publicClient.waitForTransactionReceipt({
|
|
2552
|
+
await this.publicClient.waitForTransactionReceipt({
|
|
2553
|
+
hash: feeTxHash
|
|
2554
|
+
});
|
|
1535
2555
|
}
|
|
1536
2556
|
} catch (err) {
|
|
1537
|
-
console.warn(
|
|
2557
|
+
console.warn(
|
|
2558
|
+
"[SettlementWriter] Fee collection failed (non-fatal):",
|
|
2559
|
+
err
|
|
2560
|
+
);
|
|
1538
2561
|
}
|
|
1539
2562
|
}
|
|
1540
2563
|
return {
|
|
@@ -1547,12 +2570,11 @@ var SettlementWriterService = class {
|
|
|
1547
2570
|
};
|
|
1548
2571
|
|
|
1549
2572
|
// src/services/events.ts
|
|
1550
|
-
import { createPublicClient as
|
|
1551
|
-
import { sepolia as
|
|
1552
|
-
import { DEFAULT_CHAIN_ID as DEFAULT_CHAIN_ID4, getContractAddresses as getContractAddresses4 } from "@arcenpay/sdk";
|
|
2573
|
+
import { createPublicClient as createPublicClient6, http as http6 } from "viem";
|
|
2574
|
+
import { sepolia as sepolia6, baseSepolia as baseSepolia6, base as base5 } from "viem/chains";
|
|
1553
2575
|
var CHAIN_MAP5 = {
|
|
1554
|
-
11155111:
|
|
1555
|
-
84532:
|
|
2576
|
+
11155111: sepolia6,
|
|
2577
|
+
84532: baseSepolia6,
|
|
1556
2578
|
8453: base5
|
|
1557
2579
|
};
|
|
1558
2580
|
var EventListenerService = class {
|
|
@@ -1563,14 +2585,14 @@ var EventListenerService = class {
|
|
|
1563
2585
|
pollInterval = null;
|
|
1564
2586
|
lastBlock = 0n;
|
|
1565
2587
|
constructor(config) {
|
|
1566
|
-
const chainId = config.chainId ??
|
|
1567
|
-
const chain = CHAIN_MAP5[chainId] ||
|
|
1568
|
-
const contracts =
|
|
2588
|
+
const chainId = config.chainId ?? DEFAULT_CHAIN_ID;
|
|
2589
|
+
const chain = CHAIN_MAP5[chainId] || baseSepolia6;
|
|
2590
|
+
const contracts = getContractAddresses(chainId);
|
|
1569
2591
|
this.registryAddress = config.registryAddress || contracts.subscriptionRegistry;
|
|
1570
2592
|
this.autopayModuleAddress = contracts.autopayModule;
|
|
1571
|
-
this.publicClient =
|
|
2593
|
+
this.publicClient = createPublicClient6({
|
|
1572
2594
|
chain,
|
|
1573
|
-
transport:
|
|
2595
|
+
transport: http6(config.rpcUrl)
|
|
1574
2596
|
});
|
|
1575
2597
|
}
|
|
1576
2598
|
/**
|
|
@@ -1582,7 +2604,10 @@ var EventListenerService = class {
|
|
|
1582
2604
|
this.callbacks.set(eventType, existing);
|
|
1583
2605
|
return () => {
|
|
1584
2606
|
const cbs = this.callbacks.get(eventType) || [];
|
|
1585
|
-
this.callbacks.set(
|
|
2607
|
+
this.callbacks.set(
|
|
2608
|
+
eventType,
|
|
2609
|
+
cbs.filter((cb) => cb !== callback)
|
|
2610
|
+
);
|
|
1586
2611
|
};
|
|
1587
2612
|
}
|
|
1588
2613
|
/**
|
|
@@ -1594,7 +2619,9 @@ var EventListenerService = class {
|
|
|
1594
2619
|
} catch {
|
|
1595
2620
|
this.lastBlock = 0n;
|
|
1596
2621
|
}
|
|
1597
|
-
console.log(
|
|
2622
|
+
console.log(
|
|
2623
|
+
`[EventListener] Watching SubscriptionRegistry at ${this.registryAddress} from block ${this.lastBlock}`
|
|
2624
|
+
);
|
|
1598
2625
|
this.pollInterval = setInterval(async () => {
|
|
1599
2626
|
await this.poll();
|
|
1600
2627
|
}, intervalMs);
|
|
@@ -1618,7 +2645,13 @@ var EventListenerService = class {
|
|
|
1618
2645
|
if (currentBlock <= this.lastBlock) return;
|
|
1619
2646
|
const addr = this.registryAddress;
|
|
1620
2647
|
const from = this.lastBlock + 1n;
|
|
1621
|
-
const [
|
|
2648
|
+
const [
|
|
2649
|
+
mintedLogs,
|
|
2650
|
+
renewedLogs,
|
|
2651
|
+
cancelledLogs,
|
|
2652
|
+
planChangedLogs,
|
|
2653
|
+
billingLogs
|
|
2654
|
+
] = await Promise.all([
|
|
1622
2655
|
this.publicClient.getLogs({
|
|
1623
2656
|
address: addr,
|
|
1624
2657
|
event: {
|
|
@@ -1653,9 +2686,7 @@ var EventListenerService = class {
|
|
|
1653
2686
|
event: {
|
|
1654
2687
|
type: "event",
|
|
1655
2688
|
name: "SubscriptionCancelled",
|
|
1656
|
-
inputs: [
|
|
1657
|
-
{ name: "tokenId", type: "uint256", indexed: true }
|
|
1658
|
-
]
|
|
2689
|
+
inputs: [{ name: "tokenId", type: "uint256", indexed: true }]
|
|
1659
2690
|
},
|
|
1660
2691
|
fromBlock: from,
|
|
1661
2692
|
toBlock: currentBlock
|
|
@@ -1765,7 +2796,9 @@ var EventListenerService = class {
|
|
|
1765
2796
|
* Dispatch event to registered callbacks
|
|
1766
2797
|
*/
|
|
1767
2798
|
async emit(event) {
|
|
1768
|
-
console.log(
|
|
2799
|
+
console.log(
|
|
2800
|
+
`[EventListener] ${event.type} \u2014 tokenId=${event.tokenId} tx=${event.transactionHash}`
|
|
2801
|
+
);
|
|
1769
2802
|
const typeCallbacks = this.callbacks.get(event.type) || [];
|
|
1770
2803
|
const wildcardCallbacks = this.callbacks.get("*") || [];
|
|
1771
2804
|
for (const cb of [...typeCallbacks, ...wildcardCallbacks]) {
|
|
@@ -1839,7 +2872,10 @@ var WebhookService = class {
|
|
|
1839
2872
|
deliveredAt: Date.now(),
|
|
1840
2873
|
success: response.ok
|
|
1841
2874
|
});
|
|
1842
|
-
await this.persistDelivery(
|
|
2875
|
+
await this.persistDelivery(
|
|
2876
|
+
this.deliveryLog[this.deliveryLog.length - 1],
|
|
2877
|
+
payload
|
|
2878
|
+
);
|
|
1843
2879
|
if (!response.ok && attempt < this.config.maxRetries) {
|
|
1844
2880
|
await this.scheduleRetry(payload, attempt);
|
|
1845
2881
|
}
|
|
@@ -1854,7 +2890,10 @@ var WebhookService = class {
|
|
|
1854
2890
|
success: false,
|
|
1855
2891
|
error: err.message
|
|
1856
2892
|
});
|
|
1857
|
-
await this.persistDelivery(
|
|
2893
|
+
await this.persistDelivery(
|
|
2894
|
+
this.deliveryLog[this.deliveryLog.length - 1],
|
|
2895
|
+
payload
|
|
2896
|
+
);
|
|
1858
2897
|
if (attempt < this.config.maxRetries) {
|
|
1859
2898
|
await this.scheduleRetry(payload, attempt);
|
|
1860
2899
|
}
|
|
@@ -1872,7 +2911,9 @@ var WebhookService = class {
|
|
|
1872
2911
|
async scheduleRetry(payload, currentAttempt) {
|
|
1873
2912
|
const delay = this.config.retryDelays[currentAttempt - 1] || 18e5;
|
|
1874
2913
|
const retryId = `retry-${payload.event}-${currentAttempt}`;
|
|
1875
|
-
console.log(
|
|
2914
|
+
console.log(
|
|
2915
|
+
`[Webhook] Scheduling retry ${currentAttempt + 1} in ${delay}ms for ${payload.event}`
|
|
2916
|
+
);
|
|
1876
2917
|
const timer = setTimeout(() => {
|
|
1877
2918
|
this.deliver(payload, currentAttempt + 1);
|
|
1878
2919
|
this.pendingRetries.delete(retryId);
|
|
@@ -1887,7 +2928,9 @@ var WebhookService = class {
|
|
|
1887
2928
|
if (this.deliveryLog.length > 1e3) {
|
|
1888
2929
|
this.deliveryLog = this.deliveryLog.slice(-500);
|
|
1889
2930
|
}
|
|
1890
|
-
console.log(
|
|
2931
|
+
console.log(
|
|
2932
|
+
`[Webhook] ${entry.success ? "\u2705" : "\u274C"} ${entry.event} \u2192 ${entry.statusCode} (attempt ${entry.attemptNumber})`
|
|
2933
|
+
);
|
|
1891
2934
|
}
|
|
1892
2935
|
async persistDelivery(entry, payload) {
|
|
1893
2936
|
if (!entry || !this.config.onDelivery) return;
|
|
@@ -1972,7 +3015,9 @@ var EmailService = class {
|
|
|
1972
3015
|
return { success: false, error: err };
|
|
1973
3016
|
}
|
|
1974
3017
|
const result = await response.json();
|
|
1975
|
-
console.log(
|
|
3018
|
+
console.log(
|
|
3019
|
+
`[Email] \u2705 Sent ${template} to ${recipient.email} (${result.id})`
|
|
3020
|
+
);
|
|
1976
3021
|
return { success: true, messageId: result.id };
|
|
1977
3022
|
} catch (err) {
|
|
1978
3023
|
console.error(`[Email] Error sending ${template}:`, err.message);
|
|
@@ -2224,7 +3269,9 @@ var AggregatorService = class {
|
|
|
2224
3269
|
this.logs.set(entry.sessionId, existing);
|
|
2225
3270
|
const thresholdReached = existing.length >= this.settlementThreshold;
|
|
2226
3271
|
if (thresholdReached) {
|
|
2227
|
-
console.log(
|
|
3272
|
+
console.log(
|
|
3273
|
+
`[Aggregator] Threshold reached for session ${entry.sessionId} (${existing.length} entries)`
|
|
3274
|
+
);
|
|
2228
3275
|
}
|
|
2229
3276
|
return { totalEntries: existing.length, thresholdReached };
|
|
2230
3277
|
}
|
|
@@ -2235,12 +3282,12 @@ var AggregatorService = class {
|
|
|
2235
3282
|
buildMerkleTree(sessionId) {
|
|
2236
3283
|
const entries = this.logs.get(sessionId) || [];
|
|
2237
3284
|
if (entries.length === 0) return "0x" + "0".repeat(64);
|
|
2238
|
-
const leaves = entries.map(
|
|
2239
|
-
(entry) => this.hashEntry(entry)
|
|
2240
|
-
);
|
|
3285
|
+
const leaves = entries.map((entry) => this.hashEntry(entry));
|
|
2241
3286
|
const root = this.computeMerkleRoot(leaves);
|
|
2242
3287
|
this.merkleRoots.set(sessionId, root);
|
|
2243
|
-
console.log(
|
|
3288
|
+
console.log(
|
|
3289
|
+
`[Aggregator] Merkle root for ${sessionId}: ${root} (${entries.length} leaves)`
|
|
3290
|
+
);
|
|
2244
3291
|
return root;
|
|
2245
3292
|
}
|
|
2246
3293
|
/**
|
|
@@ -2271,7 +3318,9 @@ var AggregatorService = class {
|
|
|
2271
3318
|
entries.filter((e) => e.timestamp > windowEnd)
|
|
2272
3319
|
);
|
|
2273
3320
|
this.merkleRoots.delete(sessionId);
|
|
2274
|
-
console.log(
|
|
3321
|
+
console.log(
|
|
3322
|
+
`[Aggregator] Cleared entries for ${sessionId} before ${windowEnd}`
|
|
3323
|
+
);
|
|
2275
3324
|
}
|
|
2276
3325
|
/**
|
|
2277
3326
|
* Get aggregation stats for monitoring
|
|
@@ -2312,7 +3361,9 @@ var AggregatorService = class {
|
|
|
2312
3361
|
const nextLevel = [];
|
|
2313
3362
|
for (let i = 0; i < currentLevel.length; i += 2) {
|
|
2314
3363
|
const combined = currentLevel[i] + currentLevel[i + 1].slice(2);
|
|
2315
|
-
nextLevel.push(
|
|
3364
|
+
nextLevel.push(
|
|
3365
|
+
"0x" + createHash2("sha256").update(combined).digest("hex")
|
|
3366
|
+
);
|
|
2316
3367
|
}
|
|
2317
3368
|
currentLevel = nextLevel;
|
|
2318
3369
|
}
|
|
@@ -2367,7 +3418,11 @@ var RedisUsageStore = class {
|
|
|
2367
3418
|
await this.connect();
|
|
2368
3419
|
}
|
|
2369
3420
|
const upper = Math.max(0, limit - 1);
|
|
2370
|
-
const values = await this.client.lRange(
|
|
3421
|
+
const values = await this.client.lRange(
|
|
3422
|
+
sessionKey(this.config.keyPrefix, sessionId),
|
|
3423
|
+
0,
|
|
3424
|
+
upper
|
|
3425
|
+
);
|
|
2371
3426
|
return values.map((value) => {
|
|
2372
3427
|
try {
|
|
2373
3428
|
return JSON.parse(value);
|
|
@@ -2380,14 +3435,24 @@ var RedisUsageStore = class {
|
|
|
2380
3435
|
if (!this.connected) {
|
|
2381
3436
|
await this.connect();
|
|
2382
3437
|
}
|
|
2383
|
-
await this.client.hSet(
|
|
2384
|
-
|
|
3438
|
+
await this.client.hSet(
|
|
3439
|
+
settlementKey(this.config.keyPrefix),
|
|
3440
|
+
sessionId,
|
|
3441
|
+
txHash
|
|
3442
|
+
);
|
|
3443
|
+
await this.client.expire(
|
|
3444
|
+
settlementKey(this.config.keyPrefix),
|
|
3445
|
+
this.config.ttlSeconds
|
|
3446
|
+
);
|
|
2385
3447
|
}
|
|
2386
3448
|
async getLatestSettlementTx(sessionId) {
|
|
2387
3449
|
if (!this.connected) {
|
|
2388
3450
|
await this.connect();
|
|
2389
3451
|
}
|
|
2390
|
-
const txHash = await this.client.hGet(
|
|
3452
|
+
const txHash = await this.client.hGet(
|
|
3453
|
+
settlementKey(this.config.keyPrefix),
|
|
3454
|
+
sessionId
|
|
3455
|
+
);
|
|
2391
3456
|
return txHash ?? null;
|
|
2392
3457
|
}
|
|
2393
3458
|
async stop() {
|
|
@@ -2615,16 +3680,15 @@ var ProofOrchestrator = class {
|
|
|
2615
3680
|
|
|
2616
3681
|
// src/services/transport-axelar.ts
|
|
2617
3682
|
import {
|
|
2618
|
-
createPublicClient as
|
|
3683
|
+
createPublicClient as createPublicClient7,
|
|
2619
3684
|
createWalletClient as createWalletClient3,
|
|
2620
|
-
http as
|
|
3685
|
+
http as http7
|
|
2621
3686
|
} from "viem";
|
|
2622
3687
|
import { privateKeyToAccount as privateKeyToAccount3 } from "viem/accounts";
|
|
2623
|
-
import { sepolia as
|
|
2624
|
-
import { DEFAULT_CHAIN_ID as DEFAULT_CHAIN_ID5 } from "@arcenpay/sdk";
|
|
3688
|
+
import { sepolia as sepolia7, baseSepolia as baseSepolia7, base as base6 } from "viem/chains";
|
|
2625
3689
|
var CHAIN_MAP6 = {
|
|
2626
|
-
11155111:
|
|
2627
|
-
84532:
|
|
3690
|
+
11155111: sepolia7,
|
|
3691
|
+
84532: baseSepolia7,
|
|
2628
3692
|
8453: base6
|
|
2629
3693
|
};
|
|
2630
3694
|
var AXELAR_CHAIN_NAMES = {
|
|
@@ -2684,18 +3748,18 @@ var AxelarTransport = class {
|
|
|
2684
3748
|
signerAddress;
|
|
2685
3749
|
constructor(config) {
|
|
2686
3750
|
this.config = config;
|
|
2687
|
-
this.chainId = config.chainId ??
|
|
2688
|
-
const chain = CHAIN_MAP6[this.chainId] ||
|
|
3751
|
+
this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
|
|
3752
|
+
const chain = CHAIN_MAP6[this.chainId] || baseSepolia7;
|
|
2689
3753
|
const account = privateKeyToAccount3(config.privateKey);
|
|
2690
3754
|
this.signerAddress = account.address;
|
|
2691
|
-
this.publicClient =
|
|
3755
|
+
this.publicClient = createPublicClient7({
|
|
2692
3756
|
chain,
|
|
2693
|
-
transport:
|
|
3757
|
+
transport: http7(config.rpcUrl)
|
|
2694
3758
|
});
|
|
2695
3759
|
this.walletClient = createWalletClient3({
|
|
2696
3760
|
account,
|
|
2697
3761
|
chain,
|
|
2698
|
-
transport:
|
|
3762
|
+
transport: http7(config.rpcUrl)
|
|
2699
3763
|
});
|
|
2700
3764
|
}
|
|
2701
3765
|
/**
|
|
@@ -2782,13 +3846,12 @@ var AxelarTransport = class {
|
|
|
2782
3846
|
};
|
|
2783
3847
|
|
|
2784
3848
|
// src/services/transport-ccip.ts
|
|
2785
|
-
import { createPublicClient as
|
|
3849
|
+
import { createPublicClient as createPublicClient8, createWalletClient as createWalletClient4, http as http8 } from "viem";
|
|
2786
3850
|
import { privateKeyToAccount as privateKeyToAccount4 } from "viem/accounts";
|
|
2787
|
-
import { sepolia as
|
|
2788
|
-
import { DEFAULT_CHAIN_ID as DEFAULT_CHAIN_ID6 } from "@arcenpay/sdk";
|
|
3851
|
+
import { sepolia as sepolia8, baseSepolia as baseSepolia8, base as base7 } from "viem/chains";
|
|
2789
3852
|
var CHAIN_MAP7 = {
|
|
2790
|
-
11155111:
|
|
2791
|
-
84532:
|
|
3853
|
+
11155111: sepolia8,
|
|
3854
|
+
84532: baseSepolia8,
|
|
2792
3855
|
8453: base7
|
|
2793
3856
|
};
|
|
2794
3857
|
var CCIP_CHAIN_SELECTORS = {
|
|
@@ -2874,19 +3937,19 @@ var CCIPTransport = class {
|
|
|
2874
3937
|
gasLimit;
|
|
2875
3938
|
constructor(config) {
|
|
2876
3939
|
this.config = config;
|
|
2877
|
-
this.chainId = config.chainId ??
|
|
3940
|
+
this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
|
|
2878
3941
|
this.gasLimit = config.gasLimit || 200000n;
|
|
2879
|
-
const chain = CHAIN_MAP7[this.chainId] ||
|
|
3942
|
+
const chain = CHAIN_MAP7[this.chainId] || baseSepolia8;
|
|
2880
3943
|
const account = privateKeyToAccount4(config.privateKey);
|
|
2881
3944
|
this.signerAddress = account.address;
|
|
2882
|
-
this.publicClient =
|
|
3945
|
+
this.publicClient = createPublicClient8({
|
|
2883
3946
|
chain,
|
|
2884
|
-
transport:
|
|
3947
|
+
transport: http8(config.rpcUrl)
|
|
2885
3948
|
});
|
|
2886
3949
|
this.walletClient = createWalletClient4({
|
|
2887
3950
|
account,
|
|
2888
3951
|
chain,
|
|
2889
|
-
transport:
|
|
3952
|
+
transport: http8(config.rpcUrl)
|
|
2890
3953
|
});
|
|
2891
3954
|
}
|
|
2892
3955
|
/**
|
|
@@ -2958,7 +4021,10 @@ var CCIPTransport = class {
|
|
|
2958
4021
|
address: this.config.routerAddress,
|
|
2959
4022
|
abi: CCIP_ROUTER_ABI,
|
|
2960
4023
|
functionName: "getFee",
|
|
2961
|
-
args: [
|
|
4024
|
+
args: [
|
|
4025
|
+
destSelector,
|
|
4026
|
+
this.buildMessage(payload, destinationAddressOverride)
|
|
4027
|
+
]
|
|
2962
4028
|
});
|
|
2963
4029
|
} catch {
|
|
2964
4030
|
return 5000000000000000n;
|
|
@@ -2973,18 +4039,12 @@ var CCIPTransport = class {
|
|
|
2973
4039
|
};
|
|
2974
4040
|
|
|
2975
4041
|
// src/services/keeper.ts
|
|
2976
|
-
import { createPublicClient as
|
|
4042
|
+
import { createPublicClient as createPublicClient9, createWalletClient as createWalletClient5, http as http9 } from "viem";
|
|
2977
4043
|
import { privateKeyToAccount as privateKeyToAccount5 } from "viem/accounts";
|
|
2978
|
-
import { sepolia as
|
|
2979
|
-
import {
|
|
2980
|
-
DEFAULT_CHAIN_ID as DEFAULT_CHAIN_ID7,
|
|
2981
|
-
SubscriptionRegistryABI,
|
|
2982
|
-
ERC7579AutopayModuleABI,
|
|
2983
|
-
getContractAddresses as getContractAddresses5
|
|
2984
|
-
} from "@arcenpay/sdk";
|
|
4044
|
+
import { sepolia as sepolia9, baseSepolia as baseSepolia9, base as base8 } from "viem/chains";
|
|
2985
4045
|
var CHAIN_MAP8 = {
|
|
2986
|
-
11155111:
|
|
2987
|
-
84532:
|
|
4046
|
+
11155111: sepolia9,
|
|
4047
|
+
84532: baseSepolia9,
|
|
2988
4048
|
8453: base8
|
|
2989
4049
|
};
|
|
2990
4050
|
var BillingKeeper = class {
|
|
@@ -3002,9 +4062,9 @@ var BillingKeeper = class {
|
|
|
3002
4062
|
renewalLog = [];
|
|
3003
4063
|
callbacks = [];
|
|
3004
4064
|
constructor(config) {
|
|
3005
|
-
this.chainId = config.chainId ??
|
|
3006
|
-
const chain = CHAIN_MAP8[this.chainId] ||
|
|
3007
|
-
const contracts =
|
|
4065
|
+
this.chainId = config.chainId ?? DEFAULT_CHAIN_ID;
|
|
4066
|
+
const chain = CHAIN_MAP8[this.chainId] || baseSepolia9;
|
|
4067
|
+
const contracts = getContractAddresses(this.chainId);
|
|
3008
4068
|
this.registryAddress = contracts.subscriptionRegistry;
|
|
3009
4069
|
this.autopayModuleAddress = contracts.autopayModule;
|
|
3010
4070
|
this.intervalMs = config.intervalMs || 6e4;
|
|
@@ -3012,14 +4072,14 @@ var BillingKeeper = class {
|
|
|
3012
4072
|
this.renewalBufferSeconds = config.renewalBufferSeconds || 86400;
|
|
3013
4073
|
const account = privateKeyToAccount5(config.privateKey);
|
|
3014
4074
|
this.signerAddress = account.address;
|
|
3015
|
-
this.publicClient =
|
|
4075
|
+
this.publicClient = createPublicClient9({
|
|
3016
4076
|
chain,
|
|
3017
|
-
transport:
|
|
4077
|
+
transport: http9(config.rpcUrl)
|
|
3018
4078
|
});
|
|
3019
4079
|
this.walletClient = createWalletClient5({
|
|
3020
4080
|
account,
|
|
3021
4081
|
chain,
|
|
3022
|
-
transport:
|
|
4082
|
+
transport: http9(config.rpcUrl)
|
|
3023
4083
|
});
|
|
3024
4084
|
}
|
|
3025
4085
|
/**
|
|
@@ -3139,7 +4199,10 @@ var BillingKeeper = class {
|
|
|
3139
4199
|
}
|
|
3140
4200
|
return tokenIds;
|
|
3141
4201
|
} catch (err) {
|
|
3142
|
-
console.error(
|
|
4202
|
+
console.error(
|
|
4203
|
+
"[BillingKeeper] Error finding expiring subscriptions:",
|
|
4204
|
+
err
|
|
4205
|
+
);
|
|
3143
4206
|
return [];
|
|
3144
4207
|
}
|
|
3145
4208
|
}
|
|
@@ -3167,7 +4230,9 @@ var BillingKeeper = class {
|
|
|
3167
4230
|
functionName: "getConfig",
|
|
3168
4231
|
args: [subscriber]
|
|
3169
4232
|
});
|
|
3170
|
-
const merchant = String(
|
|
4233
|
+
const merchant = String(
|
|
4234
|
+
config?.merchant ?? config?.[0] ?? ""
|
|
4235
|
+
).toLowerCase();
|
|
3171
4236
|
const amount = BigInt(config?.maxAmount ?? config?.[1] ?? 0);
|
|
3172
4237
|
if (amount <= 0n) {
|
|
3173
4238
|
console.log(
|