@aastar/core 0.16.7

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 (136) hide show
  1. package/LICENSE +21 -0
  2. package/dist/abis/BLSAggregator.json +686 -0
  3. package/dist/abis/BLSValidator.json +42 -0
  4. package/dist/abis/DVTValidator.json +368 -0
  5. package/dist/abis/Eip7702Support.json +24 -0
  6. package/dist/abis/EntryPoint.json +1382 -0
  7. package/dist/abis/GToken.json +513 -0
  8. package/dist/abis/GTokenStaking.json +949 -0
  9. package/dist/abis/LegacyAccount.json +625 -0
  10. package/dist/abis/MySBT.json +1518 -0
  11. package/dist/abis/Paymaster.json +1143 -0
  12. package/dist/abis/PaymasterFactory.json +640 -0
  13. package/dist/abis/Registry.json +1942 -0
  14. package/dist/abis/ReputationSystem.json +699 -0
  15. package/dist/abis/SenderCreator.json +99 -0
  16. package/dist/abis/Simple7702Account.json +395 -0
  17. package/dist/abis/SimpleAccount.json +560 -0
  18. package/dist/abis/SimpleAccountFactory.json +111 -0
  19. package/dist/abis/SimpleAccountFactoryV08.json +87 -0
  20. package/dist/abis/SimpleAccountV08.json +557 -0
  21. package/dist/abis/SuperPaymaster.json +1781 -0
  22. package/dist/abis/UserOperationLib.json +57 -0
  23. package/dist/abis/abi.config.json +24 -0
  24. package/dist/abis/index.d.ts +1126 -0
  25. package/dist/abis/index.js +91 -0
  26. package/dist/abis/xPNTsFactory.json +718 -0
  27. package/dist/abis/xPNTsToken.json +1280 -0
  28. package/dist/actions/StateValidator.d.ts +68 -0
  29. package/dist/actions/StateValidator.js +187 -0
  30. package/dist/actions/StateValidator.test.d.ts +1 -0
  31. package/dist/actions/StateValidator.test.js +144 -0
  32. package/dist/actions/account.d.ts +55 -0
  33. package/dist/actions/account.js +133 -0
  34. package/dist/actions/account.test.d.ts +1 -0
  35. package/dist/actions/account.test.js +118 -0
  36. package/dist/actions/aggregator.d.ts +17 -0
  37. package/dist/actions/aggregator.js +31 -0
  38. package/dist/actions/aggregator.test.d.ts +1 -0
  39. package/dist/actions/aggregator.test.js +67 -0
  40. package/dist/actions/dvt.d.ts +30 -0
  41. package/dist/actions/dvt.js +41 -0
  42. package/dist/actions/dvt.test.d.ts +1 -0
  43. package/dist/actions/dvt.test.js +98 -0
  44. package/dist/actions/entryPoint.d.ts +90 -0
  45. package/dist/actions/entryPoint.js +211 -0
  46. package/dist/actions/entryPoint.test.d.ts +1 -0
  47. package/dist/actions/entryPoint.test.js +139 -0
  48. package/dist/actions/factory.d.ts +215 -0
  49. package/dist/actions/factory.js +442 -0
  50. package/dist/actions/factory.test.d.ts +1 -0
  51. package/dist/actions/factory.test.js +197 -0
  52. package/dist/actions/faucet.d.ts +48 -0
  53. package/dist/actions/faucet.js +337 -0
  54. package/dist/actions/faucet.test.d.ts +1 -0
  55. package/dist/actions/faucet.test.js +120 -0
  56. package/dist/actions/gtokenExtended.d.ts +39 -0
  57. package/dist/actions/gtokenExtended.js +115 -0
  58. package/dist/actions/gtokenExtended.test.d.ts +1 -0
  59. package/dist/actions/gtokenExtended.test.js +118 -0
  60. package/dist/actions/index.d.ts +15 -0
  61. package/dist/actions/index.js +17 -0
  62. package/dist/actions/paymasterV4.d.ts +170 -0
  63. package/dist/actions/paymasterV4.js +334 -0
  64. package/dist/actions/paymasterV4.test.d.ts +1 -0
  65. package/dist/actions/paymasterV4.test.js +159 -0
  66. package/dist/actions/registry.d.ts +246 -0
  67. package/dist/actions/registry.js +667 -0
  68. package/dist/actions/registry.test.d.ts +1 -0
  69. package/dist/actions/registry.test.js +360 -0
  70. package/dist/actions/reputation.d.ts +129 -0
  71. package/dist/actions/reputation.js +281 -0
  72. package/dist/actions/reputation.test.d.ts +1 -0
  73. package/dist/actions/reputation.test.js +169 -0
  74. package/dist/actions/sbt.d.ts +191 -0
  75. package/dist/actions/sbt.js +533 -0
  76. package/dist/actions/sbt.test.d.ts +1 -0
  77. package/dist/actions/sbt.test.js +256 -0
  78. package/dist/actions/staking.d.ts +132 -0
  79. package/dist/actions/staking.js +330 -0
  80. package/dist/actions/staking.test.d.ts +1 -0
  81. package/dist/actions/staking.test.js +223 -0
  82. package/dist/actions/superPaymaster.d.ts +237 -0
  83. package/dist/actions/superPaymaster.js +644 -0
  84. package/dist/actions/superPaymaster.test.d.ts +1 -0
  85. package/dist/actions/superPaymaster.test.js +287 -0
  86. package/dist/actions/tokens.d.ts +229 -0
  87. package/dist/actions/tokens.js +415 -0
  88. package/dist/actions/tokens.test.d.ts +1 -0
  89. package/dist/actions/tokens.test.js +53 -0
  90. package/dist/actions/validators.d.ts +194 -0
  91. package/dist/actions/validators.js +433 -0
  92. package/dist/actions/validators.test.d.ts +1 -0
  93. package/dist/actions/validators.test.js +215 -0
  94. package/dist/branding.d.ts +30 -0
  95. package/dist/branding.js +30 -0
  96. package/dist/clients/BaseClient.d.ts +25 -0
  97. package/dist/clients/BaseClient.js +66 -0
  98. package/dist/clients/types.d.ts +60 -0
  99. package/dist/clients/types.js +1 -0
  100. package/dist/clients.d.ts +5 -0
  101. package/dist/clients.js +11 -0
  102. package/dist/communities.d.ts +52 -0
  103. package/dist/communities.js +73 -0
  104. package/dist/config/ContractConfigManager.d.ts +20 -0
  105. package/dist/config/ContractConfigManager.js +48 -0
  106. package/dist/constants.d.ts +88 -0
  107. package/dist/constants.js +125 -0
  108. package/dist/contract-addresses.d.ts +110 -0
  109. package/dist/contract-addresses.js +99 -0
  110. package/dist/contracts.d.ts +424 -0
  111. package/dist/contracts.js +343 -0
  112. package/dist/contracts.test.d.ts +1 -0
  113. package/dist/contracts.test.js +40 -0
  114. package/dist/crypto/blsSigner.d.ts +64 -0
  115. package/dist/crypto/blsSigner.js +98 -0
  116. package/dist/crypto/index.d.ts +1 -0
  117. package/dist/crypto/index.js +1 -0
  118. package/dist/index.d.ts +21 -0
  119. package/dist/index.js +21 -0
  120. package/dist/networks.d.ts +127 -0
  121. package/dist/networks.js +118 -0
  122. package/dist/requirementChecker.d.ts +38 -0
  123. package/dist/requirementChecker.js +139 -0
  124. package/dist/requirementChecker.test.d.ts +1 -0
  125. package/dist/requirementChecker.test.js +60 -0
  126. package/dist/roles.d.ts +204 -0
  127. package/dist/roles.js +211 -0
  128. package/dist/roles.test.d.ts +1 -0
  129. package/dist/roles.test.js +23 -0
  130. package/dist/utils/validation.d.ts +24 -0
  131. package/dist/utils/validation.js +56 -0
  132. package/dist/utils/validation.test.d.ts +1 -0
  133. package/dist/utils/validation.test.js +40 -0
  134. package/dist/utils.d.ts +12 -0
  135. package/dist/utils.js +14 -0
  136. package/package.json +33 -0
