@t402/wdk-gasless 1.0.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.
- package/dist/cjs/index.d.ts +409 -0
- package/dist/cjs/index.js +727 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.mts +409 -0
- package/dist/esm/index.mjs +701 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { PublicClient, Address, Hex } from 'viem';
|
|
2
|
+
import { SmartAccountSigner, BundlerConfig, PaymasterConfig } from '@t402/evm';
|
|
3
|
+
export { BundlerConfig, PaymasterConfig, SmartAccountSigner, UserOperationReceipt } from '@t402/evm';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* WDK Gasless Types
|
|
7
|
+
*
|
|
8
|
+
* Type definitions for gasless payments using Tether WDK and ERC-4337.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* WDK account interface (compatible with @tetherto/wdk)
|
|
13
|
+
*/
|
|
14
|
+
interface WdkAccount {
|
|
15
|
+
/** Get the account's address */
|
|
16
|
+
getAddress(): Promise<string>;
|
|
17
|
+
/** Get the account's native balance */
|
|
18
|
+
getBalance(): Promise<bigint>;
|
|
19
|
+
/** Get the account's token balance */
|
|
20
|
+
getTokenBalance(tokenAddress: string): Promise<bigint>;
|
|
21
|
+
/** Sign a message */
|
|
22
|
+
signMessage(message: string): Promise<string>;
|
|
23
|
+
/** Sign typed data (EIP-712) */
|
|
24
|
+
signTypedData(params: {
|
|
25
|
+
domain: {
|
|
26
|
+
name?: string;
|
|
27
|
+
version?: string;
|
|
28
|
+
chainId?: number;
|
|
29
|
+
verifyingContract?: string;
|
|
30
|
+
};
|
|
31
|
+
types: Record<string, Array<{
|
|
32
|
+
name: string;
|
|
33
|
+
type: string;
|
|
34
|
+
}>>;
|
|
35
|
+
primaryType: string;
|
|
36
|
+
message: Record<string, unknown>;
|
|
37
|
+
}): Promise<string>;
|
|
38
|
+
/** Send a transaction */
|
|
39
|
+
sendTransaction(params: {
|
|
40
|
+
to: string;
|
|
41
|
+
value?: bigint;
|
|
42
|
+
data?: string;
|
|
43
|
+
}): Promise<string>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* WDK instance interface
|
|
47
|
+
*/
|
|
48
|
+
interface WdkInstance {
|
|
49
|
+
/** Get accounts */
|
|
50
|
+
getAccounts(): WdkAccount[];
|
|
51
|
+
/** Get account by index */
|
|
52
|
+
getAccount(index: number): WdkAccount;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for WDK smart account
|
|
56
|
+
*/
|
|
57
|
+
interface WdkSmartAccountConfig {
|
|
58
|
+
/** WDK account to use as the signer */
|
|
59
|
+
wdkAccount: WdkAccount;
|
|
60
|
+
/** Public client for chain interactions */
|
|
61
|
+
publicClient: PublicClient;
|
|
62
|
+
/** Chain ID */
|
|
63
|
+
chainId: number;
|
|
64
|
+
/** Additional owners for multi-sig (optional) */
|
|
65
|
+
additionalOwners?: Address[];
|
|
66
|
+
/** Threshold for multi-sig (defaults to 1) */
|
|
67
|
+
threshold?: number;
|
|
68
|
+
/** Salt nonce for address generation (defaults to 0) */
|
|
69
|
+
saltNonce?: bigint;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Configuration for WDK gasless client
|
|
73
|
+
*/
|
|
74
|
+
interface WdkGaslessClientConfig {
|
|
75
|
+
/** WDK smart account signer */
|
|
76
|
+
signer: SmartAccountSigner;
|
|
77
|
+
/** Bundler configuration */
|
|
78
|
+
bundler: BundlerConfig;
|
|
79
|
+
/** Paymaster configuration for gas sponsorship */
|
|
80
|
+
paymaster?: PaymasterConfig;
|
|
81
|
+
/** Chain ID */
|
|
82
|
+
chainId: number;
|
|
83
|
+
/** Public client */
|
|
84
|
+
publicClient: PublicClient;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parameters for a gasless payment
|
|
88
|
+
*/
|
|
89
|
+
interface GaslessPaymentParams {
|
|
90
|
+
/** Recipient address */
|
|
91
|
+
to: Address;
|
|
92
|
+
/** Amount to send (in token decimals, e.g., 1000000 for 1 USDT) */
|
|
93
|
+
amount: bigint;
|
|
94
|
+
/** Token to send (defaults to USDT0) */
|
|
95
|
+
token?: "USDT0" | "USDC" | Address;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Parameters for a batch payment
|
|
99
|
+
*/
|
|
100
|
+
interface BatchPaymentParams {
|
|
101
|
+
/** List of payments to execute */
|
|
102
|
+
payments: Array<{
|
|
103
|
+
/** Recipient address */
|
|
104
|
+
to: Address;
|
|
105
|
+
/** Amount to send */
|
|
106
|
+
amount: bigint;
|
|
107
|
+
/** Token to send (defaults to USDT0) */
|
|
108
|
+
token?: "USDT0" | "USDC" | Address;
|
|
109
|
+
}>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Result of a gasless payment
|
|
113
|
+
*/
|
|
114
|
+
interface GaslessPaymentResult {
|
|
115
|
+
/** UserOperation hash */
|
|
116
|
+
userOpHash: Hex;
|
|
117
|
+
/** Smart account address */
|
|
118
|
+
sender: Address;
|
|
119
|
+
/** Whether the payment was sponsored (free gas) */
|
|
120
|
+
sponsored: boolean;
|
|
121
|
+
/** Wait for the operation to be included */
|
|
122
|
+
wait(): Promise<GaslessPaymentReceipt>;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Receipt of a gasless payment
|
|
126
|
+
*/
|
|
127
|
+
interface GaslessPaymentReceipt {
|
|
128
|
+
/** UserOperation hash */
|
|
129
|
+
userOpHash: Hex;
|
|
130
|
+
/** Transaction hash (on-chain) */
|
|
131
|
+
txHash: Hex;
|
|
132
|
+
/** Block number */
|
|
133
|
+
blockNumber: bigint;
|
|
134
|
+
/** Whether the payment succeeded */
|
|
135
|
+
success: boolean;
|
|
136
|
+
/** Gas used (in native token) */
|
|
137
|
+
gasUsed: bigint;
|
|
138
|
+
/** Gas cost (in native token wei) */
|
|
139
|
+
gasCost: bigint;
|
|
140
|
+
/** Revert reason if failed */
|
|
141
|
+
reason?: string;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Sponsorship check result
|
|
145
|
+
*/
|
|
146
|
+
interface SponsorshipInfo {
|
|
147
|
+
/** Whether the payment can be sponsored */
|
|
148
|
+
canSponsor: boolean;
|
|
149
|
+
/** Reason if cannot sponsor */
|
|
150
|
+
reason?: string;
|
|
151
|
+
/** Maximum amount that can be sponsored (if applicable) */
|
|
152
|
+
maxAmount?: bigint;
|
|
153
|
+
/** Estimated gas cost if not sponsored */
|
|
154
|
+
estimatedGasCost?: bigint;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* WDK Gasless Client
|
|
159
|
+
*
|
|
160
|
+
* High-level client for executing gasless USDT0 payments using
|
|
161
|
+
* Tether WDK accounts and ERC-4337 Account Abstraction.
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* WDK Gasless Client
|
|
166
|
+
*
|
|
167
|
+
* Provides a simple API for executing gasless USDT0 payments using
|
|
168
|
+
* WDK accounts and ERC-4337 smart accounts.
|
|
169
|
+
*/
|
|
170
|
+
declare class WdkGaslessClient {
|
|
171
|
+
private readonly signer;
|
|
172
|
+
private readonly builder;
|
|
173
|
+
private readonly bundler;
|
|
174
|
+
private readonly paymaster?;
|
|
175
|
+
private readonly chainId;
|
|
176
|
+
private readonly publicClient;
|
|
177
|
+
private readonly chainName;
|
|
178
|
+
constructor(config: WdkGaslessClientConfig);
|
|
179
|
+
/**
|
|
180
|
+
* Execute a gasless payment
|
|
181
|
+
*
|
|
182
|
+
* Sends USDT0 (or other tokens) without the user paying gas fees.
|
|
183
|
+
* Gas is sponsored by a paymaster if configured.
|
|
184
|
+
*/
|
|
185
|
+
pay(params: GaslessPaymentParams): Promise<GaslessPaymentResult>;
|
|
186
|
+
/**
|
|
187
|
+
* Execute multiple payments in a single transaction
|
|
188
|
+
*
|
|
189
|
+
* More gas efficient than individual payments.
|
|
190
|
+
* All payments are executed atomically.
|
|
191
|
+
*/
|
|
192
|
+
payBatch(params: BatchPaymentParams): Promise<GaslessPaymentResult>;
|
|
193
|
+
/**
|
|
194
|
+
* Check if a payment can be sponsored (free gas)
|
|
195
|
+
*/
|
|
196
|
+
canSponsor(params: GaslessPaymentParams): Promise<SponsorshipInfo>;
|
|
197
|
+
/**
|
|
198
|
+
* Get the smart account address
|
|
199
|
+
*/
|
|
200
|
+
getAccountAddress(): Promise<Address>;
|
|
201
|
+
/**
|
|
202
|
+
* Check if the smart account is deployed
|
|
203
|
+
*/
|
|
204
|
+
isAccountDeployed(): Promise<boolean>;
|
|
205
|
+
/**
|
|
206
|
+
* Get the token balance of the smart account
|
|
207
|
+
*/
|
|
208
|
+
getBalance(token?: "USDT0" | "USDC" | Address): Promise<bigint>;
|
|
209
|
+
/**
|
|
210
|
+
* Get the formatted token balance
|
|
211
|
+
*/
|
|
212
|
+
getFormattedBalance(token?: "USDT0" | "USDC" | Address, decimals?: number): Promise<string>;
|
|
213
|
+
/**
|
|
214
|
+
* Estimate gas for a single transaction
|
|
215
|
+
*/
|
|
216
|
+
private estimateGas;
|
|
217
|
+
/**
|
|
218
|
+
* Estimate gas for a batch transaction
|
|
219
|
+
*/
|
|
220
|
+
private estimateBatchGas;
|
|
221
|
+
/**
|
|
222
|
+
* Get paymaster data if configured
|
|
223
|
+
*/
|
|
224
|
+
private getPaymasterData;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Configuration for creating a WDK gasless client
|
|
228
|
+
*/
|
|
229
|
+
interface CreateWdkGaslessClientConfig {
|
|
230
|
+
/** WDK account to use as the signer */
|
|
231
|
+
wdkAccount: WdkAccount;
|
|
232
|
+
/** Public client for chain interactions */
|
|
233
|
+
publicClient: PublicClient;
|
|
234
|
+
/** Chain ID */
|
|
235
|
+
chainId: number;
|
|
236
|
+
/** Bundler configuration */
|
|
237
|
+
bundler: BundlerConfig;
|
|
238
|
+
/** Optional paymaster for gas sponsorship */
|
|
239
|
+
paymaster?: PaymasterConfig;
|
|
240
|
+
/** Salt nonce for address generation (defaults to 0) */
|
|
241
|
+
saltNonce?: bigint;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create a WDK gasless client
|
|
245
|
+
*
|
|
246
|
+
* This is the main entry point for using WDK with gasless payments.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* import { createWdkGaslessClient } from '@t402/wdk-gasless';
|
|
251
|
+
*
|
|
252
|
+
* const client = await createWdkGaslessClient({
|
|
253
|
+
* wdkAccount: myWdkAccount,
|
|
254
|
+
* publicClient,
|
|
255
|
+
* chainId: 42161, // Arbitrum
|
|
256
|
+
* bundler: {
|
|
257
|
+
* bundlerUrl: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',
|
|
258
|
+
* chainId: 42161,
|
|
259
|
+
* },
|
|
260
|
+
* paymaster: {
|
|
261
|
+
* address: '0x...',
|
|
262
|
+
* url: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',
|
|
263
|
+
* type: 'sponsoring',
|
|
264
|
+
* },
|
|
265
|
+
* });
|
|
266
|
+
*
|
|
267
|
+
* // Execute gasless payment
|
|
268
|
+
* const result = await client.pay({
|
|
269
|
+
* to: '0x...',
|
|
270
|
+
* amount: 1000000n, // 1 USDT0
|
|
271
|
+
* });
|
|
272
|
+
*
|
|
273
|
+
* const receipt = await result.wait();
|
|
274
|
+
* console.log('Payment confirmed:', receipt.txHash);
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
declare function createWdkGaslessClient(config: CreateWdkGaslessClientConfig): Promise<WdkGaslessClient>;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* WDK Smart Account
|
|
281
|
+
*
|
|
282
|
+
* Wraps a Tether WDK account to work with ERC-4337 smart accounts.
|
|
283
|
+
* Creates a Safe smart account with the WDK account as the owner/signer.
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Safe 4337 module addresses (v0.3.0)
|
|
288
|
+
* Deployed on all major EVM chains at the same addresses
|
|
289
|
+
*/
|
|
290
|
+
declare const SAFE_4337_ADDRESSES: {
|
|
291
|
+
/** Safe 4337 Module */
|
|
292
|
+
readonly module: Address;
|
|
293
|
+
/** Safe Module Setup */
|
|
294
|
+
readonly moduleSetup: Address;
|
|
295
|
+
/** Safe Singleton */
|
|
296
|
+
readonly singleton: Address;
|
|
297
|
+
/** Safe Proxy Factory */
|
|
298
|
+
readonly proxyFactory: Address;
|
|
299
|
+
/** Safe Fallback Handler */
|
|
300
|
+
readonly fallbackHandler: Address;
|
|
301
|
+
/** Add Modules Lib */
|
|
302
|
+
readonly addModulesLib: Address;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* WDK Smart Account
|
|
306
|
+
*
|
|
307
|
+
* Creates a Safe smart account using a WDK account as the owner/signer.
|
|
308
|
+
* Implements SmartAccountSigner for ERC-4337 compatibility.
|
|
309
|
+
*/
|
|
310
|
+
declare class WdkSmartAccount implements SmartAccountSigner {
|
|
311
|
+
private readonly wdkAccount;
|
|
312
|
+
private readonly publicClient;
|
|
313
|
+
private readonly chainId;
|
|
314
|
+
private readonly owners;
|
|
315
|
+
private readonly threshold;
|
|
316
|
+
private readonly saltNonce;
|
|
317
|
+
private cachedAddress?;
|
|
318
|
+
private cachedInitCode?;
|
|
319
|
+
private cachedOwnerAddress?;
|
|
320
|
+
private deploymentChecked;
|
|
321
|
+
private isAccountDeployed;
|
|
322
|
+
constructor(config: WdkSmartAccountConfig);
|
|
323
|
+
/**
|
|
324
|
+
* Initialize the account (fetch WDK address)
|
|
325
|
+
* Call this before using the account
|
|
326
|
+
*/
|
|
327
|
+
initialize(): Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* Get the WDK account's EOA address
|
|
330
|
+
*/
|
|
331
|
+
getOwnerAddress(): Promise<Address>;
|
|
332
|
+
/**
|
|
333
|
+
* Get the smart account address (counterfactual)
|
|
334
|
+
*/
|
|
335
|
+
getAddress(): Promise<Address>;
|
|
336
|
+
/**
|
|
337
|
+
* Sign a UserOperation hash using the WDK account
|
|
338
|
+
*/
|
|
339
|
+
signUserOpHash(userOpHash: Hex): Promise<Hex>;
|
|
340
|
+
/**
|
|
341
|
+
* Get the account's init code for deployment
|
|
342
|
+
*/
|
|
343
|
+
getInitCode(): Promise<Hex>;
|
|
344
|
+
/**
|
|
345
|
+
* Check if the account is deployed
|
|
346
|
+
*/
|
|
347
|
+
isDeployed(): Promise<boolean>;
|
|
348
|
+
/**
|
|
349
|
+
* Encode a call to the account's execute function
|
|
350
|
+
*/
|
|
351
|
+
encodeExecute(target: Address, value: bigint, data: Hex): Hex;
|
|
352
|
+
/**
|
|
353
|
+
* Encode a batch call to the account's executeBatch function
|
|
354
|
+
*/
|
|
355
|
+
encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex;
|
|
356
|
+
/**
|
|
357
|
+
* Build the Safe setup initializer data
|
|
358
|
+
*/
|
|
359
|
+
private buildInitializer;
|
|
360
|
+
/**
|
|
361
|
+
* Get the Safe's owners
|
|
362
|
+
*/
|
|
363
|
+
getOwners(): Address[];
|
|
364
|
+
/**
|
|
365
|
+
* Get the Safe's threshold
|
|
366
|
+
*/
|
|
367
|
+
getThreshold(): number;
|
|
368
|
+
/**
|
|
369
|
+
* Clear cached values (useful after deployment)
|
|
370
|
+
*/
|
|
371
|
+
clearCache(): void;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Create a WDK smart account
|
|
375
|
+
*/
|
|
376
|
+
declare function createWdkSmartAccount(config: WdkSmartAccountConfig): Promise<WdkSmartAccount>;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* WDK Gasless Constants
|
|
380
|
+
*
|
|
381
|
+
* Addresses and configuration for gasless USDT0 payments.
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* USDT0 OFT addresses by chain
|
|
386
|
+
*/
|
|
387
|
+
declare const USDT0_ADDRESSES: Record<string, Address>;
|
|
388
|
+
/**
|
|
389
|
+
* USDC addresses by chain
|
|
390
|
+
*/
|
|
391
|
+
declare const USDC_ADDRESSES: Record<string, Address>;
|
|
392
|
+
/**
|
|
393
|
+
* Chain IDs for supported networks
|
|
394
|
+
*/
|
|
395
|
+
declare const CHAIN_IDS: Record<string, number>;
|
|
396
|
+
/**
|
|
397
|
+
* Default bundler URLs by chain (using public endpoints)
|
|
398
|
+
*/
|
|
399
|
+
declare const DEFAULT_BUNDLER_URLS: Record<number, string>;
|
|
400
|
+
/**
|
|
401
|
+
* Get token address for a chain
|
|
402
|
+
*/
|
|
403
|
+
declare function getTokenAddress(token: "USDT0" | "USDC" | Address, chainName: string): Address;
|
|
404
|
+
/**
|
|
405
|
+
* Get chain name from chain ID
|
|
406
|
+
*/
|
|
407
|
+
declare function getChainName(chainId: number): string;
|
|
408
|
+
|
|
409
|
+
export { type BatchPaymentParams, CHAIN_IDS, type CreateWdkGaslessClientConfig, DEFAULT_BUNDLER_URLS, type GaslessPaymentParams, type GaslessPaymentReceipt, type GaslessPaymentResult, SAFE_4337_ADDRESSES, type SponsorshipInfo, USDC_ADDRESSES, USDT0_ADDRESSES, type WdkAccount, WdkGaslessClient, type WdkGaslessClientConfig, type WdkInstance, WdkSmartAccount, type WdkSmartAccountConfig, createWdkGaslessClient, createWdkSmartAccount, getChainName, getTokenAddress };
|