@aastar/core 0.16.8 → 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,48 +1,44 @@
1
1
  import { type Address, type WalletClient, type PublicClient } from 'viem';
2
+ export type FaucetPreparationResult = {
3
+ ethFunded: boolean;
4
+ roleRegistered: boolean;
5
+ tokenMinted: boolean;
6
+ paymasterDeposited: boolean;
7
+ };
8
+ export type FaucetConfig = {
9
+ targetAA: Address;
10
+ token: Address;
11
+ registry: Address;
12
+ paymasterV4?: Address;
13
+ ethAmount?: bigint;
14
+ tokenAmount?: bigint;
15
+ };
16
+ /**
17
+ * SepoliaFaucetAPI provides orchestration for setting up test accounts on Sepolia/Anvil.
18
+ */
2
19
  export declare class SepoliaFaucetAPI {
3
20
  /**
4
21
  * Orchestrates the complete setup for a test account.
5
22
  * 1. Funds ETH
6
23
  * 2. Registers ENDUSER role
7
- * 3. Mints potential Paymaster Tokens (cPNTs/dPNTs)
24
+ * 3. Mints GTokens to user
8
25
  * 4. Deposits to Paymaster V4 (if address provided) using Admin's tokens
9
26
  */
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
- }>;
27
+ static prepareTestAccount(adminWallet: WalletClient, publicClient: PublicClient, config: FaucetConfig): Promise<FaucetPreparationResult>;
25
28
  /**
26
29
  * Funds the target with ETH if balance is below threshold.
27
30
  */
28
31
  static fundETH(adminWallet: WalletClient, publicClient: PublicClient, target: Address, amount: bigint): Promise<boolean>;
29
- /**
30
- * Registers the ENDUSER role via Registry.
31
- */
32
32
  /**
33
33
  * Registers the ENDUSER role using Sponsor Mode (Admin pays stake).
34
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>;
35
+ static registerEndUser(adminWallet: WalletClient, publicClient: PublicClient, registryAddr: Address, target: Address, gasToken: Address): Promise<boolean>;
37
36
  /**
38
37
  * Mints tokens directly to the target.
39
38
  */
40
- static mintTestTokens(adminWallet: WalletClient, publicClient: PublicClient, token: Address, target: Address, amount: bigint): Promise<boolean>;
39
+ static mintTestTokens(adminWallet: WalletClient, publicClient: PublicClient, tokenAddr: Address, target: Address, amount: bigint): Promise<boolean>;
41
40
  /**
42
- * Complex Flow:
43
- * 1. Admin mints tokens to SELF.
44
- * 2. Admin approves Paymaster.
45
- * 3. Admin calls depositFor(target) on Paymaster.
41
+ * Admin mints tokens to self, approves Paymaster, and deposits FOR user.
46
42
  */
47
- static adminDepositForUser(adminWallet: WalletClient, publicClient: PublicClient, paymaster: Address, target: Address, token: Address, amount: bigint): Promise<boolean>;
43
+ static adminDepositForUser(adminWallet: WalletClient, publicClient: PublicClient, paymasterAddr: Address, target: Address, tokenAddr: Address, amount: bigint): Promise<boolean>;
48
44
  }
