viem 2.9.28 → 2.9.30

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 (127) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/_cjs/chains/definitions/cyber.js +2 -2
  3. package/_cjs/chains/definitions/cyber.js.map +1 -1
  4. package/_cjs/chains/definitions/otimDevnet.js +24 -0
  5. package/_cjs/chains/definitions/otimDevnet.js.map +1 -0
  6. package/_cjs/chains/definitions/telcoinTestnet.js +22 -0
  7. package/_cjs/chains/definitions/telcoinTestnet.js.map +1 -0
  8. package/_cjs/chains/index.js +7 -3
  9. package/_cjs/chains/index.js.map +1 -1
  10. package/_cjs/errors/version.js +1 -1
  11. package/_cjs/experimental/eip3074/constants/abis.js +123 -0
  12. package/_cjs/experimental/eip3074/constants/abis.js.map +1 -0
  13. package/_cjs/experimental/eip3074/invokers/coders/batchInvokerCoder.js +26 -0
  14. package/_cjs/experimental/eip3074/invokers/coders/batchInvokerCoder.js.map +1 -0
  15. package/_cjs/experimental/eip3074/invokers/coders/defineInvokerCoder.js +8 -0
  16. package/_cjs/experimental/eip3074/invokers/coders/defineInvokerCoder.js.map +1 -0
  17. package/_cjs/experimental/eip3074/invokers/getInvoker.js +64 -0
  18. package/_cjs/experimental/eip3074/invokers/getInvoker.js.map +1 -0
  19. package/_cjs/experimental/index.js +7 -1
  20. package/_cjs/experimental/index.js.map +1 -1
  21. package/_cjs/utils/rpc/http.js +6 -2
  22. package/_cjs/utils/rpc/http.js.map +1 -1
  23. package/_cjs/utils/signature/recoverTransactionAddress.js +6 -8
  24. package/_cjs/utils/signature/recoverTransactionAddress.js.map +1 -1
  25. package/_cjs/utils/signature/signatureToHex.js +7 -7
  26. package/_cjs/utils/signature/signatureToHex.js.map +1 -1
  27. package/_cjs/utils/transaction/parseTransaction.js +1 -1
  28. package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
  29. package/_cjs/zksync/constants/abis.js +39 -1
  30. package/_cjs/zksync/constants/abis.js.map +1 -1
  31. package/_cjs/zksync/index.js +5 -1
  32. package/_cjs/zksync/index.js.map +1 -1
  33. package/_cjs/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js +16 -0
  34. package/_cjs/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js.map +1 -0
  35. package/_cjs/zksync/utils/paymaster/getGeneralPaymasterInput.js +16 -0
  36. package/_cjs/zksync/utils/paymaster/getGeneralPaymasterInput.js.map +1 -0
  37. package/_esm/chains/definitions/cyber.js +2 -2
  38. package/_esm/chains/definitions/cyber.js.map +1 -1
  39. package/_esm/chains/definitions/otimDevnet.js +21 -0
  40. package/_esm/chains/definitions/otimDevnet.js.map +1 -0
  41. package/_esm/chains/definitions/telcoinTestnet.js +19 -0
  42. package/_esm/chains/definitions/telcoinTestnet.js.map +1 -0
  43. package/_esm/chains/index.js +2 -0
  44. package/_esm/chains/index.js.map +1 -1
  45. package/_esm/errors/version.js +1 -1
  46. package/_esm/experimental/eip3074/constants/abis.js +120 -0
  47. package/_esm/experimental/eip3074/constants/abis.js.map +1 -0
  48. package/_esm/experimental/eip3074/invokers/coders/batchInvokerCoder.js +22 -0
  49. package/_esm/experimental/eip3074/invokers/coders/batchInvokerCoder.js.map +1 -0
  50. package/_esm/experimental/eip3074/invokers/coders/defineInvokerCoder.js +4 -0
  51. package/_esm/experimental/eip3074/invokers/coders/defineInvokerCoder.js.map +1 -0
  52. package/_esm/experimental/eip3074/invokers/getInvoker.js +60 -0
  53. package/_esm/experimental/eip3074/invokers/getInvoker.js.map +1 -0
  54. package/_esm/experimental/index.js +3 -0
  55. package/_esm/experimental/index.js.map +1 -1
  56. package/_esm/utils/rpc/http.js +6 -2
  57. package/_esm/utils/rpc/http.js.map +1 -1
  58. package/_esm/utils/signature/recoverTransactionAddress.js +6 -8
  59. package/_esm/utils/signature/recoverTransactionAddress.js.map +1 -1
  60. package/_esm/utils/signature/signatureToHex.js +7 -8
  61. package/_esm/utils/signature/signatureToHex.js.map +1 -1
  62. package/_esm/utils/transaction/parseTransaction.js +1 -1
  63. package/_esm/utils/transaction/parseTransaction.js.map +1 -1
  64. package/_esm/zksync/constants/abis.js +38 -0
  65. package/_esm/zksync/constants/abis.js.map +1 -1
  66. package/_esm/zksync/index.js +2 -0
  67. package/_esm/zksync/index.js.map +1 -1
  68. package/_esm/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js +13 -0
  69. package/_esm/zksync/utils/paymaster/getApprovalBasedPaymasterInput.js.map +1 -0
  70. package/_esm/zksync/utils/paymaster/getGeneralPaymasterInput.js +12 -0
  71. package/_esm/zksync/utils/paymaster/getGeneralPaymasterInput.js.map +1 -0
  72. package/_types/accounts/types.d.ts +1 -1
  73. package/_types/accounts/types.d.ts.map +1 -1
  74. package/_types/chains/definitions/cyber.d.ts +2 -2
  75. package/_types/chains/definitions/otimDevnet.d.ts +38 -0
  76. package/_types/chains/definitions/otimDevnet.d.ts.map +1 -0
  77. package/_types/chains/definitions/telcoinTestnet.d.ts +35 -0
  78. package/_types/chains/definitions/telcoinTestnet.d.ts.map +1 -0
  79. package/_types/chains/index.d.ts +2 -0
  80. package/_types/chains/index.d.ts.map +1 -1
  81. package/_types/errors/version.d.ts +1 -1
  82. package/_types/experimental/eip3074/actions/signAuthMessage.d.ts +5 -5
  83. package/_types/experimental/eip3074/actions/signAuthMessage.d.ts.map +1 -1
  84. package/_types/experimental/eip3074/constants/abis.d.ts +91 -0
  85. package/_types/experimental/eip3074/constants/abis.d.ts.map +1 -0
  86. package/_types/experimental/eip3074/invokers/coders/batchInvokerCoder.d.ts +11 -0
  87. package/_types/experimental/eip3074/invokers/coders/batchInvokerCoder.d.ts.map +1 -0
  88. package/_types/experimental/eip3074/invokers/coders/defineInvokerCoder.d.ts +14 -0
  89. package/_types/experimental/eip3074/invokers/coders/defineInvokerCoder.d.ts.map +1 -0
  90. package/_types/experimental/eip3074/invokers/getInvoker.d.ts +48 -0
  91. package/_types/experimental/eip3074/invokers/getInvoker.d.ts.map +1 -0
  92. package/_types/experimental/index.d.ts +3 -0
  93. package/_types/experimental/index.d.ts.map +1 -1
  94. package/_types/utils/rpc/http.d.ts.map +1 -1
  95. package/_types/utils/signature/recoverTransactionAddress.d.ts +1 -1
  96. package/_types/utils/signature/recoverTransactionAddress.d.ts.map +1 -1
  97. package/_types/utils/signature/signatureToHex.d.ts +1 -1
  98. package/_types/utils/signature/signatureToHex.d.ts.map +1 -1
  99. package/_types/zksync/constants/abis.d.ts +11 -0
  100. package/_types/zksync/constants/abis.d.ts.map +1 -1
  101. package/_types/zksync/index.d.ts +2 -0
  102. package/_types/zksync/index.d.ts.map +1 -1
  103. package/_types/zksync/utils/paymaster/getApprovalBasedPaymasterInput.d.ts +11 -0
  104. package/_types/zksync/utils/paymaster/getApprovalBasedPaymasterInput.d.ts.map +1 -0
  105. package/_types/zksync/utils/paymaster/getGeneralPaymasterInput.d.ts +8 -0
  106. package/_types/zksync/utils/paymaster/getGeneralPaymasterInput.d.ts.map +1 -0
  107. package/accounts/types.ts +1 -1
  108. package/chains/definitions/cyber.ts +2 -2
  109. package/chains/definitions/otimDevnet.ts +21 -0
  110. package/chains/definitions/telcoinTestnet.ts +19 -0
  111. package/chains/index.ts +2 -0
  112. package/errors/version.ts +1 -1
  113. package/experimental/eip3074/actions/signAuthMessage.ts +5 -5
  114. package/experimental/eip3074/constants/abis.ts +119 -0
  115. package/experimental/eip3074/invokers/coders/batchInvokerCoder.ts +46 -0
  116. package/experimental/eip3074/invokers/coders/defineInvokerCoder.ts +20 -0
  117. package/experimental/eip3074/invokers/getInvoker.ts +192 -0
  118. package/experimental/index.ts +21 -0
  119. package/package.json +1 -1
  120. package/utils/rpc/http.ts +7 -6
  121. package/utils/signature/recoverTransactionAddress.ts +7 -12
  122. package/utils/signature/signatureToHex.ts +6 -6
  123. package/utils/transaction/parseTransaction.ts +1 -1
  124. package/zksync/constants/abis.ts +39 -0
  125. package/zksync/index.ts +11 -0
  126. package/zksync/utils/paymaster/getApprovalBasedPaymasterInput.ts +29 -0
  127. package/zksync/utils/paymaster/getGeneralPaymasterInput.ts +25 -0
