@zerodev/sdk 5.0.0 → 5.0.2

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.
Files changed (35) hide show
  1. package/_cjs/actions/paymaster/sponsorUserOperation.js +1 -3
  2. package/_cjs/actions/paymaster/sponsorUserOperation.js.map +1 -1
  3. package/_cjs/gasTokenChainAddresses.js +358 -0
  4. package/_cjs/gasTokenChainAddresses.js.map +1 -0
  5. package/_cjs/index.js +3 -1
  6. package/_cjs/index.js.map +1 -1
  7. package/_cjs/types/kernel.js.map +1 -1
  8. package/_cjs/utils.js +32 -3
  9. package/_cjs/utils.js.map +1 -1
  10. package/_esm/actions/paymaster/sponsorUserOperation.js +1 -3
  11. package/_esm/actions/paymaster/sponsorUserOperation.js.map +1 -1
  12. package/_esm/gasTokenChainAddresses.js +355 -0
  13. package/_esm/gasTokenChainAddresses.js.map +1 -0
  14. package/_esm/index.js +1 -0
  15. package/_esm/index.js.map +1 -1
  16. package/_esm/types/kernel.js.map +1 -1
  17. package/_esm/utils.js +31 -3
  18. package/_esm/utils.js.map +1 -1
  19. package/_types/actions/paymaster/sponsorUserOperation.d.ts +0 -2
  20. package/_types/actions/paymaster/sponsorUserOperation.d.ts.map +1 -1
  21. package/_types/clients/kernelAccountClient.d.ts +8 -8
  22. package/_types/gasTokenChainAddresses.d.ts +27 -0
  23. package/_types/gasTokenChainAddresses.d.ts.map +1 -0
  24. package/_types/index.d.ts +1 -0
  25. package/_types/index.d.ts.map +1 -1
  26. package/_types/types/kernel.d.ts +10 -2
  27. package/_types/types/kernel.d.ts.map +1 -1
  28. package/_types/utils.d.ts +11 -2
  29. package/_types/utils.d.ts.map +1 -1
  30. package/actions/paymaster/sponsorUserOperation.ts +1 -13
  31. package/gasTokenChainAddresses.ts +670 -0
  32. package/index.ts +4 -0
  33. package/package.json +1 -1
  34. package/types/kernel.ts +10 -8
  35. package/utils.ts +42 -2
package/types/kernel.ts CHANGED
@@ -20,14 +20,6 @@ export type ZeroDevPaymasterRpcSchema = [
20
20
  entryPointAddress: Address
21
21
  gasTokenData?: {
22
22
  tokenAddress: Hex
23
- erc20UserOp: PartialBy<
24
- UserOperationWithBigIntAsHex,
25
- | "callGasLimit"
26
- | "preVerificationGas"
27
- | "verificationGasLimit"
28
- | "paymasterAndData"
29
- >
30
- erc20CallData: Hex
31
23
  }
32
24
  shouldOverrideFee?: boolean
33
25
  manualGasEstimation?: boolean
@@ -42,6 +34,16 @@ export type ZeroDevPaymasterRpcSchema = [
42
34
  maxFeePerGas: Hex
43
35
  maxPriorityFeePerGas: Hex
44
36
  }
37
+ },
38
+ {
39
+ Method: "zd_pm_accounts"
40
+ Parameters: [
41
+ {
42
+ chainId: number
43
+ entryPointAddress: Address
44
+ }
45
+ ]
46
+ ReturnType: Address[]
45
47
  }
46
48
  ]
47
49
 
package/utils.ts CHANGED
@@ -5,8 +5,12 @@ import {
5
5
  type WalletClient,
6
6
  createWalletClient,
7
7
  custom,
8
+ encodeFunctionData,
9
+ erc20Abi,
8
10
  zeroAddress
9
11
  } from "viem"
12
+ import { KERNEL_ADDRESSES } from "./accounts/index.js"
13
+ import type { ZeroDevPaymasterClient } from "./clients/paymasterClient.js"
10
14
  import { KernelImplToVersionMap, LATEST_KERNEL_VERSION } from "./constants.js"
11
15
 
12
16
  export const getKernelVersion = (kernelImpl?: Address): string => {
@@ -23,9 +27,15 @@ interface EIP1193Provider {
23
27
  }
24
28
 
25
29
  export const providerToSmartAccountSigner = async (
26
- provider: EIP1193Provider
30
+ provider: EIP1193Provider,
31
+ signerAddress?: Hex
27
32
  ) => {
28
- const [account] = await provider.request({ method: "eth_requestAccounts" })
33
+ let account: Hex
34
+ if (!signerAddress) {
35
+ ;[account] = await provider.request({ method: "eth_requestAccounts" })
36
+ } else {
37
+ account = signerAddress
38
+ }
29
39
  const walletClient = createWalletClient({
30
40
  account: account as Hex,
31
41
  transport: custom(provider)
@@ -39,3 +49,33 @@ export const walletClientToSmartAccountSigner = (
39
49
  // biome-ignore lint/suspicious/noExplicitAny: I believe this type error is because of a version mismatch between viem and permissionless
40
50
  return walletClientToCustomSigner(walletClient as any)
41
51
  }
52
+
53
+ export const getERC20PaymasterApproveData = async (
54
+ client: ZeroDevPaymasterClient,
55
+ {
56
+ tokenAddress,
57
+ approveAmount
58
+ }: {
59
+ tokenAddress: Address
60
+ approveAmount: bigint
61
+ }
62
+ ): Promise<{ to: Address; value: bigint; data: Hex }> => {
63
+ const response = await client.request({
64
+ method: "zd_pm_accounts",
65
+ params: [
66
+ {
67
+ chainId: client.chain?.id as number,
68
+ entryPointAddress: KERNEL_ADDRESSES.ENTRYPOINT_V0_6
69
+ }
70
+ ]
71
+ })
72
+ return {
73
+ to: tokenAddress,
74
+ data: encodeFunctionData({
75
+ abi: erc20Abi,
76
+ functionName: "approve",
77
+ args: [response[0], approveAmount]
78
+ }),
79
+ value: 0n
80
+ }
81
+ }