@aastar/sdk 0.20.8 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/BaseClient-CkBhQ1ou.d.cts +88 -0
  2. package/dist/UserClient-BDGP37PK.js +6 -0
  3. package/dist/{UserClient-AIIHB54I.js.map → UserClient-BDGP37PK.js.map} +1 -1
  4. package/dist/UserClient-FOAOBLGK.cjs +15 -0
  5. package/dist/UserClient-FOAOBLGK.cjs.map +1 -0
  6. package/dist/account.cjs +31 -0
  7. package/dist/account.cjs.map +1 -0
  8. package/dist/account.d.cts +48 -0
  9. package/dist/account.js +3 -3
  10. package/dist/admin.cjs +15 -0
  11. package/dist/admin.cjs.map +1 -0
  12. package/dist/admin.d.cts +62 -0
  13. package/dist/admin.js +3 -3
  14. package/dist/airaccount.cjs +452 -0
  15. package/dist/airaccount.cjs.map +1 -0
  16. package/dist/airaccount.d.cts +4 -0
  17. package/dist/airaccount.js +3 -3
  18. package/dist/channel-CkRRbzT8.d.cts +77 -0
  19. package/dist/channel.cjs +27 -0
  20. package/dist/channel.cjs.map +1 -0
  21. package/dist/channel.d.cts +64 -0
  22. package/dist/channel.js +3 -3
  23. package/dist/chunk-3HZEIFBW.cjs +118 -0
  24. package/dist/chunk-3HZEIFBW.cjs.map +1 -0
  25. package/dist/{chunk-7ARJ3OSU.js → chunk-57XLR2NT.js} +3 -3
  26. package/dist/{chunk-7ARJ3OSU.js.map → chunk-57XLR2NT.js.map} +1 -1
  27. package/dist/chunk-5JFYTJOE.cjs +448 -0
  28. package/dist/chunk-5JFYTJOE.cjs.map +1 -0
  29. package/dist/{chunk-KDH3UPKD.js → chunk-5NKU5NT5.js} +8 -8
  30. package/dist/{chunk-KDH3UPKD.js.map → chunk-5NKU5NT5.js.map} +1 -1
  31. package/dist/chunk-63JM67L7.cjs +435 -0
  32. package/dist/chunk-63JM67L7.cjs.map +1 -0
  33. package/dist/{chunk-IC3G6YM2.js → chunk-6OWZOTE7.js} +113 -9
  34. package/dist/chunk-6OWZOTE7.js.map +1 -0
  35. package/dist/chunk-CIEYY3A6.cjs +43259 -0
  36. package/dist/chunk-CIEYY3A6.cjs.map +1 -0
  37. package/dist/chunk-DEUBKZH5.cjs +421 -0
  38. package/dist/chunk-DEUBKZH5.cjs.map +1 -0
  39. package/dist/{chunk-TENYCMJ3.js → chunk-DF4WVR2H.js} +9 -9
  40. package/dist/{chunk-TENYCMJ3.js.map → chunk-DF4WVR2H.js.map} +1 -1
  41. package/dist/{chunk-BN5WY5GM.js → chunk-DQBKE4ND.js} +4 -4
  42. package/dist/{chunk-BN5WY5GM.js.map → chunk-DQBKE4ND.js.map} +1 -1
  43. package/dist/{chunk-4EZD7LPE.js → chunk-E4CQFW75.js} +3 -3
  44. package/dist/{chunk-4EZD7LPE.js.map → chunk-E4CQFW75.js.map} +1 -1
  45. package/dist/{chunk-LXWIPTPX.js → chunk-ENSMYCU6.js} +3 -3
  46. package/dist/{chunk-LXWIPTPX.js.map → chunk-ENSMYCU6.js.map} +1 -1
  47. package/dist/{chunk-FJ7XECC5.js → chunk-EY2AJTGV.js} +3 -3
  48. package/dist/{chunk-FJ7XECC5.js.map → chunk-EY2AJTGV.js.map} +1 -1
  49. package/dist/chunk-GAMSWXWI.cjs +1168 -0
  50. package/dist/chunk-GAMSWXWI.cjs.map +1 -0
  51. package/dist/chunk-IJN776TA.cjs +585 -0
  52. package/dist/chunk-IJN776TA.cjs.map +1 -0
  53. package/dist/{chunk-PKCHRXFR.js → chunk-KZERVPUR.js} +3 -3
  54. package/dist/{chunk-PKCHRXFR.js.map → chunk-KZERVPUR.js.map} +1 -1
  55. package/dist/{chunk-6QYXGMCR.js → chunk-M5WFKETT.js} +833 -47
  56. package/dist/chunk-M5WFKETT.js.map +1 -0
  57. package/dist/chunk-M7HXR7G5.cjs +128 -0
  58. package/dist/chunk-M7HXR7G5.cjs.map +1 -0
  59. package/dist/{chunk-PAABYXS6.js → chunk-MCALA6WM.js} +6 -6
  60. package/dist/{chunk-PAABYXS6.js.map → chunk-MCALA6WM.js.map} +1 -1
  61. package/dist/chunk-MXJEULSE.cjs +396 -0
  62. package/dist/chunk-MXJEULSE.cjs.map +1 -0
  63. package/dist/chunk-OVNOSAL3.cjs +4797 -0
  64. package/dist/chunk-OVNOSAL3.cjs.map +1 -0
  65. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  66. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  67. package/dist/{chunk-MVEWJIPY.js → chunk-RXPSL33E.js} +3 -3
  68. package/dist/{chunk-MVEWJIPY.js.map → chunk-RXPSL33E.js.map} +1 -1
  69. package/dist/{chunk-G3UJC4EL.js → chunk-UCLK6LTB.js} +39 -36
  70. package/dist/chunk-UCLK6LTB.js.map +1 -0
  71. package/dist/chunk-WR4OZUXR.cjs +115 -0
  72. package/dist/chunk-WR4OZUXR.cjs.map +1 -0
  73. package/dist/chunk-XQROKLZI.cjs +4521 -0
  74. package/dist/chunk-XQROKLZI.cjs.map +1 -0
  75. package/dist/chunk-Y4EJX7UA.cjs +228 -0
  76. package/dist/chunk-Y4EJX7UA.cjs.map +1 -0
  77. package/dist/chunk-Z4GZ6DQA.cjs +108 -0
  78. package/dist/chunk-Z4GZ6DQA.cjs.map +1 -0
  79. package/dist/contract-addresses-RABD77VP.cjs +49 -0
  80. package/dist/contract-addresses-RABD77VP.cjs.map +1 -0
  81. package/dist/{contract-addresses-N3TOL2WL.js → contract-addresses-TVXSRQ7I.js} +3 -3
  82. package/dist/{contract-addresses-N3TOL2WL.js.map → contract-addresses-TVXSRQ7I.js.map} +1 -1
  83. package/dist/core.cjs +898 -0
  84. package/dist/core.cjs.map +1 -0
  85. package/dist/core.d.cts +7048 -0
  86. package/dist/core.d.ts +130 -12
  87. package/dist/core.js +2 -2
  88. package/dist/dapp.cjs +289 -0
  89. package/dist/dapp.cjs.map +1 -0
  90. package/dist/dapp.d.cts +127 -0
  91. package/dist/dapp.js +3 -3
  92. package/dist/doc-types-471vSmPO.d.cts +16 -0
  93. package/dist/enduser.cjs +24 -0
  94. package/dist/enduser.cjs.map +1 -0
  95. package/dist/enduser.d.cts +261 -0
  96. package/dist/enduser.js +4 -4
  97. package/dist/identity.cjs +23 -0
  98. package/dist/identity.cjs.map +1 -0
  99. package/dist/identity.d.cts +81 -0
  100. package/dist/identity.js +3 -3
  101. package/dist/index-B6SfEQxo.d.cts +47 -0
  102. package/dist/index.cjs +2818 -0
  103. package/dist/index.cjs.map +1 -0
  104. package/dist/index.d.cts +656 -0
  105. package/dist/index.d.ts +1 -1
  106. package/dist/index.js +17 -17
  107. package/dist/kms.cjs +452 -0
  108. package/dist/kms.cjs.map +1 -0
  109. package/dist/kms.d.cts +3104 -0
  110. package/dist/kms.d.ts +62 -12
  111. package/dist/kms.js +3 -3
  112. package/dist/lib-FE4GR7TO.cjs +1865 -0
  113. package/dist/lib-FE4GR7TO.cjs.map +1 -0
  114. package/dist/operator.cjs +27 -0
  115. package/dist/operator.cjs.map +1 -0
  116. package/dist/operator.d.cts +164 -0
  117. package/dist/operator.js +3 -3
  118. package/dist/paymaster.cjs +63 -0
  119. package/dist/paymaster.cjs.map +1 -0
  120. package/dist/paymaster.d.cts +312 -0
  121. package/dist/paymaster.js +3 -3
  122. package/dist/src-CUHI6G6W.cjs +898 -0
  123. package/dist/src-CUHI6G6W.cjs.map +1 -0
  124. package/dist/src-KHCWIS4Q.cjs +63 -0
  125. package/dist/src-KHCWIS4Q.cjs.map +1 -0
  126. package/dist/{src-X5MIV3EB.js → src-RSN4U2T2.js} +5 -5
  127. package/dist/src-RSN4U2T2.js.map +1 -0
  128. package/dist/{src-L5SI5WNB.js → src-XCV6BTSV.js} +4 -4
  129. package/dist/{src-X5MIV3EB.js.map → src-XCV6BTSV.js.map} +1 -1
  130. package/dist/tier-router-DeeVg69O.d.cts +370 -0
  131. package/dist/tokens.cjs +15 -0
  132. package/dist/tokens.cjs.map +1 -0
  133. package/dist/tokens.d.cts +64 -0
  134. package/dist/tokens.js +3 -3
  135. package/dist/x402.cjs +103 -0
  136. package/dist/x402.cjs.map +1 -0
  137. package/dist/x402.d.cts +373 -0
  138. package/dist/x402.js +3 -3
  139. package/package.json +116 -32
  140. package/dist/UserClient-AIIHB54I.js +0 -6
  141. package/dist/chunk-6QYXGMCR.js.map +0 -1
  142. package/dist/chunk-G3UJC4EL.js.map +0 -1
  143. package/dist/chunk-IC3G6YM2.js.map +0 -1
  144. package/dist/src-L5SI5WNB.js.map +0 -1
