@dag-kit/kit 1.0.2 → 1.0.4-alpha.3
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/index.cjs +564 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +209 -0
- package/dist/index.d.ts +209 -0
- package/dist/index.js +544 -0
- package/dist/index.js.map +1 -0
- package/package.json +16 -11
- package/src/clients/actions/contract.ts +1 -1
- package/src/clients/actions/example.ts +252 -252
- package/src/clients/actions/example2.ts +60 -60
- package/src/clients/actions/index.ts +145 -0
- package/src/clients/actions/main.ts +34 -17
- package/src/clients/actions/test.ts +210 -210
- package/src/clients/types.ts +2 -1
- package/src/exports/index.ts +7 -4
- package/src/exports/public-types.ts +6 -0
- package/src/index.ts +17 -0
- package/src/signers/PrivateKeySigner.ts +41 -0
- package/src/signers/PrivySigner.ts +93 -0
- package/src/signers/types.ts +45 -0
- package/src/version.ts +1 -1
- package/dist/esm/clients/actions/contract.js +0 -42
- package/dist/esm/clients/actions/example.js +0 -211
- package/dist/esm/clients/actions/example2.js +0 -50
- package/dist/esm/clients/actions/index.js +0 -1
- package/dist/esm/clients/actions/main.js +0 -415
- package/dist/esm/clients/actions/test.js +0 -1
- package/dist/esm/clients/actions/testPaymasterService.js +0 -88
- package/dist/esm/clients/chains.js +0 -19
- package/dist/esm/clients/types.js +0 -1
- package/dist/esm/exports/index.js +0 -2
- package/dist/esm/version.js +0 -3
- package/dist/types/clients/actions/contract.d.ts +0 -12
- package/dist/types/clients/actions/contract.d.ts.map +0 -1
- package/dist/types/clients/actions/example.d.ts +0 -2
- package/dist/types/clients/actions/example.d.ts.map +0 -1
- package/dist/types/clients/actions/example2.d.ts +0 -2
- package/dist/types/clients/actions/example2.d.ts.map +0 -1
- package/dist/types/clients/actions/index.d.ts +0 -1
- package/dist/types/clients/actions/index.d.ts.map +0 -1
- package/dist/types/clients/actions/main.d.ts +0 -40
- package/dist/types/clients/actions/main.d.ts.map +0 -1
- package/dist/types/clients/actions/test.d.ts +0 -1
- package/dist/types/clients/actions/test.d.ts.map +0 -1
- package/dist/types/clients/actions/testPaymasterService.d.ts +0 -2
- package/dist/types/clients/actions/testPaymasterService.d.ts.map +0 -1
- package/dist/types/clients/chains.d.ts +0 -81
- package/dist/types/clients/chains.d.ts.map +0 -1
- package/dist/types/clients/types.d.ts +0 -31
- package/dist/types/clients/types.d.ts.map +0 -1
- package/dist/types/exports/index.d.ts +0 -4
- package/dist/types/exports/index.d.ts.map +0 -1
- package/dist/types/version.d.ts +0 -2
- package/dist/types/version.d.ts.map +0 -1
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
// ==============================================================================
|
|
2
|
-
// DAG AA SDK - BlockDAG Account Abstraction SDK
|
|
3
|
-
// Inspired by Alchemy AA SDK
|
|
4
|
-
// ==============================================================================
|
|
5
|
-
import { createPublicClient, createWalletClient, http, encodeFunctionData, parseEther, } from "viem";
|
|
6
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
7
|
-
import { toSimpleSmartAccount } from "permissionless/accounts";
|
|
8
|
-
import { createPimlicoClient } from "permissionless/clients/pimlico";
|
|
9
|
-
import { entryPoint06Address } from "viem/account-abstraction";
|
|
10
|
-
import { createSmartAccountClient } from "permissionless";
|
|
11
|
-
// ==============================================================================
|
|
12
|
-
// Main SDK Class
|
|
13
|
-
// ==============================================================================
|
|
14
|
-
export class DagAAClient {
|
|
15
|
-
config;
|
|
16
|
-
publicClient;
|
|
17
|
-
walletClient;
|
|
18
|
-
bundlerClient = null;
|
|
19
|
-
smartAccount = null;
|
|
20
|
-
paymasterClient = null;
|
|
21
|
-
smartAccountClient = null;
|
|
22
|
-
constructor(config) {
|
|
23
|
-
this.config = {
|
|
24
|
-
...config,
|
|
25
|
-
entryPointAddress: config.entryPointAddress || entryPoint06Address,
|
|
26
|
-
};
|
|
27
|
-
this.publicClient = createPublicClient({
|
|
28
|
-
chain: config.chain,
|
|
29
|
-
transport: http(config.rpcUrl),
|
|
30
|
-
});
|
|
31
|
-
this.walletClient = createWalletClient({
|
|
32
|
-
chain: config.chain,
|
|
33
|
-
transport: http(config.rpcUrl),
|
|
34
|
-
});
|
|
35
|
-
// Initialize paymaster client if URL provided
|
|
36
|
-
if (config.paymasterUrl) {
|
|
37
|
-
this.paymasterClient = this.createPaymasterClient(config.paymasterUrl);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
// ==============================================================================
|
|
41
|
-
// Paymaster Client (Fixed Serialization)
|
|
42
|
-
// ==============================================================================
|
|
43
|
-
createPaymasterClient(paymasterUrl) {
|
|
44
|
-
// 1. Define a robust serializer that handles nested BigInts automatically
|
|
45
|
-
const stringify = (data) => {
|
|
46
|
-
return JSON.stringify(data, (_, value) => typeof value === "bigint" ? `0x${value.toString(16)}` : value);
|
|
47
|
-
};
|
|
48
|
-
return {
|
|
49
|
-
/**
|
|
50
|
-
* Get paymaster stub data for gas estimation
|
|
51
|
-
*/
|
|
52
|
-
async getPaymasterStubData(userOp, entryPoint) {
|
|
53
|
-
try {
|
|
54
|
-
const response = await fetch(paymasterUrl, {
|
|
55
|
-
method: "POST",
|
|
56
|
-
headers: { "Content-Type": "application/json" },
|
|
57
|
-
// 👇 Use the robust stringify helper
|
|
58
|
-
body: stringify({
|
|
59
|
-
jsonrpc: "2.0",
|
|
60
|
-
id: 1,
|
|
61
|
-
method: "pm_getPaymasterStubData",
|
|
62
|
-
params: [userOp, entryPoint, {}],
|
|
63
|
-
}),
|
|
64
|
-
});
|
|
65
|
-
const data = await response.json();
|
|
66
|
-
if (data.error)
|
|
67
|
-
throw new Error(data.error.message);
|
|
68
|
-
return data.result;
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
console.warn("Failed to get paymaster stub data:", error);
|
|
72
|
-
// ⚠️ If this fails, the UserOp usually fails with AA21
|
|
73
|
-
return { paymasterAndData: "0x" };
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
/**
|
|
77
|
-
* Get paymaster data for actual transaction
|
|
78
|
-
*/
|
|
79
|
-
async getPaymasterData(userOp, entryPoint) {
|
|
80
|
-
try {
|
|
81
|
-
const response = await fetch(paymasterUrl, {
|
|
82
|
-
method: "POST",
|
|
83
|
-
headers: { "Content-Type": "application/json" },
|
|
84
|
-
body: stringify({
|
|
85
|
-
jsonrpc: "2.0",
|
|
86
|
-
id: 1,
|
|
87
|
-
method: "pm_getPaymasterData",
|
|
88
|
-
params: [userOp, entryPoint, {}],
|
|
89
|
-
}),
|
|
90
|
-
});
|
|
91
|
-
const data = await response.json();
|
|
92
|
-
if (data.error)
|
|
93
|
-
throw new Error(data.error.message);
|
|
94
|
-
return data.result;
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
console.warn("Failed to get paymaster data:", error);
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
/**
|
|
102
|
-
* Sponsor user operation
|
|
103
|
-
*/
|
|
104
|
-
async sponsorUserOperation(userOp, entryPoint) {
|
|
105
|
-
try {
|
|
106
|
-
const response = await fetch(paymasterUrl, {
|
|
107
|
-
method: "POST",
|
|
108
|
-
headers: { "Content-Type": "application/json" },
|
|
109
|
-
body: stringify({
|
|
110
|
-
jsonrpc: "2.0",
|
|
111
|
-
id: 1,
|
|
112
|
-
method: "pm_sponsorUserOperation",
|
|
113
|
-
params: [userOp, entryPoint, {}],
|
|
114
|
-
}),
|
|
115
|
-
});
|
|
116
|
-
const data = await response.json();
|
|
117
|
-
if (data.error)
|
|
118
|
-
throw new Error(data.error.message);
|
|
119
|
-
return data.result;
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
console.warn("Failed to sponsor user operation:", error);
|
|
123
|
-
throw error;
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
// ==============================================================================
|
|
129
|
-
// Smart Account Management
|
|
130
|
-
// ==============================================================================
|
|
131
|
-
async connectSmartAccount(accountConfig) {
|
|
132
|
-
const owner = privateKeyToAccount(accountConfig.owner);
|
|
133
|
-
const signingClient = createWalletClient({
|
|
134
|
-
account: owner,
|
|
135
|
-
chain: this.config.chain,
|
|
136
|
-
transport: http(this.config.rpcUrl),
|
|
137
|
-
});
|
|
138
|
-
if (accountConfig.accountAddress) {
|
|
139
|
-
// Use existing account
|
|
140
|
-
this.smartAccount = await toSimpleSmartAccount({
|
|
141
|
-
client: signingClient,
|
|
142
|
-
owner: owner,
|
|
143
|
-
factoryAddress: this.config.factoryAddress,
|
|
144
|
-
entryPoint: {
|
|
145
|
-
address: this.config.entryPointAddress,
|
|
146
|
-
version: "0.6",
|
|
147
|
-
},
|
|
148
|
-
address: accountConfig.accountAddress,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
// Create new account
|
|
153
|
-
this.smartAccount = await toSimpleSmartAccount({
|
|
154
|
-
client: signingClient,
|
|
155
|
-
owner: owner,
|
|
156
|
-
factoryAddress: this.config.factoryAddress,
|
|
157
|
-
entryPoint: {
|
|
158
|
-
address: this.config.entryPointAddress,
|
|
159
|
-
version: "0.6",
|
|
160
|
-
},
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
// Create bundler client
|
|
164
|
-
this.bundlerClient = createPimlicoClient({
|
|
165
|
-
transport: http(this.config.bundlerUrl),
|
|
166
|
-
entryPoint: {
|
|
167
|
-
address: this.config.entryPointAddress,
|
|
168
|
-
version: "0.6",
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
// Create smart account client with optional paymaster
|
|
172
|
-
const clientConfig = {
|
|
173
|
-
bundlerTransport: http(this.config.bundlerUrl),
|
|
174
|
-
chain: this.config.chain,
|
|
175
|
-
account: this.smartAccount,
|
|
176
|
-
};
|
|
177
|
-
// Add paymaster if configured
|
|
178
|
-
if (this.paymasterClient) {
|
|
179
|
-
clientConfig.paymaster = {
|
|
180
|
-
getPaymasterData: async (userOperation) => {
|
|
181
|
-
console.log("🎫 Requesting paymaster sponsorship...");
|
|
182
|
-
console.log("UserOp sender:", userOperation.sender);
|
|
183
|
-
try {
|
|
184
|
-
const result = await this.paymasterClient.sponsorUserOperation(userOperation, this.config.entryPointAddress);
|
|
185
|
-
console.log("Paymaster result:", result);
|
|
186
|
-
if (result && result.paymasterAndData) {
|
|
187
|
-
console.log("✅ Paymaster sponsorship approved!");
|
|
188
|
-
console.log("PaymasterAndData:", result.paymasterAndData);
|
|
189
|
-
return {
|
|
190
|
-
paymasterAndData: result.paymasterAndData,
|
|
191
|
-
...(result.preVerificationGas && {
|
|
192
|
-
preVerificationGas: BigInt(result.preVerificationGas),
|
|
193
|
-
}),
|
|
194
|
-
...(result.verificationGasLimit && {
|
|
195
|
-
verificationGasLimit: BigInt(result.verificationGasLimit),
|
|
196
|
-
}),
|
|
197
|
-
...(result.callGasLimit && {
|
|
198
|
-
callGasLimit: BigInt(result.callGasLimit),
|
|
199
|
-
}),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
console.error("❌ No paymasterAndData in response:", result);
|
|
204
|
-
throw new Error("No paymaster data returned");
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
console.error("❌ Paymaster sponsorship failed:", error);
|
|
209
|
-
throw error;
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
getPaymasterStubData: async (userOperation) => {
|
|
213
|
-
console.log("📝 Getting paymaster stub data for gas estimation...");
|
|
214
|
-
try {
|
|
215
|
-
const result = await this.paymasterClient.getPaymasterStubData(userOperation, this.config.entryPointAddress);
|
|
216
|
-
console.log("Stub data result:", result);
|
|
217
|
-
if (result && result.paymasterAndData) {
|
|
218
|
-
console.log("✅ Got paymaster stub data");
|
|
219
|
-
return {
|
|
220
|
-
paymasterAndData: result.paymasterAndData,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
console.warn("⚠️ Failed to get paymaster stub data:", error);
|
|
226
|
-
}
|
|
227
|
-
// Return default stub if fails
|
|
228
|
-
console.log("⚠️ Using default stub data");
|
|
229
|
-
return {
|
|
230
|
-
paymasterAndData: "0x",
|
|
231
|
-
};
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
this.smartAccountClient = createSmartAccountClient(clientConfig);
|
|
236
|
-
console.log(`✅ Connected to smart account: ${this.smartAccount.address}`);
|
|
237
|
-
return this.smartAccount.address;
|
|
238
|
-
}
|
|
239
|
-
// ==============================================================================
|
|
240
|
-
// Account Information
|
|
241
|
-
// ==============================================================================
|
|
242
|
-
getAddress() {
|
|
243
|
-
if (!this.smartAccount) {
|
|
244
|
-
throw new Error("Smart account not connected. Call connectSmartAccount() first.");
|
|
245
|
-
}
|
|
246
|
-
return this.smartAccount.address;
|
|
247
|
-
}
|
|
248
|
-
async getBalance() {
|
|
249
|
-
if (!this.smartAccount) {
|
|
250
|
-
throw new Error("Smart account not connected");
|
|
251
|
-
}
|
|
252
|
-
return await this.publicClient.getBalance({
|
|
253
|
-
address: this.smartAccount.address,
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
async isDeployed() {
|
|
257
|
-
if (!this.smartAccount) {
|
|
258
|
-
throw new Error("Smart account not connected");
|
|
259
|
-
}
|
|
260
|
-
const code = await this.publicClient.getCode({
|
|
261
|
-
address: this.smartAccount.address,
|
|
262
|
-
});
|
|
263
|
-
return code !== undefined && code !== "0x";
|
|
264
|
-
}
|
|
265
|
-
async getNonce() {
|
|
266
|
-
if (!this.smartAccount) {
|
|
267
|
-
throw new Error("Smart account not connected");
|
|
268
|
-
}
|
|
269
|
-
return await this.publicClient.readContract({
|
|
270
|
-
address: this.config.entryPointAddress,
|
|
271
|
-
abi: [
|
|
272
|
-
{
|
|
273
|
-
name: "getNonce",
|
|
274
|
-
type: "function",
|
|
275
|
-
stateMutability: "view",
|
|
276
|
-
inputs: [
|
|
277
|
-
{ name: "sender", type: "address" },
|
|
278
|
-
{ name: "key", type: "uint192" },
|
|
279
|
-
],
|
|
280
|
-
outputs: [{ name: "nonce", type: "uint256" }],
|
|
281
|
-
},
|
|
282
|
-
],
|
|
283
|
-
functionName: "getNonce",
|
|
284
|
-
args: [this.smartAccount.address, 0n],
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
// ==============================================================================
|
|
288
|
-
// Send UserOperations
|
|
289
|
-
// ==============================================================================
|
|
290
|
-
async sendUserOperation(params) {
|
|
291
|
-
if (!this.smartAccountClient) {
|
|
292
|
-
throw new Error("Smart account not connected");
|
|
293
|
-
}
|
|
294
|
-
const { target, data = "0x", value = 0n, maxFeePerGas, maxPriorityFeePerGas, callGasLimit, verificationGasLimit, preVerificationGas, } = params;
|
|
295
|
-
// Get gas prices if not provided
|
|
296
|
-
let gasPrices = {
|
|
297
|
-
maxFeePerGas: maxFeePerGas,
|
|
298
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas,
|
|
299
|
-
};
|
|
300
|
-
if (!maxFeePerGas || !maxPriorityFeePerGas) {
|
|
301
|
-
const estimatedGas = await this.bundlerClient.getUserOperationGasPrice();
|
|
302
|
-
gasPrices = {
|
|
303
|
-
maxFeePerGas: maxFeePerGas || estimatedGas.fast.maxFeePerGas,
|
|
304
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas || estimatedGas.fast.maxPriorityFeePerGas,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
console.log("Sending UserOperation...");
|
|
308
|
-
console.log(` Target: ${target}`);
|
|
309
|
-
console.log(` Value: ${value}`);
|
|
310
|
-
console.log(` Gas: ${gasPrices.maxFeePerGas} / ${gasPrices.maxPriorityFeePerGas}`);
|
|
311
|
-
const txOptions = {
|
|
312
|
-
calls: [
|
|
313
|
-
{
|
|
314
|
-
to: target,
|
|
315
|
-
value: value,
|
|
316
|
-
data: data,
|
|
317
|
-
},
|
|
318
|
-
],
|
|
319
|
-
maxFeePerGas: gasPrices.maxFeePerGas,
|
|
320
|
-
maxPriorityFeePerGas: gasPrices.maxPriorityFeePerGas,
|
|
321
|
-
};
|
|
322
|
-
// Add optional gas limits if provided
|
|
323
|
-
if (callGasLimit)
|
|
324
|
-
txOptions.callGasLimit = callGasLimit;
|
|
325
|
-
if (verificationGasLimit)
|
|
326
|
-
txOptions.verificationGasLimit = verificationGasLimit;
|
|
327
|
-
if (preVerificationGas)
|
|
328
|
-
txOptions.preVerificationGas = preVerificationGas;
|
|
329
|
-
// Send transaction - paymaster is automatically called if configured
|
|
330
|
-
const userOpHash = await this.smartAccountClient.sendTransaction(txOptions);
|
|
331
|
-
console.log(`✅ UserOperation sent: ${userOpHash}`);
|
|
332
|
-
return userOpHash;
|
|
333
|
-
}
|
|
334
|
-
// ==============================================================================
|
|
335
|
-
// Contract Interactions
|
|
336
|
-
// ==============================================================================
|
|
337
|
-
async writeContract(params) {
|
|
338
|
-
const { address, abi, functionName, args = [], value = 0n } = params;
|
|
339
|
-
const data = encodeFunctionData({
|
|
340
|
-
abi,
|
|
341
|
-
functionName,
|
|
342
|
-
args,
|
|
343
|
-
});
|
|
344
|
-
return await this.sendUserOperation({
|
|
345
|
-
target: address,
|
|
346
|
-
data,
|
|
347
|
-
value,
|
|
348
|
-
maxFeePerGas: params.maxFeePerGas,
|
|
349
|
-
maxPriorityFeePerGas: params.maxPriorityFeePerGas,
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
async readContract(params) {
|
|
353
|
-
return await this.publicClient.readContract({
|
|
354
|
-
address: params.address,
|
|
355
|
-
abi: params.abi,
|
|
356
|
-
functionName: params.functionName,
|
|
357
|
-
args: params.args || [],
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
// ==============================================================================
|
|
361
|
-
// Utilities
|
|
362
|
-
// ==============================================================================
|
|
363
|
-
async waitForUserOperationReceipt(userOpHash, timeout = 30000) {
|
|
364
|
-
console.log(`Waiting for UserOperation receipt...`);
|
|
365
|
-
const startTime = Date.now();
|
|
366
|
-
while (Date.now() - startTime < timeout) {
|
|
367
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
368
|
-
// In a real implementation, you'd query the bundler for receipt
|
|
369
|
-
// For now, we'll return a basic receipt structure
|
|
370
|
-
console.log("Checking for receipt...");
|
|
371
|
-
}
|
|
372
|
-
return {
|
|
373
|
-
userOpHash,
|
|
374
|
-
success: true,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
async fundAccount(amount, fromPrivateKey) {
|
|
378
|
-
if (!this.smartAccount) {
|
|
379
|
-
throw new Error("Smart account not connected");
|
|
380
|
-
}
|
|
381
|
-
const signer = privateKeyToAccount(fromPrivateKey);
|
|
382
|
-
const client = createWalletClient({
|
|
383
|
-
account: signer,
|
|
384
|
-
chain: this.config.chain,
|
|
385
|
-
transport: http(this.config.rpcUrl),
|
|
386
|
-
});
|
|
387
|
-
console.log(`Funding account with ${amount} wei...`);
|
|
388
|
-
const hash = await client.sendTransaction({
|
|
389
|
-
to: this.smartAccount.address,
|
|
390
|
-
value: amount,
|
|
391
|
-
});
|
|
392
|
-
console.log(`✅ Funded: ${hash}`);
|
|
393
|
-
return hash;
|
|
394
|
-
}
|
|
395
|
-
// ==============================================================================
|
|
396
|
-
// Batch Operations
|
|
397
|
-
// ==============================================================================
|
|
398
|
-
async sendBatchUserOperations(operations) {
|
|
399
|
-
const results = [];
|
|
400
|
-
for (const op of operations) {
|
|
401
|
-
const hash = await this.sendUserOperation(op);
|
|
402
|
-
results.push(hash);
|
|
403
|
-
}
|
|
404
|
-
return results;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
// ==============================================================================
|
|
408
|
-
// Helper Functions
|
|
409
|
-
// ==============================================================================
|
|
410
|
-
export function createDagAAClient(config) {
|
|
411
|
-
return new DagAAClient(config);
|
|
412
|
-
}
|
|
413
|
-
export function parseDAG(amount) {
|
|
414
|
-
return parseEther(amount);
|
|
415
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Test if paymaster service is working
|
|
3
|
-
async function testPaymasterService() {
|
|
4
|
-
const PAYMASTER_URL = "http://localhost:3001/rpc";
|
|
5
|
-
console.log("Testing paymaster service...");
|
|
6
|
-
// Test 1: Health check
|
|
7
|
-
try {
|
|
8
|
-
const healthResponse = await fetch("http://localhost:3001/health");
|
|
9
|
-
const health = await healthResponse.json();
|
|
10
|
-
console.log("✅ Health check passed:", health);
|
|
11
|
-
}
|
|
12
|
-
catch (error) {
|
|
13
|
-
console.error("❌ Health check failed:", error);
|
|
14
|
-
console.error("Is the paymaster service running? Run: pnpm start");
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
// Test 2: Get paymaster info
|
|
18
|
-
try {
|
|
19
|
-
const infoResponse = await fetch("http://localhost:3001/info");
|
|
20
|
-
const info = await infoResponse.json();
|
|
21
|
-
console.log("✅ Paymaster info:", info);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
console.error("❌ Failed to get paymaster info:", error);
|
|
25
|
-
}
|
|
26
|
-
// Test 3: Test pm_getPaymasterStubData
|
|
27
|
-
const mockUserOp = {
|
|
28
|
-
sender: "0xCa28afE1e9Fb8B9AF996c97F3dc291bE54EAEe4E",
|
|
29
|
-
nonce: "0x0",
|
|
30
|
-
initCode: "0x",
|
|
31
|
-
callData: "0x",
|
|
32
|
-
callGasLimit: "0x30d40",
|
|
33
|
-
verificationGasLimit: "0x30d40",
|
|
34
|
-
preVerificationGas: "0x30d40",
|
|
35
|
-
maxFeePerGas: "0xba43b7400",
|
|
36
|
-
maxPriorityFeePerGas: "0xba43b7400",
|
|
37
|
-
paymasterAndData: "0x",
|
|
38
|
-
signature: "0x",
|
|
39
|
-
};
|
|
40
|
-
try {
|
|
41
|
-
const response = await fetch(PAYMASTER_URL, {
|
|
42
|
-
method: "POST",
|
|
43
|
-
headers: { "Content-Type": "application/json" },
|
|
44
|
-
body: JSON.stringify({
|
|
45
|
-
jsonrpc: "2.0",
|
|
46
|
-
id: 1,
|
|
47
|
-
method: "pm_getPaymasterStubData",
|
|
48
|
-
params: [mockUserOp, "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", {}],
|
|
49
|
-
}),
|
|
50
|
-
});
|
|
51
|
-
const data = await response.json();
|
|
52
|
-
if (data.error) {
|
|
53
|
-
console.error("❌ pm_getPaymasterStubData failed:", data.error);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
console.log("✅ pm_getPaymasterStubData success:", data.result);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
console.error("❌ pm_getPaymasterStubData request failed:", error);
|
|
61
|
-
}
|
|
62
|
-
// Test 4: Test pm_sponsorUserOperation
|
|
63
|
-
try {
|
|
64
|
-
const response = await fetch(PAYMASTER_URL, {
|
|
65
|
-
method: "POST",
|
|
66
|
-
headers: { "Content-Type": "application/json" },
|
|
67
|
-
body: JSON.stringify({
|
|
68
|
-
jsonrpc: "2.0",
|
|
69
|
-
id: 1,
|
|
70
|
-
method: "pm_sponsorUserOperation",
|
|
71
|
-
params: [mockUserOp, "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", {}],
|
|
72
|
-
}),
|
|
73
|
-
});
|
|
74
|
-
const data = await response.json();
|
|
75
|
-
if (data.error) {
|
|
76
|
-
console.error("❌ pm_sponsorUserOperation failed:", data.error);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
console.log("✅ pm_sponsorUserOperation success:");
|
|
80
|
-
console.log(" paymasterAndData:", data.result.paymasterAndData);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
console.error("❌ pm_sponsorUserOperation request failed:", error);
|
|
85
|
-
}
|
|
86
|
-
console.log("\n✅ Paymaster tests complete!");
|
|
87
|
-
}
|
|
88
|
-
testPaymasterService().catch(console.error);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { defineChain } from "viem";
|
|
2
|
-
import { arbitrumSepolia } from "viem/chains";
|
|
3
|
-
const awakening_ = defineChain({
|
|
4
|
-
id: 1043,
|
|
5
|
-
name: "Awakening Testnet",
|
|
6
|
-
nativeCurrency: { decimals: 18, name: "Dag", symbol: "DAG" },
|
|
7
|
-
rpcUrls: { default: { http: ["https://public-bdag.nownodes.io"] } },
|
|
8
|
-
blockExplorers: {
|
|
9
|
-
default: { name: "Explorer", url: "https://awakening.bdagscan.com/" },
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
export const awakening = {
|
|
13
|
-
bundler_rpc: "http://0.0.0.0:3000/",
|
|
14
|
-
chain_config: awakening_,
|
|
15
|
-
};
|
|
16
|
-
export const arbitrumSep = {
|
|
17
|
-
bundler_rpc: "http://0.0.0.0:3001/",
|
|
18
|
-
chain_config: arbitrumSepolia,
|
|
19
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/version.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../../src/clients/actions/contract.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG;;;;;;;;;;GAyCf,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../../../src/clients/actions/example.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"example2.d.ts","sourceRoot":"","sources":["../../../../src/clients/actions/example2.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/clients/actions/index.ts"],"names":[],"mappings":""}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { type Hash, type Address } from "viem";
|
|
2
|
-
import { DagAAConfig, SmartAccountConfig, SendUserOperationParams, UserOperationReceipt } from "../types";
|
|
3
|
-
export declare class DagAAClient {
|
|
4
|
-
private config;
|
|
5
|
-
private publicClient;
|
|
6
|
-
private walletClient;
|
|
7
|
-
private bundlerClient;
|
|
8
|
-
private smartAccount;
|
|
9
|
-
private paymasterClient;
|
|
10
|
-
private smartAccountClient;
|
|
11
|
-
constructor(config: DagAAConfig);
|
|
12
|
-
private createPaymasterClient;
|
|
13
|
-
connectSmartAccount(accountConfig: SmartAccountConfig): Promise<Address>;
|
|
14
|
-
getAddress(): Address;
|
|
15
|
-
getBalance(): Promise<bigint>;
|
|
16
|
-
isDeployed(): Promise<boolean>;
|
|
17
|
-
getNonce(): Promise<bigint>;
|
|
18
|
-
sendUserOperation(params: SendUserOperationParams): Promise<Hash>;
|
|
19
|
-
writeContract(params: {
|
|
20
|
-
address: Address;
|
|
21
|
-
abi: any[];
|
|
22
|
-
functionName: string;
|
|
23
|
-
args?: any[];
|
|
24
|
-
value?: bigint;
|
|
25
|
-
maxFeePerGas?: bigint;
|
|
26
|
-
maxPriorityFeePerGas?: bigint;
|
|
27
|
-
}): Promise<Hash>;
|
|
28
|
-
readContract(params: {
|
|
29
|
-
address: Address;
|
|
30
|
-
abi: any[];
|
|
31
|
-
functionName: string;
|
|
32
|
-
args?: any[];
|
|
33
|
-
}): Promise<any>;
|
|
34
|
-
waitForUserOperationReceipt(userOpHash: Hash, timeout?: number): Promise<UserOperationReceipt>;
|
|
35
|
-
fundAccount(amount: bigint, fromPrivateKey: `0x${string}`): Promise<Hash>;
|
|
36
|
-
sendBatchUserOperations(operations: SendUserOperationParams[]): Promise<Hash[]>;
|
|
37
|
-
}
|
|
38
|
-
export declare function createDagAAClient(config: DagAAConfig): DagAAClient;
|
|
39
|
-
export declare function parseDAG(amount: string): bigint;
|
|
40
|
-
//# sourceMappingURL=main.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../../src/clients/actions/main.ts"],"names":[],"mappings":"AAKA,OAAO,EAOL,KAAK,IAAI,EACT,KAAK,OAAO,EAGb,MAAM,MAAM,CAAC;AAMd,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAMlB,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,YAAY,CAAwC;IAC5D,OAAO,CAAC,YAAY,CAAwC;IAC5D,OAAO,CAAC,aAAa,CAAuD;IAC5E,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,eAAe,CAAoB;IAC3C,OAAO,CAAC,kBAAkB,CAEV;gBAEJ,MAAM,EAAE,WAAW;IAyB/B,OAAO,CAAC,qBAAqB;IAoGvB,mBAAmB,CACvB,aAAa,EAAE,kBAAkB,GAChC,OAAO,CAAC,OAAO,CAAC;IAkInB,UAAU,IAAI,OAAO;IASf,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAU7B,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAY9B,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IA4B3B,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmEjE,aAAa,CAAC,MAAM,EAAE;QAC1B,OAAO,EAAE,OAAO,CAAC;QACjB,GAAG,EAAE,GAAG,EAAE,CAAC;QACX,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;KAC/B,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBX,YAAY,CAAC,MAAM,EAAE;QACzB,OAAO,EAAE,OAAO,CAAC;QACjB,GAAG,EAAE,GAAG,EAAE,CAAC;QACX,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;KACd,GAAG,OAAO,CAAC,GAAG,CAAC;IAaV,2BAA2B,CAC/B,UAAU,EAAE,IAAI,EAChB,OAAO,GAAE,MAAc,GACtB,OAAO,CAAC,oBAAoB,CAAC;IAmB1B,WAAW,CACf,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,KAAK,MAAM,EAAE,GAC5B,OAAO,CAAC,IAAI,CAAC;IA2BV,uBAAuB,CAC3B,UAAU,EAAE,uBAAuB,EAAE,GACpC,OAAO,CAAC,IAAI,EAAE,CAAC;CAUnB;AAMD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAElE;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=test.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../../../src/clients/actions/test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testPaymasterService.d.ts","sourceRoot":"","sources":["../../../../src/clients/actions/testPaymasterService.ts"],"names":[],"mappings":"AAEA,iBAAe,oBAAoB,kBAyFlC"}
|