@aastar/sdk 0.18.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +180 -21
  2. package/dist/UserClient-YUHCJJJL.js +6 -0
  3. package/dist/UserClient-YUHCJJJL.js.map +1 -0
  4. package/dist/account.d.ts +1 -0
  5. package/dist/account.js +6 -0
  6. package/dist/account.js.map +1 -0
  7. package/dist/admin.d.ts +1 -0
  8. package/dist/admin.js +6 -0
  9. package/dist/admin.js.map +1 -0
  10. package/dist/airaccount.d.ts +2 -0
  11. package/dist/airaccount.js +4501 -0
  12. package/dist/airaccount.js.map +1 -0
  13. package/dist/channel.d.ts +1 -0
  14. package/dist/channel.js +6 -0
  15. package/dist/channel.js.map +1 -0
  16. package/dist/chunk-4DVUM4MC.js +106 -0
  17. package/dist/chunk-4DVUM4MC.js.map +1 -0
  18. package/dist/chunk-4KRQXOTI.js +4421 -0
  19. package/dist/chunk-4KRQXOTI.js.map +1 -0
  20. package/dist/chunk-6JCYPTSH.js +281 -0
  21. package/dist/chunk-6JCYPTSH.js.map +1 -0
  22. package/dist/chunk-DI3E6PMI.js +426 -0
  23. package/dist/chunk-DI3E6PMI.js.map +1 -0
  24. package/dist/chunk-DSZ372PH.js +333 -0
  25. package/dist/chunk-DSZ372PH.js.map +1 -0
  26. package/dist/chunk-HVAB4TTT.js +116 -0
  27. package/dist/chunk-HVAB4TTT.js.map +1 -0
  28. package/dist/chunk-MPOMWT2J.js +1140 -0
  29. package/dist/chunk-MPOMWT2J.js.map +1 -0
  30. package/dist/chunk-NZGXB2C5.js +115 -0
  31. package/dist/chunk-NZGXB2C5.js.map +1 -0
  32. package/dist/chunk-O3Y7II3B.js +578 -0
  33. package/dist/chunk-O3Y7II3B.js.map +1 -0
  34. package/dist/chunk-OSPRJZ5T.js +113 -0
  35. package/dist/chunk-OSPRJZ5T.js.map +1 -0
  36. package/dist/chunk-PCLPYRTX.js +229 -0
  37. package/dist/chunk-PCLPYRTX.js.map +1 -0
  38. package/dist/chunk-PZ5AY32C.js +9 -0
  39. package/dist/chunk-PZ5AY32C.js.map +1 -0
  40. package/dist/chunk-XFI3AK32.js +416 -0
  41. package/dist/chunk-XFI3AK32.js.map +1 -0
  42. package/dist/chunk-YHM77LIP.js +432 -0
  43. package/dist/chunk-YHM77LIP.js.map +1 -0
  44. package/dist/chunk-ZSSNU3UF.js +42091 -0
  45. package/dist/chunk-ZSSNU3UF.js.map +1 -0
  46. package/dist/contract-addresses-JE3X6DFY.js +4 -0
  47. package/dist/contract-addresses-JE3X6DFY.js.map +1 -0
  48. package/dist/core.d.ts +13 -0
  49. package/dist/core.js +5 -0
  50. package/dist/core.js.map +1 -0
  51. package/dist/dapp.d.ts +1 -0
  52. package/dist/dapp.js +7 -0
  53. package/dist/dapp.js.map +1 -0
  54. package/dist/dist-GHTBO7CD.js +6 -0
  55. package/dist/dist-GHTBO7CD.js.map +1 -0
  56. package/dist/enduser.d.ts +1 -0
  57. package/dist/enduser.js +7 -0
  58. package/dist/enduser.js.map +1 -0
  59. package/dist/identity.d.ts +1 -0
  60. package/dist/identity.js +6 -0
  61. package/dist/identity.js.map +1 -0
  62. package/dist/index.d.ts +601 -12
  63. package/dist/index.js +1640 -28
  64. package/dist/index.js.map +1 -0
  65. package/dist/index.node-55LOPHNQ.js +5 -0
  66. package/dist/index.node-55LOPHNQ.js.map +1 -0
  67. package/dist/lib-VRTYVDUO.js +1861 -0
  68. package/dist/lib-VRTYVDUO.js.map +1 -0
  69. package/dist/operator.d.ts +1 -0
  70. package/dist/operator.js +6 -0
  71. package/dist/operator.js.map +1 -0
  72. package/dist/paymaster.d.ts +1 -0
  73. package/dist/paymaster.js +6 -0
  74. package/dist/paymaster.js.map +1 -0
  75. package/dist/tokens.d.ts +1 -0
  76. package/dist/tokens.js +6 -0
  77. package/dist/tokens.js.map +1 -0
  78. package/dist/x402.d.ts +1 -0
  79. package/dist/x402.js +6 -0
  80. package/dist/x402.js.map +1 -0
  81. package/package.json +87 -18
  82. package/dist/clients/ExperimentClient.d.ts +0 -34
  83. package/dist/clients/ExperimentClient.js +0 -58
  84. package/dist/clients/admin.d.ts +0 -11
  85. package/dist/clients/admin.js +0 -20
  86. package/dist/clients/community.d.ts +0 -40
  87. package/dist/clients/community.js +0 -300
  88. package/dist/clients/endUser.d.ts +0 -77
  89. package/dist/clients/endUser.js +0 -298
  90. package/dist/clients/operator.d.ts +0 -66
  91. package/dist/clients/operator.js +0 -209
  92. package/dist/errors/decoder.d.ts +0 -6
  93. package/dist/errors/decoder.js +0 -44
  94. package/dist/utils/errorHandler.d.ts +0 -40
  95. package/dist/utils/errorHandler.js +0 -114
  96. package/dist/utils/funding.d.ts +0 -115
  97. package/dist/utils/funding.js +0 -188
  98. package/dist/utils/keys.d.ts +0 -61
  99. package/dist/utils/keys.js +0 -130
  100. package/dist/utils/roleData.d.ts +0 -66
  101. package/dist/utils/roleData.js +0 -128
  102. package/dist/utils/testScenarios.d.ts +0 -33
  103. package/dist/utils/testScenarios.js +0 -85
  104. package/dist/utils/userOp.d.ts +0 -89
  105. package/dist/utils/userOp.js +0 -231
