@aastar/sdk 0.20.7 → 0.20.9

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 (94) hide show
  1. package/dist/BaseClient-CkBhQ1ou.d.cts +88 -0
  2. package/dist/UserClient-2J6XMTNV.cjs +15 -0
  3. package/dist/UserClient-2J6XMTNV.cjs.map +1 -0
  4. package/dist/account.cjs +31 -0
  5. package/dist/account.cjs.map +1 -0
  6. package/dist/account.d.cts +48 -0
  7. package/dist/admin.cjs +15 -0
  8. package/dist/admin.cjs.map +1 -0
  9. package/dist/admin.d.cts +62 -0
  10. package/dist/airaccount.cjs +452 -0
  11. package/dist/airaccount.cjs.map +1 -0
  12. package/dist/airaccount.d.cts +4 -0
  13. package/dist/airaccount.js +3 -1
  14. package/dist/channel-CkRRbzT8.d.cts +77 -0
  15. package/dist/channel.cjs +27 -0
  16. package/dist/channel.cjs.map +1 -0
  17. package/dist/channel.d.cts +64 -0
  18. package/dist/chunk-2RCJBWPO.cjs +1168 -0
  19. package/dist/chunk-2RCJBWPO.cjs.map +1 -0
  20. package/dist/chunk-FTJD2DWE.cjs +42472 -0
  21. package/dist/chunk-FTJD2DWE.cjs.map +1 -0
  22. package/dist/chunk-GRDC6ZRA.cjs +118 -0
  23. package/dist/chunk-GRDC6ZRA.cjs.map +1 -0
  24. package/dist/chunk-GX7NROST.cjs +421 -0
  25. package/dist/chunk-GX7NROST.cjs.map +1 -0
  26. package/dist/chunk-HSVQIFIK.cjs +128 -0
  27. package/dist/chunk-HSVQIFIK.cjs.map +1 -0
  28. package/dist/{chunk-UIFMIVDK.js → chunk-IC3G6YM2.js} +24 -26
  29. package/dist/chunk-IC3G6YM2.js.map +1 -0
  30. package/dist/chunk-JTWY2XEG.cjs +115 -0
  31. package/dist/chunk-JTWY2XEG.cjs.map +1 -0
  32. package/dist/chunk-MRREGCWN.cjs +585 -0
  33. package/dist/chunk-MRREGCWN.cjs.map +1 -0
  34. package/dist/chunk-NT26BDGN.cjs +228 -0
  35. package/dist/chunk-NT26BDGN.cjs.map +1 -0
  36. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  37. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  38. package/dist/chunk-QLF7N6H7.cjs +448 -0
  39. package/dist/chunk-QLF7N6H7.cjs.map +1 -0
  40. package/dist/chunk-RNHSA3LO.cjs +108 -0
  41. package/dist/chunk-RNHSA3LO.cjs.map +1 -0
  42. package/dist/chunk-S5IKOOUR.cjs +393 -0
  43. package/dist/chunk-S5IKOOUR.cjs.map +1 -0
  44. package/dist/chunk-TFLZETWB.cjs +4693 -0
  45. package/dist/chunk-TFLZETWB.cjs.map +1 -0
  46. package/dist/chunk-WQREDGUF.cjs +435 -0
  47. package/dist/chunk-WQREDGUF.cjs.map +1 -0
  48. package/dist/chunk-XQROKLZI.cjs +4521 -0
  49. package/dist/chunk-XQROKLZI.cjs.map +1 -0
  50. package/dist/contract-addresses-TANQ5DLX.cjs +49 -0
  51. package/dist/contract-addresses-TANQ5DLX.cjs.map +1 -0
  52. package/dist/core.cjs +894 -0
  53. package/dist/core.cjs.map +1 -0
  54. package/dist/core.d.cts +6930 -0
  55. package/dist/dapp.cjs +289 -0
  56. package/dist/dapp.cjs.map +1 -0
  57. package/dist/dapp.d.cts +127 -0
  58. package/dist/doc-types-471vSmPO.d.cts +16 -0
  59. package/dist/enduser.cjs +24 -0
  60. package/dist/enduser.cjs.map +1 -0
  61. package/dist/enduser.d.cts +261 -0
  62. package/dist/identity.cjs +23 -0
  63. package/dist/identity.cjs.map +1 -0
  64. package/dist/identity.d.cts +81 -0
  65. package/dist/index-B6SfEQxo.d.cts +47 -0
  66. package/dist/index.cjs +2814 -0
  67. package/dist/index.cjs.map +1 -0
  68. package/dist/index.d.cts +656 -0
  69. package/dist/kms.cjs +452 -0
  70. package/dist/kms.cjs.map +1 -0
  71. package/dist/kms.d.cts +3054 -0
  72. package/dist/kms.d.ts +13 -13
  73. package/dist/kms.js +3 -1
  74. package/dist/lib-FE4GR7TO.cjs +1865 -0
  75. package/dist/lib-FE4GR7TO.cjs.map +1 -0
  76. package/dist/operator.cjs +27 -0
  77. package/dist/operator.cjs.map +1 -0
  78. package/dist/operator.d.cts +164 -0
  79. package/dist/paymaster.cjs +63 -0
  80. package/dist/paymaster.cjs.map +1 -0
  81. package/dist/paymaster.d.cts +312 -0
  82. package/dist/src-ENPA7D2S.cjs +63 -0
  83. package/dist/src-ENPA7D2S.cjs.map +1 -0
  84. package/dist/src-TQKEO2I4.cjs +894 -0
  85. package/dist/src-TQKEO2I4.cjs.map +1 -0
  86. package/dist/tier-router-DeeVg69O.d.cts +370 -0
  87. package/dist/tokens.cjs +15 -0
  88. package/dist/tokens.cjs.map +1 -0
  89. package/dist/tokens.d.cts +64 -0
  90. package/dist/x402.cjs +103 -0
  91. package/dist/x402.cjs.map +1 -0
  92. package/dist/x402.d.cts +373 -0
  93. package/package.json +32 -32
  94. package/dist/chunk-UIFMIVDK.js.map +0 -1
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ var chunkFTJD2DWE_cjs = require('./chunk-FTJD2DWE.cjs');
4
+
5
+ // ../channel/src/voucher.ts
6
+ var VOUCHER_TYPES = {
7
+ Voucher: [
8
+ { name: "channelId", type: "bytes32" },
9
+ { name: "cumulativeAmount", type: "uint128" }
10
+ ]
11
+ };
12
+ function getVoucherDomain(chainId, verifyingContract) {
13
+ return {
14
+ name: "MicroPaymentChannel",
15
+ version: "1.0.0",
16
+ chainId,
17
+ verifyingContract
18
+ };
19
+ }
20
+ async function signVoucher(walletClient, params) {
21
+ const domain = getVoucherDomain(params.chainId, params.verifyingContract);
22
+ const account = walletClient.account;
23
+ if (!account) {
24
+ throw new Error("WalletClient must have an account");
25
+ }
26
+ return walletClient.signTypedData({
27
+ account,
28
+ domain,
29
+ types: VOUCHER_TYPES,
30
+ primaryType: "Voucher",
31
+ message: {
32
+ channelId: params.channelId,
33
+ cumulativeAmount: params.cumulativeAmount
34
+ }
35
+ });
36
+ }
37
+
38
+ // ../channel/src/ChannelClient.ts
39
+ var ChannelClient = class {
40
+ readActions;
41
+ writeActions;
42
+ config;
43
+ constructor(config) {
44
+ this.config = config;
45
+ this.readActions = chunkFTJD2DWE_cjs.channelActions(config.channelAddress)(config.publicClient);
46
+ this.writeActions = chunkFTJD2DWE_cjs.channelActions(config.channelAddress)(config.walletClient);
47
+ }
48
+ async openChannel(channelConfig) {
49
+ return this.writeActions.openChannel({
50
+ payee: channelConfig.payee,
51
+ token: channelConfig.token,
52
+ deposit: channelConfig.deposit,
53
+ salt: channelConfig.salt,
54
+ authorizedSigner: channelConfig.authorizedSigner,
55
+ account: this.config.walletClient.account
56
+ });
57
+ }
58
+ async signVoucherOffline(channelId, cumulativeAmount) {
59
+ const signature = await signVoucher(this.config.walletClient, {
60
+ channelId,
61
+ cumulativeAmount,
62
+ chainId: this.config.chainId,
63
+ verifyingContract: this.config.channelAddress
64
+ });
65
+ return { channelId, cumulativeAmount, signature };
66
+ }
67
+ async settleChannel(voucher) {
68
+ return this.writeActions.settleChannel({
69
+ channelId: voucher.channelId,
70
+ cumulativeAmount: voucher.cumulativeAmount,
71
+ signature: voucher.signature,
72
+ account: this.config.walletClient.account
73
+ });
74
+ }
75
+ async closeChannel(voucher) {
76
+ return this.writeActions.closeChannel({
77
+ channelId: voucher.channelId,
78
+ cumulativeAmount: voucher.cumulativeAmount,
79
+ signature: voucher.signature,
80
+ account: this.config.walletClient.account
81
+ });
82
+ }
83
+ async topUpChannel(channelId, amount) {
84
+ return this.writeActions.topUpChannel({
85
+ channelId,
86
+ amount,
87
+ account: this.config.walletClient.account
88
+ });
89
+ }
90
+ async requestClose(channelId) {
91
+ return this.writeActions.requestCloseChannel({
92
+ channelId,
93
+ account: this.config.walletClient.account
94
+ });
95
+ }
96
+ async withdraw(channelId) {
97
+ return this.writeActions.withdrawChannel({
98
+ channelId,
99
+ account: this.config.walletClient.account
100
+ });
101
+ }
102
+ async getChannelState(channelId) {
103
+ return this.readActions.getChannel({ channelId });
104
+ }
105
+ async getCloseTimeout() {
106
+ return this.readActions.CLOSE_TIMEOUT();
107
+ }
108
+ async getVersion() {
109
+ return this.readActions.version();
110
+ }
111
+ };
112
+
113
+ exports.ChannelClient = ChannelClient;
114
+ exports.VOUCHER_TYPES = VOUCHER_TYPES;
115
+ exports.getVoucherDomain = getVoucherDomain;
116
+ exports.signVoucher = signVoucher;
117
+ //# sourceMappingURL=chunk-GRDC6ZRA.cjs.map
118
+ //# sourceMappingURL=chunk-GRDC6ZRA.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../channel/src/voucher.ts","../../channel/src/ChannelClient.ts"],"names":["channelActions"],"mappings":";;;;;AAEO,IAAM,aAAA,GAAgB;AAAA,EACzB,OAAA,EAAS;AAAA,IACL,EAAE,IAAA,EAAM,WAAA,EAAa,IAAA,EAAM,SAAA,EAAU;AAAA,IACrC,EAAE,IAAA,EAAM,kBAAA,EAAoB,IAAA,EAAM,SAAA;AAAU;AAEpD;AAEO,SAAS,gBAAA,CAAiB,SAAiB,iBAAA,EAA4B;AAC1E,EAAA,OAAO;AAAA,IACH,IAAA,EAAM,qBAAA;AAAA,IACN,OAAA,EAAS,OAAA;AAAA,IACT,OAAA;AAAA,IACA;AAAA,GACJ;AACJ;AAEA,eAAsB,WAAA,CAClB,cACA,MAAA,EAMY;AACZ,EAAA,MAAM,MAAA,GAAS,gBAAA,CAAiB,MAAA,CAAO,OAAA,EAAS,OAAO,iBAAiB,CAAA;AAExE,EAAA,MAAM,UAAU,YAAA,CAAa,OAAA;AAC7B,EAAA,IAAI,CAAC,OAAA,EAAS;AACV,IAAA,MAAM,IAAI,MAAM,mCAAmC,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO,aAAa,aAAA,CAAc;AAAA,IAC9B,OAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA,EAAO,aAAA;AAAA,IACP,WAAA,EAAa,SAAA;AAAA,IACb,OAAA,EAAS;AAAA,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W,CAAA;AAAA,EACpD;AAAA,EAEA,MAAM,eAAA,GAAmC;AACrC,IAAA,OAAO,IAAA,CAAK,YAAY,aAAA,EAAc;AAAA,EAC1C;AAAA,EAEA,MAAM,UAAA,GAA8B;AAChC,IAAA,OAAO,IAAA,CAAK,YAAY,OAAA,EAAQ;AAAA,EACpC;AACJ","file":"chunk-GRDC6ZRA.cjs","sourcesContent":["import { type Address, type Hex, type WalletClient } from 'viem';\n\nexport const VOUCHER_TYPES = {\n Voucher: [\n { name: 'channelId', type: 'bytes32' },\n { name: 'cumulativeAmount', type: 'uint128' },\n ],\n} as const;\n\nexport function getVoucherDomain(chainId: number, verifyingContract: Address) {\n return {\n name: 'MicroPaymentChannel',\n version: '1.0.0',\n chainId,\n verifyingContract,\n };\n}\n\nexport async function signVoucher(\n walletClient: WalletClient,\n params: {\n channelId: Hex;\n cumulativeAmount: bigint;\n chainId: number;\n verifyingContract: Address;\n }\n): Promise<Hex> {\n const domain = getVoucherDomain(params.chainId, params.verifyingContract);\n\n const account = walletClient.account;\n if (!account) {\n throw new Error('WalletClient must have an account');\n }\n\n return walletClient.signTypedData({\n account,\n domain,\n types: VOUCHER_TYPES,\n primaryType: 'Voucher',\n message: {\n channelId: params.channelId,\n cumulativeAmount: params.cumulativeAmount,\n },\n });\n}\n","import { type Address, type Hex, type Hash, type PublicClient, type WalletClient } from 'viem';\nimport { channelActions, type ChannelState } from '@aastar/core';\nimport type { SignedVoucher, ChannelConfig } from './types.js';\nimport { signVoucher } from './voucher.js';\n\nexport type ChannelClientConfig = {\n publicClient: PublicClient;\n walletClient: WalletClient;\n channelAddress: Address;\n chainId: number;\n};\n\nexport class ChannelClient {\n private readonly readActions;\n private readonly writeActions;\n private readonly config: ChannelClientConfig;\n\n constructor(config: ChannelClientConfig) {\n this.config = config;\n // Separate clients: publicClient for reads (no account required),\n // walletClient for writes. Unlike X402Client which is always write-first,\n // ChannelClient exposes read-heavy helpers (getChannel, verifyVoucher) that\n // callers may invoke without a wallet configured.\n this.readActions = channelActions(config.channelAddress)(config.publicClient);\n this.writeActions = channelActions(config.channelAddress)(config.walletClient);\n }\n\n async openChannel(channelConfig: ChannelConfig): Promise<Hash> {\n return this.writeActions.openChannel({\n payee: channelConfig.payee,\n token: channelConfig.token,\n deposit: channelConfig.deposit,\n salt: channelConfig.salt,\n authorizedSigner: channelConfig.authorizedSigner,\n account: this.config.walletClient.account!,\n });\n }\n\n async signVoucherOffline(channelId: Hex, cumulativeAmount: bigint): Promise<SignedVoucher> {\n const signature = await signVoucher(this.config.walletClient, {\n channelId,\n cumulativeAmount,\n chainId: this.config.chainId,\n verifyingContract: this.config.channelAddress,\n });\n\n return { channelId, cumulativeAmount, signature };\n }\n\n async settleChannel(voucher: SignedVoucher): Promise<Hash> {\n return this.writeActions.settleChannel({\n channelId: voucher.channelId,\n cumulativeAmount: voucher.cumulativeAmount,\n signature: voucher.signature,\n account: this.config.walletClient.account!,\n });\n }\n\n async closeChannel(voucher: SignedVoucher): Promise<Hash> {\n return this.writeActions.closeChannel({\n channelId: voucher.channelId,\n cumulativeAmount: voucher.cumulativeAmount,\n signature: voucher.signature,\n account: this.config.walletClient.account!,\n });\n }\n\n async topUpChannel(channelId: Hex, amount: bigint): Promise<Hash> {\n return this.writeActions.topUpChannel({\n channelId,\n amount,\n account: this.config.walletClient.account!,\n });\n }\n\n async requestClose(channelId: Hex): Promise<Hash> {\n return this.writeActions.requestCloseChannel({\n channelId,\n account: this.config.walletClient.account!,\n });\n }\n\n async withdraw(channelId: Hex): Promise<Hash> {\n return this.writeActions.withdrawChannel({\n channelId,\n account: this.config.walletClient.account!,\n });\n }\n\n async getChannelState(channelId: Hex): Promise<ChannelState> {\n return this.readActions.getChannel({ channelId });\n }\n\n async getCloseTimeout(): Promise<bigint> {\n return this.readActions.CLOSE_TIMEOUT();\n }\n\n async getVersion(): Promise<string> {\n return this.readActions.version();\n }\n}\n"]}
@@ -0,0 +1,421 @@
1
+ 'use strict';
2
+
3
+ var chunkFTJD2DWE_cjs = require('./chunk-FTJD2DWE.cjs');
4
+ var viem = require('viem');
5
+ var accountAbstraction = require('viem/account-abstraction');
6
+
7
+ var UserClient = class extends chunkFTJD2DWE_cjs.BaseClient {
8
+ accountAddress;
9
+ sbtAddress;
10
+ entryPointAddress;
11
+ gTokenStakingAddress;
12
+ registryAddress;
13
+ gTokenAddress;
14
+ bundlerClient;
15
+ constructor(config) {
16
+ super(config);
17
+ this.bundlerClient = config.bundlerClient;
18
+ this.accountAddress = config.accountAddress;
19
+ this.sbtAddress = config.sbtAddress;
20
+ this.entryPointAddress = config.entryPointAddress;
21
+ this.gTokenStakingAddress = config.gTokenStakingAddress;
22
+ this.registryAddress = config.registryAddress;
23
+ this.gTokenAddress = config.gTokenAddress;
24
+ }
25
+ /**
26
+ * Deploy a new Smart Account (Supports multiple factory types)
27
+ * Static helper to facilitate onboarding before instantiating the UserClient.
28
+ *
29
+ * @param client - WalletClient to sign the deployment transaction
30
+ * @param params - Deployment parameters
31
+ * @returns Object containing the deployed account address and transaction hash
32
+ */
33
+ static async deployAccount(client, params) {
34
+ const { accountFactoryActions, SimpleAccountFactoryABI } = await import('./src-TQKEO2I4.cjs');
35
+ let abi = params.customAbi || (SimpleAccountFactoryABI?.abi || SimpleAccountFactoryABI);
36
+ const factoryAddr = params.factoryAddress || "0x9406Cc6185a346906296840746125a0E44976454";
37
+ const salt = params.salt || 0n;
38
+ const readClient = params.publicClient || client;
39
+ const factoryRead = accountFactoryActions(factoryAddr, abi)(readClient);
40
+ const factoryWrite = accountFactoryActions(factoryAddr, abi)(client);
41
+ const accountAddress = await factoryRead.getAddress({
42
+ owner: params.owner,
43
+ salt
44
+ });
45
+ try {
46
+ const hash = await factoryWrite.createAccount({
47
+ owner: params.owner,
48
+ salt,
49
+ account: client.account
50
+ });
51
+ return { accountAddress, hash };
52
+ } catch (error) {
53
+ const messageParts = [
54
+ error?.shortMessage,
55
+ error?.message,
56
+ error?.details,
57
+ error?.cause?.shortMessage,
58
+ error?.cause?.message,
59
+ error?.cause?.details,
60
+ error?.cause?.cause?.shortMessage,
61
+ error?.cause?.cause?.message
62
+ ].filter(Boolean);
63
+ const message = messageParts.join(" ");
64
+ if (message.includes("gas required exceeds allowance") || message.includes("intrinsic gas too low")) {
65
+ const data = viem.encodeFunctionData({
66
+ abi,
67
+ functionName: "createAccount",
68
+ args: [params.owner, salt]
69
+ });
70
+ const hash = await client.sendTransaction({
71
+ to: factoryAddr,
72
+ data,
73
+ gas: 2000000n,
74
+ account: client.account
75
+ });
76
+ return { accountAddress, hash };
77
+ }
78
+ throw error;
79
+ }
80
+ }
81
+ // ========================================
82
+ // 1. 账户基本操作 (基于 L1 simpleAccountActions)
83
+ // ========================================
84
+ /**
85
+ * Get the nonce of the account from EntryPoint (more reliable for 4337)
86
+ */
87
+ async getNonce(key = 0n) {
88
+ try {
89
+ if (!this.entryPointAddress) {
90
+ throw new Error("EntryPoint address required for this client");
91
+ }
92
+ const entryPoint = chunkFTJD2DWE_cjs.entryPointActions(this.entryPointAddress);
93
+ return await entryPoint(this.getStartPublicClient()).getNonce({
94
+ sender: this.accountAddress,
95
+ key
96
+ });
97
+ } catch (error) {
98
+ throw error;
99
+ }
100
+ }
101
+ /**
102
+ * Get the owner of the AA account
103
+ */
104
+ async getOwner() {
105
+ try {
106
+ const account = chunkFTJD2DWE_cjs.accountActions(this.accountAddress);
107
+ return await account(this.getStartPublicClient()).owner();
108
+ } catch (error) {
109
+ throw error;
110
+ }
111
+ }
112
+ /**
113
+ * Execute a transaction from the AA account
114
+ */
115
+ async execute(target, value, data, options) {
116
+ try {
117
+ const account = chunkFTJD2DWE_cjs.accountActions(this.accountAddress);
118
+ return await account(this.client).execute({
119
+ dest: target,
120
+ value,
121
+ func: data,
122
+ account: options?.account
123
+ });
124
+ } catch (error) {
125
+ throw error;
126
+ }
127
+ }
128
+ /**
129
+ * Execute a batch of transactions
130
+ */
131
+ async executeBatch(targets, values, datas, options) {
132
+ try {
133
+ const account = chunkFTJD2DWE_cjs.accountActions(this.accountAddress);
134
+ return await account(this.client).executeBatch({
135
+ dest: targets,
136
+ value: values,
137
+ func: datas,
138
+ account: options?.account
139
+ });
140
+ } catch (error) {
141
+ throw error;
142
+ }
143
+ }
144
+ // ========================================
145
+ // identity 与 SBT (基于 L1 sbtActions)
146
+ // ========================================
147
+ /**
148
+ * Get user's SBT balance
149
+ */
150
+ async getSBTBalance() {
151
+ try {
152
+ if (!this.sbtAddress) throw new Error("SBT address required for this client");
153
+ const sbt = chunkFTJD2DWE_cjs.sbtActions(this.sbtAddress);
154
+ return await sbt(this.getStartPublicClient()).balanceOf({
155
+ owner: this.accountAddress
156
+ });
157
+ } catch (error) {
158
+ throw error;
159
+ }
160
+ }
161
+ async mintSBT(roleId, options) {
162
+ try {
163
+ if (!this.sbtAddress) throw new Error("SBT address required for this client");
164
+ const { encodeFunctionData: encodeFunctionData2 } = await import('viem');
165
+ const data = encodeFunctionData2({
166
+ abi: [{ name: "mintForRole", type: "function", inputs: [{ name: "user", type: "address" }, { name: "roleId", type: "bytes32" }, { name: "roleData", type: "bytes" }], outputs: [{ type: "uint256" }] }],
167
+ functionName: "mintForRole",
168
+ args: [this.accountAddress, roleId, "0x"]
169
+ });
170
+ return await this.execute(this.sbtAddress, 0n, data, options);
171
+ } catch (error) {
172
+ throw error;
173
+ }
174
+ }
175
+ // ========================================
176
+ // 3. 资产管理 (基于 L1 tokenActions)
177
+ // ========================================
178
+ async transferToken(token, to, amount, options) {
179
+ try {
180
+ const { encodeFunctionData: encodeFunctionData2 } = await import('viem');
181
+ const data = encodeFunctionData2({
182
+ abi: [{ name: "transfer", type: "function", inputs: [{ name: "to", type: "address" }, { name: "amount", type: "uint256" }], outputs: [{ type: "bool" }] }],
183
+ functionName: "transfer",
184
+ args: [to, amount]
185
+ });
186
+ return await this.execute(token, 0n, data, options);
187
+ } catch (error) {
188
+ throw error;
189
+ }
190
+ }
191
+ /**
192
+ * Get Token Balance
193
+ */
194
+ async getTokenBalance(token) {
195
+ try {
196
+ const tokens = chunkFTJD2DWE_cjs.tokenActions()(this.getStartPublicClient());
197
+ return await tokens.balanceOf({
198
+ token,
199
+ account: this.accountAddress
200
+ });
201
+ } catch (error) {
202
+ throw error;
203
+ }
204
+ }
205
+ // ========================================
206
+ // 4. 委托与质押 (Delegation & Staking)
207
+ // ========================================
208
+ async stakeForRole(roleId, amount, options) {
209
+ try {
210
+ if (!this.gTokenStakingAddress) throw new Error("GTokenStaking address required for this client");
211
+ const { encodeFunctionData: encodeFunctionData2 } = await import('viem');
212
+ const data = encodeFunctionData2({
213
+ abi: [{ name: "lockStake", type: "function", inputs: [{ name: "user", type: "address" }, { name: "roleId", type: "bytes32" }, { name: "stakeAmount", type: "uint256" }, { name: "entryBurn", type: "uint256" }, { name: "payer", type: "address" }], outputs: [] }],
214
+ functionName: "lockStake",
215
+ args: [this.accountAddress, roleId, amount, 0n, this.accountAddress]
216
+ });
217
+ return await this.execute(this.gTokenStakingAddress, 0n, data, options);
218
+ } catch (error) {
219
+ throw error;
220
+ }
221
+ }
222
+ async unstakeFromRole(roleId, options) {
223
+ try {
224
+ if (!this.gTokenStakingAddress) throw new Error("GTokenStaking address required for this client");
225
+ const { encodeFunctionData: encodeFunctionData2 } = await import('viem');
226
+ const data = encodeFunctionData2({
227
+ abi: [{ name: "unlockAndTransfer", type: "function", inputs: [{ name: "user", type: "address" }, { name: "roleId", type: "bytes32" }], outputs: [{ name: "netAmount", type: "uint256" }] }],
228
+ functionName: "unlockAndTransfer",
229
+ args: [this.accountAddress, roleId]
230
+ });
231
+ return await this.execute(this.gTokenStakingAddress, 0n, data, options);
232
+ } catch (error) {
233
+ throw error;
234
+ }
235
+ }
236
+ /**
237
+ * Get staked balance for a specific role
238
+ */
239
+ async getStakedBalance(roleId) {
240
+ try {
241
+ if (!this.gTokenStakingAddress) throw new Error("GTokenStaking address required for this client");
242
+ const staking = chunkFTJD2DWE_cjs.stakingActions(this.gTokenStakingAddress);
243
+ return await staking(this.getStartPublicClient()).getLockedStake({
244
+ user: this.accountAddress,
245
+ roleId
246
+ });
247
+ } catch (error) {
248
+ throw error;
249
+ }
250
+ }
251
+ // ========================================
252
+ // 5. 生命周期管理 (Lifecycle)
253
+ // ========================================
254
+ async exitRole(roleId, options) {
255
+ try {
256
+ if (!this.registryAddress) throw new Error("Registry address required for this client");
257
+ const { encodeFunctionData: encodeFunctionData2 } = await import('viem');
258
+ const data = encodeFunctionData2({
259
+ abi: [{ name: "exitRole", type: "function", inputs: [{ name: "roleId", type: "bytes32" }], outputs: [] }],
260
+ functionName: "exitRole",
261
+ args: [roleId]
262
+ });
263
+ return await this.execute(this.registryAddress, 0n, data, options);
264
+ } catch (error) {
265
+ throw error;
266
+ }
267
+ }
268
+ async leaveCommunity(community, options) {
269
+ try {
270
+ if (!this.sbtAddress) throw new Error("SBT address required for this client");
271
+ const { encodeFunctionData: encodeFunctionData2 } = await import('viem');
272
+ const data = encodeFunctionData2({
273
+ abi: [{ name: "leaveCommunity", type: "function", inputs: [{ name: "comm", type: "address" }], outputs: [] }],
274
+ functionName: "leaveCommunity",
275
+ args: [community]
276
+ });
277
+ return await this.execute(this.sbtAddress, 0n, data, options);
278
+ } catch (error) {
279
+ throw error;
280
+ }
281
+ }
282
+ /**
283
+ * Register as EndUser (One-click: Approve + Register)
284
+ * Handles GToken approval to Staking contract and Role registration.
285
+ */
286
+ async registerAsEndUser(communityAddress, stakeAmount, options) {
287
+ try {
288
+ if (!this.registryAddress) throw new Error("Registry address required for this client");
289
+ if (!this.gTokenStakingAddress) throw new Error("GTokenStaking address required for this client");
290
+ if (!this.gTokenAddress) throw new Error("GToken address required for this client");
291
+ const { encodeAbiParameters, keccak256, toBytes, parseEther } = await import('viem');
292
+ const ROLE_ENDUSER = keccak256(toBytes("ENDUSER"));
293
+ const registry = chunkFTJD2DWE_cjs.registryActions(this.registryAddress);
294
+ const publicClient = this.getStartPublicClient();
295
+ const tokens = chunkFTJD2DWE_cjs.tokenActions()(publicClient);
296
+ const allowance = await tokens.allowance({
297
+ token: this.gTokenAddress,
298
+ owner: this.accountAddress,
299
+ spender: this.gTokenStakingAddress
300
+ });
301
+ console.log(` \u{1F50D} Debug Allowance: Account=${this.accountAddress}, Allowance=${allowance}, Needed=${stakeAmount}`);
302
+ const txs = [];
303
+ if (allowance < stakeAmount) {
304
+ const approveData = viem.encodeFunctionData({
305
+ abi: [{ name: "approve", type: "function", inputs: [{ type: "address" }, { type: "uint256" }], outputs: [{ type: "bool" }], stateMutability: "nonpayable" }],
306
+ functionName: "approve",
307
+ args: [this.gTokenStakingAddress, parseEther("1000")]
308
+ });
309
+ txs.push({ target: this.gTokenAddress, value: 0n, data: approveData });
310
+ }
311
+ const roleData = encodeAbiParameters(
312
+ [
313
+ { type: "address", name: "account" },
314
+ { type: "address", name: "community" },
315
+ { type: "string", name: "avatarURI" },
316
+ { type: "string", name: "ensName" },
317
+ { type: "uint256", name: "stakeAmount" }
318
+ ],
319
+ [
320
+ this.accountAddress,
321
+ communityAddress,
322
+ "",
323
+ "",
324
+ stakeAmount
325
+ ]
326
+ );
327
+ const registerData = viem.encodeFunctionData({
328
+ abi: [{ name: "registerRoleSelf", type: "function", inputs: [{ type: "bytes32" }, { type: "bytes" }], outputs: [{ type: "uint256" }], stateMutability: "nonpayable" }],
329
+ functionName: "registerRoleSelf",
330
+ args: [ROLE_ENDUSER, roleData]
331
+ });
332
+ txs.push({ target: this.registryAddress, value: 0n, data: registerData });
333
+ console.log(` \u{1F50D} Debug Onboard: Community=${communityAddress}, AA=${this.accountAddress}, Stake=${stakeAmount}`);
334
+ console.log(` \u{1F50D} Debug Batch: Txs=${txs.length}, Targets=${txs.map((t) => t.target)}`);
335
+ const hashes = [];
336
+ for (const tx of txs) {
337
+ const h = await this.execute(tx.target, tx.value, tx.data, options);
338
+ hashes.push(h);
339
+ await this.getStartPublicClient().waitForTransactionReceipt({ hash: h });
340
+ }
341
+ return hashes[hashes.length - 1];
342
+ } catch (error) {
343
+ throw error;
344
+ }
345
+ }
346
+ // ========================================
347
+ // 6. Gasless Execution (Advanced)
348
+ // ========================================
349
+ /**
350
+ * Execute a transaction with Gasless Sponsorship
351
+ */
352
+ async executeGasless(params, options) {
353
+ try {
354
+ const client = this.bundlerClient ? this.bundlerClient.extend(accountAbstraction.bundlerActions) : this.client.extend(accountAbstraction.bundlerActions);
355
+ const ep = this.requireEntryPoint();
356
+ const callData = viem.encodeFunctionData({
357
+ abi: [{ name: "execute", type: "function", inputs: [{ name: "dest", type: "address" }, { name: "value", type: "uint256" }, { name: "func", type: "bytes" }], outputs: [] }],
358
+ functionName: "execute",
359
+ args: [params.target, params.value, params.data]
360
+ });
361
+ const { PaymasterClient: SDKPaymasterClient } = await import('./src-ENPA7D2S.cjs');
362
+ let verificationGasLimit;
363
+ let paymasterVerificationGasLimit;
364
+ let paymasterPostOpGasLimit;
365
+ let autoEstimate = true;
366
+ if (params.paymasterType === "Super") {
367
+ const { tuneGasLimit } = await import('./src-ENPA7D2S.cjs');
368
+ const est = await SDKPaymasterClient.estimateUserOperationGas(
369
+ this.client,
370
+ this.client,
371
+ this.accountAddress,
372
+ ep,
373
+ params.paymaster,
374
+ params.target,
375
+ // placeholder
376
+ this.bundlerClient?.transport?.url || this.client.transport.url || "",
377
+ callData,
378
+ {
379
+ operator: params.operator,
380
+ factory: void 0,
381
+ factoryData: void 0
382
+ }
383
+ );
384
+ const bundlerEstimate = est.paymasterVerificationGasLimit || 100000n;
385
+ paymasterVerificationGasLimit = tuneGasLimit(bundlerEstimate, 60000n, 0.45);
386
+ const SAFETY_PAD = 80000n;
387
+ verificationGasLimit = est.verificationGasLimit + SAFETY_PAD;
388
+ const _postOpBase = est.paymasterPostOpGasLimit + 100000n;
389
+ paymasterPostOpGasLimit = _postOpBase > 200000n ? _postOpBase : 200000n;
390
+ autoEstimate = false;
391
+ }
392
+ const txHash = await SDKPaymasterClient.submitGaslessUserOperation(
393
+ this.client,
394
+ this.client,
395
+ // WalletClient acts as signer
396
+ this.accountAddress,
397
+ ep,
398
+ params.paymaster,
399
+ params.target,
400
+ // placeholder for token if V4
401
+ this.bundlerClient?.transport?.url || this.client.transport.url || "",
402
+ callData,
403
+ {
404
+ operator: params.operator,
405
+ autoEstimate,
406
+ verificationGasLimit,
407
+ paymasterVerificationGasLimit,
408
+ paymasterPostOpGasLimit
409
+ }
410
+ );
411
+ return txHash;
412
+ } catch (error) {
413
+ console.error(" \u274C executeGasless Error:", error.message);
414
+ throw error;
415
+ }
416
+ }
417
+ };
418
+
419
+ exports.UserClient = UserClient;
420
+ //# sourceMappingURL=chunk-GX7NROST.cjs.map
421
+ //# sourceMappingURL=chunk-GX7NROST.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../enduser/src/UserClient.ts"],"names":["BaseClient","encodeFunctionData","entryPointActions","accountActions","sbtActions","tokenActions","stakingActions","registryActions","bundlerActions"],"mappings":";;;;;;AAgBO,IAAM,UAAA,GAAN,cAAyBA,4BAAA,CAAW;AAAA,EAChC,cAAA;AAAA,EACA,UAAA;AAAA,EACA,iBAAA;AAAA,EACA,oBAAA;AAAA,EACA,eAAA;AAAA,EACA,aAAA;AAAA,EACA,aAAA;AAAA,EAEP,YAAY,MAAA,EAA0B;AAClC,IAAA,KAAA,CAAM,MAAM,CAAA;AACZ,IAAA,IAAA,CAAK,gBAAgB,MAAA,CAAO,aAAA;AAC5B,IAAA,IAAA,CAAK,iBAAiB,MAAA,CAAO,cAAA;AAC7B,IAAA,IAAA,CAAK,aAAa,MAAA,CAAO,UAAA;AACzB,IAAA,IAAA,CAAK,oBAAoB,MAAA,CAAO,iBAAA;AAChC,IAAA,IAAA,CAAK,uBAAuB,MAAA,CAAO,oBAAA;AACnC,IAAA,IAAA,CAAK,kBAAkB,MAAA,CAAO,eAAA;AAC9B,IAAA,IAAA,CAAK,gBAAgB,MAAA,CAAO,aAAA;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,aAAa,aAAA,CACT,MAAA,EACA,M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, concat, pad, toHex, encodeFunctionData } from 'viem';\nimport { BaseClient, type ClientConfig, type TransactionOptions } from '@aastar/core';\nimport { accountActions, sbtActions, tokenActions, entryPointActions, stakingActions, registryActions, paymasterActions, superPaymasterActions } from '@aastar/core';\nimport { bundlerActions, type UserOperation, getUserOperationHash } from 'viem/account-abstraction';\n\nexport interface UserClientConfig extends ClientConfig {\n accountAddress: Address; // The AA account address\n sbtAddress?: Address;\n entryPointAddress?: Address;\n superPaymasterAddress?: Address; // For sponsorship queries\n gTokenStakingAddress?: Address; // For staking/investing\n registryAddress?: Address; // For role management\n gTokenAddress?: Address; // For fee payment approval\n bundlerClient?: any;\n}\n\nexport class UserClient extends BaseClient {\n public accountAddress: Address;\n public sbtAddress?: Address;\n public entryPointAddress?: Address;\n public gTokenStakingAddress?: Address;\n public registryAddress?: Address;\n public gTokenAddress?: Address;\n public bundlerClient?: any;\n\n constructor(config: UserClientConfig) {\n super(config);\n this.bundlerClient = config.bundlerClient;\n this.accountAddress = config.accountAddress;\n this.sbtAddress = config.sbtAddress;\n this.entryPointAddress = config.entryPointAddress;\n this.gTokenStakingAddress = config.gTokenStakingAddress;\n this.registryAddress = config.registryAddress;\n this.gTokenAddress = config.gTokenAddress;\n }\n\n /**\n * Deploy a new Smart Account (Supports multiple factory types)\n * Static helper to facilitate onboarding before instantiating the UserClient.\n * \n * @param client - WalletClient to sign the deployment transaction\n * @param params - Deployment parameters\n * @returns Object containing the deployed account address and transaction hash\n */\n static async deployAccount(\n client: any, \n params: {\n owner: Address;\n salt?: bigint;\n factoryAddress?: Address;\n publicClient?: any;\n accountType?: 'simple' | 'kernel' | 'safe' | string;\n customAbi?: any;\n }\n ): Promise<{ accountAddress: Address; hash: Hash }> {\n const { accountFactoryActions, SimpleAccountFactoryABI } = await import('@aastar/core');\n \n // 1. Determine Factory ABI (Ensure it's the raw ABI array)\n let abi = params.customAbi || (SimpleAccountFactoryABI?.abi || SimpleAccountFactoryABI);\n \n // In the future, we can add more built-in ABIs here based on accountType\n // if (params.accountType === 'kernel') abi = KernelFactoryABI;\n \n const factoryAddr = params.factoryAddress || '0x9406Cc6185a346906296840746125a0E44976454'; // Default v0.7 Factory\n const salt = params.salt || 0n;\n \n // Use publicClient for reading if provided, otherwise fallback to client (which might be a Full Client)\n const readClient = params.publicClient || client;\n \n // Use the generic actions with the selected ABI\n const factoryRead = accountFactoryActions(factoryAddr, abi)(readClient);\n const factoryWrite = accountFactoryActions(factoryAddr, abi)(client);\n \n // 1. Predict Address\n const accountAddress = await factoryRead.getAddress({\n owner: params.owner,\n salt\n });\n\n // 2. Deploy\n try {\n const hash = await factoryWrite.createAccount({\n owner: params.owner,\n salt,\n account: client.account\n });\n return { accountAddress, hash };\n } catch (error: any) {\n const messageParts = [\n error?.shortMessage,\n error?.message,\n error?.details,\n error?.cause?.shortMessage,\n error?.cause?.message,\n error?.cause?.details,\n error?.cause?.cause?.shortMessage,\n error?.cause?.cause?.message\n ].filter(Boolean);\n const message = messageParts.join(' ');\n if (message.includes('gas required exceeds allowance') || message.includes('intrinsic gas too low')) {\n const data = encodeFunctionData({\n abi,\n functionName: 'createAccount',\n args: [params.owner, salt]\n });\n const hash = await client.sendTransaction({\n to: factoryAddr,\n data,\n gas: 2_000_000n,\n account: client.account\n });\n return { accountAddress, hash };\n }\n throw error;\n }\n }\n\n // ========================================\n // 1. 账户基本操作 (基于 L1 simpleAccountActions)\n // ========================================\n\n /**\n * Get the nonce of the account from EntryPoint (more reliable for 4337)\n */\n async getNonce(key: bigint = 0n): Promise<bigint> {\n try {\n if (!this.entryPointAddress) {\n throw new Error('EntryPoint address required for this client');\n }\n const entryPoint = entryPointActions(this.entryPointAddress);\n return await entryPoint(this.getStartPublicClient()).getNonce({\n sender: this.accountAddress,\n key\n });\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Get the owner of the AA account\n */\n async getOwner(): Promise<Address> {\n try {\n const account = accountActions(this.accountAddress);\n return await account(this.getStartPublicClient()).owner();\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Execute a transaction from the AA account\n */\n async execute(target: Address, value: bigint, data: Hex, options?: TransactionOptions): Promise<Hash> {\n try {\n const account = accountActions(this.accountAddress);\n \n // Use standard AA execute\n return await account(this.client).execute({\n dest: target,\n value,\n func: data,\n account: options?.account\n });\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Execute a batch of transactions\n */\n async executeBatch(targets: Address[], values: bigint[], datas: Hex[], options?: TransactionOptions): Promise<Hash> {\n try {\n const account = accountActions(this.accountAddress);\n \n return await account(this.client).executeBatch({\n dest: targets,\n value: values,\n func: datas,\n account: options?.account\n });\n } catch (error) {\n throw error;\n }\n }\n\n // ========================================\n // identity 与 SBT (基于 L1 sbtActions)\n // ========================================\n\n /**\n * Get user's SBT balance\n */\n async getSBTBalance(): Promise<bigint> {\n try {\n if (!this.sbtAddress) throw new Error('SBT address required for this client');\n const sbt = sbtActions(this.sbtAddress);\n \n return await sbt(this.getStartPublicClient()).balanceOf({\n owner: this.accountAddress\n });\n } catch (error) {\n throw error;\n }\n }\n\n async mintSBT(roleId: Hex, options?: TransactionOptions): Promise<Hash> {\n try {\n if (!this.sbtAddress) throw new Error('SBT address required for this client');\n const { encodeFunctionData } = await import('viem');\n \n const data = encodeFunctionData({\n abi: [{ name: 'mintForRole', type: 'function', inputs: [{ name: 'user', type: 'address' }, { name: 'roleId', type: 'bytes32' }, { name: 'roleData', type: 'bytes' }], outputs: [{ type: 'uint256' }] }],\n functionName: 'mintForRole',\n args: [this.accountAddress, roleId, '0x']\n });\n\n return await this.execute(this.sbtAddress, 0n, data, options);\n } catch (error) {\n throw error;\n }\n }\n\n // ========================================\n // 3. 资产管理 (基于 L1 tokenActions)\n // ========================================\n\n async transferToken(token: Address, to: Address, amount: bigint, options?: TransactionOptions): Promise<Hash> {\n try {\n const { encodeFunctionData } = await import('viem');\n const data = encodeFunctionData({\n abi: [{ name: 'transfer', type: 'function', inputs: [{ name: 'to', type: 'address' }, { name: 'amount', type: 'uint256' }], outputs: [{ type: 'bool' }] }],\n functionName: 'transfer',\n args: [to, amount]\n });\n\n return await this.execute(token, 0n, data, options);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Get Token Balance\n */\n async getTokenBalance(token: Address): Promise<bigint> {\n try {\n const tokens = tokenActions()(this.getStartPublicClient());\n \n return await tokens.balanceOf({\n token,\n account: this.accountAddress\n });\n } catch (error) {\n throw error;\n }\n }\n\n // ========================================\n // 4. 委托与质押 (Delegation & Staking)\n // ========================================\n\n async stakeForRole(roleId: Hex, amount: bigint, options?: TransactionOptions): Promise<Hash> {\n try {\n if (!this.gTokenStakingAddress) throw new Error('GTokenStaking address required for this client');\n const { encodeFunctionData } = await import('viem');\n \n const data = encodeFunctionData({\n abi: [{ name: 'lockStake', type: 'function', inputs: [{ name: 'user', type: 'address' }, { name: 'roleId', type: 'bytes32' }, { name: 'stakeAmount', type: 'uint256' }, { name: 'entryBurn', type: 'uint256' }, { name: 'payer', type: 'address' }], outputs: [] }],\n functionName: 'lockStake',\n args: [this.accountAddress, roleId, amount, 0n, this.accountAddress]\n });\n\n return await this.execute(this.gTokenStakingAddress, 0n, data, options);\n } catch (error) {\n throw error;\n }\n }\n\n async unstakeFromRole(roleId: Hex, options?: TransactionOptions): Promise<Hash> {\n try {\n if (!this.gTokenStakingAddress) throw new Error('GTokenStaking address required for this client');\n const { encodeFunctionData } = await import('viem');\n \n const data = encodeFunctionData({\n abi: [{ name: 'unlockAndTransfer', type: 'function', inputs: [{ name: 'user', type: 'address' }, { name: 'roleId', type: 'bytes32' }], outputs: [{ name: 'netAmount', type: 'uint256' }] }],\n functionName: 'unlockAndTransfer',\n args: [this.accountAddress, roleId]\n });\n\n return await this.execute(this.gTokenStakingAddress, 0n, data, options);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Get staked balance for a specific role\n */\n async getStakedBalance(roleId: Hex): Promise<bigint> {\n try {\n if (!this.gTokenStakingAddress) throw new Error('GTokenStaking address required for this client');\n const staking = stakingActions(this.gTokenStakingAddress);\n \n return await staking(this.getStartPublicClient()).getLockedStake({\n user: this.accountAddress,\n roleId\n });\n } catch (error) {\n throw error;\n }\n }\n\n // ========================================\n // 5. 生命周期管理 (Lifecycle)\n // ========================================\n\n async exitRole(roleId: Hex, options?: TransactionOptions): Promise<Hash> {\n try {\n if (!this.registryAddress) throw new Error('Registry address required for this client');\n const { encodeFunctionData } = await import('viem');\n \n const data = encodeFunctionData({\n abi: [{ name: 'exitRole', type: 'function', inputs: [{ name: 'roleId', type: 'bytes32' }], outputs: [] }],\n functionName: 'exitRole',\n args: [roleId]\n });\n\n return await this.execute(this.registryAddress, 0n, data, options);\n } catch (error) {\n throw error;\n }\n }\n\n async leaveCommunity(community: Address, options?: TransactionOptions): Promise<Hash> {\n try {\n if (!this.sbtAddress) throw new Error('SBT address required for this client');\n const { encodeFunctionData } = await import('viem');\n \n const data = encodeFunctionData({\n abi: [{ name: 'leaveCommunity', type: 'function', inputs: [{ name: 'comm', type: 'address' }], outputs: [] }],\n functionName: 'leaveCommunity',\n args: [community]\n });\n\n return await this.execute(this.sbtAddress, 0n, data, options);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Register as EndUser (One-click: Approve + Register)\n * Handles GToken approval to Staking contract and Role registration.\n */\n async registerAsEndUser(communityAddress: Address, stakeAmount: bigint, options?: TransactionOptions): Promise<Hash> {\n try {\n if (!this.registryAddress) throw new Error('Registry address required for this client');\n if (!this.gTokenStakingAddress) throw new Error('GTokenStaking address required for this client');\n if (!this.gTokenAddress) throw new Error('GToken address required for this client');\n\n const { encodeAbiParameters, keccak256, toBytes, parseEther } = await import('viem');\n const ROLE_ENDUSER = keccak256(toBytes(\"ENDUSER\"));\n // Correct mapping for Registry Actions\n const registry = registryActions(this.registryAddress);\n const publicClient = this.getStartPublicClient();\n const tokens = tokenActions()(publicClient);\n\n // 1. Check Allowance\n const allowance = await tokens.allowance({\n token: this.gTokenAddress,\n owner: this.accountAddress,\n spender: this.gTokenStakingAddress\n });\n console.log(` 🔍 Debug Allowance: Account=${this.accountAddress}, Allowance=${allowance}, Needed=${stakeAmount}`);\n \n const txs: { target: Address, value: bigint, data: Hex }[] = [];\n\n if (allowance < stakeAmount) {\n const approveData = encodeFunctionData({\n abi: [{name:'approve', type:'function', inputs:[{type:'address'},{type:'uint256'}], outputs:[{type:'bool'}], stateMutability:'nonpayable'}],\n functionName: 'approve',\n args: [this.gTokenStakingAddress, parseEther('1000')]\n });\n txs.push({ target: this.gTokenAddress, value: 0n, data: approveData });\n }\n\n // 2. Construct Register Call\n // struct EndUserRoleData { address account; address community; string avatarURI; string ensName; uint256 stakeAmount; }\n const roleData = encodeAbiParameters(\n [\n { type: 'address', name: 'account' },\n { type: 'address', name: 'community' },\n { type: 'string', name: 'avatarURI' },\n { type: 'string', name: 'ensName' },\n { type: 'uint256', name: 'stakeAmount' }\n ],\n [\n this.accountAddress,\n communityAddress,\n '',\n '',\n stakeAmount\n ]\n );\n\n const registerData = encodeFunctionData({\n abi: [{ name: 'registerRoleSelf', type: 'function', inputs: [{type:'bytes32'}, {type:'bytes'}], outputs: [{type:'uint256'}], stateMutability: 'nonpayable' }],\n functionName: 'registerRoleSelf',\n args: [ROLE_ENDUSER, roleData]\n });\n \n txs.push({ target: this.registryAddress, value: 0n, data: registerData });\n \n console.log(` 🔍 Debug Onboard: Community=${communityAddress}, AA=${this.accountAddress}, Stake=${stakeAmount}`);\n console.log(` 🔍 Debug Batch: Txs=${txs.length}, Targets=${txs.map(t => t.target)}`);\n\n // 3. Execute separately for stability (Batch execution has issues on current AA deployment)\n const hashes: Hash[] = [];\n for (const tx of txs) {\n const h = await this.execute(tx.target, tx.value, tx.data, options);\n hashes.push(h);\n // Wait for each tx to ensure sequential state updates (approve -> register)\n await (this.getStartPublicClient() as any).waitForTransactionReceipt({ hash: h });\n }\n return hashes[hashes.length - 1];\n } catch (error) {\n throw error;\n }\n }\n\n // ========================================\n // 6. Gasless Execution (Advanced)\n // ========================================\n\n /**\n * Execute a transaction with Gasless Sponsorship\n */\n async executeGasless(params: {\n target: Address;\n value: bigint;\n data: Hex;\n paymaster: Address;\n paymasterType: 'V4' | 'Super';\n operator?: Address; // Added for SuperPaymaster\n maxRate?: bigint; // Added for SuperPaymaster\n }, options?: TransactionOptions): Promise<Hash> {\n try {\n const client = this.bundlerClient ? this.bundlerClient.extend(bundlerActions) : (this.client as any).extend(bundlerActions);\n \n const ep = this.requireEntryPoint();\n \n // 1. Prepare Call Data\n const callData = encodeFunctionData({\n abi: [{ name: 'execute', type: 'function', inputs: [{ name: 'dest', type: 'address' }, { name: 'value', type: 'uint256' }, { name: 'func', type: 'bytes' }], outputs: [] }],\n functionName: 'execute',\n args: [params.target, params.value, params.data]\n });\n\n // 3. Delegate to PaymasterClient for v0.7 Gasless Submission\n // This ensures we follow the exact same logic as successful demo scripts\n // We dynamic import to avoid circular dependencies if any\n const { PaymasterClient: SDKPaymasterClient } = await import('@aastar/paymaster');\n \n let verificationGasLimit: bigint | undefined;\n let paymasterVerificationGasLimit: bigint | undefined;\n let paymasterPostOpGasLimit: bigint | undefined;\n let autoEstimate = true;\n\n if (params.paymasterType === 'Super') {\n // Apply Smart Buffer Strategy via PaymasterUtils (Same as SuperPaymasterClient)\n const { tuneGasLimit } = await import('@aastar/paymaster');\n \n const est = await SDKPaymasterClient.estimateUserOperationGas(\n this.client,\n this.client, \n this.accountAddress,\n ep,\n params.paymaster,\n params.target, // placeholder\n this.bundlerClient?.transport?.url || (this.client.transport as any).url || '', \n callData,\n {\n operator: params.operator,\n factory: undefined,\n factoryData: undefined\n }\n );\n \n // Matches SuperPaymasterClient Logic exactly:\n const bundlerEstimate = est.paymasterVerificationGasLimit || 100000n;\n // Nominal 60k, Efficiency 0.45\n paymasterVerificationGasLimit = tuneGasLimit(bundlerEstimate, 60_000n, 0.45);\n \n // Safety Pad for VGL (Moderate, not 1M)\n const SAFETY_PAD = 80000n;\n verificationGasLimit = est.verificationGasLimit + SAFETY_PAD;\n \n // SuperPaymaster postOp calls burnFromWithOpHash (~40k gas) + storage writes.\n // Add 100k buffer; floor at 200k to prevent OOG. Pure BigInt to avoid Number precision loss.\n const _postOpBase = est.paymasterPostOpGasLimit + 100_000n;\n paymasterPostOpGasLimit = _postOpBase > 200_000n ? _postOpBase : 200_000n;\n \n autoEstimate = false; // logic handled\n }\n\n const txHash = await SDKPaymasterClient.submitGaslessUserOperation(\n this.client,\n this.client, // WalletClient acts as signer\n this.accountAddress,\n ep,\n params.paymaster,\n params.target, // placeholder for token if V4\n this.bundlerClient?.transport?.url || (this.client.transport as any).url || '', \n callData,\n {\n operator: params.operator,\n autoEstimate, \n verificationGasLimit,\n paymasterVerificationGasLimit,\n paymasterPostOpGasLimit\n }\n );\n\n return txHash;\n } catch (error: any) {\n console.error(\" ❌ executeGasless Error:\", error.message);\n throw error;\n }\n }\n}\n"]}