@1llet.xyz/erc4337-gasless-sdk 0.1.0

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,326 @@
1
+ import { Chain, Address, Hex, Hash } from 'viem';
2
+
3
+ interface ChainConfig {
4
+ chain: Chain;
5
+ rpcUrl: string;
6
+ bundlerUrl: string;
7
+ entryPointAddress: Address;
8
+ factoryAddress: Address;
9
+ paymasterAddress: Address;
10
+ usdcAddress: Address;
11
+ }
12
+ interface UserOperation {
13
+ sender: Address;
14
+ nonce: bigint;
15
+ initCode: Hex;
16
+ callData: Hex;
17
+ callGasLimit: bigint;
18
+ verificationGasLimit: bigint;
19
+ preVerificationGas: bigint;
20
+ maxFeePerGas: bigint;
21
+ maxPriorityFeePerGas: bigint;
22
+ paymasterAndData: Hex;
23
+ signature: Hex;
24
+ }
25
+ interface GasEstimate {
26
+ callGasLimit: string;
27
+ verificationGasLimit: string;
28
+ preVerificationGas: string;
29
+ maxFeePerGas: string;
30
+ maxPriorityFeePerGas: string;
31
+ }
32
+ interface UserOpReceipt {
33
+ userOpHash: Hash;
34
+ sender: Address;
35
+ success: boolean;
36
+ actualGasCost: string;
37
+ receipt: {
38
+ transactionHash: Hash;
39
+ blockNumber: string;
40
+ };
41
+ }
42
+ interface ApprovalSupportResult {
43
+ type: "permit" | "approve" | "none";
44
+ gasCost?: string;
45
+ fundingNeeded?: string;
46
+ fundedAmount?: string;
47
+ }
48
+
49
+ /**
50
+ * ERC-4337 Account Abstraction Client
51
+ */
52
+ declare class AccountAbstraction {
53
+ private owner;
54
+ private smartAccountAddress;
55
+ private chainConfig;
56
+ private publicClient;
57
+ constructor(chainConfig: ChainConfig);
58
+ /**
59
+ * Connect to MetaMask and get the owner address
60
+ */
61
+ connect(): Promise<{
62
+ owner: Address;
63
+ smartAccount: Address;
64
+ }>;
65
+ /**
66
+ * Get the Smart Account address for an owner (counterfactual)
67
+ */
68
+ getSmartAccountAddress(owner: Address): Promise<Address>;
69
+ /**
70
+ * Check if the Smart Account is deployed
71
+ */
72
+ isAccountDeployed(): Promise<boolean>;
73
+ /**
74
+ * Get the USDC balance of the Smart Account
75
+ */
76
+ getUsdcBalance(): Promise<bigint>;
77
+ /**
78
+ * Get the EOA's USDC balance
79
+ */
80
+ getEoaUsdcBalance(): Promise<bigint>;
81
+ /**
82
+ * Get the allowance of the Smart Account to spend the EOA's USDC
83
+ */
84
+ getAllowance(): Promise<bigint>;
85
+ /**
86
+ * Get the nonce for the Smart Account
87
+ */
88
+ getNonce(): Promise<bigint>;
89
+ /**
90
+ * Build initCode for account deployment
91
+ */
92
+ buildInitCode(): Hex;
93
+ /**
94
+ * Estimate gas for a UserOperation
95
+ */
96
+ estimateGas(userOp: Partial<UserOperation>): Promise<GasEstimate>;
97
+ /**
98
+ * Build a UserOperation for Batched Execution (e.g. USDC Transfer + Fee)
99
+ */
100
+ buildUserOperationBatch(transactions: {
101
+ target: Address;
102
+ value: bigint;
103
+ data: Hex;
104
+ }[]): Promise<UserOperation>;
105
+ /**
106
+ * Build a UserOperation to ONLY deploy the account (empty callData)
107
+ */
108
+ buildDeployUserOperation(): Promise<UserOperation>;
109
+ /**
110
+ * Calculate the UserOperation hash
111
+ */
112
+ getUserOpHash(userOp: UserOperation): Hex;
113
+ /**
114
+ * Sign a UserOperation with MetaMask
115
+ */
116
+ signUserOperation(userOp: UserOperation): Promise<UserOperation>;
117
+ /**
118
+ * Send a signed UserOperation to the bundler
119
+ */
120
+ sendUserOperation(userOp: UserOperation): Promise<Hash>;
121
+ /**
122
+ * Wait for a UserOperation to be confirmed
123
+ */
124
+ waitForUserOperation(userOpHash: Hash, timeout?: number): Promise<UserOpReceipt>;
125
+ /**
126
+ * Request support for token approval (fund if needed)
127
+ */
128
+ requestApprovalSupport(token: Address, spender: Address, amount: bigint): Promise<ApprovalSupportResult>;
129
+ getOwner(): Address | null;
130
+ getSmartAccount(): Address | null;
131
+ }
132
+ declare global {
133
+ interface Window {
134
+ ethereum?: {
135
+ request: (args: {
136
+ method: string;
137
+ params?: unknown[];
138
+ }) => Promise<unknown>;
139
+ on: (event: string, callback: (args: unknown) => void) => void;
140
+ removeListener: (event: string, callback: (args: unknown) => void) => void;
141
+ };
142
+ }
143
+ }
144
+
145
+ declare const DEFAULT_ENTRYPOINT = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
146
+ declare const DEFAULT_FACTORY = "0x9406Cc6185a346906296840746125a0E44976454";
147
+ declare const factoryAbi: readonly [{
148
+ readonly inputs: readonly [{
149
+ readonly name: "owner";
150
+ readonly type: "address";
151
+ }, {
152
+ readonly name: "salt";
153
+ readonly type: "uint256";
154
+ }];
155
+ readonly name: "getAccountAddress";
156
+ readonly outputs: readonly [{
157
+ readonly name: "";
158
+ readonly type: "address";
159
+ }];
160
+ readonly stateMutability: "view";
161
+ readonly type: "function";
162
+ }, {
163
+ readonly inputs: readonly [{
164
+ readonly name: "owner";
165
+ readonly type: "address";
166
+ }, {
167
+ readonly name: "salt";
168
+ readonly type: "uint256";
169
+ }];
170
+ readonly name: "isAccountDeployed";
171
+ readonly outputs: readonly [{
172
+ readonly name: "";
173
+ readonly type: "bool";
174
+ }];
175
+ readonly stateMutability: "view";
176
+ readonly type: "function";
177
+ }, {
178
+ readonly inputs: readonly [{
179
+ readonly name: "owner";
180
+ readonly type: "address";
181
+ }, {
182
+ readonly name: "salt";
183
+ readonly type: "uint256";
184
+ }];
185
+ readonly name: "createAccount";
186
+ readonly outputs: readonly [{
187
+ readonly name: "account";
188
+ readonly type: "address";
189
+ }];
190
+ readonly stateMutability: "nonpayable";
191
+ readonly type: "function";
192
+ }];
193
+ declare const entryPointAbi: readonly [{
194
+ readonly inputs: readonly [{
195
+ readonly name: "sender";
196
+ readonly type: "address";
197
+ }, {
198
+ readonly name: "key";
199
+ readonly type: "uint192";
200
+ }];
201
+ readonly name: "getNonce";
202
+ readonly outputs: readonly [{
203
+ readonly name: "nonce";
204
+ readonly type: "uint256";
205
+ }];
206
+ readonly stateMutability: "view";
207
+ readonly type: "function";
208
+ }];
209
+ declare const smartAccountAbi: readonly [{
210
+ readonly inputs: readonly [{
211
+ readonly name: "target";
212
+ readonly type: "address";
213
+ }, {
214
+ readonly name: "value";
215
+ readonly type: "uint256";
216
+ }, {
217
+ readonly name: "data";
218
+ readonly type: "bytes";
219
+ }];
220
+ readonly name: "execute";
221
+ readonly outputs: readonly [];
222
+ readonly stateMutability: "nonpayable";
223
+ readonly type: "function";
224
+ }, {
225
+ readonly inputs: readonly [{
226
+ readonly name: "targets";
227
+ readonly type: "address[]";
228
+ }, {
229
+ readonly name: "values";
230
+ readonly type: "uint256[]";
231
+ }, {
232
+ readonly name: "datas";
233
+ readonly type: "bytes[]";
234
+ }];
235
+ readonly name: "executeBatch";
236
+ readonly outputs: readonly [];
237
+ readonly stateMutability: "nonpayable";
238
+ readonly type: "function";
239
+ }];
240
+ declare const erc20Abi: readonly [{
241
+ readonly inputs: readonly [{
242
+ readonly name: "account";
243
+ readonly type: "address";
244
+ }];
245
+ readonly name: "balanceOf";
246
+ readonly outputs: readonly [{
247
+ readonly name: "";
248
+ readonly type: "uint256";
249
+ }];
250
+ readonly stateMutability: "view";
251
+ readonly type: "function";
252
+ }, {
253
+ readonly inputs: readonly [{
254
+ readonly name: "to";
255
+ readonly type: "address";
256
+ }, {
257
+ readonly name: "amount";
258
+ readonly type: "uint256";
259
+ }];
260
+ readonly name: "transfer";
261
+ readonly outputs: readonly [{
262
+ readonly name: "";
263
+ readonly type: "bool";
264
+ }];
265
+ readonly stateMutability: "nonpayable";
266
+ readonly type: "function";
267
+ }, {
268
+ readonly inputs: readonly [{
269
+ readonly name: "spender";
270
+ readonly type: "address";
271
+ }, {
272
+ readonly name: "amount";
273
+ readonly type: "uint256";
274
+ }];
275
+ readonly name: "approve";
276
+ readonly outputs: readonly [{
277
+ readonly name: "";
278
+ readonly type: "bool";
279
+ }];
280
+ readonly stateMutability: "nonpayable";
281
+ readonly type: "function";
282
+ }, {
283
+ readonly inputs: readonly [{
284
+ readonly name: "owner";
285
+ readonly type: "address";
286
+ }, {
287
+ readonly name: "spender";
288
+ readonly type: "address";
289
+ }];
290
+ readonly name: "allowance";
291
+ readonly outputs: readonly [{
292
+ readonly name: "";
293
+ readonly type: "uint256";
294
+ }];
295
+ readonly stateMutability: "view";
296
+ readonly type: "function";
297
+ }, {
298
+ readonly inputs: readonly [{
299
+ readonly name: "from";
300
+ readonly type: "address";
301
+ }, {
302
+ readonly name: "to";
303
+ readonly type: "address";
304
+ }, {
305
+ readonly name: "amount";
306
+ readonly type: "uint256";
307
+ }];
308
+ readonly name: "transferFrom";
309
+ readonly outputs: readonly [{
310
+ readonly name: "";
311
+ readonly type: "bool";
312
+ }];
313
+ readonly stateMutability: "nonpayable";
314
+ readonly type: "function";
315
+ }, {
316
+ readonly inputs: readonly [];
317
+ readonly name: "decimals";
318
+ readonly outputs: readonly [{
319
+ readonly name: "";
320
+ readonly type: "uint8";
321
+ }];
322
+ readonly stateMutability: "view";
323
+ readonly type: "function";
324
+ }];
325
+
326
+ export { AccountAbstraction, type ApprovalSupportResult, type ChainConfig, DEFAULT_ENTRYPOINT, DEFAULT_FACTORY, type GasEstimate, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, factoryAbi, smartAccountAbi };
@@ -0,0 +1,326 @@
1
+ import { Chain, Address, Hex, Hash } from 'viem';
2
+
3
+ interface ChainConfig {
4
+ chain: Chain;
5
+ rpcUrl: string;
6
+ bundlerUrl: string;
7
+ entryPointAddress: Address;
8
+ factoryAddress: Address;
9
+ paymasterAddress: Address;
10
+ usdcAddress: Address;
11
+ }
12
+ interface UserOperation {
13
+ sender: Address;
14
+ nonce: bigint;
15
+ initCode: Hex;
16
+ callData: Hex;
17
+ callGasLimit: bigint;
18
+ verificationGasLimit: bigint;
19
+ preVerificationGas: bigint;
20
+ maxFeePerGas: bigint;
21
+ maxPriorityFeePerGas: bigint;
22
+ paymasterAndData: Hex;
23
+ signature: Hex;
24
+ }
25
+ interface GasEstimate {
26
+ callGasLimit: string;
27
+ verificationGasLimit: string;
28
+ preVerificationGas: string;
29
+ maxFeePerGas: string;
30
+ maxPriorityFeePerGas: string;
31
+ }
32
+ interface UserOpReceipt {
33
+ userOpHash: Hash;
34
+ sender: Address;
35
+ success: boolean;
36
+ actualGasCost: string;
37
+ receipt: {
38
+ transactionHash: Hash;
39
+ blockNumber: string;
40
+ };
41
+ }
42
+ interface ApprovalSupportResult {
43
+ type: "permit" | "approve" | "none";
44
+ gasCost?: string;
45
+ fundingNeeded?: string;
46
+ fundedAmount?: string;
47
+ }
48
+
49
+ /**
50
+ * ERC-4337 Account Abstraction Client
51
+ */
52
+ declare class AccountAbstraction {
53
+ private owner;
54
+ private smartAccountAddress;
55
+ private chainConfig;
56
+ private publicClient;
57
+ constructor(chainConfig: ChainConfig);
58
+ /**
59
+ * Connect to MetaMask and get the owner address
60
+ */
61
+ connect(): Promise<{
62
+ owner: Address;
63
+ smartAccount: Address;
64
+ }>;
65
+ /**
66
+ * Get the Smart Account address for an owner (counterfactual)
67
+ */
68
+ getSmartAccountAddress(owner: Address): Promise<Address>;
69
+ /**
70
+ * Check if the Smart Account is deployed
71
+ */
72
+ isAccountDeployed(): Promise<boolean>;
73
+ /**
74
+ * Get the USDC balance of the Smart Account
75
+ */
76
+ getUsdcBalance(): Promise<bigint>;
77
+ /**
78
+ * Get the EOA's USDC balance
79
+ */
80
+ getEoaUsdcBalance(): Promise<bigint>;
81
+ /**
82
+ * Get the allowance of the Smart Account to spend the EOA's USDC
83
+ */
84
+ getAllowance(): Promise<bigint>;
85
+ /**
86
+ * Get the nonce for the Smart Account
87
+ */
88
+ getNonce(): Promise<bigint>;
89
+ /**
90
+ * Build initCode for account deployment
91
+ */
92
+ buildInitCode(): Hex;
93
+ /**
94
+ * Estimate gas for a UserOperation
95
+ */
96
+ estimateGas(userOp: Partial<UserOperation>): Promise<GasEstimate>;
97
+ /**
98
+ * Build a UserOperation for Batched Execution (e.g. USDC Transfer + Fee)
99
+ */
100
+ buildUserOperationBatch(transactions: {
101
+ target: Address;
102
+ value: bigint;
103
+ data: Hex;
104
+ }[]): Promise<UserOperation>;
105
+ /**
106
+ * Build a UserOperation to ONLY deploy the account (empty callData)
107
+ */
108
+ buildDeployUserOperation(): Promise<UserOperation>;
109
+ /**
110
+ * Calculate the UserOperation hash
111
+ */
112
+ getUserOpHash(userOp: UserOperation): Hex;
113
+ /**
114
+ * Sign a UserOperation with MetaMask
115
+ */
116
+ signUserOperation(userOp: UserOperation): Promise<UserOperation>;
117
+ /**
118
+ * Send a signed UserOperation to the bundler
119
+ */
120
+ sendUserOperation(userOp: UserOperation): Promise<Hash>;
121
+ /**
122
+ * Wait for a UserOperation to be confirmed
123
+ */
124
+ waitForUserOperation(userOpHash: Hash, timeout?: number): Promise<UserOpReceipt>;
125
+ /**
126
+ * Request support for token approval (fund if needed)
127
+ */
128
+ requestApprovalSupport(token: Address, spender: Address, amount: bigint): Promise<ApprovalSupportResult>;
129
+ getOwner(): Address | null;
130
+ getSmartAccount(): Address | null;
131
+ }
132
+ declare global {
133
+ interface Window {
134
+ ethereum?: {
135
+ request: (args: {
136
+ method: string;
137
+ params?: unknown[];
138
+ }) => Promise<unknown>;
139
+ on: (event: string, callback: (args: unknown) => void) => void;
140
+ removeListener: (event: string, callback: (args: unknown) => void) => void;
141
+ };
142
+ }
143
+ }
144
+
145
+ declare const DEFAULT_ENTRYPOINT = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
146
+ declare const DEFAULT_FACTORY = "0x9406Cc6185a346906296840746125a0E44976454";
147
+ declare const factoryAbi: readonly [{
148
+ readonly inputs: readonly [{
149
+ readonly name: "owner";
150
+ readonly type: "address";
151
+ }, {
152
+ readonly name: "salt";
153
+ readonly type: "uint256";
154
+ }];
155
+ readonly name: "getAccountAddress";
156
+ readonly outputs: readonly [{
157
+ readonly name: "";
158
+ readonly type: "address";
159
+ }];
160
+ readonly stateMutability: "view";
161
+ readonly type: "function";
162
+ }, {
163
+ readonly inputs: readonly [{
164
+ readonly name: "owner";
165
+ readonly type: "address";
166
+ }, {
167
+ readonly name: "salt";
168
+ readonly type: "uint256";
169
+ }];
170
+ readonly name: "isAccountDeployed";
171
+ readonly outputs: readonly [{
172
+ readonly name: "";
173
+ readonly type: "bool";
174
+ }];
175
+ readonly stateMutability: "view";
176
+ readonly type: "function";
177
+ }, {
178
+ readonly inputs: readonly [{
179
+ readonly name: "owner";
180
+ readonly type: "address";
181
+ }, {
182
+ readonly name: "salt";
183
+ readonly type: "uint256";
184
+ }];
185
+ readonly name: "createAccount";
186
+ readonly outputs: readonly [{
187
+ readonly name: "account";
188
+ readonly type: "address";
189
+ }];
190
+ readonly stateMutability: "nonpayable";
191
+ readonly type: "function";
192
+ }];
193
+ declare const entryPointAbi: readonly [{
194
+ readonly inputs: readonly [{
195
+ readonly name: "sender";
196
+ readonly type: "address";
197
+ }, {
198
+ readonly name: "key";
199
+ readonly type: "uint192";
200
+ }];
201
+ readonly name: "getNonce";
202
+ readonly outputs: readonly [{
203
+ readonly name: "nonce";
204
+ readonly type: "uint256";
205
+ }];
206
+ readonly stateMutability: "view";
207
+ readonly type: "function";
208
+ }];
209
+ declare const smartAccountAbi: readonly [{
210
+ readonly inputs: readonly [{
211
+ readonly name: "target";
212
+ readonly type: "address";
213
+ }, {
214
+ readonly name: "value";
215
+ readonly type: "uint256";
216
+ }, {
217
+ readonly name: "data";
218
+ readonly type: "bytes";
219
+ }];
220
+ readonly name: "execute";
221
+ readonly outputs: readonly [];
222
+ readonly stateMutability: "nonpayable";
223
+ readonly type: "function";
224
+ }, {
225
+ readonly inputs: readonly [{
226
+ readonly name: "targets";
227
+ readonly type: "address[]";
228
+ }, {
229
+ readonly name: "values";
230
+ readonly type: "uint256[]";
231
+ }, {
232
+ readonly name: "datas";
233
+ readonly type: "bytes[]";
234
+ }];
235
+ readonly name: "executeBatch";
236
+ readonly outputs: readonly [];
237
+ readonly stateMutability: "nonpayable";
238
+ readonly type: "function";
239
+ }];
240
+ declare const erc20Abi: readonly [{
241
+ readonly inputs: readonly [{
242
+ readonly name: "account";
243
+ readonly type: "address";
244
+ }];
245
+ readonly name: "balanceOf";
246
+ readonly outputs: readonly [{
247
+ readonly name: "";
248
+ readonly type: "uint256";
249
+ }];
250
+ readonly stateMutability: "view";
251
+ readonly type: "function";
252
+ }, {
253
+ readonly inputs: readonly [{
254
+ readonly name: "to";
255
+ readonly type: "address";
256
+ }, {
257
+ readonly name: "amount";
258
+ readonly type: "uint256";
259
+ }];
260
+ readonly name: "transfer";
261
+ readonly outputs: readonly [{
262
+ readonly name: "";
263
+ readonly type: "bool";
264
+ }];
265
+ readonly stateMutability: "nonpayable";
266
+ readonly type: "function";
267
+ }, {
268
+ readonly inputs: readonly [{
269
+ readonly name: "spender";
270
+ readonly type: "address";
271
+ }, {
272
+ readonly name: "amount";
273
+ readonly type: "uint256";
274
+ }];
275
+ readonly name: "approve";
276
+ readonly outputs: readonly [{
277
+ readonly name: "";
278
+ readonly type: "bool";
279
+ }];
280
+ readonly stateMutability: "nonpayable";
281
+ readonly type: "function";
282
+ }, {
283
+ readonly inputs: readonly [{
284
+ readonly name: "owner";
285
+ readonly type: "address";
286
+ }, {
287
+ readonly name: "spender";
288
+ readonly type: "address";
289
+ }];
290
+ readonly name: "allowance";
291
+ readonly outputs: readonly [{
292
+ readonly name: "";
293
+ readonly type: "uint256";
294
+ }];
295
+ readonly stateMutability: "view";
296
+ readonly type: "function";
297
+ }, {
298
+ readonly inputs: readonly [{
299
+ readonly name: "from";
300
+ readonly type: "address";
301
+ }, {
302
+ readonly name: "to";
303
+ readonly type: "address";
304
+ }, {
305
+ readonly name: "amount";
306
+ readonly type: "uint256";
307
+ }];
308
+ readonly name: "transferFrom";
309
+ readonly outputs: readonly [{
310
+ readonly name: "";
311
+ readonly type: "bool";
312
+ }];
313
+ readonly stateMutability: "nonpayable";
314
+ readonly type: "function";
315
+ }, {
316
+ readonly inputs: readonly [];
317
+ readonly name: "decimals";
318
+ readonly outputs: readonly [{
319
+ readonly name: "";
320
+ readonly type: "uint8";
321
+ }];
322
+ readonly stateMutability: "view";
323
+ readonly type: "function";
324
+ }];
325
+
326
+ export { AccountAbstraction, type ApprovalSupportResult, type ChainConfig, DEFAULT_ENTRYPOINT, DEFAULT_FACTORY, type GasEstimate, type UserOpReceipt, type UserOperation, entryPointAbi, erc20Abi, factoryAbi, smartAccountAbi };