@dag-kit/kit 1.0.0 → 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.
@@ -0,0 +1,210 @@
1
+ // import "dotenv/config";
2
+ // import { toSimpleSmartAccount } from "permissionless/accounts";
3
+ // import {
4
+ // createPublicClient,
5
+ // createWalletClient,
6
+ // http,
7
+ // parseEther,
8
+ // encodeFunctionData,
9
+ // defineChain,
10
+ // } from "viem";
11
+ // import { privateKeyToAccount } from "viem/accounts";
12
+ // import { createPimlicoClient } from "permissionless/clients/pimlico";
13
+ // import { entryPoint06Address } from "viem/account-abstraction";
14
+ // import { createSmartAccountClient } from "permissionless";
15
+ // import { abi } from "./contract";
16
+
17
+ // // Configuration
18
+ // const adminKey =
19
+ // "0x5810098e367422376897bb2645c5ada5850a99aeec0505a58d38853ebd7f9f31";
20
+ // const FACTORY_ADDRESS = "0x8FaB6DF00085eb05D5F2C1FA46a6E539587ae3f3"; // Your factory
21
+ // const TARGET_ADDRESS = "0x7fd5385efcB7B2898933288948a9496CDc0fA8ee"; // Your desired address
22
+
23
+ // // BlockDAG Awakening Testnet
24
+ // const awakening = defineChain({
25
+ // id: 1043,
26
+ // name: "Awakening Testnet",
27
+ // nativeCurrency: { decimals: 18, name: "Dag", symbol: "DAG" },
28
+ // rpcUrls: { default: { http: ["https://relay.awakening.bdagscan.com"] } },
29
+ // blockExplorers: {
30
+ // default: { name: "Explorer", url: "https://awakening.bdagscan.com/" },
31
+ // },
32
+ // });
33
+
34
+ // const localBundler = "http://0.0.0.0:3000/";
35
+
36
+ // console.log("\nšŸ” Using Your Existing Address");
37
+ // console.log("=================================\n");
38
+
39
+ // const publicClient = createPublicClient({
40
+ // chain: awakening,
41
+ // transport: http(awakening.rpcUrls.default.http[0]),
42
+ // });
43
+
44
+ // const walletClient = createWalletClient({
45
+ // account: privateKeyToAccount(adminKey),
46
+ // chain: awakening,
47
+ // transport: http(awakening.rpcUrls.default.http[0]),
48
+ // });
49
+
50
+ // console.log(`Target Address: ${TARGET_ADDRESS}`);
51
+ // console.log(`Owner: ${privateKeyToAccount(adminKey).address}`);
52
+ // console.log(`Factory: ${FACTORY_ADDRESS}\n`);
53
+
54
+ // // Step 1: Create account using the specific address
55
+ // // Since the account is already deployed, we just need to reference it
56
+ // const account = await toSimpleSmartAccount({
57
+ // client: publicClient,
58
+ // owner: privateKeyToAccount(adminKey),
59
+ // factoryAddress: FACTORY_ADDRESS,
60
+ // entryPoint: {
61
+ // address: entryPoint06Address,
62
+ // version: "0.6",
63
+ // },
64
+ // address: TARGET_ADDRESS, // Use the existing address directly
65
+ // });
66
+
67
+ // console.log("=== Smart Account Information ===");
68
+ // console.log(`Address: ${account.address}`);
69
+ // console.log(
70
+ // `Explorer: https://awakening.bdagscan.com/address/${account.address}`
71
+ // );
72
+ // console.log("āœ… Using your existing account\n");
73
+
74
+ // // Check if deployed
75
+ // const code = await publicClient.getCode({
76
+ // address: account.address,
77
+ // });
78
+
79
+ // const isDeployed = code && code !== "0x";
80
+ // console.log(
81
+ // `Deployment Status: ${isDeployed ? "āœ… Deployed" : "āš ļø Not deployed"}`
82
+ // );
83
+
84
+ // // Check balance
85
+ // const balance = await publicClient.getBalance({
86
+ // address: account.address,
87
+ // });
88
+
89
+ // const balanceInDAG = Number(balance) / 1e18;
90
+ // console.log(`Balance: ${balanceInDAG} DAG`);
91
+
92
+ // if (!isDeployed) {
93
+ // console.log("\nāš ļø Account not deployed yet.");
94
+ // console.log("The account should already be deployed based on the explorer.");
95
+ // console.log("If you need to deploy it, do so manually first.\n");
96
+ // }
97
+
98
+ // // Step 3: Test bundler connection
99
+ // console.log("=== Testing Bundler ===");
100
+ // try {
101
+ // const dagClient = createPimlicoClient({
102
+ // transport: http(localBundler),
103
+ // entryPoint: {
104
+ // address: entryPoint06Address,
105
+ // version: "0.6",
106
+ // },
107
+ // });
108
+
109
+ // const gasPrice = await dagClient.getUserOperationGasPrice();
110
+ // console.log("āœ… Bundler responding");
111
+ // console.log(`Gas Price: ${gasPrice.fast.maxFeePerGas} wei\n`);
112
+ // } catch (error: any) {
113
+ // console.error("āŒ Bundler not responding:", error.message);
114
+ // console.log("\nšŸ’” Start Alto bundler:");
115
+ // console.log(`./alto \\
116
+ // --entrypoints "${entryPoint06Address}" \\
117
+ // --executor-private-keys "${adminKey}" \\
118
+ // --utility-private-key "${adminKey}" \\
119
+ // --rpc-url "https://relay.awakening.bdagscan.com" \\
120
+ // --port 3000 \\
121
+ // --safe-mode false \\
122
+ // --dangerous-skip-user-operation-validation true`);
123
+ // process.exit(1);
124
+ // }
125
+
126
+ // // Step 4: Send test UserOperation
127
+ // console.log("=== Sending Test UserOperation ===");
128
+
129
+ // const smartAccountClient = createSmartAccountClient({
130
+ // bundlerTransport: http(localBundler),
131
+ // chain: awakening,
132
+ // account,
133
+ // });
134
+
135
+ // const cd = encodeFunctionData({
136
+ // abi,
137
+ // functionName: "decrement",
138
+ // args: [],
139
+ // });
140
+
141
+ // try {
142
+ // // Simple test: send 0 value to self
143
+ // const txHash = await smartAccountClient.sendTransaction({
144
+ // to: "0x692e69cA1Fe89eF72ca94B0E3a32A92835501a08",
145
+ // value: 0n,
146
+ // data: cd,
147
+ // maxFeePerGas: 50000000000n, // 50 gwei
148
+ // maxPriorityFeePerGas: 50000000000n, // 50 gwei
149
+ // callGasLimit: 150000n,
150
+ // verificationGasLimit: 500000n,
151
+ // preVerificationGas: 100000n,
152
+ // });
153
+
154
+ // console.log(`\nāœ… Success!`);
155
+ // console.log(`UserOperation Hash: ${txHash}`);
156
+ // console.log(`Explorer: https://awakening.bdagscan.com/tx/${txHash}`);
157
+
158
+ // console.log("\nā³ Waiting for confirmation...");
159
+ // await new Promise((resolve) => setTimeout(resolve, 5000));
160
+
161
+ // const newBalance = await publicClient.getBalance({
162
+ // address: account.address,
163
+ // });
164
+ // const newBalanceInDAG = Number(newBalance) / 1e18;
165
+ // console.log(`\nFinal Balance: ${newBalanceInDAG} DAG`);
166
+ // console.log(`Gas Cost: ${balanceInDAG - newBalanceInDAG} DAG`);
167
+
168
+ // console.log("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
169
+ // console.log("šŸŽ‰ Success! Your account is ready for reuse.");
170
+ // console.log(` Address: ${TARGET_ADDRESS}`);
171
+ // console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
172
+
173
+ // const result = await publicClient.readContract({
174
+ // address: "0x692e69cA1Fe89eF72ca94B0E3a32A92835501a08",
175
+ // abi: abi,
176
+ // functionName: "getNum",
177
+ // });
178
+
179
+ // console.log("Result is given as", result);
180
+ // } catch (error: any) {
181
+ // console.error("\nāŒ Transaction failed:");
182
+ // console.error(error.message);
183
+
184
+ // if (error.message?.includes("Missing or invalid parameters")) {
185
+ // console.log("\nāš ļø This is the known Awakening RPC issue.");
186
+ // console.log("The RPC cannot properly handle eth_call for UserOperations.");
187
+ // console.log(
188
+ // "\nYour setup is correct - the issue is with Awakening's RPC implementation."
189
+ // );
190
+ // }
191
+
192
+ // if (error.details) {
193
+ // console.log("\nDetails:", error.details);
194
+ // }
195
+ // }
196
+
197
+ // // Instructions for reuse
198
+ // console.log("\nšŸ’¾ To reuse this address in future scripts:");
199
+ // console.log(`
200
+ // const account = await toSimpleSmartAccount({
201
+ // client: publicClient,
202
+ // owner: privateKeyToAccount(adminKey),
203
+ // factoryAddress: "${FACTORY_ADDRESS}",
204
+ // entryPoint: {
205
+ // address: entryPoint06Address,
206
+ // version: "0.6",
207
+ // },
208
+ // address: "${TARGET_ADDRESS}", // Your existing account
209
+ // });
210
+ // `);
@@ -0,0 +1,94 @@
1
+ // Test if paymaster service is working
2
+
3
+ async function testPaymasterService() {
4
+ const PAYMASTER_URL = "http://localhost:3001/rpc";
5
+
6
+ console.log("Testing paymaster service...");
7
+
8
+ // Test 1: Health check
9
+ try {
10
+ const healthResponse = await fetch("http://localhost:3001/health");
11
+ const health = await healthResponse.json();
12
+ console.log("āœ… Health check passed:", health);
13
+ } catch (error) {
14
+ console.error("āŒ Health check failed:", error);
15
+ console.error("Is the paymaster service running? Run: pnpm start");
16
+ process.exit(1);
17
+ }
18
+
19
+ // Test 2: Get paymaster info
20
+ try {
21
+ const infoResponse = await fetch("http://localhost:3001/info");
22
+ const info = await infoResponse.json();
23
+ console.log("āœ… Paymaster info:", info);
24
+ } catch (error) {
25
+ console.error("āŒ Failed to get paymaster info:", error);
26
+ }
27
+
28
+ // Test 3: Test pm_getPaymasterStubData
29
+ const mockUserOp = {
30
+ sender: "0xCa28afE1e9Fb8B9AF996c97F3dc291bE54EAEe4E",
31
+ nonce: "0x0",
32
+ initCode: "0x",
33
+ callData: "0x",
34
+ callGasLimit: "0x30d40",
35
+ verificationGasLimit: "0x30d40",
36
+ preVerificationGas: "0x30d40",
37
+ maxFeePerGas: "0xba43b7400",
38
+ maxPriorityFeePerGas: "0xba43b7400",
39
+ paymasterAndData: "0x",
40
+ signature: "0x",
41
+ };
42
+
43
+ try {
44
+ const response = await fetch(PAYMASTER_URL, {
45
+ method: "POST",
46
+ headers: { "Content-Type": "application/json" },
47
+ body: JSON.stringify({
48
+ jsonrpc: "2.0",
49
+ id: 1,
50
+ method: "pm_getPaymasterStubData",
51
+ params: [mockUserOp, "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", {}],
52
+ }),
53
+ });
54
+
55
+ const data = await response.json();
56
+
57
+ if (data.error) {
58
+ console.error("āŒ pm_getPaymasterStubData failed:", data.error);
59
+ } else {
60
+ console.log("āœ… pm_getPaymasterStubData success:", data.result);
61
+ }
62
+ } catch (error) {
63
+ console.error("āŒ pm_getPaymasterStubData request failed:", error);
64
+ }
65
+
66
+ // Test 4: Test pm_sponsorUserOperation
67
+ try {
68
+ const response = await fetch(PAYMASTER_URL, {
69
+ method: "POST",
70
+ headers: { "Content-Type": "application/json" },
71
+ body: JSON.stringify({
72
+ jsonrpc: "2.0",
73
+ id: 1,
74
+ method: "pm_sponsorUserOperation",
75
+ params: [mockUserOp, "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", {}],
76
+ }),
77
+ });
78
+
79
+ const data = await response.json();
80
+
81
+ if (data.error) {
82
+ console.error("āŒ pm_sponsorUserOperation failed:", data.error);
83
+ } else {
84
+ console.log("āœ… pm_sponsorUserOperation success:");
85
+ console.log(" paymasterAndData:", data.result.paymasterAndData);
86
+ }
87
+ } catch (error) {
88
+ console.error("āŒ pm_sponsorUserOperation request failed:", error);
89
+ }
90
+
91
+ console.log("\nāœ… Paymaster tests complete!");
92
+ }
93
+
94
+ testPaymasterService().catch(console.error);
@@ -1,5 +1,5 @@
1
1
  import { defineChain } from "viem";