@@ -0,0 +1,585 @@
1
+ 'use strict';
2
+
3
+ var chunkCIEYY3A6_cjs = require('./chunk-CIEYY3A6.cjs');
4
+ var viem = require('viem');
5
+
6
+ var PaymasterOperatorClient = class extends chunkCIEYY3A6_cjs.BaseClient {
7
+ superPaymasterAddress;
8
+ tokenAddress;
9
+ ethUsdPriceFeed;
10
+ xpntsFactory;
11
+ constructor(config) {
12
+ super(config);
13
+ this.superPaymasterAddress = config.superPaymasterAddress;
14
+ this.tokenAddress = config.tokenAddress;
15
+ this.ethUsdPriceFeed = config.ethUsdPriceFeedAddress || "0x694AA1769357215DE4FAC081bf1f309aDC325306";
16
+ this.xpntsFactory = config.xpntsFactoryAddress || "0x0000000000000000000000000000000000000000";
17
+ }
18
+ // ========================================
19
+ // 0. 注册与入驻 (One-Stop Registration)
20
+ // ========================================
21
+ /**
22
+ * Register as SuperPaymaster Operator (one-stop API).
23
+ * This method handles all necessary steps:
24
+ * 1. Checks prerequisites (must have ROLE_COMMUNITY)
25
+ * 2. Checks and approves GToken to GTokenStaking
26
+ * 3. Registers ROLE_PAYMASTER_SUPER
27
+ * 4. Optionally deposits collateral to SuperPaymaster
28
+ *
29
+ * @param params Registration parameters
30
+ * @param options Transaction options
31
+ * @returns Transaction hash of role registration
32
+ */
33
+ async registerAsSuperPaymasterOperator(params, options) {
34
+ try {
35
+ const registryAddr = this.requireRegistry();
36
+ const gTokenAddr = this.requireGToken();
37
+ const gTokenStakingAddr = this.requireGTokenStaking();
38
+ const registry = chunkCIEYY3A6_cjs.registryActions(registryAddr);
39
+ const gToken = chunkCIEYY3A6_cjs.tokenActions();
40
+ const publicClient = this.getStartPublicClient();
41
+ const ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();
42
+ const hasCommunity = await registry(publicClient).hasRole({
43
+ user: this.getAddress(),
44
+ roleId: ROLE_COMMUNITY
45
+ });
46
+ if (!hasCommunity) {
47
+ throw new Error("Must have ROLE_COMMUNITY before registering as SuperPaymaster operator");
48
+ }
49
+ const ROLE_PAYMASTER_SUPER = await registry(publicClient).ROLE_PAYMASTER_SUPER();
50
+ const hasSuper = await registry(publicClient).hasRole({
51
+ user: this.getAddress(),
52
+ roleId: ROLE_PAYMASTER_SUPER
53
+ });
54
+ if (hasSuper) {
55
+ if (params?.depositAmount) {
56
+ return this.depositCollateral(params.depositAmount, options);
57
+ }
58
+ throw new Error("Already registered as SuperPaymaster operator");
59
+ }
60
+ const stakeAmount = params?.stakeAmount || viem.parseEther("50");
61
+ const allowance = await gToken(publicClient).allowance({
62
+ token: gTokenAddr,
63
+ owner: this.getAddress(),
64
+ spender: gTokenStakingAddr
65
+ });
66
+ if (allowance < stakeAmount) {
67
+ const approveHash = await gToken(this.client).approve({
68
+ token: gTokenAddr,
69
+ spender: gTokenStakingAddr,
70
+ amount: stakeAmount * 2n,
71
+ // Approve 2x for future use
72
+ account: options?.account
73
+ });
74
+ await publicClient.waitForTransactionReceipt({ hash: approveHash });
75
+ }
76
+ const registerHash = await registry(this.client).registerRoleSelf({
77
+ roleId: ROLE_PAYMASTER_SUPER,
78
+ data: "0x",
79
+ // SuperPaymaster role doesn't need special data
80
+ account: options?.account
81
+ });
82
+ await publicClient.waitForTransactionReceipt({ hash: registerHash });
83
+ if (params?.depositAmount) {
84
+ await this.depositCollateral(params.depositAmount, options);
85
+ }
86
+ return registerHash;
87
+ } catch (error) {
88
+ throw error;
89
+ }
90
+ }
91
+ /**
92
+ * Deploy a new Paymaster V4 and Register as AOA Operator (one-stop API).
93
+ * This method handles:
94
+ * 1. Checks prerequisites (ROLE_COMMUNITY)
95
+ * 2. Predicts new Paymaster address
96
+ * 3. Deploys Paymaster V4 via Factory
97
+ * 4. Registers ROLE_PAYMASTER_AOA with staking
98
+ *
99
+ * @param params Deployment parameters
100
+ * @param options Transaction options
101
+ * @returns Object containing new paymaster address and transaction hashes
102
+ */
103
+ async deployAndRegisterPaymasterV4(params, options) {
104
+ try {
105
+ const registryAddr = this.requireRegistry();
106
+ const gTokenAddr = this.requireGToken();
107
+ const gTokenStakingAddr = this.requireGTokenStaking();
108
+ const factoryAddr = this.requirePaymasterFactory();
109
+ const registry = chunkCIEYY3A6_cjs.registryActions(registryAddr);
110
+ const gToken = chunkCIEYY3A6_cjs.tokenActions();
111
+ const factory = chunkCIEYY3A6_cjs.paymasterFactoryActions(factoryAddr);
112
+ const publicClient = this.getStartPublicClient();
113
+ const account = options?.account || this.client.account || this.getAddress();
114
+ const accountAddr = typeof account === "string" ? account : account.address;
115
+ const ROLE_COMMUNITY = await registry(publicClient).ROLE_COMMUNITY();
116
+ const hasCommunity = await registry(publicClient).hasRole({
117
+ user: accountAddr,
118
+ roleId: ROLE_COMMUNITY
119
+ });
120
+ if (!hasCommunity) {
121
+ throw new Error("Must have ROLE_COMMUNITY before deploying Paymaster V4");
122
+ }
123
+ const existingPaymaster = await factory(publicClient).getPaymaster({ owner: accountAddr });
124
+ let deployHash = "0x0000000000000000000000000000000000000000000000000000000000000000";
125
+ let paymasterAddress;
126
+ if (existingPaymaster && existingPaymaster !== "0x0000000000000000000000000000000000000000") {
127
+ console.log(` \u2139\uFE0F Paymaster already deployed at: ${existingPaymaster}`);
128
+ paymasterAddress = existingPaymaster;
129
+ } else {
130
+ console.log(" \u{1F6E0}\uFE0F Deploying Paymaster V4 with args:", {
131
+ entryPoint: this.requireEntryPoint(),
132
+ owner: accountAddr,
133
+ priceFeed: this.ethUsdPriceFeed,
134
+ factory: factoryAddr
135
+ });
136
+ const { encodeFunctionData } = await import('viem');
137
+ const initData = encodeFunctionData({
138
+ abi: chunkCIEYY3A6_cjs.PaymasterABI,
139
+ functionName: "initialize",
140
+ args: [
141
+ this.requireEntryPoint(),
142
+ // EntryPoint v0.7
143
+ accountAddr,
144
+ accountAddr,
145
+ // Treasury defaults to owner
146
+ this.ethUsdPriceFeed,
147
+ 200n,
148
+ // serviceFeeRate (2%)
149
+ viem.parseEther("0.1"),
150
+ // maxGasCostCap
151
+ 3600n
152
+ // priceStalenessThreshold (1 hour)
153
+ ]
154
+ });
155
+ deployHash = await factory(this.client).deployPaymaster({
156
+ version: params?.version,
157
+ initData,
158
+ account
159
+ });
160
+ await publicClient.waitForTransactionReceipt({ hash: deployHash });
161
+ paymasterAddress = await factory(publicClient).getPaymaster({ owner: accountAddr });
162
+ }
163
+ if (!paymasterAddress || paymasterAddress === "0x0000000000000000000000000000000000000000") {
164
+ throw new Error("Failed to retrieve Paymaster address from Factory");
165
+ }
166
+ const ROLE_PAYMASTER_AOA = await registry(publicClient).ROLE_PAYMASTER_AOA();
167
+ const hasAOA = await registry(publicClient).hasRole({
168
+ user: accountAddr,
169
+ roleId: ROLE_PAYMASTER_AOA
170
+ });
171
+ if (hasAOA) {
172
+ return { paymasterAddress, deployHash, registerHash: "0x0000000000000000000000000000000000000000000000000000000000000000" };
173
+ }
174
+ const stakeAmount = params?.stakeAmount || viem.parseEther("30");
175
+ const allowance = await gToken(publicClient).allowance({
176
+ token: gTokenAddr,
177
+ owner: accountAddr,
178
+ spender: gTokenStakingAddr
179
+ });
180
+ if (allowance < stakeAmount) {
181
+ const approveHash = await gToken(this.client).approve({
182
+ token: gTokenAddr,
183
+ spender: gTokenStakingAddr,
184
+ amount: stakeAmount * 2n,
185
+ account
186
+ });
187
+ await publicClient.waitForTransactionReceipt({ hash: approveHash });
188
+ }
189
+ const { encodeAbiParameters, parseAbiParameters } = await import('viem');
190
+ let roleData = "0x";
191
+ if (stakeAmount > 0) {
192
+ roleData = encodeAbiParameters(
193
+ parseAbiParameters("uint256"),
194
+ [stakeAmount]
195
+ );
196
+ }
197
+ const registerHash = await registry(this.client).registerRoleSelf({
198
+ roleId: ROLE_PAYMASTER_AOA,
199
+ data: roleData,
200
+ account
201
+ });
202
+ await publicClient.waitForTransactionReceipt({ hash: registerHash });
203
+ return {
204
+ paymasterAddress,
205
+ deployHash,
206
+ registerHash
207
+ };
208
+ } catch (error) {
209
+ throw error;
210
+ }
211
+ }
212
+ /**
213
+ * Deposit collateral (aPNTs/GToken) to SuperPaymaster.
214
+ * This is a helper method used by registerAsSuperPaymasterOperator.
215
+ */
216
+ async depositCollateral(amount, options) {
217
+ try {
218
+ const pm = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
219
+ const publicClient = this.getStartPublicClient();
220
+ const depositToken = await pm(publicClient).APNTS_TOKEN();
221
+ const token = chunkCIEYY3A6_cjs.tokenActions();
222
+ const allowance = await token(publicClient).allowance({
223
+ token: depositToken,
224
+ owner: this.getAddress(),
225
+ spender: this.superPaymasterAddress
226
+ });
227
+ if (allowance < amount) {
228
+ const approveHash = await token(this.client).approve({
229
+ token: depositToken,
230
+ spender: this.superPaymasterAddress,
231
+ amount,
232
+ account: options?.account
233
+ });
234
+ await publicClient.waitForTransactionReceipt({ hash: approveHash });
235
+ }
236
+ return pm(this.client).deposit({
237
+ amount,
238
+ account: options?.account
239
+ });
240
+ } catch (error) {
241
+ throw error;
242
+ }
243
+ }
244
+ /**
245
+ * Configure operator parameters (Token, Treasury).
246
+ * Exchange rate is now read live from xPNTsToken.exchangeRate() at runtime.
247
+ * If parameters are undefined, existing values are preserved.
248
+ */
249
+ async configureOperator(xPNTsToken, treasury, options) {
250
+ try {
251
+ const sp = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
252
+ const publicClient = this.getStartPublicClient();
253
+ const currentConfig = await sp(publicClient).operators({ operator: this.getAddress() });
254
+ const currentToken = currentConfig.xPNTsToken;
255
+ const currentTreasury = currentConfig.treasury;
256
+ return await sp(this.client).configureOperator({
257
+ xPNTsToken: xPNTsToken || currentToken,
258
+ opTreasury: treasury || currentTreasury,
259
+ account: options?.account
260
+ });
261
+ } catch (error) {
262
+ throw error;
263
+ }
264
+ }
265
+ async withdrawCollateral(to, amount, options) {
266
+ try {
267
+ const sp = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
268
+ return await sp(this.client).withdrawTo({
269
+ to,
270
+ amount,
271
+ account: options?.account
272
+ });
273
+ } catch (error) {
274
+ throw error;
275
+ }
276
+ }
277
+ async isOperator(operator) {
278
+ try {
279
+ const sp = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
280
+ const config = await sp(this.getStartPublicClient()).operators({ operator });
281
+ return config.isConfigured;
282
+ } catch (error) {
283
+ return false;
284
+ }
285
+ }
286
+ async getOperatorDetails(operator) {
287
+ try {
288
+ const target = operator || this.getAddress();
289
+ const sp = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
290
+ return await sp(this.getStartPublicClient()).operators({ operator: target });
291
+ } catch (error) {
292
+ throw error;
293
+ }
294
+ }
295
+ async initiateExit(options) {
296
+ try {
297
+ const sp = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
298
+ return await sp(this.client).unlockStake({
299
+ account: options?.account
300
+ });
301
+ } catch (error) {
302
+ throw error;
303
+ }
304
+ }
305
+ async withdrawStake(to, options) {
306
+ try {
307
+ const sp = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
308
+ return await sp(this.client).withdrawStake({
309
+ to,
310
+ account: options?.account
311
+ });
312
+ } catch (error) {
313
+ throw error;
314
+ }
315
+ }
316
+ // ========================================
317
+ // 3. 支付代币管理 (基于 PaymasterActions)
318
+ // ========================================
319
+ async addGasToken(token, price, options) {
320
+ try {
321
+ const pm = chunkCIEYY3A6_cjs.paymasterActions(this.superPaymasterAddress);
322
+ return await pm(this.client).setTokenPrice({
323
+ token,
324
+ price,
325
+ account: options?.account
326
+ });
327
+ } catch (error) {
328
+ throw error;
329
+ }
330
+ }
331
+ async getTokenPrice(token) {
332
+ try {
333
+ const pm = chunkCIEYY3A6_cjs.paymasterActions(this.superPaymasterAddress);
334
+ return await pm(this.getStartPublicClient()).tokenPrices({ token });
335
+ } catch (error) {
336
+ throw error;
337
+ }
338
+ }
339
+ async setupPaymasterDeposit(params, options) {
340
+ try {
341
+ const pm = chunkCIEYY3A6_cjs.paymasterActions(params.paymaster);
342
+ return await pm(this.client).depositFor({
343
+ user: params.user,
344
+ token: params.token,
345
+ amount: params.amount,
346
+ account: options?.account
347
+ });
348
+ } catch (error) {
349
+ throw error;
350
+ }
351
+ }
352
+ };
353
+
354
+ // ../operator/src/ProtocolClient.ts
355
+ var ProposalState = /* @__PURE__ */ ((ProposalState2) => {
356
+ ProposalState2[ProposalState2["Pending"] = 0] = "Pending";
357
+ ProposalState2[ProposalState2["Active"] = 1] = "Active";
358
+ ProposalState2[ProposalState2["Canceled"] = 2] = "Canceled";
359
+ ProposalState2[ProposalState2["Defeated"] = 3] = "Defeated";
360
+ ProposalState2[ProposalState2["Succeeded"] = 4] = "Succeeded";
361
+ ProposalState2[ProposalState2["Queued"] = 5] = "Queued";
362
+ ProposalState2[ProposalState2["Expired"] = 6] = "Expired";
363
+ ProposalState2[ProposalState2["Executed"] = 7] = "Executed";
364
+ return ProposalState2;
365
+ })(ProposalState || {});
366
+ var ProtocolClient = class extends chunkCIEYY3A6_cjs.BaseClient {
367
+ dvtValidatorAddress;
368
+ blsAggregatorAddress;
369
+ superPaymasterAddress;
370
+ constructor(config) {
371
+ super(config);
372
+ this.dvtValidatorAddress = config.dvtValidatorAddress;
373
+ this.blsAggregatorAddress = config.blsAggregatorAddress;
374
+ this.superPaymasterAddress = config.superPaymasterAddress;
375
+ }
376
+ // ========================================
377
+ // 1. 提案管理 (DVT)
378
+ // ========================================
379
+ /**
380
+ * Create a new proposal
381
+ */
382
+ async createProposal(target, calldata, description, options) {
383
+ try {
384
+ const dvt = chunkCIEYY3A6_cjs.dvtActions(this.dvtValidatorAddress)(this.client);
385
+ return await dvt.createSlashProposal({
386
+ operator: target,
387
+ level: 1,
388
+ // Default level
389
+ reason: description,
390
+ account: options?.account
391
+ });
392
+ } catch (error) {
393
+ throw error;
394
+ }
395
+ }
396
+ async signProposal(proposalId, signature = "0x", options) {
397
+ try {
398
+ const dvt = chunkCIEYY3A6_cjs.dvtActions(this.dvtValidatorAddress)(this.client);
399
+ return await dvt.signSlashProposal({
400
+ proposalId,
401
+ signature,
402
+ account: options?.account
403
+ });
404
+ } catch (error) {
405
+ throw error;
406
+ }
407
+ }
408
+ /**
409
+ * Execute a proposal with collected signatures
410
+ */
411
+ async executeWithProof(proposalId, signatures, options) {
412
+ try {
413
+ const proof = "0x";
414
+ const dvt = chunkCIEYY3A6_cjs.dvtActions(this.dvtValidatorAddress)(this.client);
415
+ return await dvt.executeSlashWithProof({
416
+ proposalId,
417
+ repUsers: [],
418
+ // Needs real data in production
419
+ newScores: [],
420
+ epoch: 0n,
421
+ proof,
422
+ account: options?.account
423
+ });
424
+ } catch (error) {
425
+ throw error;
426
+ }
427
+ }
428
+ // ========================================
429
+ // 2. 验证器管理 / BLS
430
+ // ========================================
431
+ async registerBLSKey(publicKey, options) {
432
+ try {
433
+ if (!this.blsAggregatorAddress) {
434
+ throw new Error("BLS Aggregator address required for this client");
435
+ }
436
+ const agg = chunkCIEYY3A6_cjs.aggregatorActions(this.blsAggregatorAddress)(this.client);
437
+ return await agg.registerBLSPublicKey({
438
+ validator: this.getAddress(),
439
+ publicKey,
440
+ account: options?.account
441
+ });
442
+ } catch (error) {
443
+ throw error;
444
+ }
445
+ }
446
+ // ========================================
447
+ // 3. 全局参数管理 (Admin)
448
+ // ========================================
449
+ async setProtocolFee(bps, options) {
450
+ try {
451
+ if (!this.superPaymasterAddress) {
452
+ throw new Error("SuperPaymaster address required for this client");
453
+ }
454
+ const sp = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
455
+ return await sp(this.client).setProtocolFee({
456
+ newFeeBPS: bps,
457
+ account: options?.account
458
+ });
459
+ } catch (error) {
460
+ throw error;
461
+ }
462
+ }
463
+ async setTreasury(treasury, options) {
464
+ try {
465
+ if (!this.superPaymasterAddress) {
466
+ throw new Error("SuperPaymaster address required for this client");
467
+ }
468
+ const sp = chunkCIEYY3A6_cjs.superPaymasterActions(this.superPaymasterAddress);
469
+ return await sp(this.client).setTreasury({
470
+ treasury,
471
+ account: options?.account
472
+ });
473
+ } catch (error) {
474
+ throw error;
475
+ }
476
+ }
477
+ };
478
+
479
+ // ../operator/src/OperatorLifecycle.ts
480
+ var OperatorLifecycle = class extends PaymasterOperatorClient {
481
+ constructor(config) {
482
+ super(config);
483
+ }
484
+ // ===========================================
485
+ // 1. Setup Phase (Onboarding)
486
+ // ===========================================
487
+ /**
488
+ * Check if the account is ready to become an operator
489
+ * (e.g., has GToken, has ROLE_COMMUNITY, etc.)
490
+ */
491
+ async checkReadiness() {
492
+ const isOp = await this.isOperator(this.getAddress());
493
+ const details = await this.getOperatorDetails();
494
+ const balance = details.aPNTsBalance || 0n;
495
+ return {
496
+ isConfigured: isOp,
497
+ isActive: isOp,
498
+ // Simplification
499
+ balance
500
+ };
501
+ }
502
+ /**
503
+ * One-click Setup: Register + Deposit + Deploy Node
504
+ * Wraps existing registerAsSuperPaymasterOperator or deployAndRegisterPaymasterV4
505
+ */
506
+ async setupNode(params, options) {
507
+ const hashes = [];
508
+ if (params.type === "SUPER") {
509
+ const h = await this.registerAsSuperPaymasterOperator({
510
+ stakeAmount: params.stakeAmount,
511
+ depositAmount: params.depositAmount
512
+ }, options);
513
+ hashes.push(h);
514
+ const factory = await import('./src-CUHI6G6W.cjs').then((m) => m.xPNTsFactoryActions(this.xpntsFactory)(this.getStartPublicClient()));
515
+ const token = await factory.getTokenAddress({ community: this.getAddress() });
516
+ if (token && token !== "0x0000000000000000000000000000000000000000") {
517
+ const hConfig = await this.configureOperator(
518
+ token,
519
+ this.getAddress(),
520
+ // Default treasury to self
521
+ options
522
+ );
523
+ hashes.push(hConfig);
524
+ }
525
+ } else {
526
+ const result = await this.deployAndRegisterPaymasterV4({
527
+ stakeAmount: params.stakeAmount
528
+ }, options);
529
+ hashes.push(result.deployHash);
530
+ hashes.push(result.registerHash);
531
+ }
532
+ return hashes;
533
+ }
534
+ // ===========================================
535
+ // 2. Operational Phase (Config & Funds)
536
+ // ===========================================
537
+ // Inherits: addGasToken, configureOperator, depositCollateral from PaymasterOperatorClient
538
+ async getOperatorStats() {
539
+ return await this.getOperatorDetails();
540
+ }
541
+ // ===========================================
542
+ // 3. Exit Phase (Withdraw & Leave)
543
+ // ===========================================
544
+ /**
545
+ * Start the exit process: Unstake from Registry/SuperPaymaster and Unlock funds
546
+ */
547
+ async initiateExit(options) {
548
+ return await super.initiateExit(options);
549
+ }
550
+ /**
551
+ * Finalize exit: Withdraw all funds (Collateral + Rewards)
552
+ */
553
+ async withdrawAllFunds(to, options) {
554
+ const recipient = to || this.getAddress();
555
+ const hashes = [];
556
+ const stats = await this.checkReadiness();
557
+ if (stats.balance > 0n) {
558
+ const hCol = await this.withdrawCollateral(recipient, stats.balance, options);
559
+ hashes.push(hCol);
560
+ }
561
+ const client = this.getStartPublicClient();
562
+ const registry = chunkCIEYY3A6_cjs.registryActions(this.registryAddress);
563
+ const registryWriter = chunkCIEYY3A6_cjs.registryActions(this.registryAddress)(this.client);
564
+ const ROLE_PAYMASTER_SUPER = await registry(client).ROLE_PAYMASTER_SUPER();
565
+ const hasRole = await registry(client).hasRole({ user: this.getAddress(), roleId: ROLE_PAYMASTER_SUPER });
566
+ if (hasRole) {
567
+ const hExit = await registryWriter.exitRole({ roleId: ROLE_PAYMASTER_SUPER, account: options?.account });
568
+ hashes.push(hExit);
569
+ }
570
+ return hashes;
571
+ }
572
+ // Helper: Get GToken Balance
573
+ async getTokenBalance() {
574
+ if (!this.tokenAddress) return 0n;
575
+ const token = chunkCIEYY3A6_cjs.tokenActions()(this.getStartPublicClient());
576
+ return await token.balanceOf({ token: this.tokenAddress, account: this.getAddress() });
577
+ }
578
+ };
579
+
580
+ exports.OperatorLifecycle = OperatorLifecycle;
581
+ exports.PaymasterOperatorClient = PaymasterOperatorClient;
582
+ exports.ProposalState = ProposalState;
583
+ exports.ProtocolClient = ProtocolClient;
584
+ //# sourceMappingURL=chunk-IJN776TA.cjs.map
585
+ //# sourceMappingURL=chunk-IJN776TA.cjs.map