@aastar/core 0.16.7 → 0.16.11

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 (60) hide show
  1. package/dist/abis/PaymasterV4_2.json +1193 -0
  2. package/dist/abis/SuperPaymaster.json +1 -1
  3. package/dist/abis/aPNTs.json +1160 -0
  4. package/dist/abis/abi.config.json +3 -3
  5. package/dist/abis/index.d.ts +15 -104
  6. package/dist/abis/index.js +22 -46
  7. package/dist/actions/account.d.ts +0 -15
  8. package/dist/actions/account.js +143 -108
  9. package/dist/actions/aggregator.d.ts +68 -7
  10. package/dist/actions/aggregator.js +328 -28
  11. package/dist/actions/dvt.d.ts +33 -5
  12. package/dist/actions/dvt.js +238 -38
  13. package/dist/actions/entryPoint.d.ts +3 -63
  14. package/dist/actions/entryPoint.js +52 -184
  15. package/dist/actions/factory.d.ts +48 -115
  16. package/dist/actions/factory.js +638 -438
  17. package/dist/actions/faucet.d.ts +23 -27
  18. package/dist/actions/faucet.js +150 -289
  19. package/dist/actions/index.d.ts +1 -2
  20. package/dist/actions/index.js +2 -4
  21. package/dist/actions/paymaster.d.ts +147 -0
  22. package/dist/actions/paymaster.js +706 -0
  23. package/dist/actions/paymasterV4.d.ts +26 -95
  24. package/dist/actions/paymasterV4.js +28 -121
  25. package/dist/actions/registry.d.ts +116 -165
  26. package/dist/actions/registry.js +855 -654
  27. package/dist/actions/reputation.d.ts +74 -52
  28. package/dist/actions/reputation.js +548 -242
  29. package/dist/actions/sbt.d.ts +90 -100
  30. package/dist/actions/sbt.js +801 -518
  31. package/dist/actions/staking.d.ts +45 -32
  32. package/dist/actions/staking.js +431 -260
  33. package/dist/actions/superPaymaster.d.ts +140 -158
  34. package/dist/actions/superPaymaster.js +965 -631
  35. package/dist/actions/tokens.d.ts +130 -108
  36. package/dist/actions/tokens.js +470 -414
  37. package/dist/actions/validators.d.ts +0 -73
  38. package/dist/actions/validators.js +0 -94
  39. package/dist/clients/BaseClient.d.ts +3 -3
  40. package/dist/clients/BundlerClient.d.ts +55 -0
  41. package/dist/clients/BundlerClient.js +92 -0
  42. package/dist/communities.js +2 -2
  43. package/dist/constants.js +1 -28
  44. package/dist/contract-addresses.d.ts +5 -14
  45. package/dist/contract-addresses.js +3 -9
  46. package/dist/contract-versions.d.ts +138 -0
  47. package/dist/contract-versions.js +328 -0
  48. package/dist/contracts.d.ts +6 -24
  49. package/dist/contracts.js +2 -2
  50. package/dist/errors/index.d.ts +57 -0
  51. package/dist/errors/index.js +123 -0
  52. package/dist/index.d.ts +2 -1
  53. package/dist/index.js +2 -1
  54. package/dist/requirementChecker.d.ts +35 -1
  55. package/dist/requirementChecker.js +39 -1
  56. package/dist/roles.d.ts +50 -61
  57. package/dist/roles.js +50 -61
  58. package/dist/validators/index.d.ts +35 -0
  59. package/dist/validators/index.js +60 -0
  60. package/package.json +5 -13
@@ -1,415 +1,471 @@
1
1
  import { GTokenABI, xPNTsTokenABI } from '../abis/index.js';
