@t402/wdk-gasless 2.4.0 → 2.6.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 +56 -2
- package/dist/cjs/index.js +71 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.mts +56 -2
- package/dist/esm/index.mjs +67 -7
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +29 -17
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Address, Hex, PublicClient } from 'viem';
|
|
2
2
|
import { SmartAccountSigner, BundlerConfig, PaymasterConfig } from '@t402/evm';
|
|
3
3
|
export { BundlerConfig, PaymasterConfig, SmartAccountSigner, UserOperationReceipt } from '@t402/evm';
|
|
4
4
|
import { WdkAccount } from '@t402/wdk';
|
|
@@ -207,6 +207,12 @@ interface CreateWdkGaslessClientConfig {
|
|
|
207
207
|
paymaster?: PaymasterConfig;
|
|
208
208
|
/** Salt nonce for address generation (defaults to 0) */
|
|
209
209
|
saltNonce?: bigint;
|
|
210
|
+
/**
|
|
211
|
+
* Optional pre-created upstream ERC-4337 wallet instance
|
|
212
|
+
* (from @tetherto/wdk-wallet-evm-erc-4337).
|
|
213
|
+
* When provided, this is used instead of the custom Safe-based smart account.
|
|
214
|
+
*/
|
|
215
|
+
upstreamWallet?: unknown;
|
|
210
216
|
}
|
|
211
217
|
/**
|
|
212
218
|
* Create a WDK gasless client
|
|
@@ -347,6 +353,54 @@ declare class WdkSmartAccount implements SmartAccountSigner {
|
|
|
347
353
|
*/
|
|
348
354
|
declare function createWdkSmartAccount(config: WdkSmartAccountConfig): Promise<WdkSmartAccount>;
|
|
349
355
|
|
|
356
|
+
/**
|
|
357
|
+
* WDK EVM Gasless Adapter
|
|
358
|
+
*
|
|
359
|
+
* Detection and delegation layer for @tetherto/wdk-wallet-evm-erc-4337.
|
|
360
|
+
* When the upstream module is available, its smart account implementation
|
|
361
|
+
* is used. Otherwise, the custom Safe-based WdkSmartAccount is used as fallback.
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Upstream ERC-4337 wallet interface (from @tetherto/wdk-wallet-evm-erc-4337)
|
|
366
|
+
*
|
|
367
|
+
* The upstream module provides a smart account that implements these methods.
|
|
368
|
+
* We detect it by checking for characteristic method signatures.
|
|
369
|
+
*/
|
|
370
|
+
interface UpstreamErc4337Wallet {
|
|
371
|
+
getAddress(): Promise<Address>;
|
|
372
|
+
signUserOpHash(hash: Hex): Promise<Hex>;
|
|
373
|
+
getInitCode(): Promise<Hex>;
|
|
374
|
+
isDeployed(): Promise<boolean>;
|
|
375
|
+
encodeExecute(target: Address, value: bigint, data: Hex): Hex;
|
|
376
|
+
encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Check if an object looks like an upstream ERC-4337 smart account signer
|
|
380
|
+
*/
|
|
381
|
+
declare function isUpstreamErc4337Wallet(instance: unknown): instance is UpstreamErc4337Wallet;
|
|
382
|
+
/**
|
|
383
|
+
* Create a SmartAccountSigner, preferring the upstream @tetherto/wdk-wallet-evm-erc-4337
|
|
384
|
+
* module when available, falling back to the custom WdkSmartAccount.
|
|
385
|
+
*
|
|
386
|
+
* Resolution order:
|
|
387
|
+
* 1. If `upstreamWallet` is provided and satisfies SmartAccountSigner, use it directly
|
|
388
|
+
* 2. If `upstreamModule` is provided (the module constructor), create an instance
|
|
389
|
+
* 3. Fall back to custom WdkSmartAccount (Safe-based ERC-4337)
|
|
390
|
+
*
|
|
391
|
+
* @param config - Smart account configuration
|
|
392
|
+
* @param upstreamWallet - Optional pre-created upstream wallet instance
|
|
393
|
+
*/
|
|
394
|
+
declare function createSmartAccountSigner(config: WdkSmartAccountConfig, upstreamWallet?: unknown): Promise<SmartAccountSigner>;
|
|
395
|
+
/**
|
|
396
|
+
* Try to dynamically import the upstream @tetherto/wdk-wallet-evm-erc-4337 module.
|
|
397
|
+
* Returns the module if available, or undefined if not installed.
|
|
398
|
+
*
|
|
399
|
+
* Uses a string variable for the module specifier to avoid TypeScript
|
|
400
|
+
* emitting type declarations for the optional dependency.
|
|
401
|
+
*/
|
|
402
|
+
declare function tryLoadUpstreamModule(): Promise<unknown | undefined>;
|
|
403
|
+
|
|
350
404
|
/**
|
|
351
405
|
* WDK Gasless Constants
|
|
352
406
|
*
|
|
@@ -378,4 +432,4 @@ declare function getTokenAddress(token: 'USDT0' | 'USDC' | Address, chainName: s
|
|
|
378
432
|
*/
|
|
379
433
|
declare function getChainName(chainId: number): string;
|
|
380
434
|
|
|
381
|
-
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, WdkGaslessClient, type WdkGaslessClientConfig, type WdkInstance, WdkSmartAccount, type WdkSmartAccountConfig, createWdkGaslessClient, createWdkSmartAccount, getChainName, getTokenAddress };
|
|
435
|
+
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 UpstreamErc4337Wallet, WdkGaslessClient, type WdkGaslessClientConfig, type WdkInstance, WdkSmartAccount, type WdkSmartAccountConfig, createSmartAccountSigner, createWdkGaslessClient, createWdkSmartAccount, getChainName, getTokenAddress, isUpstreamErc4337Wallet, tryLoadUpstreamModule };
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,10 +27,13 @@ __export(index_exports, {
|
|
|
27
27
|
USDT0_ADDRESSES: () => USDT0_ADDRESSES,
|
|
28
28
|
WdkGaslessClient: () => WdkGaslessClient,
|
|
29
29
|
WdkSmartAccount: () => WdkSmartAccount,
|
|
30
|
+
createSmartAccountSigner: () => createSmartAccountSigner,
|
|
30
31
|
createWdkGaslessClient: () => createWdkGaslessClient,
|
|
31
32
|
createWdkSmartAccount: () => createWdkSmartAccount,
|
|
32
33
|
getChainName: () => getChainName,
|
|
33
|
-
getTokenAddress: () => getTokenAddress
|
|
34
|
+
getTokenAddress: () => getTokenAddress,
|
|
35
|
+
isUpstreamErc4337Wallet: () => isUpstreamErc4337Wallet,
|
|
36
|
+
tryLoadUpstreamModule: () => tryLoadUpstreamModule
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(index_exports);
|
|
36
39
|
|
|
@@ -354,6 +357,60 @@ async function createWdkSmartAccount(config) {
|
|
|
354
357
|
return account;
|
|
355
358
|
}
|
|
356
359
|
|
|
360
|
+
// src/adapter.ts
|
|
361
|
+
function isUpstreamErc4337Wallet(instance) {
|
|
362
|
+
if (typeof instance !== "object" || instance === null) return false;
|
|
363
|
+
const obj = instance;
|
|
364
|
+
return typeof obj.getAddress === "function" && typeof obj.signUserOpHash === "function" && typeof obj.getInitCode === "function" && typeof obj.isDeployed === "function" && typeof obj.encodeExecute === "function" && typeof obj.encodeExecuteBatch === "function";
|
|
365
|
+
}
|
|
366
|
+
async function createSmartAccountSigner(config, upstreamWallet) {
|
|
367
|
+
if (upstreamWallet && isUpstreamErc4337Wallet(upstreamWallet)) {
|
|
368
|
+
return upstreamWallet;
|
|
369
|
+
}
|
|
370
|
+
const upstreamModule = await tryLoadUpstreamModule();
|
|
371
|
+
if (upstreamModule) {
|
|
372
|
+
try {
|
|
373
|
+
const wallet = await createFromUpstream(upstreamModule, config);
|
|
374
|
+
if (wallet && isUpstreamErc4337Wallet(wallet)) {
|
|
375
|
+
return wallet;
|
|
376
|
+
}
|
|
377
|
+
} catch {
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return createWdkSmartAccount(config);
|
|
381
|
+
}
|
|
382
|
+
async function createFromUpstream(upstreamModule, config) {
|
|
383
|
+
if (typeof upstreamModule !== "object" || upstreamModule === null) {
|
|
384
|
+
return void 0;
|
|
385
|
+
}
|
|
386
|
+
const mod = upstreamModule;
|
|
387
|
+
const factoryNames = ["createSmartAccount", "createErc4337Wallet", "create", "default"];
|
|
388
|
+
for (const name of factoryNames) {
|
|
389
|
+
if (typeof mod[name] === "function") {
|
|
390
|
+
const factory = mod[name];
|
|
391
|
+
return factory({
|
|
392
|
+
account: config.wdkAccount,
|
|
393
|
+
publicClient: config.publicClient,
|
|
394
|
+
chainId: config.chainId,
|
|
395
|
+
saltNonce: config.saltNonce
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return void 0;
|
|
400
|
+
}
|
|
401
|
+
async function tryLoadUpstreamModule() {
|
|
402
|
+
try {
|
|
403
|
+
const moduleName = "@tetherto/wdk-wallet-evm-erc-4337";
|
|
404
|
+
const mod = await Function("m", "return import(m)")(
|
|
405
|
+
moduleName
|
|
406
|
+
);
|
|
407
|
+
const resolved = mod;
|
|
408
|
+
return resolved.default ?? resolved;
|
|
409
|
+
} catch {
|
|
410
|
+
return void 0;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
357
414
|
// src/constants.ts
|
|
358
415
|
var USDT0_ADDRESSES = {
|
|
359
416
|
ethereum: "0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee",
|
|
@@ -711,12 +768,15 @@ var WdkGaslessClient = class {
|
|
|
711
768
|
}
|
|
712
769
|
};
|
|
713
770
|
async function createWdkGaslessClient(config) {
|
|
714
|
-
const smartAccount = await
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
771
|
+
const smartAccount = await createSmartAccountSigner(
|
|
772
|
+
{
|
|
773
|
+
wdkAccount: config.wdkAccount,
|
|
774
|
+
publicClient: config.publicClient,
|
|
775
|
+
chainId: config.chainId,
|
|
776
|
+
saltNonce: config.saltNonce
|
|
777
|
+
},
|
|
778
|
+
config.upstreamWallet
|
|
779
|
+
);
|
|
720
780
|
return new WdkGaslessClient({
|
|
721
781
|
signer: smartAccount,
|
|
722
782
|
bundler: config.bundler,
|
|
@@ -734,9 +794,12 @@ async function createWdkGaslessClient(config) {
|
|
|
734
794
|
USDT0_ADDRESSES,
|
|
735
795
|
WdkGaslessClient,
|
|
736
796
|
WdkSmartAccount,
|
|
797
|
+
createSmartAccountSigner,
|
|
737
798
|
createWdkGaslessClient,
|
|
738
799
|
createWdkSmartAccount,
|
|
739
800
|
getChainName,
|
|
740
|
-
getTokenAddress
|
|
801
|
+
getTokenAddress,
|
|
802
|
+
isUpstreamErc4337Wallet,
|
|
803
|
+
tryLoadUpstreamModule
|
|
741
804
|
});
|
|
742
805
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/client.ts","../../src/account.ts","../../src/constants.ts"],"sourcesContent":["/**\n * @t402/wdk-gasless\n *\n * Gasless USDT0 payments using Tether WDK and ERC-4337 Account Abstraction.\n *\n * This package enables users to send USDT0 payments without holding any ETH\n * for gas fees. It works by:\n *\n * 1. Wrapping a WDK account in a Safe smart account (ERC-4337)\n * 2. Using a paymaster to sponsor gas fees\n * 3. Submitting UserOperations through a bundler\n *\n * @example Basic usage\n * ```typescript\n * import { createWdkGaslessClient } from '@t402/wdk-gasless';\n * import { createPublicClient, http } from 'viem';\n * import { arbitrum } from 'viem/chains';\n *\n * // Create public client\n * const publicClient = createPublicClient({\n * chain: arbitrum,\n * transport: http(),\n * });\n *\n * // Create gasless client\n * const client = await createWdkGaslessClient({\n * wdkAccount: myWdkAccount,\n * publicClient,\n * chainId: 42161,\n * bundler: {\n * bundlerUrl: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * chainId: 42161,\n * },\n * paymaster: {\n * address: '0x...',\n * url: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * type: 'sponsoring',\n * },\n * });\n *\n * // Check balance\n * const balance = await client.getFormattedBalance();\n * console.log(`USDT0 Balance: ${balance}`);\n *\n * // Execute gasless payment\n * const result = await client.pay({\n * to: '0x...',\n * amount: 1000000n, // 1 USDT0 (6 decimals)\n * });\n *\n * console.log('UserOp submitted:', result.userOpHash);\n * console.log('Sponsored (free gas):', result.sponsored);\n *\n * // Wait for confirmation\n * const receipt = await result.wait();\n * console.log('Confirmed in tx:', receipt.txHash);\n * ```\n *\n * @example Batch payments\n * ```typescript\n * // Send to multiple recipients in one transaction\n * const result = await client.payBatch({\n * payments: [\n * { to: '0xAlice...', amount: 1000000n }, // 1 USDT0\n * { to: '0xBob...', amount: 2000000n }, // 2 USDT0\n * { to: '0xCharlie...', amount: 500000n }, // 0.5 USDT0\n * ],\n * });\n * ```\n *\n * @example Check sponsorship eligibility\n * ```typescript\n * const info = await client.canSponsor({\n * to: '0x...',\n * amount: 1000000n,\n * });\n *\n * if (info.canSponsor) {\n * console.log('Payment will be sponsored (free gas)');\n * } else {\n * console.log('Not sponsored:', info.reason);\n * console.log('Estimated gas cost:', info.estimatedGasCost);\n * }\n * ```\n *\n * @packageDocumentation\n */\n\n// Main client\nexport { WdkGaslessClient, createWdkGaslessClient } from './client.js'\nexport type { CreateWdkGaslessClientConfig } from './client.js'\n\n// Smart account\nexport { WdkSmartAccount, createWdkSmartAccount, SAFE_4337_ADDRESSES } from './account.js'\n\n// Types\nexport type {\n WdkAccount,\n WdkInstance,\n WdkSmartAccountConfig,\n WdkGaslessClientConfig,\n GaslessPaymentParams,\n BatchPaymentParams,\n GaslessPaymentResult,\n GaslessPaymentReceipt,\n SponsorshipInfo,\n} from './types.js'\n\n// Constants\nexport {\n USDT0_ADDRESSES,\n USDC_ADDRESSES,\n CHAIN_IDS,\n DEFAULT_BUNDLER_URLS,\n getTokenAddress,\n getChainName,\n} from './constants.js'\n\n// Re-export essential types from @t402/evm for convenience\nexport type {\n SmartAccountSigner,\n BundlerConfig,\n PaymasterConfig,\n UserOperationReceipt,\n} from '@t402/evm'\n","/**\n * WDK Gasless Client\n *\n * High-level client for executing gasless USDT0 payments using\n * Tether WDK accounts and ERC-4337 Account Abstraction.\n */\n\nimport type { Address, Hex, PublicClient } from 'viem'\nimport { encodeFunctionData, formatUnits } from 'viem'\nimport { BundlerClient, PaymasterClient, UserOpBuilder, ENTRYPOINT_V07_ADDRESS } from '@t402/evm'\nimport type {\n SmartAccountSigner,\n BundlerConfig,\n PaymasterConfig,\n TransactionIntent,\n GasEstimate,\n PaymasterData,\n} from '@t402/evm'\nimport type {\n WdkGaslessClientConfig,\n GaslessPaymentParams,\n BatchPaymentParams,\n GaslessPaymentResult,\n GaslessPaymentReceipt,\n SponsorshipInfo,\n WdkAccount,\n} from './types.js'\nimport { createWdkSmartAccount } from './account.js'\nimport { getTokenAddress, getChainName } from './constants.js'\n\n/**\n * ERC20 transfer ABI\n */\nconst ERC20_TRANSFER_ABI = [\n {\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'amount', type: 'uint256' },\n ],\n name: 'transfer',\n outputs: [{ name: '', type: 'bool' }],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * ERC20 balanceOf ABI\n */\nconst ERC20_BALANCE_ABI = [\n {\n inputs: [{ name: 'account', type: 'address' }],\n name: 'balanceOf',\n outputs: [{ name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n\n/**\n * WDK Gasless Client\n *\n * Provides a simple API for executing gasless USDT0 payments using\n * WDK accounts and ERC-4337 smart accounts.\n */\nexport class WdkGaslessClient {\n private readonly signer: SmartAccountSigner\n private readonly builder: UserOpBuilder\n private readonly bundler: BundlerClient\n private readonly paymaster?: PaymasterClient\n private readonly chainId: number\n private readonly publicClient: PublicClient\n private readonly chainName: string\n\n constructor(config: WdkGaslessClientConfig) {\n this.signer = config.signer\n this.builder = new UserOpBuilder()\n this.bundler = new BundlerClient(config.bundler)\n this.paymaster = config.paymaster ? new PaymasterClient(config.paymaster) : undefined\n this.chainId = config.chainId\n this.publicClient = config.publicClient\n this.chainName = getChainName(config.chainId)\n }\n\n /**\n * Execute a gasless payment\n *\n * Sends USDT0 (or other tokens) without the user paying gas fees.\n * Gas is sponsored by a paymaster if configured.\n */\n async pay(params: GaslessPaymentParams): Promise<GaslessPaymentResult> {\n // Validate payment params\n if (!params.to || params.to === '0x0000000000000000000000000000000000000000') {\n throw new Error('Recipient address must not be the zero address')\n }\n\n if (params.amount <= 0n) {\n throw new Error('Payment amount must be greater than zero')\n }\n\n const token = params.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n // Build the transfer call data\n const callData = encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [params.to, params.amount],\n })\n\n // Create the transaction intent\n const intent: TransactionIntent = {\n to: tokenAddress,\n value: 0n,\n data: callData,\n }\n\n // Estimate gas\n const gasEstimate = await this.estimateGas(intent)\n\n // Get paymaster data if configured\n const paymasterData = await this.getPaymasterData(gasEstimate)\n const sponsored = paymasterData !== undefined\n\n // Build the UserOperation\n const userOp = await this.builder.buildUserOp(\n this.signer,\n intent,\n this.publicClient,\n gasEstimate,\n paymasterData,\n )\n\n // Sign the UserOperation\n const signedUserOp = await this.builder.signUserOp(\n userOp,\n this.signer,\n this.publicClient,\n this.chainId,\n )\n\n // Submit to bundler\n const result = await this.bundler.sendUserOperation(signedUserOp)\n const sender = await this.signer.getAddress()\n\n return {\n userOpHash: result.userOpHash,\n sender,\n sponsored,\n wait: async (): Promise<GaslessPaymentReceipt> => {\n const receipt = await result.wait()\n return {\n userOpHash: receipt.userOpHash,\n txHash: receipt.receipt.transactionHash,\n blockNumber: receipt.receipt.blockNumber,\n success: receipt.success,\n gasUsed: receipt.actualGasUsed,\n gasCost: receipt.actualGasCost,\n reason: receipt.reason,\n }\n },\n }\n }\n\n /**\n * Execute multiple payments in a single transaction\n *\n * More gas efficient than individual payments.\n * All payments are executed atomically.\n */\n async payBatch(params: BatchPaymentParams): Promise<GaslessPaymentResult> {\n // Validate batch params\n if (!params.payments || params.payments.length === 0) {\n throw new Error('Batch payments must contain at least one payment')\n }\n\n if (params.payments.length > 50) {\n throw new Error('Batch payments must not exceed 50 payments')\n }\n\n for (const payment of params.payments) {\n if (!payment.to || payment.to === '0x0000000000000000000000000000000000000000') {\n throw new Error('Recipient address must not be the zero address')\n }\n if (payment.amount <= 0n) {\n throw new Error('Payment amount must be greater than zero')\n }\n }\n\n // Build transaction intents for all payments\n const intents: TransactionIntent[] = params.payments.map((payment) => {\n const token = payment.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n return {\n to: tokenAddress,\n value: 0n,\n data: encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [payment.to, payment.amount],\n }),\n }\n })\n\n // Estimate gas for batch\n const gasEstimate = await this.estimateBatchGas(intents)\n\n // Get paymaster data\n const paymasterData = await this.getPaymasterData(gasEstimate)\n const sponsored = paymasterData !== undefined\n\n // Build batch UserOperation\n const userOp = await this.builder.buildBatchUserOp(\n this.signer,\n intents,\n this.publicClient,\n gasEstimate,\n paymasterData,\n )\n\n // Sign and submit\n const signedUserOp = await this.builder.signUserOp(\n userOp,\n this.signer,\n this.publicClient,\n this.chainId,\n )\n\n const result = await this.bundler.sendUserOperation(signedUserOp)\n const sender = await this.signer.getAddress()\n\n return {\n userOpHash: result.userOpHash,\n sender,\n sponsored,\n wait: async (): Promise<GaslessPaymentReceipt> => {\n const receipt = await result.wait()\n return {\n userOpHash: receipt.userOpHash,\n txHash: receipt.receipt.transactionHash,\n blockNumber: receipt.receipt.blockNumber,\n success: receipt.success,\n gasUsed: receipt.actualGasUsed,\n gasCost: receipt.actualGasCost,\n reason: receipt.reason,\n }\n },\n }\n }\n\n /**\n * Check if a payment can be sponsored (free gas)\n */\n async canSponsor(params: GaslessPaymentParams): Promise<SponsorshipInfo> {\n if (!this.paymaster) {\n return {\n canSponsor: false,\n reason: 'No paymaster configured',\n }\n }\n\n const token = params.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n const callData = encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [params.to, params.amount],\n })\n\n const sender = await this.signer.getAddress()\n const encodedCallData = this.signer.encodeExecute(tokenAddress, 0n, callData)\n\n try {\n const canSponsor = await this.paymaster.willSponsor(\n { sender, callData: encodedCallData },\n this.chainId,\n ENTRYPOINT_V07_ADDRESS,\n )\n\n if (canSponsor) {\n return { canSponsor: true }\n } else {\n // Estimate gas cost if not sponsored\n const intent: TransactionIntent = {\n to: tokenAddress,\n value: 0n,\n data: callData,\n }\n const gasEstimate = await this.estimateGas(intent)\n const gasPrice = await this.publicClient.getGasPrice()\n const estimatedGasCost =\n (gasEstimate.verificationGasLimit +\n gasEstimate.callGasLimit +\n gasEstimate.preVerificationGas) *\n gasPrice\n\n return {\n canSponsor: false,\n reason: 'Payment not eligible for sponsorship',\n estimatedGasCost,\n }\n }\n } catch (error) {\n return {\n canSponsor: false,\n reason: error instanceof Error ? error.message : 'Unknown error',\n }\n }\n }\n\n /**\n * Get the smart account address\n */\n async getAccountAddress(): Promise<Address> {\n return this.signer.getAddress()\n }\n\n /**\n * Check if the smart account is deployed\n */\n async isAccountDeployed(): Promise<boolean> {\n return this.signer.isDeployed()\n }\n\n /**\n * Get the token balance of the smart account\n */\n async getBalance(token: 'USDT0' | 'USDC' | Address = 'USDT0'): Promise<bigint> {\n const tokenAddress = getTokenAddress(token, this.chainName)\n const accountAddress = await this.signer.getAddress()\n\n const balance = await this.publicClient.readContract({\n address: tokenAddress,\n abi: ERC20_BALANCE_ABI,\n functionName: 'balanceOf',\n args: [accountAddress],\n })\n\n return balance as bigint\n }\n\n /**\n * Get the formatted token balance\n */\n async getFormattedBalance(\n token: 'USDT0' | 'USDC' | Address = 'USDT0',\n decimals = 6,\n ): Promise<string> {\n const balance = await this.getBalance(token)\n return formatUnits(balance, decimals)\n }\n\n /**\n * Estimate gas for a single transaction\n */\n private async estimateGas(intent: TransactionIntent): Promise<GasEstimate> {\n const sender = await this.signer.getAddress()\n const callData = this.signer.encodeExecute(intent.to, intent.value ?? 0n, intent.data ?? '0x')\n\n try {\n return await this.bundler.estimateUserOperationGas({\n sender,\n callData,\n })\n } catch {\n // Return defaults if estimation fails\n return {\n verificationGasLimit: 150000n,\n callGasLimit: 100000n,\n preVerificationGas: 50000n,\n }\n }\n }\n\n /**\n * Estimate gas for a batch transaction\n */\n private async estimateBatchGas(intents: TransactionIntent[]): Promise<GasEstimate> {\n const sender = await this.signer.getAddress()\n const callData = this.signer.encodeExecuteBatch(\n intents.map((i) => i.to),\n intents.map((i) => i.value ?? 0n),\n intents.map((i) => (i.data ?? '0x') as Hex),\n )\n\n try {\n return await this.bundler.estimateUserOperationGas({\n sender,\n callData,\n })\n } catch {\n // Return defaults with multiplier for batch size\n return {\n verificationGasLimit: 150000n,\n callGasLimit: 100000n * BigInt(intents.length),\n preVerificationGas: 50000n,\n }\n }\n }\n\n /**\n * Get paymaster data if configured\n */\n private async getPaymasterData(_gasEstimate: GasEstimate): Promise<PaymasterData | undefined> {\n if (!this.paymaster) return undefined\n\n const sender = await this.signer.getAddress()\n\n return this.paymaster.getPaymasterData({ sender }, this.chainId, ENTRYPOINT_V07_ADDRESS)\n }\n}\n\n/**\n * Configuration for creating a WDK gasless client\n */\nexport interface CreateWdkGaslessClientConfig {\n /** WDK account to use as the signer */\n wdkAccount: WdkAccount\n /** Public client for chain interactions */\n publicClient: PublicClient\n /** Chain ID */\n chainId: number\n /** Bundler configuration */\n bundler: BundlerConfig\n /** Optional paymaster for gas sponsorship */\n paymaster?: PaymasterConfig\n /** Salt nonce for address generation (defaults to 0) */\n saltNonce?: bigint\n}\n\n/**\n * Create a WDK gasless client\n *\n * This is the main entry point for using WDK with gasless payments.\n *\n * @example\n * ```typescript\n * import { createWdkGaslessClient } from '@t402/wdk-gasless';\n *\n * const client = await createWdkGaslessClient({\n * wdkAccount: myWdkAccount,\n * publicClient,\n * chainId: 42161, // Arbitrum\n * bundler: {\n * bundlerUrl: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * chainId: 42161,\n * },\n * paymaster: {\n * address: '0x...',\n * url: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * type: 'sponsoring',\n * },\n * });\n *\n * // Execute gasless payment\n * const result = await client.pay({\n * to: '0x...',\n * amount: 1000000n, // 1 USDT0\n * });\n *\n * const receipt = await result.wait();\n * console.log('Payment confirmed:', receipt.txHash);\n * ```\n */\nexport async function createWdkGaslessClient(\n config: CreateWdkGaslessClientConfig,\n): Promise<WdkGaslessClient> {\n // Create the WDK smart account\n const smartAccount = await createWdkSmartAccount({\n wdkAccount: config.wdkAccount,\n publicClient: config.publicClient,\n chainId: config.chainId,\n saltNonce: config.saltNonce,\n })\n\n // Create the gasless client\n return new WdkGaslessClient({\n signer: smartAccount,\n bundler: config.bundler,\n paymaster: config.paymaster,\n chainId: config.chainId,\n publicClient: config.publicClient,\n })\n}\n","/**\n * WDK Smart Account\n *\n * Wraps a Tether WDK account to work with ERC-4337 smart accounts.\n * Creates a Safe smart account with the WDK account as the owner/signer.\n */\n\nimport type { Address, Hex, PublicClient } from 'viem'\nimport {\n encodeFunctionData,\n encodeAbiParameters,\n concat,\n keccak256,\n getContractAddress,\n} from 'viem'\nimport type { SmartAccountSigner } from '@t402/evm'\nimport type { WdkAccount, WdkSmartAccountConfig } from './types.js'\n\n/**\n * Safe 4337 module addresses (v0.3.0)\n * Deployed on all major EVM chains at the same addresses\n */\nexport const SAFE_4337_ADDRESSES = {\n /** Safe 4337 Module */\n module: '0xa581c4A4DB7175302464fF3C06380BC3270b4037' as Address,\n /** Safe Module Setup */\n moduleSetup: '0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47' as Address,\n /** Safe Singleton */\n singleton: '0x29fcB43b46531BcA003ddC8FCB67FFE91900C762' as Address,\n /** Safe Proxy Factory */\n proxyFactory: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67' as Address,\n /** Safe Fallback Handler */\n fallbackHandler: '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99' as Address,\n /** Add Modules Lib */\n addModulesLib: '0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb' as Address,\n} as const\n\n/**\n * Safe Proxy Factory ABI\n */\nconst PROXY_FACTORY_ABI = [\n {\n inputs: [\n { name: 'singleton', type: 'address' },\n { name: 'initializer', type: 'bytes' },\n { name: 'saltNonce', type: 'uint256' },\n ],\n name: 'createProxyWithNonce',\n outputs: [{ name: 'proxy', type: 'address' }],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { name: 'singleton', type: 'address' },\n { name: 'initializer', type: 'bytes' },\n { name: 'saltNonce', type: 'uint256' },\n ],\n name: 'proxyCreationCode',\n outputs: [{ name: '', type: 'bytes' }],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n\n/**\n * Safe Singleton ABI\n */\nconst SAFE_ABI = [\n {\n inputs: [\n { name: 'owners', type: 'address[]' },\n { name: 'threshold', type: 'uint256' },\n { name: 'to', type: 'address' },\n { name: 'data', type: 'bytes' },\n { name: 'fallbackHandler', type: 'address' },\n { name: 'paymentToken', type: 'address' },\n { name: 'payment', type: 'uint256' },\n { name: 'paymentReceiver', type: 'address' },\n ],\n name: 'setup',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * Add Modules Lib ABI\n */\nconst ADD_MODULES_LIB_ABI = [\n {\n inputs: [{ name: 'modules', type: 'address[]' }],\n name: 'enableModules',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * Safe 4337 Module ABI\n */\nconst SAFE_4337_MODULE_ABI = [\n {\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'data', type: 'bytes' },\n { name: 'operation', type: 'uint8' },\n ],\n name: 'executeUserOp',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { name: 'tos', type: 'address[]' },\n { name: 'values', type: 'uint256[]' },\n { name: 'datas', type: 'bytes[]' },\n { name: 'operations', type: 'uint8[]' },\n ],\n name: 'executeUserOpBatch',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * WDK Smart Account\n *\n * Creates a Safe smart account using a WDK account as the owner/signer.\n * Implements SmartAccountSigner for ERC-4337 compatibility.\n */\nexport class WdkSmartAccount implements SmartAccountSigner {\n private readonly wdkAccount: WdkAccount\n private readonly publicClient: PublicClient\n private readonly _chainId: number\n private readonly owners: Address[]\n private readonly threshold: number\n private readonly saltNonce: bigint\n\n private cachedAddress?: Address\n private cachedInitCode?: Hex\n private cachedOwnerAddress?: Address\n private deploymentChecked = false\n private isAccountDeployed = false\n\n constructor(config: WdkSmartAccountConfig) {\n this.wdkAccount = config.wdkAccount\n this.publicClient = config.publicClient\n this._chainId = config.chainId\n this.threshold = config.threshold ?? 1\n this.saltNonce = config.saltNonce ?? 0n\n\n // Owners will be set when we get the WDK account address\n this.owners = config.additionalOwners ?? []\n }\n\n /**\n * Initialize the account (fetch WDK address)\n * Call this before using the account\n */\n async initialize(): Promise<void> {\n if (!this.cachedOwnerAddress) {\n const address = await this.wdkAccount.getAddress()\n this.cachedOwnerAddress = address as Address\n\n // Add WDK account as the first owner if not already in owners\n if (!this.owners.includes(this.cachedOwnerAddress)) {\n this.owners.unshift(this.cachedOwnerAddress)\n }\n }\n }\n\n /**\n * Get the WDK account's EOA address\n */\n async getOwnerAddress(): Promise<Address> {\n await this.initialize()\n return this.cachedOwnerAddress!\n }\n\n /**\n * Get the chain ID\n */\n getChainId(): number {\n return this._chainId\n }\n\n /**\n * Get the smart account address (counterfactual)\n */\n async getAddress(): Promise<Address> {\n await this.initialize()\n\n if (this.cachedAddress) {\n return this.cachedAddress\n }\n\n const initCode = await this.getInitCode()\n\n // If already deployed, get address from code\n if (initCode === '0x') {\n // Need to compute it anyway for first time\n const initializerData = await this.buildInitializer()\n const salt = keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'uint256' }],\n [keccak256(initializerData), this.saltNonce],\n ),\n )\n\n const proxyCreationCode = (await this.publicClient.readContract({\n address: SAFE_4337_ADDRESSES.proxyFactory,\n abi: PROXY_FACTORY_ABI,\n functionName: 'proxyCreationCode',\n args: [SAFE_4337_ADDRESSES.singleton, initializerData, this.saltNonce],\n })) as Hex\n\n this.cachedAddress = getContractAddress({\n bytecode: proxyCreationCode,\n from: SAFE_4337_ADDRESSES.proxyFactory,\n opcode: 'CREATE2',\n salt,\n })\n } else {\n // Extract initializer from init code\n const initializerData = `0x${initCode.slice(2 + 40 * 2)}` as Hex\n\n const salt = keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'uint256' }],\n [keccak256(initializerData), this.saltNonce],\n ),\n )\n\n const proxyCreationCode = (await this.publicClient.readContract({\n address: SAFE_4337_ADDRESSES.proxyFactory,\n abi: PROXY_FACTORY_ABI,\n functionName: 'proxyCreationCode',\n args: [SAFE_4337_ADDRESSES.singleton, initializerData, this.saltNonce],\n })) as Hex\n\n this.cachedAddress = getContractAddress({\n bytecode: proxyCreationCode,\n from: SAFE_4337_ADDRESSES.proxyFactory,\n opcode: 'CREATE2',\n salt,\n })\n }\n\n return this.cachedAddress\n }\n\n /**\n * Sign a UserOperation hash using the WDK account\n */\n async signUserOpHash(userOpHash: Hex): Promise<Hex> {\n await this.initialize()\n\n // Sign the hash using WDK account's signMessage\n // The hash is signed as raw bytes (personal_sign format)\n const signature = await this.wdkAccount.signMessage(userOpHash)\n\n // Format signature for Safe (add signature type byte)\n // Type 0: EOA signature\n return concat([signature as Hex, '0x00']) as Hex\n }\n\n /**\n * Get the account's init code for deployment\n */\n async getInitCode(): Promise<Hex> {\n await this.initialize()\n\n // Check if already deployed\n if (await this.isDeployed()) {\n return '0x' as Hex\n }\n\n if (this.cachedInitCode) {\n return this.cachedInitCode\n }\n\n const safeSetupData = await this.buildInitializer()\n\n // Build factory call data\n const createProxyData = encodeFunctionData({\n abi: PROXY_FACTORY_ABI,\n functionName: 'createProxyWithNonce',\n args: [SAFE_4337_ADDRESSES.singleton, safeSetupData, this.saltNonce],\n })\n\n // Init code = factory address + factory call data\n this.cachedInitCode = concat([SAFE_4337_ADDRESSES.proxyFactory, createProxyData]) as Hex\n\n return this.cachedInitCode\n }\n\n /**\n * Check if the account is deployed\n */\n async isDeployed(): Promise<boolean> {\n if (this.deploymentChecked) {\n return this.isAccountDeployed\n }\n\n // Set flag early to break infinite recursion:\n // getAddress() → getInitCode() → isDeployed() → getAddress() → ...\n // Default assumption (not deployed) is correct for init code computation.\n this.deploymentChecked = true\n\n await this.initialize()\n const address = this.cachedAddress ?? (await this.getAddress())\n const code = await this.publicClient.getCode({ address })\n\n this.isAccountDeployed = code !== undefined && code !== '0x'\n\n return this.isAccountDeployed\n }\n\n /**\n * Encode a call to the account's execute function\n */\n encodeExecute(target: Address, value: bigint, data: Hex): Hex {\n return encodeFunctionData({\n abi: SAFE_4337_MODULE_ABI,\n functionName: 'executeUserOp',\n args: [target, value, data, 0], // operation: CALL\n })\n }\n\n /**\n * Encode a batch call to the account's executeBatch function\n */\n encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex {\n if (targets.length !== values.length || targets.length !== datas.length) {\n throw new Error('Array lengths must match')\n }\n\n const operations = targets.map(() => 0) // All CALL operations\n\n return encodeFunctionData({\n abi: SAFE_4337_MODULE_ABI,\n functionName: 'executeUserOpBatch',\n args: [targets, values, datas, operations],\n })\n }\n\n /**\n * Build the Safe setup initializer data\n */\n private async buildInitializer(): Promise<Hex> {\n await this.initialize()\n\n // Build Safe setup data with 4337 module\n const setupModulesData = encodeFunctionData({\n abi: ADD_MODULES_LIB_ABI,\n functionName: 'enableModules',\n args: [[SAFE_4337_ADDRESSES.module]],\n })\n\n return encodeFunctionData({\n abi: SAFE_ABI,\n functionName: 'setup',\n args: [\n this.owners,\n BigInt(this.threshold),\n SAFE_4337_ADDRESSES.addModulesLib, // to: AddModulesLib\n setupModulesData, // data: enableModules([module])\n SAFE_4337_ADDRESSES.fallbackHandler,\n '0x0000000000000000000000000000000000000000' as Address, // paymentToken\n 0n, // payment\n '0x0000000000000000000000000000000000000000' as Address, // paymentReceiver\n ],\n })\n }\n\n /**\n * Get the Safe's owners\n */\n getOwners(): Address[] {\n return [...this.owners]\n }\n\n /**\n * Get the Safe's threshold\n */\n getThreshold(): number {\n return this.threshold\n }\n\n /**\n * Clear cached values (useful after deployment)\n */\n clearCache(): void {\n this.cachedAddress = undefined\n this.cachedInitCode = undefined\n this.deploymentChecked = false\n this.isAccountDeployed = false\n }\n}\n\n/**\n * Create a WDK smart account\n */\nexport async function createWdkSmartAccount(\n config: WdkSmartAccountConfig,\n): Promise<WdkSmartAccount> {\n const account = new WdkSmartAccount(config)\n await account.initialize()\n return account\n}\n","/**\n * WDK Gasless Constants\n *\n * Addresses and configuration for gasless USDT0 payments.\n */\n\nimport type { Address } from 'viem'\n\n/**\n * USDT0 OFT addresses by chain\n */\nexport const USDT0_ADDRESSES: Record<string, Address> = {\n ethereum: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n arbitrum: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',\n ink: '0x0200C29006150606B650577BBE7B6248F58470c1',\n berachain: '0x779Ded0c9e1022225f8E0630b35a9b54bE713736',\n unichain: '0x9151434b16b9763660705744891fA906F660EcC5',\n base: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n optimism: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n} as const\n\n/**\n * USDC addresses by chain\n */\nexport const USDC_ADDRESSES: Record<string, Address> = {\n ethereum: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n arbitrum: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',\n base: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n optimism: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',\n polygon: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n} as const\n\n/**\n * Chain IDs for supported networks\n */\nexport const CHAIN_IDS: Record<string, number> = {\n ethereum: 1,\n arbitrum: 42161,\n base: 8453,\n optimism: 10,\n polygon: 137,\n ink: 57073,\n berachain: 80094,\n unichain: 130,\n} as const\n\n/**\n * Default bundler URLs by chain (using public endpoints)\n */\nexport const DEFAULT_BUNDLER_URLS: Record<number, string> = {\n 1: 'https://api.pimlico.io/v2/ethereum/rpc',\n 42161: 'https://api.pimlico.io/v2/arbitrum/rpc',\n 8453: 'https://api.pimlico.io/v2/base/rpc',\n 10: 'https://api.pimlico.io/v2/optimism/rpc',\n 137: 'https://api.pimlico.io/v2/polygon/rpc',\n} as const\n\n/**\n * Get token address for a chain\n */\nexport function getTokenAddress(token: 'USDT0' | 'USDC' | Address, chainName: string): Address {\n if (token.startsWith('0x')) {\n return token as Address\n }\n\n const addresses = token === 'USDT0' ? USDT0_ADDRESSES : USDC_ADDRESSES\n const address = addresses[chainName.toLowerCase()]\n\n if (!address) {\n throw new Error(`Token ${token} not available on ${chainName}`)\n }\n\n return address\n}\n\n/**\n * Get chain name from chain ID\n */\nexport function getChainName(chainId: number): string {\n const entry = Object.entries(CHAIN_IDS).find(([, id]) => id === chainId)\n if (!entry) {\n throw new Error(`Unsupported chain ID: ${chainId}`)\n }\n return entry[0]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,IAAAA,eAAgD;AAChD,iBAAsF;;;ACDtF,kBAMO;AAQA,IAAM,sBAAsB;AAAA;AAAA,EAEjC,QAAQ;AAAA;AAAA,EAER,aAAa;AAAA;AAAA,EAEb,WAAW;AAAA;AAA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SAAS,MAAM,KAAK,OAAO,WAAW;AAC5C,UAAM,WAAW,KAAK,OAAO;AAAA,MAC3B,QAAQ,IAAI,CAAC,MAAM,EAAE,EAAE;AAAA,MACvB,QAAQ,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE;AAAA,MAChC,QAAQ,IAAI,CAAC,MAAO,EAAE,QAAQ,IAAY;AAAA,IAC5C;AAEA,QAAI;AACF,aAAO,MAAM,KAAK,QAAQ,yBAAyB;AAAA,QACjD;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,QAAQ;AAEN,aAAO;AAAA,QACL,sBAAsB;AAAA,QACtB,cAAc,UAAU,OAAO,QAAQ,MAAM;AAAA,QAC7C,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAc,iBAAiB,cAA+D;AAC5F,QAAI,CAAC,KAAK,UAAW,QAAO;AAE5B,UAAM,SAAS,MAAM,KAAK,OAAO,WAAW;AAE5C,WAAO,KAAK,UAAU,iBAAiB,EAAE,OAAO,GAAG,KAAK,SAAS,iCAAsB;AAAA,EACzF;AACF;AAsDA,eAAsB,uBACpB,QAC2B;AAE3B,QAAM,eAAe,MAAM,sBAAsB;AAAA,IAC/C,YAAY,OAAO;AAAA,IACnB,cAAc,OAAO;AAAA,IACrB,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,EACpB,CAAC;AAGD,SAAO,IAAI,iBAAiB;AAAA,IAC1B,QAAQ;AAAA,IACR,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,cAAc,OAAO;AAAA,EACvB,CAAC;AACH;","names":["import_viem"]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/client.ts","../../src/account.ts","../../src/adapter.ts","../../src/constants.ts"],"sourcesContent":["/**\n * @t402/wdk-gasless\n *\n * Gasless USDT0 payments using Tether WDK and ERC-4337 Account Abstraction.\n *\n * This package enables users to send USDT0 payments without holding any ETH\n * for gas fees. It works by:\n *\n * 1. Wrapping a WDK account in a Safe smart account (ERC-4337)\n * 2. Using a paymaster to sponsor gas fees\n * 3. Submitting UserOperations through a bundler\n *\n * @example Basic usage\n * ```typescript\n * import { createWdkGaslessClient } from '@t402/wdk-gasless';\n * import { createPublicClient, http } from 'viem';\n * import { arbitrum } from 'viem/chains';\n *\n * // Create public client\n * const publicClient = createPublicClient({\n * chain: arbitrum,\n * transport: http(),\n * });\n *\n * // Create gasless client\n * const client = await createWdkGaslessClient({\n * wdkAccount: myWdkAccount,\n * publicClient,\n * chainId: 42161,\n * bundler: {\n * bundlerUrl: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * chainId: 42161,\n * },\n * paymaster: {\n * address: '0x...',\n * url: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * type: 'sponsoring',\n * },\n * });\n *\n * // Check balance\n * const balance = await client.getFormattedBalance();\n * console.log(`USDT0 Balance: ${balance}`);\n *\n * // Execute gasless payment\n * const result = await client.pay({\n * to: '0x...',\n * amount: 1000000n, // 1 USDT0 (6 decimals)\n * });\n *\n * console.log('UserOp submitted:', result.userOpHash);\n * console.log('Sponsored (free gas):', result.sponsored);\n *\n * // Wait for confirmation\n * const receipt = await result.wait();\n * console.log('Confirmed in tx:', receipt.txHash);\n * ```\n *\n * @example Batch payments\n * ```typescript\n * // Send to multiple recipients in one transaction\n * const result = await client.payBatch({\n * payments: [\n * { to: '0xAlice...', amount: 1000000n }, // 1 USDT0\n * { to: '0xBob...', amount: 2000000n }, // 2 USDT0\n * { to: '0xCharlie...', amount: 500000n }, // 0.5 USDT0\n * ],\n * });\n * ```\n *\n * @example Check sponsorship eligibility\n * ```typescript\n * const info = await client.canSponsor({\n * to: '0x...',\n * amount: 1000000n,\n * });\n *\n * if (info.canSponsor) {\n * console.log('Payment will be sponsored (free gas)');\n * } else {\n * console.log('Not sponsored:', info.reason);\n * console.log('Estimated gas cost:', info.estimatedGasCost);\n * }\n * ```\n *\n * @packageDocumentation\n */\n\n// Main client\nexport { WdkGaslessClient, createWdkGaslessClient } from './client.js'\nexport type { CreateWdkGaslessClientConfig } from './client.js'\n\n// Smart account\nexport { WdkSmartAccount, createWdkSmartAccount, SAFE_4337_ADDRESSES } from './account.js'\n\n// Adapter (upstream integration)\nexport {\n createSmartAccountSigner,\n isUpstreamErc4337Wallet,\n tryLoadUpstreamModule,\n} from './adapter.js'\nexport type { UpstreamErc4337Wallet } from './adapter.js'\n\n// Types\nexport type {\n WdkAccount,\n WdkInstance,\n WdkSmartAccountConfig,\n WdkGaslessClientConfig,\n GaslessPaymentParams,\n BatchPaymentParams,\n GaslessPaymentResult,\n GaslessPaymentReceipt,\n SponsorshipInfo,\n} from './types.js'\n\n// Constants\nexport {\n USDT0_ADDRESSES,\n USDC_ADDRESSES,\n CHAIN_IDS,\n DEFAULT_BUNDLER_URLS,\n getTokenAddress,\n getChainName,\n} from './constants.js'\n\n// Re-export essential types from @t402/evm for convenience\nexport type {\n SmartAccountSigner,\n BundlerConfig,\n PaymasterConfig,\n UserOperationReceipt,\n} from '@t402/evm'\n","/**\n * WDK Gasless Client\n *\n * High-level client for executing gasless USDT0 payments using\n * Tether WDK accounts and ERC-4337 Account Abstraction.\n */\n\nimport type { Address, Hex, PublicClient } from 'viem'\nimport { encodeFunctionData, formatUnits } from 'viem'\nimport { BundlerClient, PaymasterClient, UserOpBuilder, ENTRYPOINT_V07_ADDRESS } from '@t402/evm'\nimport type {\n SmartAccountSigner,\n BundlerConfig,\n PaymasterConfig,\n TransactionIntent,\n GasEstimate,\n PaymasterData,\n} from '@t402/evm'\nimport type {\n WdkGaslessClientConfig,\n GaslessPaymentParams,\n BatchPaymentParams,\n GaslessPaymentResult,\n GaslessPaymentReceipt,\n SponsorshipInfo,\n WdkAccount,\n} from './types.js'\nimport { createSmartAccountSigner } from './adapter.js'\nimport { getTokenAddress, getChainName } from './constants.js'\n\n/**\n * ERC20 transfer ABI\n */\nconst ERC20_TRANSFER_ABI = [\n {\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'amount', type: 'uint256' },\n ],\n name: 'transfer',\n outputs: [{ name: '', type: 'bool' }],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * ERC20 balanceOf ABI\n */\nconst ERC20_BALANCE_ABI = [\n {\n inputs: [{ name: 'account', type: 'address' }],\n name: 'balanceOf',\n outputs: [{ name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n\n/**\n * WDK Gasless Client\n *\n * Provides a simple API for executing gasless USDT0 payments using\n * WDK accounts and ERC-4337 smart accounts.\n */\nexport class WdkGaslessClient {\n private readonly signer: SmartAccountSigner\n private readonly builder: UserOpBuilder\n private readonly bundler: BundlerClient\n private readonly paymaster?: PaymasterClient\n private readonly chainId: number\n private readonly publicClient: PublicClient\n private readonly chainName: string\n\n constructor(config: WdkGaslessClientConfig) {\n this.signer = config.signer\n this.builder = new UserOpBuilder()\n this.bundler = new BundlerClient(config.bundler)\n this.paymaster = config.paymaster ? new PaymasterClient(config.paymaster) : undefined\n this.chainId = config.chainId\n this.publicClient = config.publicClient\n this.chainName = getChainName(config.chainId)\n }\n\n /**\n * Execute a gasless payment\n *\n * Sends USDT0 (or other tokens) without the user paying gas fees.\n * Gas is sponsored by a paymaster if configured.\n */\n async pay(params: GaslessPaymentParams): Promise<GaslessPaymentResult> {\n // Validate payment params\n if (!params.to || params.to === '0x0000000000000000000000000000000000000000') {\n throw new Error('Recipient address must not be the zero address')\n }\n\n if (params.amount <= 0n) {\n throw new Error('Payment amount must be greater than zero')\n }\n\n const token = params.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n // Build the transfer call data\n const callData = encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [params.to, params.amount],\n })\n\n // Create the transaction intent\n const intent: TransactionIntent = {\n to: tokenAddress,\n value: 0n,\n data: callData,\n }\n\n // Estimate gas\n const gasEstimate = await this.estimateGas(intent)\n\n // Get paymaster data if configured\n const paymasterData = await this.getPaymasterData(gasEstimate)\n const sponsored = paymasterData !== undefined\n\n // Build the UserOperation\n const userOp = await this.builder.buildUserOp(\n this.signer,\n intent,\n this.publicClient,\n gasEstimate,\n paymasterData,\n )\n\n // Sign the UserOperation\n const signedUserOp = await this.builder.signUserOp(\n userOp,\n this.signer,\n this.publicClient,\n this.chainId,\n )\n\n // Submit to bundler\n const result = await this.bundler.sendUserOperation(signedUserOp)\n const sender = await this.signer.getAddress()\n\n return {\n userOpHash: result.userOpHash,\n sender,\n sponsored,\n wait: async (): Promise<GaslessPaymentReceipt> => {\n const receipt = await result.wait()\n return {\n userOpHash: receipt.userOpHash,\n txHash: receipt.receipt.transactionHash,\n blockNumber: receipt.receipt.blockNumber,\n success: receipt.success,\n gasUsed: receipt.actualGasUsed,\n gasCost: receipt.actualGasCost,\n reason: receipt.reason,\n }\n },\n }\n }\n\n /**\n * Execute multiple payments in a single transaction\n *\n * More gas efficient than individual payments.\n * All payments are executed atomically.\n */\n async payBatch(params: BatchPaymentParams): Promise<GaslessPaymentResult> {\n // Validate batch params\n if (!params.payments || params.payments.length === 0) {\n throw new Error('Batch payments must contain at least one payment')\n }\n\n if (params.payments.length > 50) {\n throw new Error('Batch payments must not exceed 50 payments')\n }\n\n for (const payment of params.payments) {\n if (!payment.to || payment.to === '0x0000000000000000000000000000000000000000') {\n throw new Error('Recipient address must not be the zero address')\n }\n if (payment.amount <= 0n) {\n throw new Error('Payment amount must be greater than zero')\n }\n }\n\n // Build transaction intents for all payments\n const intents: TransactionIntent[] = params.payments.map((payment) => {\n const token = payment.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n return {\n to: tokenAddress,\n value: 0n,\n data: encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [payment.to, payment.amount],\n }),\n }\n })\n\n // Estimate gas for batch\n const gasEstimate = await this.estimateBatchGas(intents)\n\n // Get paymaster data\n const paymasterData = await this.getPaymasterData(gasEstimate)\n const sponsored = paymasterData !== undefined\n\n // Build batch UserOperation\n const userOp = await this.builder.buildBatchUserOp(\n this.signer,\n intents,\n this.publicClient,\n gasEstimate,\n paymasterData,\n )\n\n // Sign and submit\n const signedUserOp = await this.builder.signUserOp(\n userOp,\n this.signer,\n this.publicClient,\n this.chainId,\n )\n\n const result = await this.bundler.sendUserOperation(signedUserOp)\n const sender = await this.signer.getAddress()\n\n return {\n userOpHash: result.userOpHash,\n sender,\n sponsored,\n wait: async (): Promise<GaslessPaymentReceipt> => {\n const receipt = await result.wait()\n return {\n userOpHash: receipt.userOpHash,\n txHash: receipt.receipt.transactionHash,\n blockNumber: receipt.receipt.blockNumber,\n success: receipt.success,\n gasUsed: receipt.actualGasUsed,\n gasCost: receipt.actualGasCost,\n reason: receipt.reason,\n }\n },\n }\n }\n\n /**\n * Check if a payment can be sponsored (free gas)\n */\n async canSponsor(params: GaslessPaymentParams): Promise<SponsorshipInfo> {\n if (!this.paymaster) {\n return {\n canSponsor: false,\n reason: 'No paymaster configured',\n }\n }\n\n const token = params.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n const callData = encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [params.to, params.amount],\n })\n\n const sender = await this.signer.getAddress()\n const encodedCallData = this.signer.encodeExecute(tokenAddress, 0n, callData)\n\n try {\n const canSponsor = await this.paymaster.willSponsor(\n { sender, callData: encodedCallData },\n this.chainId,\n ENTRYPOINT_V07_ADDRESS,\n )\n\n if (canSponsor) {\n return { canSponsor: true }\n } else {\n // Estimate gas cost if not sponsored\n const intent: TransactionIntent = {\n to: tokenAddress,\n value: 0n,\n data: callData,\n }\n const gasEstimate = await this.estimateGas(intent)\n const gasPrice = await this.publicClient.getGasPrice()\n const estimatedGasCost =\n (gasEstimate.verificationGasLimit +\n gasEstimate.callGasLimit +\n gasEstimate.preVerificationGas) *\n gasPrice\n\n return {\n canSponsor: false,\n reason: 'Payment not eligible for sponsorship',\n estimatedGasCost,\n }\n }\n } catch (error) {\n return {\n canSponsor: false,\n reason: error instanceof Error ? error.message : 'Unknown error',\n }\n }\n }\n\n /**\n * Get the smart account address\n */\n async getAccountAddress(): Promise<Address> {\n return this.signer.getAddress()\n }\n\n /**\n * Check if the smart account is deployed\n */\n async isAccountDeployed(): Promise<boolean> {\n return this.signer.isDeployed()\n }\n\n /**\n * Get the token balance of the smart account\n */\n async getBalance(token: 'USDT0' | 'USDC' | Address = 'USDT0'): Promise<bigint> {\n const tokenAddress = getTokenAddress(token, this.chainName)\n const accountAddress = await this.signer.getAddress()\n\n const balance = await this.publicClient.readContract({\n address: tokenAddress,\n abi: ERC20_BALANCE_ABI,\n functionName: 'balanceOf',\n args: [accountAddress],\n })\n\n return balance as bigint\n }\n\n /**\n * Get the formatted token balance\n */\n async getFormattedBalance(\n token: 'USDT0' | 'USDC' | Address = 'USDT0',\n decimals = 6,\n ): Promise<string> {\n const balance = await this.getBalance(token)\n return formatUnits(balance, decimals)\n }\n\n /**\n * Estimate gas for a single transaction\n */\n private async estimateGas(intent: TransactionIntent): Promise<GasEstimate> {\n const sender = await this.signer.getAddress()\n const callData = this.signer.encodeExecute(intent.to, intent.value ?? 0n, intent.data ?? '0x')\n\n try {\n return await this.bundler.estimateUserOperationGas({\n sender,\n callData,\n })\n } catch {\n // Return defaults if estimation fails\n return {\n verificationGasLimit: 150000n,\n callGasLimit: 100000n,\n preVerificationGas: 50000n,\n }\n }\n }\n\n /**\n * Estimate gas for a batch transaction\n */\n private async estimateBatchGas(intents: TransactionIntent[]): Promise<GasEstimate> {\n const sender = await this.signer.getAddress()\n const callData = this.signer.encodeExecuteBatch(\n intents.map((i) => i.to),\n intents.map((i) => i.value ?? 0n),\n intents.map((i) => (i.data ?? '0x') as Hex),\n )\n\n try {\n return await this.bundler.estimateUserOperationGas({\n sender,\n callData,\n })\n } catch {\n // Return defaults with multiplier for batch size\n return {\n verificationGasLimit: 150000n,\n callGasLimit: 100000n * BigInt(intents.length),\n preVerificationGas: 50000n,\n }\n }\n }\n\n /**\n * Get paymaster data if configured\n */\n private async getPaymasterData(_gasEstimate: GasEstimate): Promise<PaymasterData | undefined> {\n if (!this.paymaster) return undefined\n\n const sender = await this.signer.getAddress()\n\n return this.paymaster.getPaymasterData({ sender }, this.chainId, ENTRYPOINT_V07_ADDRESS)\n }\n}\n\n/**\n * Configuration for creating a WDK gasless client\n */\nexport interface CreateWdkGaslessClientConfig {\n /** WDK account to use as the signer */\n wdkAccount: WdkAccount\n /** Public client for chain interactions */\n publicClient: PublicClient\n /** Chain ID */\n chainId: number\n /** Bundler configuration */\n bundler: BundlerConfig\n /** Optional paymaster for gas sponsorship */\n paymaster?: PaymasterConfig\n /** Salt nonce for address generation (defaults to 0) */\n saltNonce?: bigint\n /**\n * Optional pre-created upstream ERC-4337 wallet instance\n * (from @tetherto/wdk-wallet-evm-erc-4337).\n * When provided, this is used instead of the custom Safe-based smart account.\n */\n upstreamWallet?: unknown\n}\n\n/**\n * Create a WDK gasless client\n *\n * This is the main entry point for using WDK with gasless payments.\n *\n * @example\n * ```typescript\n * import { createWdkGaslessClient } from '@t402/wdk-gasless';\n *\n * const client = await createWdkGaslessClient({\n * wdkAccount: myWdkAccount,\n * publicClient,\n * chainId: 42161, // Arbitrum\n * bundler: {\n * bundlerUrl: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * chainId: 42161,\n * },\n * paymaster: {\n * address: '0x...',\n * url: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * type: 'sponsoring',\n * },\n * });\n *\n * // Execute gasless payment\n * const result = await client.pay({\n * to: '0x...',\n * amount: 1000000n, // 1 USDT0\n * });\n *\n * const receipt = await result.wait();\n * console.log('Payment confirmed:', receipt.txHash);\n * ```\n */\nexport async function createWdkGaslessClient(\n config: CreateWdkGaslessClientConfig,\n): Promise<WdkGaslessClient> {\n // Create the smart account signer.\n // Uses upstream @tetherto/wdk-wallet-evm-erc-4337 when available,\n // falls back to custom Safe-based WdkSmartAccount.\n const smartAccount = await createSmartAccountSigner(\n {\n wdkAccount: config.wdkAccount,\n publicClient: config.publicClient,\n chainId: config.chainId,\n saltNonce: config.saltNonce,\n },\n config.upstreamWallet,\n )\n\n // Create the gasless client\n return new WdkGaslessClient({\n signer: smartAccount,\n bundler: config.bundler,\n paymaster: config.paymaster,\n chainId: config.chainId,\n publicClient: config.publicClient,\n })\n}\n","/**\n * WDK Smart Account\n *\n * Wraps a Tether WDK account to work with ERC-4337 smart accounts.\n * Creates a Safe smart account with the WDK account as the owner/signer.\n */\n\nimport type { Address, Hex, PublicClient } from 'viem'\nimport {\n encodeFunctionData,\n encodeAbiParameters,\n concat,\n keccak256,\n getContractAddress,\n} from 'viem'\nimport type { SmartAccountSigner } from '@t402/evm'\nimport type { WdkAccount, WdkSmartAccountConfig } from './types.js'\n\n/**\n * Safe 4337 module addresses (v0.3.0)\n * Deployed on all major EVM chains at the same addresses\n */\nexport const SAFE_4337_ADDRESSES = {\n /** Safe 4337 Module */\n module: '0xa581c4A4DB7175302464fF3C06380BC3270b4037' as Address,\n /** Safe Module Setup */\n moduleSetup: '0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47' as Address,\n /** Safe Singleton */\n singleton: '0x29fcB43b46531BcA003ddC8FCB67FFE91900C762' as Address,\n /** Safe Proxy Factory */\n proxyFactory: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67' as Address,\n /** Safe Fallback Handler */\n fallbackHandler: '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99' as Address,\n /** Add Modules Lib */\n addModulesLib: '0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb' as Address,\n} as const\n\n/**\n * Safe Proxy Factory ABI\n */\nconst PROXY_FACTORY_ABI = [\n {\n inputs: [\n { name: 'singleton', type: 'address' },\n { name: 'initializer', type: 'bytes' },\n { name: 'saltNonce', type: 'uint256' },\n ],\n name: 'createProxyWithNonce',\n outputs: [{ name: 'proxy', type: 'address' }],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { name: 'singleton', type: 'address' },\n { name: 'initializer', type: 'bytes' },\n { name: 'saltNonce', type: 'uint256' },\n ],\n name: 'proxyCreationCode',\n outputs: [{ name: '', type: 'bytes' }],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n\n/**\n * Safe Singleton ABI\n */\nconst SAFE_ABI = [\n {\n inputs: [\n { name: 'owners', type: 'address[]' },\n { name: 'threshold', type: 'uint256' },\n { name: 'to', type: 'address' },\n { name: 'data', type: 'bytes' },\n { name: 'fallbackHandler', type: 'address' },\n { name: 'paymentToken', type: 'address' },\n { name: 'payment', type: 'uint256' },\n { name: 'paymentReceiver', type: 'address' },\n ],\n name: 'setup',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * Add Modules Lib ABI\n */\nconst ADD_MODULES_LIB_ABI = [\n {\n inputs: [{ name: 'modules', type: 'address[]' }],\n name: 'enableModules',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * Safe 4337 Module ABI\n */\nconst SAFE_4337_MODULE_ABI = [\n {\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'data', type: 'bytes' },\n { name: 'operation', type: 'uint8' },\n ],\n name: 'executeUserOp',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { name: 'tos', type: 'address[]' },\n { name: 'values', type: 'uint256[]' },\n { name: 'datas', type: 'bytes[]' },\n { name: 'operations', type: 'uint8[]' },\n ],\n name: 'executeUserOpBatch',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * WDK Smart Account\n *\n * Creates a Safe smart account using a WDK account as the owner/signer.\n * Implements SmartAccountSigner for ERC-4337 compatibility.\n */\nexport class WdkSmartAccount implements SmartAccountSigner {\n private readonly wdkAccount: WdkAccount\n private readonly publicClient: PublicClient\n private readonly _chainId: number\n private readonly owners: Address[]\n private readonly threshold: number\n private readonly saltNonce: bigint\n\n private cachedAddress?: Address\n private cachedInitCode?: Hex\n private cachedOwnerAddress?: Address\n private deploymentChecked = false\n private isAccountDeployed = false\n\n constructor(config: WdkSmartAccountConfig) {\n this.wdkAccount = config.wdkAccount\n this.publicClient = config.publicClient\n this._chainId = config.chainId\n this.threshold = config.threshold ?? 1\n this.saltNonce = config.saltNonce ?? 0n\n\n // Owners will be set when we get the WDK account address\n this.owners = config.additionalOwners ?? []\n }\n\n /**\n * Initialize the account (fetch WDK address)\n * Call this before using the account\n */\n async initialize(): Promise<void> {\n if (!this.cachedOwnerAddress) {\n const address = await this.wdkAccount.getAddress()\n this.cachedOwnerAddress = address as Address\n\n // Add WDK account as the first owner if not already in owners\n if (!this.owners.includes(this.cachedOwnerAddress)) {\n this.owners.unshift(this.cachedOwnerAddress)\n }\n }\n }\n\n /**\n * Get the WDK account's EOA address\n */\n async getOwnerAddress(): Promise<Address> {\n await this.initialize()\n return this.cachedOwnerAddress!\n }\n\n /**\n * Get the chain ID\n */\n getChainId(): number {\n return this._chainId\n }\n\n /**\n * Get the smart account address (counterfactual)\n */\n async getAddress(): Promise<Address> {\n await this.initialize()\n\n if (this.cachedAddress) {\n return this.cachedAddress\n }\n\n const initCode = await this.getInitCode()\n\n // If already deployed, get address from code\n if (initCode === '0x') {\n // Need to compute it anyway for first time\n const initializerData = await this.buildInitializer()\n const salt = keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'uint256' }],\n [keccak256(initializerData), this.saltNonce],\n ),\n )\n\n const proxyCreationCode = (await this.publicClient.readContract({\n address: SAFE_4337_ADDRESSES.proxyFactory,\n abi: PROXY_FACTORY_ABI,\n functionName: 'proxyCreationCode',\n args: [SAFE_4337_ADDRESSES.singleton, initializerData, this.saltNonce],\n })) as Hex\n\n this.cachedAddress = getContractAddress({\n bytecode: proxyCreationCode,\n from: SAFE_4337_ADDRESSES.proxyFactory,\n opcode: 'CREATE2',\n salt,\n })\n } else {\n // Extract initializer from init code\n const initializerData = `0x${initCode.slice(2 + 40 * 2)}` as Hex\n\n const salt = keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'uint256' }],\n [keccak256(initializerData), this.saltNonce],\n ),\n )\n\n const proxyCreationCode = (await this.publicClient.readContract({\n address: SAFE_4337_ADDRESSES.proxyFactory,\n abi: PROXY_FACTORY_ABI,\n functionName: 'proxyCreationCode',\n args: [SAFE_4337_ADDRESSES.singleton, initializerData, this.saltNonce],\n })) as Hex\n\n this.cachedAddress = getContractAddress({\n bytecode: proxyCreationCode,\n from: SAFE_4337_ADDRESSES.proxyFactory,\n opcode: 'CREATE2',\n salt,\n })\n }\n\n return this.cachedAddress\n }\n\n /**\n * Sign a UserOperation hash using the WDK account\n */\n async signUserOpHash(userOpHash: Hex): Promise<Hex> {\n await this.initialize()\n\n // Sign the hash using WDK account's signMessage\n // The hash is signed as raw bytes (personal_sign format)\n const signature = await this.wdkAccount.signMessage(userOpHash)\n\n // Format signature for Safe (add signature type byte)\n // Type 0: EOA signature\n return concat([signature as Hex, '0x00']) as Hex\n }\n\n /**\n * Get the account's init code for deployment\n */\n async getInitCode(): Promise<Hex> {\n await this.initialize()\n\n // Check if already deployed\n if (await this.isDeployed()) {\n return '0x' as Hex\n }\n\n if (this.cachedInitCode) {\n return this.cachedInitCode\n }\n\n const safeSetupData = await this.buildInitializer()\n\n // Build factory call data\n const createProxyData = encodeFunctionData({\n abi: PROXY_FACTORY_ABI,\n functionName: 'createProxyWithNonce',\n args: [SAFE_4337_ADDRESSES.singleton, safeSetupData, this.saltNonce],\n })\n\n // Init code = factory address + factory call data\n this.cachedInitCode = concat([SAFE_4337_ADDRESSES.proxyFactory, createProxyData]) as Hex\n\n return this.cachedInitCode\n }\n\n /**\n * Check if the account is deployed\n */\n async isDeployed(): Promise<boolean> {\n if (this.deploymentChecked) {\n return this.isAccountDeployed\n }\n\n // Set flag early to break infinite recursion:\n // getAddress() → getInitCode() → isDeployed() → getAddress() → ...\n // Default assumption (not deployed) is correct for init code computation.\n this.deploymentChecked = true\n\n await this.initialize()\n const address = this.cachedAddress ?? (await this.getAddress())\n const code = await this.publicClient.getCode({ address })\n\n this.isAccountDeployed = code !== undefined && code !== '0x'\n\n return this.isAccountDeployed\n }\n\n /**\n * Encode a call to the account's execute function\n */\n encodeExecute(target: Address, value: bigint, data: Hex): Hex {\n return encodeFunctionData({\n abi: SAFE_4337_MODULE_ABI,\n functionName: 'executeUserOp',\n args: [target, value, data, 0], // operation: CALL\n })\n }\n\n /**\n * Encode a batch call to the account's executeBatch function\n */\n encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex {\n if (targets.length !== values.length || targets.length !== datas.length) {\n throw new Error('Array lengths must match')\n }\n\n const operations = targets.map(() => 0) // All CALL operations\n\n return encodeFunctionData({\n abi: SAFE_4337_MODULE_ABI,\n functionName: 'executeUserOpBatch',\n args: [targets, values, datas, operations],\n })\n }\n\n /**\n * Build the Safe setup initializer data\n */\n private async buildInitializer(): Promise<Hex> {\n await this.initialize()\n\n // Build Safe setup data with 4337 module\n const setupModulesData = encodeFunctionData({\n abi: ADD_MODULES_LIB_ABI,\n functionName: 'enableModules',\n args: [[SAFE_4337_ADDRESSES.module]],\n })\n\n return encodeFunctionData({\n abi: SAFE_ABI,\n functionName: 'setup',\n args: [\n this.owners,\n BigInt(this.threshold),\n SAFE_4337_ADDRESSES.addModulesLib, // to: AddModulesLib\n setupModulesData, // data: enableModules([module])\n SAFE_4337_ADDRESSES.fallbackHandler,\n '0x0000000000000000000000000000000000000000' as Address, // paymentToken\n 0n, // payment\n '0x0000000000000000000000000000000000000000' as Address, // paymentReceiver\n ],\n })\n }\n\n /**\n * Get the Safe's owners\n */\n getOwners(): Address[] {\n return [...this.owners]\n }\n\n /**\n * Get the Safe's threshold\n */\n getThreshold(): number {\n return this.threshold\n }\n\n /**\n * Clear cached values (useful after deployment)\n */\n clearCache(): void {\n this.cachedAddress = undefined\n this.cachedInitCode = undefined\n this.deploymentChecked = false\n this.isAccountDeployed = false\n }\n}\n\n/**\n * Create a WDK smart account\n */\nexport async function createWdkSmartAccount(\n config: WdkSmartAccountConfig,\n): Promise<WdkSmartAccount> {\n const account = new WdkSmartAccount(config)\n await account.initialize()\n return account\n}\n","/**\n * WDK EVM Gasless Adapter\n *\n * Detection and delegation layer for @tetherto/wdk-wallet-evm-erc-4337.\n * When the upstream module is available, its smart account implementation\n * is used. Otherwise, the custom Safe-based WdkSmartAccount is used as fallback.\n */\n\nimport type { Address, Hex } from 'viem'\nimport type { SmartAccountSigner } from '@t402/evm'\nimport type { WdkSmartAccountConfig } from './types.js'\nimport { createWdkSmartAccount } from './account.js'\n\n/**\n * Upstream ERC-4337 wallet interface (from @tetherto/wdk-wallet-evm-erc-4337)\n *\n * The upstream module provides a smart account that implements these methods.\n * We detect it by checking for characteristic method signatures.\n */\nexport interface UpstreamErc4337Wallet {\n getAddress(): Promise<Address>\n signUserOpHash(hash: Hex): Promise<Hex>\n getInitCode(): Promise<Hex>\n isDeployed(): Promise<boolean>\n encodeExecute(target: Address, value: bigint, data: Hex): Hex\n encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex\n}\n\n/**\n * Check if an object looks like an upstream ERC-4337 smart account signer\n */\nexport function isUpstreamErc4337Wallet(instance: unknown): instance is UpstreamErc4337Wallet {\n if (typeof instance !== 'object' || instance === null) return false\n const obj = instance as Record<string, unknown>\n return (\n typeof obj.getAddress === 'function' &&\n typeof obj.signUserOpHash === 'function' &&\n typeof obj.getInitCode === 'function' &&\n typeof obj.isDeployed === 'function' &&\n typeof obj.encodeExecute === 'function' &&\n typeof obj.encodeExecuteBatch === 'function'\n )\n}\n\n/**\n * Create a SmartAccountSigner, preferring the upstream @tetherto/wdk-wallet-evm-erc-4337\n * module when available, falling back to the custom WdkSmartAccount.\n *\n * Resolution order:\n * 1. If `upstreamWallet` is provided and satisfies SmartAccountSigner, use it directly\n * 2. If `upstreamModule` is provided (the module constructor), create an instance\n * 3. Fall back to custom WdkSmartAccount (Safe-based ERC-4337)\n *\n * @param config - Smart account configuration\n * @param upstreamWallet - Optional pre-created upstream wallet instance\n */\nexport async function createSmartAccountSigner(\n config: WdkSmartAccountConfig,\n upstreamWallet?: unknown,\n): Promise<SmartAccountSigner> {\n // Case 1: Pre-created upstream wallet that satisfies the signer interface\n if (upstreamWallet && isUpstreamErc4337Wallet(upstreamWallet)) {\n return upstreamWallet as SmartAccountSigner\n }\n\n // Case 2: Try to dynamically load the upstream module\n const upstreamModule = await tryLoadUpstreamModule()\n if (upstreamModule) {\n try {\n const wallet = await createFromUpstream(upstreamModule, config)\n if (wallet && isUpstreamErc4337Wallet(wallet)) {\n return wallet as SmartAccountSigner\n }\n } catch {\n // Fall through to custom implementation\n }\n }\n\n // Case 3: Fall back to custom Safe-based WdkSmartAccount\n return createWdkSmartAccount(config)\n}\n\n/**\n * Try to create a smart account from the upstream module.\n * The upstream module is expected to export a factory function.\n */\nasync function createFromUpstream(\n upstreamModule: unknown,\n config: WdkSmartAccountConfig,\n): Promise<unknown> {\n if (typeof upstreamModule !== 'object' || upstreamModule === null) {\n return undefined\n }\n\n const mod = upstreamModule as Record<string, unknown>\n\n // Try common factory function names from the upstream module\n const factoryNames = ['createSmartAccount', 'createErc4337Wallet', 'create', 'default']\n for (const name of factoryNames) {\n if (typeof mod[name] === 'function') {\n const factory = mod[name] as (config: Record<string, unknown>) => Promise<unknown>\n return factory({\n account: config.wdkAccount,\n publicClient: config.publicClient,\n chainId: config.chainId,\n saltNonce: config.saltNonce,\n })\n }\n }\n\n return undefined\n}\n\n/**\n * Try to dynamically import the upstream @tetherto/wdk-wallet-evm-erc-4337 module.\n * Returns the module if available, or undefined if not installed.\n *\n * Uses a string variable for the module specifier to avoid TypeScript\n * emitting type declarations for the optional dependency.\n */\nexport async function tryLoadUpstreamModule(): Promise<unknown | undefined> {\n try {\n // Use a variable to prevent TypeScript from resolving the module at compile time\n const moduleName = '@tetherto/wdk-wallet-evm-erc-4337'\n const mod = await (Function('m', 'return import(m)') as (m: string) => Promise<unknown>)(\n moduleName,\n )\n const resolved = mod as Record<string, unknown>\n return resolved.default ?? resolved\n } catch {\n return undefined\n }\n}\n","/**\n * WDK Gasless Constants\n *\n * Addresses and configuration for gasless USDT0 payments.\n */\n\nimport type { Address } from 'viem'\n\n/**\n * USDT0 OFT addresses by chain\n */\nexport const USDT0_ADDRESSES: Record<string, Address> = {\n ethereum: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n arbitrum: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',\n ink: '0x0200C29006150606B650577BBE7B6248F58470c1',\n berachain: '0x779Ded0c9e1022225f8E0630b35a9b54bE713736',\n unichain: '0x9151434b16b9763660705744891fA906F660EcC5',\n base: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n optimism: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n} as const\n\n/**\n * USDC addresses by chain\n */\nexport const USDC_ADDRESSES: Record<string, Address> = {\n ethereum: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n arbitrum: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',\n base: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n optimism: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',\n polygon: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n} as const\n\n/**\n * Chain IDs for supported networks\n */\nexport const CHAIN_IDS: Record<string, number> = {\n ethereum: 1,\n arbitrum: 42161,\n base: 8453,\n optimism: 10,\n polygon: 137,\n ink: 57073,\n berachain: 80094,\n unichain: 130,\n} as const\n\n/**\n * Default bundler URLs by chain (using public endpoints)\n */\nexport const DEFAULT_BUNDLER_URLS: Record<number, string> = {\n 1: 'https://api.pimlico.io/v2/ethereum/rpc',\n 42161: 'https://api.pimlico.io/v2/arbitrum/rpc',\n 8453: 'https://api.pimlico.io/v2/base/rpc',\n 10: 'https://api.pimlico.io/v2/optimism/rpc',\n 137: 'https://api.pimlico.io/v2/polygon/rpc',\n} as const\n\n/**\n * Get token address for a chain\n */\nexport function getTokenAddress(token: 'USDT0' | 'USDC' | Address, chainName: string): Address {\n if (token.startsWith('0x')) {\n return token as Address\n }\n\n const addresses = token === 'USDT0' ? USDT0_ADDRESSES : USDC_ADDRESSES\n const address = addresses[chainName.toLowerCase()]\n\n if (!address) {\n throw new Error(`Token ${token} not available on ${chainName}`)\n }\n\n return address\n}\n\n/**\n * Get chain name from chain ID\n */\nexport function getChainName(chainId: number): string {\n const entry = Object.entries(CHAIN_IDS).find(([, id]) => id === chainId)\n if (!entry) {\n throw new Error(`Unsupported chain ID: ${chainId}`)\n }\n return entry[0]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACQA,IAAAA,eAAgD;AAChD,iBAAsF;;;ACDtF,kBAMO;AAQA,IAAM,sBAAsB;AAAA;AAAA,EAEjC,QAAQ;AAAA;AAAA,EAER,aAAa;AAAA;AAAA,EAEb,WAAW;AAAA;AAAA,EAEX,cAAc;AAAA;AAAA,EAEd,iBAAiB;AAAA;AAAA,EAEjB,eAAe;AACjB;AAKA,IAAM,oBAAoB;AAAA,EACxB;AAAA,IACE,QAAQ;AAAA,MACN,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,MACrC,EAAE,MAAM,eAAe,MAAM,QAAQ;AAAA,MACrC,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,IACvC;AAAA,IACA,MAAM;AAAA,IACN,SAAS,CAAC,EAAE,MAAM,SAAS,MAAM,UAAU,CAAC;AAAA,IAC5C,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACR;AAAA,EACA;AAAA,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sBAAsB;AAAA,QACtB,cAAc,UAAU,OAAO,QAAQ,MAAM;AAAA,QAC7C,oBAAoB;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAc,iBAAiB,cAA+D;AAC5F,QAAI,CAAC,KAAK,UAAW,QAAO;AAE5B,UAAM,SAAS,MAAM,KAAK,OAAO,WAAW;AAE5C,WAAO,KAAK,UAAU,iBAAiB,EAAE,OAAO,GAAG,KAAK,SAAS,iCAAsB;AAAA,EACzF;AACF;AA4DA,eAAsB,uBACpB,QAC2B;AAI3B,QAAM,eAAe,MAAM;AAAA,IACzB;AAAA,MACE,YAAY,OAAO;AAAA,MACnB,cAAc,OAAO;AAAA,MACrB,SAAS,OAAO;AAAA,MAChB,WAAW,OAAO;AAAA,IACpB;AAAA,IACA,OAAO;AAAA,EACT;AAGA,SAAO,IAAI,iBAAiB;AAAA,IAC1B,QAAQ;AAAA,IACR,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,cAAc,OAAO;AAAA,EACvB,CAAC;AACH;","names":["import_viem"]}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Address, Hex, PublicClient } from 'viem';
|
|
2
2
|
import { SmartAccountSigner, BundlerConfig, PaymasterConfig } from '@t402/evm';
|
|
3
3
|
export { BundlerConfig, PaymasterConfig, SmartAccountSigner, UserOperationReceipt } from '@t402/evm';
|
|
4
4
|
import { WdkAccount } from '@t402/wdk';
|
|
@@ -207,6 +207,12 @@ interface CreateWdkGaslessClientConfig {
|
|
|
207
207
|
paymaster?: PaymasterConfig;
|
|
208
208
|
/** Salt nonce for address generation (defaults to 0) */
|
|
209
209
|
saltNonce?: bigint;
|
|
210
|
+
/**
|
|
211
|
+
* Optional pre-created upstream ERC-4337 wallet instance
|
|
212
|
+
* (from @tetherto/wdk-wallet-evm-erc-4337).
|
|
213
|
+
* When provided, this is used instead of the custom Safe-based smart account.
|
|
214
|
+
*/
|
|
215
|
+
upstreamWallet?: unknown;
|
|
210
216
|
}
|
|
211
217
|
/**
|
|
212
218
|
* Create a WDK gasless client
|
|
@@ -347,6 +353,54 @@ declare class WdkSmartAccount implements SmartAccountSigner {
|
|
|
347
353
|
*/
|
|
348
354
|
declare function createWdkSmartAccount(config: WdkSmartAccountConfig): Promise<WdkSmartAccount>;
|
|
349
355
|
|
|
356
|
+
/**
|
|
357
|
+
* WDK EVM Gasless Adapter
|
|
358
|
+
*
|
|
359
|
+
* Detection and delegation layer for @tetherto/wdk-wallet-evm-erc-4337.
|
|
360
|
+
* When the upstream module is available, its smart account implementation
|
|
361
|
+
* is used. Otherwise, the custom Safe-based WdkSmartAccount is used as fallback.
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Upstream ERC-4337 wallet interface (from @tetherto/wdk-wallet-evm-erc-4337)
|
|
366
|
+
*
|
|
367
|
+
* The upstream module provides a smart account that implements these methods.
|
|
368
|
+
* We detect it by checking for characteristic method signatures.
|
|
369
|
+
*/
|
|
370
|
+
interface UpstreamErc4337Wallet {
|
|
371
|
+
getAddress(): Promise<Address>;
|
|
372
|
+
signUserOpHash(hash: Hex): Promise<Hex>;
|
|
373
|
+
getInitCode(): Promise<Hex>;
|
|
374
|
+
isDeployed(): Promise<boolean>;
|
|
375
|
+
encodeExecute(target: Address, value: bigint, data: Hex): Hex;
|
|
376
|
+
encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Check if an object looks like an upstream ERC-4337 smart account signer
|
|
380
|
+
*/
|
|
381
|
+
declare function isUpstreamErc4337Wallet(instance: unknown): instance is UpstreamErc4337Wallet;
|
|
382
|
+
/**
|
|
383
|
+
* Create a SmartAccountSigner, preferring the upstream @tetherto/wdk-wallet-evm-erc-4337
|
|
384
|
+
* module when available, falling back to the custom WdkSmartAccount.
|
|
385
|
+
*
|
|
386
|
+
* Resolution order:
|
|
387
|
+
* 1. If `upstreamWallet` is provided and satisfies SmartAccountSigner, use it directly
|
|
388
|
+
* 2. If `upstreamModule` is provided (the module constructor), create an instance
|
|
389
|
+
* 3. Fall back to custom WdkSmartAccount (Safe-based ERC-4337)
|
|
390
|
+
*
|
|
391
|
+
* @param config - Smart account configuration
|
|
392
|
+
* @param upstreamWallet - Optional pre-created upstream wallet instance
|
|
393
|
+
*/
|
|
394
|
+
declare function createSmartAccountSigner(config: WdkSmartAccountConfig, upstreamWallet?: unknown): Promise<SmartAccountSigner>;
|
|
395
|
+
/**
|
|
396
|
+
* Try to dynamically import the upstream @tetherto/wdk-wallet-evm-erc-4337 module.
|
|
397
|
+
* Returns the module if available, or undefined if not installed.
|
|
398
|
+
*
|
|
399
|
+
* Uses a string variable for the module specifier to avoid TypeScript
|
|
400
|
+
* emitting type declarations for the optional dependency.
|
|
401
|
+
*/
|
|
402
|
+
declare function tryLoadUpstreamModule(): Promise<unknown | undefined>;
|
|
403
|
+
|
|
350
404
|
/**
|
|
351
405
|
* WDK Gasless Constants
|
|
352
406
|
*
|
|
@@ -378,4 +432,4 @@ declare function getTokenAddress(token: 'USDT0' | 'USDC' | Address, chainName: s
|
|
|
378
432
|
*/
|
|
379
433
|
declare function getChainName(chainId: number): string;
|
|
380
434
|
|
|
381
|
-
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, WdkGaslessClient, type WdkGaslessClientConfig, type WdkInstance, WdkSmartAccount, type WdkSmartAccountConfig, createWdkGaslessClient, createWdkSmartAccount, getChainName, getTokenAddress };
|
|
435
|
+
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 UpstreamErc4337Wallet, WdkGaslessClient, type WdkGaslessClientConfig, type WdkInstance, WdkSmartAccount, type WdkSmartAccountConfig, createSmartAccountSigner, createWdkGaslessClient, createWdkSmartAccount, getChainName, getTokenAddress, isUpstreamErc4337Wallet, tryLoadUpstreamModule };
|
package/dist/esm/index.mjs
CHANGED
|
@@ -324,6 +324,60 @@ async function createWdkSmartAccount(config) {
|
|
|
324
324
|
return account;
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
// src/adapter.ts
|
|
328
|
+
function isUpstreamErc4337Wallet(instance) {
|
|
329
|
+
if (typeof instance !== "object" || instance === null) return false;
|
|
330
|
+
const obj = instance;
|
|
331
|
+
return typeof obj.getAddress === "function" && typeof obj.signUserOpHash === "function" && typeof obj.getInitCode === "function" && typeof obj.isDeployed === "function" && typeof obj.encodeExecute === "function" && typeof obj.encodeExecuteBatch === "function";
|
|
332
|
+
}
|
|
333
|
+
async function createSmartAccountSigner(config, upstreamWallet) {
|
|
334
|
+
if (upstreamWallet && isUpstreamErc4337Wallet(upstreamWallet)) {
|
|
335
|
+
return upstreamWallet;
|
|
336
|
+
}
|
|
337
|
+
const upstreamModule = await tryLoadUpstreamModule();
|
|
338
|
+
if (upstreamModule) {
|
|
339
|
+
try {
|
|
340
|
+
const wallet = await createFromUpstream(upstreamModule, config);
|
|
341
|
+
if (wallet && isUpstreamErc4337Wallet(wallet)) {
|
|
342
|
+
return wallet;
|
|
343
|
+
}
|
|
344
|
+
} catch {
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return createWdkSmartAccount(config);
|
|
348
|
+
}
|
|
349
|
+
async function createFromUpstream(upstreamModule, config) {
|
|
350
|
+
if (typeof upstreamModule !== "object" || upstreamModule === null) {
|
|
351
|
+
return void 0;
|
|
352
|
+
}
|
|
353
|
+
const mod = upstreamModule;
|
|
354
|
+
const factoryNames = ["createSmartAccount", "createErc4337Wallet", "create", "default"];
|
|
355
|
+
for (const name of factoryNames) {
|
|
356
|
+
if (typeof mod[name] === "function") {
|
|
357
|
+
const factory = mod[name];
|
|
358
|
+
return factory({
|
|
359
|
+
account: config.wdkAccount,
|
|
360
|
+
publicClient: config.publicClient,
|
|
361
|
+
chainId: config.chainId,
|
|
362
|
+
saltNonce: config.saltNonce
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return void 0;
|
|
367
|
+
}
|
|
368
|
+
async function tryLoadUpstreamModule() {
|
|
369
|
+
try {
|
|
370
|
+
const moduleName = "@tetherto/wdk-wallet-evm-erc-4337";
|
|
371
|
+
const mod = await Function("m", "return import(m)")(
|
|
372
|
+
moduleName
|
|
373
|
+
);
|
|
374
|
+
const resolved = mod;
|
|
375
|
+
return resolved.default ?? resolved;
|
|
376
|
+
} catch {
|
|
377
|
+
return void 0;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
327
381
|
// src/constants.ts
|
|
328
382
|
var USDT0_ADDRESSES = {
|
|
329
383
|
ethereum: "0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee",
|
|
@@ -681,12 +735,15 @@ var WdkGaslessClient = class {
|
|
|
681
735
|
}
|
|
682
736
|
};
|
|
683
737
|
async function createWdkGaslessClient(config) {
|
|
684
|
-
const smartAccount = await
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
738
|
+
const smartAccount = await createSmartAccountSigner(
|
|
739
|
+
{
|
|
740
|
+
wdkAccount: config.wdkAccount,
|
|
741
|
+
publicClient: config.publicClient,
|
|
742
|
+
chainId: config.chainId,
|
|
743
|
+
saltNonce: config.saltNonce
|
|
744
|
+
},
|
|
745
|
+
config.upstreamWallet
|
|
746
|
+
);
|
|
690
747
|
return new WdkGaslessClient({
|
|
691
748
|
signer: smartAccount,
|
|
692
749
|
bundler: config.bundler,
|
|
@@ -703,9 +760,12 @@ export {
|
|
|
703
760
|
USDT0_ADDRESSES,
|
|
704
761
|
WdkGaslessClient,
|
|
705
762
|
WdkSmartAccount,
|
|
763
|
+
createSmartAccountSigner,
|
|
706
764
|
createWdkGaslessClient,
|
|
707
765
|
createWdkSmartAccount,
|
|
708
766
|
getChainName,
|
|
709
|
-
getTokenAddress
|
|
767
|
+
getTokenAddress,
|
|
768
|
+
isUpstreamErc4337Wallet,
|
|
769
|
+
tryLoadUpstreamModule
|
|
710
770
|
};
|
|
711
771
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client.ts","../../src/account.ts","../../src/constants.ts"],"sourcesContent":["/**\n * WDK Gasless Client\n *\n * High-level client for executing gasless USDT0 payments using\n * Tether WDK accounts and ERC-4337 Account Abstraction.\n */\n\nimport type { Address, Hex, PublicClient } from 'viem'\nimport { encodeFunctionData, formatUnits } from 'viem'\nimport { BundlerClient, PaymasterClient, UserOpBuilder, ENTRYPOINT_V07_ADDRESS } from '@t402/evm'\nimport type {\n SmartAccountSigner,\n BundlerConfig,\n PaymasterConfig,\n TransactionIntent,\n GasEstimate,\n PaymasterData,\n} from '@t402/evm'\nimport type {\n WdkGaslessClientConfig,\n GaslessPaymentParams,\n BatchPaymentParams,\n GaslessPaymentResult,\n GaslessPaymentReceipt,\n SponsorshipInfo,\n WdkAccount,\n} from './types.js'\nimport { createWdkSmartAccount } from './account.js'\nimport { getTokenAddress, getChainName } from './constants.js'\n\n/**\n * ERC20 transfer ABI\n */\nconst ERC20_TRANSFER_ABI = [\n {\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'amount', type: 'uint256' },\n ],\n name: 'transfer',\n outputs: [{ name: '', type: 'bool' }],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * ERC20 balanceOf ABI\n */\nconst ERC20_BALANCE_ABI = [\n {\n inputs: [{ name: 'account', type: 'address' }],\n name: 'balanceOf',\n outputs: [{ name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n\n/**\n * WDK Gasless Client\n *\n * Provides a simple API for executing gasless USDT0 payments using\n * WDK accounts and ERC-4337 smart accounts.\n */\nexport class WdkGaslessClient {\n private readonly signer: SmartAccountSigner\n private readonly builder: UserOpBuilder\n private readonly bundler: BundlerClient\n private readonly paymaster?: PaymasterClient\n private readonly chainId: number\n private readonly publicClient: PublicClient\n private readonly chainName: string\n\n constructor(config: WdkGaslessClientConfig) {\n this.signer = config.signer\n this.builder = new UserOpBuilder()\n this.bundler = new BundlerClient(config.bundler)\n this.paymaster = config.paymaster ? new PaymasterClient(config.paymaster) : undefined\n this.chainId = config.chainId\n this.publicClient = config.publicClient\n this.chainName = getChainName(config.chainId)\n }\n\n /**\n * Execute a gasless payment\n *\n * Sends USDT0 (or other tokens) without the user paying gas fees.\n * Gas is sponsored by a paymaster if configured.\n */\n async pay(params: GaslessPaymentParams): Promise<GaslessPaymentResult> {\n // Validate payment params\n if (!params.to || params.to === '0x0000000000000000000000000000000000000000') {\n throw new Error('Recipient address must not be the zero address')\n }\n\n if (params.amount <= 0n) {\n throw new Error('Payment amount must be greater than zero')\n }\n\n const token = params.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n // Build the transfer call data\n const callData = encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [params.to, params.amount],\n })\n\n // Create the transaction intent\n const intent: TransactionIntent = {\n to: tokenAddress,\n value: 0n,\n data: callData,\n }\n\n // Estimate gas\n const gasEstimate = await this.estimateGas(intent)\n\n // Get paymaster data if configured\n const paymasterData = await this.getPaymasterData(gasEstimate)\n const sponsored = paymasterData !== undefined\n\n // Build the UserOperation\n const userOp = await this.builder.buildUserOp(\n this.signer,\n intent,\n this.publicClient,\n gasEstimate,\n paymasterData,\n )\n\n // Sign the UserOperation\n const signedUserOp = await this.builder.signUserOp(\n userOp,\n this.signer,\n this.publicClient,\n this.chainId,\n )\n\n // Submit to bundler\n const result = await this.bundler.sendUserOperation(signedUserOp)\n const sender = await this.signer.getAddress()\n\n return {\n userOpHash: result.userOpHash,\n sender,\n sponsored,\n wait: async (): Promise<GaslessPaymentReceipt> => {\n const receipt = await result.wait()\n return {\n userOpHash: receipt.userOpHash,\n txHash: receipt.receipt.transactionHash,\n blockNumber: receipt.receipt.blockNumber,\n success: receipt.success,\n gasUsed: receipt.actualGasUsed,\n gasCost: receipt.actualGasCost,\n reason: receipt.reason,\n }\n },\n }\n }\n\n /**\n * Execute multiple payments in a single transaction\n *\n * More gas efficient than individual payments.\n * All payments are executed atomically.\n */\n async payBatch(params: BatchPaymentParams): Promise<GaslessPaymentResult> {\n // Validate batch params\n if (!params.payments || params.payments.length === 0) {\n throw new Error('Batch payments must contain at least one payment')\n }\n\n if (params.payments.length > 50) {\n throw new Error('Batch payments must not exceed 50 payments')\n }\n\n for (const payment of params.payments) {\n if (!payment.to || payment.to === '0x0000000000000000000000000000000000000000') {\n throw new Error('Recipient address must not be the zero address')\n }\n if (payment.amount <= 0n) {\n throw new Error('Payment amount must be greater than zero')\n }\n }\n\n // Build transaction intents for all payments\n const intents: TransactionIntent[] = params.payments.map((payment) => {\n const token = payment.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n return {\n to: tokenAddress,\n value: 0n,\n data: encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [payment.to, payment.amount],\n }),\n }\n })\n\n // Estimate gas for batch\n const gasEstimate = await this.estimateBatchGas(intents)\n\n // Get paymaster data\n const paymasterData = await this.getPaymasterData(gasEstimate)\n const sponsored = paymasterData !== undefined\n\n // Build batch UserOperation\n const userOp = await this.builder.buildBatchUserOp(\n this.signer,\n intents,\n this.publicClient,\n gasEstimate,\n paymasterData,\n )\n\n // Sign and submit\n const signedUserOp = await this.builder.signUserOp(\n userOp,\n this.signer,\n this.publicClient,\n this.chainId,\n )\n\n const result = await this.bundler.sendUserOperation(signedUserOp)\n const sender = await this.signer.getAddress()\n\n return {\n userOpHash: result.userOpHash,\n sender,\n sponsored,\n wait: async (): Promise<GaslessPaymentReceipt> => {\n const receipt = await result.wait()\n return {\n userOpHash: receipt.userOpHash,\n txHash: receipt.receipt.transactionHash,\n blockNumber: receipt.receipt.blockNumber,\n success: receipt.success,\n gasUsed: receipt.actualGasUsed,\n gasCost: receipt.actualGasCost,\n reason: receipt.reason,\n }\n },\n }\n }\n\n /**\n * Check if a payment can be sponsored (free gas)\n */\n async canSponsor(params: GaslessPaymentParams): Promise<SponsorshipInfo> {\n if (!this.paymaster) {\n return {\n canSponsor: false,\n reason: 'No paymaster configured',\n }\n }\n\n const token = params.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n const callData = encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [params.to, params.amount],\n })\n\n const sender = await this.signer.getAddress()\n const encodedCallData = this.signer.encodeExecute(tokenAddress, 0n, callData)\n\n try {\n const canSponsor = await this.paymaster.willSponsor(\n { sender, callData: encodedCallData },\n this.chainId,\n ENTRYPOINT_V07_ADDRESS,\n )\n\n if (canSponsor) {\n return { canSponsor: true }\n } else {\n // Estimate gas cost if not sponsored\n const intent: TransactionIntent = {\n to: tokenAddress,\n value: 0n,\n data: callData,\n }\n const gasEstimate = await this.estimateGas(intent)\n const gasPrice = await this.publicClient.getGasPrice()\n const estimatedGasCost =\n (gasEstimate.verificationGasLimit +\n gasEstimate.callGasLimit +\n gasEstimate.preVerificationGas) *\n gasPrice\n\n return {\n canSponsor: false,\n reason: 'Payment not eligible for sponsorship',\n estimatedGasCost,\n }\n }\n } catch (error) {\n return {\n canSponsor: false,\n reason: error instanceof Error ? error.message : 'Unknown error',\n }\n }\n }\n\n /**\n * Get the smart account address\n */\n async getAccountAddress(): Promise<Address> {\n return this.signer.getAddress()\n }\n\n /**\n * Check if the smart account is deployed\n */\n async isAccountDeployed(): Promise<boolean> {\n return this.signer.isDeployed()\n }\n\n /**\n * Get the token balance of the smart account\n */\n async getBalance(token: 'USDT0' | 'USDC' | Address = 'USDT0'): Promise<bigint> {\n const tokenAddress = getTokenAddress(token, this.chainName)\n const accountAddress = await this.signer.getAddress()\n\n const balance = await this.publicClient.readContract({\n address: tokenAddress,\n abi: ERC20_BALANCE_ABI,\n functionName: 'balanceOf',\n args: [accountAddress],\n })\n\n return balance as bigint\n }\n\n /**\n * Get the formatted token balance\n */\n async getFormattedBalance(\n token: 'USDT0' | 'USDC' | Address = 'USDT0',\n decimals = 6,\n ): Promise<string> {\n const balance = await this.getBalance(token)\n return formatUnits(balance, decimals)\n }\n\n /**\n * Estimate gas for a single transaction\n */\n private async estimateGas(intent: TransactionIntent): Promise<GasEstimate> {\n const sender = await this.signer.getAddress()\n const callData = this.signer.encodeExecute(intent.to, intent.value ?? 0n, intent.data ?? '0x')\n\n try {\n return await this.bundler.estimateUserOperationGas({\n sender,\n callData,\n })\n } catch {\n // Return defaults if estimation fails\n return {\n verificationGasLimit: 150000n,\n callGasLimit: 100000n,\n preVerificationGas: 50000n,\n }\n }\n }\n\n /**\n * Estimate gas for a batch transaction\n */\n private async estimateBatchGas(intents: TransactionIntent[]): Promise<GasEstimate> {\n const sender = await this.signer.getAddress()\n const callData = this.signer.encodeExecuteBatch(\n intents.map((i) => i.to),\n intents.map((i) => i.value ?? 0n),\n intents.map((i) => (i.data ?? '0x') as Hex),\n )\n\n try {\n return await this.bundler.estimateUserOperationGas({\n sender,\n callData,\n })\n } catch {\n // Return defaults with multiplier for batch size\n return {\n verificationGasLimit: 150000n,\n callGasLimit: 100000n * BigInt(intents.length),\n preVerificationGas: 50000n,\n }\n }\n }\n\n /**\n * Get paymaster data if configured\n */\n private async getPaymasterData(_gasEstimate: GasEstimate): Promise<PaymasterData | undefined> {\n if (!this.paymaster) return undefined\n\n const sender = await this.signer.getAddress()\n\n return this.paymaster.getPaymasterData({ sender }, this.chainId, ENTRYPOINT_V07_ADDRESS)\n }\n}\n\n/**\n * Configuration for creating a WDK gasless client\n */\nexport interface CreateWdkGaslessClientConfig {\n /** WDK account to use as the signer */\n wdkAccount: WdkAccount\n /** Public client for chain interactions */\n publicClient: PublicClient\n /** Chain ID */\n chainId: number\n /** Bundler configuration */\n bundler: BundlerConfig\n /** Optional paymaster for gas sponsorship */\n paymaster?: PaymasterConfig\n /** Salt nonce for address generation (defaults to 0) */\n saltNonce?: bigint\n}\n\n/**\n * Create a WDK gasless client\n *\n * This is the main entry point for using WDK with gasless payments.\n *\n * @example\n * ```typescript\n * import { createWdkGaslessClient } from '@t402/wdk-gasless';\n *\n * const client = await createWdkGaslessClient({\n * wdkAccount: myWdkAccount,\n * publicClient,\n * chainId: 42161, // Arbitrum\n * bundler: {\n * bundlerUrl: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * chainId: 42161,\n * },\n * paymaster: {\n * address: '0x...',\n * url: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * type: 'sponsoring',\n * },\n * });\n *\n * // Execute gasless payment\n * const result = await client.pay({\n * to: '0x...',\n * amount: 1000000n, // 1 USDT0\n * });\n *\n * const receipt = await result.wait();\n * console.log('Payment confirmed:', receipt.txHash);\n * ```\n */\nexport async function createWdkGaslessClient(\n config: CreateWdkGaslessClientConfig,\n): Promise<WdkGaslessClient> {\n // Create the WDK smart account\n const smartAccount = await createWdkSmartAccount({\n wdkAccount: config.wdkAccount,\n publicClient: config.publicClient,\n chainId: config.chainId,\n saltNonce: config.saltNonce,\n })\n\n // Create the gasless client\n return new WdkGaslessClient({\n signer: smartAccount,\n bundler: config.bundler,\n paymaster: config.paymaster,\n chainId: config.chainId,\n publicClient: config.publicClient,\n })\n}\n","/**\n * WDK Smart Account\n *\n * Wraps a Tether WDK account to work with ERC-4337 smart accounts.\n * Creates a Safe smart account with the WDK account as the owner/signer.\n */\n\nimport type { Address, Hex, PublicClient } from 'viem'\nimport {\n encodeFunctionData,\n encodeAbiParameters,\n concat,\n keccak256,\n getContractAddress,\n} from 'viem'\nimport type { SmartAccountSigner } from '@t402/evm'\nimport type { WdkAccount, WdkSmartAccountConfig } from './types.js'\n\n/**\n * Safe 4337 module addresses (v0.3.0)\n * Deployed on all major EVM chains at the same addresses\n */\nexport const SAFE_4337_ADDRESSES = {\n /** Safe 4337 Module */\n module: '0xa581c4A4DB7175302464fF3C06380BC3270b4037' as Address,\n /** Safe Module Setup */\n moduleSetup: '0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47' as Address,\n /** Safe Singleton */\n singleton: '0x29fcB43b46531BcA003ddC8FCB67FFE91900C762' as Address,\n /** Safe Proxy Factory */\n proxyFactory: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67' as Address,\n /** Safe Fallback Handler */\n fallbackHandler: '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99' as Address,\n /** Add Modules Lib */\n addModulesLib: '0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb' as Address,\n} as const\n\n/**\n * Safe Proxy Factory ABI\n */\nconst PROXY_FACTORY_ABI = [\n {\n inputs: [\n { name: 'singleton', type: 'address' },\n { name: 'initializer', type: 'bytes' },\n { name: 'saltNonce', type: 'uint256' },\n ],\n name: 'createProxyWithNonce',\n outputs: [{ name: 'proxy', type: 'address' }],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { name: 'singleton', type: 'address' },\n { name: 'initializer', type: 'bytes' },\n { name: 'saltNonce', type: 'uint256' },\n ],\n name: 'proxyCreationCode',\n outputs: [{ name: '', type: 'bytes' }],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n\n/**\n * Safe Singleton ABI\n */\nconst SAFE_ABI = [\n {\n inputs: [\n { name: 'owners', type: 'address[]' },\n { name: 'threshold', type: 'uint256' },\n { name: 'to', type: 'address' },\n { name: 'data', type: 'bytes' },\n { name: 'fallbackHandler', type: 'address' },\n { name: 'paymentToken', type: 'address' },\n { name: 'payment', type: 'uint256' },\n { name: 'paymentReceiver', type: 'address' },\n ],\n name: 'setup',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * Add Modules Lib ABI\n */\nconst ADD_MODULES_LIB_ABI = [\n {\n inputs: [{ name: 'modules', type: 'address[]' }],\n name: 'enableModules',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * Safe 4337 Module ABI\n */\nconst SAFE_4337_MODULE_ABI = [\n {\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'data', type: 'bytes' },\n { name: 'operation', type: 'uint8' },\n ],\n name: 'executeUserOp',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { name: 'tos', type: 'address[]' },\n { name: 'values', type: 'uint256[]' },\n { name: 'datas', type: 'bytes[]' },\n { name: 'operations', type: 'uint8[]' },\n ],\n name: 'executeUserOpBatch',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * WDK Smart Account\n *\n * Creates a Safe smart account using a WDK account as the owner/signer.\n * Implements SmartAccountSigner for ERC-4337 compatibility.\n */\nexport class WdkSmartAccount implements SmartAccountSigner {\n private readonly wdkAccount: WdkAccount\n private readonly publicClient: PublicClient\n private readonly _chainId: number\n private readonly owners: Address[]\n private readonly threshold: number\n private readonly saltNonce: bigint\n\n private cachedAddress?: Address\n private cachedInitCode?: Hex\n private cachedOwnerAddress?: Address\n private deploymentChecked = false\n private isAccountDeployed = false\n\n constructor(config: WdkSmartAccountConfig) {\n this.wdkAccount = config.wdkAccount\n this.publicClient = config.publicClient\n this._chainId = config.chainId\n this.threshold = config.threshold ?? 1\n this.saltNonce = config.saltNonce ?? 0n\n\n // Owners will be set when we get the WDK account address\n this.owners = config.additionalOwners ?? []\n }\n\n /**\n * Initialize the account (fetch WDK address)\n * Call this before using the account\n */\n async initialize(): Promise<void> {\n if (!this.cachedOwnerAddress) {\n const address = await this.wdkAccount.getAddress()\n this.cachedOwnerAddress = address as Address\n\n // Add WDK account as the first owner if not already in owners\n if (!this.owners.includes(this.cachedOwnerAddress)) {\n this.owners.unshift(this.cachedOwnerAddress)\n }\n }\n }\n\n /**\n * Get the WDK account's EOA address\n */\n async getOwnerAddress(): Promise<Address> {\n await this.initialize()\n return this.cachedOwnerAddress!\n }\n\n /**\n * Get the chain ID\n */\n getChainId(): number {\n return this._chainId\n }\n\n /**\n * Get the smart account address (counterfactual)\n */\n async getAddress(): Promise<Address> {\n await this.initialize()\n\n if (this.cachedAddress) {\n return this.cachedAddress\n }\n\n const initCode = await this.getInitCode()\n\n // If already deployed, get address from code\n if (initCode === '0x') {\n // Need to compute it anyway for first time\n const initializerData = await this.buildInitializer()\n const salt = keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'uint256' }],\n [keccak256(initializerData), this.saltNonce],\n ),\n )\n\n const proxyCreationCode = (await this.publicClient.readContract({\n address: SAFE_4337_ADDRESSES.proxyFactory,\n abi: PROXY_FACTORY_ABI,\n functionName: 'proxyCreationCode',\n args: [SAFE_4337_ADDRESSES.singleton, initializerData, this.saltNonce],\n })) as Hex\n\n this.cachedAddress = getContractAddress({\n bytecode: proxyCreationCode,\n from: SAFE_4337_ADDRESSES.proxyFactory,\n opcode: 'CREATE2',\n salt,\n })\n } else {\n // Extract initializer from init code\n const initializerData = `0x${initCode.slice(2 + 40 * 2)}` as Hex\n\n const salt = keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'uint256' }],\n [keccak256(initializerData), this.saltNonce],\n ),\n )\n\n const proxyCreationCode = (await this.publicClient.readContract({\n address: SAFE_4337_ADDRESSES.proxyFactory,\n abi: PROXY_FACTORY_ABI,\n functionName: 'proxyCreationCode',\n args: [SAFE_4337_ADDRESSES.singleton, initializerData, this.saltNonce],\n })) as Hex\n\n this.cachedAddress = getContractAddress({\n bytecode: proxyCreationCode,\n from: SAFE_4337_ADDRESSES.proxyFactory,\n opcode: 'CREATE2',\n salt,\n })\n }\n\n return this.cachedAddress\n }\n\n /**\n * Sign a UserOperation hash using the WDK account\n */\n async signUserOpHash(userOpHash: Hex): Promise<Hex> {\n await this.initialize()\n\n // Sign the hash using WDK account's signMessage\n // The hash is signed as raw bytes (personal_sign format)\n const signature = await this.wdkAccount.signMessage(userOpHash)\n\n // Format signature for Safe (add signature type byte)\n // Type 0: EOA signature\n return concat([signature as Hex, '0x00']) as Hex\n }\n\n /**\n * Get the account's init code for deployment\n */\n async getInitCode(): Promise<Hex> {\n await this.initialize()\n\n // Check if already deployed\n if (await this.isDeployed()) {\n return '0x' as Hex\n }\n\n if (this.cachedInitCode) {\n return this.cachedInitCode\n }\n\n const safeSetupData = await this.buildInitializer()\n\n // Build factory call data\n const createProxyData = encodeFunctionData({\n abi: PROXY_FACTORY_ABI,\n functionName: 'createProxyWithNonce',\n args: [SAFE_4337_ADDRESSES.singleton, safeSetupData, this.saltNonce],\n })\n\n // Init code = factory address + factory call data\n this.cachedInitCode = concat([SAFE_4337_ADDRESSES.proxyFactory, createProxyData]) as Hex\n\n return this.cachedInitCode\n }\n\n /**\n * Check if the account is deployed\n */\n async isDeployed(): Promise<boolean> {\n if (this.deploymentChecked) {\n return this.isAccountDeployed\n }\n\n // Set flag early to break infinite recursion:\n // getAddress() → getInitCode() → isDeployed() → getAddress() → ...\n // Default assumption (not deployed) is correct for init code computation.\n this.deploymentChecked = true\n\n await this.initialize()\n const address = this.cachedAddress ?? (await this.getAddress())\n const code = await this.publicClient.getCode({ address })\n\n this.isAccountDeployed = code !== undefined && code !== '0x'\n\n return this.isAccountDeployed\n }\n\n /**\n * Encode a call to the account's execute function\n */\n encodeExecute(target: Address, value: bigint, data: Hex): Hex {\n return encodeFunctionData({\n abi: SAFE_4337_MODULE_ABI,\n functionName: 'executeUserOp',\n args: [target, value, data, 0], // operation: CALL\n })\n }\n\n /**\n * Encode a batch call to the account's executeBatch function\n */\n encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex {\n if (targets.length !== values.length || targets.length !== datas.length) {\n throw new Error('Array lengths must match')\n }\n\n const operations = targets.map(() => 0) // All CALL operations\n\n return encodeFunctionData({\n abi: SAFE_4337_MODULE_ABI,\n functionName: 'executeUserOpBatch',\n args: [targets, values, datas, operations],\n })\n }\n\n /**\n * Build the Safe setup initializer data\n */\n private async buildInitializer(): Promise<Hex> {\n await this.initialize()\n\n // Build Safe setup data with 4337 module\n const setupModulesData = encodeFunctionData({\n abi: ADD_MODULES_LIB_ABI,\n functionName: 'enableModules',\n args: [[SAFE_4337_ADDRESSES.module]],\n })\n\n return encodeFunctionData({\n abi: SAFE_ABI,\n functionName: 'setup',\n args: [\n this.owners,\n BigInt(this.threshold),\n SAFE_4337_ADDRESSES.addModulesLib, // to: AddModulesLib\n setupModulesData, // data: enableModules([module])\n SAFE_4337_ADDRESSES.fallbackHandler,\n '0x0000000000000000000000000000000000000000' as Address, // paymentToken\n 0n, // payment\n '0x0000000000000000000000000000000000000000' as Address, // paymentReceiver\n ],\n })\n }\n\n /**\n * Get the Safe's owners\n */\n getOwners(): Address[] {\n return [...this.owners]\n }\n\n /**\n * Get the Safe's threshold\n */\n getThreshold(): number {\n return this.threshold\n }\n\n /**\n * Clear cached values (useful after deployment)\n */\n clearCache(): void {\n this.cachedAddress = undefined\n this.cachedInitCode = undefined\n this.deploymentChecked = false\n this.isAccountDeployed = false\n }\n}\n\n/**\n * Create a WDK smart account\n */\nexport async function createWdkSmartAccount(\n config: WdkSmartAccountConfig,\n): Promise<WdkSmartAccount> {\n const account = new WdkSmartAccount(config)\n await account.initialize()\n return account\n}\n","/**\n * WDK Gasless Constants\n *\n * Addresses and configuration for gasless USDT0 payments.\n */\n\nimport type { Address } from 'viem'\n\n/**\n * USDT0 OFT addresses by chain\n */\nexport const USDT0_ADDRESSES: Record<string, Address> = {\n ethereum: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n arbitrum: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',\n ink: '0x0200C29006150606B650577BBE7B6248F58470c1',\n berachain: '0x779Ded0c9e1022225f8E0630b35a9b54bE713736',\n unichain: '0x9151434b16b9763660705744891fA906F660EcC5',\n base: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n optimism: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n} as const\n\n/**\n * USDC addresses by chain\n */\nexport const USDC_ADDRESSES: Record<string, Address> = {\n ethereum: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n arbitrum: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',\n base: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n optimism: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',\n polygon: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n} as const\n\n/**\n * Chain IDs for supported networks\n */\nexport const CHAIN_IDS: Record<string, number> = {\n ethereum: 1,\n arbitrum: 42161,\n base: 8453,\n optimism: 10,\n polygon: 137,\n ink: 57073,\n berachain: 80094,\n unichain: 130,\n} as const\n\n/**\n * Default bundler URLs by chain (using public endpoints)\n */\nexport const DEFAULT_BUNDLER_URLS: Record<number, string> = {\n 1: 'https://api.pimlico.io/v2/ethereum/rpc',\n 42161: 'https://api.pimlico.io/v2/arbitrum/rpc',\n 8453: 'https://api.pimlico.io/v2/base/rpc',\n 10: 'https://api.pimlico.io/v2/optimism/rpc',\n 137: 'https://api.pimlico.io/v2/polygon/rpc',\n} as const\n\n/**\n * Get token address for a chain\n */\nexport function getTokenAddress(token: 'USDT0' | 'USDC' | Address, chainName: string): Address {\n if (token.startsWith('0x')) {\n return token as Address\n }\n\n const addresses = token === 'USDT0' ? USDT0_ADDRESSES : USDC_ADDRESSES\n const address = addresses[chainName.toLowerCase()]\n\n if (!address) {\n throw new Error(`Token ${token} not available on ${chainName}`)\n }\n\n return address\n}\n\n/**\n * Get chain name from chain ID\n */\nexport function getChainName(chainId: number): string {\n const entry = Object.entries(CHAIN_IDS).find(([, id]) => id === chainId)\n if (!entry) {\n throw new Error(`Unsupported chain ID: ${chainId}`)\n }\n return entry[0]\n}\n"],"mappings":";AAQA,SAAS,sBAAAA,qBAAoB,mBAAmB;AAChD,SAAS,eAAe,iBAAiB,eAAe,8BAA8B;;;ACDtF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQA,IAAM,sBAAsB;AAAA;AAAA,EAEjC,QAAQ;AAAA;AAAA,EAER,aAAa;AAAA;AAAA,EAEb,WAAW;AAAA;AAAA,EAEX,cAAc;AAAA;AAAA,EAEd,iBAAiB;AAAA;AAAA,EAEjB,eAAe;AACjB;AAKA,IAAM,oBAAoB;AAAA,EACxB;AAAA,IACE,QAAQ;AAAA,MACN,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,MACrC,EAAE,MAAM,eAAe,MAAM,QAAQ;AAAA,MACrC,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,IACvC;AAAA,IACA,MAAM;AAAA,IACN,SAAS,CAAC,EAAE,MAAM,SAAS,MAAM,UAAU,CAAC;AAAA,IAC5C,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,QAAQ;AAAA,MACN,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,MACrC,EAAE,MAAM,eAAe,MAAM,QAAQ;AAAA,MACrC,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,IACvC;AAAA,IACA,MAAM;AAAA,IACN,SAAS,CAAC,EAAE,MAAM,IAAI,MAAM,QAAQ,CAAC;AAAA,IACrC,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACR;AACF;AAKA,IAAM,WAAW;AAAA,EACf;AAAA,IACE,QAAQ;AAAA,MACN,EAAE,MAAM,UAAU,MAAM,YAAY;AAAA,MACpC,EAAE,MAAM,aAAa,MAAM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,IACrB,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,EACpB,CAAC;AAGD,SAAO,IAAI,iBAAiB;AAAA,IAC1B,QAAQ;AAAA,IACR,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,cAAc,OAAO;AAAA,EACvB,CAAC;AACH;","names":["encodeFunctionData","encodeFunctionData"]}
|
|
1
|
+
{"version":3,"sources":["../../src/client.ts","../../src/account.ts","../../src/adapter.ts","../../src/constants.ts"],"sourcesContent":["/**\n * WDK Gasless Client\n *\n * High-level client for executing gasless USDT0 payments using\n * Tether WDK accounts and ERC-4337 Account Abstraction.\n */\n\nimport type { Address, Hex, PublicClient } from 'viem'\nimport { encodeFunctionData, formatUnits } from 'viem'\nimport { BundlerClient, PaymasterClient, UserOpBuilder, ENTRYPOINT_V07_ADDRESS } from '@t402/evm'\nimport type {\n SmartAccountSigner,\n BundlerConfig,\n PaymasterConfig,\n TransactionIntent,\n GasEstimate,\n PaymasterData,\n} from '@t402/evm'\nimport type {\n WdkGaslessClientConfig,\n GaslessPaymentParams,\n BatchPaymentParams,\n GaslessPaymentResult,\n GaslessPaymentReceipt,\n SponsorshipInfo,\n WdkAccount,\n} from './types.js'\nimport { createSmartAccountSigner } from './adapter.js'\nimport { getTokenAddress, getChainName } from './constants.js'\n\n/**\n * ERC20 transfer ABI\n */\nconst ERC20_TRANSFER_ABI = [\n {\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'amount', type: 'uint256' },\n ],\n name: 'transfer',\n outputs: [{ name: '', type: 'bool' }],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * ERC20 balanceOf ABI\n */\nconst ERC20_BALANCE_ABI = [\n {\n inputs: [{ name: 'account', type: 'address' }],\n name: 'balanceOf',\n outputs: [{ name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n\n/**\n * WDK Gasless Client\n *\n * Provides a simple API for executing gasless USDT0 payments using\n * WDK accounts and ERC-4337 smart accounts.\n */\nexport class WdkGaslessClient {\n private readonly signer: SmartAccountSigner\n private readonly builder: UserOpBuilder\n private readonly bundler: BundlerClient\n private readonly paymaster?: PaymasterClient\n private readonly chainId: number\n private readonly publicClient: PublicClient\n private readonly chainName: string\n\n constructor(config: WdkGaslessClientConfig) {\n this.signer = config.signer\n this.builder = new UserOpBuilder()\n this.bundler = new BundlerClient(config.bundler)\n this.paymaster = config.paymaster ? new PaymasterClient(config.paymaster) : undefined\n this.chainId = config.chainId\n this.publicClient = config.publicClient\n this.chainName = getChainName(config.chainId)\n }\n\n /**\n * Execute a gasless payment\n *\n * Sends USDT0 (or other tokens) without the user paying gas fees.\n * Gas is sponsored by a paymaster if configured.\n */\n async pay(params: GaslessPaymentParams): Promise<GaslessPaymentResult> {\n // Validate payment params\n if (!params.to || params.to === '0x0000000000000000000000000000000000000000') {\n throw new Error('Recipient address must not be the zero address')\n }\n\n if (params.amount <= 0n) {\n throw new Error('Payment amount must be greater than zero')\n }\n\n const token = params.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n // Build the transfer call data\n const callData = encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [params.to, params.amount],\n })\n\n // Create the transaction intent\n const intent: TransactionIntent = {\n to: tokenAddress,\n value: 0n,\n data: callData,\n }\n\n // Estimate gas\n const gasEstimate = await this.estimateGas(intent)\n\n // Get paymaster data if configured\n const paymasterData = await this.getPaymasterData(gasEstimate)\n const sponsored = paymasterData !== undefined\n\n // Build the UserOperation\n const userOp = await this.builder.buildUserOp(\n this.signer,\n intent,\n this.publicClient,\n gasEstimate,\n paymasterData,\n )\n\n // Sign the UserOperation\n const signedUserOp = await this.builder.signUserOp(\n userOp,\n this.signer,\n this.publicClient,\n this.chainId,\n )\n\n // Submit to bundler\n const result = await this.bundler.sendUserOperation(signedUserOp)\n const sender = await this.signer.getAddress()\n\n return {\n userOpHash: result.userOpHash,\n sender,\n sponsored,\n wait: async (): Promise<GaslessPaymentReceipt> => {\n const receipt = await result.wait()\n return {\n userOpHash: receipt.userOpHash,\n txHash: receipt.receipt.transactionHash,\n blockNumber: receipt.receipt.blockNumber,\n success: receipt.success,\n gasUsed: receipt.actualGasUsed,\n gasCost: receipt.actualGasCost,\n reason: receipt.reason,\n }\n },\n }\n }\n\n /**\n * Execute multiple payments in a single transaction\n *\n * More gas efficient than individual payments.\n * All payments are executed atomically.\n */\n async payBatch(params: BatchPaymentParams): Promise<GaslessPaymentResult> {\n // Validate batch params\n if (!params.payments || params.payments.length === 0) {\n throw new Error('Batch payments must contain at least one payment')\n }\n\n if (params.payments.length > 50) {\n throw new Error('Batch payments must not exceed 50 payments')\n }\n\n for (const payment of params.payments) {\n if (!payment.to || payment.to === '0x0000000000000000000000000000000000000000') {\n throw new Error('Recipient address must not be the zero address')\n }\n if (payment.amount <= 0n) {\n throw new Error('Payment amount must be greater than zero')\n }\n }\n\n // Build transaction intents for all payments\n const intents: TransactionIntent[] = params.payments.map((payment) => {\n const token = payment.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n return {\n to: tokenAddress,\n value: 0n,\n data: encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [payment.to, payment.amount],\n }),\n }\n })\n\n // Estimate gas for batch\n const gasEstimate = await this.estimateBatchGas(intents)\n\n // Get paymaster data\n const paymasterData = await this.getPaymasterData(gasEstimate)\n const sponsored = paymasterData !== undefined\n\n // Build batch UserOperation\n const userOp = await this.builder.buildBatchUserOp(\n this.signer,\n intents,\n this.publicClient,\n gasEstimate,\n paymasterData,\n )\n\n // Sign and submit\n const signedUserOp = await this.builder.signUserOp(\n userOp,\n this.signer,\n this.publicClient,\n this.chainId,\n )\n\n const result = await this.bundler.sendUserOperation(signedUserOp)\n const sender = await this.signer.getAddress()\n\n return {\n userOpHash: result.userOpHash,\n sender,\n sponsored,\n wait: async (): Promise<GaslessPaymentReceipt> => {\n const receipt = await result.wait()\n return {\n userOpHash: receipt.userOpHash,\n txHash: receipt.receipt.transactionHash,\n blockNumber: receipt.receipt.blockNumber,\n success: receipt.success,\n gasUsed: receipt.actualGasUsed,\n gasCost: receipt.actualGasCost,\n reason: receipt.reason,\n }\n },\n }\n }\n\n /**\n * Check if a payment can be sponsored (free gas)\n */\n async canSponsor(params: GaslessPaymentParams): Promise<SponsorshipInfo> {\n if (!this.paymaster) {\n return {\n canSponsor: false,\n reason: 'No paymaster configured',\n }\n }\n\n const token = params.token ?? 'USDT0'\n const tokenAddress = getTokenAddress(token, this.chainName)\n\n const callData = encodeFunctionData({\n abi: ERC20_TRANSFER_ABI,\n functionName: 'transfer',\n args: [params.to, params.amount],\n })\n\n const sender = await this.signer.getAddress()\n const encodedCallData = this.signer.encodeExecute(tokenAddress, 0n, callData)\n\n try {\n const canSponsor = await this.paymaster.willSponsor(\n { sender, callData: encodedCallData },\n this.chainId,\n ENTRYPOINT_V07_ADDRESS,\n )\n\n if (canSponsor) {\n return { canSponsor: true }\n } else {\n // Estimate gas cost if not sponsored\n const intent: TransactionIntent = {\n to: tokenAddress,\n value: 0n,\n data: callData,\n }\n const gasEstimate = await this.estimateGas(intent)\n const gasPrice = await this.publicClient.getGasPrice()\n const estimatedGasCost =\n (gasEstimate.verificationGasLimit +\n gasEstimate.callGasLimit +\n gasEstimate.preVerificationGas) *\n gasPrice\n\n return {\n canSponsor: false,\n reason: 'Payment not eligible for sponsorship',\n estimatedGasCost,\n }\n }\n } catch (error) {\n return {\n canSponsor: false,\n reason: error instanceof Error ? error.message : 'Unknown error',\n }\n }\n }\n\n /**\n * Get the smart account address\n */\n async getAccountAddress(): Promise<Address> {\n return this.signer.getAddress()\n }\n\n /**\n * Check if the smart account is deployed\n */\n async isAccountDeployed(): Promise<boolean> {\n return this.signer.isDeployed()\n }\n\n /**\n * Get the token balance of the smart account\n */\n async getBalance(token: 'USDT0' | 'USDC' | Address = 'USDT0'): Promise<bigint> {\n const tokenAddress = getTokenAddress(token, this.chainName)\n const accountAddress = await this.signer.getAddress()\n\n const balance = await this.publicClient.readContract({\n address: tokenAddress,\n abi: ERC20_BALANCE_ABI,\n functionName: 'balanceOf',\n args: [accountAddress],\n })\n\n return balance as bigint\n }\n\n /**\n * Get the formatted token balance\n */\n async getFormattedBalance(\n token: 'USDT0' | 'USDC' | Address = 'USDT0',\n decimals = 6,\n ): Promise<string> {\n const balance = await this.getBalance(token)\n return formatUnits(balance, decimals)\n }\n\n /**\n * Estimate gas for a single transaction\n */\n private async estimateGas(intent: TransactionIntent): Promise<GasEstimate> {\n const sender = await this.signer.getAddress()\n const callData = this.signer.encodeExecute(intent.to, intent.value ?? 0n, intent.data ?? '0x')\n\n try {\n return await this.bundler.estimateUserOperationGas({\n sender,\n callData,\n })\n } catch {\n // Return defaults if estimation fails\n return {\n verificationGasLimit: 150000n,\n callGasLimit: 100000n,\n preVerificationGas: 50000n,\n }\n }\n }\n\n /**\n * Estimate gas for a batch transaction\n */\n private async estimateBatchGas(intents: TransactionIntent[]): Promise<GasEstimate> {\n const sender = await this.signer.getAddress()\n const callData = this.signer.encodeExecuteBatch(\n intents.map((i) => i.to),\n intents.map((i) => i.value ?? 0n),\n intents.map((i) => (i.data ?? '0x') as Hex),\n )\n\n try {\n return await this.bundler.estimateUserOperationGas({\n sender,\n callData,\n })\n } catch {\n // Return defaults with multiplier for batch size\n return {\n verificationGasLimit: 150000n,\n callGasLimit: 100000n * BigInt(intents.length),\n preVerificationGas: 50000n,\n }\n }\n }\n\n /**\n * Get paymaster data if configured\n */\n private async getPaymasterData(_gasEstimate: GasEstimate): Promise<PaymasterData | undefined> {\n if (!this.paymaster) return undefined\n\n const sender = await this.signer.getAddress()\n\n return this.paymaster.getPaymasterData({ sender }, this.chainId, ENTRYPOINT_V07_ADDRESS)\n }\n}\n\n/**\n * Configuration for creating a WDK gasless client\n */\nexport interface CreateWdkGaslessClientConfig {\n /** WDK account to use as the signer */\n wdkAccount: WdkAccount\n /** Public client for chain interactions */\n publicClient: PublicClient\n /** Chain ID */\n chainId: number\n /** Bundler configuration */\n bundler: BundlerConfig\n /** Optional paymaster for gas sponsorship */\n paymaster?: PaymasterConfig\n /** Salt nonce for address generation (defaults to 0) */\n saltNonce?: bigint\n /**\n * Optional pre-created upstream ERC-4337 wallet instance\n * (from @tetherto/wdk-wallet-evm-erc-4337).\n * When provided, this is used instead of the custom Safe-based smart account.\n */\n upstreamWallet?: unknown\n}\n\n/**\n * Create a WDK gasless client\n *\n * This is the main entry point for using WDK with gasless payments.\n *\n * @example\n * ```typescript\n * import { createWdkGaslessClient } from '@t402/wdk-gasless';\n *\n * const client = await createWdkGaslessClient({\n * wdkAccount: myWdkAccount,\n * publicClient,\n * chainId: 42161, // Arbitrum\n * bundler: {\n * bundlerUrl: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * chainId: 42161,\n * },\n * paymaster: {\n * address: '0x...',\n * url: 'https://api.pimlico.io/v2/arbitrum/rpc?apikey=...',\n * type: 'sponsoring',\n * },\n * });\n *\n * // Execute gasless payment\n * const result = await client.pay({\n * to: '0x...',\n * amount: 1000000n, // 1 USDT0\n * });\n *\n * const receipt = await result.wait();\n * console.log('Payment confirmed:', receipt.txHash);\n * ```\n */\nexport async function createWdkGaslessClient(\n config: CreateWdkGaslessClientConfig,\n): Promise<WdkGaslessClient> {\n // Create the smart account signer.\n // Uses upstream @tetherto/wdk-wallet-evm-erc-4337 when available,\n // falls back to custom Safe-based WdkSmartAccount.\n const smartAccount = await createSmartAccountSigner(\n {\n wdkAccount: config.wdkAccount,\n publicClient: config.publicClient,\n chainId: config.chainId,\n saltNonce: config.saltNonce,\n },\n config.upstreamWallet,\n )\n\n // Create the gasless client\n return new WdkGaslessClient({\n signer: smartAccount,\n bundler: config.bundler,\n paymaster: config.paymaster,\n chainId: config.chainId,\n publicClient: config.publicClient,\n })\n}\n","/**\n * WDK Smart Account\n *\n * Wraps a Tether WDK account to work with ERC-4337 smart accounts.\n * Creates a Safe smart account with the WDK account as the owner/signer.\n */\n\nimport type { Address, Hex, PublicClient } from 'viem'\nimport {\n encodeFunctionData,\n encodeAbiParameters,\n concat,\n keccak256,\n getContractAddress,\n} from 'viem'\nimport type { SmartAccountSigner } from '@t402/evm'\nimport type { WdkAccount, WdkSmartAccountConfig } from './types.js'\n\n/**\n * Safe 4337 module addresses (v0.3.0)\n * Deployed on all major EVM chains at the same addresses\n */\nexport const SAFE_4337_ADDRESSES = {\n /** Safe 4337 Module */\n module: '0xa581c4A4DB7175302464fF3C06380BC3270b4037' as Address,\n /** Safe Module Setup */\n moduleSetup: '0x2dd68b007B46fBe91B9A7c3EDa5A7a1063cB5b47' as Address,\n /** Safe Singleton */\n singleton: '0x29fcB43b46531BcA003ddC8FCB67FFE91900C762' as Address,\n /** Safe Proxy Factory */\n proxyFactory: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67' as Address,\n /** Safe Fallback Handler */\n fallbackHandler: '0xfd0732Dc9E303f09fCEf3a7388Ad10A83459Ec99' as Address,\n /** Add Modules Lib */\n addModulesLib: '0x8EcD4ec46D4D2a6B64fE960B3D64e8B94B2234eb' as Address,\n} as const\n\n/**\n * Safe Proxy Factory ABI\n */\nconst PROXY_FACTORY_ABI = [\n {\n inputs: [\n { name: 'singleton', type: 'address' },\n { name: 'initializer', type: 'bytes' },\n { name: 'saltNonce', type: 'uint256' },\n ],\n name: 'createProxyWithNonce',\n outputs: [{ name: 'proxy', type: 'address' }],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { name: 'singleton', type: 'address' },\n { name: 'initializer', type: 'bytes' },\n { name: 'saltNonce', type: 'uint256' },\n ],\n name: 'proxyCreationCode',\n outputs: [{ name: '', type: 'bytes' }],\n stateMutability: 'view',\n type: 'function',\n },\n] as const\n\n/**\n * Safe Singleton ABI\n */\nconst SAFE_ABI = [\n {\n inputs: [\n { name: 'owners', type: 'address[]' },\n { name: 'threshold', type: 'uint256' },\n { name: 'to', type: 'address' },\n { name: 'data', type: 'bytes' },\n { name: 'fallbackHandler', type: 'address' },\n { name: 'paymentToken', type: 'address' },\n { name: 'payment', type: 'uint256' },\n { name: 'paymentReceiver', type: 'address' },\n ],\n name: 'setup',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * Add Modules Lib ABI\n */\nconst ADD_MODULES_LIB_ABI = [\n {\n inputs: [{ name: 'modules', type: 'address[]' }],\n name: 'enableModules',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * Safe 4337 Module ABI\n */\nconst SAFE_4337_MODULE_ABI = [\n {\n inputs: [\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'data', type: 'bytes' },\n { name: 'operation', type: 'uint8' },\n ],\n name: 'executeUserOp',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { name: 'tos', type: 'address[]' },\n { name: 'values', type: 'uint256[]' },\n { name: 'datas', type: 'bytes[]' },\n { name: 'operations', type: 'uint8[]' },\n ],\n name: 'executeUserOpBatch',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n] as const\n\n/**\n * WDK Smart Account\n *\n * Creates a Safe smart account using a WDK account as the owner/signer.\n * Implements SmartAccountSigner for ERC-4337 compatibility.\n */\nexport class WdkSmartAccount implements SmartAccountSigner {\n private readonly wdkAccount: WdkAccount\n private readonly publicClient: PublicClient\n private readonly _chainId: number\n private readonly owners: Address[]\n private readonly threshold: number\n private readonly saltNonce: bigint\n\n private cachedAddress?: Address\n private cachedInitCode?: Hex\n private cachedOwnerAddress?: Address\n private deploymentChecked = false\n private isAccountDeployed = false\n\n constructor(config: WdkSmartAccountConfig) {\n this.wdkAccount = config.wdkAccount\n this.publicClient = config.publicClient\n this._chainId = config.chainId\n this.threshold = config.threshold ?? 1\n this.saltNonce = config.saltNonce ?? 0n\n\n // Owners will be set when we get the WDK account address\n this.owners = config.additionalOwners ?? []\n }\n\n /**\n * Initialize the account (fetch WDK address)\n * Call this before using the account\n */\n async initialize(): Promise<void> {\n if (!this.cachedOwnerAddress) {\n const address = await this.wdkAccount.getAddress()\n this.cachedOwnerAddress = address as Address\n\n // Add WDK account as the first owner if not already in owners\n if (!this.owners.includes(this.cachedOwnerAddress)) {\n this.owners.unshift(this.cachedOwnerAddress)\n }\n }\n }\n\n /**\n * Get the WDK account's EOA address\n */\n async getOwnerAddress(): Promise<Address> {\n await this.initialize()\n return this.cachedOwnerAddress!\n }\n\n /**\n * Get the chain ID\n */\n getChainId(): number {\n return this._chainId\n }\n\n /**\n * Get the smart account address (counterfactual)\n */\n async getAddress(): Promise<Address> {\n await this.initialize()\n\n if (this.cachedAddress) {\n return this.cachedAddress\n }\n\n const initCode = await this.getInitCode()\n\n // If already deployed, get address from code\n if (initCode === '0x') {\n // Need to compute it anyway for first time\n const initializerData = await this.buildInitializer()\n const salt = keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'uint256' }],\n [keccak256(initializerData), this.saltNonce],\n ),\n )\n\n const proxyCreationCode = (await this.publicClient.readContract({\n address: SAFE_4337_ADDRESSES.proxyFactory,\n abi: PROXY_FACTORY_ABI,\n functionName: 'proxyCreationCode',\n args: [SAFE_4337_ADDRESSES.singleton, initializerData, this.saltNonce],\n })) as Hex\n\n this.cachedAddress = getContractAddress({\n bytecode: proxyCreationCode,\n from: SAFE_4337_ADDRESSES.proxyFactory,\n opcode: 'CREATE2',\n salt,\n })\n } else {\n // Extract initializer from init code\n const initializerData = `0x${initCode.slice(2 + 40 * 2)}` as Hex\n\n const salt = keccak256(\n encodeAbiParameters(\n [{ type: 'bytes32' }, { type: 'uint256' }],\n [keccak256(initializerData), this.saltNonce],\n ),\n )\n\n const proxyCreationCode = (await this.publicClient.readContract({\n address: SAFE_4337_ADDRESSES.proxyFactory,\n abi: PROXY_FACTORY_ABI,\n functionName: 'proxyCreationCode',\n args: [SAFE_4337_ADDRESSES.singleton, initializerData, this.saltNonce],\n })) as Hex\n\n this.cachedAddress = getContractAddress({\n bytecode: proxyCreationCode,\n from: SAFE_4337_ADDRESSES.proxyFactory,\n opcode: 'CREATE2',\n salt,\n })\n }\n\n return this.cachedAddress\n }\n\n /**\n * Sign a UserOperation hash using the WDK account\n */\n async signUserOpHash(userOpHash: Hex): Promise<Hex> {\n await this.initialize()\n\n // Sign the hash using WDK account's signMessage\n // The hash is signed as raw bytes (personal_sign format)\n const signature = await this.wdkAccount.signMessage(userOpHash)\n\n // Format signature for Safe (add signature type byte)\n // Type 0: EOA signature\n return concat([signature as Hex, '0x00']) as Hex\n }\n\n /**\n * Get the account's init code for deployment\n */\n async getInitCode(): Promise<Hex> {\n await this.initialize()\n\n // Check if already deployed\n if (await this.isDeployed()) {\n return '0x' as Hex\n }\n\n if (this.cachedInitCode) {\n return this.cachedInitCode\n }\n\n const safeSetupData = await this.buildInitializer()\n\n // Build factory call data\n const createProxyData = encodeFunctionData({\n abi: PROXY_FACTORY_ABI,\n functionName: 'createProxyWithNonce',\n args: [SAFE_4337_ADDRESSES.singleton, safeSetupData, this.saltNonce],\n })\n\n // Init code = factory address + factory call data\n this.cachedInitCode = concat([SAFE_4337_ADDRESSES.proxyFactory, createProxyData]) as Hex\n\n return this.cachedInitCode\n }\n\n /**\n * Check if the account is deployed\n */\n async isDeployed(): Promise<boolean> {\n if (this.deploymentChecked) {\n return this.isAccountDeployed\n }\n\n // Set flag early to break infinite recursion:\n // getAddress() → getInitCode() → isDeployed() → getAddress() → ...\n // Default assumption (not deployed) is correct for init code computation.\n this.deploymentChecked = true\n\n await this.initialize()\n const address = this.cachedAddress ?? (await this.getAddress())\n const code = await this.publicClient.getCode({ address })\n\n this.isAccountDeployed = code !== undefined && code !== '0x'\n\n return this.isAccountDeployed\n }\n\n /**\n * Encode a call to the account's execute function\n */\n encodeExecute(target: Address, value: bigint, data: Hex): Hex {\n return encodeFunctionData({\n abi: SAFE_4337_MODULE_ABI,\n functionName: 'executeUserOp',\n args: [target, value, data, 0], // operation: CALL\n })\n }\n\n /**\n * Encode a batch call to the account's executeBatch function\n */\n encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex {\n if (targets.length !== values.length || targets.length !== datas.length) {\n throw new Error('Array lengths must match')\n }\n\n const operations = targets.map(() => 0) // All CALL operations\n\n return encodeFunctionData({\n abi: SAFE_4337_MODULE_ABI,\n functionName: 'executeUserOpBatch',\n args: [targets, values, datas, operations],\n })\n }\n\n /**\n * Build the Safe setup initializer data\n */\n private async buildInitializer(): Promise<Hex> {\n await this.initialize()\n\n // Build Safe setup data with 4337 module\n const setupModulesData = encodeFunctionData({\n abi: ADD_MODULES_LIB_ABI,\n functionName: 'enableModules',\n args: [[SAFE_4337_ADDRESSES.module]],\n })\n\n return encodeFunctionData({\n abi: SAFE_ABI,\n functionName: 'setup',\n args: [\n this.owners,\n BigInt(this.threshold),\n SAFE_4337_ADDRESSES.addModulesLib, // to: AddModulesLib\n setupModulesData, // data: enableModules([module])\n SAFE_4337_ADDRESSES.fallbackHandler,\n '0x0000000000000000000000000000000000000000' as Address, // paymentToken\n 0n, // payment\n '0x0000000000000000000000000000000000000000' as Address, // paymentReceiver\n ],\n })\n }\n\n /**\n * Get the Safe's owners\n */\n getOwners(): Address[] {\n return [...this.owners]\n }\n\n /**\n * Get the Safe's threshold\n */\n getThreshold(): number {\n return this.threshold\n }\n\n /**\n * Clear cached values (useful after deployment)\n */\n clearCache(): void {\n this.cachedAddress = undefined\n this.cachedInitCode = undefined\n this.deploymentChecked = false\n this.isAccountDeployed = false\n }\n}\n\n/**\n * Create a WDK smart account\n */\nexport async function createWdkSmartAccount(\n config: WdkSmartAccountConfig,\n): Promise<WdkSmartAccount> {\n const account = new WdkSmartAccount(config)\n await account.initialize()\n return account\n}\n","/**\n * WDK EVM Gasless Adapter\n *\n * Detection and delegation layer for @tetherto/wdk-wallet-evm-erc-4337.\n * When the upstream module is available, its smart account implementation\n * is used. Otherwise, the custom Safe-based WdkSmartAccount is used as fallback.\n */\n\nimport type { Address, Hex } from 'viem'\nimport type { SmartAccountSigner } from '@t402/evm'\nimport type { WdkSmartAccountConfig } from './types.js'\nimport { createWdkSmartAccount } from './account.js'\n\n/**\n * Upstream ERC-4337 wallet interface (from @tetherto/wdk-wallet-evm-erc-4337)\n *\n * The upstream module provides a smart account that implements these methods.\n * We detect it by checking for characteristic method signatures.\n */\nexport interface UpstreamErc4337Wallet {\n getAddress(): Promise<Address>\n signUserOpHash(hash: Hex): Promise<Hex>\n getInitCode(): Promise<Hex>\n isDeployed(): Promise<boolean>\n encodeExecute(target: Address, value: bigint, data: Hex): Hex\n encodeExecuteBatch(targets: Address[], values: bigint[], datas: Hex[]): Hex\n}\n\n/**\n * Check if an object looks like an upstream ERC-4337 smart account signer\n */\nexport function isUpstreamErc4337Wallet(instance: unknown): instance is UpstreamErc4337Wallet {\n if (typeof instance !== 'object' || instance === null) return false\n const obj = instance as Record<string, unknown>\n return (\n typeof obj.getAddress === 'function' &&\n typeof obj.signUserOpHash === 'function' &&\n typeof obj.getInitCode === 'function' &&\n typeof obj.isDeployed === 'function' &&\n typeof obj.encodeExecute === 'function' &&\n typeof obj.encodeExecuteBatch === 'function'\n )\n}\n\n/**\n * Create a SmartAccountSigner, preferring the upstream @tetherto/wdk-wallet-evm-erc-4337\n * module when available, falling back to the custom WdkSmartAccount.\n *\n * Resolution order:\n * 1. If `upstreamWallet` is provided and satisfies SmartAccountSigner, use it directly\n * 2. If `upstreamModule` is provided (the module constructor), create an instance\n * 3. Fall back to custom WdkSmartAccount (Safe-based ERC-4337)\n *\n * @param config - Smart account configuration\n * @param upstreamWallet - Optional pre-created upstream wallet instance\n */\nexport async function createSmartAccountSigner(\n config: WdkSmartAccountConfig,\n upstreamWallet?: unknown,\n): Promise<SmartAccountSigner> {\n // Case 1: Pre-created upstream wallet that satisfies the signer interface\n if (upstreamWallet && isUpstreamErc4337Wallet(upstreamWallet)) {\n return upstreamWallet as SmartAccountSigner\n }\n\n // Case 2: Try to dynamically load the upstream module\n const upstreamModule = await tryLoadUpstreamModule()\n if (upstreamModule) {\n try {\n const wallet = await createFromUpstream(upstreamModule, config)\n if (wallet && isUpstreamErc4337Wallet(wallet)) {\n return wallet as SmartAccountSigner\n }\n } catch {\n // Fall through to custom implementation\n }\n }\n\n // Case 3: Fall back to custom Safe-based WdkSmartAccount\n return createWdkSmartAccount(config)\n}\n\n/**\n * Try to create a smart account from the upstream module.\n * The upstream module is expected to export a factory function.\n */\nasync function createFromUpstream(\n upstreamModule: unknown,\n config: WdkSmartAccountConfig,\n): Promise<unknown> {\n if (typeof upstreamModule !== 'object' || upstreamModule === null) {\n return undefined\n }\n\n const mod = upstreamModule as Record<string, unknown>\n\n // Try common factory function names from the upstream module\n const factoryNames = ['createSmartAccount', 'createErc4337Wallet', 'create', 'default']\n for (const name of factoryNames) {\n if (typeof mod[name] === 'function') {\n const factory = mod[name] as (config: Record<string, unknown>) => Promise<unknown>\n return factory({\n account: config.wdkAccount,\n publicClient: config.publicClient,\n chainId: config.chainId,\n saltNonce: config.saltNonce,\n })\n }\n }\n\n return undefined\n}\n\n/**\n * Try to dynamically import the upstream @tetherto/wdk-wallet-evm-erc-4337 module.\n * Returns the module if available, or undefined if not installed.\n *\n * Uses a string variable for the module specifier to avoid TypeScript\n * emitting type declarations for the optional dependency.\n */\nexport async function tryLoadUpstreamModule(): Promise<unknown | undefined> {\n try {\n // Use a variable to prevent TypeScript from resolving the module at compile time\n const moduleName = '@tetherto/wdk-wallet-evm-erc-4337'\n const mod = await (Function('m', 'return import(m)') as (m: string) => Promise<unknown>)(\n moduleName,\n )\n const resolved = mod as Record<string, unknown>\n return resolved.default ?? resolved\n } catch {\n return undefined\n }\n}\n","/**\n * WDK Gasless Constants\n *\n * Addresses and configuration for gasless USDT0 payments.\n */\n\nimport type { Address } from 'viem'\n\n/**\n * USDT0 OFT addresses by chain\n */\nexport const USDT0_ADDRESSES: Record<string, Address> = {\n ethereum: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n arbitrum: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',\n ink: '0x0200C29006150606B650577BBE7B6248F58470c1',\n berachain: '0x779Ded0c9e1022225f8E0630b35a9b54bE713736',\n unichain: '0x9151434b16b9763660705744891fA906F660EcC5',\n base: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n optimism: '0x6C96dE32CEa08842dcc4058c14d3aaAD7Fa41dee',\n} as const\n\n/**\n * USDC addresses by chain\n */\nexport const USDC_ADDRESSES: Record<string, Address> = {\n ethereum: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n arbitrum: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',\n base: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n optimism: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',\n polygon: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n} as const\n\n/**\n * Chain IDs for supported networks\n */\nexport const CHAIN_IDS: Record<string, number> = {\n ethereum: 1,\n arbitrum: 42161,\n base: 8453,\n optimism: 10,\n polygon: 137,\n ink: 57073,\n berachain: 80094,\n unichain: 130,\n} as const\n\n/**\n * Default bundler URLs by chain (using public endpoints)\n */\nexport const DEFAULT_BUNDLER_URLS: Record<number, string> = {\n 1: 'https://api.pimlico.io/v2/ethereum/rpc',\n 42161: 'https://api.pimlico.io/v2/arbitrum/rpc',\n 8453: 'https://api.pimlico.io/v2/base/rpc',\n 10: 'https://api.pimlico.io/v2/optimism/rpc',\n 137: 'https://api.pimlico.io/v2/polygon/rpc',\n} as const\n\n/**\n * Get token address for a chain\n */\nexport function getTokenAddress(token: 'USDT0' | 'USDC' | Address, chainName: string): Address {\n if (token.startsWith('0x')) {\n return token as Address\n }\n\n const addresses = token === 'USDT0' ? USDT0_ADDRESSES : USDC_ADDRESSES\n const address = addresses[chainName.toLowerCase()]\n\n if (!address) {\n throw new Error(`Token ${token} not available on ${chainName}`)\n }\n\n return address\n}\n\n/**\n * Get chain name from chain ID\n */\nexport function getChainName(chainId: number): string {\n const entry = Object.entries(CHAIN_IDS).find(([, id]) => id === chainId)\n if (!entry) {\n throw new Error(`Unsupported chain ID: ${chainId}`)\n }\n return entry[0]\n}\n"],"mappings":";AAQA,SAAS,sBAAAA,qBAAoB,mBAAmB;AAChD,SAAS,eAAe,iBAAiB,eAAe,8BAA8B;;;ACDtF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQA,IAAM,sBAAsB;AAAA;AAAA,EAEjC,QAAQ;AAAA;AAAA,EAER,aAAa;AAAA;AAAA,EAEb,WAAW;AAAA;AAAA,EAEX,cAAc;AAAA;AAAA,EAEd,iBAAiB;AAAA;AAAA,EAEjB,eAAe;AACjB;AAKA,IAAM,oBAAoB;AAAA,EACxB;AAAA,IACE,QAAQ;AAAA,MACN,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,MACrC,EAAE,MAAM,eAAe,MAAM,QAAQ;AAAA,MACrC,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,IACvC;AAAA,IACA,MAAM;AAAA,IACN,SAAS,CAAC,EAAE,MAAM,SAAS,MAAM,UAAU,CAAC;AAAA,IAC5C,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,QAAQ;AAAA,MACN,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,MACrC,EAAE,MAAM,eAAe,MAAM,QAAQ;AAAA,MACrC,EAAE,MAAM,aAAa,MAAM,UAAU;AAAA,IACvC;AAAA,IACA,MAAM;AAAA,IACN,SAAS,CAAC,EAAE,MAAM,IAAI,MAAM,QAAQ,CAAC;AAAA,IACrC,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACR;AACF;AAKA,IAAM,WAAW;AAAA,EACf;AAAA,IACE,QAAQ;AAAA,MACN,EAAE,MAAM,UAAU,MAAM,YAAY;AAAA,MACpC,EAAE,MAA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AAA,MACE,YAAY,OAAO;AAAA,MACnB,cAAc,OAAO;AAAA,MACrB,SAAS,OAAO;AAAA,MAChB,WAAW,OAAO;AAAA,IACpB;AAAA,IACA,OAAO;AAAA,EACT;AAGA,SAAO,IAAI,iBAAiB;AAAA,IAC1B,QAAQ;AAAA,IACR,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,cAAc,OAAO;AAAA,EACvB,CAAC;AACH;","names":["encodeFunctionData","encodeFunctionData"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t402/wdk-gasless",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/cjs/index.d.ts",
|
|
@@ -18,35 +18,40 @@
|
|
|
18
18
|
],
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
20
|
"author": "T402 Team",
|
|
21
|
-
"repository":
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/t402-io/t402.git",
|
|
24
|
+
"directory": "sdks/typescript/packages/wdk-gasless"
|
|
25
|
+
},
|
|
22
26
|
"description": "Gasless USDT0 payments with Tether WDK and ERC-4337 Account Abstraction",
|
|
23
27
|
"devDependencies": {
|
|
24
|
-
"@eslint/js": "^9.
|
|
25
|
-
"@types/node": "^25.2.
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
27
|
-
"@typescript-eslint/parser": "^8.
|
|
28
|
+
"@eslint/js": "^9.39.2",
|
|
29
|
+
"@types/node": "^25.2.3",
|
|
30
|
+
"@typescript-eslint/eslint-plugin": "^8.56.0",
|
|
31
|
+
"@typescript-eslint/parser": "^8.56.0",
|
|
28
32
|
"eslint": "^9.24.0",
|
|
29
33
|
"eslint-plugin-import": "^2.31.0",
|
|
30
|
-
"eslint-plugin-jsdoc": "^62.
|
|
31
|
-
"eslint-plugin-prettier": "^5.
|
|
32
|
-
"glob": "^13.0.
|
|
33
|
-
"prettier": "3.
|
|
34
|
-
"tsup": "^8.
|
|
34
|
+
"eslint-plugin-jsdoc": "^62.6.0",
|
|
35
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
36
|
+
"glob": "^13.0.5",
|
|
37
|
+
"prettier": "3.8.1",
|
|
38
|
+
"tsup": "^8.5.1",
|
|
35
39
|
"tsx": "^4.21.0",
|
|
36
|
-
"typescript": "^5.
|
|
40
|
+
"typescript": "^5.9.3",
|
|
37
41
|
"vite": "^7.3.1",
|
|
38
|
-
"vite-tsconfig-paths": "^
|
|
42
|
+
"vite-tsconfig-paths": "^6.1.1",
|
|
39
43
|
"vitest": "^3.2.4"
|
|
40
44
|
},
|
|
41
45
|
"dependencies": {
|
|
42
|
-
"@t402/core": "2.
|
|
43
|
-
"@t402/
|
|
44
|
-
"@t402/
|
|
46
|
+
"@t402/core": "2.6.0",
|
|
47
|
+
"@t402/evm": "2.6.0",
|
|
48
|
+
"@t402/wdk": "2.6.0"
|
|
45
49
|
},
|
|
46
50
|
"peerDependencies": {
|
|
47
51
|
"viem": "^2.0.0",
|
|
48
52
|
"@tetherto/wdk": ">=1.0.0-beta.0",
|
|
49
|
-
"@tetherto/wdk-wallet-evm": ">=1.0.0-beta.0"
|
|
53
|
+
"@tetherto/wdk-wallet-evm": ">=1.0.0-beta.0",
|
|
54
|
+
"@tetherto/wdk-wallet-evm-erc-4337": ">=1.0.0-beta.0"
|
|
50
55
|
},
|
|
51
56
|
"peerDependenciesMeta": {
|
|
52
57
|
"@tetherto/wdk": {
|
|
@@ -54,6 +59,9 @@
|
|
|
54
59
|
},
|
|
55
60
|
"@tetherto/wdk-wallet-evm": {
|
|
56
61
|
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"@tetherto/wdk-wallet-evm-erc-4337": {
|
|
64
|
+
"optional": true
|
|
57
65
|
}
|
|
58
66
|
},
|
|
59
67
|
"exports": {
|
|
@@ -71,6 +79,10 @@
|
|
|
71
79
|
"files": [
|
|
72
80
|
"dist"
|
|
73
81
|
],
|
|
82
|
+
"homepage": "https://t402.io",
|
|
83
|
+
"publishConfig": {
|
|
84
|
+
"access": "public"
|
|
85
|
+
},
|
|
74
86
|
"scripts": {
|
|
75
87
|
"build": "tsup",
|
|
76
88
|
"test": "vitest run --pool=forks",
|