2
-
2
+ import { arbitrumSepolia } from "viem/chains";
3
3
  const awakening_ = defineChain({
4
4
  id: 1043,
5
5
  name: "Awakening Testnet",
@@ -14,3 +14,8 @@ export const awakening = {
14
14
  bundler_rpc: "http://0.0.0.0:3000/",
15
15
  chain_config: awakening_,
16
16
  };
17
+
18
+ export const arbitrumSep = {
19
+ bundler_rpc: "http://0.0.0.0:3001/",
20
+ chain_config: arbitrumSepolia,
21
+ };
@@ -10,6 +10,7 @@ import {
10
10
  encodeFunctionData,
11
11
  parseEther,
12
12
  } from "viem";
13
+ import { ISigner } from "../signers/types.js";
13
14
 
14
15
  export interface DagAAConfig {
15
16
  chain: Chain;
@@ -17,10 +18,11 @@ export interface DagAAConfig {
17
18
  bundlerUrl: string;
18
19
  factoryAddress: Address;
19
20
  entryPointAddress?: Address;
21
+ paymasterUrl?: string;
20
22
  }
21
23
 
22
24
  export interface SmartAccountConfig {
23
- owner: `0x${string}`;
25
+ signer: ISigner;
24
26
  accountAddress?: Address;
25
27
  }
26
28
 
@@ -1,8 +1,13 @@
1
- export { createDagAAClient, parseDAG } from "../clients/actions/main";
1
+ export { createDagAAClient, parseDAG } from "../clients/actions/main.js";
2
+ export { awakening, arbitrumSep } from "../clients/chains.js";
3
+ export { DagAAClient } from "../clients/actions/main.js";
2
4
 
3
- export {
5
+ export type {
4
6
  DagAAConfig,
5
7
  SmartAccountConfig,
6
8
  SendUserOperationParams,
7
9
  UserOperationReceipt,
8
- } from "../clients/types";
10
+ } from "./public-types.js";
11
+
12
+ export { PrivySigner } from "../signers/PrivySigner.js";
13
+ export { PrivateKeySigner } from "../signers/PrivateKeySigner.js";
@@ -0,0 +1,6 @@
1
+ export type {
2
+ DagAAConfig,
3
+ SmartAccountConfig,
4
+ SendUserOperationParams,
5
+ UserOperationReceipt,
6
+ } from "../clients/types.js";
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ export { createDagAAClient, parseDAG } from "./clients/actions/main.js";
2
+ export { awakening, arbitrumSep } from "./clients/chains.js";
3
+ export { DagAAClient } from "./clients/actions/main.js";
4
+
5
+ export type {
6
+ DagAAConfig,
7
+ SmartAccountConfig,
8
+ SendUserOperationParams,
9
+ UserOperationReceipt,
10
+ } from "./exports/public-types.js";
11
+
12
+ export { PrivySigner } from "./signers/PrivySigner.js";
13
+ export { PrivateKeySigner } from "./signers/PrivateKeySigner.js";
14
+
15
+ // Re-export commonly used viem types for convenience
16
+ export type { Address, Hash, Chain } from "viem";
17
+ export type { ISigner } from "./signers/types.js";
@@ -0,0 +1,41 @@
1
+ // src/signers/PrivateKeySigner.ts
2
+ import {
3
+ createWalletClient,
4
+ http,
5
+ type Chain,
6
+ type Account,
7
+ type WalletClient,
8
+ LocalAccount,
9
+ } from "viem";
10
+ import { privateKeyToAccount } from "viem/accounts";
11
+ import { ISigner } from "./types.js";
12
+
13
+ export class PrivateKeySigner implements ISigner {
14
+ private account: LocalAccount;
15
+ private walletClient;
16
+
17
+ constructor(privateKey: `0x${string}`, chain: Chain, rpcUrl: string) {
18
+ this.account = privateKeyToAccount(privateKey);
19
+ this.walletClient = createWalletClient({
20
+ account: this.account,
21
+ chain,
22
+ transport: http(rpcUrl),
23
+ });
24
+ }
25
+
26
+ getAccount(): LocalAccount {
27
+ return this.account;
28
+ }
29
+
30
+ getWalletClient(): WalletClient {
31
+ return this.walletClient;
32
+ }
33
+
34
+ getAddress(): `0x${string}` {
35
+ return this.account.address;
36
+ }
37
+
38
+ isReady(): boolean {
39
+ return true;
40
+ }
41
+ }
@@ -0,0 +1,93 @@
1
+ // src/signers/PrivySigner.ts
2
+ import {
3
+ type Account,
4
+ type WalletClient,
5
+ createWalletClient,
6
+ custom,
7
+ type Chain,
8
+ LocalAccount,
9
+ } from "viem";
10
+ import { ISigner } from "./types.js";
11
+
12
+ /**
13
+ * Privy Signer - Works with Privy's embedded wallets
14
+ *
15
+ * Usage in React:
16
+ * ```tsx
17
+ * import { useWallets } from '@privy-io/react-auth';
18
+ *
19
+ * const { wallets } = useWallets();
20
+ * const embeddedWallet = wallets.find(w => w.walletClientType === 'privy');
21
+ *
22
+ * const signer = new PrivySigner(embeddedWallet, chain);
23
+ * ```
24
+ */
25
+ export class PrivySigner implements ISigner {
26
+ private privyWallet: any; // Privy wallet object
27
+ private chain: Chain;
28
+ private cachedAddress?: `0x${string}`;
29
+ private cachedWalletClient;
30
+
31
+ constructor(privyWallet: any, chain: Chain) {
32
+ if (!privyWallet) {
33
+ throw new Error("Privy wallet is required");
34
+ }
35
+ this.privyWallet = privyWallet;
36
+ this.chain = chain;
37
+ }
38
+
39
+ async getAccount(): Promise<LocalAccount> {
40
+ const provider = await this.privyWallet.getEthereumProvider();
41
+
42
+ if (!provider) {
43
+ throw new Error("No Ethereum provider found in Privy wallet");
44
+ }
45
+
46
+ // Create a custom account from the provider
47
+ return {
48
+ address: this.privyWallet.address as `0x${string}`,
49
+ type: "json-rpc",
50
+ // @ts-ignore - Privy provider compatible with viem
51
+ source: "privateKey",
52
+ } as unknown as LocalAccount;
53
+ }
54
+
55
+ async getWalletClient(): Promise<WalletClient> {
56
+ if (this.cachedWalletClient) {
57
+ return this.cachedWalletClient;
58
+ }
59
+
60
+ const provider = await this.privyWallet.getEthereumProvider();
61
+
62
+ if (!provider) {
63
+ throw new Error("No Ethereum provider found in Privy wallet");
64
+ }
65
+
66
+ // Create wallet client with Privy's provider
67
+ this.cachedWalletClient = createWalletClient({
68
+ account: await this.getAccount(),
69
+ chain: this.chain,
70
+ transport: custom(provider),
71
+ });
72
+
73
+ return this.cachedWalletClient;
74
+ }
75
+
76
+ async getAddress(): Promise<`0x${string}`> {
77
+ if (this.cachedAddress) {
78
+ return this.cachedAddress;
79
+ }
80
+
81
+ this.cachedAddress = this.privyWallet.address as `0x${string}`;
82
+ return this.cachedAddress;
83
+ }
84
+
85
+ async isReady(): Promise<boolean> {
86
+ try {
87
+ const provider = await this.privyWallet.getEthereumProvider();
88
+ return !!provider && !!this.privyWallet.address;
89
+ } catch {
90
+ return false;
91
+ }
92
+ }
93
+ }
@@ -0,0 +1,45 @@
1
+ // src/signers/types.ts
2
+ import { Account, LocalAccount, WalletClient } from "viem";
3
+
4
+ /**
5
+ * Common interface for all signers
6
+ * This allows users to plug in different signing methods
7
+ */
8
+ export interface ISigner {
9
+ /**
10
+ * Get the viem Account object for signing
11
+ */
12
+ getAccount(): LocalAccount | Promise<LocalAccount>;
13
+
14
+ /**
15
+ * Get the wallet client for transactions
16
+ */
17
+ getWalletClient(): WalletClient | Promise<WalletClient>;
18
+
19
+ /**
20
+ * Get the signer's address
21
+ */
22
+ getAddress(): `0x${string}` | Promise<`0x${string}`>;
23
+
24
+ /**
25
+ * Check if signer is ready/connected
26
+ */
27
+ isReady(): boolean | Promise<boolean>;
28
+ }
29
+
30
+ /**
31
+ * Configuration for different signer types
32
+ */
33
+ export type SignerConfig =
34
+ | {
35
+ type: "privateKey";
36
+ privateKey: `0x${string}`;
37
+ }
38
+ | {
39
+ type: "privy";
40
+ // Privy handles its own state, no config needed
41
+ }
42
+ | {
43
+ type: "custom";
44
+ signer: ISigner;
45
+ };
package/src/version.ts ADDED
@@ -0,0 +1,3 @@
1
+ // This file is autogenerated by inject-version.ts. Any changes will be
2
+ // overwritten on commit!
3
+ export const VERSION = "1.0.4-alpha.3";
@@ -1,42 +0,0 @@
1
- export const abi = [
2
- {
3
- inputs: [],
4
- name: "decrement",
5
- outputs: [],
6
- stateMutability: "nonpayable",
7
- type: "function",
8
- },
9
- {
10
- inputs: [],
11
- name: "increment",
12
- outputs: [],
13
- stateMutability: "nonpayable",
14
- type: "function",
15
- },
16
- {
17
- inputs: [],
18
- name: "getNum",
19
- outputs: [
20
- {
21
- internalType: "uint256",
22
- name: "",
23
- type: "uint256",
24
- },
25
- ],
26
- stateMutability: "view",
27
- type: "function",
28
- },
29
- {
30
- inputs: [],
31
- name: "num",
32
- outputs: [
33
- {
34
- internalType: "uint256",
35
- name: "",
36
- type: "uint256",
37
- },
38
- ],
39
- stateMutability: "view",
40
- type: "function",
41
- },
42
- ];