2
- function getTokenABI(token) {
3
- // Auto-detect ABI based on token type or use generic xPNTsTokenABI
4
- return xPNTsTokenABI;
5
- }
6
- export const gTokenActions = () => (client) => ({
7
- // Use GTokenABI for everything
8
- ...tokenActions()(client),
9
- async tokenTotalSupply({ token }) {
10
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'totalSupply', args: [] });
11
- },
12
- async tokenBalanceOf({ token, account }) {
13
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'balanceOf', args: [account] });
14
- },
15
- async tokenTransfer({ token, to, amount, account }) {
16
- return client.writeContract({ address: token, abi: GTokenABI, functionName: 'transfer', args: [to, amount], account: account, chain: client.chain });
17
- },
18
- async tokenTransferFrom({ token, from, to, amount, account }) {
19
- return client.writeContract({ address: token, abi: GTokenABI, functionName: 'transferFrom', args: [from, to, amount], account: account, chain: client.chain });
20
- },
21
- async tokenApprove({ token, spender, amount, account }) {
22
- return client.writeContract({ address: token, abi: GTokenABI, functionName: 'approve', args: [spender, amount], account: account, chain: client.chain });
23
- },
24
- async tokenAllowance({ token, owner, spender }) {
25
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'allowance', args: [owner, spender] });
26
- },
27
- async tokenMint({ token, to, amount, account }) {
28
- return client.writeContract({ address: token, abi: GTokenABI, functionName: 'mint', args: [to, amount], account: account, chain: client.chain });
29
- },
30
- async tokenBurn({ token, amount, account }) {
31
- return client.writeContract({ address: token, abi: GTokenABI, functionName: 'burn', args: [amount], account: account, chain: client.chain });
32
- },
33
- async tokenBurnFrom({ token, from, amount, account }) {
34
- return client.writeContract({ address: token, abi: GTokenABI, functionName: 'burnFrom', args: [from, amount], account: account, chain: client.chain });
35
- },
36
- async tokenName({ token }) {
37
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'name', args: [] });
38
- },
39
- async tokenSymbol({ token }) {
40
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'symbol', args: [] });
41
- },
42
- async tokenDecimals({ token }) {
43
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'decimals', args: [] });
44
- },
45
- async tokenOwner({ token }) {
46
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'owner', args: [] });
47
- },
48
- async tokenTransferTokenOwnership({ token, newOwner, account }) {
49
- return client.writeContract({ address: token, abi: GTokenABI, functionName: 'transferOwnership', args: [newOwner], account: account, chain: client.chain });
50
- },
51
- async tokenRenounceOwnership({ token, account }) {
52
- return client.writeContract({ address: token, abi: GTokenABI, functionName: 'renounceOwnership', args: [], account: account, chain: client.chain });
53
- },
54
- async tokenCap({ token }) {
55
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'cap', args: [] });
56
- },
57
- async tokenRemainingMintableSupply({ token }) {
58
- return client.readContract({ address: token, abi: GTokenABI, functionName: 'remainingMintableSupply', args: [] });
59
- },
60
- });
61
- export const tokenActions = () => (client) => ({
62
- // ERC20 Standard
63
- async tokenTotalSupply({ token }) {
64
- return client.readContract({
65
- address: token,
66
- abi: getTokenABI(token),
67
- functionName: 'totalSupply',
68
- args: []
69
- });
70
- },
71
- async tokenCap({ token }) {
72
- return client.readContract({
73
- address: token,
74
- abi: getTokenABI(token),
75
- functionName: 'cap',
76
- args: []
77
- });
78
- },
79
- async tokenRemainingMintableSupply({ token }) {
80
- return client.readContract({
81
- address: token,
82
- abi: getTokenABI(token),
83
- functionName: 'remainingMintableSupply',
84
- args: []
85
- });
86
- },
87
- async tokenBalanceOf({ token, account }) {
88
- return client.readContract({
89
- address: token,
90
- abi: getTokenABI(token),
91
- functionName: 'balanceOf',
92
- args: [account]
93
- });
94
- },
95
- async tokenTransfer({ token, to, amount, account }) {
96
- return client.writeContract({
97
- address: token,
98
- abi: getTokenABI(token),
99
- functionName: 'transfer',
100
- args: [to, amount],
101
- account: account,
102
- chain: client.chain
103
- });
104
- },
105
- async tokenTransferFrom({ token, from, to, amount, account }) {
106
- return client.writeContract({
107
- address: token,
108
- abi: getTokenABI(token),
109
- functionName: 'transferFrom',
110
- args: [from, to, amount],
111
- account: account,
112
- chain: client.chain
113
- });
114
- },
115
- async tokenApprove({ token, spender, amount, account }) {
116
- return client.writeContract({
117
- address: token,
118
- abi: getTokenABI(token),
119
- functionName: 'approve',
120
- args: [spender, amount],
121
- account: account,
122
- chain: client.chain
123
- });
124
- },
125
- async tokenAllowance({ token, owner, spender }) {
126
- return client.readContract({
127
- address: token,
128
- abi: getTokenABI(token),
129
- functionName: 'allowance',
130
- args: [owner, spender]
131
- });
132
- },
133
- // Mintable/Burnable
134
- async tokenMint({ token, to, amount, account }) {
135
- return client.writeContract({
136
- address: token,
137
- abi: getTokenABI(token),
138
- functionName: 'mint',
139
- args: [to, amount],
140
- account: account,
141
- chain: client.chain
142
- });
143
- },
144
- async tokenBurn({ token, amount, account }) {
145
- return client.writeContract({
146
- address: token,
147
- abi: getTokenABI(token),
148
- functionName: 'burn',
149
- args: [amount],
150
- account: account,
151
- chain: client.chain
152
- });
153
- },
154
- async tokenBurnFrom({ token, from, amount, account }) {
155
- return client.writeContract({
156
- address: token,
157
- abi: getTokenABI(token),
158
- functionName: 'burnFrom',
159
- args: [from, amount],
160
- account: account,
161
- chain: client.chain
162
- });
163
- },
164
- // ERC20 Metadata
165
- async tokenName({ token }) {
166
- return client.readContract({
167
- address: token,
168
- abi: getTokenABI(token),
169
- functionName: 'name',
170
- args: []
171
- });
172
- },
173
- async tokenSymbol({ token }) {
174
- return client.readContract({
175
- address: token,
176
- abi: getTokenABI(token),
177
- functionName: 'symbol',
178
- args: []
179
- });
180
- },
181
- async tokenDecimals({ token }) {
182
- return client.readContract({
183
- address: token,
184
- abi: getTokenABI(token),
185
- functionName: 'decimals',
186
- args: []
187
- });
188
- },
189
- // Ownable
190
- async tokenOwner({ token }) {
191
- return client.readContract({
192
- address: token,
193
- abi: getTokenABI(token),
194
- functionName: 'owner',
195
- args: []
196
- });
197
- },
198
- async tokenTransferTokenOwnership({ token, newOwner, account }) {
199
- return client.writeContract({
200
- address: token,
201
- abi: getTokenABI(token),
202
- functionName: 'transferOwnership',
203
- args: [newOwner],
204
- account: account,
205
- chain: client.chain
206
- });
207
- },
208
- async tokenRenounceOwnership({ token, account }) {
209
- return client.writeContract({
210
- address: token,
211
- abi: getTokenABI(token),
212
- functionName: 'renounceOwnership',
213
- args: [],
214
- account: account,
215
- chain: client.chain
216
- });
217
- },
218
- // xPNTs/aPNTs specific
219
- async tokenUpdateExchangeRate({ token, newRate, account }) {
220
- return client.writeContract({
221
- address: token,
222
- abi: getTokenABI(token),
223
- functionName: 'updateExchangeRate',
224
- args: [newRate],
225
- account: account,
226
- chain: client.chain
227
- });
228
- },
229
- async tokenGetDebt({ token, user }) {
230
- return client.readContract({
231
- address: token,
232
- abi: getTokenABI(token),
233
- functionName: 'getDebt',
234
- args: [user]
235
- });
236
- },
237
- async tokenRepayDebt({ token, amount, account }) {
238
- return client.writeContract({
239
- address: token,
240
- abi: getTokenABI(token),
241
- functionName: 'repayDebt',
242
- args: [amount],
243
- account: account,
244
- chain: client.chain
245
- });
246
- },
247
- async tokenTransferAndCall({ token, to, amount, data = '0x', account }) {
248
- return client.writeContract({
249
- address: token,
250
- abi: getTokenABI(token),
251
- functionName: 'transferAndCall',
252
- args: [to, amount, data],
253
- account: account,
254
- chain: client.chain
255
- });
256
- },
257
- // Auto Approval
258
- async tokenAddAutoApprovedSpender({ token, spender, account }) {
259
- return client.writeContract({
260
- address: token,
261
- abi: xPNTsTokenABI,
262
- functionName: 'addAutoApprovedSpender',
263
- args: [spender],
264
- account: account,
265
- chain: client.chain
266
- });
267
- },
268
- async tokenRemoveAutoApprovedSpender({ token, spender, account }) {
269
- return client.writeContract({
270
- address: token,
271
- abi: xPNTsTokenABI,
272
- functionName: 'removeAutoApprovedSpender',
273
- args: [spender],
274
- account: account,
275
- chain: client.chain
276
- });
277
- },
278
- async tokenIsAutoApprovedSpender({ token, spender }) {
279
- return client.readContract({
280
- address: token,
281
- abi: xPNTsTokenABI,
282
- functionName: 'isAutoApprovedSpender',
283
- args: [spender]
284
- });
285
- },
286
- // Constants
287
- async tokenSUPERPAYMASTER_ADDRESS({ token }) {
288
- return client.readContract({
289
- address: token,
290
- abi: xPNTsTokenABI,
291
- functionName: 'SUPERPAYMASTER_ADDRESS',
292
- args: []
293
- });
294
- },
295
- async tokenFACTORY({ token }) {
296
- return client.readContract({
297
- address: token,
298
- abi: xPNTsTokenABI,
299
- functionName: 'FACTORY',
300
- args: []
301
- });
302
- },
303
- async tokenTransferOwnership(args) {
304
- return this.tokenTransferTokenOwnership(args);
305
- },
306
- async tokenTransferCommunityOwnership({ token, newOwner, account }) {
307
- return client.writeContract({
308
- address: token,
309
- abi: xPNTsTokenABI,
310
- functionName: 'transferCommunityOwnership',
311
- args: [newOwner],
312
- account: account,
313
- chain: client.chain
314
- });
315
- },
316
- // xPNTs Views
317
- async tokenCommunityName({ token }) {
318
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'communityName', args: [] });
319
- },
320
- async tokenCommunityENS({ token }) {
321
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'communityENS', args: [] });
322
- },
323
- async tokenExchangeRate({ token }) {
324
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'exchangeRate', args: [] });
325
- },
326
- async tokenSpendingLimits({ token, user }) {
327
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'spendingLimits', args: [user] });
328
- },
329
- async tokenDefaultSpendingLimitXPNTs({ token }) {
330
- try {
331
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'defaultSpendingLimitXPNTs', args: [] });
332
- }
333
- catch {
334
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'getDefaultSpendingLimitXPNTs', args: [] });
335
- }
336
- },
337
- async tokenCumulativeSpent({ token, user }) {
338
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'cumulativeSpent', args: [user] });
339
- },
340
- async tokenDebts({ token, user }) {
341
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'debts', args: [user] });
342
- },
343
- async tokenUsedOpHashes({ token, hash }) {
344
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'usedOpHashes', args: [hash] });
345
- },
346
- // EIP2612
347
- async tokenDOMAIN_SEPARATOR({ token }) {
348
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'DOMAIN_SEPARATOR', args: [] });
349
- },
350
- async tokenNonces({ token, owner }) {
351
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'nonces', args: [owner] });
352
- },
353
- async tokenPermit({ token, owner, spender, value, deadline, v, r, s, account }) {
354
- return client.writeContract({
355
- address: token,
356
- abi: xPNTsTokenABI,
357
- functionName: 'permit',
358
- args: [owner, spender, value, deadline, v, r, s],
359
- account: account,
360
- chain: client.chain
361
- });
362
- },
363
- // xPNTs Additional
364
- async tokenAutoApprovedSpenders({ token, spender }) {
365
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'autoApprovedSpenders', args: [spender] });
366
- },
367
- async tokenBurnFromWithOpHash({ token, account: user, amount, opHash, userOpAccount }) {
368
- return client.writeContract({ address: token, abi: xPNTsTokenABI, functionName: 'burnFromWithOpHash', args: [user, amount, opHash], account: userOpAccount, chain: client.chain });
369
- },
370
- async tokenCommunityOwner({ token }) {
371
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'communityOwner', args: [] });
372
- },
373
- async tokenEip712Domain({ token }) {
374
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'eip712Domain', args: [] });
375
- },
376
- async tokenGetDefaultSpendingLimitXPNTs({ token }) {
377
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'getDefaultSpendingLimitXPNTs', args: [] });
378
- },
379
- async tokenGetMetadata({ token }) {
380
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'getMetadata', args: [] });
381
- },
382
- async tokenNeedsApproval({ token, owner, spender, amount }) {
383
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'needsApproval', args: [owner, spender, amount] });
384
- },
385
- async tokenRecordDebt({ token, user, amount, account }) {
386
- return client.writeContract({ address: token, abi: xPNTsTokenABI, functionName: 'recordDebt', args: [user, amount], account: account, chain: client.chain });
387
- },
388
- async tokenDEFAULT_SPENDING_LIMIT_APNTS({ token }) {
389
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'DEFAULT_SPENDING_LIMIT_APNTS', args: [] });
390
- },
391
- // Admin
392
- async tokenSetPaymasterLimit({ token, user, limit, account }) {
393
- return client.writeContract({
394
- address: token,
395
- abi: xPNTsTokenABI,
396
- functionName: 'setPaymasterLimit',
397
- args: [user, limit],
398
- account: account,
399
- chain: client.chain
400
- });
401
- },
402
- async tokenSetSuperPaymasterAddress({ token, superPaymaster, account }) {
403
- return client.writeContract({
404
- address: token,
405
- abi: xPNTsTokenABI,
406
- functionName: 'setSuperPaymasterAddress',
407
- args: [superPaymaster],
408
- account: account,
409
- chain: client.chain
410
- });
411
- },
412
- async tokenVersion({ token }) {
413
- return client.readContract({ address: token, abi: xPNTsTokenABI, functionName: 'version', args: [] });
414
- }
415
- });
2
+ import { validateAddress, validateAmount, validateRequired } from '../validators/index.js';
3
+ import { AAStarError } from '../errors/index.js';
4
+ export const gTokenActions = (address) => (client) => {
5
+ const abi = GTokenABI;
6
+ const actions = {
7
+ async totalSupply({ token = address } = {}) {
8
+ validateAddress(token, 'token');
9
+ return client.readContract({ address: token, abi, functionName: 'totalSupply', args: [] });
10
+ },
11
+ async balanceOf({ token = address, account }) {
12
+ validateAddress(token, 'token');
13
+ validateAddress(account, 'account');
14
+ return client.readContract({ address: token, abi, functionName: 'balanceOf', args: [account] });
15
+ },
16
+ async transfer({ token = address, to, amount, account }) {
17
+ try {
18
+ validateAddress(token, 'token');
19
+ validateAddress(to, 'to');
20
+ validateAmount(amount, 'amount');
21
+ return await client.writeContract({ address: token, abi, functionName: 'transfer', args: [to, amount], account: account, chain: client.chain });
22
+ }
23
+ catch (error) {
24
+ throw AAStarError.fromViemError(error, 'transfer');
25
+ }
26
+ },
27
+ async transferFrom({ token = address, from, to, amount, account }) {
28
+ try {
29
+ validateAddress(token, 'token');
30
+ validateAddress(from, 'from');
31
+ validateAddress(to, 'to');
32
+ validateAmount(amount, 'amount');
33
+ return await client.writeContract({ address: token, abi, functionName: 'transferFrom', args: [from, to, amount], account: account, chain: client.chain });
34
+ }
35
+ catch (error) {
36
+ throw AAStarError.fromViemError(error, 'transferFrom');
37
+ }
38
+ },
39
+ async approve({ token = address, spender, amount, account }) {
40
+ try {
41
+ validateAddress(token, 'token');
42
+ validateAddress(spender, 'spender');
43
+ validateAmount(amount, 'amount');
44
+ return await client.writeContract({ address: token, abi, functionName: 'approve', args: [spender, amount], account: account, chain: client.chain });
45
+ }
46
+ catch (error) {
47
+ throw AAStarError.fromViemError(error, 'approve');
48
+ }
49
+ },
50
+ async allowance({ token = address, owner, spender }) {
51
+ validateAddress(token, 'token');
52
+ validateAddress(owner, 'owner');
53
+ validateAddress(spender, 'spender');
54
+ return client.readContract({ address: token, abi, functionName: 'allowance', args: [owner, spender] });
55
+ },
56
+ async mint({ token = address, to, amount, account }) {
57
+ try {
58
+ validateAddress(token, 'token');
59
+ validateAddress(to, 'to');
60
+ validateAmount(amount, 'amount');
61
+ return await client.writeContract({ address: token, abi, functionName: 'mint', args: [to, amount], account: account, chain: client.chain });
62
+ }
63
+ catch (error) {
64
+ throw AAStarError.fromViemError(error, 'mint');
65
+ }
66
+ },
67
+ async burn({ token = address, amount, account }) {
68
+ try {
69
+ validateAddress(token, 'token');
70
+ validateAmount(amount, 'amount');
71
+ return await client.writeContract({ address: token, abi, functionName: 'burn', args: [amount], account: account, chain: client.chain });
72
+ }
73
+ catch (error) {
74
+ throw AAStarError.fromViemError(error, 'burn');
75
+ }
76
+ },
77
+ async burnFrom({ token = address, from, amount, account }) {
78
+ try {
79
+ validateAddress(token, 'token');
80
+ validateAddress(from, 'from');
81
+ validateAmount(amount, 'amount');
82
+ return await client.writeContract({ address: token, abi, functionName: 'burnFrom', args: [from, amount], account: account, chain: client.chain });
83
+ }
84
+ catch (error) {
85
+ throw AAStarError.fromViemError(error, 'burnFrom');
86
+ }
87
+ },
88
+ async cap({ token = address } = {}) {
89
+ validateAddress(token, 'token');
90
+ return client.readContract({ address: token, abi, functionName: 'cap', args: [] });
91
+ },
92
+ async remainingMintableSupply({ token = address } = {}) {
93
+ validateAddress(token, 'token');
94
+ return client.readContract({ address: token, abi, functionName: 'remainingMintableSupply', args: [] });
95
+ },
96
+ async name({ token = address } = {}) {
97
+ validateAddress(token, 'token');
98
+ return client.readContract({ address: token, abi, functionName: 'name', args: [] });
99
+ },
100
+ async symbol({ token = address } = {}) {
101
+ validateAddress(token, 'token');
102
+ return client.readContract({ address: token, abi, functionName: 'symbol', args: [] });
103
+ },
104
+ async decimals({ token = address } = {}) {
105
+ validateAddress(token, 'token');
106
+ return client.readContract({ address: token, abi, functionName: 'decimals', args: [] });
107
+ },
108
+ async version({ token = address } = {}) {
109
+ validateAddress(token, 'token');
110
+ return client.readContract({ address: token, abi, functionName: 'version', args: [] });
111
+ },
112
+ async owner({ token = address } = {}) {
113
+ validateAddress(token, 'token');
114
+ return client.readContract({ address: token, abi, functionName: 'owner', args: [] });
115
+ },
116
+ async transferOwnership({ token = address, newOwner, account }) {
117
+ try {
118
+ validateAddress(token, 'token');
119
+ validateAddress(newOwner, 'newOwner');
120
+ return await client.writeContract({ address: token, abi, functionName: 'transferOwnership', args: [newOwner], account: account, chain: client.chain });
121
+ }
122
+ catch (error) {
123
+ throw AAStarError.fromViemError(error, 'transferOwnership');
124
+ }
125
+ },
126
+ async renounceOwnership({ token = address, account }) {
127
+ try {
128
+ validateAddress(token, 'token');
129
+ return await client.writeContract({ address: token, abi, functionName: 'renounceOwnership', args: [], account: account, chain: client.chain });
130
+ }
131
+ catch (error) {
132
+ throw AAStarError.fromViemError(error, 'renounceOwnership');
133
+ }
134
+ },
135
+ };
136
+ return actions;
137
+ };
138
+ export const xPNTsTokenActions = (address) => (client) => {
139
+ const abi = xPNTsTokenABI;
140
+ const actions = {
141
+ async totalSupply({ token = address } = {}) {
142
+ validateAddress(token, 'token');
143
+ return client.readContract({ address: token, abi, functionName: 'totalSupply', args: [] });
144
+ },
145
+ async balanceOf({ token = address, account }) {
146
+ validateAddress(token, 'token');
147
+ validateAddress(account, 'account');
148
+ return client.readContract({ address: token, abi, functionName: 'balanceOf', args: [account] });
149
+ },
150
+ async transfer({ token = address, to, amount, account }) {
151
+ try {
152
+ validateAddress(token, 'token');
153
+ validateAddress(to, 'to');
154
+ validateAmount(amount, 'amount');
155
+ return await client.writeContract({ address: token, abi, functionName: 'transfer', args: [to, amount], account: account, chain: client.chain });
156
+ }
157
+ catch (error) {
158
+ throw AAStarError.fromViemError(error, 'transfer');
159
+ }
160
+ },
161
+ async transferFrom({ token = address, from, to, amount, account }) {
162
+ try {
163
+ validateAddress(token, 'token');
164
+ validateAddress(from, 'from');
165
+ validateAddress(to, 'to');
166
+ validateAmount(amount, 'amount');
167
+ return await client.writeContract({ address: token, abi, functionName: 'transferFrom', args: [from, to, amount], account: account, chain: client.chain });
168
+ }
169
+ catch (error) {
170
+ throw AAStarError.fromViemError(error, 'transferFrom');
171
+ }
172
+ },
173
+ async approve({ token = address, spender, amount, account }) {
174
+ try {
175
+ validateAddress(token, 'token');
176
+ validateAddress(spender, 'spender');
177
+ validateAmount(amount, 'amount');
178
+ return await client.writeContract({ address: token, abi, functionName: 'approve', args: [spender, amount], account: account, chain: client.chain });
179
+ }
180
+ catch (error) {
181
+ throw AAStarError.fromViemError(error, 'approve');
182
+ }
183
+ },
184
+ async allowance({ token = address, owner, spender }) {
185
+ validateAddress(token, 'token');
186
+ validateAddress(owner, 'owner');
187
+ validateAddress(spender, 'spender');
188
+ return client.readContract({ address: token, abi, functionName: 'allowance', args: [owner, spender] });
189
+ },
190
+ async mint({ token = address, to, amount, account }) {
191
+ try {
192
+ validateAddress(token, 'token');
193
+ validateAddress(to, 'to');
194
+ validateAmount(amount, 'amount');
195
+ return await client.writeContract({ address: token, abi, functionName: 'mint', args: [to, amount], account: account, chain: client.chain });
196
+ }
197
+ catch (error) {
198
+ throw AAStarError.fromViemError(error, 'mint');
199
+ }
200
+ },
201
+ async burn({ token = address, amount, account }) {
202
+ try {
203
+ validateAddress(token, 'token');
204
+ validateAmount(amount, 'amount');
205
+ return await client.writeContract({ address: token, abi, functionName: 'burn', args: [amount], account: account, chain: client.chain });
206
+ }
207
+ catch (error) {
208
+ throw AAStarError.fromViemError(error, 'burn');
209
+ }
210
+ },
211
+ async burnFrom({ token = address, from, amount, account }) {
212
+ try {
213
+ validateAddress(token, 'token');
214
+ validateAddress(from, 'from');
215
+ validateAmount(amount, 'amount');
216
+ return await client.writeContract({ address: token, abi, functionName: 'burn', args: [from, amount], account: account, chain: client.chain });
217
+ }
218
+ catch (error) {
219
+ throw AAStarError.fromViemError(error, 'burnFrom');
220
+ }
221
+ },
222
+ async burnFromWithOpHash({ token = address, from, amount, userOpHash, account }) {
223
+ try {
224
+ validateAddress(token, 'token');
225
+ validateAddress(from, 'from');
226
+ validateAmount(amount, 'amount');
227
+ validateRequired(userOpHash, 'userOpHash');
228
+ return await client.writeContract({ address: token, abi, functionName: 'burnFromWithOpHash', args: [from, amount, userOpHash], account: account, chain: client.chain });
229
+ }
230
+ catch (error) {
231
+ throw AAStarError.fromViemError(error, 'burnFromWithOpHash');
232
+ }
233
+ },
234
+ async name({ token = address } = {}) {
235
+ validateAddress(token, 'token');
236
+ return client.readContract({ address: token, abi, functionName: 'name', args: [] });
237
+ },
238
+ async symbol({ token = address } = {}) {
239
+ validateAddress(token, 'token');
240
+ return client.readContract({ address: token, abi, functionName: 'symbol', args: [] });
241
+ },
242
+ async decimals({ token = address } = {}) {
243
+ validateAddress(token, 'token');
244
+ return client.readContract({ address: token, abi, functionName: 'decimals', args: [] });
245
+ },
246
+ async version({ token = address } = {}) {
247
+ validateAddress(token, 'token');
248
+ return client.readContract({ address: token, abi, functionName: 'version', args: [] });
249
+ },
250
+ async exchangeRate({ token = address } = {}) {
251
+ validateAddress(token, 'token');
252
+ return client.readContract({ address: token, abi, functionName: 'exchangeRate', args: [] });
253
+ },
254
+ async updateExchangeRate({ token = address, newRate, account }) {
255
+ try {
256
+ validateAddress(token, 'token');
257
+ validateAmount(newRate, 'newRate');
258
+ return await client.writeContract({ address: token, abi, functionName: 'updateExchangeRate', args: [newRate], account: account, chain: client.chain });
259
+ }
260
+ catch (error) {
261
+ throw AAStarError.fromViemError(error, 'updateExchangeRate');
262
+ }
263
+ },
264
+ async debts({ token = address, user }) {
265
+ validateAddress(token, 'token');
266
+ validateAddress(user, 'user');
267
+ return await client.readContract({
268
+ address: token,
269
+ abi,
270
+ functionName: 'debts',
271
+ args: [user]
272
+ });
273
+ },
274
+ async getDebt({ token = address, user }) {
275
+ validateAddress(token, 'token');
276
+ validateAddress(user, 'user');
277
+ return client.readContract({ address: token, abi, functionName: 'getDebt', args: [user] });
278
+ },
279
+ async recordDebt({ token = address, user, amountXPNTs, account }) {
280
+ try {
281
+ validateAddress(token, 'token');
282
+ validateAddress(user, 'user');
283
+ validateAmount(amountXPNTs, 'amountXPNTs');
284
+ return await client.writeContract({ address: token, abi, functionName: 'recordDebt', args: [user, amountXPNTs], account: account, chain: client.chain });
285
+ }
286
+ catch (error) {
287
+ throw AAStarError.fromViemError(error, 'recordDebt');
288
+ }
289
+ },
290
+ async repayDebt({ token = address, amount, account }) {
291
+ try {
292
+ validateAddress(token, 'token');
293
+ validateAmount(amount, 'amount');
294
+ return await client.writeContract({ address: token, abi, functionName: 'repayDebt', args: [amount], account: account, chain: client.chain });
295
+ }
296
+ catch (error) {
297
+ throw AAStarError.fromViemError(error, 'repayDebt');
298
+ }
299
+ },
300
+ async spendingLimits({ token = address, owner, spender }) {
301
+ validateAddress(token, 'token');
302
+ validateAddress(owner, 'owner');
303
+ validateAddress(spender, 'spender');
304
+ return client.readContract({ address: token, abi, functionName: 'spendingLimits', args: [owner, spender] });
305
+ },
306
+ async cumulativeSpent({ token = address, owner, spender }) {
307
+ validateAddress(token, 'token');
308
+ validateAddress(owner, 'owner');
309
+ validateAddress(spender, 'spender');
310
+ return client.readContract({ address: token, abi, functionName: 'cumulativeSpent', args: [owner, spender] });
311
+ },
312
+ async setPaymasterLimit({ token = address, spender, limit, account }) {
313
+ try {
314
+ validateAddress(token, 'token');
315
+ validateAddress(spender, 'spender');
316
+ validateAmount(limit, 'limit');
317
+ return await client.writeContract({ address: token, abi, functionName: 'setPaymasterLimit', args: [spender, limit], account: account, chain: client.chain });
318
+ }
319
+ catch (error) {
320
+ throw AAStarError.fromViemError(error, 'setPaymasterLimit');
321
+ }
322
+ },
323
+ async DEFAULT_SPENDING_LIMIT_APNTS({ token = address } = {}) {
324
+ validateAddress(token, 'token');
325
+ return client.readContract({ address: token, abi, functionName: 'DEFAULT_SPENDING_LIMIT_APNTS', args: [] });
326
+ },
327
+ async getDefaultSpendingLimitXPNTs({ token = address } = {}) {
328
+ validateAddress(token, 'token');
329
+ return client.readContract({ address: token, abi, functionName: 'getDefaultSpendingLimitXPNTs', args: [] });
330
+ },
331
+ async needsApproval({ token = address, owner, spender, amount }) {
332
+ validateAddress(token, 'token');
333
+ validateAddress(owner, 'owner');
334
+ validateAddress(spender, 'spender');
335
+ validateAmount(amount, 'amount');
336
+ return client.readContract({ address: token, abi, functionName: 'needsApproval', args: [owner, spender, amount] });
337
+ },
338
+ async addAutoApprovedSpender({ token = address, spender, account }) {
339
+ try {
340
+ validateAddress(token, 'token');
341
+ validateAddress(spender, 'spender');
342
+ return await client.writeContract({ address: token, abi, functionName: 'addAutoApprovedSpender', args: [spender], account: account, chain: client.chain });
343
+ }
344
+ catch (error) {
345
+ throw AAStarError.fromViemError(error, 'addAutoApprovedSpender');
346
+ }
347
+ },
348
+ async removeAutoApprovedSpender({ token = address, spender, account }) {
349
+ try {
350
+ validateAddress(token, 'token');
351
+ validateAddress(spender, 'spender');
352
+ return await client.writeContract({ address: token, abi, functionName: 'removeAutoApprovedSpender', args: [spender], account: account, chain: client.chain });
353
+ }
354
+ catch (error) {
355
+ throw AAStarError.fromViemError(error, 'removeAutoApprovedSpender');
356
+ }
357
+ },
358
+ async autoApprovedSpenders({ token = address, spender }) {
359
+ validateAddress(token, 'token');
360
+ validateAddress(spender, 'spender');
361
+ return client.readContract({ address: token, abi, functionName: 'autoApprovedSpenders', args: [spender] });
362
+ },
363
+ async DOMAIN_SEPARATOR({ token = address } = {}) {
364
+ validateAddress(token, 'token');
365
+ return client.readContract({ address: token, abi, functionName: 'DOMAIN_SEPARATOR', args: [] });
366
+ },
367
+ async nonces({ token = address, owner }) {
368
+ validateAddress(token, 'token');
369
+ validateAddress(owner, 'owner');
370
+ return client.readContract({ address: token, abi, functionName: 'nonces', args: [owner] });
371
+ },
372
+ async permit({ token = address, owner, spender, value, deadline, v, r, s, account }) {
373
+ try {
374
+ validateAddress(token, 'token');
375
+ validateAddress(owner, 'owner');
376
+ validateAddress(spender, 'spender');
377
+ validateAmount(value, 'value');
378
+ validateRequired(deadline, 'deadline');
379
+ return await client.writeContract({ address: token, abi, functionName: 'permit', args: [owner, spender, value, deadline, v, r, s], account: account, chain: client.chain });
380
+ }
381
+ catch (error) {
382
+ throw AAStarError.fromViemError(error, 'permit');
383
+ }
384
+ },
385
+ async eip712Domain({ token = address } = {}) {
386
+ validateAddress(token, 'token');
387
+ return client.readContract({ address: token, abi, functionName: 'eip712Domain', args: [] });
388
+ },
389
+ async transferAndCall({ token = address, to, amount, data = '0x', account }) {
390
+ try {
391
+ validateAddress(token, 'token');
392
+ validateAddress(to, 'to');
393
+ validateAmount(amount, 'amount');
394
+ return await client.writeContract({ address: token, abi, functionName: 'transferAndCall', args: [to, amount, data], account: account, chain: client.chain });
395
+ }
396
+ catch (error) {
397
+ throw AAStarError.fromViemError(error, 'transferAndCall');
398
+ }
399
+ },
400
+ async communityENS({ token = address } = {}) {
401
+ validateAddress(token, 'token');
402
+ return client.readContract({ address: token, abi, functionName: 'communityENS', args: [] });
403
+ },
404
+ async communityName({ token = address } = {}) {
405
+ validateAddress(token, 'token');
406
+ return client.readContract({ address: token, abi, functionName: 'communityName', args: [] });
407
+ },
408
+ async communityOwner({ token = address } = {}) {
409
+ validateAddress(token, 'token');
410
+ return client.readContract({ address: token, abi, functionName: 'communityOwner', args: [] });
411
+ },
412
+ async getMetadata({ token = address } = {}) {
413
+ const abi = xPNTsTokenABI;
414
+ const res = await client.readContract({
415
+ address: token,
416
+ abi,
417
+ functionName: 'getMetadata',
418
+ args: []
419
+ });
420
+ if (Array.isArray(res)) {
421
+ return {
422
+ name: res[0],
423
+ symbol: res[1],
424
+ communityName: res[2],
425
+ communityENS: res[3],
426
+ communityOwner: res[4]
427
+ };
428
+ }
429
+ return res;
430
+ },
431
+ async transferCommunityOwnership({ token = address, newOwner, account }) {
432
+ try {
433
+ validateAddress(token, 'token');
434
+ validateAddress(newOwner, 'newOwner');
435
+ return await client.writeContract({ address: token, abi, functionName: 'transferCommunityOwnership', args: [newOwner], account: account, chain: client.chain });
436
+ }
437
+ catch (error) {
438
+ throw AAStarError.fromViemError(error, 'transferCommunityOwnership');
439
+ }
440
+ },
441
+ async setSuperPaymasterAddress({ token = address, spAddress, account }) {
442
+ try {
443
+ validateAddress(token, 'token');
444
+ validateAddress(spAddress, 'spAddress');
445
+ return await client.writeContract({ address: token, abi, functionName: 'setSuperPaymasterAddress', args: [spAddress], account: account, chain: client.chain });
446
+ }
447
+ catch (error) {
448
+ throw AAStarError.fromViemError(error, 'setSuperPaymasterAddress');
449
+ }
450
+ },
451
+ async SUPERPAYMASTER_ADDRESS({ token = address } = {}) {
452
+ validateAddress(token, 'token');
453
+ return client.readContract({ address: token, abi, functionName: 'SUPERPAYMASTER_ADDRESS', args: [] });
454
+ },
455
+ async FACTORY({ token = address } = {}) {
456
+ validateAddress(token, 'token');
457
+ return client.readContract({ address: token, abi, functionName: 'FACTORY', args: [] });
458
+ },
459
+ async usedOpHashes({ token = address, opHash }) {
460
+ validateAddress(token, 'token');
461
+ validateRequired(opHash, 'opHash');
462
+ return client.readContract({ address: token, abi, functionName: 'usedOpHashes', args: [opHash] });
463
+ },
464
+ };
465
+ return actions;
466
+ };
467
+ // Legacy compatibility
468
+ export const tokenActions = (address) => (client) => {
469
+ // This is essentially xPNTsTokenActions for now as it's the more complex one
470
+ return xPNTsTokenActions(address)(client);
471
+ };