@@ -0,0 +1,442 @@
1
+ import { parseEther } from 'viem';
2
+ import { xPNTsFactoryABI, PaymasterFactoryABI } from '../abis/index.js';
3
+ export const xPNTsFactoryActions = (address) => (client) => ({
4
+ async createToken({ name, symbol, community, account }) {
5
+ // Map to deployxPNTsToken
6
+ // Args: name, symbol, communityName, communityENS, exchangeRate, paymasterAOA
7
+ // We use name/symbol as community name/ens placeholder if not provided
8
+ // We assume msg.sender (account) is the community owner
9
+ return client.writeContract({
10
+ address,
11
+ abi: xPNTsFactoryABI,
12
+ functionName: 'deployxPNTsToken',
13
+ args: [
14
+ name,
15
+ symbol,
16
+ name, // communityName
17
+ symbol, // communityENS
18
+ parseEther('1'), // exchangeRate: 1:1 with 18 decimals (1e18)
19
+ '0x0000000000000000000000000000000000000000' // paymasterAOA
20
+ ],
21
+ account: account,
22
+ chain: client.chain
23
+ });
24
+ },
25
+ async deployForCommunity({ community, account }) {
26
+ return client.writeContract({
27
+ address,
28
+ abi: xPNTsFactoryABI,
29
+ functionName: 'deployForCommunity',
30
+ args: [community],
31
+ account: account,
32
+ chain: client.chain
33
+ });
34
+ },
35
+ async getTokenAddress({ community }) {
36
+ return client.readContract({
37
+ address,
38
+ abi: xPNTsFactoryABI,
39
+ functionName: 'getTokenAddress',
40
+ args: [community]
41
+ });
42
+ },
43
+ async predictAddress({ community, salt }) {
44
+ return client.readContract({
45
+ address,
46
+ abi: xPNTsFactoryABI,
47
+ functionName: 'predictAddress',
48
+ args: salt !== undefined ? [community, salt] : [community]
49
+ });
50
+ },
51
+ async isTokenDeployed({ community }) {
52
+ return client.readContract({
53
+ address,
54
+ abi: xPNTsFactoryABI,
55
+ functionName: 'isTokenDeployed',
56
+ args: [community]
57
+ });
58
+ },
59
+ async getCommunityByToken({ token }) {
60
+ return client.readContract({
61
+ address,
62
+ abi: xPNTsFactoryABI,
63
+ functionName: 'getCommunityByToken',
64
+ args: [token]
65
+ });
66
+ },
67
+ async getAllTokens() {
68
+ return client.readContract({
69
+ address,
70
+ abi: xPNTsFactoryABI,
71
+ functionName: 'getAllTokens',
72
+ args: []
73
+ });
74
+ },
75
+ async getTokenCount() {
76
+ return client.readContract({
77
+ address,
78
+ abi: xPNTsFactoryABI,
79
+ functionName: 'getTokenCount',
80
+ args: []
81
+ });
82
+ },
83
+ async deployedTokens({ index }) {
84
+ return client.readContract({
85
+ address,
86
+ abi: xPNTsFactoryABI,
87
+ functionName: 'deployedTokens',
88
+ args: [index]
89
+ });
90
+ },
91
+ async communityToToken({ community }) {
92
+ return client.readContract({
93
+ address,
94
+ abi: xPNTsFactoryABI,
95
+ functionName: 'communityToToken',
96
+ args: [community]
97
+ });
98
+ },
99
+ async setRegistry({ registry, account }) {
100
+ return client.writeContract({
101
+ address,
102
+ abi: xPNTsFactoryABI,
103
+ functionName: 'setRegistry',
104
+ args: [registry],
105
+ account: account,
106
+ chain: client.chain
107
+ });
108
+ },
109
+ async setSuperPaymaster({ paymaster, account }) {
110
+ return client.writeContract({
111
+ address,
112
+ abi: xPNTsFactoryABI,
113
+ functionName: 'setSuperPaymaster',
114
+ args: [paymaster],
115
+ account: account,
116
+ chain: client.chain
117
+ });
118
+ },
119
+ async setImplementation({ impl, account }) {
120
+ return client.writeContract({
121
+ address,
122
+ abi: xPNTsFactoryABI,
123
+ functionName: 'setImplementation',
124
+ args: [impl],
125
+ account: account,
126
+ chain: client.chain
127
+ });
128
+ },
129
+ async getImplementation() {
130
+ return client.readContract({
131
+ address,
132
+ abi: xPNTsFactoryABI,
133
+ functionName: 'getImplementation',
134
+ args: []
135
+ });
136
+ },
137
+ async REGISTRY() {
138
+ return client.readContract({
139
+ address,
140
+ abi: xPNTsFactoryABI,
141
+ functionName: 'REGISTRY',
142
+ args: []
143
+ });
144
+ },
145
+ async tokenImplementation() {
146
+ return client.readContract({
147
+ address,
148
+ abi: xPNTsFactoryABI,
149
+ functionName: 'tokenImplementation',
150
+ args: []
151
+ });
152
+ },
153
+ async xPNTsFactoryOwner() {
154
+ return client.readContract({
155
+ address,
156
+ abi: xPNTsFactoryABI,
157
+ functionName: 'owner',
158
+ args: []
159
+ });
160
+ },
161
+ async transferXPNTsFactoryOwnership({ newOwner, account }) {
162
+ return client.writeContract({
163
+ address,
164
+ abi: xPNTsFactoryABI,
165
+ functionName: 'transferOwnership',
166
+ args: [newOwner],
167
+ account: account,
168
+ chain: client.chain
169
+ });
170
+ },
171
+ async renounceXPNTsFactoryOwnership({ account }) {
172
+ return client.writeContract({
173
+ address,
174
+ abi: xPNTsFactoryABI,
175
+ functionName: 'renounceOwnership',
176
+ args: [],
177
+ account: account,
178
+ chain: client.chain
179
+ });
180
+ },
181
+ async deployxPNTsToken(args) {
182
+ return this.createToken(args);
183
+ },
184
+ // Prediction & Economics
185
+ async predictDepositAmount({ community, userCount }) {
186
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'predictDepositAmount', args: [community, userCount] });
187
+ },
188
+ async getPredictionParams({ community }) {
189
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'getPredictionParams', args: [community] });
190
+ },
191
+ async getDepositBreakdown({ community }) {
192
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'getDepositBreakdown', args: [community] });
193
+ },
194
+ async getAPNTsPrice() {
195
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'getAPNTsPrice', args: [] });
196
+ },
197
+ async aPNTsPriceUSD() {
198
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'aPNTsPriceUSD', args: [] });
199
+ },
200
+ async SUPER_PAYMASTER() {
201
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'SUPER_PAYMASTER', args: [] });
202
+ },
203
+ async SUPERPAYMASTER() {
204
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'SUPERPAYMASTER', args: [] });
205
+ },
206
+ // Admin & Config
207
+ async setIndustryMultiplier({ industry, multiplier, account }) {
208
+ return client.writeContract({ address, abi: xPNTsFactoryABI, functionName: 'setIndustryMultiplier', args: [industry, multiplier], account: account, chain: client.chain });
209
+ },
210
+ async setSuperPaymasterAddress({ paymaster, account }) {
211
+ return client.writeContract({ address, abi: xPNTsFactoryABI, functionName: 'setSuperPaymasterAddress', args: [paymaster], account: account, chain: client.chain });
212
+ },
213
+ async updateAPNTsPrice({ newPrice, account }) {
214
+ return client.writeContract({ address, abi: xPNTsFactoryABI, functionName: 'updateAPNTsPrice', args: [newPrice], account: account, chain: client.chain });
215
+ },
216
+ async updatePrediction({ community, userCount, account }) {
217
+ return client.writeContract({ address, abi: xPNTsFactoryABI, functionName: 'updatePrediction', args: [community, userCount], account: account, chain: client.chain });
218
+ },
219
+ async updatePredictionCustom({ community, params, account }) {
220
+ return client.writeContract({ address, abi: xPNTsFactoryABI, functionName: 'updatePredictionCustom', args: [community, params], account: account, chain: client.chain });
221
+ },
222
+ // Views
223
+ async hasToken({ token }) {
224
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'hasToken', args: [token] });
225
+ },
226
+ async getDeployedCount() {
227
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'getDeployedCount', args: [] });
228
+ },
229
+ async industryMultipliers({ industry }) {
230
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'industryMultipliers', args: [industry] });
231
+ },
232
+ async getIndustryMultiplier({ industry }) {
233
+ return this.industryMultipliers({ industry });
234
+ },
235
+ async predictions({ community }) {
236
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'predictions', args: [community] });
237
+ },
238
+ // Constants
239
+ async DEFAULT_SAFETY_FACTOR() {
240
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'DEFAULT_SAFETY_FACTOR', args: [] });
241
+ },
242
+ async MIN_SUGGESTED_AMOUNT() {
243
+ return client.readContract({ address, abi: xPNTsFactoryABI, functionName: 'MIN_SUGGESTED_AMOUNT', args: [] });
244
+ },
245
+ async xPNTsFactoryVersion() {
246
+ return client.readContract({
247
+ address,
248
+ abi: xPNTsFactoryABI,
249
+ functionName: 'version',
250
+ args: []
251
+ });
252
+ }
253
+ });
254
+ export const paymasterFactoryActions = (address) => (client) => ({
255
+ async deployPaymaster({ owner, version, initData, account }) {
256
+ // Factory.deployPaymaster(version, initData)
257
+ const defaultVer = 'v4.2'; // 当前标准版本
258
+ const useVer = version || defaultVer;
259
+ return client.writeContract({
260
+ address,
261
+ abi: PaymasterFactoryABI,
262
+ functionName: 'deployPaymaster',
263
+ args: [useVer, initData || '0x'],
264
+ account: account,
265
+ chain: client.chain
266
+ });
267
+ },
268
+ async deployPaymasterDeterministic({ owner, version, initData, salt, account }) {
269
+ return client.writeContract({ address, abi: PaymasterFactoryABI, functionName: 'deployPaymasterDeterministic', args: [version || 'v4.2', initData || '0x', salt], account: account, chain: client.chain });
270
+ },
271
+ async predictPaymasterAddress({ owner, salt }) {
272
+ // Note: Contract might not have this function exposed directly or it is separate logic
273
+ // But ABI says it's missing, so let's try calling it if it exists in ABI
274
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'predictPaymasterAddress', args: [owner, salt] });
275
+ },
276
+ async calculateAddress({ owner }) {
277
+ // This function doesn't exist in V4 factory for non-deterministic deploy
278
+ // We throw to avoid misleading usage
279
+ throw new Error('Predicting address not supported for standard deploy. Use getPaymaster after deploy.');
280
+ },
281
+ async getPaymaster({ owner }) {
282
+ // 使用 paymasterByOperator mapping(不支持 salt)
283
+ return client.readContract({
284
+ address,
285
+ abi: PaymasterFactoryABI,
286
+ functionName: 'paymasterByOperator',
287
+ args: [owner]
288
+ });
289
+ },
290
+ async getPaymasterCount() {
291
+ return client.readContract({
292
+ address,
293
+ abi: PaymasterFactoryABI,
294
+ functionName: 'getPaymasterCount',
295
+ args: []
296
+ });
297
+ },
298
+ async getAllPaymasters() {
299
+ // Not directly supported by contract as single call (it has list + pagination), using pagination shim
300
+ const count = await client.readContract({
301
+ address, abi: PaymasterFactoryABI, functionName: 'getPaymasterCount', args: []
302
+ });
303
+ return client.readContract({
304
+ address,
305
+ abi: PaymasterFactoryABI,
306
+ functionName: 'getPaymasterList',
307
+ args: [0n, count]
308
+ });
309
+ },
310
+ async isPaymasterDeployed({ owner }) {
311
+ return client.readContract({
312
+ address,
313
+ abi: PaymasterFactoryABI,
314
+ functionName: 'hasPaymaster', // Corrected from isPaymasterDeployed
315
+ args: [owner]
316
+ });
317
+ },
318
+ async hasPaymaster({ owner }) { return this.isPaymasterDeployed({ owner }); },
319
+ async getPaymasterList({ offset, limit }) {
320
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'getPaymasterList', args: [offset, limit] });
321
+ },
322
+ async paymasterList({ index }) {
323
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'paymasterList', args: [index] });
324
+ },
325
+ async totalDeployed() {
326
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'totalDeployed', args: [] });
327
+ },
328
+ async getOperatorByPaymaster({ paymaster }) {
329
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'getOperatorByPaymaster', args: [paymaster] });
330
+ },
331
+ async operatorByPaymaster({ paymaster }) { return this.getOperatorByPaymaster({ paymaster }); },
332
+ async getPaymasterByOperator({ operator }) {
333
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'getPaymasterByOperator', args: [operator] });
334
+ },
335
+ async paymasterByOperator({ operator }) { return this.getPaymasterByOperator({ operator }); },
336
+ async getPaymasterInfo({ paymaster }) {
337
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'getPaymasterInfo', args: [paymaster] });
338
+ },
339
+ async hasImplementation({ version }) {
340
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'hasImplementation', args: [version] });
341
+ },
342
+ async implementations({ version }) {
343
+ return client.readContract({ address, abi: PaymasterFactoryABI, functionName: 'implementations', args: [version] });
344
+ },
345
+ async setImplementationV4({ impl, account }) {
346
+ return client.writeContract({
347
+ address,
348
+ abi: PaymasterFactoryABI,
349
+ functionName: 'setImplementationV4',
350
+ args: [impl],
351
+ account: account,
352
+ chain: client.chain
353
+ });
354
+ },
355
+ async getImplementationV4() {
356
+ return client.readContract({
357
+ address,
358
+ abi: PaymasterFactoryABI,
359
+ functionName: 'getImplementationV4',
360
+ args: []
361
+ });
362
+ },
363
+ async setRegistry({ registry, account }) {
364
+ return client.writeContract({
365
+ address,
366
+ abi: PaymasterFactoryABI,
367
+ functionName: 'setRegistry',
368
+ args: [registry],
369
+ account: account,
370
+ chain: client.chain
371
+ });
372
+ },
373
+ async addImplementation({ version, implementation, account }) {
374
+ return client.writeContract({ address, abi: PaymasterFactoryABI, functionName: 'addImplementation', args: [version, implementation], account: account, chain: client.chain });
375
+ },
376
+ async upgradeImplementation({ version, newImplementation, account }) {
377
+ return client.writeContract({ address, abi: PaymasterFactoryABI, functionName: 'upgradeImplementation', args: [version, newImplementation], account: account, chain: client.chain });
378
+ },
379
+ async setDefaultVersion({ version, account }) {
380
+ return client.writeContract({ address, abi: PaymasterFactoryABI, functionName: 'setDefaultVersion', args: [version], account: account, chain: client.chain });
381
+ },
382
+ async REGISTRY() {
383
+ return client.readContract({
384
+ address,
385
+ abi: PaymasterFactoryABI,
386
+ functionName: 'REGISTRY',
387
+ args: []
388
+ });
389
+ },
390
+ async ENTRY_POINT() {
391
+ return client.readContract({
392
+ address,
393
+ abi: PaymasterFactoryABI,
394
+ functionName: 'ENTRY_POINT',
395
+ args: []
396
+ });
397
+ },
398
+ async paymasterFactoryOwner() {
399
+ return client.readContract({
400
+ address,
401
+ abi: PaymasterFactoryABI,
402
+ functionName: 'owner',
403
+ args: []
404
+ });
405
+ },
406
+ async transferPaymasterFactoryOwnership({ newOwner, account }) {
407
+ return client.writeContract({
408
+ address,
409
+ abi: PaymasterFactoryABI,
410
+ functionName: 'transferOwnership',
411
+ args: [newOwner],
412
+ account: account,
413
+ chain: client.chain
414
+ });
415
+ },
416
+ async renouncePaymasterFactoryOwnership({ account }) {
417
+ return client.writeContract({
418
+ address,
419
+ abi: PaymasterFactoryABI,
420
+ functionName: 'renounceOwnership',
421
+ args: [],
422
+ account: account,
423
+ chain: client.chain
424
+ });
425
+ },
426
+ async defaultVersion() {
427
+ return client.readContract({
428
+ address,
429
+ abi: PaymasterFactoryABI,
430
+ functionName: 'defaultVersion',
431
+ args: []
432
+ });
433
+ },
434
+ async paymasterFactoryVersion() {
435
+ return client.readContract({
436
+ address,
437
+ abi: PaymasterFactoryABI,
438
+ functionName: 'version',
439
+ args: []
440
+ });
441
+ }
442
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,197 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { xPNTsFactoryActions, paymasterFactoryActions } from './factory.js';
3
+ describe('Factory Actions', () => {
4
+ let mockPublicClient;
5
+ let mockWalletClient;
6
+ let mockAccount;
7
+ const MOCK_FACTORY = '0x1111111111111111111111111111111111111111';
8
+ const MOCK_COMMUNITY = '0x2222222222222222222222222222222222222222';
9
+ const MOCK_USER = '0x3333333333333333333333333333333333333333';
10
+ beforeEach(() => {
11
+ mockAccount = {
12
+ address: MOCK_USER,
13
+ type: 'json-rpc'
14
+ };
15
+ mockPublicClient = {
16
+ readContract: vi.fn(),
17
+ };
18
+ mockWalletClient = {
19
+ writeContract: vi.fn(),
20
+ account: mockAccount,
21
+ };
22
+ });
23
+ describe('xPNTsFactoryActions', () => {
24
+ it('should create token', async () => {
25
+ const txHash = '0xhash';
26
+ mockWalletClient.writeContract.mockResolvedValue(txHash);
27
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockWalletClient);
28
+ const result = await actions.createToken({
29
+ name: 'Test',
30
+ symbol: 'TST',
31
+ community: MOCK_COMMUNITY,
32
+ account: mockAccount
33
+ });
34
+ expect(result).toBe(txHash);
35
+ expect(mockWalletClient.writeContract).toHaveBeenCalledWith(expect.objectContaining({
36
+ functionName: 'deployxPNTsToken',
37
+ }));
38
+ });
39
+ it('should get token address', async () => {
40
+ const mockToken = '0xTOKEN';
41
+ mockPublicClient.readContract.mockResolvedValue(mockToken);
42
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockPublicClient);
43
+ const result = await actions.getTokenAddress({ community: MOCK_COMMUNITY });
44
+ expect(result).toBe(mockToken);
45
+ });
46
+ it('should predict address', async () => {
47
+ const mockToken = '0xPREDICTED';
48
+ mockPublicClient.readContract.mockResolvedValue(mockToken);
49
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockPublicClient);
50
+ const result = await actions.predictAddress({ community: MOCK_COMMUNITY, salt: 1234n });
51
+ expect(result).toBe(mockToken);
52
+ });
53
+ it('should check if token is deployed', async () => {
54
+ mockPublicClient.readContract.mockResolvedValue(true);
55
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockPublicClient);
56
+ const result = await actions.isTokenDeployed({ community: MOCK_COMMUNITY });
57
+ expect(result).toBe(true);
58
+ });
59
+ it('should handle predictions and economics', async () => {
60
+ mockPublicClient.readContract
61
+ .mockResolvedValueOnce(100n) // predictDepositAmount
62
+ .mockResolvedValueOnce([1n, 2n, 3n]) // getPredictionParams
63
+ .mockResolvedValueOnce(50n); // getAPNTsPrice
64
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockPublicClient);
65
+ expect(await actions.predictDepositAmount({ community: MOCK_COMMUNITY, userCount: 10n })).toBe(100n);
66
+ expect(await actions.getPredictionParams({ community: MOCK_COMMUNITY })).toEqual([1n, 2n, 3n]);
67
+ expect(await actions.getAPNTsPrice()).toBe(50n);
68
+ });
69
+ it('should manage configuration', async () => {
70
+ const txHash = '0xhash';
71
+ mockWalletClient.writeContract.mockResolvedValue(txHash);
72
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockWalletClient);
73
+ expect(await actions.setIndustryMultiplier({ industry: 'tech', multiplier: 2n, account: mockAccount })).toBe(txHash);
74
+ expect(await actions.setSuperPaymasterAddress({ paymaster: MOCK_USER, account: mockAccount })).toBe(txHash);
75
+ expect(await actions.updateAPNTsPrice({ newPrice: 100n, account: mockAccount })).toBe(txHash);
76
+ });
77
+ it('should view config', async () => {
78
+ mockPublicClient.readContract
79
+ .mockResolvedValueOnce(123n) // industryMultipliers
80
+ .mockResolvedValueOnce(MOCK_USER); // SUPER_PAYMASTER
81
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockPublicClient);
82
+ expect(await actions.industryMultipliers({ industry: 'tech' })).toBe(123n);
83
+ expect(await actions.SUPER_PAYMASTER()).toBe(MOCK_USER);
84
+ });
85
+ });
86
+ describe('paymasterFactoryActions', () => {
87
+ it('should deploy for community', async () => {
88
+ const txHash = '0xhash';
89
+ mockWalletClient.writeContract.mockResolvedValue(txHash);
90
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockWalletClient);
91
+ const result = await actions.deployForCommunity({ community: MOCK_COMMUNITY, account: mockAccount });
92
+ expect(result).toBe(txHash);
93
+ });
94
+ it('should query tokens and stats', async () => {
95
+ mockPublicClient.readContract
96
+ .mockResolvedValueOnce(MOCK_COMMUNITY) // getCommunityByToken
97
+ .mockResolvedValueOnce(['0xT1']) // getAllTokens
98
+ .mockResolvedValueOnce(1n) // getTokenCount
99
+ .mockResolvedValueOnce('0xT1'); // deployedTokens
100
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockPublicClient);
101
+ expect(await actions.getCommunityByToken({ token: '0xT' })).toBe(MOCK_COMMUNITY);
102
+ expect(await actions.getAllTokens()).toEqual(['0xT1']);
103
+ expect(await actions.getTokenCount()).toBe(1n);
104
+ expect(await actions.deployedTokens({ index: 0n })).toBe('0xT1');
105
+ });
106
+ it('should manage implementation and configuration', async () => {
107
+ const txHash = '0xhash';
108
+ mockWalletClient.writeContract.mockResolvedValue(txHash);
109
+ mockPublicClient.readContract.mockResolvedValue(MOCK_USER);
110
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockWalletClient);
111
+ expect(await actions.setImplementation({ impl: MOCK_USER, account: mockAccount })).toBe(txHash);
112
+ expect(await actions.setRegistry({ registry: MOCK_USER, account: mockAccount })).toBe(txHash);
113
+ expect(await actions.setSuperPaymaster({ paymaster: MOCK_USER, account: mockAccount })).toBe(txHash);
114
+ const pClient = xPNTsFactoryActions(MOCK_FACTORY)(mockPublicClient);
115
+ expect(await pClient.getImplementation()).toBe(MOCK_USER);
116
+ expect(await pClient.REGISTRY()).toBe(MOCK_USER);
117
+ expect(await pClient.SUPER_PAYMASTER()).toBe(MOCK_USER);
118
+ });
119
+ it('should handle ownership and version', async () => {
120
+ mockPublicClient.readContract.mockResolvedValue(MOCK_USER);
121
+ const actions = xPNTsFactoryActions(MOCK_FACTORY)(mockPublicClient);
122
+ expect(await actions.xPNTsFactoryOwner()).toBe(MOCK_USER);
123
+ mockPublicClient.readContract.mockResolvedValue('v1');
124
+ expect(await actions.xPNTsFactoryVersion()).toBe('v1');
125
+ });
126
+ });
127
+ describe('paymasterFactoryActions', () => {
128
+ it('should deploy paymaster', async () => {
129
+ const txHash = '0xhash';
130
+ mockWalletClient.writeContract.mockResolvedValue(txHash);
131
+ const actions = paymasterFactoryActions(MOCK_FACTORY)(mockWalletClient);
132
+ const result = await actions.deployPaymaster({
133
+ owner: MOCK_USER,
134
+ account: mockAccount
135
+ });
136
+ expect(result).toBe(txHash);
137
+ });
138
+ it('should get paymaster by operator', async () => {
139
+ const mockPM = '0xPAYMASTER';
140
+ mockPublicClient.readContract.mockResolvedValue(mockPM);
141
+ const actions = paymasterFactoryActions(MOCK_FACTORY)(mockPublicClient);
142
+ const result = await actions.getPaymaster({ owner: MOCK_USER });
143
+ expect(result).toBe(mockPM);
144
+ });
145
+ it('should get all paymasters', async () => {
146
+ mockPublicClient.readContract
147
+ .mockResolvedValueOnce(2n) // count
148
+ .mockResolvedValueOnce(['0xPM1', '0xPM2']); // list
149
+ const actions = paymasterFactoryActions(MOCK_FACTORY)(mockPublicClient);
150
+ const result = await actions.getAllPaymasters();
151
+ expect(result).toEqual(['0xPM1', '0xPM2']);
152
+ });
153
+ it('should manage implementation and registry', async () => {
154
+ const txHash = '0xhash';
155
+ mockWalletClient.writeContract.mockResolvedValue(txHash);
156
+ mockPublicClient.readContract.mockResolvedValue(MOCK_USER);
157
+ const actions = paymasterFactoryActions(MOCK_FACTORY)(mockWalletClient);
158
+ expect(await actions.setImplementationV4({ impl: MOCK_USER, account: mockAccount })).toBe(txHash);
159
+ expect(await actions.setRegistry({ registry: MOCK_USER, account: mockAccount })).toBe(txHash);
160
+ const pClient = paymasterFactoryActions(MOCK_FACTORY)(mockPublicClient);
161
+ expect(await pClient.getImplementationV4()).toBe(MOCK_USER);
162
+ expect(await pClient.REGISTRY()).toBe(MOCK_USER);
163
+ expect(await pClient.ENTRY_POINT()).toBe(MOCK_USER);
164
+ });
165
+ it('should check if paymaster is deployed', async () => {
166
+ mockPublicClient.readContract.mockResolvedValue(true);
167
+ const actions = paymasterFactoryActions(MOCK_FACTORY)(mockPublicClient);
168
+ const result = await actions.isPaymasterDeployed({ owner: MOCK_USER });
169
+ expect(result).toBe(true);
170
+ });
171
+ it('should get versions and ownership', async () => {
172
+ mockPublicClient.readContract.mockResolvedValue('v1');
173
+ const actions = paymasterFactoryActions(MOCK_FACTORY)(mockPublicClient);
174
+ expect(await actions.paymasterFactoryVersion()).toBe('v1');
175
+ expect(await actions.defaultVersion()).toBe('v1');
176
+ mockPublicClient.readContract.mockResolvedValue(MOCK_USER);
177
+ expect(await actions.paymasterFactoryOwner()).toBe(MOCK_USER);
178
+ });
179
+ it('should handle implementations list', async () => {
180
+ mockPublicClient.readContract
181
+ .mockResolvedValueOnce(true) // implementations
182
+ .mockResolvedValueOnce(['0xI1']) // getPaymasterList
183
+ .mockResolvedValueOnce(5n); // totalDeployed
184
+ const actions = paymasterFactoryActions(MOCK_FACTORY)(mockPublicClient);
185
+ expect(await actions.implementations({ version: 'v1' })).toBe(true);
186
+ expect(await actions.getPaymasterList({ offset: 0n, limit: 10n })).toEqual(['0xI1']);
187
+ expect(await actions.totalDeployed()).toBe(5n);
188
+ });
189
+ it('should manage implementations', async () => {
190
+ const txHash = '0xhash';
191
+ mockWalletClient.writeContract.mockResolvedValue(txHash);
192
+ const actions = paymasterFactoryActions(MOCK_FACTORY)(mockWalletClient);
193
+ expect(await actions.addImplementation({ version: 'v2', implementation: MOCK_USER, account: mockAccount })).toBe(txHash);
194
+ expect(await actions.setDefaultVersion({ version: 'v2', account: mockAccount })).toBe(txHash);
195
+ });
196
+ });
197
+ });
@@ -0,0 +1,48 @@
1
+ import { type Address, type WalletClient, type PublicClient } from 'viem';
2
+ export declare class SepoliaFaucetAPI {
3
+ /**
4
+ * Orchestrates the complete setup for a test account.
5
+ * 1. Funds ETH
6
+ * 2. Registers ENDUSER role
7
+ * 3. Mints potential Paymaster Tokens (cPNTs/dPNTs)
8
+ * 4. Deposits to Paymaster V4 (if address provided) using Admin's tokens
9
+ */
10
+ static prepareTestAccount(adminWallet: WalletClient, publicClient: PublicClient, config: {
11
+ targetAA: Address;
12
+ token: Address;
13
+ registry: Address;
14
+ paymasterV4?: Address;
15
+ superPaymaster?: Address;
16
+ ethAmount?: bigint;
17
+ tokenAmount?: bigint;
18
+ community?: Address;
19
+ }): Promise<{
20
+ ethFunded: boolean;
21
+ roleRegistered: boolean;
22
+ tokenMinted: boolean;
23
+ paymasterDeposited: boolean;
24
+ }>;
25
+ /**
26
+ * Funds the target with ETH if balance is below threshold.
27
+ */
28
+ static fundETH(adminWallet: WalletClient, publicClient: PublicClient, target: Address, amount: bigint): Promise<boolean>;
29
+ /**
30
+ * Registers the ENDUSER role via Registry.
31
+ */
32
+ /**
33
+ * Registers the ENDUSER role using Sponsor Mode (Admin pays stake).
34
+ */
35
+ static registerEndUser(adminWallet: WalletClient, publicClient: PublicClient, registryAddr: Address, target: Address, gasToken: Address, // Re-using the 'token' passed in config which is GToken
36
+ community?: Address): Promise<boolean>;
37
+ /**
38
+ * Mints tokens directly to the target.
39
+ */
40
+ static mintTestTokens(adminWallet: WalletClient, publicClient: PublicClient, token: Address, target: Address, amount: bigint): Promise<boolean>;
41
+ /**
42
+ * Complex Flow:
43
+ * 1. Admin mints tokens to SELF.
44
+ * 2. Admin approves Paymaster.
45
+ * 3. Admin calls depositFor(target) on Paymaster.
46
+ */
47
+ static adminDepositForUser(adminWallet: WalletClient, publicClient: PublicClient, paymaster: Address, target: Address, token: Address, amount: bigint): Promise<boolean>;
48
+ }