@@ -0,0 +1,192 @@
1
+ import type { Address } from 'abitype'
2
+ import {
3
+ type GetTransactionCountErrorType,
4
+ getTransactionCount,
5
+ } from '../../../actions/public/getTransactionCount.js'
6
+ import {
7
+ type WriteContractErrorType,
8
+ writeContract,
9
+ } from '../../../actions/wallet/writeContract.js'
10
+ import type { Client } from '../../../clients/createClient.js'
11
+ import type { Transport } from '../../../clients/transports/createTransport.js'
12
+ import type { ErrorType } from '../../../errors/utils.js'
13
+ import type { Account, LocalAccount } from '../../../types/account.js'
14
+ import type { Chain, GetChainParameter } from '../../../types/chain.js'
15
+ import type { Hex } from '../../../types/misc.js'
16
+ import type { IsUndefined } from '../../../types/utils.js'
17
+ import { parseAccount } from '../../../utils/accounts.js'
18
+ import {
19
+ type IsAddressEqualErrorType,
20
+ isAddressEqual,
21
+ } from '../../../utils/address/isAddressEqual.js'
22
+ import { getAction } from '../../../utils/getAction.js'
23
+ import {
24
+ type Keccak256ErrorType,
25
+ keccak256,
26
+ } from '../../../utils/hash/keccak256.js'
27
+ import {
28
+ type HexToSignatureErrorType,
29
+ hexToSignature,
30
+ } from '../../../utils/signature/hexToSignature.js'
31
+ import {
32
+ type SignAuthMessageErrorType,
33
+ signAuthMessage,
34
+ } from '../actions/signAuthMessage.js'
35
+ import { invokerAbi } from '../constants/abis.js'
36
+ import type { InvokerCoder } from './coders/defineInvokerCoder.js'
37
+
38
+ type GetExecutorParameter<
39
+ TAccount extends Account | undefined = Account | undefined,
40
+ TAccountOverride extends Account | Address | undefined = Account | Address,
41
+ TRequired extends boolean = true,
42
+ > = IsUndefined<TAccount> extends true
43
+ ? TRequired extends true
44
+ ? { executor: TAccountOverride | Account | Address }
45
+ : { executor?: TAccountOverride | Account | Address | undefined }
46
+ : { executor?: TAccountOverride | Account | Address | undefined }
47
+
48
+ export type InvokerExecuteParameters<
49
+ account extends Account | undefined = Account | undefined,
50
+ chain extends Chain | undefined = Chain | undefined,
51
+ chainOverride extends Chain | undefined = Chain | undefined,
52
+ args = unknown,
53
+ > = {
54
+ args: args
55
+ authority: Account | Address
56
+ signature: Hex
57
+ } & GetExecutorParameter<account> &
58
+ GetChainParameter<chain, chainOverride>
59
+
60
+ export type InvokerExecuteErrorType =
61
+ | WriteContractErrorType
62
+ | HexToSignatureErrorType
63
+ | ErrorType
64
+
65
+ export type InvokerSignParameters<
66
+ account extends Account | undefined = Account | undefined,
67
+ chain extends Chain | undefined = Chain | undefined,
68
+ chainOverride extends Chain | undefined = Chain | undefined,
69
+ args = unknown,
70
+ > = {
71
+ args: args
72
+ authority: LocalAccount
73
+ } & GetExecutorParameter<account, Account | Address, false> &
74
+ GetChainParameter<chain, chainOverride>
75
+
76
+ export type InvokerSignErrorType =
77
+ | GetTransactionCountErrorType
78
+ | SignAuthMessageErrorType
79
+ | Keccak256ErrorType
80
+ | IsAddressEqualErrorType
81
+ | ErrorType
82
+
83
+ export type Invoker<
84
+ account extends Account | undefined = Account | undefined,
85
+ chain extends Chain | undefined = Chain | undefined,
86
+ args = unknown,
87
+ > = {
88
+ address: Address
89
+ execute<chainOverride extends Chain | undefined = undefined>(
90
+ parameters: InvokerExecuteParameters<account, chain, chainOverride, args>,
91
+ ): Promise<Hex>
92
+ sign<chainOverride extends Chain | undefined = undefined>(
93
+ parameters: InvokerSignParameters<account, chain, chainOverride, args>,
94
+ ): Promise<Hex>
95
+ }
96
+
97
+ export type GetInvokerParameters<
98
+ account extends Account | undefined = Account | undefined,
99
+ chain extends Chain | undefined = Chain | undefined,
100
+ args = unknown,
101
+ > = {
102
+ address: Address
103
+ client: Client<Transport, chain, account>
104
+ coder: InvokerCoder<args>
105
+ }
106
+
107
+ export type GetInvokerErrorType = ErrorType
108
+
109
+ export type InvokerArgs<invoker extends Invoker<any, any, any> = Invoker> =
110
+ invoker extends Invoker<any, any, infer args> ? args : unknown
111
+
112
+ export function getInvoker<
113
+ account extends Account | undefined,
114
+ chain extends Chain | undefined,
115
+ args,
116
+ >(
117
+ parameters: GetInvokerParameters<account, chain, args>,
118
+ ): Invoker<account, chain, args> {
119
+ const { address, client, coder } = parameters
120
+ return {
121
+ address,
122
+ async execute(parameters) {
123
+ const {
124
+ executor: executor_ = client.account,
125
+ authority: authority_,
126
+ args,
127
+ chain = client.chain,
128
+ signature,
129
+ } = parameters
130
+ const authority = parseAccount(authority_!)
131
+ const executor = parseAccount(executor_!)
132
+
133
+ const execData = await coder.toExecData(args, {
134
+ authority: authority.address,
135
+ client,
136
+ invokerAddress: address,
137
+ })
138
+
139
+ const { r, s, yParity } = hexToSignature(signature)
140
+ return getAction(
141
+ client,
142
+ writeContract,
143
+ 'writeContract',
144
+ )({
145
+ abi: invokerAbi,
146
+ address,
147
+ account: executor,
148
+ chain,
149
+ functionName: 'execute',
150
+ args: [execData, { signer: authority.address, r, s, yParity }],
151
+ })
152
+ },
153
+ async sign(parameters) {
154
+ const {
155
+ args,
156
+ authority,
157
+ executor: executor_ = client.account,
158
+ chain = client.chain,
159
+ } = parameters
160
+ const executor = parseAccount(executor_!)
161
+ const [execData, nonce] = await Promise.all([
162
+ await coder.toExecData(args, {
163
+ authority: authority.address,
164
+ client,
165
+ invokerAddress: address,
166
+ }),
167
+ getAction(
168
+ client,
169
+ getTransactionCount,
170
+ 'getTransactionCount',
171
+ )({
172
+ address: authority.address,
173
+ blockTag: 'pending',
174
+ }),
175
+ ])
176
+ const signature = await getAction(
177
+ client,
178
+ signAuthMessage,
179
+ 'signAuthMessage',
180
+ )({
181
+ account: authority,
182
+ chain,
183
+ commit: keccak256(execData),
184
+ invokerAddress: address,
185
+ nonce: isAddressEqual(authority.address, executor.address)
186
+ ? nonce + 1
187
+ : nonce,
188
+ })
189
+ return signature
190
+ },
191
+ }
192
+ }
@@ -20,6 +20,27 @@ export {
20
20
  type WalletActionsEip3074,
21
21
  walletActionsEip3074,
22
22
  } from './eip3074/decorators/eip3074.js'
