@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.
- package/dist/abis/PaymasterV4_2.json +1193 -0
- package/dist/abis/SuperPaymaster.json +1 -1
- package/dist/abis/aPNTs.json +1160 -0
- package/dist/abis/abi.config.json +3 -3
- package/dist/abis/index.d.ts +15 -104
- package/dist/abis/index.js +22 -46
- package/dist/actions/account.d.ts +0 -15
- package/dist/actions/account.js +143 -108
- package/dist/actions/aggregator.d.ts +68 -7
- package/dist/actions/aggregator.js +328 -28
- package/dist/actions/dvt.d.ts +33 -5
- package/dist/actions/dvt.js +238 -38
- package/dist/actions/entryPoint.d.ts +3 -63
- package/dist/actions/entryPoint.js +52 -184
- package/dist/actions/factory.d.ts +48 -115
- package/dist/actions/factory.js +638 -438
- package/dist/actions/faucet.d.ts +23 -27
- package/dist/actions/faucet.js +150 -289
- package/dist/actions/index.d.ts +1 -2
- package/dist/actions/index.js +2 -4
- package/dist/actions/paymaster.d.ts +147 -0
- package/dist/actions/paymaster.js +706 -0
- package/dist/actions/paymasterV4.d.ts +26 -95
- package/dist/actions/paymasterV4.js +28 -121
- package/dist/actions/registry.d.ts +116 -165
- package/dist/actions/registry.js +855 -654
- package/dist/actions/reputation.d.ts +74 -52
- package/dist/actions/reputation.js +548 -242
- package/dist/actions/sbt.d.ts +90 -100
- package/dist/actions/sbt.js +801 -518
- package/dist/actions/staking.d.ts +45 -32
- package/dist/actions/staking.js +431 -260
- package/dist/actions/superPaymaster.d.ts +140 -158
- package/dist/actions/superPaymaster.js +965 -631
- package/dist/actions/tokens.d.ts +130 -108
- package/dist/actions/tokens.js +470 -414
- package/dist/actions/validators.d.ts +0 -73
- package/dist/actions/validators.js +0 -94
- package/dist/clients/BaseClient.d.ts +3 -3
- package/dist/clients/BundlerClient.d.ts +55 -0
- package/dist/clients/BundlerClient.js +92 -0
- package/dist/communities.js +2 -2
- package/dist/constants.js +1 -28
- package/dist/contract-addresses.d.ts +5 -14
- package/dist/contract-addresses.js +3 -9
- package/dist/contract-versions.d.ts +138 -0
- package/dist/contract-versions.js +328 -0
- package/dist/contracts.d.ts +6 -24
- package/dist/contracts.js +2 -2
- package/dist/errors/index.d.ts +57 -0
- package/dist/errors/index.js +123 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/requirementChecker.d.ts +35 -1
- package/dist/requirementChecker.js +39 -1
- package/dist/roles.d.ts +50 -61
- package/dist/roles.js +50 -61
- package/dist/validators/index.d.ts +35 -0
- package/dist/validators/index.js +60 -0
- package/package.json +5 -13
package/dist/actions/faucet.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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,
|
|
39
|
+
static mintTestTokens(adminWallet: WalletClient, publicClient: PublicClient, tokenAddr: Address, target: Address, amount: bigint): Promise<boolean>;
|
|
41
40
|
/**
|
|
42
|
-
*
|
|
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,
|
|
43
|
+
static adminDepositForUser(adminWallet: WalletClient, publicClient: PublicClient, paymasterAddr: Address, target: Address, tokenAddr: Address, amount: bigint): Promise<boolean>;
|
|
48
44
|
}
|
package/dist/actions/faucet.js
CHANGED
|
@@ -1,336 +1,197 @@
|
|
|
1
|
-
import { parseEther,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
results.
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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(
|
|
122
|
-
const hashApprove = await
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
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.
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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:
|
|
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
|
-
|
|
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,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
*
|
|
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,
|
|
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
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
await
|
|
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 (
|
|
333
|
-
console.warn(` ⚠️ Deposit Failed (Maybe not supported on this PM?):`,
|
|
193
|
+
catch (error) {
|
|
194
|
+
console.warn(` ⚠️ Deposit Failed (Maybe not supported on this PM?):`, error);
|
|
334
195
|
return false;
|
|
335
196
|
}
|
|
336
197
|
}
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -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 './
|
|
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';
|
package/dist/actions/index.js
CHANGED
|
@@ -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 './
|
|
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
|
|
17
|
-
// validators.ts merged into dvt.js and aggregator.js
|
|
15
|
+
// validators.ts legacy removed
|