@gelatocloud/gasless 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/_dist/account/actions/getFeeQuote.d.ts +11 -0
  2. package/_dist/account/actions/getFeeQuote.d.ts.map +1 -0
  3. package/_dist/account/actions/getFeeQuote.js +21 -0
  4. package/_dist/account/actions/getFeeQuote.js.map +1 -0
  5. package/_dist/account/actions/index.d.ts +4 -0
  6. package/_dist/account/actions/index.d.ts.map +1 -0
  7. package/_dist/account/actions/index.js +20 -0
  8. package/_dist/account/actions/index.js.map +1 -0
  9. package/_dist/account/actions/sendTransaction.d.ts +20 -0
  10. package/_dist/account/actions/sendTransaction.d.ts.map +1 -0
  11. package/_dist/account/actions/sendTransaction.js +33 -0
  12. package/_dist/account/actions/sendTransaction.js.map +1 -0
  13. package/_dist/account/actions/sendTransactionSync.d.ts +9 -0
  14. package/_dist/account/actions/sendTransactionSync.d.ts.map +1 -0
  15. package/_dist/account/actions/sendTransactionSync.js +34 -0
  16. package/_dist/account/actions/sendTransactionSync.js.map +1 -0
  17. package/_dist/account/adapters/gelato/abi.d.ts +39 -0
  18. package/_dist/account/adapters/gelato/abi.d.ts.map +1 -0
  19. package/_dist/account/adapters/gelato/abi.js +13 -0
  20. package/_dist/account/adapters/gelato/abi.js.map +1 -0
  21. package/_dist/account/adapters/gelato/constants.d.ts +7 -0
  22. package/_dist/account/adapters/gelato/constants.d.ts.map +1 -0
  23. package/_dist/account/adapters/gelato/constants.js +9 -0
  24. package/_dist/account/adapters/gelato/constants.js.map +1 -0
  25. package/_dist/account/adapters/gelato/index.d.ts +10 -0
  26. package/_dist/account/adapters/gelato/index.d.ts.map +1 -0
  27. package/_dist/account/adapters/gelato/index.js +160 -0
  28. package/_dist/account/adapters/gelato/index.js.map +1 -0
  29. package/_dist/account/adapters/index.d.ts +2 -0
  30. package/_dist/account/adapters/index.d.ts.map +1 -0
  31. package/_dist/account/adapters/index.js +18 -0
  32. package/_dist/account/adapters/index.js.map +1 -0
  33. package/_dist/account/adapters/types/index.d.ts +22 -0
  34. package/_dist/account/adapters/types/index.d.ts.map +1 -0
  35. package/_dist/account/adapters/types/index.js +3 -0
  36. package/_dist/account/adapters/types/index.js.map +1 -0
  37. package/_dist/account/index.d.ts +17 -0
  38. package/_dist/account/index.d.ts.map +1 -0
  39. package/_dist/account/index.js +41 -0
  40. package/_dist/account/index.js.map +1 -0
  41. package/_dist/account/utils/delegation.d.ts +4 -0
  42. package/_dist/account/utils/delegation.d.ts.map +1 -0
  43. package/_dist/account/utils/delegation.js +12 -0
  44. package/_dist/account/utils/delegation.js.map +1 -0
  45. package/_dist/account/utils/estimation.d.ts +3 -0
  46. package/_dist/account/utils/estimation.d.ts.map +1 -0
  47. package/_dist/account/utils/estimation.js +19 -0
  48. package/_dist/account/utils/estimation.js.map +1 -0
  49. package/_dist/account/utils/index.d.ts +3 -0
  50. package/_dist/account/utils/index.d.ts.map +1 -0
  51. package/_dist/account/utils/index.js +19 -0
  52. package/_dist/account/utils/index.js.map +1 -0
  53. package/_dist/bundler/actions/estimateUserOperationGas.d.ts +6 -0
  54. package/_dist/bundler/actions/estimateUserOperationGas.d.ts.map +1 -0
  55. package/_dist/bundler/actions/estimateUserOperationGas.js +43 -0
  56. package/_dist/bundler/actions/estimateUserOperationGas.js.map +1 -0
  57. package/_dist/bundler/actions/getUserOperationGasPrice.d.ts +5 -0
  58. package/_dist/bundler/actions/getUserOperationGasPrice.d.ts.map +1 -0
  59. package/_dist/bundler/actions/getUserOperationGasPrice.js +20 -0
  60. package/_dist/bundler/actions/getUserOperationGasPrice.js.map +1 -0
  61. package/_dist/bundler/actions/getUserOperationQuote.d.ts +13 -0
  62. package/_dist/bundler/actions/getUserOperationQuote.d.ts.map +1 -0
  63. package/_dist/bundler/actions/getUserOperationQuote.js +50 -0
  64. package/_dist/bundler/actions/getUserOperationQuote.js.map +1 -0
  65. package/_dist/bundler/actions/index.d.ts +7 -0
  66. package/_dist/bundler/actions/index.d.ts.map +1 -0
  67. package/_dist/bundler/actions/index.js +23 -0
  68. package/_dist/bundler/actions/index.js.map +1 -0
  69. package/_dist/bundler/actions/prepareUserOperation.d.ts +6 -0
  70. package/_dist/bundler/actions/prepareUserOperation.d.ts.map +1 -0
  71. package/_dist/bundler/actions/prepareUserOperation.js +340 -0
  72. package/_dist/bundler/actions/prepareUserOperation.js.map +1 -0
  73. package/_dist/bundler/actions/sendUserOperation.d.ts +6 -0
  74. package/_dist/bundler/actions/sendUserOperation.d.ts.map +1 -0
  75. package/_dist/bundler/actions/sendUserOperation.js +41 -0
  76. package/_dist/bundler/actions/sendUserOperation.js.map +1 -0
  77. package/_dist/bundler/actions/sendUserOperationSync.d.ts +9 -0
  78. package/_dist/bundler/actions/sendUserOperationSync.d.ts.map +1 -0
  79. package/_dist/bundler/actions/sendUserOperationSync.js +42 -0
  80. package/_dist/bundler/actions/sendUserOperationSync.js.map +1 -0
  81. package/_dist/bundler/index.d.ts +18 -0
  82. package/_dist/bundler/index.d.ts.map +1 -0
  83. package/_dist/bundler/index.js +61 -0
  84. package/_dist/bundler/index.js.map +1 -0
  85. package/_dist/index.d.ts +5 -0
  86. package/_dist/index.d.ts.map +1 -0
  87. package/_dist/index.js +21 -0
  88. package/_dist/index.js.map +1 -0
  89. package/_dist/relayer/constants/index.d.ts +3 -0
  90. package/_dist/relayer/constants/index.d.ts.map +1 -0
  91. package/_dist/relayer/constants/index.js +6 -0
  92. package/_dist/relayer/constants/index.js.map +1 -0
  93. package/_dist/relayer/evm/actions/getCapabilities.d.ts +21 -0
  94. package/_dist/relayer/evm/actions/getCapabilities.d.ts.map +1 -0
  95. package/_dist/relayer/evm/actions/getCapabilities.js +19 -0
  96. package/_dist/relayer/evm/actions/getCapabilities.js.map +1 -0
  97. package/_dist/relayer/evm/actions/getFeeData.d.ts +21 -0
  98. package/_dist/relayer/evm/actions/getFeeData.d.ts.map +1 -0
  99. package/_dist/relayer/evm/actions/getFeeData.js +26 -0
  100. package/_dist/relayer/evm/actions/getFeeData.js.map +1 -0
  101. package/_dist/relayer/evm/actions/getFeeQuote.d.ts +22 -0
  102. package/_dist/relayer/evm/actions/getFeeQuote.d.ts.map +1 -0
  103. package/_dist/relayer/evm/actions/getFeeQuote.js +27 -0
  104. package/_dist/relayer/evm/actions/getFeeQuote.js.map +1 -0
  105. package/_dist/relayer/evm/actions/getStatus.d.ts +81 -0
  106. package/_dist/relayer/evm/actions/getStatus.d.ts.map +1 -0
  107. package/_dist/relayer/evm/actions/getStatus.js +72 -0
  108. package/_dist/relayer/evm/actions/getStatus.js.map +1 -0
  109. package/_dist/relayer/evm/actions/index.d.ts +8 -0
  110. package/_dist/relayer/evm/actions/index.d.ts.map +1 -0
  111. package/_dist/relayer/evm/actions/index.js +24 -0
  112. package/_dist/relayer/evm/actions/index.js.map +1 -0
  113. package/_dist/relayer/evm/actions/sendTransaction.d.ts +12 -0
  114. package/_dist/relayer/evm/actions/sendTransaction.d.ts.map +1 -0
  115. package/_dist/relayer/evm/actions/sendTransaction.js +22 -0
  116. package/_dist/relayer/evm/actions/sendTransaction.js.map +1 -0
  117. package/_dist/relayer/evm/actions/sendTransactionSync.d.ts +8 -0
  118. package/_dist/relayer/evm/actions/sendTransactionSync.d.ts.map +1 -0
  119. package/_dist/relayer/evm/actions/sendTransactionSync.js +23 -0
  120. package/_dist/relayer/evm/actions/sendTransactionSync.js.map +1 -0
  121. package/_dist/relayer/evm/actions/waitForStatus.d.ts +4 -0
  122. package/_dist/relayer/evm/actions/waitForStatus.d.ts.map +1 -0
  123. package/_dist/relayer/evm/actions/waitForStatus.js +17 -0
  124. package/_dist/relayer/evm/actions/waitForStatus.js.map +1 -0
  125. package/_dist/relayer/evm/index.d.ts +18 -0
  126. package/_dist/relayer/evm/index.d.ts.map +1 -0
  127. package/_dist/relayer/evm/index.js +46 -0
  128. package/_dist/relayer/evm/index.js.map +1 -0
  129. package/_dist/relayer/index.d.ts +2 -0
  130. package/_dist/relayer/index.d.ts.map +1 -0
  131. package/_dist/relayer/index.js +18 -0
  132. package/_dist/relayer/index.js.map +1 -0
  133. package/_dist/tsconfig.build.tsbuildinfo +1 -0
  134. package/_dist/types/error.d.ts +14 -0
  135. package/_dist/types/error.d.ts.map +1 -0
  136. package/_dist/types/error.js +27 -0
  137. package/_dist/types/error.js.map +1 -0
  138. package/_dist/types/index.d.ts +4 -0
  139. package/_dist/types/index.d.ts.map +1 -0
  140. package/_dist/types/index.js +20 -0
  141. package/_dist/types/index.js.map +1 -0
  142. package/_dist/types/payment.d.ts +17 -0
  143. package/_dist/types/payment.d.ts.map +1 -0
  144. package/_dist/types/payment.js +16 -0
  145. package/_dist/types/payment.js.map +1 -0
  146. package/_dist/types/schema.d.ts +10 -0
  147. package/_dist/types/schema.d.ts.map +1 -0
  148. package/_dist/types/schema.js +25 -0
  149. package/_dist/types/schema.js.map +1 -0
  150. package/_dist/utils/index.d.ts +3 -0
  151. package/_dist/utils/index.d.ts.map +1 -0
  152. package/_dist/utils/index.js +19 -0
  153. package/_dist/utils/index.js.map +1 -0
  154. package/_dist/utils/payment.d.ts +3 -0
  155. package/_dist/utils/payment.d.ts.map +1 -0
  156. package/_dist/utils/payment.js +17 -0
  157. package/_dist/utils/payment.js.map +1 -0
  158. package/_dist/utils/serialize.d.ts +17 -0
  159. package/_dist/utils/serialize.d.ts.map +1 -0
  160. package/_dist/utils/serialize.js +77 -0
  161. package/_dist/utils/serialize.js.map +1 -0
  162. package/account/actions/getFeeQuote.ts +34 -0
  163. package/account/actions/index.ts +3 -0
  164. package/account/actions/sendTransaction.ts +61 -0
  165. package/account/actions/sendTransactionSync.ts +51 -0
  166. package/account/adapters/gelato/abi.ts +13 -0
  167. package/account/adapters/gelato/constants.ts +13 -0
  168. package/account/adapters/gelato/index.ts +216 -0
  169. package/account/adapters/index.ts +1 -0
  170. package/account/adapters/types/index.ts +36 -0
  171. package/account/index.ts +60 -0
  172. package/account/utils/delegation.ts +9 -0
  173. package/account/utils/estimation.ts +29 -0
  174. package/account/utils/index.ts +2 -0
  175. package/bundler/actions/estimateUserOperationGas.ts +63 -0
  176. package/bundler/actions/getUserOperationGasPrice.ts +25 -0
  177. package/bundler/actions/getUserOperationQuote.ts +83 -0
  178. package/bundler/actions/index.ts +6 -0
  179. package/bundler/actions/prepareUserOperation.ts +437 -0
  180. package/bundler/actions/sendUserOperation.ts +64 -0
  181. package/bundler/actions/sendUserOperationSync.ts +71 -0
  182. package/bundler/index.ts +98 -0
  183. package/index.ts +4 -0
  184. package/package.json +36 -0
  185. package/relayer/constants/index.ts +2 -0
  186. package/relayer/evm/actions/getCapabilities.ts +22 -0
  187. package/relayer/evm/actions/getFeeData.ts +36 -0
  188. package/relayer/evm/actions/getFeeQuote.ts +39 -0
  189. package/relayer/evm/actions/getStatus.ts +92 -0
  190. package/relayer/evm/actions/index.ts +7 -0
  191. package/relayer/evm/actions/sendTransaction.ts +33 -0
  192. package/relayer/evm/actions/sendTransactionSync.ts +30 -0
  193. package/relayer/evm/actions/waitForStatus.ts +24 -0
  194. package/relayer/evm/index.ts +68 -0
  195. package/relayer/index.ts +1 -0
  196. package/tsconfig.build.json +19 -0
  197. package/tsconfig.json +8 -0
  198. package/types/error.ts +38 -0
  199. package/types/index.ts +3 -0
  200. package/types/payment.ts +23 -0
  201. package/types/schema.ts +28 -0
  202. package/utils/index.ts +2 -0
  203. package/utils/payment.ts +20 -0
  204. package/utils/serialize.ts +91 -0