23
+ export {
24
+ type GetInvokerErrorType,
25
+ type GetInvokerParameters,
26
+ type Invoker,
27
+ type InvokerArgs,
28
+ type InvokerExecuteErrorType,
29
+ type InvokerExecuteParameters,
30
+ type InvokerSignErrorType,
31
+ type InvokerSignParameters,
32
+ getInvoker,
33
+ } from './eip3074/invokers/getInvoker.js'
34
+ export {
35
+ type BatchInvokerArgs,
36
+ batchInvokerCoder,
37
+ } from './eip3074/invokers/coders/batchInvokerCoder.js'
38
+ export {
39
+ type DefineInvokerCoderParameters,
40
+ type DefineInvokerCoderReturnType,
41
+ type InvokerCoder,
42
+ defineInvokerCoder,
43
+ } from './eip3074/invokers/coders/defineInvokerCoder.js'
23
44
 
24
45
  export {
25
46
  type GetCapabilitiesErrorType,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.9.28",
4
+ "version": "2.9.30",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/utils/rpc/http.ts CHANGED
@@ -63,16 +63,17 @@ export function getHttpRpcClient(
63
63
  async request(params) {
64
64
  const {
65
65
  body,
66
- fetchOptions = {},
67
66
  onRequest = options.onRequest,
68
67
  onResponse = options.onResponse,
69
68
  timeout = options.timeout ?? 10_000,
70
69
  } = params
71
- const {
72
- headers,
73
- method,
74
- signal: signal_,
75
- } = { ...options.fetchOptions, ...fetchOptions }
70
+
71
+ const fetchOptions = {
72
+ ...(options.fetchOptions ?? {}),
73
+ ...(params.fetchOptions ?? {}),
74
+ }
75
+
76
+ const { headers, method, signal: signal_ } = fetchOptions
76
77
 
77
78
  try {
78
79
  const response = await withTimeout(
@@ -12,10 +12,7 @@ import {
12
12
  type RecoverAddressErrorType,
13
13
  recoverAddress,
14
14
  } from './recoverAddress.js'
15
- import {
16
- type SignatureToHexErrorType,
17
- signatureToHex,
18
- } from './signatureToHex.js'
15
+ import type { SignatureToHexErrorType } from './signatureToHex.js'
19
16
 
20
17
  export type RecoverTransactionAddressParameters = {
21
18
  serializedTransaction: TransactionSerialized
@@ -38,14 +35,12 @@ export async function recoverTransactionAddress(
38
35
 
39
36
  const transaction = parseTransaction(serializedTransaction)
40
37
 
41
- const signature =
42
- signature_ ??
43
- signatureToHex({
44
- r: transaction.r!,
45
- s: transaction.s!,
46
- v: transaction.v!,
47
- yParity: transaction.yParity!,
48
- })
38
+ const signature = signature_ ?? {
39
+ r: transaction.r!,
40
+ s: transaction.s!,
41
+ v: transaction.v!,
42
+ yParity: transaction.yParity!,
43
+ }
49
44
 
50
45
  const serialized = serializeTransaction({
51
46
  ...transaction,
@@ -6,7 +6,7 @@ import {
6
6
  type HexToBigIntErrorType,
7
7
  hexToBigInt,
8
8
  } from '../../utils/encoding/fromHex.js'
9
- import { type ToHexErrorType } from '../../utils/encoding/toHex.js'
9
+ import type { ToHexErrorType } from '../../utils/encoding/toHex.js'
10
10
 
11
11
  export type SignatureToHexErrorType =
12
12
  | HexToBigIntErrorType
@@ -28,13 +28,13 @@ export type SignatureToHexErrorType =
28
28
  * // "0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c"
29
29
  */
30
30
  export function signatureToHex({ r, s, v, yParity }: Signature): Hex {
31
- const vHex = (() => {
32
- if (v === 27n || yParity === 0) return '1b'
33
- if (v === 28n || yParity === 1) return '1c'
34
- throw new Error('Invalid v value')
31
+ const yParity_ = (() => {
32
+ if (yParity === 0 || yParity === 1) return yParity
33
+ if (v && (v === 27n || v === 28n || v >= 35n)) return v % 2n === 0n ? 1 : 0
34
+ throw new Error('Invalid `v` or `yParity` value')
35
35
  })()
36
36
  return `0x${new secp256k1.Signature(
37
37
  hexToBigInt(r),
38
38
  hexToBigInt(s),
39
- ).toCompactHex()}${vHex}`
39
+ ).toCompactHex()}${yParity_ === 0 ? '1b' : '1c'}`
40
40
  }
@@ -422,10 +422,10 @@ function parseTransactionLegacy(
422
422
  if (chainId > 0) transaction.chainId = chainId
423
423
  else if (v !== 27n && v !== 28n) throw new InvalidLegacyVError({ v })
424
424
 
425
- delete transaction.yParity
426
425
  transaction.v = v
427
426
  transaction.s = s as Hex
428
427
  transaction.r = r as Hex
428
+ transaction.yParity = v % 2n === 0n ? 1 : 0
429
429
 
430
430
  return transaction
431
431
  }
@@ -422,3 +422,42 @@ export const contractDeployerAbi = [
422
422
  type: 'function',
423
423
  },
424
424
  ]
425
+
426
+ export const paymasterAbi = [
427
+ {
428
+ inputs: [
429
+ {
430
+ internalType: 'address',
431
+ name: '_token',
432
+ type: 'address',
433
+ },
434
+ {
435
+ internalType: 'uint256',
436
+ name: '_minAllowance',
437
+ type: 'uint256',
438
+ },
439
+ {
440
+ internalType: 'bytes',
441
+ name: '_innerInput',
442
+ type: 'bytes',
443
+ },
444
+ ],
445
+ name: 'approvalBased',
446
+ outputs: [],
447
+ stateMutability: 'nonpayable',
448
+ type: 'function',
449
+ },
450
+ {
451
+ inputs: [
452
+ {
453
+ internalType: 'bytes',
454
+ name: 'input',
455
+ type: 'bytes',
456
+ },
457
+ ],
458
+ name: 'general',
459
+ outputs: [],
460
+ stateMutability: 'nonpayable',
461
+ type: 'function',
462
+ },
463
+ ]
package/zksync/index.ts CHANGED
@@ -84,3 +84,14 @@ export type {
84
84
  ZkSyncTransactionSerializedEIP712,
85
85
  ZkSyncTransactionType,
86
86
  } from './types/transaction.js'
87
+
88
+ export {
89
+ type GetApprovalBasedPaymasterInputParameters,
90
+ type GetApprovalBasedPaymasterInputReturnType,
91
+ getApprovalBasedPaymasterInput,
92
+ } from './utils/paymaster/getApprovalBasedPaymasterInput.js'
93
+ export {
94
+ type GetGeneralPaymasterInputParameters,
95
+ type GetGeneralPaymasterInputReturnType,
96
+ getGeneralPaymasterInput,
97
+ } from './utils/paymaster/getGeneralPaymasterInput.js'
@@ -0,0 +1,29 @@
1
+ import { type Address } from 'abitype'
2
+ import type { ByteArray, Hex } from '../../../types/misc.js'
3
+ import type { EncodeFunctionDataReturnType } from '../../../utils/abi/encodeFunctionData.js'
4
+ import { bytesToHex, encodeFunctionData } from '../../../utils/index.js'
5
+ import { paymasterAbi } from '../../constants/abis.js'
6
+
7
+ export type GetApprovalBasedPaymasterInputParameters = {
8
+ innerInput: Hex | ByteArray
9
+ minAllowance: bigint
10
+ token: Address
11
+ }
12
+
13
+ export type GetApprovalBasedPaymasterInputReturnType =
14
+ EncodeFunctionDataReturnType
15
+
16
+ export function getApprovalBasedPaymasterInput(
17
+ parameters: GetApprovalBasedPaymasterInputParameters,
18
+ ): GetApprovalBasedPaymasterInputReturnType {
19
+ const { innerInput, minAllowance, token } = parameters
20
+
21
+ const innerInputHex =
22
+ typeof innerInput === 'string' ? innerInput : bytesToHex(innerInput)
23
+
24
+ return encodeFunctionData({
25
+ abi: paymasterAbi,
26
+ functionName: 'approvalBased',
27
+ args: [token, minAllowance, innerInputHex],
28
+ })
29
+ }
@@ -0,0 +1,25 @@
1
+ import type { ByteArray, Hex } from '../../../types/misc.js'
2
+ import type { EncodeFunctionDataReturnType } from '../../../utils/abi/encodeFunctionData.js'
3
+ import { bytesToHex, encodeFunctionData } from '../../../utils/index.js'
4
+ import { paymasterAbi } from '../../constants/abis.js'
5
+
6
+ export type GetGeneralPaymasterInputParameters = {
7
+ innerInput: Hex | ByteArray
8
+ }
9
+
10
+ export type GetGeneralPaymasterInputReturnType = EncodeFunctionDataReturnType
11
+
12
+ export function getGeneralPaymasterInput(
13
+ parameters: GetGeneralPaymasterInputParameters,
14
+ ): GetGeneralPaymasterInputReturnType {
15
+ const { innerInput } = parameters
16
+
17
+ const innerInputHex =
18
+ typeof innerInput === 'string' ? innerInput : bytesToHex(innerInput)
19
+
20
+ return encodeFunctionData({
21
+ abi: paymasterAbi,
22
+ functionName: 'general',
23
+ args: [innerInputHex],
24
+ })
25
+ }