@dynamic-labs-sdk/zerodev 0.8.0 → 0.9.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/BatchCall.types.d.ts +19 -0
- package/dist/BatchCall.types.d.ts.map +1 -0
- package/dist/canSponsorUserOperation/canSponsorUserOperation.d.ts +27 -0
- package/dist/canSponsorUserOperation/canSponsorUserOperation.d.ts.map +1 -0
- package/dist/canSponsorUserOperation/index.d.ts +3 -0
- package/dist/canSponsorUserOperation/index.d.ts.map +1 -0
- package/dist/core.cjs.js +1 -1
- package/dist/core.esm.js +1 -1
- package/dist/estimateUserOperationGas/estimateUserOperationGas.d.ts +16 -0
- package/dist/estimateUserOperationGas/estimateUserOperationGas.d.ts.map +1 -0
- package/dist/estimateUserOperationGas/index.d.ts +3 -0
- package/dist/estimateUserOperationGas/index.d.ts.map +1 -0
- package/dist/exports/index.d.ts +7 -2
- package/dist/exports/index.d.ts.map +1 -1
- package/dist/{getZerodevRpc-DEYl7xdY.cjs.js → getZerodevRpc-BaEt21uP.cjs.js} +2 -2
- package/dist/{getZerodevRpc-DEYl7xdY.cjs.js.map → getZerodevRpc-BaEt21uP.cjs.js.map} +1 -1
- package/dist/{getZerodevRpc-yychTISi.esm.js → getZerodevRpc-Buy6FN1e.esm.js} +2 -2
- package/dist/{getZerodevRpc-yychTISi.esm.js.map → getZerodevRpc-Buy6FN1e.esm.js.map} +1 -1
- package/dist/index.cjs.js +72 -29
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +70 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/sendUserOperation/index.d.ts +3 -0
- package/dist/sendUserOperation/index.d.ts.map +1 -0
- package/dist/sendUserOperation/sendUserOperation.d.ts +31 -0
- package/dist/sendUserOperation/sendUserOperation.d.ts.map +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/utils/prepareUserOperationFromCalls/index.d.ts +3 -0
- package/dist/utils/prepareUserOperationFromCalls/index.d.ts.map +1 -0
- package/dist/utils/{prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.d.ts → prepareUserOperationFromCalls/prepareUserOperationFromCalls.d.ts} +40 -37
- package/dist/utils/prepareUserOperationFromCalls/prepareUserOperationFromCalls.d.ts.map +1 -0
- package/package.json +4 -4
- package/dist/canSponsorTransaction/canSponsorTransaction.d.ts +0 -29
- package/dist/canSponsorTransaction/canSponsorTransaction.d.ts.map +0 -1
- package/dist/canSponsorTransaction/index.d.ts +0 -2
- package/dist/canSponsorTransaction/index.d.ts.map +0 -1
- package/dist/estimateTransactionGas/estimateTransactionGas.d.ts +0 -18
- package/dist/estimateTransactionGas/estimateTransactionGas.d.ts.map +0 -1
- package/dist/estimateTransactionGas/index.d.ts +0 -2
- package/dist/estimateTransactionGas/index.d.ts.map +0 -1
- package/dist/utils/prepareUserOperationWithKernelClient/index.d.ts +0 -2
- package/dist/utils/prepareUserOperationWithKernelClient/index.d.ts.map +0 -1
- package/dist/utils/prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.d.ts.map +0 -1
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","names":["WalletProviderEnum","ZERODEV_METADATA","networkData: NetworkData | undefined","getZerodevRpc","createKernelAccount","getPaymasterConfig","shouldUseEIP7702","chain: Chain","WalletProviderEnum","ZERODEV_METADATA","signMessage","InvalidParamError","signMessageUtils","getZerodevChainProviderForNetworkId","UnrecognizedNetworkError","WalletProviderPriority","getSignerForSmartWalletAccount","networkData: NetworkData | undefined","constants","name","version"],"sources":["../src/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.ts","../src/createKernelClientForWalletAccount/createKernelClientForWalletAccount.ts","../src/utils/shouldSignWithEoa/shouldSignWithEoa.ts","../src/utils/signMessage/signMessage.ts","../src/utils/createZerodevWalletProvider/createZerodevWalletProvider.ts","../src/addZerodevExtension/addZerodevExtension.ts","../src/utils/prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.ts","../src/canSponsorTransaction/canSponsorTransaction.ts","../src/utils/calculateGasForUserOperation/calculateGasForUserOperation.ts","../src/estimateTransactionGas/estimateTransactionGas.ts","../src/isGasSponsorshipError/isGasSponsorshipError.ts","../src/signEip7702Authorization/signEip7702Authorization.ts","../src/exports/index.ts"],"sourcesContent":["import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getChainFromVerifiedCredentialChain } from '@dynamic-labs-sdk/client/core';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\n\nexport const getAllUserZerodevAddresses = (client: DynamicClient): string[] => {\n const zerodevWalletCredentials =\n client.user?.verifiedCredentials.filter(\n (credential) =>\n credential.walletProvider === WalletProviderEnum.SmartContractWallet &&\n credential.walletName\n ?.toLowerCase()\n .startsWith(ZERODEV_METADATA.normalizedWalletName) &&\n credential.address &&\n credential.chain &&\n getChainFromVerifiedCredentialChain(credential.chain) === 'EVM'\n ) ?? [];\n\n const zerodevAddresses: string[] = zerodevWalletCredentials.map(\n // casting because we're already filtering out credentials without an address\n (credential) => credential.address as string\n );\n\n return zerodevAddresses;\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport type { ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';\nimport {\n createKernelAccountClient,\n getUserOperationGasPrice,\n} from '@zerodev/sdk';\nimport type { Hex } from 'viem';\nimport { createPublicClient, http } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { KernelClient } from '../KernelClient.types';\nimport { createKernelAccount } from '../utils/createKernelAccount';\nimport { getPaymasterConfig } from '../utils/getPaymasterConfig';\nimport { getZerodevRpc } from '../utils/getZerodevRpc';\n\nexport type Eip7702Authorization = SignAuthorizationReturnType;\n\ntype CreateKernelClientForWalletAccountParams = {\n bundlerProvider?: ZerodevBundlerProvider;\n bundlerRpc?: string;\n eip7702Auth?: SignAuthorizationReturnType;\n gasTokenAddress?: Hex;\n networkId?: string;\n paymasterRpc?: string;\n smartWalletAccount: EvmWalletAccount;\n withSponsorship?: boolean;\n};\n\n/**\n * Creates a KernelClient instance for a given smart wallet account.\n *\n * @param params.smartWalletAccount - The smart wallet account to create the KernelClient for.\n * @param [params.bundlerProvider] - A custom bundler provider to use\n * @param [params.bundlerRpc] - A custom bundler RPC to use\n * @param [params.networkId] - The network ID to use for the KernelClient.\n * If not provided, the network ID will be fetched from the active network data.\n * @param [params.paymasterRpc] - A custom paymaster RPC to use\n * @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token\n * @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).\n * @param [params.eip7702Auth] - A pre-signed EIP-7702 authorization. When provided, the kernel client uses \n * this authorization instead of signing a new one internally. Useful for singleUse MFA flows where you need\n * to separate the authorization signing step from the transaction step.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a KernelClient instance.\n */\nexport const createKernelClientForWalletAccount = async (\n {\n smartWalletAccount,\n withSponsorship = true,\n bundlerProvider,\n networkId,\n bundlerRpc: bundlerRpcOverride,\n paymasterRpc: paymasterRpcOverride,\n gasTokenAddress,\n eip7702Auth,\n }: CreateKernelClientForWalletAccountParams,\n client = getDefaultClient()\n): Promise<KernelClient> => {\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n `No active network data found for this wallet account.`\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n const bundlerRpc =\n bundlerRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'bundler',\n },\n client\n );\n\n const bundlerTransport = http(bundlerRpc);\n\n const publicClient = createPublicClient({\n chain: viemChain,\n transport: bundlerTransport,\n });\n\n const account = await createKernelAccount(\n {\n eip7702Auth,\n publicClient,\n smartWalletAccount,\n },\n client\n );\n\n const paymasterRpc =\n paymasterRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'paymaster',\n },\n client\n );\n\n const paymasterConfig = withSponsorship\n ? getPaymasterConfig({\n chain: viemChain,\n gasTokenAddress,\n paymasterRpc,\n })\n : {};\n\n return createKernelAccountClient({\n account,\n bundlerTransport,\n chain: viemChain,\n client: publicClient,\n userOperation: {\n estimateFeesPerGas: async ({ bundlerClient }) =>\n getUserOperationGasPrice(bundlerClient),\n },\n ...paymasterConfig,\n });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { KernelClient } from '../../KernelClient.types';\nimport { shouldUseEIP7702 } from '../shouldUseEIP7702';\n\ntype ShouldSignWithEoaParams = {\n kernelClient: KernelClient;\n smartWalletAccount: EvmWalletAccount;\n};\n\nexport const shouldSignWithEoa = async (\n { kernelClient, smartWalletAccount }: ShouldSignWithEoaParams,\n client: DynamicClient\n) => {\n const useEIP7702 = shouldUseEIP7702({ smartWalletAccount }, client);\n\n if (!useEIP7702) {\n return false;\n }\n\n const isDeployed = await kernelClient.account.isDeployed();\n\n return !isDeployed;\n};\n","import {\n type DynamicClient,\n getOwnerWalletAccountForSmartWalletAccount,\n signMessage as signMessageWithWalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport { createKernelClientForWalletAccount } from '../../createKernelClientForWalletAccount';\nimport { shouldSignWithEoa } from '../shouldSignWithEoa';\n\ntype SignMessageParams = {\n message: string;\n walletAccount: EvmWalletAccount;\n};\n\nexport const signMessage = async (\n { walletAccount, message }: SignMessageParams,\n client: DynamicClient\n): Promise<{ signature: string }> => {\n const kernelClient = await createKernelClientForWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n const shouldUseEoa = await shouldSignWithEoa(\n {\n kernelClient,\n smartWalletAccount: walletAccount,\n },\n client\n );\n\n if (shouldUseEoa) {\n const eoaWalletAccount = getOwnerWalletAccountForSmartWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n assertDefined(eoaWalletAccount, 'Eoa wallet account not found');\n\n const { signature } = await signMessageWithWalletAccount({\n message,\n walletAccount: eoaWalletAccount,\n });\n\n return { signature };\n }\n\n const signature = await kernelClient.signMessage({ message });\n return { signature };\n};\n","import {\n type Chain,\n type DynamicClient,\n InvalidParamError,\n UnrecognizedNetworkError,\n type WalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n formatWalletProviderGroupKey,\n formatWalletProviderKey,\n getActiveNetworkIdFromLastKnownRegistry,\n switchActiveNetworkInLastKnownRegistry,\n} from '@dynamic-labs-sdk/client/core';\nimport {\n type EvmWalletProvider,\n isEvmWalletAccount,\n} from '@dynamic-labs-sdk/evm';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\nimport { getAllUserZerodevAddresses } from '../getAllUserZerodevAddresses';\nimport { getZerodevChainProviderForNetworkId } from '../getZerodevChainProviderForNetworkId';\nimport { signMessage as signMessageUtils } from '../signMessage';\n\nexport const createZerodevWalletProvider = (\n client: DynamicClient\n): EvmWalletProvider => {\n const chain: Chain = 'EVM';\n const walletProviderType = WalletProviderEnum.SmartContractWallet;\n const key = formatWalletProviderKey({\n chain,\n displayName: ZERODEV_METADATA.displayName,\n walletProviderType,\n });\n\n const getActiveNetworkId = async () =>\n getActiveNetworkIdFromLastKnownRegistry({\n client,\n walletProviderKey: key,\n });\n\n const getConnectedAddresses = async () => {\n const zerodevAddresses = getAllUserZerodevAddresses(client);\n\n return {\n addresses: zerodevAddresses,\n };\n };\n\n const signMessage = async ({\n walletAccount,\n message,\n }: {\n message: string;\n walletAccount?: WalletAccount;\n }) => {\n assertDefined(walletAccount, 'Wallet account is required');\n\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError(`walletAccount is not an EVM wallet account`);\n }\n\n return signMessageUtils({ message, walletAccount }, client);\n };\n\n const switchActiveNetwork = async ({ networkId }: { networkId: string }) => {\n const isNetworkEnabled = getZerodevChainProviderForNetworkId(\n { networkId },\n client\n );\n\n if (!isNetworkEnabled) {\n throw new UnrecognizedNetworkError({\n networkId,\n originalError: null,\n walletProviderKey: key,\n });\n }\n\n return switchActiveNetworkInLastKnownRegistry({\n client,\n networkId,\n walletProviderKey: key,\n });\n };\n\n return {\n chain,\n getActiveNetworkId,\n getConnectedAddresses,\n groupKey: formatWalletProviderGroupKey(ZERODEV_METADATA.displayName),\n key,\n metadata: {\n displayName: ZERODEV_METADATA.displayName,\n icon: ZERODEV_METADATA.icon,\n },\n signMessage,\n switchActiveNetwork,\n walletProviderType,\n };\n};\n","import {\n WalletProviderPriority,\n getDefaultClient,\n getWalletProviderRegistry,\n hasExtension,\n registerExtension,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { createZerodevWalletProvider } from '../utils/createZerodevWalletProvider';\n\nexport const ZERODEV_EXTENSION_KEY = 'zerodev';\n\n/**\n * Adds the ZeroDev extension to the Dynamic client.\n *\n * This extension enables Account Abstraction integration with ZeroDev\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const addZerodevExtension = (client = getDefaultClient()) => {\n if (hasExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client)) {\n return;\n }\n\n registerExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client);\n\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = createZerodevWalletProvider(client);\n\n walletProviderRegistry.register({\n priority: WalletProviderPriority.WALLET_SDK,\n walletProvider,\n });\n};\n","import type { Hex } from 'viem';\n\nimport type { KernelClient } from '../../KernelClient.types';\n\ntype PrepareUserOperationWithKernelClientParams = {\n kernelClient: KernelClient;\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n};\n\nexport const prepareUserOperationWithKernelClient = async ({\n kernelClient,\n transaction,\n}: PrepareUserOperationWithKernelClientParams) => {\n const callData = await kernelClient.account.encodeCalls([\n {\n data: transaction.data ?? '0x',\n to: transaction.to,\n value: transaction.value,\n },\n ]);\n\n return kernelClient.prepareUserOperation({\n callData,\n });\n};\n","import { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { Hex } from 'viem';\n\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport type { KernelClient } from '../KernelClient.types';\nimport { prepareUserOperationWithKernelClient } from '../utils/prepareUserOperationWithKernelClient';\n\ntype CanSponsorTransactionBaseParams = {\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n};\n\ntype CanSponsorTransactionWithWalletParams = CanSponsorTransactionBaseParams & {\n kernelClient?: never;\n walletAccount: EvmWalletAccount;\n};\n\ntype CanSponsorTransactionWithClientParams = CanSponsorTransactionBaseParams & {\n kernelClient: KernelClient;\n walletAccount?: never;\n};\n\nexport type CanSponsorTransactionParams =\n | CanSponsorTransactionWithWalletParams\n | CanSponsorTransactionWithClientParams;\n\n/**\n * Checks if a transaction can be sponsored\n * @param params.transaction - The transaction to check if it can be sponsored\n * @param params.kernelClient - The kernel client to use to check if the transaction can be sponsored. If no provided, a walletAccount is required to create a kernel client with sponsorship.\n * @param params.walletAccount - The wallet account that will be used to send the transaction, Only required if no kernel client is provided\n * @returns True if the transaction can be sponsored, false otherwise\n */\nexport const canSponsorTransaction = async ({\n walletAccount,\n transaction,\n kernelClient,\n}: CanSponsorTransactionParams): Promise<boolean> => {\n let kernelClientToUse = kernelClient;\n\n if (!kernelClientToUse) {\n assertDefined(\n walletAccount,\n 'Please provide either a wallet account or a kernel client in the parameters'\n );\n\n kernelClientToUse = await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n });\n }\n\n try {\n const sponsorResult = await prepareUserOperationWithKernelClient({\n kernelClient: kernelClientToUse,\n transaction,\n });\n\n const hasPaymaster = sponsorResult.paymasterAndData !== '0x';\n\n return hasPaymaster;\n } catch {\n return false;\n }\n};\n","import type { UserOperation } from 'viem/account-abstraction';\n\ntype CalculateGasForUserOperationParams = {\n userOperationData: Pick<\n UserOperation,\n | 'callGasLimit'\n | 'verificationGasLimit'\n | 'preVerificationGas'\n | 'maxFeePerGas'\n >;\n};\n\nexport const calculateGasForUserOperation = ({\n userOperationData,\n}: CalculateGasForUserOperationParams): bigint => {\n // Sum all gas units\n const totalGasUnits =\n userOperationData.callGasLimit +\n userOperationData.verificationGasLimit +\n userOperationData.preVerificationGas;\n\n // Multiply by maxFeePerGas to get the total gas cost in wei\n const gasCost = totalGasUnits * userOperationData.maxFeePerGas;\n\n return gasCost;\n};\n","import type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { Hex } from 'viem';\n\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport { calculateGasForUserOperation } from '../utils/calculateGasForUserOperation';\nimport { prepareUserOperationWithKernelClient } from '../utils/prepareUserOperationWithKernelClient';\n\nexport type EstimateTransactionGasParams = {\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Estimates the total gas for a transaction\n * @param params.transaction - The transaction to estimate the gas for\n * @param params.walletAccount - The wallet account that will be used to send the transaction\n * @returns The gas for the transaction in wei\n */\nexport const estimateTransactionGas = async ({\n walletAccount,\n transaction,\n}: EstimateTransactionGasParams): Promise<bigint | null> => {\n try {\n const kernelClientWithoutSponsorship =\n await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n withSponsorship: false,\n });\n\n const unsponsoredUserOperation = await prepareUserOperationWithKernelClient(\n {\n kernelClient: kernelClientWithoutSponsorship,\n transaction,\n }\n );\n\n return calculateGasForUserOperation({\n userOperationData: unsponsoredUserOperation,\n });\n } catch {\n return null;\n }\n};\n","export const isGasSponsorshipError = (err: unknown): boolean => {\n const errorWithMessage = err as { message?: string } | undefined;\n\n return (\n errorWithMessage?.message?.includes(\n 'userOp did not match any gas sponsoring policies'\n ) || false\n );\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport { constants } from '@zerodev/sdk';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\nimport { signAuthorization } from 'viem/actions';\n\nimport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\n\nexport type SignEip7702AuthorizationParams = {\n networkId?: string;\n smartWalletAccount: EvmWalletAccount;\n};\n\n/**\n * Signs an EIP-7702 authorization for ZeroDev kernel delegation.\n *\n * This function creates a signed authorization that allows a wallet to delegate\n * its execution to the ZeroDev kernel contract. The signed authorization can then\n * be passed to `createKernelClientForWalletAccount` via the `eip7702Auth` parameter.\n *\n * @param params - The parameters for signing the authorization.\n * @param params.smartWalletAccount - The EVM smart wallet account to sign the authorization for.\n * @param [params.networkId] - The network ID to use for signing. If not provided, uses the wallet's active network.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the signed EIP-7702 authorization.\n */\nexport const signEip7702Authorization = async (\n { smartWalletAccount, networkId }: SignEip7702AuthorizationParams,\n client = getDefaultClient()\n): Promise<SignAuthorizationReturnType> => {\n const walletClient = await getSignerForSmartWalletAccount(\n { smartWalletAccount },\n client\n );\n\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n 'No active network data found for this wallet account.'\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n return signAuthorization(walletClient, {\n chainId: viemChain.id,\n contractAddress: constants.KERNEL_7702_DELEGATION_ADDRESS,\n });\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport { name, version } from '../../package.json';\n\nassertPackageVersion(name, version);\n\nexport { addZerodevExtension } from '../addZerodevExtension';\nexport { canSponsorTransaction } from '../canSponsorTransaction';\nexport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nexport type { Eip7702Authorization } from '../createKernelClientForWalletAccount';\nexport { estimateTransactionGas } from '../estimateTransactionGas';\nexport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\nexport { isGasSponsorshipError } from '../isGasSponsorshipError';\nexport type { KernelClient } from '../KernelClient.types';\nexport { signEip7702Authorization } from '../signEip7702Authorization';\n"],"mappings":";;;;;;;;;;;;AAMA,MAAa,8BAA8B,WAAoC;AAkB7E,SAhBE,OAAO,MAAM,oBAAoB,QAC9B,eACC,WAAW,mBAAmBA,8CAAmB,uBACjD,WAAW,YACP,aAAa,CACd,WAAWC,uCAAiB,qBAAqB,IACpD,WAAW,WACX,WAAW,gFACyB,WAAW,MAAM,KAAK,MAC7D,IAAI,EAAE,EAEmD,KA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GAAE,OAAO;GAAO;GAAW,EAC3B,OACD;AAED,mDACE,aACA,mDAAmD,UAAU,sDAC9D;QACI;AAML,iBAL0B,yDACxB,EAAE,eAAe,oBAAoB,EACrC,OACD,EAE+B;AAEhC,mDACE,aACA,wDACD;;AAKH,4CAAyB,cAAc;EACrC,mEAH0C,YAAY,CAGnC;EACnB,iBAAiBC,uBAAU;EAC5B,CAAC;;;;;mECrEiBC,4BAAMC,8BAAQ"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","names":["WalletProviderEnum","ZERODEV_METADATA","networkData: NetworkData | undefined","getZerodevRpc","createKernelAccount","getPaymasterConfig","shouldUseEIP7702","chain: Chain","WalletProviderEnum","ZERODEV_METADATA","signMessage","InvalidParamError","signMessageUtils","getZerodevChainProviderForNetworkId","UnrecognizedNetworkError","WalletProviderPriority","getSignerForSmartWalletAccount","networkData: NetworkData | undefined","constants","name","version"],"sources":["../src/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.ts","../src/createKernelClientForWalletAccount/createKernelClientForWalletAccount.ts","../src/utils/shouldSignWithEoa/shouldSignWithEoa.ts","../src/utils/signMessage/signMessage.ts","../src/utils/createZerodevWalletProvider/createZerodevWalletProvider.ts","../src/addZerodevExtension/addZerodevExtension.ts","../src/utils/prepareUserOperationFromCalls/prepareUserOperationFromCalls.ts","../src/canSponsorUserOperation/canSponsorUserOperation.ts","../src/utils/calculateGasForUserOperation/calculateGasForUserOperation.ts","../src/estimateUserOperationGas/estimateUserOperationGas.ts","../src/isGasSponsorshipError/isGasSponsorshipError.ts","../src/sendUserOperation/sendUserOperation.ts","../src/signEip7702Authorization/signEip7702Authorization.ts","../src/exports/index.ts"],"sourcesContent":["import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getChainFromVerifiedCredentialChain } from '@dynamic-labs-sdk/client/core';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\n\nexport const getAllUserZerodevAddresses = (client: DynamicClient): string[] => {\n const zerodevWalletCredentials =\n client.user?.verifiedCredentials.filter(\n (credential) =>\n credential.walletProvider === WalletProviderEnum.SmartContractWallet &&\n credential.walletName\n ?.toLowerCase()\n .startsWith(ZERODEV_METADATA.normalizedWalletName) &&\n credential.address &&\n credential.chain &&\n getChainFromVerifiedCredentialChain(credential.chain) === 'EVM'\n ) ?? [];\n\n const zerodevAddresses: string[] = zerodevWalletCredentials.map(\n // casting because we're already filtering out credentials without an address\n (credential) => credential.address as string\n );\n\n return zerodevAddresses;\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport type { ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';\nimport {\n createKernelAccountClient,\n getUserOperationGasPrice,\n} from '@zerodev/sdk';\nimport type { Hex } from 'viem';\nimport { createPublicClient, http } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { KernelClient } from '../KernelClient.types';\nimport { createKernelAccount } from '../utils/createKernelAccount';\nimport { getPaymasterConfig } from '../utils/getPaymasterConfig';\nimport { getZerodevRpc } from '../utils/getZerodevRpc';\n\nexport type Eip7702Authorization = SignAuthorizationReturnType;\n\ntype CreateKernelClientForWalletAccountParams = {\n bundlerProvider?: ZerodevBundlerProvider;\n bundlerRpc?: string;\n eip7702Auth?: SignAuthorizationReturnType;\n gasTokenAddress?: Hex;\n networkId?: string;\n paymasterRpc?: string;\n smartWalletAccount: EvmWalletAccount;\n withSponsorship?: boolean;\n};\n\n/**\n * Creates a KernelClient instance for a given smart wallet account.\n *\n * @param params.smartWalletAccount - The smart wallet account to create the KernelClient for.\n * @param [params.bundlerProvider] - A custom bundler provider to use\n * @param [params.bundlerRpc] - A custom bundler RPC to use\n * @param [params.networkId] - The network ID to use for the KernelClient.\n * If not provided, the network ID will be fetched from the active network data.\n * @param [params.paymasterRpc] - A custom paymaster RPC to use\n * @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token\n * @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).\n * @param [params.eip7702Auth] - A pre-signed EIP-7702 authorization. When provided, the kernel client uses \n * this authorization instead of signing a new one internally. Useful for singleUse MFA flows where you need\n * to separate the authorization signing step from the transaction step.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a KernelClient instance.\n */\nexport const createKernelClientForWalletAccount = async (\n {\n smartWalletAccount,\n withSponsorship = true,\n bundlerProvider,\n networkId,\n bundlerRpc: bundlerRpcOverride,\n paymasterRpc: paymasterRpcOverride,\n gasTokenAddress,\n eip7702Auth,\n }: CreateKernelClientForWalletAccountParams,\n client = getDefaultClient()\n): Promise<KernelClient> => {\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n `No active network data found for this wallet account.`\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n const bundlerRpc =\n bundlerRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'bundler',\n },\n client\n );\n\n const bundlerTransport = http(bundlerRpc);\n\n const publicClient = createPublicClient({\n chain: viemChain,\n transport: bundlerTransport,\n });\n\n const account = await createKernelAccount(\n {\n eip7702Auth,\n publicClient,\n smartWalletAccount,\n },\n client\n );\n\n const paymasterRpc =\n paymasterRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'paymaster',\n },\n client\n );\n\n const paymasterConfig = withSponsorship\n ? getPaymasterConfig({\n chain: viemChain,\n gasTokenAddress,\n paymasterRpc,\n })\n : {};\n\n return createKernelAccountClient({\n account,\n bundlerTransport,\n chain: viemChain,\n client: publicClient,\n userOperation: {\n estimateFeesPerGas: async ({ bundlerClient }) =>\n getUserOperationGasPrice(bundlerClient),\n },\n ...paymasterConfig,\n });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { KernelClient } from '../../KernelClient.types';\nimport { shouldUseEIP7702 } from '../shouldUseEIP7702';\n\ntype ShouldSignWithEoaParams = {\n kernelClient: KernelClient;\n smartWalletAccount: EvmWalletAccount;\n};\n\nexport const shouldSignWithEoa = async (\n { kernelClient, smartWalletAccount }: ShouldSignWithEoaParams,\n client: DynamicClient\n) => {\n const useEIP7702 = shouldUseEIP7702({ smartWalletAccount }, client);\n\n if (!useEIP7702) {\n return false;\n }\n\n const isDeployed = await kernelClient.account.isDeployed();\n\n return !isDeployed;\n};\n","import {\n type DynamicClient,\n getOwnerWalletAccountForSmartWalletAccount,\n signMessage as signMessageWithWalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport { createKernelClientForWalletAccount } from '../../createKernelClientForWalletAccount';\nimport { shouldSignWithEoa } from '../shouldSignWithEoa';\n\ntype SignMessageParams = {\n message: string;\n walletAccount: EvmWalletAccount;\n};\n\nexport const signMessage = async (\n { walletAccount, message }: SignMessageParams,\n client: DynamicClient\n): Promise<{ signature: string }> => {\n const kernelClient = await createKernelClientForWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n const shouldUseEoa = await shouldSignWithEoa(\n {\n kernelClient,\n smartWalletAccount: walletAccount,\n },\n client\n );\n\n if (shouldUseEoa) {\n const eoaWalletAccount = getOwnerWalletAccountForSmartWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n assertDefined(eoaWalletAccount, 'Eoa wallet account not found');\n\n const { signature } = await signMessageWithWalletAccount({\n message,\n walletAccount: eoaWalletAccount,\n });\n\n return { signature };\n }\n\n const signature = await kernelClient.signMessage({ message });\n return { signature };\n};\n","import {\n type Chain,\n type DynamicClient,\n InvalidParamError,\n UnrecognizedNetworkError,\n type WalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n formatWalletProviderGroupKey,\n formatWalletProviderKey,\n getActiveNetworkIdFromLastKnownRegistry,\n switchActiveNetworkInLastKnownRegistry,\n} from '@dynamic-labs-sdk/client/core';\nimport {\n type EvmWalletProvider,\n isEvmWalletAccount,\n} from '@dynamic-labs-sdk/evm';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\nimport { getAllUserZerodevAddresses } from '../getAllUserZerodevAddresses';\nimport { getZerodevChainProviderForNetworkId } from '../getZerodevChainProviderForNetworkId';\nimport { signMessage as signMessageUtils } from '../signMessage';\n\nexport const createZerodevWalletProvider = (\n client: DynamicClient\n): EvmWalletProvider => {\n const chain: Chain = 'EVM';\n const walletProviderType = WalletProviderEnum.SmartContractWallet;\n const key = formatWalletProviderKey({\n chain,\n displayName: ZERODEV_METADATA.displayName,\n walletProviderType,\n });\n\n const getActiveNetworkId = async () =>\n getActiveNetworkIdFromLastKnownRegistry({\n client,\n walletProviderKey: key,\n });\n\n const getConnectedAddresses = async () => {\n const zerodevAddresses = getAllUserZerodevAddresses(client);\n\n return {\n addresses: zerodevAddresses,\n };\n };\n\n const signMessage = async ({\n walletAccount,\n message,\n }: {\n message: string;\n walletAccount?: WalletAccount;\n }) => {\n assertDefined(walletAccount, 'Wallet account is required');\n\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError(`walletAccount is not an EVM wallet account`);\n }\n\n return signMessageUtils({ message, walletAccount }, client);\n };\n\n const switchActiveNetwork = async ({ networkId }: { networkId: string }) => {\n const isNetworkEnabled = getZerodevChainProviderForNetworkId(\n { networkId },\n client\n );\n\n if (!isNetworkEnabled) {\n throw new UnrecognizedNetworkError({\n networkId,\n originalError: null,\n walletProviderKey: key,\n });\n }\n\n return switchActiveNetworkInLastKnownRegistry({\n client,\n networkId,\n walletProviderKey: key,\n });\n };\n\n return {\n chain,\n getActiveNetworkId,\n getConnectedAddresses,\n groupKey: formatWalletProviderGroupKey(ZERODEV_METADATA.displayName),\n key,\n metadata: {\n displayName: ZERODEV_METADATA.displayName,\n icon: ZERODEV_METADATA.icon,\n },\n signMessage,\n switchActiveNetwork,\n walletProviderType,\n };\n};\n","import {\n WalletProviderPriority,\n getDefaultClient,\n getWalletProviderRegistry,\n hasExtension,\n registerExtension,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { createZerodevWalletProvider } from '../utils/createZerodevWalletProvider';\n\nexport const ZERODEV_EXTENSION_KEY = 'zerodev';\n\n/**\n * Adds the ZeroDev extension to the Dynamic client.\n *\n * This extension enables Account Abstraction integration with ZeroDev\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const addZerodevExtension = (client = getDefaultClient()) => {\n if (hasExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client)) {\n return;\n }\n\n registerExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client);\n\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = createZerodevWalletProvider(client);\n\n walletProviderRegistry.register({\n priority: WalletProviderPriority.WALLET_SDK,\n walletProvider,\n });\n};\n","import type { BatchCall } from '../../BatchCall.types';\nimport type { KernelClient } from '../../KernelClient.types';\n\nexport type PrepareUserOperationFromCallsParams = {\n calls: BatchCall[];\n kernelClient: KernelClient;\n};\n\n/**\n * Prepares a user operation from an array of calls\n * Replaces prepareUserOperationWithKernelClient to handle both single and batch transactions\n *\n * @param params.kernelClient - The kernel client to use for preparing the user operation\n * @param params.calls - Array of calls (can be single call or multiple calls)\n * @returns Promise resolving to the prepared user operation\n */\nexport const prepareUserOperationFromCalls = async ({\n kernelClient,\n calls,\n}: PrepareUserOperationFromCallsParams) => {\n // Normalize calls to ensure data field exists\n const normalizedCalls = calls.map((call) => ({\n data: call.data ?? '0x',\n to: call.to,\n value: call.value,\n }));\n\n const callData = await kernelClient.account.encodeCalls(normalizedCalls);\n\n return kernelClient.prepareUserOperation({\n callData,\n });\n};\n","import { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { BatchCall } from '../BatchCall.types';\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport type { KernelClient } from '../KernelClient.types';\nimport { prepareUserOperationFromCalls } from '../utils/prepareUserOperationFromCalls';\n\ntype CanSponsorUserOperationBaseParams = {\n calls: BatchCall[];\n};\n\ntype CanSponsorUserOperationWithWalletParams =\n CanSponsorUserOperationBaseParams & {\n kernelClient?: never;\n walletAccount: EvmWalletAccount;\n };\n\ntype CanSponsorUserOperationWithClientParams =\n CanSponsorUserOperationBaseParams & {\n kernelClient: KernelClient;\n walletAccount?: never;\n };\n\nexport type CanSponsorUserOperationParams =\n | CanSponsorUserOperationWithWalletParams\n | CanSponsorUserOperationWithClientParams;\n\n/**\n * Checks if a user operation can be sponsored by the paymaster\n * Handles both single transactions and batch transactions\n *\n * @param params.calls - Array of calls (single call or multiple calls)\n * @param params.kernelClient - Optional kernel client with sponsorship configured\n * @param params.walletAccount - The wallet account to use (required if kernelClient not provided)\n * @returns True if the user operation can be sponsored, false otherwise\n */\nexport const canSponsorUserOperation = async ({\n walletAccount,\n calls,\n kernelClient,\n}: CanSponsorUserOperationParams): Promise<boolean> => {\n let kernelClientToUse = kernelClient;\n\n if (!kernelClientToUse) {\n assertDefined(\n walletAccount,\n 'Please provide either a wallet account or a kernel client in the parameters'\n );\n\n kernelClientToUse = await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n });\n }\n\n try {\n const sponsorResult = await prepareUserOperationFromCalls({\n calls,\n kernelClient: kernelClientToUse,\n });\n\n const hasPaymaster = sponsorResult.paymasterAndData !== '0x';\n\n return hasPaymaster;\n } catch {\n return false;\n }\n};\n","import type { UserOperation } from 'viem/account-abstraction';\n\ntype CalculateGasForUserOperationParams = {\n userOperationData: Pick<\n UserOperation,\n | 'callGasLimit'\n | 'verificationGasLimit'\n | 'preVerificationGas'\n | 'maxFeePerGas'\n >;\n};\n\nexport const calculateGasForUserOperation = ({\n userOperationData,\n}: CalculateGasForUserOperationParams): bigint => {\n // Sum all gas units\n const totalGasUnits =\n userOperationData.callGasLimit +\n userOperationData.verificationGasLimit +\n userOperationData.preVerificationGas;\n\n // Multiply by maxFeePerGas to get the total gas cost in wei\n const gasCost = totalGasUnits * userOperationData.maxFeePerGas;\n\n return gasCost;\n};\n","import type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { BatchCall } from '../BatchCall.types';\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport { calculateGasForUserOperation } from '../utils/calculateGasForUserOperation';\nimport { prepareUserOperationFromCalls } from '../utils/prepareUserOperationFromCalls';\n\nexport type EstimateUserOperationGasParams = {\n calls: BatchCall[];\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Estimates the total gas cost for a user operation with one or more calls\n * Handles both single transactions and batch transactions\n *\n * @param params.calls - Array of calls (single call or multiple calls)\n * @param params.walletAccount - The wallet account that will execute the user operation\n * @returns The estimated gas cost in wei, or null if estimation fails\n */\nexport const estimateUserOperationGas = async ({\n walletAccount,\n calls,\n}: EstimateUserOperationGasParams): Promise<bigint | null> => {\n try {\n const kernelClientWithoutSponsorship =\n await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n withSponsorship: false,\n });\n\n const unsponsoredUserOperation = await prepareUserOperationFromCalls({\n calls,\n kernelClient: kernelClientWithoutSponsorship,\n });\n\n return calculateGasForUserOperation({\n userOperationData: unsponsoredUserOperation,\n });\n } catch {\n return null;\n }\n};\n","export const isGasSponsorshipError = (err: unknown): boolean => {\n const errorWithMessage = err as { message?: string } | undefined;\n\n return (\n errorWithMessage?.message?.includes(\n 'userOp did not match any gas sponsoring policies'\n ) || false\n );\n};\n","import { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { UserOperationReceipt } from 'viem/account-abstraction';\n\nimport type { BatchCall } from '../BatchCall.types';\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport type { KernelClient } from '../KernelClient.types';\nimport { prepareUserOperationFromCalls } from '../utils/prepareUserOperationFromCalls';\n\ntype SendUserOperationBaseParams = {\n calls: BatchCall[];\n};\n\ntype SendUserOperationWithWalletParams = SendUserOperationBaseParams & {\n kernelClient?: never;\n walletAccount: EvmWalletAccount;\n withSponsorship?: boolean;\n};\n\ntype SendUserOperationWithClientParams = SendUserOperationBaseParams & {\n kernelClient: KernelClient;\n walletAccount?: never;\n withSponsorship?: never;\n};\n\nexport type SendUserOperationParams =\n | SendUserOperationWithWalletParams\n | SendUserOperationWithClientParams;\n\n/**\n * Sends a user operation with one or more calls\n * Handles both single transactions and batch transactions\n *\n * @param params.calls - Array of calls (single call or multiple calls)\n * @param params.kernelClient - Optional pre-configured kernel client\n * @param params.walletAccount - The wallet account to use (required if kernelClient not provided)\n * @param params.withSponsorship - Whether to use sponsorship (default: true, only used with walletAccount)\n * @returns Promise resolving to the UserOperation receipt\n */\nexport const sendUserOperation = async ({\n walletAccount,\n calls,\n kernelClient,\n withSponsorship = true,\n}: SendUserOperationParams): Promise<UserOperationReceipt> => {\n let kernelClientToUse = kernelClient;\n\n if (!kernelClientToUse) {\n assertDefined(\n walletAccount,\n 'Please provide either a wallet account or a kernel client in the parameters'\n );\n\n kernelClientToUse = await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n withSponsorship,\n });\n }\n\n const userOperation = await prepareUserOperationFromCalls({\n calls,\n kernelClient: kernelClientToUse,\n });\n\n // Type cast needed: prepareUserOperation returns a fully prepared UserOperation with all fields,\n // but sendUserOperation's discriminated union types expect specific field combinations.\n // This is safe as the prepared operation is compatible at runtime.\n const userOperationHash = await kernelClientToUse.sendUserOperation(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n userOperation as any\n );\n\n return kernelClientToUse.waitForUserOperationReceipt({\n hash: userOperationHash,\n });\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport { constants } from '@zerodev/sdk';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\nimport { signAuthorization } from 'viem/actions';\n\nimport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\n\nexport type SignEip7702AuthorizationParams = {\n networkId?: string;\n smartWalletAccount: EvmWalletAccount;\n};\n\n/**\n * Signs an EIP-7702 authorization for ZeroDev kernel delegation.\n *\n * This function creates a signed authorization that allows a wallet to delegate\n * its execution to the ZeroDev kernel contract. The signed authorization can then\n * be passed to `createKernelClientForWalletAccount` via the `eip7702Auth` parameter.\n *\n * @param params - The parameters for signing the authorization.\n * @param params.smartWalletAccount - The EVM smart wallet account to sign the authorization for.\n * @param [params.networkId] - The network ID to use for signing. If not provided, uses the wallet's active network.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the signed EIP-7702 authorization.\n */\nexport const signEip7702Authorization = async (\n { smartWalletAccount, networkId }: SignEip7702AuthorizationParams,\n client = getDefaultClient()\n): Promise<SignAuthorizationReturnType> => {\n const walletClient = await getSignerForSmartWalletAccount(\n { smartWalletAccount },\n client\n );\n\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n 'No active network data found for this wallet account.'\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n return signAuthorization(walletClient, {\n chainId: viemChain.id,\n contractAddress: constants.KERNEL_7702_DELEGATION_ADDRESS,\n });\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport { name, version } from '../../package.json';\n\nassertPackageVersion(name, version);\n\nexport { addZerodevExtension } from '../addZerodevExtension';\nexport type { BatchCall } from '../BatchCall.types';\nexport { canSponsorUserOperation } from '../canSponsorUserOperation';\nexport type { CanSponsorUserOperationParams } from '../canSponsorUserOperation';\nexport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nexport type { Eip7702Authorization } from '../createKernelClientForWalletAccount';\nexport { estimateUserOperationGas } from '../estimateUserOperationGas';\nexport type { EstimateUserOperationGasParams } from '../estimateUserOperationGas';\nexport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\nexport { isGasSponsorshipError } from '../isGasSponsorshipError';\nexport type { KernelClient } from '../KernelClient.types';\nexport { sendUserOperation } from '../sendUserOperation';\nexport type { SendUserOperationParams } from '../sendUserOperation';\nexport { signEip7702Authorization } from '../signEip7702Authorization';\n"],"mappings":";;;;;;;;;;;;AAMA,MAAa,8BAA8B,WAAoC;AAkB7E,SAhBE,OAAO,MAAM,oBAAoB,QAC9B,eACC,WAAW,mBAAmBA,8CAAmB,uBACjD,WAAW,YACP,aAAa,CACd,WAAWC,uCAAiB,qBAAqB,IACpD,WAAW,WACX,WAAW,gFACyB,WAAW,MAAM,KAAK,MA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ExB,KAAI,CAAC,mBAAmB;AACtB,mDACE,eACA,8EACD;AAED,sBAAoB,MAAM,mCAAmC;GAC3D,oBAAoB;GACpB;GACD,CAAC;;CAGJ,MAAM,gBAAgB,MAAM,8BAA8B;EACxD;EACA,cAAc;EACf,CAAC;CAKF,MAAM,oBAAoB,MAAM,kBAAkB,kBAEhD,cACD;AAED,QAAO,kBAAkB,4BAA4B,EACnD,MAAM,mBACP,CAAC;;;;;;;;;;;;;;;;;;ACzCJ,MAAa,2BAA2B,OACtC,EAAE,oBAAoB,aACtB,8DAA2B,KACc;CACzC,MAAM,eAAe,MAAMC,qDACzB,EAAE,oBAAoB,EACtB,OACD;CAED,IAAIC;AAEJ,KAAI,WAAW;AACb,8EACE;GAAE,OAAO;GAAO;GAAW,EAC3B,OACD;AAED,mDACE,aACA,mDAAmD,UAAU,sDAC9D;QACI;AAML,iBAL0B,yDACxB,EAAE,eAAe,oBAAoB,EACrC,OACD,EAE+B;AAEhC,mDACE,aACA,wDACD;;AAKH,4CAAyB,cAAc;EACrC,mEAH0C,YAAY,CAGnC;EACnB,iBAAiBC,uBAAU;EAC5B,CAAC;;;;;mECrEiBC,4BAAMC,8BAAQ"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as getSignerForSmartWalletAccount, d as ZERODEV_METADATA, f as name, i as shouldUseEIP7702, l as getZerodevChainProviderForNetworkId, n as getPaymasterConfig, p as version, r as createKernelAccount$1, t as getZerodevRpc } from "./getZerodevRpc-
|
|
1
|
+
import { c as getSignerForSmartWalletAccount, d as ZERODEV_METADATA, f as name, i as shouldUseEIP7702, l as getZerodevChainProviderForNetworkId, n as getPaymasterConfig, p as version, r as createKernelAccount$1, t as getZerodevRpc } from "./getZerodevRpc-Buy6FN1e.esm.js";
|
|
2
2
|
import { assertPackageVersion } from "@dynamic-labs-sdk/assert-package-version";
|
|
3
3
|
import { WalletProviderPriority, assertDefined, formatWalletProviderGroupKey, formatWalletProviderKey, getActiveNetworkIdFromLastKnownRegistry, getChainFromVerifiedCredentialChain, getDefaultClient, getNetworkDataForNetworkId, getWalletProviderRegistry, hasExtension, registerExtension, switchActiveNetworkInLastKnownRegistry } from "@dynamic-labs-sdk/client/core";
|
|
4
4
|
import { InvalidParamError, UnrecognizedNetworkError, getActiveNetworkData, getOwnerWalletAccountForSmartWalletAccount, signMessage } from "@dynamic-labs-sdk/client";
|
|
@@ -180,35 +180,46 @@ const addZerodevExtension = (client = getDefaultClient()) => {
|
|
|
180
180
|
};
|
|
181
181
|
|
|
182
182
|
//#endregion
|
|
183
|
-
//#region src/utils/
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
//#region src/utils/prepareUserOperationFromCalls/prepareUserOperationFromCalls.ts
|
|
184
|
+
/**
|
|
185
|
+
* Prepares a user operation from an array of calls
|
|
186
|
+
* Replaces prepareUserOperationWithKernelClient to handle both single and batch transactions
|
|
187
|
+
*
|
|
188
|
+
* @param params.kernelClient - The kernel client to use for preparing the user operation
|
|
189
|
+
* @param params.calls - Array of calls (can be single call or multiple calls)
|
|
190
|
+
* @returns Promise resolving to the prepared user operation
|
|
191
|
+
*/
|
|
192
|
+
const prepareUserOperationFromCalls = async ({ kernelClient, calls }) => {
|
|
193
|
+
const normalizedCalls = calls.map((call) => ({
|
|
194
|
+
data: call.data ?? "0x",
|
|
195
|
+
to: call.to,
|
|
196
|
+
value: call.value
|
|
197
|
+
}));
|
|
198
|
+
const callData = await kernelClient.account.encodeCalls(normalizedCalls);
|
|
190
199
|
return kernelClient.prepareUserOperation({ callData });
|
|
191
200
|
};
|
|
192
201
|
|
|
193
202
|
//#endregion
|
|
194
|
-
//#region src/
|
|
203
|
+
//#region src/canSponsorUserOperation/canSponsorUserOperation.ts
|
|
195
204
|
/**
|
|
196
|
-
* Checks if a
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* @param params.
|
|
200
|
-
* @
|
|
205
|
+
* Checks if a user operation can be sponsored by the paymaster
|
|
206
|
+
* Handles both single transactions and batch transactions
|
|
207
|
+
*
|
|
208
|
+
* @param params.calls - Array of calls (single call or multiple calls)
|
|
209
|
+
* @param params.kernelClient - Optional kernel client with sponsorship configured
|
|
210
|
+
* @param params.walletAccount - The wallet account to use (required if kernelClient not provided)
|
|
211
|
+
* @returns True if the user operation can be sponsored, false otherwise
|
|
201
212
|
*/
|
|
202
|
-
const
|
|
213
|
+
const canSponsorUserOperation = async ({ walletAccount, calls, kernelClient }) => {
|
|
203
214
|
let kernelClientToUse = kernelClient;
|
|
204
215
|
if (!kernelClientToUse) {
|
|
205
216
|
assertDefined(walletAccount, "Please provide either a wallet account or a kernel client in the parameters");
|
|
206
217
|
kernelClientToUse = await createKernelClientForWalletAccount({ smartWalletAccount: walletAccount });
|
|
207
218
|
}
|
|
208
219
|
try {
|
|
209
|
-
return (await
|
|
210
|
-
|
|
211
|
-
|
|
220
|
+
return (await prepareUserOperationFromCalls({
|
|
221
|
+
calls,
|
|
222
|
+
kernelClient: kernelClientToUse
|
|
212
223
|
})).paymasterAndData !== "0x";
|
|
213
224
|
} catch {
|
|
214
225
|
return false;
|
|
@@ -222,21 +233,23 @@ const calculateGasForUserOperation = ({ userOperationData }) => {
|
|
|
222
233
|
};
|
|
223
234
|
|
|
224
235
|
//#endregion
|
|
225
|
-
//#region src/
|
|
236
|
+
//#region src/estimateUserOperationGas/estimateUserOperationGas.ts
|
|
226
237
|
/**
|
|
227
|
-
* Estimates the total gas for a
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
* @
|
|
238
|
+
* Estimates the total gas cost for a user operation with one or more calls
|
|
239
|
+
* Handles both single transactions and batch transactions
|
|
240
|
+
*
|
|
241
|
+
* @param params.calls - Array of calls (single call or multiple calls)
|
|
242
|
+
* @param params.walletAccount - The wallet account that will execute the user operation
|
|
243
|
+
* @returns The estimated gas cost in wei, or null if estimation fails
|
|
231
244
|
*/
|
|
232
|
-
const
|
|
245
|
+
const estimateUserOperationGas = async ({ walletAccount, calls }) => {
|
|
233
246
|
try {
|
|
234
|
-
return calculateGasForUserOperation({ userOperationData: await
|
|
247
|
+
return calculateGasForUserOperation({ userOperationData: await prepareUserOperationFromCalls({
|
|
248
|
+
calls,
|
|
235
249
|
kernelClient: await createKernelClientForWalletAccount({
|
|
236
250
|
smartWalletAccount: walletAccount,
|
|
237
251
|
withSponsorship: false
|
|
238
|
-
})
|
|
239
|
-
transaction
|
|
252
|
+
})
|
|
240
253
|
}) });
|
|
241
254
|
} catch {
|
|
242
255
|
return null;
|
|
@@ -249,6 +262,35 @@ const isGasSponsorshipError = (err) => {
|
|
|
249
262
|
return err?.message?.includes("userOp did not match any gas sponsoring policies") || false;
|
|
250
263
|
};
|
|
251
264
|
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/sendUserOperation/sendUserOperation.ts
|
|
267
|
+
/**
|
|
268
|
+
* Sends a user operation with one or more calls
|
|
269
|
+
* Handles both single transactions and batch transactions
|
|
270
|
+
*
|
|
271
|
+
* @param params.calls - Array of calls (single call or multiple calls)
|
|
272
|
+
* @param params.kernelClient - Optional pre-configured kernel client
|
|
273
|
+
* @param params.walletAccount - The wallet account to use (required if kernelClient not provided)
|
|
274
|
+
* @param params.withSponsorship - Whether to use sponsorship (default: true, only used with walletAccount)
|
|
275
|
+
* @returns Promise resolving to the UserOperation receipt
|
|
276
|
+
*/
|
|
277
|
+
const sendUserOperation = async ({ walletAccount, calls, kernelClient, withSponsorship = true }) => {
|
|
278
|
+
let kernelClientToUse = kernelClient;
|
|
279
|
+
if (!kernelClientToUse) {
|
|
280
|
+
assertDefined(walletAccount, "Please provide either a wallet account or a kernel client in the parameters");
|
|
281
|
+
kernelClientToUse = await createKernelClientForWalletAccount({
|
|
282
|
+
smartWalletAccount: walletAccount,
|
|
283
|
+
withSponsorship
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const userOperation = await prepareUserOperationFromCalls({
|
|
287
|
+
calls,
|
|
288
|
+
kernelClient: kernelClientToUse
|
|
289
|
+
});
|
|
290
|
+
const userOperationHash = await kernelClientToUse.sendUserOperation(userOperation);
|
|
291
|
+
return kernelClientToUse.waitForUserOperationReceipt({ hash: userOperationHash });
|
|
292
|
+
};
|
|
293
|
+
|
|
252
294
|
//#endregion
|
|
253
295
|
//#region src/signEip7702Authorization/signEip7702Authorization.ts
|
|
254
296
|
/**
|
|
@@ -288,5 +330,5 @@ const signEip7702Authorization = async ({ smartWalletAccount, networkId }, clien
|
|
|
288
330
|
assertPackageVersion(name, version);
|
|
289
331
|
|
|
290
332
|
//#endregion
|
|
291
|
-
export { addZerodevExtension,
|
|
333
|
+
export { addZerodevExtension, canSponsorUserOperation, createKernelClientForWalletAccount, estimateUserOperationGas, getSignerForSmartWalletAccount, isGasSponsorshipError, sendUserOperation, signEip7702Authorization };
|
|
292
334
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","names":["networkData: NetworkData | undefined","createKernelAccount","signMessage","signMessageWithWalletAccount","chain: Chain","signMessage","signMessageUtils","networkData: NetworkData | undefined"],"sources":["../src/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.ts","../src/createKernelClientForWalletAccount/createKernelClientForWalletAccount.ts","../src/utils/shouldSignWithEoa/shouldSignWithEoa.ts","../src/utils/signMessage/signMessage.ts","../src/utils/createZerodevWalletProvider/createZerodevWalletProvider.ts","../src/addZerodevExtension/addZerodevExtension.ts","../src/utils/prepareUserOperationWithKernelClient/prepareUserOperationWithKernelClient.ts","../src/canSponsorTransaction/canSponsorTransaction.ts","../src/utils/calculateGasForUserOperation/calculateGasForUserOperation.ts","../src/estimateTransactionGas/estimateTransactionGas.ts","../src/isGasSponsorshipError/isGasSponsorshipError.ts","../src/signEip7702Authorization/signEip7702Authorization.ts","../src/exports/index.ts"],"sourcesContent":["import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getChainFromVerifiedCredentialChain } from '@dynamic-labs-sdk/client/core';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\n\nexport const getAllUserZerodevAddresses = (client: DynamicClient): string[] => {\n const zerodevWalletCredentials =\n client.user?.verifiedCredentials.filter(\n (credential) =>\n credential.walletProvider === WalletProviderEnum.SmartContractWallet &&\n credential.walletName\n ?.toLowerCase()\n .startsWith(ZERODEV_METADATA.normalizedWalletName) &&\n credential.address &&\n credential.chain &&\n getChainFromVerifiedCredentialChain(credential.chain) === 'EVM'\n ) ?? [];\n\n const zerodevAddresses: string[] = zerodevWalletCredentials.map(\n // casting because we're already filtering out credentials without an address\n (credential) => credential.address as string\n );\n\n return zerodevAddresses;\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport type { ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';\nimport {\n createKernelAccountClient,\n getUserOperationGasPrice,\n} from '@zerodev/sdk';\nimport type { Hex } from 'viem';\nimport { createPublicClient, http } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { KernelClient } from '../KernelClient.types';\nimport { createKernelAccount } from '../utils/createKernelAccount';\nimport { getPaymasterConfig } from '../utils/getPaymasterConfig';\nimport { getZerodevRpc } from '../utils/getZerodevRpc';\n\nexport type Eip7702Authorization = SignAuthorizationReturnType;\n\ntype CreateKernelClientForWalletAccountParams = {\n bundlerProvider?: ZerodevBundlerProvider;\n bundlerRpc?: string;\n eip7702Auth?: SignAuthorizationReturnType;\n gasTokenAddress?: Hex;\n networkId?: string;\n paymasterRpc?: string;\n smartWalletAccount: EvmWalletAccount;\n withSponsorship?: boolean;\n};\n\n/**\n * Creates a KernelClient instance for a given smart wallet account.\n *\n * @param params.smartWalletAccount - The smart wallet account to create the KernelClient for.\n * @param [params.bundlerProvider] - A custom bundler provider to use\n * @param [params.bundlerRpc] - A custom bundler RPC to use\n * @param [params.networkId] - The network ID to use for the KernelClient.\n * If not provided, the network ID will be fetched from the active network data.\n * @param [params.paymasterRpc] - A custom paymaster RPC to use\n * @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token\n * @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).\n * @param [params.eip7702Auth] - A pre-signed EIP-7702 authorization. When provided, the kernel client uses \n * this authorization instead of signing a new one internally. Useful for singleUse MFA flows where you need\n * to separate the authorization signing step from the transaction step.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a KernelClient instance.\n */\nexport const createKernelClientForWalletAccount = async (\n {\n smartWalletAccount,\n withSponsorship = true,\n bundlerProvider,\n networkId,\n bundlerRpc: bundlerRpcOverride,\n paymasterRpc: paymasterRpcOverride,\n gasTokenAddress,\n eip7702Auth,\n }: CreateKernelClientForWalletAccountParams,\n client = getDefaultClient()\n): Promise<KernelClient> => {\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n `No active network data found for this wallet account.`\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n const bundlerRpc =\n bundlerRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'bundler',\n },\n client\n );\n\n const bundlerTransport = http(bundlerRpc);\n\n const publicClient = createPublicClient({\n chain: viemChain,\n transport: bundlerTransport,\n });\n\n const account = await createKernelAccount(\n {\n eip7702Auth,\n publicClient,\n smartWalletAccount,\n },\n client\n );\n\n const paymasterRpc =\n paymasterRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'paymaster',\n },\n client\n );\n\n const paymasterConfig = withSponsorship\n ? getPaymasterConfig({\n chain: viemChain,\n gasTokenAddress,\n paymasterRpc,\n })\n : {};\n\n return createKernelAccountClient({\n account,\n bundlerTransport,\n chain: viemChain,\n client: publicClient,\n userOperation: {\n estimateFeesPerGas: async ({ bundlerClient }) =>\n getUserOperationGasPrice(bundlerClient),\n },\n ...paymasterConfig,\n });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { KernelClient } from '../../KernelClient.types';\nimport { shouldUseEIP7702 } from '../shouldUseEIP7702';\n\ntype ShouldSignWithEoaParams = {\n kernelClient: KernelClient;\n smartWalletAccount: EvmWalletAccount;\n};\n\nexport const shouldSignWithEoa = async (\n { kernelClient, smartWalletAccount }: ShouldSignWithEoaParams,\n client: DynamicClient\n) => {\n const useEIP7702 = shouldUseEIP7702({ smartWalletAccount }, client);\n\n if (!useEIP7702) {\n return false;\n }\n\n const isDeployed = await kernelClient.account.isDeployed();\n\n return !isDeployed;\n};\n","import {\n type DynamicClient,\n getOwnerWalletAccountForSmartWalletAccount,\n signMessage as signMessageWithWalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport { createKernelClientForWalletAccount } from '../../createKernelClientForWalletAccount';\nimport { shouldSignWithEoa } from '../shouldSignWithEoa';\n\ntype SignMessageParams = {\n message: string;\n walletAccount: EvmWalletAccount;\n};\n\nexport const signMessage = async (\n { walletAccount, message }: SignMessageParams,\n client: DynamicClient\n): Promise<{ signature: string }> => {\n const kernelClient = await createKernelClientForWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n const shouldUseEoa = await shouldSignWithEoa(\n {\n kernelClient,\n smartWalletAccount: walletAccount,\n },\n client\n );\n\n if (shouldUseEoa) {\n const eoaWalletAccount = getOwnerWalletAccountForSmartWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n assertDefined(eoaWalletAccount, 'Eoa wallet account not found');\n\n const { signature } = await signMessageWithWalletAccount({\n message,\n walletAccount: eoaWalletAccount,\n });\n\n return { signature };\n }\n\n const signature = await kernelClient.signMessage({ message });\n return { signature };\n};\n","import {\n type Chain,\n type DynamicClient,\n InvalidParamError,\n UnrecognizedNetworkError,\n type WalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n formatWalletProviderGroupKey,\n formatWalletProviderKey,\n getActiveNetworkIdFromLastKnownRegistry,\n switchActiveNetworkInLastKnownRegistry,\n} from '@dynamic-labs-sdk/client/core';\nimport {\n type EvmWalletProvider,\n isEvmWalletAccount,\n} from '@dynamic-labs-sdk/evm';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\nimport { getAllUserZerodevAddresses } from '../getAllUserZerodevAddresses';\nimport { getZerodevChainProviderForNetworkId } from '../getZerodevChainProviderForNetworkId';\nimport { signMessage as signMessageUtils } from '../signMessage';\n\nexport const createZerodevWalletProvider = (\n client: DynamicClient\n): EvmWalletProvider => {\n const chain: Chain = 'EVM';\n const walletProviderType = WalletProviderEnum.SmartContractWallet;\n const key = formatWalletProviderKey({\n chain,\n displayName: ZERODEV_METADATA.displayName,\n walletProviderType,\n });\n\n const getActiveNetworkId = async () =>\n getActiveNetworkIdFromLastKnownRegistry({\n client,\n walletProviderKey: key,\n });\n\n const getConnectedAddresses = async () => {\n const zerodevAddresses = getAllUserZerodevAddresses(client);\n\n return {\n addresses: zerodevAddresses,\n };\n };\n\n const signMessage = async ({\n walletAccount,\n message,\n }: {\n message: string;\n walletAccount?: WalletAccount;\n }) => {\n assertDefined(walletAccount, 'Wallet account is required');\n\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError(`walletAccount is not an EVM wallet account`);\n }\n\n return signMessageUtils({ message, walletAccount }, client);\n };\n\n const switchActiveNetwork = async ({ networkId }: { networkId: string }) => {\n const isNetworkEnabled = getZerodevChainProviderForNetworkId(\n { networkId },\n client\n );\n\n if (!isNetworkEnabled) {\n throw new UnrecognizedNetworkError({\n networkId,\n originalError: null,\n walletProviderKey: key,\n });\n }\n\n return switchActiveNetworkInLastKnownRegistry({\n client,\n networkId,\n walletProviderKey: key,\n });\n };\n\n return {\n chain,\n getActiveNetworkId,\n getConnectedAddresses,\n groupKey: formatWalletProviderGroupKey(ZERODEV_METADATA.displayName),\n key,\n metadata: {\n displayName: ZERODEV_METADATA.displayName,\n icon: ZERODEV_METADATA.icon,\n },\n signMessage,\n switchActiveNetwork,\n walletProviderType,\n };\n};\n","import {\n WalletProviderPriority,\n getDefaultClient,\n getWalletProviderRegistry,\n hasExtension,\n registerExtension,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { createZerodevWalletProvider } from '../utils/createZerodevWalletProvider';\n\nexport const ZERODEV_EXTENSION_KEY = 'zerodev';\n\n/**\n * Adds the ZeroDev extension to the Dynamic client.\n *\n * This extension enables Account Abstraction integration with ZeroDev\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const addZerodevExtension = (client = getDefaultClient()) => {\n if (hasExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client)) {\n return;\n }\n\n registerExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client);\n\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = createZerodevWalletProvider(client);\n\n walletProviderRegistry.register({\n priority: WalletProviderPriority.WALLET_SDK,\n walletProvider,\n });\n};\n","import type { Hex } from 'viem';\n\nimport type { KernelClient } from '../../KernelClient.types';\n\ntype PrepareUserOperationWithKernelClientParams = {\n kernelClient: KernelClient;\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n};\n\nexport const prepareUserOperationWithKernelClient = async ({\n kernelClient,\n transaction,\n}: PrepareUserOperationWithKernelClientParams) => {\n const callData = await kernelClient.account.encodeCalls([\n {\n data: transaction.data ?? '0x',\n to: transaction.to,\n value: transaction.value,\n },\n ]);\n\n return kernelClient.prepareUserOperation({\n callData,\n });\n};\n","import { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { Hex } from 'viem';\n\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport type { KernelClient } from '../KernelClient.types';\nimport { prepareUserOperationWithKernelClient } from '../utils/prepareUserOperationWithKernelClient';\n\ntype CanSponsorTransactionBaseParams = {\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n};\n\ntype CanSponsorTransactionWithWalletParams = CanSponsorTransactionBaseParams & {\n kernelClient?: never;\n walletAccount: EvmWalletAccount;\n};\n\ntype CanSponsorTransactionWithClientParams = CanSponsorTransactionBaseParams & {\n kernelClient: KernelClient;\n walletAccount?: never;\n};\n\nexport type CanSponsorTransactionParams =\n | CanSponsorTransactionWithWalletParams\n | CanSponsorTransactionWithClientParams;\n\n/**\n * Checks if a transaction can be sponsored\n * @param params.transaction - The transaction to check if it can be sponsored\n * @param params.kernelClient - The kernel client to use to check if the transaction can be sponsored. If no provided, a walletAccount is required to create a kernel client with sponsorship.\n * @param params.walletAccount - The wallet account that will be used to send the transaction, Only required if no kernel client is provided\n * @returns True if the transaction can be sponsored, false otherwise\n */\nexport const canSponsorTransaction = async ({\n walletAccount,\n transaction,\n kernelClient,\n}: CanSponsorTransactionParams): Promise<boolean> => {\n let kernelClientToUse = kernelClient;\n\n if (!kernelClientToUse) {\n assertDefined(\n walletAccount,\n 'Please provide either a wallet account or a kernel client in the parameters'\n );\n\n kernelClientToUse = await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n });\n }\n\n try {\n const sponsorResult = await prepareUserOperationWithKernelClient({\n kernelClient: kernelClientToUse,\n transaction,\n });\n\n const hasPaymaster = sponsorResult.paymasterAndData !== '0x';\n\n return hasPaymaster;\n } catch {\n return false;\n }\n};\n","import type { UserOperation } from 'viem/account-abstraction';\n\ntype CalculateGasForUserOperationParams = {\n userOperationData: Pick<\n UserOperation,\n | 'callGasLimit'\n | 'verificationGasLimit'\n | 'preVerificationGas'\n | 'maxFeePerGas'\n >;\n};\n\nexport const calculateGasForUserOperation = ({\n userOperationData,\n}: CalculateGasForUserOperationParams): bigint => {\n // Sum all gas units\n const totalGasUnits =\n userOperationData.callGasLimit +\n userOperationData.verificationGasLimit +\n userOperationData.preVerificationGas;\n\n // Multiply by maxFeePerGas to get the total gas cost in wei\n const gasCost = totalGasUnits * userOperationData.maxFeePerGas;\n\n return gasCost;\n};\n","import type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { Hex } from 'viem';\n\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport { calculateGasForUserOperation } from '../utils/calculateGasForUserOperation';\nimport { prepareUserOperationWithKernelClient } from '../utils/prepareUserOperationWithKernelClient';\n\nexport type EstimateTransactionGasParams = {\n transaction: {\n data?: Hex;\n to: Hex;\n value: bigint;\n };\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Estimates the total gas for a transaction\n * @param params.transaction - The transaction to estimate the gas for\n * @param params.walletAccount - The wallet account that will be used to send the transaction\n * @returns The gas for the transaction in wei\n */\nexport const estimateTransactionGas = async ({\n walletAccount,\n transaction,\n}: EstimateTransactionGasParams): Promise<bigint | null> => {\n try {\n const kernelClientWithoutSponsorship =\n await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n withSponsorship: false,\n });\n\n const unsponsoredUserOperation = await prepareUserOperationWithKernelClient(\n {\n kernelClient: kernelClientWithoutSponsorship,\n transaction,\n }\n );\n\n return calculateGasForUserOperation({\n userOperationData: unsponsoredUserOperation,\n });\n } catch {\n return null;\n }\n};\n","export const isGasSponsorshipError = (err: unknown): boolean => {\n const errorWithMessage = err as { message?: string } | undefined;\n\n return (\n errorWithMessage?.message?.includes(\n 'userOp did not match any gas sponsoring policies'\n ) || false\n );\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport { constants } from '@zerodev/sdk';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\nimport { signAuthorization } from 'viem/actions';\n\nimport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\n\nexport type SignEip7702AuthorizationParams = {\n networkId?: string;\n smartWalletAccount: EvmWalletAccount;\n};\n\n/**\n * Signs an EIP-7702 authorization for ZeroDev kernel delegation.\n *\n * This function creates a signed authorization that allows a wallet to delegate\n * its execution to the ZeroDev kernel contract. The signed authorization can then\n * be passed to `createKernelClientForWalletAccount` via the `eip7702Auth` parameter.\n *\n * @param params - The parameters for signing the authorization.\n * @param params.smartWalletAccount - The EVM smart wallet account to sign the authorization for.\n * @param [params.networkId] - The network ID to use for signing. If not provided, uses the wallet's active network.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the signed EIP-7702 authorization.\n */\nexport const signEip7702Authorization = async (\n { smartWalletAccount, networkId }: SignEip7702AuthorizationParams,\n client = getDefaultClient()\n): Promise<SignAuthorizationReturnType> => {\n const walletClient = await getSignerForSmartWalletAccount(\n { smartWalletAccount },\n client\n );\n\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n 'No active network data found for this wallet account.'\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n return signAuthorization(walletClient, {\n chainId: viemChain.id,\n contractAddress: constants.KERNEL_7702_DELEGATION_ADDRESS,\n });\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport { name, version } from '../../package.json';\n\nassertPackageVersion(name, version);\n\nexport { addZerodevExtension } from '../addZerodevExtension';\nexport { canSponsorTransaction } from '../canSponsorTransaction';\nexport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nexport type { Eip7702Authorization } from '../createKernelClientForWalletAccount';\nexport { estimateTransactionGas } from '../estimateTransactionGas';\nexport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\nexport { isGasSponsorshipError } from '../isGasSponsorshipError';\nexport type { KernelClient } from '../KernelClient.types';\nexport { signEip7702Authorization } from '../signEip7702Authorization';\n"],"mappings":";;;;;;;;;;;;AAMA,MAAa,8BAA8B,WAAoC;AAkB7E,SAhBE,OAAO,MAAM,oBAAoB,QAC9B,eACC,WAAW,mBAAmB,mBAAmB,uBACjD,WAAW,YACP,aAAa,CACd,WAAW,iBAAiB,qBAAqB,IACpD,WAAW,WACX,WAAW,SACX,oCAAoC,WAAW,MAAM,KAAK,MAC7D,IAAI,EAAE,EAEmD,KAEzD,eAAe,WAAW,QAC5B;;;;;;;;;;;;;;;;;;;;;;AC+BH,MAAa,qCAAqC,OAChD,EACE,oBACA,kBAAkB,MAClB,iBACA,WACA,YAAY,oBACZ,cAAc,sBACd,iBACA,eAEF,SAAS,kBAAkB,KACD;CAC1B,IAAIA;AAEJ,KAAI,WAAW;AACb,gBAAc,2BACZ;GAAE,OAAO;GAAO;GAAW,EAC3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C,OACD,EAE+B;AAEhC,gBACE,aACA,wDACD;;AAKH,QAAO,kBAAkB,cAAc;EACrC,SAHgB,0BAA0B,YAAY,CAGnC;EACnB,iBAAiB,UAAU;EAC5B,CAAC;;;;;ACrEJ,qBAAqB,MAAM,QAAQ"}
|
|
1
|
+
{"version":3,"file":"index.esm.js","names":["networkData: NetworkData | undefined","createKernelAccount","signMessage","signMessageWithWalletAccount","chain: Chain","signMessage","signMessageUtils","networkData: NetworkData | undefined"],"sources":["../src/utils/getAllUserZerodevAddresses/getAllUserZerodevAddresses.ts","../src/createKernelClientForWalletAccount/createKernelClientForWalletAccount.ts","../src/utils/shouldSignWithEoa/shouldSignWithEoa.ts","../src/utils/signMessage/signMessage.ts","../src/utils/createZerodevWalletProvider/createZerodevWalletProvider.ts","../src/addZerodevExtension/addZerodevExtension.ts","../src/utils/prepareUserOperationFromCalls/prepareUserOperationFromCalls.ts","../src/canSponsorUserOperation/canSponsorUserOperation.ts","../src/utils/calculateGasForUserOperation/calculateGasForUserOperation.ts","../src/estimateUserOperationGas/estimateUserOperationGas.ts","../src/isGasSponsorshipError/isGasSponsorshipError.ts","../src/sendUserOperation/sendUserOperation.ts","../src/signEip7702Authorization/signEip7702Authorization.ts","../src/exports/index.ts"],"sourcesContent":["import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { getChainFromVerifiedCredentialChain } from '@dynamic-labs-sdk/client/core';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\n\nexport const getAllUserZerodevAddresses = (client: DynamicClient): string[] => {\n const zerodevWalletCredentials =\n client.user?.verifiedCredentials.filter(\n (credential) =>\n credential.walletProvider === WalletProviderEnum.SmartContractWallet &&\n credential.walletName\n ?.toLowerCase()\n .startsWith(ZERODEV_METADATA.normalizedWalletName) &&\n credential.address &&\n credential.chain &&\n getChainFromVerifiedCredentialChain(credential.chain) === 'EVM'\n ) ?? [];\n\n const zerodevAddresses: string[] = zerodevWalletCredentials.map(\n // casting because we're already filtering out credentials without an address\n (credential) => credential.address as string\n );\n\n return zerodevAddresses;\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport type { ZerodevBundlerProvider } from '@dynamic-labs/sdk-api-core';\nimport {\n createKernelAccountClient,\n getUserOperationGasPrice,\n} from '@zerodev/sdk';\nimport type { Hex } from 'viem';\nimport { createPublicClient, http } from 'viem';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\n\nimport type { KernelClient } from '../KernelClient.types';\nimport { createKernelAccount } from '../utils/createKernelAccount';\nimport { getPaymasterConfig } from '../utils/getPaymasterConfig';\nimport { getZerodevRpc } from '../utils/getZerodevRpc';\n\nexport type Eip7702Authorization = SignAuthorizationReturnType;\n\ntype CreateKernelClientForWalletAccountParams = {\n bundlerProvider?: ZerodevBundlerProvider;\n bundlerRpc?: string;\n eip7702Auth?: SignAuthorizationReturnType;\n gasTokenAddress?: Hex;\n networkId?: string;\n paymasterRpc?: string;\n smartWalletAccount: EvmWalletAccount;\n withSponsorship?: boolean;\n};\n\n/**\n * Creates a KernelClient instance for a given smart wallet account.\n *\n * @param params.smartWalletAccount - The smart wallet account to create the KernelClient for.\n * @param [params.bundlerProvider] - A custom bundler provider to use\n * @param [params.bundlerRpc] - A custom bundler RPC to use\n * @param [params.networkId] - The network ID to use for the KernelClient.\n * If not provided, the network ID will be fetched from the active network data.\n * @param [params.paymasterRpc] - A custom paymaster RPC to use\n * @param [params.gasTokenAddress] - The address of a custom ERC20 token to use as a gas token\n * @param [params.withSponsorship] - Whether to use sponsorship for the KernelClient or not (default is true).\n * @param [params.eip7702Auth] - A pre-signed EIP-7702 authorization. When provided, the kernel client uses \n * this authorization instead of signing a new one internally. Useful for singleUse MFA flows where you need\n * to separate the authorization signing step from the transaction step.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to a KernelClient instance.\n */\nexport const createKernelClientForWalletAccount = async (\n {\n smartWalletAccount,\n withSponsorship = true,\n bundlerProvider,\n networkId,\n bundlerRpc: bundlerRpcOverride,\n paymasterRpc: paymasterRpcOverride,\n gasTokenAddress,\n eip7702Auth,\n }: CreateKernelClientForWalletAccountParams,\n client = getDefaultClient()\n): Promise<KernelClient> => {\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n `No active network data found for this wallet account.`\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n const bundlerRpc =\n bundlerRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'bundler',\n },\n client\n );\n\n const bundlerTransport = http(bundlerRpc);\n\n const publicClient = createPublicClient({\n chain: viemChain,\n transport: bundlerTransport,\n });\n\n const account = await createKernelAccount(\n {\n eip7702Auth,\n publicClient,\n smartWalletAccount,\n },\n client\n );\n\n const paymasterRpc =\n paymasterRpcOverride ??\n getZerodevRpc(\n {\n bundlerProvider,\n networkId: networkData.networkId,\n rpcType: 'paymaster',\n },\n client\n );\n\n const paymasterConfig = withSponsorship\n ? getPaymasterConfig({\n chain: viemChain,\n gasTokenAddress,\n paymasterRpc,\n })\n : {};\n\n return createKernelAccountClient({\n account,\n bundlerTransport,\n chain: viemChain,\n client: publicClient,\n userOperation: {\n estimateFeesPerGas: async ({ bundlerClient }) =>\n getUserOperationGasPrice(bundlerClient),\n },\n ...paymasterConfig,\n });\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { KernelClient } from '../../KernelClient.types';\nimport { shouldUseEIP7702 } from '../shouldUseEIP7702';\n\ntype ShouldSignWithEoaParams = {\n kernelClient: KernelClient;\n smartWalletAccount: EvmWalletAccount;\n};\n\nexport const shouldSignWithEoa = async (\n { kernelClient, smartWalletAccount }: ShouldSignWithEoaParams,\n client: DynamicClient\n) => {\n const useEIP7702 = shouldUseEIP7702({ smartWalletAccount }, client);\n\n if (!useEIP7702) {\n return false;\n }\n\n const isDeployed = await kernelClient.account.isDeployed();\n\n return !isDeployed;\n};\n","import {\n type DynamicClient,\n getOwnerWalletAccountForSmartWalletAccount,\n signMessage as signMessageWithWalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport { createKernelClientForWalletAccount } from '../../createKernelClientForWalletAccount';\nimport { shouldSignWithEoa } from '../shouldSignWithEoa';\n\ntype SignMessageParams = {\n message: string;\n walletAccount: EvmWalletAccount;\n};\n\nexport const signMessage = async (\n { walletAccount, message }: SignMessageParams,\n client: DynamicClient\n): Promise<{ signature: string }> => {\n const kernelClient = await createKernelClientForWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n const shouldUseEoa = await shouldSignWithEoa(\n {\n kernelClient,\n smartWalletAccount: walletAccount,\n },\n client\n );\n\n if (shouldUseEoa) {\n const eoaWalletAccount = getOwnerWalletAccountForSmartWalletAccount(\n { smartWalletAccount: walletAccount },\n client\n );\n\n assertDefined(eoaWalletAccount, 'Eoa wallet account not found');\n\n const { signature } = await signMessageWithWalletAccount({\n message,\n walletAccount: eoaWalletAccount,\n });\n\n return { signature };\n }\n\n const signature = await kernelClient.signMessage({ message });\n return { signature };\n};\n","import {\n type Chain,\n type DynamicClient,\n InvalidParamError,\n UnrecognizedNetworkError,\n type WalletAccount,\n} from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n formatWalletProviderGroupKey,\n formatWalletProviderKey,\n getActiveNetworkIdFromLastKnownRegistry,\n switchActiveNetworkInLastKnownRegistry,\n} from '@dynamic-labs-sdk/client/core';\nimport {\n type EvmWalletProvider,\n isEvmWalletAccount,\n} from '@dynamic-labs-sdk/evm';\nimport { WalletProviderEnum } from '@dynamic-labs/sdk-api-core';\n\nimport { ZERODEV_METADATA } from '../../constants';\nimport { getAllUserZerodevAddresses } from '../getAllUserZerodevAddresses';\nimport { getZerodevChainProviderForNetworkId } from '../getZerodevChainProviderForNetworkId';\nimport { signMessage as signMessageUtils } from '../signMessage';\n\nexport const createZerodevWalletProvider = (\n client: DynamicClient\n): EvmWalletProvider => {\n const chain: Chain = 'EVM';\n const walletProviderType = WalletProviderEnum.SmartContractWallet;\n const key = formatWalletProviderKey({\n chain,\n displayName: ZERODEV_METADATA.displayName,\n walletProviderType,\n });\n\n const getActiveNetworkId = async () =>\n getActiveNetworkIdFromLastKnownRegistry({\n client,\n walletProviderKey: key,\n });\n\n const getConnectedAddresses = async () => {\n const zerodevAddresses = getAllUserZerodevAddresses(client);\n\n return {\n addresses: zerodevAddresses,\n };\n };\n\n const signMessage = async ({\n walletAccount,\n message,\n }: {\n message: string;\n walletAccount?: WalletAccount;\n }) => {\n assertDefined(walletAccount, 'Wallet account is required');\n\n if (!isEvmWalletAccount(walletAccount)) {\n throw new InvalidParamError(`walletAccount is not an EVM wallet account`);\n }\n\n return signMessageUtils({ message, walletAccount }, client);\n };\n\n const switchActiveNetwork = async ({ networkId }: { networkId: string }) => {\n const isNetworkEnabled = getZerodevChainProviderForNetworkId(\n { networkId },\n client\n );\n\n if (!isNetworkEnabled) {\n throw new UnrecognizedNetworkError({\n networkId,\n originalError: null,\n walletProviderKey: key,\n });\n }\n\n return switchActiveNetworkInLastKnownRegistry({\n client,\n networkId,\n walletProviderKey: key,\n });\n };\n\n return {\n chain,\n getActiveNetworkId,\n getConnectedAddresses,\n groupKey: formatWalletProviderGroupKey(ZERODEV_METADATA.displayName),\n key,\n metadata: {\n displayName: ZERODEV_METADATA.displayName,\n icon: ZERODEV_METADATA.icon,\n },\n signMessage,\n switchActiveNetwork,\n walletProviderType,\n };\n};\n","import {\n WalletProviderPriority,\n getDefaultClient,\n getWalletProviderRegistry,\n hasExtension,\n registerExtension,\n} from '@dynamic-labs-sdk/client/core';\n\nimport { createZerodevWalletProvider } from '../utils/createZerodevWalletProvider';\n\nexport const ZERODEV_EXTENSION_KEY = 'zerodev';\n\n/**\n * Adds the ZeroDev extension to the Dynamic client.\n *\n * This extension enables Account Abstraction integration with ZeroDev\n *\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n */\nexport const addZerodevExtension = (client = getDefaultClient()) => {\n if (hasExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client)) {\n return;\n }\n\n registerExtension({ extensionKey: ZERODEV_EXTENSION_KEY }, client);\n\n const walletProviderRegistry = getWalletProviderRegistry(client);\n\n const walletProvider = createZerodevWalletProvider(client);\n\n walletProviderRegistry.register({\n priority: WalletProviderPriority.WALLET_SDK,\n walletProvider,\n });\n};\n","import type { BatchCall } from '../../BatchCall.types';\nimport type { KernelClient } from '../../KernelClient.types';\n\nexport type PrepareUserOperationFromCallsParams = {\n calls: BatchCall[];\n kernelClient: KernelClient;\n};\n\n/**\n * Prepares a user operation from an array of calls\n * Replaces prepareUserOperationWithKernelClient to handle both single and batch transactions\n *\n * @param params.kernelClient - The kernel client to use for preparing the user operation\n * @param params.calls - Array of calls (can be single call or multiple calls)\n * @returns Promise resolving to the prepared user operation\n */\nexport const prepareUserOperationFromCalls = async ({\n kernelClient,\n calls,\n}: PrepareUserOperationFromCallsParams) => {\n // Normalize calls to ensure data field exists\n const normalizedCalls = calls.map((call) => ({\n data: call.data ?? '0x',\n to: call.to,\n value: call.value,\n }));\n\n const callData = await kernelClient.account.encodeCalls(normalizedCalls);\n\n return kernelClient.prepareUserOperation({\n callData,\n });\n};\n","import { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { BatchCall } from '../BatchCall.types';\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport type { KernelClient } from '../KernelClient.types';\nimport { prepareUserOperationFromCalls } from '../utils/prepareUserOperationFromCalls';\n\ntype CanSponsorUserOperationBaseParams = {\n calls: BatchCall[];\n};\n\ntype CanSponsorUserOperationWithWalletParams =\n CanSponsorUserOperationBaseParams & {\n kernelClient?: never;\n walletAccount: EvmWalletAccount;\n };\n\ntype CanSponsorUserOperationWithClientParams =\n CanSponsorUserOperationBaseParams & {\n kernelClient: KernelClient;\n walletAccount?: never;\n };\n\nexport type CanSponsorUserOperationParams =\n | CanSponsorUserOperationWithWalletParams\n | CanSponsorUserOperationWithClientParams;\n\n/**\n * Checks if a user operation can be sponsored by the paymaster\n * Handles both single transactions and batch transactions\n *\n * @param params.calls - Array of calls (single call or multiple calls)\n * @param params.kernelClient - Optional kernel client with sponsorship configured\n * @param params.walletAccount - The wallet account to use (required if kernelClient not provided)\n * @returns True if the user operation can be sponsored, false otherwise\n */\nexport const canSponsorUserOperation = async ({\n walletAccount,\n calls,\n kernelClient,\n}: CanSponsorUserOperationParams): Promise<boolean> => {\n let kernelClientToUse = kernelClient;\n\n if (!kernelClientToUse) {\n assertDefined(\n walletAccount,\n 'Please provide either a wallet account or a kernel client in the parameters'\n );\n\n kernelClientToUse = await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n });\n }\n\n try {\n const sponsorResult = await prepareUserOperationFromCalls({\n calls,\n kernelClient: kernelClientToUse,\n });\n\n const hasPaymaster = sponsorResult.paymasterAndData !== '0x';\n\n return hasPaymaster;\n } catch {\n return false;\n }\n};\n","import type { UserOperation } from 'viem/account-abstraction';\n\ntype CalculateGasForUserOperationParams = {\n userOperationData: Pick<\n UserOperation,\n | 'callGasLimit'\n | 'verificationGasLimit'\n | 'preVerificationGas'\n | 'maxFeePerGas'\n >;\n};\n\nexport const calculateGasForUserOperation = ({\n userOperationData,\n}: CalculateGasForUserOperationParams): bigint => {\n // Sum all gas units\n const totalGasUnits =\n userOperationData.callGasLimit +\n userOperationData.verificationGasLimit +\n userOperationData.preVerificationGas;\n\n // Multiply by maxFeePerGas to get the total gas cost in wei\n const gasCost = totalGasUnits * userOperationData.maxFeePerGas;\n\n return gasCost;\n};\n","import type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\n\nimport type { BatchCall } from '../BatchCall.types';\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport { calculateGasForUserOperation } from '../utils/calculateGasForUserOperation';\nimport { prepareUserOperationFromCalls } from '../utils/prepareUserOperationFromCalls';\n\nexport type EstimateUserOperationGasParams = {\n calls: BatchCall[];\n walletAccount: EvmWalletAccount;\n};\n\n/**\n * Estimates the total gas cost for a user operation with one or more calls\n * Handles both single transactions and batch transactions\n *\n * @param params.calls - Array of calls (single call or multiple calls)\n * @param params.walletAccount - The wallet account that will execute the user operation\n * @returns The estimated gas cost in wei, or null if estimation fails\n */\nexport const estimateUserOperationGas = async ({\n walletAccount,\n calls,\n}: EstimateUserOperationGasParams): Promise<bigint | null> => {\n try {\n const kernelClientWithoutSponsorship =\n await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n withSponsorship: false,\n });\n\n const unsponsoredUserOperation = await prepareUserOperationFromCalls({\n calls,\n kernelClient: kernelClientWithoutSponsorship,\n });\n\n return calculateGasForUserOperation({\n userOperationData: unsponsoredUserOperation,\n });\n } catch {\n return null;\n }\n};\n","export const isGasSponsorshipError = (err: unknown): boolean => {\n const errorWithMessage = err as { message?: string } | undefined;\n\n return (\n errorWithMessage?.message?.includes(\n 'userOp did not match any gas sponsoring policies'\n ) || false\n );\n};\n","import { assertDefined } from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport type { UserOperationReceipt } from 'viem/account-abstraction';\n\nimport type { BatchCall } from '../BatchCall.types';\nimport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nimport type { KernelClient } from '../KernelClient.types';\nimport { prepareUserOperationFromCalls } from '../utils/prepareUserOperationFromCalls';\n\ntype SendUserOperationBaseParams = {\n calls: BatchCall[];\n};\n\ntype SendUserOperationWithWalletParams = SendUserOperationBaseParams & {\n kernelClient?: never;\n walletAccount: EvmWalletAccount;\n withSponsorship?: boolean;\n};\n\ntype SendUserOperationWithClientParams = SendUserOperationBaseParams & {\n kernelClient: KernelClient;\n walletAccount?: never;\n withSponsorship?: never;\n};\n\nexport type SendUserOperationParams =\n | SendUserOperationWithWalletParams\n | SendUserOperationWithClientParams;\n\n/**\n * Sends a user operation with one or more calls\n * Handles both single transactions and batch transactions\n *\n * @param params.calls - Array of calls (single call or multiple calls)\n * @param params.kernelClient - Optional pre-configured kernel client\n * @param params.walletAccount - The wallet account to use (required if kernelClient not provided)\n * @param params.withSponsorship - Whether to use sponsorship (default: true, only used with walletAccount)\n * @returns Promise resolving to the UserOperation receipt\n */\nexport const sendUserOperation = async ({\n walletAccount,\n calls,\n kernelClient,\n withSponsorship = true,\n}: SendUserOperationParams): Promise<UserOperationReceipt> => {\n let kernelClientToUse = kernelClient;\n\n if (!kernelClientToUse) {\n assertDefined(\n walletAccount,\n 'Please provide either a wallet account or a kernel client in the parameters'\n );\n\n kernelClientToUse = await createKernelClientForWalletAccount({\n smartWalletAccount: walletAccount,\n withSponsorship,\n });\n }\n\n const userOperation = await prepareUserOperationFromCalls({\n calls,\n kernelClient: kernelClientToUse,\n });\n\n // Type cast needed: prepareUserOperation returns a fully prepared UserOperation with all fields,\n // but sendUserOperation's discriminated union types expect specific field combinations.\n // This is safe as the prepared operation is compatible at runtime.\n const userOperationHash = await kernelClientToUse.sendUserOperation(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n userOperation as any\n );\n\n return kernelClientToUse.waitForUserOperationReceipt({\n hash: userOperationHash,\n });\n};\n","import type { NetworkData } from '@dynamic-labs-sdk/client';\nimport { getActiveNetworkData } from '@dynamic-labs-sdk/client';\nimport {\n assertDefined,\n getDefaultClient,\n getNetworkDataForNetworkId,\n} from '@dynamic-labs-sdk/client/core';\nimport type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';\nimport { mapNetworkDataToViemChain } from '@dynamic-labs-sdk/evm/viem';\nimport { constants } from '@zerodev/sdk';\nimport type { SignAuthorizationReturnType } from 'viem/accounts';\nimport { signAuthorization } from 'viem/actions';\n\nimport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\n\nexport type SignEip7702AuthorizationParams = {\n networkId?: string;\n smartWalletAccount: EvmWalletAccount;\n};\n\n/**\n * Signs an EIP-7702 authorization for ZeroDev kernel delegation.\n *\n * This function creates a signed authorization that allows a wallet to delegate\n * its execution to the ZeroDev kernel contract. The signed authorization can then\n * be passed to `createKernelClientForWalletAccount` via the `eip7702Auth` parameter.\n *\n * @param params - The parameters for signing the authorization.\n * @param params.smartWalletAccount - The EVM smart wallet account to sign the authorization for.\n * @param [params.networkId] - The network ID to use for signing. If not provided, uses the wallet's active network.\n * @param [client] - The Dynamic client instance. Only required when using multiple Dynamic clients.\n * @returns A promise that resolves to the signed EIP-7702 authorization.\n */\nexport const signEip7702Authorization = async (\n { smartWalletAccount, networkId }: SignEip7702AuthorizationParams,\n client = getDefaultClient()\n): Promise<SignAuthorizationReturnType> => {\n const walletClient = await getSignerForSmartWalletAccount(\n { smartWalletAccount },\n client\n );\n\n let networkData: NetworkData | undefined;\n\n if (networkId) {\n networkData = getNetworkDataForNetworkId(\n { chain: 'EVM', networkId },\n client\n );\n\n assertDefined(\n networkData,\n `No network data found for specified network ID: ${networkId}. Make sure the network is enabled for your project.`\n );\n } else {\n const activeNetworkData = await getActiveNetworkData(\n { walletAccount: smartWalletAccount },\n client\n );\n\n networkData = activeNetworkData.networkData;\n\n assertDefined(\n networkData,\n 'No active network data found for this wallet account.'\n );\n }\n\n const viemChain = mapNetworkDataToViemChain(networkData);\n\n return signAuthorization(walletClient, {\n chainId: viemChain.id,\n contractAddress: constants.KERNEL_7702_DELEGATION_ADDRESS,\n });\n};\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport { name, version } from '../../package.json';\n\nassertPackageVersion(name, version);\n\nexport { addZerodevExtension } from '../addZerodevExtension';\nexport type { BatchCall } from '../BatchCall.types';\nexport { canSponsorUserOperation } from '../canSponsorUserOperation';\nexport type { CanSponsorUserOperationParams } from '../canSponsorUserOperation';\nexport { createKernelClientForWalletAccount } from '../createKernelClientForWalletAccount';\nexport type { Eip7702Authorization } from '../createKernelClientForWalletAccount';\nexport { estimateUserOperationGas } from '../estimateUserOperationGas';\nexport type { EstimateUserOperationGasParams } from '../estimateUserOperationGas';\nexport { getSignerForSmartWalletAccount } from '../getSignerForSmartWalletAccount';\nexport { isGasSponsorshipError } from '../isGasSponsorshipError';\nexport type { KernelClient } from '../KernelClient.types';\nexport { sendUserOperation } from '../sendUserOperation';\nexport type { SendUserOperationParams } from '../sendUserOperation';\nexport { signEip7702Authorization } from '../signEip7702Authorization';\n"],"mappings":";;;;;;;;;;;;AAMA,MAAa,8BAA8B,WAAoC;AAkB7E,SAhBE,OAAO,MAAM,oBAAoB,QAC9B,eACC,WAAW,mBAAmB,mBAAmB,uBACjD,WAAW,YACP,aAAa,CACd,WAAW,iBAAiB,qBAAqB,IACpD,WAAW,WACX,WAAW,SACX,oCAAoC,WAAW,MAAM,KAAK,MAC7D,IAAI,EAAE,EAEmD,KAEzD,eAAe,WAAW,QAC5B;;;;;;;;;;;;;;;;;;;;;;AC+BH,MAAa,qCAAqC,OAChD,EACE,oBACA,kBAAkB,MAClB,iBACA,WACA,YAAY,oBACZ,cAAc,sBACd,iBACA,eAEF,SAAS,kBAAkB,KACD;CAC1B,IAAIA;AAEJ,KAAI,WAAW;AACb,gBAAc,2BACZ;GAAE,OAA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ACA,cAAc;EACf,CAAC;CAKF,MAAM,oBAAoB,MAAM,kBAAkB,kBAEhD,cACD;AAED,QAAO,kBAAkB,4BAA4B,EACnD,MAAM,mBACP,CAAC;;;;;;;;;;;;;;;;;;ACzCJ,MAAa,2BAA2B,OACtC,EAAE,oBAAoB,aACtB,SAAS,kBAAkB,KACc;CACzC,MAAM,eAAe,MAAM,+BACzB,EAAE,oBAAoB,EACtB,OACD;CAED,IAAIC;AAEJ,KAAI,WAAW;AACb,gBAAc,2BACZ;GAAE,OAAO;GAAO;GAAW,EAC3B,OACD;AAED,gBACE,aACA,mDAAmD,UAAU,sDAC9D;QACI;AAML,iBAL0B,MAAM,qBAC9B,EAAE,eAAe,oBAAoB,EACrC,OACD,EAE+B;AAEhC,gBACE,aACA,wDACD;;AAKH,QAAO,kBAAkB,cAAc;EACrC,SAHgB,0BAA0B,YAAY,CAGnC;EACnB,iBAAiB,UAAU;EAC5B,CAAC;;;;;ACrEJ,qBAAqB,MAAM,QAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sendUserOperation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { EvmWalletAccount } from '@dynamic-labs-sdk/evm';
|
|
2
|
+
import type { UserOperationReceipt } from 'viem/account-abstraction';
|
|
3
|
+
import type { BatchCall } from '../BatchCall.types';
|
|
4
|
+
import type { KernelClient } from '../KernelClient.types';
|
|
5
|
+
type SendUserOperationBaseParams = {
|
|
6
|
+
calls: BatchCall[];
|
|
7
|
+
};
|
|
8
|
+
type SendUserOperationWithWalletParams = SendUserOperationBaseParams & {
|
|
9
|
+
kernelClient?: never;
|
|
10
|
+
walletAccount: EvmWalletAccount;
|
|
11
|
+
withSponsorship?: boolean;
|
|
12
|
+
};
|
|
13
|
+
type SendUserOperationWithClientParams = SendUserOperationBaseParams & {
|
|
14
|
+
kernelClient: KernelClient;
|
|
15
|
+
walletAccount?: never;
|
|
16
|
+
withSponsorship?: never;
|
|
17
|
+
};
|
|
18
|
+
export type SendUserOperationParams = SendUserOperationWithWalletParams | SendUserOperationWithClientParams;
|
|
19
|
+
/**
|
|
20
|
+
* Sends a user operation with one or more calls
|
|
21
|
+
* Handles both single transactions and batch transactions
|
|
22
|
+
*
|
|
23
|
+
* @param params.calls - Array of calls (single call or multiple calls)
|
|
24
|
+
* @param params.kernelClient - Optional pre-configured kernel client
|
|
25
|
+
* @param params.walletAccount - The wallet account to use (required if kernelClient not provided)
|
|
26
|
+
* @param params.withSponsorship - Whether to use sponsorship (default: true, only used with walletAccount)
|
|
27
|
+
* @returns Promise resolving to the UserOperation receipt
|
|
28
|
+
*/
|
|
29
|
+
export declare const sendUserOperation: ({ walletAccount, calls, kernelClient, withSponsorship, }: SendUserOperationParams) => Promise<UserOperationReceipt>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=sendUserOperation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendUserOperation.d.ts","sourceRoot":"","sources":["../../src/sendUserOperation/sendUserOperation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAG1D,KAAK,2BAA2B,GAAG;IACjC,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB,CAAC;AAEF,KAAK,iCAAiC,GAAG,2BAA2B,GAAG;IACrE,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,aAAa,EAAE,gBAAgB,CAAC;IAChC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,KAAK,iCAAiC,GAAG,2BAA2B,GAAG;IACrE,YAAY,EAAE,YAAY,CAAC;IAC3B,aAAa,CAAC,EAAE,KAAK,CAAC;IACtB,eAAe,CAAC,EAAE,KAAK,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAC/B,iCAAiC,GACjC,iCAAiC,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,6DAK3B,uBAAuB,KAAG,OAAO,CAAC,oBAAoB,CA+BxD,CAAC"}
|