@@ -0,0 +1,578 @@
1
+ import { BaseClient, registryActions, tokenActions, paymasterFactoryActions, PaymasterABI, superPaymasterActions, paymasterActions, dvtActions, aggregatorActions } from './chunk-ZSSNU3UF.js';
2
+ import { parseEther } from 'viem';
3
+
4
+ var PaymasterOperatorClient = class extends BaseClient {
5
+ superPaymasterAddress;
6
+ tokenAddress;
7
+ ethUsdPriceFeed;
8
+ xpntsFactory;
9
+ constructor(config) {
10
+ super(config);
11
+ this.superPaymasterAddress = config.superPaymasterAddress;
12
+ this.tokenAddress = config.tokenAddress;
13
+ this.ethUsdPriceFeed = config.ethUsdPriceFeedAddress || "0x694AA1769357215DE4FAC081bf1f309aDC325306";
14
+ this.xpntsFactory = config.xpntsFactoryAddress || "0x0000000000000000000000000000000000000000";
15
+ }
16
+ // ========================================
17
+ // 0. 注册与入驻 (One-Stop Registration)
18
+ // ========================================
19
+ /**
20
+ * Register as SuperPaymaster Operator (one-stop API).
21
+ * This method handles all necessary steps:
22
+ * 1. Checks prerequisites (must have ROLE_COMMUNITY)
23
+ * 2. Checks and approves GToken to GTokenStaking
24
+ * 3. Registers ROLE_PAYMASTER_SUPER
25
+ * 4. Optionally deposits collateral to SuperPaymaster
26
+ *
27
+ * @param params Registration parameters
28
+ * @param options Transaction options
29
+ * @returns Transaction hash of role registration
30
+ */
31
+ async registerAsSuperPaymasterOperator(params, options) {
32
+ try {
33
+ const registryAddr = this.requireRegistry();
34
+ const gTokenAddr = this.requireGToken();
35
+ const gTokenStakingAddr = this.requireGTokenStaking();
36
+ const registry = registryActions(registryAddr);
37
+ const gToken = tokenActions();
38
+ const publicClient = this.getStartPublicClient();
39
+ const ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();
40
+ const hasCommunity = await registry(publicClient).hasRole({
41
+ user: this.getAddress(),
42
+ roleId: ROLE_COMMUNITY
43
+ });
44
+ if (!hasCommunity) {
45
+ throw new Error("Must have ROLE_COMMUNITY before registering as SuperPaymaster operator");
46
+ }
47
+ const ROLE_PAYMASTER_SUPER = await registry(publicClient).ROLE_PAYMASTER_SUPER();
48
+ const hasSuper = await registry(publicClient).hasRole({
49
+ user: this.getAddress(),
50
+ roleId: ROLE_PAYMASTER_SUPER
51
+ });
52
+ if (hasSuper) {
53
+ if (params?.depositAmount) {
54
+ return this.depositCollateral(params.depositAmount, options);
55
+ }
56
+ throw new Error("Already registered as SuperPaymaster operator");
57
+ }
58
+ const stakeAmount = params?.stakeAmount || parseEther("50");
59
+ const allowance = await gToken(publicClient).allowance({
60
+ token: gTokenAddr,
61
+ owner: this.getAddress(),
62
+ spender: gTokenStakingAddr
63
+ });
64
+ if (allowance < stakeAmount) {
65
+ const approveHash = await gToken(this.client).approve({
66
+ token: gTokenAddr,
67
+ spender: gTokenStakingAddr,
68
+ amount: stakeAmount * 2n,
69
+ // Approve 2x for future use
70
+ account: options?.account
71
+ });
72
+ await publicClient.waitForTransactionReceipt({ hash: approveHash });
73
+ }
74
+ const registerHash = await registry(this.client).registerRoleSelf({
75
+ roleId: ROLE_PAYMASTER_SUPER,
76
+ data: "0x",
77
+ // SuperPaymaster role doesn't need special data
78
+ account: options?.account
79
+ });
80
+ await publicClient.waitForTransactionReceipt({ hash: registerHash });
81
+ if (params?.depositAmount) {
82
+ await this.depositCollateral(params.depositAmount, options);
83
+ }
84
+ return registerHash;
85
+ } catch (error) {
86
+ throw error;
87
+ }
88
+ }
89
+ /**
90
+ * Deploy a new Paymaster V4 and Register as AOA Operator (one-stop API).
91
+ * This method handles:
92
+ * 1. Checks prerequisites (ROLE_COMMUNITY)
93
+ * 2. Predicts new Paymaster address
94
+ * 3. Deploys Paymaster V4 via Factory
95
+ * 4. Registers ROLE_PAYMASTER_AOA with staking
96
+ *
97
+ * @param params Deployment parameters
98
+ * @param options Transaction options
99
+ * @returns Object containing new paymaster address and transaction hashes
100
+ */
101
+ async deployAndRegisterPaymasterV4(params, options) {
102
+ try {
103
+ const registryAddr = this.requireRegistry();
104
+ const gTokenAddr = this.requireGToken();
105
+ const gTokenStakingAddr = this.requireGTokenStaking();
106
+ const factoryAddr = this.requirePaymasterFactory();
107
+ const registry = registryActions(registryAddr);
108
+ const gToken = tokenActions();
109
+ const factory = paymasterFactoryActions(factoryAddr);
110
+ const publicClient = this.getStartPublicClient();
111
+ const account = options?.account || this.client.account || this.getAddress();
112
+ const accountAddr = typeof account === "string" ? account : account.address;
113
+ const ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();
114
+ const hasCommunity = await registry(publicClient).hasRole({
115
+ user: accountAddr,
116
+ roleId: ROLE_COMMUNITY
117
+ });
118
+ if (!hasCommunity) {
119
+ throw new Error("Must have ROLE_COMMUNITY before deploying Paymaster V4");
120
+ }
121
+ const existingPaymaster = await factory(publicClient).getPaymaster({ owner: accountAddr });
122
+ let deployHash = "0x0000000000000000000000000000000000000000000000000000000000000000";
123
+ let paymasterAddress;
124
+ if (existingPaymaster && existingPaymaster !== "0x0000000000000000000000000000000000000000") {
125
+ console.log(` \u2139\uFE0F Paymaster already deployed at: ${existingPaymaster}`);
126
+ paymasterAddress = existingPaymaster;
127
+ } else {
128
+ console.log(" \u{1F6E0}\uFE0F Deploying Paymaster V4 with args:", {
129
+ entryPoint: this.requireEntryPoint(),
130
+ owner: accountAddr,
131
+ priceFeed: this.ethUsdPriceFeed,
132
+ factory: factoryAddr
133
+ });
134
+ const { encodeFunctionData } = await import('viem');
135
+ const initData = encodeFunctionData({
136
+ abi: PaymasterABI,
137
+ functionName: "initialize",
138
+ args: [
139
+ this.requireEntryPoint(),
140
+ // EntryPoint v0.7
141
+ accountAddr,
142
+ accountAddr,
143
+ // Treasury defaults to owner
144
+ this.ethUsdPriceFeed,
145
+ 200n,
146
+ // serviceFeeRate (2%)
147
+ parseEther("0.1"),
148
+ // maxGasCostCap
149
+ 3600n
150
+ // priceStalenessThreshold (1 hour)
151
+ ]
152
+ });
153
+ deployHash = await factory(this.client).deployPaymaster({
154
+ version: params?.version,
155
+ initData,
156
+ account
157
+ });
158
+ await publicClient.waitForTransactionReceipt({ hash: deployHash });
159
+ paymasterAddress = await factory(publicClient).getPaymaster({ owner: accountAddr });
160
+ }
161
+ if (!paymasterAddress || paymasterAddress === "0x0000000000000000000000000000000000000000") {
162
+ throw new Error("Failed to retrieve Paymaster address from Factory");
163
+ }
164
+ const ROLE_PAYMASTER_AOA = await registry(publicClient).ROLE_PAYMASTER_AOA();
165
+ const hasAOA = await registry(publicClient).hasRole({
166
+ user: accountAddr,
167
+ roleId: ROLE_PAYMASTER_AOA
168
+ });
169
+ if (hasAOA) {
170
+ return { paymasterAddress, deployHash, registerHash: "0x0000000000000000000000000000000000000000000000000000000000000000" };
171
+ }
172
+ const stakeAmount = params?.stakeAmount || parseEther("30");
173
+ const allowance = await gToken(publicClient).allowance({
174
+ token: gTokenAddr,
175
+ owner: accountAddr,
176
+ spender: gTokenStakingAddr
177
+ });
178
+ if (allowance < stakeAmount) {
179
+ const approveHash = await gToken(this.client).approve({
180
+ token: gTokenAddr,
181
+ spender: gTokenStakingAddr,
182
+ amount: stakeAmount * 2n,
183
+ account
184
+ });
185
+ await publicClient.waitForTransactionReceipt({ hash: approveHash });
186
+ }
187
+ const { encodeAbiParameters, parseAbiParameters } = await import('viem');
188
+ let roleData = "0x";
189
+ if (stakeAmount > 0) {
190
+ roleData = encodeAbiParameters(parseAbiParameters("uint256"), [stakeAmount]);
191
+ }
192
+ const registerHash = await registry(this.client).registerRoleSelf({
193
+ roleId: ROLE_PAYMASTER_AOA,
194
+ data: roleData,
195
+ account
196
+ });
197
+ await publicClient.waitForTransactionReceipt({ hash: registerHash });
198
+ return {
199
+ paymasterAddress,
200
+ deployHash,
201
+ registerHash
202
+ };
203
+ } catch (error) {
204
+ throw error;
205
+ }
206
+ }
207
+ /**
208
+ * Deposit collateral (aPNTs/GToken) to SuperPaymaster.
209
+ * This is a helper method used by registerAsSuperPaymasterOperator.
210
+ */
211
+ async depositCollateral(amount, options) {
212
+ try {
213
+ const pm = superPaymasterActions(this.superPaymasterAddress);
214
+ const publicClient = this.getStartPublicClient();
215
+ const depositToken = await pm(publicClient).APNTS_TOKEN();
216
+ const token = tokenActions();
217
+ const allowance = await token(publicClient).allowance({
218
+ token: depositToken,
219
+ owner: this.getAddress(),
220
+ spender: this.superPaymasterAddress
221
+ });
222
+ if (allowance < amount) {
223
+ const approveHash = await token(this.client).approve({
224
+ token: depositToken,
225
+ spender: this.superPaymasterAddress,
226
+ amount,
227
+ account: options?.account
228
+ });
229
+ await publicClient.waitForTransactionReceipt({ hash: approveHash });
230
+ }
231
+ return pm(this.client).deposit({
232
+ amount,
233
+ account: options?.account
234
+ });
235
+ } catch (error) {
236
+ throw error;
237
+ }
238
+ }
239
+ /**
240
+ * Configure operator parameters (Token, Treasury).
241
+ * Exchange rate is now read live from xPNTsToken.exchangeRate() at runtime.
242
+ * If parameters are undefined, existing values are preserved.
243
+ */
244
+ async configureOperator(xPNTsToken, treasury, options) {
245
+ try {
246
+ const sp = superPaymasterActions(this.superPaymasterAddress);
247
+ const publicClient = this.getStartPublicClient();
248
+ const currentConfig = await sp(publicClient).operators({ operator: this.getAddress() });
249
+ const currentToken = currentConfig.xPNTsToken;
250
+ const currentTreasury = currentConfig.treasury;
251
+ return await sp(this.client).configureOperator({
252
+ xPNTsToken: xPNTsToken || currentToken,
253
+ opTreasury: treasury || currentTreasury,
254
+ account: options?.account
255
+ });
256
+ } catch (error) {
257
+ throw error;
258
+ }
259
+ }
260
+ async withdrawCollateral(to, amount, options) {
261
+ try {
262
+ const sp = superPaymasterActions(this.superPaymasterAddress);
263
+ return await sp(this.client).withdrawTo({
264
+ to,
265
+ amount,
266
+ account: options?.account
267
+ });
268
+ } catch (error) {
269
+ throw error;
270
+ }
271
+ }
272
+ async isOperator(operator) {
273
+ try {
274
+ const sp = superPaymasterActions(this.superPaymasterAddress);
275
+ const config = await sp(this.getStartPublicClient()).operators({ operator });
276
+ return config.isConfigured;
277
+ } catch (error) {
278
+ return false;
279
+ }
280
+ }
281
+ async getOperatorDetails(operator) {
282
+ try {
283
+ const target = operator || this.getAddress();
284
+ const sp = superPaymasterActions(this.superPaymasterAddress);
285
+ return await sp(this.getStartPublicClient()).operators({ operator: target });
286
+ } catch (error) {
287
+ throw error;
288
+ }
289
+ }
290
+ async initiateExit(options) {
291
+ try {
292
+ const sp = superPaymasterActions(this.superPaymasterAddress);
293
+ return await sp(this.client).unlockStake({
294
+ account: options?.account
295
+ });
296
+ } catch (error) {
297
+ throw error;
298
+ }
299
+ }
300
+ async withdrawStake(to, options) {
301
+ try {
302
+ const sp = superPaymasterActions(this.superPaymasterAddress);
303
+ return await sp(this.client).withdrawStake({
304
+ to,
305
+ account: options?.account
306
+ });
307
+ } catch (error) {
308
+ throw error;
309
+ }
310
+ }
311
+ // ========================================
312
+ // 3. 支付代币管理 (基于 PaymasterActions)
313
+ // ========================================
314
+ async addGasToken(token, price, options) {
315
+ try {
316
+ const pm = paymasterActions(this.superPaymasterAddress);
317
+ return await pm(this.client).setTokenPrice({
318
+ token,
319
+ price,
320
+ account: options?.account
321
+ });
322
+ } catch (error) {
323
+ throw error;
324
+ }
325
+ }
326
+ async getTokenPrice(token) {
327
+ try {
328
+ const pm = paymasterActions(this.superPaymasterAddress);
329
+ return await pm(this.getStartPublicClient()).tokenPrices({ token });
330
+ } catch (error) {
331
+ throw error;
332
+ }
333
+ }
334
+ async setupPaymasterDeposit(params, options) {
335
+ try {
336
+ const pm = paymasterActions(params.paymaster);
337
+ return await pm(this.client).depositFor({
338
+ user: params.user,
339
+ token: params.token,
340
+ amount: params.amount,
341
+ account: options?.account
342
+ });
343
+ } catch (error) {
344
+ throw error;
345
+ }
346
+ }
347
+ };
348
+
349
+ // ../operator/dist/ProtocolClient.js
350
+ var ProposalState;
351
+ (function(ProposalState2) {
352
+ ProposalState2[ProposalState2["Pending"] = 0] = "Pending";
353
+ ProposalState2[ProposalState2["Active"] = 1] = "Active";
354
+ ProposalState2[ProposalState2["Canceled"] = 2] = "Canceled";
355
+ ProposalState2[ProposalState2["Defeated"] = 3] = "Defeated";
356
+ ProposalState2[ProposalState2["Succeeded"] = 4] = "Succeeded";
357
+ ProposalState2[ProposalState2["Queued"] = 5] = "Queued";
358
+ ProposalState2[ProposalState2["Expired"] = 6] = "Expired";
359
+ ProposalState2[ProposalState2["Executed"] = 7] = "Executed";
360
+ })(ProposalState || (ProposalState = {}));
361
+ var ProtocolClient = class extends BaseClient {
362
+ dvtValidatorAddress;
363
+ blsAggregatorAddress;
364
+ superPaymasterAddress;
365
+ constructor(config) {
366
+ super(config);
367
+ this.dvtValidatorAddress = config.dvtValidatorAddress;
368
+ this.blsAggregatorAddress = config.blsAggregatorAddress;
369
+ this.superPaymasterAddress = config.superPaymasterAddress;
370
+ }
371
+ // ========================================
372
+ // 1. 提案管理 (DVT)
373
+ // ========================================
374
+ /**
375
+ * Create a new proposal
376
+ */
377
+ async createProposal(target, calldata, description, options) {
378
+ try {
379
+ const dvt = dvtActions(this.dvtValidatorAddress)(this.client);
380
+ return await dvt.createSlashProposal({
381
+ operator: target,
382
+ level: 1,
383
+ // Default level
384
+ reason: description,
385
+ account: options?.account
386
+ });
387
+ } catch (error) {
388
+ throw error;
389
+ }
390
+ }
391
+ async signProposal(proposalId, signature = "0x", options) {
392
+ try {
393
+ const dvt = dvtActions(this.dvtValidatorAddress)(this.client);
394
+ return await dvt.signSlashProposal({
395
+ proposalId,
396
+ signature,
397
+ account: options?.account
398
+ });
399
+ } catch (error) {
400
+ throw error;
401
+ }
402
+ }
403
+ /**
404
+ * Execute a proposal with collected signatures
405
+ */
406
+ async executeWithProof(proposalId, signatures, options) {
407
+ try {
408
+ const proof = "0x";
409
+ const dvt = dvtActions(this.dvtValidatorAddress)(this.client);
410
+ return await dvt.executeSlashWithProof({
411
+ proposalId,
412
+ repUsers: [],
413
+ // Needs real data in production
414
+ newScores: [],
415
+ epoch: 0n,
416
+ proof,
417
+ account: options?.account
418
+ });
419
+ } catch (error) {
420
+ throw error;
421
+ }
422
+ }
423
+ // ========================================
424
+ // 2. 验证器管理 / BLS
425
+ // ========================================
426
+ async registerBLSKey(publicKey, options) {
427
+ try {
428
+ if (!this.blsAggregatorAddress) {
429
+ throw new Error("BLS Aggregator address required for this client");
430
+ }
431
+ const agg = aggregatorActions(this.blsAggregatorAddress)(this.client);
432
+ return await agg.registerBLSPublicKey({
433
+ validator: this.getAddress(),
434
+ publicKey,
435
+ account: options?.account
436
+ });
437
+ } catch (error) {
438
+ throw error;
439
+ }
440
+ }
441
+ // ========================================
442
+ // 3. 全局参数管理 (Admin)
443
+ // ========================================
444
+ async setProtocolFee(bps, options) {
445
+ try {
446
+ if (!this.superPaymasterAddress) {
447
+ throw new Error("SuperPaymaster address required for this client");
448
+ }
449
+ const sp = superPaymasterActions(this.superPaymasterAddress);
450
+ return await sp(this.client).setProtocolFee({
451
+ newFeeBPS: bps,
452
+ account: options?.account
453
+ });
454
+ } catch (error) {
455
+ throw error;
456
+ }
457
+ }
458
+ async setTreasury(treasury, options) {
459
+ try {
460
+ if (!this.superPaymasterAddress) {
461
+ throw new Error("SuperPaymaster address required for this client");
462
+ }
463
+ const sp = superPaymasterActions(this.superPaymasterAddress);
464
+ return await sp(this.client).setTreasury({
465
+ treasury,
466
+ account: options?.account
467
+ });
468
+ } catch (error) {
469
+ throw error;
470
+ }
471
+ }
472
+ };
473
+
474
+ // ../operator/dist/OperatorLifecycle.js
475
+ var OperatorLifecycle = class extends PaymasterOperatorClient {
476
+ constructor(config) {
477
+ super(config);
478
+ }
479
+ // ===========================================
480
+ // 1. Setup Phase (Onboarding)
481
+ // ===========================================
482
+ /**
483
+ * Check if the account is ready to become an operator
484
+ * (e.g., has GToken, has ROLE_COMMUNITY, etc.)
485
+ */
486
+ async checkReadiness() {
487
+ const isOp = await this.isOperator(this.getAddress());
488
+ const details = await this.getOperatorDetails();
489
+ const balance = details.aPNTsBalance || 0n;
490
+ return {
491
+ isConfigured: isOp,
492
+ isActive: isOp,
493
+ // Simplification
494
+ balance
495
+ };
496
+ }
497
+ /**
498
+ * One-click Setup: Register + Deposit + Deploy Node
499
+ * Wraps existing registerAsSuperPaymasterOperator or deployAndRegisterPaymasterV4
500
+ */
501
+ async setupNode(params, options) {
502
+ const hashes = [];
503
+ if (params.type === "SUPER") {
504
+ const h = await this.registerAsSuperPaymasterOperator({
505
+ stakeAmount: params.stakeAmount,
506
+ depositAmount: params.depositAmount
507
+ }, options);
508
+ hashes.push(h);
509
+ const factory = await import('./index.node-55LOPHNQ.js').then((m) => m.xPNTsFactoryActions(this.xpntsFactory)(this.getStartPublicClient()));
510
+ const token = await factory.getTokenAddress({ community: this.getAddress() });
511
+ if (token && token !== "0x0000000000000000000000000000000000000000") {
512
+ const hConfig = await this.configureOperator(
513
+ token,
514
+ this.getAddress(),
515
+ // Default treasury to self
516
+ options
517
+ );
518
+ hashes.push(hConfig);
519
+ }
520
+ } else {
521
+ const result = await this.deployAndRegisterPaymasterV4({
522
+ stakeAmount: params.stakeAmount
523
+ }, options);
524
+ hashes.push(result.deployHash);
525
+ hashes.push(result.registerHash);
526
+ }
527
+ return hashes;
528
+ }
529
+ // ===========================================
530
+ // 2. Operational Phase (Config & Funds)
531
+ // ===========================================
532
+ // Inherits: addGasToken, configureOperator, depositCollateral from PaymasterOperatorClient
533
+ async getOperatorStats() {
534
+ return await this.getOperatorDetails();
535
+ }
536
+ // ===========================================
537
+ // 3. Exit Phase (Withdraw & Leave)
538
+ // ===========================================
539
+ /**
540
+ * Start the exit process: Unstake from Registry/SuperPaymaster and Unlock funds
541
+ */
542
+ async initiateExit(options) {
543
+ return await super.initiateExit(options);
544
+ }
545
+ /**
546
+ * Finalize exit: Withdraw all funds (Collateral + Rewards)
547
+ */
548
+ async withdrawAllFunds(to, options) {
549
+ const recipient = to || this.getAddress();
550
+ const hashes = [];
551
+ const stats = await this.checkReadiness();
552
+ if (stats.balance > 0n) {
553
+ const hCol = await this.withdrawCollateral(recipient, stats.balance, options);
554
+ hashes.push(hCol);
555
+ }
556
+ const client = this.getStartPublicClient();
557
+ const registry = registryActions(this.registryAddress);
558
+ const registryWriter = registryActions(this.registryAddress)(this.client);
559
+ const ROLE_PAYMASTER_SUPER = await registry(client).ROLE_PAYMASTER_SUPER();
560
+ const hasRole = await registry(client).hasRole({ user: this.getAddress(), roleId: ROLE_PAYMASTER_SUPER });
561
+ if (hasRole) {
562
+ const hExit = await registryWriter.exitRole({ roleId: ROLE_PAYMASTER_SUPER, account: options?.account });
563
+ hashes.push(hExit);
564
+ }
565
+ return hashes;
566
+ }
567
+ // Helper: Get GToken Balance
568
+ async getTokenBalance() {
569
+ if (!this.tokenAddress)
570
+ return 0n;
571
+ const token = tokenActions()(this.getStartPublicClient());
572
+ return await token.balanceOf({ token: this.tokenAddress, account: this.getAddress() });
573
+ }
574
+ };
575
+
576
+ export { OperatorLifecycle, PaymasterOperatorClient, ProposalState, ProtocolClient };
577
+ //# sourceMappingURL=chunk-O3Y7II3B.js.map
578
+ //# sourceMappingURL=chunk-O3Y7II3B.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../operator/dist/PaymasterOperatorClient.js","../../operator/dist/ProtocolClient.js","../../operator/dist/OperatorLifecycle.js"],"names":["ProposalState"],"mappings":";;;AAMO,IAAM,uBAAA,GAAN,cAAsC,UAAA,CAAW;AAAA,EACpD,qBAAA;AAAA,EACA,YAAA;AAAA,EACA,eAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAY,MAAA,EAAQ;AAChB,IAAA,KAAA,CAAM,MAAM,CAAA;AACZ,IAAA,IAAA,CAAK,wBAAwB,MAAA,CAAO,qBAAA;AACpC,IAAA,IAAA,CAAK,eAAe,MAAA,CAAO,YAAA;AAC3B,IAAA,IAAA,CAAK,eAAA,GAAkB,OAAO,sBAAA,IAA0B,4CAAA;AACxD,IAAA,IAAA,CAAK,YAAA,GAAe,OAAO,mBAAA,IAAuB,4CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,gCAAA,CAAiC,MAAA,EAAQ,OAAA,EAAS;AACpD,IAAA,IAAI;AACA,MAAA,MAAM,YAAA,GAAe,KAAK,eAAA,EAAgB;AAC1C,MAAA,MAAM,UAAA,GAAa,KAAK,aAAA,EAAc;AACtC,MAAA,MAAM,iBAAA,GAAoB,KAAK,oBAAA,EAAqB;AACpD,MAAA,MAAM,QAAA,GAAW,gBAAgB,YAAY,CAAA;AAC7C,MAAA,MAAM,SAAS,YAAA,EAAa;AAC5B,MAAA,MAAM,YAAA,GAAe,KAAK,oBAAA,EAAqB;AAE/C,MAAA,MAAM,cAAA,GAAiB,MAAM,QAAA,CAAS,YAAY,EAAE,cAAA,EAAe;AACnE,MAAA,MAAM,YAAA,GAAe,MAAM,QAAA,CAAS,YAAY,EAAE,OAAA,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EAAG,MAAA,EAAQ,sBAAsB,CAAA;AACxG,IAAA,IAAI,OAAA,EAAS;AACT,MAAA,MAAM,KAAA,GAAQ,MAAM,cAAA,CAAe,QAAA,CAAS,EAAE,QAAQ,oBAAA,EAAsB,OAAA,EAAS,OAAA,EAAS,OAAA,EAAS,CAAA;AACvG,MAAA,MAAA,CAAO,KAAK,KAAK,CAAA;AAAA,IACrB;AACA,IAAA,OAAO,MAAA;AAAA,EACX;AAAA;AAAA,EAEA,MAAM,eAAA,GAAkB;AACpB,IAAA,IAAI,CAAC,IAAA,CAAK,YAAA;AACN,MAAA,OAAO,EAAA;AACX,IAAA,MAAM,KAAA,GAAQ,YAAA,EAAa,CAAE,IAAA,CAAK,sBAAsB,CAAA;AACxD,IAAA,OAAO,MAAM,KAAA,CAAM,SAAA,CAAU,EAAE,KAAA,EAAO,IAAA,CAAK,YAAA,EAAc,OAAA,EAAS,IAAA,CAAK,UAAA,EAAW,EAAG,CAAA;AAAA,EACzF;AACJ","file":"chunk-O3Y7II3B.js","sourcesContent":["import { parseEther } from 'viem';\nimport { BaseClient, PaymasterABI } from '@aastar/core';\nimport { superPaymasterActions, tokenActions, paymasterActions, registryActions, paymasterFactoryActions } from '@aastar/core';\n/**\n * Client for Paymaster Operators (ROLE_PAYMASTER_SUPER)\n */\nexport class PaymasterOperatorClient extends BaseClient {\n superPaymasterAddress;\n tokenAddress;\n ethUsdPriceFeed;\n xpntsFactory;\n constructor(config) {\n super(config);\n this.superPaymasterAddress = config.superPaymasterAddress;\n this.tokenAddress = config.tokenAddress;\n this.ethUsdPriceFeed = config.ethUsdPriceFeedAddress || '0x694AA1769357215DE4FAC081bf1f309aDC325306'; // Default Sepolia\n this.xpntsFactory = config.xpntsFactoryAddress || '0x0000000000000000000000000000000000000000'; // Should be provided\n }\n // ========================================\n // 0. 注册与入驻 (One-Stop Registration)\n // ========================================\n /**\n * Register as SuperPaymaster Operator (one-stop API).\n * This method handles all necessary steps:\n * 1. Checks prerequisites (must have ROLE_COMMUNITY)\n * 2. Checks and approves GToken to GTokenStaking\n * 3. Registers ROLE_PAYMASTER_SUPER\n * 4. Optionally deposits collateral to SuperPaymaster\n *\n * @param params Registration parameters\n * @param options Transaction options\n * @returns Transaction hash of role registration\n */\n async registerAsSuperPaymasterOperator(params, options) {\n try {\n const registryAddr = this.requireRegistry();\n const gTokenAddr = this.requireGToken();\n const gTokenStakingAddr = this.requireGTokenStaking();\n const registry = registryActions(registryAddr);\n const gToken = tokenActions();\n const publicClient = this.getStartPublicClient();\n // 1. Check prerequisites\n const ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();\n const hasCommunity = await registry(publicClient).hasRole({\n user: this.getAddress(),\n roleId: ROLE_COMMUNITY\n });\n if (!hasCommunity) {\n throw new Error('Must have ROLE_COMMUNITY before registering as SuperPaymaster operator');\n }\n // 2. Check if already has role\n const ROLE_PAYMASTER_SUPER = await registry(publicClient).ROLE_PAYMASTER_SUPER();\n const hasSuper = await registry(publicClient).hasRole({\n user: this.getAddress(),\n roleId: ROLE_PAYMASTER_SUPER\n });\n if (hasSuper) {\n // Still handle deposit if requested\n if (params?.depositAmount) {\n return this.depositCollateral(params.depositAmount, options);\n }\n throw new Error('Already registered as SuperPaymaster operator');\n }\n // 3. Prepare stake amount (default 50 GToken as per Registry config)\n const stakeAmount = params?.stakeAmount || parseEther('50');\n // 4. Check and approve GToken to GTokenStaking\n const allowance = await gToken(publicClient).allowance({\n token: gTokenAddr,\n owner: this.getAddress(),\n spender: gTokenStakingAddr\n });\n if (allowance < stakeAmount) {\n const approveHash = await gToken(this.client).approve({\n token: gTokenAddr,\n spender: gTokenStakingAddr,\n amount: stakeAmount * 2n, // Approve 2x for future use\n account: options?.account\n });\n await publicClient.waitForTransactionReceipt({ hash: approveHash });\n }\n // 5. Register ROLE_PAYMASTER_SUPER\n const registerHash = await registry(this.client).registerRoleSelf({\n roleId: ROLE_PAYMASTER_SUPER,\n data: '0x', // SuperPaymaster role doesn't need special data\n account: options?.account\n });\n // Wait for registration to complete\n await publicClient.waitForTransactionReceipt({ hash: registerHash });\n // 6. Optional: Deposit collateral to SuperPaymaster\n if (params?.depositAmount) {\n await this.depositCollateral(params.depositAmount, options);\n }\n return registerHash;\n }\n catch (error) {\n throw error;\n }\n }\n /**\n * Deploy a new Paymaster V4 and Register as AOA Operator (one-stop API).\n * This method handles:\n * 1. Checks prerequisites (ROLE_COMMUNITY)\n * 2. Predicts new Paymaster address\n * 3. Deploys Paymaster V4 via Factory\n * 4. Registers ROLE_PAYMASTER_AOA with staking\n *\n * @param params Deployment parameters\n * @param options Transaction options\n * @returns Object containing new paymaster address and transaction hashes\n */\n async deployAndRegisterPaymasterV4(params, options) {\n try {\n const registryAddr = this.requireRegistry();\n const gTokenAddr = this.requireGToken();\n const gTokenStakingAddr = this.requireGTokenStaking();\n const factoryAddr = this.requirePaymasterFactory();\n const registry = registryActions(registryAddr);\n const gToken = tokenActions();\n const factory = paymasterFactoryActions(factoryAddr);\n const publicClient = this.getStartPublicClient();\n const account = options?.account || this.client.account || this.getAddress();\n const accountAddr = typeof account === 'string' ? account : account.address;\n // 1. Check prerequisites (ROLE_COMMUNITY)\n const ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();\n const hasCommunity = await registry(publicClient).hasRole({\n user: accountAddr,\n roleId: ROLE_COMMUNITY\n });\n if (!hasCommunity) {\n throw new Error('Must have ROLE_COMMUNITY before deploying Paymaster V4');\n }\n // 2. Deployment (Idempotent Check)\n const existingPaymaster = await factory(publicClient).getPaymaster({ owner: accountAddr });\n let deployHash = '0x0000000000000000000000000000000000000000000000000000000000000000';\n let paymasterAddress;\n if (existingPaymaster && existingPaymaster !== '0x0000000000000000000000000000000000000000') {\n console.log(` ℹ️ Paymaster already deployed at: ${existingPaymaster}`);\n paymasterAddress = existingPaymaster;\n }\n else {\n console.log(' 🛠️ Deploying Paymaster V4 with args:', {\n entryPoint: this.requireEntryPoint(),\n owner: accountAddr,\n priceFeed: this.ethUsdPriceFeed,\n factory: factoryAddr\n });\n const { encodeFunctionData } = await import('viem');\n const initData = encodeFunctionData({\n abi: PaymasterABI,\n functionName: 'initialize',\n args: [\n this.requireEntryPoint(), // EntryPoint v0.7\n accountAddr,\n accountAddr, // Treasury defaults to owner\n this.ethUsdPriceFeed,\n 200n, // serviceFeeRate (2%)\n parseEther('0.1'), // maxGasCostCap\n 3600n // priceStalenessThreshold (1 hour)\n ]\n });\n deployHash = await factory(this.client).deployPaymaster({\n version: params?.version,\n initData,\n account\n });\n await publicClient.waitForTransactionReceipt({ hash: deployHash });\n paymasterAddress = await factory(publicClient).getPaymaster({ owner: accountAddr });\n }\n if (!paymasterAddress || paymasterAddress === '0x0000000000000000000000000000000000000000') {\n throw new Error('Failed to retrieve Paymaster address from Factory');\n }\n // 3. Register ROLE_PAYMASTER_AOA\n const ROLE_PAYMASTER_AOA = await registry(publicClient).ROLE_PAYMASTER_AOA();\n const hasAOA = await registry(publicClient).hasRole({\n user: accountAddr,\n roleId: ROLE_PAYMASTER_AOA\n });\n if (hasAOA) {\n return { paymasterAddress, deployHash, registerHash: '0x0000000000000000000000000000000000000000000000000000000000000000' };\n }\n const stakeAmount = params?.stakeAmount || parseEther('30');\n const allowance = await gToken(publicClient).allowance({\n token: gTokenAddr,\n owner: accountAddr,\n spender: gTokenStakingAddr\n });\n if (allowance < stakeAmount) {\n const approveHash = await gToken(this.client).approve({\n token: gTokenAddr,\n spender: gTokenStakingAddr,\n amount: stakeAmount * 2n,\n account: account\n });\n await publicClient.waitForTransactionReceipt({ hash: approveHash });\n }\n const { encodeAbiParameters, parseAbiParameters } = await import('viem');\n let roleData = '0x';\n if (stakeAmount > 0) {\n roleData = encodeAbiParameters(parseAbiParameters('uint256'), [stakeAmount]);\n }\n const registerHash = await registry(this.client).registerRoleSelf({\n roleId: ROLE_PAYMASTER_AOA,\n data: roleData,\n account: account\n });\n await publicClient.waitForTransactionReceipt({ hash: registerHash });\n return {\n paymasterAddress,\n deployHash,\n registerHash\n };\n }\n catch (error) {\n throw error;\n }\n }\n /**\n * Deposit collateral (aPNTs/GToken) to SuperPaymaster.\n * This is a helper method used by registerAsSuperPaymasterOperator.\n */\n async depositCollateral(amount, options) {\n try {\n const pm = superPaymasterActions(this.superPaymasterAddress);\n const publicClient = this.getStartPublicClient();\n // V3.7: Dynamically fetch the token expected by SuperPaymaster\n const depositToken = await pm(publicClient).APNTS_TOKEN();\n const token = tokenActions();\n // Approve SuperPaymaster to spend the token (usually aPNTs on Sepolia)\n const allowance = await token(publicClient).allowance({\n token: depositToken,\n owner: this.getAddress(),\n spender: this.superPaymasterAddress\n });\n if (allowance < amount) {\n const approveHash = await token(this.client).approve({\n token: depositToken,\n spender: this.superPaymasterAddress,\n amount,\n account: options?.account\n });\n await publicClient.waitForTransactionReceipt({ hash: approveHash });\n }\n // Deposit to SuperPaymaster\n return pm(this.client).deposit({\n amount,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n /**\n * Configure operator parameters (Token, Treasury).\n * Exchange rate is now read live from xPNTsToken.exchangeRate() at runtime.\n * If parameters are undefined, existing values are preserved.\n */\n async configureOperator(xPNTsToken, treasury, options) {\n try {\n const sp = superPaymasterActions(this.superPaymasterAddress);\n const publicClient = this.getStartPublicClient();\n // Fetch current config to preserve missing values\n const currentConfig = await sp(publicClient).operators({ operator: this.getAddress() });\n const currentToken = currentConfig.xPNTsToken;\n const currentTreasury = currentConfig.treasury;\n return await sp(this.client).configureOperator({\n xPNTsToken: xPNTsToken || currentToken,\n opTreasury: treasury || currentTreasury,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n async withdrawCollateral(to, amount, options) {\n try {\n const sp = superPaymasterActions(this.superPaymasterAddress);\n return await sp(this.client).withdrawTo({\n to,\n amount,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n async isOperator(operator) {\n try {\n const sp = superPaymasterActions(this.superPaymasterAddress);\n const config = await sp(this.getStartPublicClient()).operators({ operator });\n return config.isConfigured;\n }\n catch (error) {\n return false;\n }\n }\n async getOperatorDetails(operator) {\n try {\n const target = operator || this.getAddress();\n const sp = superPaymasterActions(this.superPaymasterAddress);\n return await sp(this.getStartPublicClient()).operators({ operator: target });\n }\n catch (error) {\n throw error;\n }\n }\n async initiateExit(options) {\n try {\n const sp = superPaymasterActions(this.superPaymasterAddress);\n return await sp(this.client).unlockStake({\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n async withdrawStake(to, options) {\n try {\n const sp = superPaymasterActions(this.superPaymasterAddress);\n return await sp(this.client).withdrawStake({\n to,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n // ========================================\n // 3. 支付代币管理 (基于 PaymasterActions)\n // ========================================\n async addGasToken(token, price, options) {\n try {\n const pm = paymasterActions(this.superPaymasterAddress);\n return await pm(this.client).setTokenPrice({\n token,\n price,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n async getTokenPrice(token) {\n try {\n const pm = paymasterActions(this.superPaymasterAddress);\n return await pm(this.getStartPublicClient()).tokenPrices({ token });\n }\n catch (error) {\n throw error;\n }\n }\n async setupPaymasterDeposit(params, options) {\n try {\n const pm = paymasterActions(params.paymaster);\n return await pm(this.client).depositFor({\n user: params.user,\n token: params.token,\n amount: params.amount,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n}\n","import { BaseClient } from '@aastar/core';\nimport { dvtActions, aggregatorActions, superPaymasterActions } from '@aastar/core';\nexport var ProposalState;\n(function (ProposalState) {\n ProposalState[ProposalState[\"Pending\"] = 0] = \"Pending\";\n ProposalState[ProposalState[\"Active\"] = 1] = \"Active\";\n ProposalState[ProposalState[\"Canceled\"] = 2] = \"Canceled\";\n ProposalState[ProposalState[\"Defeated\"] = 3] = \"Defeated\";\n ProposalState[ProposalState[\"Succeeded\"] = 4] = \"Succeeded\";\n ProposalState[ProposalState[\"Queued\"] = 5] = \"Queued\";\n ProposalState[ProposalState[\"Expired\"] = 6] = \"Expired\";\n ProposalState[ProposalState[\"Executed\"] = 7] = \"Executed\";\n})(ProposalState || (ProposalState = {}));\n/**\n * Client for Protocol Governors and Validators (Infrastructure)\n */\nexport class ProtocolClient extends BaseClient {\n dvtValidatorAddress;\n blsAggregatorAddress;\n superPaymasterAddress;\n constructor(config) {\n super(config);\n this.dvtValidatorAddress = config.dvtValidatorAddress;\n this.blsAggregatorAddress = config.blsAggregatorAddress;\n this.superPaymasterAddress = config.superPaymasterAddress;\n }\n // ========================================\n // 1. 提案管理 (DVT)\n // ========================================\n /**\n * Create a new proposal\n */\n async createProposal(target, calldata, description, options) {\n try {\n const dvt = dvtActions(this.dvtValidatorAddress)(this.client);\n // Mapping general \"createProposal\" to \"createSlashProposal\" for now\n // Assuming Governance uses Validator logic or this Client is for Slash.\n // Using createSlashProposal as the available action.\n return await dvt.createSlashProposal({\n operator: target,\n level: 1, // Default level\n reason: description,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n async signProposal(proposalId, signature = '0x', options) {\n try {\n const dvt = dvtActions(this.dvtValidatorAddress)(this.client);\n return await dvt.signSlashProposal({\n proposalId,\n signature,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n /**\n * Execute a proposal with collected signatures\n */\n async executeWithProof(proposalId, signatures, options) {\n try {\n // Mock proof generation logic or placeholder\n const proof = '0x';\n const dvt = dvtActions(this.dvtValidatorAddress)(this.client);\n return await dvt.executeSlashWithProof({\n proposalId,\n repUsers: [], // Needs real data in production\n newScores: [],\n epoch: 0n,\n proof,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n // ========================================\n // 2. 验证器管理 / BLS\n // ========================================\n async registerBLSKey(publicKey, options) {\n try {\n if (!this.blsAggregatorAddress) {\n throw new Error('BLS Aggregator address required for this client');\n }\n // Aggregator actions now handle the type internally or via mapping\n const agg = aggregatorActions(this.blsAggregatorAddress)(this.client);\n return await agg.registerBLSPublicKey({\n validator: this.getAddress(),\n publicKey,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n // ========================================\n // 3. 全局参数管理 (Admin)\n // ========================================\n async setProtocolFee(bps, options) {\n try {\n if (!this.superPaymasterAddress) {\n throw new Error('SuperPaymaster address required for this client');\n }\n const sp = superPaymasterActions(this.superPaymasterAddress);\n return await sp(this.client).setProtocolFee({\n newFeeBPS: bps,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n async setTreasury(treasury, options) {\n try {\n if (!this.superPaymasterAddress) {\n throw new Error('SuperPaymaster address required for this client');\n }\n const sp = superPaymasterActions(this.superPaymasterAddress);\n return await sp(this.client).setTreasury({\n treasury,\n account: options?.account\n });\n }\n catch (error) {\n throw error;\n }\n }\n}\n","import { PaymasterOperatorClient } from './PaymasterOperatorClient.js';\nimport { tokenActions, registryActions } from '@aastar/core'; // L2/L1 Actions\n/**\n * OperatorLifecycle - L3 Pattern\n *\n * Responsibilities:\n * 1. Managing the complete lifecycle of a Paymaster Operator\n * 2. Unifying setup (onboard), operation (config), and exit (withdraw)\n */\nexport class OperatorLifecycle extends PaymasterOperatorClient {\n constructor(config) {\n super(config);\n }\n // ===========================================\n // 1. Setup Phase (Onboarding)\n // ===========================================\n /**\n * Check if the account is ready to become an operator\n * (e.g., has GToken, has ROLE_COMMUNITY, etc.)\n */\n async checkReadiness() {\n const isOp = await this.isOperator(this.getAddress());\n // For SuperPaymaster, balance is 'aPNTsBalance' (Collateral)\n const details = await this.getOperatorDetails();\n const balance = details.aPNTsBalance || 0n;\n return {\n isConfigured: isOp,\n isActive: isOp, // Simplification\n balance\n };\n }\n /**\n * One-click Setup: Register + Deposit + Deploy Node\n * Wraps existing registerAsSuperPaymasterOperator or deployAndRegisterPaymasterV4\n */\n async setupNode(params, options) {\n const hashes = [];\n if (params.type === 'SUPER') {\n const h = await this.registerAsSuperPaymasterOperator({\n stakeAmount: params.stakeAmount,\n depositAmount: params.depositAmount\n }, options);\n hashes.push(h);\n // Fetch Token Address and Configure\n const factory = await import('@aastar/core').then(m => m.xPNTsFactoryActions(this.xpntsFactory)(this.getStartPublicClient()));\n const token = await factory.getTokenAddress({ community: this.getAddress() });\n if (token && token !== '0x0000000000000000000000000000000000000000') {\n const hConfig = await this.configureOperator(token, this.getAddress(), // Default treasury to self\n options);\n hashes.push(hConfig);\n }\n }\n else {\n const result = await this.deployAndRegisterPaymasterV4({\n stakeAmount: params.stakeAmount\n }, options);\n hashes.push(result.deployHash);\n hashes.push(result.registerHash);\n }\n return hashes;\n }\n // ===========================================\n // 2. Operational Phase (Config & Funds)\n // ===========================================\n // Inherits: addGasToken, configureOperator, depositCollateral from PaymasterOperatorClient\n async getOperatorStats() {\n return await this.getOperatorDetails();\n }\n // ===========================================\n // 3. Exit Phase (Withdraw & Leave)\n // ===========================================\n /**\n * Start the exit process: Unstake from Registry/SuperPaymaster and Unlock funds\n */\n async initiateExit(options) {\n // 1. Unlock Stake from SuperPaymaster (if applicable)\n return await super.initiateExit(options);\n }\n /**\n * Finalize exit: Withdraw all funds (Collateral + Rewards)\n */\n async withdrawAllFunds(to, options) {\n const recipient = to || this.getAddress();\n const hashes = [];\n // 1. Withdraw Collateral from SuperPaymaster (if any)\n // Note: We need to know the balance to withdraw exact amount.\n // For current L3 pattern, we assume the user tracks it or we fetch it.\n const stats = await this.checkReadiness();\n if (stats.balance > 0n) {\n const hCol = await this.withdrawCollateral(recipient, stats.balance, options);\n hashes.push(hCol);\n }\n // 2. Exit Role in Registry (Unstake GToken)\n // This will fail if lock duration > 0 and not yet cooldown.\n // Or it will initiate cooldown.\n const client = this.getStartPublicClient();\n const registry = registryActions(this.registryAddress); // Use local registry address\n const registryWriter = registryActions(this.registryAddress)(this.client);\n // Check if we have the role\n // For Super Operator\n const ROLE_PAYMASTER_SUPER = await registry(client).ROLE_PAYMASTER_SUPER();\n const hasRole = await registry(client).hasRole({ user: this.getAddress(), roleId: ROLE_PAYMASTER_SUPER });\n if (hasRole) {\n const hExit = await registryWriter.exitRole({ roleId: ROLE_PAYMASTER_SUPER, account: options?.account });\n hashes.push(hExit);\n }\n return hashes;\n }\n // Helper: Get GToken Balance\n async getTokenBalance() {\n if (!this.tokenAddress)\n return 0n;\n const token = tokenActions()(this.getStartPublicClient());\n return await token.balanceOf({ token: this.tokenAddress, account: this.getAddress() });\n }\n}\n"]}