@@ -1,336 +1,197 @@
1
- import { parseEther, parseAbi, formatEther, zeroAddress, encodeAbiParameters } from 'viem';
2
- import { sepolia } from 'viem/chains';
3
- // Standard ERC20 ABI for minting/approving
4
- const ERC20_ABI = parseAbi([
5
- 'function mint(address to, uint256 amount) external',
6
- 'function approve(address spender, uint256 amount) external returns (bool)',
7
- 'function balanceOf(address account) external view returns (uint256)',
8
- 'function allowance(address owner, address spender) external view returns (uint256)',
9
- 'function transfer(address to, uint256 amount) external returns (bool)'
10
- ]);
11
- const PAYMASTER_ABI = parseAbi([
12
- 'function depositFor(address target, uint256 amount) external',
13
- 'function deposit() external payable'
14
- ]);
1
+ import { parseEther, formatEther } from 'viem';
2
+ import { registryActions } from './registry.js';
3
+ import { gTokenActions } from './tokens.js';
4
+ import { paymasterActions } from './paymaster.js';
5
+ import { validateAddress, validateAmount, validateRequired } from '../validators/index.js';
6
+ import { AAStarError } from '../errors/index.js';
7
+ /**
8
+ * SepoliaFaucetAPI provides orchestration for setting up test accounts on Sepolia/Anvil.
9
+ */
15
10
  export class SepoliaFaucetAPI {
16
11
  /**
17
12
  * Orchestrates the complete setup for a test account.
18
13
  * 1. Funds ETH
19
14
  * 2. Registers ENDUSER role
20
- * 3. Mints potential Paymaster Tokens (cPNTs/dPNTs)
15
+ * 3. Mints GTokens to user
21
16
  * 4. Deposits to Paymaster V4 (if address provided) using Admin's tokens
22
17
  */
23
18
  static async prepareTestAccount(adminWallet, publicClient, config) {
24
- console.log(`\n🚰 SepoliaFaucetAPI: Preparing ${config.targetAA}...`);
25
- const results = {
26
- ethFunded: false,
27
- roleRegistered: false,
28
- tokenMinted: false,
29
- paymasterDeposited: false
30
- };
31
- // 1. Fund ETH
32
- const ethAmount = config.ethAmount ?? parseEther('0.1');
33
- results.ethFunded = await this.fundETH(adminWallet, publicClient, config.targetAA, ethAmount);
34
- // 2. Register EndUser
35
- results.roleRegistered = await this.registerEndUser(adminWallet, publicClient, config.registry, config.targetAA, config.token, config.community);
36
- // 3. Mint Tokens (User Holding Logic - for SuperPaymaster)
37
- // If SuperPaymaster is involved, User needs to HOLD the token.
38
- // If Paymaster V4 is involved, User might need to HOLD (Pull mode) or Admin Deposits (Push mode).
39
- // Strategy: Always mint some to User for flexibility.
40
- const tokenAmount = config.tokenAmount ?? parseEther('1000');
41
- results.tokenMinted = await this.mintTestTokens(adminWallet, publicClient, config.token, config.targetAA, tokenAmount);
42
- // 4. Admin Deposit for User (Paymaster V4 Logic)
43
- if (config.paymasterV4) {
44
- results.paymasterDeposited = await this.adminDepositForUser(adminWallet, publicClient, config.paymasterV4, config.targetAA, config.token, parseEther('10') // Deposit 10 Tokens for testing
45
- );
19
+ try {
20
+ validateRequired(adminWallet, 'adminWallet');
21
+ validateRequired(publicClient, 'publicClient');
22
+ validateAddress(config.targetAA, 'targetAA');
23
+ validateAddress(config.token, 'token');
24
+ validateAddress(config.registry, 'registry');
25
+ console.log(`\n🚰 SepoliaFaucetAPI: Preparing ${config.targetAA}...`);
26
+ const results = {
27
+ ethFunded: false,
28
+ roleRegistered: false,
29
+ tokenMinted: false,
30
+ paymasterDeposited: false
31
+ };
32
+ // 1. Fund ETH
33
+ const ethAmount = config.ethAmount ?? parseEther('0.1');
34
+ results.ethFunded = await this.fundETH(adminWallet, publicClient, config.targetAA, ethAmount);
35
+ // 2. Register EndUser
36
+ results.roleRegistered = await this.registerEndUser(adminWallet, publicClient, config.registry, config.targetAA, config.token);
37
+ // 3. Mint Tokens
38
+ const tokenAmount = config.tokenAmount ?? parseEther('1000');
39
+ results.tokenMinted = await this.mintTestTokens(adminWallet, publicClient, config.token, config.targetAA, tokenAmount);
40
+ // 4. Admin Deposit for User (Paymaster V4 Logic)
41
+ if (config.paymasterV4) {
42
+ validateAddress(config.paymasterV4, 'paymasterV4');
43
+ results.paymasterDeposited = await this.adminDepositForUser(adminWallet, publicClient, config.paymasterV4, config.targetAA, config.token, parseEther('10') // Deposit 10 Tokens for testing
44
+ );
45
+ }
46
+ console.log(`✅ Preparation Complete!`, results);
47
+ return results;
48
+ }
49
+ catch (error) {
50
+ throw AAStarError.fromViemError(error, 'prepareTestAccount');
46
51
  }
47
- console.log(`✅ Preparation Complete!`, results);
48
- return results;
49
52
  }
50
53
  /**
51
54
  * Funds the target with ETH if balance is below threshold.
52
55
  */
53
56
  static async fundETH(adminWallet, publicClient, target, amount) {
54
- const balance = await publicClient.getBalance({ address: target });
55
- // Threshold: 50% of target amount
56
- if (balance < (amount / 2n)) {
57
- console.log(` 💰 Funding ETH... (Before: ${formatEther(balance)})`);
58
- const hash = await adminWallet.sendTransaction({
59
- to: target,
60
- value: amount,
61
- chain: sepolia,
62
- account: adminWallet.account
63
- });
64
- await publicClient.waitForTransactionReceipt({ hash, timeout: 300000 });
65
- console.log(` -> Sent ${formatEther(amount)} ETH. Tx: ${hash}`);
66
- return true;
57
+ try {
58
+ validateAddress(target, 'target');
59
+ validateAmount(amount, 'amount');
60
+ const balance = await publicClient.getBalance({ address: target });
61
+ // Threshold: 50% of target amount
62
+ if (balance < (amount / 2n)) {
63
+ console.log(` 💰 Funding ETH... (Before: ${formatEther(balance)})`);
64
+ const hash = await adminWallet.sendTransaction({
65
+ to: target,
66
+ value: amount,
67
+ account: adminWallet.account,
68
+ chain: adminWallet.chain
69
+ });
70
+ await publicClient.waitForTransactionReceipt({ hash, timeout: 120000 });
71
+ console.log(` -> Sent ${formatEther(amount)} ETH. Tx: ${hash}`);
72
+ return true;
73
+ }
74
+ console.log(` ✅ ETH Balance adequate (${formatEther(balance)} ETH).`);
75
+ return false;
76
+ }
77
+ catch (error) {
78
+ throw AAStarError.fromViemError(error, 'fundETH');
67
79
  }
68
- console.log(` ✅ ETH Balance adequate (${formatEther(balance)} ETH).`);
69
- return false;
70
80
  }
71
- /**
72
- * Registers the ENDUSER role via Registry.
73
- */
74
81
  /**
75
82
  * Registers the ENDUSER role using Sponsor Mode (Admin pays stake).
76
83
  */
77
- static async registerEndUser(adminWallet, publicClient, registryAddr, target, gasToken, // Re-using the 'token' passed in config which is GToken
78
- community) {
79
- // ENDUSER Hash: keccak256("ENDUSER")
80
- const ENDUSER_ROLE = '0x0c34ecc75d3bf122e0609d2576e167f53fb42429262ce8c9b33cab91ff670e3a';
81
- // 1. Check if already registered
82
- const hasRole = await publicClient.readContract({
83
- address: registryAddr,
84
- abi: parseAbi(['function hasRole(bytes32 role, address account) view returns (bool)']),
85
- functionName: 'hasRole',
86
- args: [ENDUSER_ROLE, target]
87
- });
88
- if (hasRole) {
89
- console.log(` ✅ ENDUSER Role already held.`);
90
- return false;
91
- }
92
- console.log(` 👤 Registering ENDUSER role (Sponsor Mode)...`);
84
+ static async registerEndUser(adminWallet, publicClient, registryAddr, target, gasToken) {
93
85
  try {
94
- // 2. Get Staking Contract Address
95
- const stakingAddr = await publicClient.readContract({
96
- address: registryAddr,
97
- abi: parseAbi(['function GTOKEN_STAKING() view returns (address)']),
98
- functionName: 'GTOKEN_STAKING'
99
- });
100
- // Fetch the actual GToken required by Staking
101
- const stakingToken = await publicClient.readContract({
102
- address: stakingAddr,
103
- abi: parseAbi(['function GTOKEN() view returns (address)']),
104
- functionName: 'GTOKEN'
105
- });
106
- // 3. Admin Approves Staking Contract (if needed)
86
+ validateAddress(registryAddr, 'registryAddr');
87
+ validateAddress(target, 'target');
88
+ validateAddress(gasToken, 'gasToken');
89
+ const registry = registryActions(registryAddr)(publicClient);
90
+ const walletRegistry = registryActions(registryAddr)(adminWallet);
91
+ const token = gTokenActions(gasToken)(publicClient);
92
+ const walletToken = gTokenActions(gasToken)(adminWallet);
93
+ // 1. Get ENDUSER Role ID
94
+ const ENDUSER_ROLE = await registry.ROLE_ENDUSER();
95
+ // 2. Check if already registered
96
+ const hasRole = await registry.hasRole({ roleId: ENDUSER_ROLE, user: target });
97
+ if (hasRole) {
98
+ console.log(` ✅ ENDUSER Role already held.`);
99
+ return false;
100
+ }
101
+ console.log(` 👤 Registering ENDUSER role (Sponsor Mode)...`);
102
+ // 3. Get Staking Contract Address
103
+ const stakingAddr = await registry.GTOKEN_STAKING();
104
+ // 4. Admin Approves Staking Contract (if needed)
107
105
  const adminAddr = adminWallet.account.address;
108
- console.log(` 🔎 Debug Staking: Registry=${registryAddr}, Staking=${stakingAddr}`);
109
- console.log(` 🔎 Debug Token: Contract=${stakingToken}`);
110
- // Check allowance for the STAKING TOKEN
111
- const allowance = await publicClient.readContract({
112
- address: stakingToken,
113
- abi: ERC20_ABI,
114
- functionName: 'allowance',
115
- args: [adminAddr, stakingAddr]
116
- });
117
- console.log(` 🔎 Debug Allowance: ${formatEther(allowance)} (Needed: >0.5)`);
118
- // Approve if needed (standard stake ~0.3 ETH, verify enough)
119
- const approveAmount = parseEther('1000'); // A sufficiently large amount
106
+ const allowance = await token.allowance({ token: gasToken, owner: adminAddr, spender: stakingAddr });
120
107
  if (allowance < parseEther('500')) {
121
- console.log(' 🔓 Approving Staking Contract (Core Token)...');
122
- const hashApprove = await adminWallet.writeContract({
123
- address: stakingToken,
124
- abi: ERC20_ABI,
125
- functionName: 'approve',
126
- args: [stakingAddr, approveAmount],
127
- chain: sepolia,
128
- account: adminWallet.account
129
- });
130
- await publicClient.waitForTransactionReceipt({ hash: hashApprove, timeout: 300000 });
131
- console.log(` 🔓 Approving Staking Contract... ${hashApprove}`);
132
- // Ensure Admin has GTokens (Staking Token) balance
133
- const adminGBal = await publicClient.readContract({
134
- address: stakingToken,
135
- abi: ERC20_ABI,
136
- functionName: 'balanceOf',
137
- args: [adminAddr]
138
- });
139
- if (adminGBal < parseEther('100')) {
140
- console.log(` 🪙 Minting GTokens (Staking Token) to Admin...`);
141
- try {
142
- const hashGMint = await adminWallet.writeContract({
143
- address: stakingToken,
144
- abi: ERC20_ABI,
145
- functionName: 'mint',
146
- args: [adminAddr, parseEther('1000')],
147
- chain: sepolia,
148
- account: adminWallet.account
149
- });
150
- await publicClient.waitForTransactionReceipt({ hash: hashGMint, timeout: 300000 });
151
- console.log(` ✅ GTokens Minted. Tx: ${hashGMint}`);
152
- }
153
- catch (e) {
154
- console.warn(` ⚠️ Failed to mint GTokens (Admin might not be minter):`, e);
155
- }
156
- }
157
- }
158
- // ALSO Approve Registry (just in case it pulls first)
159
- const allowReg = await publicClient.readContract({
160
- address: stakingToken,
161
- abi: ERC20_ABI,
162
- functionName: 'allowance',
163
- args: [adminAddr, registryAddr]
164
- });
165
- if (allowReg < parseEther('500')) {
166
- console.log(' 🔓 Approving Registry Contract...');
167
- const hash = await adminWallet.writeContract({
168
- address: stakingToken,
169
- abi: ERC20_ABI,
170
- functionName: 'approve',
171
- args: [registryAddr, parseEther('1000')],
172
- chain: sepolia,
173
- account: adminWallet.account
108
+ console.log(` 🔓 Approving Staking Contract...`);
109
+ const hashApprove = await walletToken.approve({
110
+ token: gasToken,
111
+ spender: stakingAddr,
112
+ amount: parseEther('1000')
174
113
  });
175
- await publicClient.waitForTransactionReceipt({ hash, timeout: 300000 });
176
- console.log(` ✅ Approved Registry. Tx: ${hash}`);
177
- }
178
- else {
179
- console.log(' ✅ Allowance sufficient.');
114
+ await publicClient.waitForTransactionReceipt({ hash: hashApprove });
180
115
  }
181
- // 5. Register Role (registerRole)
182
- // EndUser Role Data: (address account, address community, string avatarURI, string ensName, uint256 stakeAmount)
183
- const userData = encodeAbiParameters([
184
- { name: 'account', type: 'address' },
185
- { name: 'community', type: 'address' },
186
- { name: 'avatarURI', type: 'string' },
187
- { name: 'ensName', type: 'string' },
188
- { name: 'stakeAmount', type: 'uint256' }
189
- ],
190
- // Stake Amount 0, relying on Registry to enforce minStake and charge msg.sender
191
- [target, community || zeroAddress, '', '', 0n]);
192
- const hashMint = await adminWallet.writeContract({
193
- address: registryAddr,
194
- abi: parseAbi([
195
- 'function safeMintForRole(bytes32 roleId, address user, bytes calldata data) external returns (uint256)',
196
- 'error InvalidParameter(string message)'
197
- ]),
198
- functionName: 'safeMintForRole',
199
- args: [ENDUSER_ROLE, target, userData],
200
- chain: sepolia,
201
- account: adminWallet.account
116
+ // 5. SafeMint (Sponsor)
117
+ const userData = '0x';
118
+ const hashMint = await walletRegistry.safeMintForRole({
119
+ roleId: ENDUSER_ROLE,
120
+ user: target,
121
+ data: userData
202
122
  });
203
- await publicClient.waitForTransactionReceipt({ hash: hashMint, timeout: 300000 });
123
+ await publicClient.waitForTransactionReceipt({ hash: hashMint, timeout: 120000 });
204
124
  console.log(` -> Role Sponsored & Granted. Tx: ${hashMint}`);
205
125
  return true;
206
126
  }
207
127
  catch (error) {
208
- console.warn(` ⚠️ Failed to sponsor ENDUSER role. Error:`, error);
209
- return false;
128
+ throw AAStarError.fromViemError(error, 'registerEndUser');
210
129
  }
211
130
  }
212
131
  /**
213
132
  * Mints tokens directly to the target.
214
133
  */
215
- static async mintTestTokens(adminWallet, publicClient, token, target, amount) {
216
- const balance = await publicClient.readContract({
217
- address: token,
218
- abi: ERC20_ABI,
219
- functionName: 'balanceOf',
220
- args: [target]
221
- });
222
- if (balance < amount) {
223
- console.log(` 🪙 Funding Tokens... (Current: ${formatEther(balance)})`);
224
- const adminAddr = adminWallet.account.address;
225
- // 1. Try Transfer from Admin (if Admin has balance)
226
- const adminBal = await publicClient.readContract({
227
- address: token,
228
- abi: ERC20_ABI,
229
- functionName: 'balanceOf',
230
- args: [adminAddr]
231
- });
232
- if (adminBal >= amount) {
233
- console.log(` 💸 Transferring from Admin...`);
234
- const hash = await adminWallet.writeContract({
235
- address: token,
236
- abi: ERC20_ABI,
237
- functionName: 'transfer',
238
- args: [target, amount],
239
- chain: sepolia,
240
- account: adminWallet.account
241
- });
242
- await publicClient.waitForTransactionReceipt({ hash, timeout: 300000 });
243
- console.log(` ✅ Transferred ${formatEther(amount)}. Tx: ${hash}`);
244
- return true;
245
- }
246
- // 2. Try Mint (Assuming Admin has Minter Role or is Owner)
247
- console.log(` 🪙 Admin balance low. Attempting Mint...`);
248
- try {
249
- const hash = await adminWallet.writeContract({
250
- address: token,
251
- abi: ERC20_ABI,
252
- functionName: 'mint',
253
- args: [target, amount],
254
- chain: sepolia,
255
- account: adminWallet.account
256
- });
257
- await publicClient.waitForTransactionReceipt({ hash, timeout: 300000 });
258
- console.log(` ✅ Minted ${formatEther(amount)}. Tx: ${hash}`);
134
+ static async mintTestTokens(adminWallet, publicClient, tokenAddr, target, amount) {
135
+ try {
136
+ validateAddress(tokenAddr, 'tokenAddr');
137
+ validateAddress(target, 'target');
138
+ validateAmount(amount, 'amount');
139
+ const token = gTokenActions(tokenAddr)(publicClient);
140
+ const walletToken = gTokenActions(tokenAddr)(adminWallet);
141
+ const balance = await token.balanceOf({ token: tokenAddr, account: target });
142
+ if (balance < amount) {
143
+ console.log(` 🪙 Minting Tokens... (Current: ${formatEther(balance)})`);
144
+ const hash = await walletToken.mint({ token: tokenAddr, to: target, amount });
145
+ await publicClient.waitForTransactionReceipt({ hash, timeout: 120000 });
146
+ console.log(` -> Minted ${formatEther(amount)}. Tx: ${hash}`);
259
147
  return true;
260
148
  }
261
- catch (e) {
262
- console.warn(` ⚠️ Failed to mint/transfer tokens. Check Admin permissions/balance.`, e);
263
- return false;
264
- }
149
+ console.log(` ✅ Token Balance adequate.`);
150
+ return false;
151
+ }
152
+ catch (error) {
153
+ throw AAStarError.fromViemError(error, 'mintTestTokens');
265
154
  }
266
- console.log(` ✅ Token Balance adequate.`);
267
- return false;
268
155
  }
269
156
  /**
270
- * Complex Flow:
271
- * 1. Admin mints tokens to SELF.
272
- * 2. Admin approves Paymaster.
273
- * 3. Admin calls depositFor(target) on Paymaster.
157
+ * Admin mints tokens to self, approves Paymaster, and deposits FOR user.
274
158
  */
275
- static async adminDepositForUser(adminWallet, publicClient, paymaster, target, token, amount) {
276
- // 1. Mint to Admin First
277
- const adminAddr = adminWallet.account.address;
278
- const adminBal = await publicClient.readContract({
279
- address: token,
280
- abi: ERC20_ABI,
281
- functionName: 'balanceOf',
282
- args: [adminAddr]
283
- });
284
- if (adminBal < amount) {
285
- console.log(` 🏧 Admin Minting to Self (for deposit)...`);
286
- const hash = await adminWallet.writeContract({
287
- address: token,
288
- abi: ERC20_ABI,
289
- functionName: 'mint',
290
- args: [adminAddr, amount * 10n], // bulk mint
291
- chain: sepolia,
292
- account: adminWallet.account
293
- });
294
- await publicClient.waitForTransactionReceipt({ hash, timeout: 300000 });
295
- console.log(` -> Admin Minted. Tx: ${hash}`);
296
- }
297
- // 2. Approve Paymaster
298
- const allowance = await publicClient.readContract({
299
- address: token,
300
- abi: ERC20_ABI,
301
- functionName: 'allowance',
302
- args: [adminAddr, paymaster]
303
- });
304
- if (allowance < amount) {
305
- console.log(` 🔓 Admin Approving Paymaster...`);
306
- const hash = await adminWallet.writeContract({
307
- address: token,
308
- abi: ERC20_ABI,
309
- functionName: 'approve',
310
- args: [paymaster, 115792089237316195423570985008687907853269984665640564039457584007913129639935n], // Max Uint
311
- chain: sepolia,
312
- account: adminWallet.account
313
- });
314
- await publicClient.waitForTransactionReceipt({ hash, timeout: 300000 });
315
- console.log(` -> Approved Paymaster. Tx: ${hash}`);
316
- }
317
- // 3. Deposit For
318
- console.log(` 🏦 Depositing FOR User...`);
159
+ static async adminDepositForUser(adminWallet, publicClient, paymasterAddr, target, tokenAddr, amount) {
319
160
  try {
320
- const hash = await adminWallet.writeContract({
321
- address: paymaster,
322
- abi: PAYMASTER_ABI,
323
- functionName: 'depositFor',
324
- args: [target, amount],
325
- chain: sepolia,
326
- account: adminWallet.account
327
- });
328
- await publicClient.waitForTransactionReceipt({ hash, timeout: 300000 });
161
+ validateAddress(paymasterAddr, 'paymasterAddr');
162
+ validateAddress(target, 'target');
163
+ validateAddress(tokenAddr, 'tokenAddr');
164
+ validateAmount(amount, 'amount');
165
+ const token = gTokenActions(tokenAddr)(publicClient);
166
+ const walletToken = gTokenActions(tokenAddr)(adminWallet);
167
+ const paymaster = paymasterActions(paymasterAddr)(adminWallet);
168
+ const adminAddr = adminWallet.account.address;
169
+ const adminBal = await token.balanceOf({ token: tokenAddr, account: adminAddr });
170
+ if (adminBal < amount) {
171
+ console.log(` 🏧 Admin Minting to Self (for deposit)...`);
172
+ const hash = await walletToken.mint({ token: tokenAddr, to: adminAddr, amount: amount * 10n });
173
+ await publicClient.waitForTransactionReceipt({ hash });
174
+ }
175
+ const allowance = await token.allowance({ token: tokenAddr, owner: adminAddr, spender: paymasterAddr });
176
+ if (allowance < amount) {
177
+ console.log(` 🔓 Admin Approving Paymaster...`);
178
+ // Use a large but finite amount instead of max uint for safety/clarity if desired,
179
+ // but max uint is common in faucets.
180
+ const hashApprove = await walletToken.approve({
181
+ token: tokenAddr,
182
+ spender: paymasterAddr,
183
+ amount: parseEther('10000')
184
+ });
185
+ await publicClient.waitForTransactionReceipt({ hash: hashApprove });
186
+ }
187
+ console.log(` 🏦 Depositing FOR User...`);
188
+ const hash = await paymaster.depositFor({ user: target, token: tokenAddr, amount });
189
+ await publicClient.waitForTransactionReceipt({ hash, timeout: 120000 });
329
190
  console.log(` -> Deposited ${formatEther(amount)} to PM. Tx: ${hash}`);
330
191
  return true;
331
192
  }
332
- catch (e) {
333
- console.warn(` ⚠️ Deposit Failed (Maybe not supported on this PM?):`, e);
193
+ catch (error) {
194
+ console.warn(` ⚠️ Deposit Failed (Maybe not supported on this PM?):`, error);
334
195
  return false;
335
196
  }
336
197
  }
@@ -2,11 +2,10 @@ export * from './registry.js';
2
2
  export * from './staking.js';
3
3
  export * from './sbt.js';
4
4
  export * from './superPaymaster.js';
5
- export * from './paymasterV4.js';
5
+ export * from './paymaster.js';
6
6
  export * from './reputation.js';
7
7
  export * from './tokens.js';
8
8
  export * from './entryPoint.js';
9
- export * from './gtokenExtended.js';
10
9
  export * from './StateValidator.js';
11
10
  export * from './dvt.js';
12
11
  export * from './factory.js';
@@ -2,16 +2,14 @@ export * from './registry.js';
2
2
  export * from './staking.js';
3
3
  export * from './sbt.js';
4
4
  export * from './superPaymaster.js';
5
- export * from './paymasterV4.js';
5
+ export * from './paymaster.js';
6
6
  export * from './reputation.js';
7
7
  export * from './tokens.js';
8
8
  export * from './entryPoint.js';
9
- export * from './gtokenExtended.js';
10
9
  export * from './StateValidator.js';
11
10
  export * from './dvt.js';
12
11
  export * from './factory.js';
13
12
  export * from './aggregator.js';
14
13
  export * from './account.js';
15
14
  export * from './faucet.js';
16
- // validators.ts merged into dvt.js and aggregator.js
17
- // validators.ts merged into dvt.js and aggregator.js
15
+ // validators.ts legacy removed