@@ -0,0 +1,216 @@
1
+ import {
2
+ type Account,
3
+ type Chain,
4
+ type Client,
5
+ encodeFunctionData,
6
+ encodePacked,
7
+ type JsonRpcAccount,
8
+ type LocalAccount,
9
+ type StateOverride,
10
+ type Transport,
11
+ type TypedDataDefinition
12
+ } from 'viem';
13
+ import {
14
+ entryPoint08Abi,
15
+ entryPoint08Address,
16
+ getUserOperationTypedData,
17
+ type SmartAccount
18
+ } from 'viem/account-abstraction';
19
+ import {
20
+ estimateGas,
21
+ getCode,
22
+ readContract,
23
+ signMessage,
24
+ signTypedData,
25
+ signAuthorization as viem_signAuthorization
26
+ } from 'viem/actions';
27
+ import { encodeCalls } from 'viem/experimental/erc7821';
28
+ import { delegationCode, delegationGas, estimateL1Fee } from '../../utils/index.js';
29
+ import type { GelatoSmartAccountImplementation } from '../types/index.js';
30
+ import { delegationAbi, simulationAbi, simulationBytecode } from './abi.js';
31
+ import {
32
+ EXECUTION_MODE_OP_DATA,
33
+ GELATO_DELEGATION_ADDRESS,
34
+ GELATO_DELEGATION_NAME,
35
+ GELATO_DELEGATION_VERSION,
36
+ STUB_SIGNATURE
37
+ } from './constants.js';
38
+
39
+ export type GelatoSmartAccountParameters = {
40
+ client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;
41
+ owner: Account;
42
+ };
43
+
44
+ export type GelatoSmartAccountReturnType = SmartAccount<
45
+ GelatoSmartAccountImplementation<typeof entryPoint08Abi, '0.8'>
46
+ >;
47
+
48
+ export const toGelatoSmartAccount = (
49
+ parameters: GelatoSmartAccountParameters
50
+ ): GelatoSmartAccountReturnType => {
51
+ const { client, owner } = parameters;
52
+
53
+ let deployed = false;
54
+ const isDeployed = async () => {
55
+ if (deployed) {
56
+ return true;
57
+ }
58
+
59
+ const code = await getCode(client, { address: owner.address });
60
+
61
+ deployed =
62
+ code !== undefined &&
63
+ code.toLowerCase() === delegationCode(GELATO_DELEGATION_ADDRESS).toLowerCase();
64
+
65
+ return deployed;
66
+ };
67
+
68
+ const getNonce = async (parameters?: { key?: bigint }) =>
69
+ readContract(client, {
70
+ abi: delegationAbi,
71
+ address: owner.address,
72
+ args: [parameters?.key ?? 0n],
73
+ functionName: 'getNonce',
74
+ stateOverride: (await isDeployed())
75
+ ? undefined
76
+ : [
77
+ {
78
+ address: owner.address,
79
+ code: delegationCode(GELATO_DELEGATION_ADDRESS)
80
+ }
81
+ ]
82
+ });
83
+
84
+ return {
85
+ address: owner.address,
86
+ authorization: {
87
+ account: undefined as never,
88
+ address: GELATO_DELEGATION_ADDRESS
89
+ },
90
+ chain: client.chain,
91
+ client,
92
+ encodeCallData: async (parameters) => {
93
+ const { calls, nonce } = parameters;
94
+
95
+ const signature = await signTypedData(client, {
96
+ account: owner,
97
+ domain: {
98
+ chainId: client.chain.id,
99
+ name: GELATO_DELEGATION_NAME,
100
+ verifyingContract: owner.address,
101
+ version: GELATO_DELEGATION_VERSION
102
+ },
103
+ message: {
104
+ calls: calls.map((call) => ({
105
+ data: call.data ?? '0x',
106
+ to: call.to,
107
+ value: call.value ?? 0n
108
+ })),
109
+ mode: EXECUTION_MODE_OP_DATA,
110
+ nonce
111
+ },
112
+ primaryType: 'Execute',
113
+ types: {
114
+ Call: [
115
+ { name: 'to', type: 'address' },
116
+ { name: 'value', type: 'uint256' },
117
+ { name: 'data', type: 'bytes' }
118
+ ],
119
+ Execute: [
120
+ { name: 'mode', type: 'bytes32' },
121
+ { name: 'calls', type: 'Call[]' },
122
+ { name: 'nonce', type: 'uint256' }
123
+ ]
124
+ }
125
+ });
126
+
127
+ const nonceKey = nonce >> 64n;
128
+
129
+ const opData = encodePacked(['uint192', 'bytes'], [nonceKey, signature]);
130
+
131
+ return encodeFunctionData({
132
+ abi: delegationAbi,
133
+ args: [EXECUTION_MODE_OP_DATA, encodeCalls(calls, opData)],
134
+ functionName: 'execute'
135
+ });
136
+ },
137
+ encodeCalls: async (calls) => encodeCalls(calls),
138
+ entryPoint: {
139
+ abi: entryPoint08Abi,
140
+ address: entryPoint08Address,
141
+ version: '0.8'
142
+ },
143
+ estimate: async (parameters) => {
144
+ const opData = encodePacked(['uint192', 'bytes'], [0n, STUB_SIGNATURE]);
145
+
146
+ const data = encodeFunctionData({
147
+ abi: simulationAbi,
148
+ args: [EXECUTION_MODE_OP_DATA, encodeCalls(parameters.calls, opData)],
149
+ functionName: 'simulateExecute'
150
+ });
151
+
152
+ const stateOverride: StateOverride = [
153
+ {
154
+ address: owner.address,
155
+ code: simulationBytecode
156
+ }
157
+ ];
158
+
159
+ const [estimatedGas, estimatedL1Fee, deployed] = await Promise.all([
160
+ estimateGas(client, {
161
+ blockTag: 'pending',
162
+ data,
163
+ stateOverride,
164
+ to: owner.address
165
+ }),
166
+ estimateL1Fee(client, owner.address, data),
167
+ isDeployed()
168
+ ]);
169
+
170
+ return {
171
+ estimatedGas: estimatedGas + delegationGas(deployed ? 0 : 1),
172
+ estimatedL1Fee
173
+ };
174
+ },
175
+ getAddress: async () => owner.address,
176
+ getFactoryArgs: async () => ({
177
+ factory: '0x7702',
178
+ factoryData: '0x'
179
+ }),
180
+ getNonce,
181
+ getStubSignature: async () => STUB_SIGNATURE,
182
+ isDeployed,
183
+ signAuthorization: () =>
184
+ viem_signAuthorization(client, {
185
+ account: owner,
186
+ address: GELATO_DELEGATION_ADDRESS,
187
+ chainId: client.chain.id
188
+ }),
189
+ signMessage: (parameters) =>
190
+ signMessage(client, {
191
+ account: owner,
192
+ message: parameters.message
193
+ }),
194
+ signTypedData: (parameters) =>
195
+ signTypedData(client, {
196
+ ...(parameters as TypedDataDefinition),
197
+ account: owner
198
+ }),
199
+ signUserOperation: async (parameters) => {
200
+ const typedData = getUserOperationTypedData({
201
+ chainId: client.chain.id,
202
+ entryPointAddress: entryPoint08Address,
203
+ userOperation: {
204
+ ...parameters,
205
+ sender: parameters.sender ?? owner.address
206
+ }
207
+ });
208
+
209
+ return signTypedData(client, {
210
+ ...typedData,
211
+ account: owner
212
+ });
213
+ },
214
+ type: 'smart'
215
+ };
216
+ };
@@ -0,0 +1 @@
1
+ export * from './gelato/index.js';
@@ -0,0 +1,36 @@
1
+ import type { Abi, Call, Chain, Hex, SignedAuthorization } from 'viem';
2
+ import type { EntryPointVersion, SmartAccountImplementation } from 'viem/account-abstraction';
3
+
4
+ export type EstimateParameters = {
5
+ calls: Call[];
6
+ };
7
+
8
+ export type EstimateReturnType = {
9
+ estimatedGas: bigint;
10
+ estimatedL1Fee?: bigint;
11
+ };
12
+
13
+ export type EncodeCallDataParameters = EstimateParameters & {
14
+ nonce: bigint;
15
+ };
16
+
17
+ export type GelatoSmartAccountExtension = {
18
+ chain: Chain;
19
+ };
20
+
21
+ export type GelatoSmartAccountActions = {
22
+ estimate: (parameters: EstimateParameters) => Promise<EstimateReturnType>;
23
+ encodeCallData: (parameters: EncodeCallDataParameters) => Promise<Hex>;
24
+ signAuthorization: () => Promise<SignedAuthorization>;
25
+ };
26
+
27
+ export type GelatoSmartAccountImplementation<
28
+ entryPointAbi extends Abi | readonly unknown[] = Abi,
29
+ entryPointVersion extends EntryPointVersion = EntryPointVersion
30
+ > = SmartAccountImplementation<
31
+ entryPointAbi,
32
+ entryPointVersion,
33
+ GelatoSmartAccountExtension,
34
+ true
35
+ > &
36
+ GelatoSmartAccountActions;
@@ -0,0 +1,60 @@
1
+ import type { Hex } from 'viem';
2
+ import type { SmartAccount } from 'viem/account-abstraction';
3
+ import {
4
+ createGelatoEvmRelayerClient,
5
+ type FeeQuote,
6
+ type GelatoEvmRelayerClient,
7
+ type TerminalStatus
8
+ } from '../relayer/index.js';
9
+ import {
10
+ type GetFeeQuoteParameters,
11
+ getFeeQuote,
12
+ type SendTransactionParameters,
13
+ type SendTransactionSyncParameters,
14
+ sendTransaction,
15
+ sendTransactionSync
16
+ } from './actions/index.js';
17
+ import type { GelatoSmartAccountImplementation } from './adapters/types/index.js';
18
+
19
+ export * from './adapters/index.js';
20
+
21
+ export type GelatoSmartAccountClient = Pick<
22
+ GelatoEvmRelayerClient,
23
+ 'getCapabilities' | 'getStatus' | 'waitForStatus'
24
+ > & {
25
+ sendTransaction: (parameters: SendTransactionParameters) => Promise<Hex>;
26
+ sendTransactionSync: (parameters: SendTransactionSyncParameters) => Promise<TerminalStatus>;
27
+ getFeeQuote: (parameters: GetFeeQuoteParameters) => Promise<FeeQuote>;
28
+ };
29
+
30
+ export type GelatoSmartAccountClientConfig = {
31
+ apiKey: string;
32
+ account: SmartAccount<GelatoSmartAccountImplementation>;
33
+ };
34
+
35
+ export const createGelatoSmartAccountClient = async (
36
+ parameters: GelatoSmartAccountClientConfig
37
+ ): Promise<GelatoSmartAccountClient> => {
38
+ const { account, apiKey } = parameters;
39
+
40
+ const client = createGelatoEvmRelayerClient({
41
+ apiKey,
42
+ testnet: account.chain.testnet ?? false
43
+ });
44
+
45
+ const capabilities = (await client.getCapabilities())[account.chain.id];
46
+
47
+ if (!capabilities) {
48
+ throw new Error(`Chain not supported: ${account.chain.id}`);
49
+ }
50
+
51
+ return {
52
+ getCapabilities: () => client.getCapabilities(),
53
+ getFeeQuote: (parameters) => getFeeQuote(client, account, capabilities, parameters),
54
+ getStatus: (parameters) => client.getStatus(parameters),
55
+ sendTransaction: (parameters) => sendTransaction(client, account, capabilities, parameters),
56
+ sendTransactionSync: (parameters) =>
57
+ sendTransactionSync(client, account, capabilities, parameters),
58
+ waitForStatus: (parameters) => client.waitForStatus(parameters)
59
+ };
60
+ };
@@ -0,0 +1,9 @@
1
+ import { type Address, concatHex, type Hex } from 'viem';
2
+
3
+ const DELEGATION_GAS = 25_000n;
4
+
5
+ export const delegationGas = (authorizationCount: number): bigint => {
6
+ return DELEGATION_GAS * BigInt(authorizationCount);
7
+ };
8
+
9
+ export const delegationCode = (address: Address): Hex => concatHex(['0xef0100', address]);
@@ -0,0 +1,29 @@
1
+ import {
2
+ type Address,
3
+ type Chain,
4
+ type ChainContract,
5
+ type Client,
6
+ type Hex,
7
+ type Transport,
8
+ zeroAddress
9
+ } from 'viem';
10
+ import { estimateL1Fee as viem_estimateL1Fee } from 'viem/op-stack';
11
+
12
+ export const estimateL1Fee = async (
13
+ client: Client<Transport, Chain>,
14
+ to: Address,
15
+ data: Hex
16
+ ): Promise<bigint | undefined> => {
17
+ const gasPriceOracle = client.chain.contracts?.['gasPriceOracle'] as ChainContract | undefined;
18
+
19
+ if (!gasPriceOracle) {
20
+ return undefined;
21
+ }
22
+
23
+ return await viem_estimateL1Fee(client, {
24
+ account: zeroAddress,
25
+ data,
26
+ gasPriceOracleAddress: gasPriceOracle.address,
27
+ to
28
+ });
29
+ };
@@ -0,0 +1,2 @@
1
+ export * from './delegation.js';
2
+ export * from './estimation.js';
@@ -0,0 +1,63 @@
1
+ import type { BaseError, Chain, Client, Transport } from 'viem';
2
+ import {
3
+ type EstimateUserOperationGasParameters,
4
+ type EstimateUserOperationGasReturnType,
5
+ formatUserOperationGas,
6
+ formatUserOperationRequest,
7
+ getUserOperationError,
8
+ type PrepareUserOperationParameters,
9
+ type SmartAccount,
10
+ type UserOperation
11
+ } from 'viem/account-abstraction';
12
+ import { parseAccount } from 'viem/accounts';
13
+ import type { CapabilitiesByChain } from '../../relayer/evm/actions/index.js';
14
+ import { AccountNotFoundError, type Payment } from '../../types/index.js';
15
+ import { serializeStateOverride } from '../../utils/index.js';
16
+ import { prepareUserOperation } from './prepareUserOperation.js';
17
+
18
+ export const estimateUserOperationGas = async <account extends SmartAccount | undefined>(
19
+ client: Client<Transport, Chain | undefined, account>,
20
+ parameters: EstimateUserOperationGasParameters,
21
+ capabilities: CapabilitiesByChain,
22
+ payment?: Payment
23
+ ): Promise<EstimateUserOperationGasReturnType> => {
24
+ const { account: account_ = client.account, entryPointAddress, stateOverride } = parameters;
25
+
26
+ if (!account_ && !parameters.sender) throw new AccountNotFoundError();
27
+ const account = account_ ? parseAccount(account_) : undefined;
28
+
29
+ const rpcStateOverride = serializeStateOverride(stateOverride);
30
+
31
+ const request = account
32
+ ? await prepareUserOperation(
33
+ client,
34
+ {
35
+ ...parameters,
36
+ parameters: ['authorization', 'factory', 'nonce', 'paymaster', 'signature']
37
+ } as unknown as PrepareUserOperationParameters,
38
+ capabilities,
39
+ payment
40
+ )
41
+ : parameters;
42
+
43
+ try {
44
+ const params = [
45
+ formatUserOperationRequest(request as UserOperation),
46
+ // biome-ignore lint/style/noNonNullAssertion: copied from viem
47
+ (entryPointAddress ?? account?.entryPoint?.address)!
48
+ ] as const;
49
+
50
+ const result = await client.request({
51
+ method: 'eth_estimateUserOperationGas',
52
+ params: rpcStateOverride ? [...params, rpcStateOverride] : [...params]
53
+ });
54
+ return formatUserOperationGas(result) as EstimateUserOperationGasReturnType<account>;
55
+ } catch (error) {
56
+ // biome-ignore lint/suspicious/noExplicitAny: copied from viem
57
+ const calls = (parameters as any).calls;
58
+ throw getUserOperationError(error as BaseError, {
59
+ ...(request as UserOperation),
60
+ ...(calls ? { calls } : {})
61
+ });
62
+ }
63
+ };
@@ -0,0 +1,25 @@
1
+ import type { Client, EstimateFeesPerGasReturnType } from 'viem';
2
+ import type { Payment } from '../../types/index.js';
3
+
4
+ export type GetUserOperationGasPriceReturnType = EstimateFeesPerGasReturnType<'eip1559'>;
5
+
6
+ export const getUserOperationGasPrice = async (
7
+ client: Client,
8
+ payment?: Payment
9
+ ): Promise<GetUserOperationGasPriceReturnType> => {
10
+ if (payment) {
11
+ return {
12
+ maxFeePerGas: 0n,
13
+ maxPriorityFeePerGas: 0n
14
+ };
15
+ }
16
+
17
+ const { maxFeePerGas, maxPriorityFeePerGas } = await client.request({
18
+ method: 'gelato_getUserOperationGasPrice'
19
+ } as never);
20
+
21
+ return {
22
+ maxFeePerGas: BigInt(maxFeePerGas),
23
+ maxPriorityFeePerGas: BigInt(maxPriorityFeePerGas)
24
+ };
25
+ };
@@ -0,0 +1,83 @@
1
+ import type { BaseError, Client, Transport } from 'viem';
2
+ import {
3
+ type EstimateUserOperationGasParameters,
4
+ type EstimateUserOperationGasReturnType,
5
+ formatUserOperationRequest,
6
+ getUserOperationError,
7
+ type PrepareUserOperationParameters,
8
+ type SmartAccount,
9
+ type UserOperation
10
+ } from 'viem/account-abstraction';
11
+ import { parseAccount } from 'viem/accounts';
12
+ import type { Chain } from 'viem/chains';
13
+ import type { CapabilitiesByChain } from '../../relayer/evm/actions/index.js';
14
+ import { AccountNotFoundError, type Payment } from '../../types/index.js';
15
+ import { serializeStateOverride } from '../../utils/index.js';
16
+ import { prepareUserOperation } from './prepareUserOperation.js';
17
+
18
+ export type GetUserOperationQuoteParameters = Omit<
19
+ EstimateUserOperationGasParameters,
20
+ 'paymaster' | 'paymasterContext'
21
+ >;
22
+
23
+ export type GetUserOperationQuoteReturnType = EstimateUserOperationGasReturnType & {
24
+ fee: bigint;
25
+ gas: bigint;
26
+ l1Fee?: bigint;
27
+ };
28
+
29
+ export const getUserOperationQuote = async <account extends SmartAccount | undefined>(
30
+ client: Client<Transport, Chain | undefined, account>,
31
+ parameters: GetUserOperationQuoteParameters,
32
+ capabilities: CapabilitiesByChain,
33
+ payment?: Payment
34
+ ): Promise<GetUserOperationQuoteReturnType> => {
35
+ const { account: account_ = client.account, entryPointAddress, stateOverride } = parameters;
36
+
37
+ if (!account_ && !parameters.sender) throw new AccountNotFoundError();
38
+ const account = account_ ? parseAccount(account_) : undefined;
39
+
40
+ const rpcStateOverride = serializeStateOverride(stateOverride);
41
+
42
+ const request = account
43
+ ? await prepareUserOperation(
44
+ client,
45
+ {
46
+ ...parameters,
47
+ parameters: ['authorization', 'factory', 'nonce', 'signature']
48
+ } as unknown as PrepareUserOperationParameters,
49
+ capabilities,
50
+ payment
51
+ )
52
+ : parameters;
53
+
54
+ try {
55
+ const params = [
56
+ formatUserOperationRequest(request as UserOperation),
57
+ // biome-ignore lint/style/noNonNullAssertion: copied from viem
58
+ (entryPointAddress ?? account?.entryPoint?.address)!
59
+ ] as const;
60
+
61
+ const { fee, gas, l1Fee, preVerificationGas, verificationGasLimit, callGasLimit } =
62
+ await client.request({
63
+ method: 'gelato_getUserOperationQuote',
64
+ params: rpcStateOverride ? [...params, rpcStateOverride] : [...params]
65
+ } as never);
66
+
67
+ return {
68
+ callGasLimit: BigInt(callGasLimit),
69
+ fee: BigInt(fee),
70
+ gas: BigInt(gas),
71
+ l1Fee: l1Fee ? BigInt(l1Fee) : undefined,
72
+ preVerificationGas: BigInt(preVerificationGas),
73
+ verificationGasLimit: BigInt(verificationGasLimit)
74
+ };
75
+ } catch (error) {
76
+ // biome-ignore lint/suspicious/noExplicitAny: copied from viem
77
+ const calls = (parameters as any).calls;
78
+ throw getUserOperationError(error as BaseError, {
79
+ ...(request as UserOperation),
80
+ ...(calls ? { calls } : {})
81
+ });
82
+ }
83
+ };
@@ -0,0 +1,6 @@
1
+ export * from './estimateUserOperationGas.js';
2
+ export * from './getUserOperationGasPrice.js';
3
+ export * from './getUserOperationQuote.js';
4
+ export * from './prepareUserOperation.js';
5
+ export * from './sendUserOperation.js';
6
+ export * from './sendUserOperationSync.js';