@safe-global/relay-kit 3.4.0 → 3.4.1-alpha.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 (76) hide show
  1. package/dist/cjs/src/index.cjs +1323 -0
  2. package/dist/cjs/test-utils/index.cjs +1171 -0
  3. package/dist/esm/src/index.mjs +1326 -0
  4. package/dist/esm/test-utils/index.mjs +1172 -0
  5. package/dist/src/RelayKitBasePack.d.ts +1 -0
  6. package/dist/src/RelayKitBasePack.d.ts.map +1 -0
  7. package/dist/src/constants.d.ts +1 -0
  8. package/dist/src/constants.d.ts.map +1 -0
  9. package/dist/src/deprecated.d.ts +1 -0
  10. package/dist/src/deprecated.d.ts.map +1 -0
  11. package/dist/src/index.d.ts +2 -0
  12. package/dist/src/index.d.ts.map +1 -0
  13. package/dist/src/packs/gelato/GelatoRelayPack.d.ts +1 -0
  14. package/dist/src/packs/gelato/GelatoRelayPack.d.ts.map +1 -0
  15. package/dist/src/packs/gelato/types.d.ts +1 -0
  16. package/dist/src/packs/gelato/types.d.ts.map +1 -0
  17. package/dist/src/packs/safe-4337/Safe4337Pack.d.ts +1 -0
  18. package/dist/src/packs/safe-4337/Safe4337Pack.d.ts.map +1 -0
  19. package/dist/src/packs/safe-4337/SafeOperation.d.ts +1 -0
  20. package/dist/src/packs/safe-4337/SafeOperation.d.ts.map +1 -0
  21. package/dist/src/packs/safe-4337/constants.d.ts +1 -0
  22. package/dist/src/packs/safe-4337/constants.d.ts.map +1 -0
  23. package/dist/src/packs/safe-4337/estimators/PimlicoFeeEstimator.d.ts +1 -0
  24. package/dist/src/packs/safe-4337/estimators/PimlicoFeeEstimator.d.ts.map +1 -0
  25. package/dist/src/packs/safe-4337/estimators/index.d.ts +1 -0
  26. package/dist/src/packs/safe-4337/estimators/index.d.ts.map +1 -0
  27. package/dist/src/packs/safe-4337/types.d.ts +1 -0
  28. package/dist/src/packs/safe-4337/types.d.ts.map +1 -0
  29. package/dist/src/packs/safe-4337/utils/entrypoint.d.ts +1 -0
  30. package/dist/src/packs/safe-4337/utils/entrypoint.d.ts.map +1 -0
  31. package/dist/src/packs/safe-4337/utils/getRelayKitVersion.d.ts +1 -0
  32. package/dist/src/packs/safe-4337/utils/getRelayKitVersion.d.ts.map +1 -0
  33. package/dist/src/packs/safe-4337/utils.d.ts +1 -0
  34. package/dist/src/packs/safe-4337/utils.d.ts.map +1 -0
  35. package/dist/{src/packs/safe-4337/testing-utils → test-utils}/fixtures.d.ts +1 -0
  36. package/dist/test-utils/fixtures.d.ts.map +1 -0
  37. package/dist/{src/packs/safe-4337/testing-utils → test-utils}/helpers.d.ts +3 -2
  38. package/dist/test-utils/helpers.d.ts.map +1 -0
  39. package/dist/test-utils/index.d.ts +4 -0
  40. package/dist/test-utils/index.d.ts.map +1 -0
  41. package/dist/tsconfig.build.tsbuildinfo +1 -1
  42. package/package.json +22 -6
  43. package/dist/src/RelayKitBasePack.js +0 -26
  44. package/dist/src/RelayKitBasePack.js.map +0 -1
  45. package/dist/src/constants.js +0 -12
  46. package/dist/src/constants.js.map +0 -1
  47. package/dist/src/deprecated.js +0 -3
  48. package/dist/src/deprecated.js.map +0 -1
  49. package/dist/src/index.js +0 -30
  50. package/dist/src/index.js.map +0 -1
  51. package/dist/src/packs/gelato/GelatoRelayPack.js +0 -327
  52. package/dist/src/packs/gelato/GelatoRelayPack.js.map +0 -1
  53. package/dist/src/packs/gelato/types.js +0 -3
  54. package/dist/src/packs/gelato/types.js.map +0 -1
  55. package/dist/src/packs/safe-4337/Safe4337Pack.js +0 -644
  56. package/dist/src/packs/safe-4337/Safe4337Pack.js.map +0 -1
  57. package/dist/src/packs/safe-4337/SafeOperation.js +0 -68
  58. package/dist/src/packs/safe-4337/SafeOperation.js.map +0 -1
  59. package/dist/src/packs/safe-4337/constants.js +0 -55
  60. package/dist/src/packs/safe-4337/constants.js.map +0 -1
  61. package/dist/src/packs/safe-4337/estimators/PimlicoFeeEstimator.js +0 -49
  62. package/dist/src/packs/safe-4337/estimators/PimlicoFeeEstimator.js.map +0 -1
  63. package/dist/src/packs/safe-4337/estimators/index.js +0 -6
  64. package/dist/src/packs/safe-4337/estimators/index.js.map +0 -1
  65. package/dist/src/packs/safe-4337/testing-utils/fixtures.js +0 -128
  66. package/dist/src/packs/safe-4337/testing-utils/fixtures.js.map +0 -1
  67. package/dist/src/packs/safe-4337/testing-utils/helpers.js +0 -58
  68. package/dist/src/packs/safe-4337/testing-utils/helpers.js.map +0 -1
  69. package/dist/src/packs/safe-4337/types.js +0 -3
  70. package/dist/src/packs/safe-4337/types.js.map +0 -1
  71. package/dist/src/packs/safe-4337/utils/entrypoint.js +0 -23
  72. package/dist/src/packs/safe-4337/utils/entrypoint.js.map +0 -1
  73. package/dist/src/packs/safe-4337/utils/getRelayKitVersion.js +0 -6
  74. package/dist/src/packs/safe-4337/utils/getRelayKitVersion.js.map +0 -1
  75. package/dist/src/packs/safe-4337/utils.js +0 -190
  76. package/dist/src/packs/safe-4337/utils.js.map +0 -1
@@ -1,644 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
- if (kind === "m") throw new TypeError("Private method is not writable");
27
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
28
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
29
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
30
- };
31
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
32
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
33
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
34
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
- };
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
- var _Safe4337Pack_instances, _Safe4337Pack_BUNDLER_URL, _Safe4337Pack_ENTRYPOINT_ADDRESS, _Safe4337Pack_SAFE_4337_MODULE_ADDRESS, _Safe4337Pack_SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS, _Safe4337Pack_bundlerClient, _Safe4337Pack_chainId, _Safe4337Pack_paymasterOptions, _Safe4337Pack_onchainIdentifier, _Safe4337Pack_toSafeOperation, _Safe4337Pack_timestamp, _Safe4337Pack_getSafeNonceFromEntrypoint, _Safe4337Pack_encodeExecuteUserOpCallData;
40
- Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.Safe4337Pack = void 0;
42
- const satisfies_1 = __importDefault(require("semver/functions/satisfies"));
43
- const protocol_kit_1 = __importStar(require("@safe-global/protocol-kit"));
44
- const RelayKitBasePack_1 = require("../../RelayKitBasePack");
45
- const types_kit_1 = require("@safe-global/types-kit");
46
- const safe_modules_deployments_1 = require("@safe-global/safe-modules-deployments");
47
- const viem_1 = require("viem");
48
- const SafeOperation_1 = __importDefault(require("./SafeOperation"));
49
- const constants_1 = require("./constants");
50
- const utils_1 = require("./utils");
51
- const entrypoint_1 = require("./utils/entrypoint");
52
- const PimlicoFeeEstimator_1 = require("./estimators/PimlicoFeeEstimator");
53
- const getRelayKitVersion_1 = require("./utils/getRelayKitVersion");
54
- const MAX_ERC20_AMOUNT_TO_APPROVE = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn;
55
- const EQ_OR_GT_1_4_1 = '>=1.4.1';
56
- /**
57
- * Safe4337Pack class that extends RelayKitBasePack.
58
- * This class provides an implementation of the ERC-4337 that enables Safe accounts to wrk with UserOperations.
59
- * It allows to create, sign and execute transactions using the Safe 4337 Module.
60
- *
61
- * @class
62
- * @link https://github.com/safe-global/safe-modules/blob/main/modules/4337/contracts/Safe4337Module.sol
63
- * @link https://eips.ethereum.org/EIPS/eip-4337
64
- */
65
- class Safe4337Pack extends RelayKitBasePack_1.RelayKitBasePack {
66
- /**
67
- * Creates an instance of the Safe4337Pack.
68
- *
69
- * @param {Safe4337Options} options - The initialization parameters.
70
- */
71
- constructor({ protocolKit, bundlerClient, bundlerUrl, chainId, paymasterOptions, entryPointAddress, safe4337ModuleAddress, safeWebAuthnSharedSignerAddress, onchainAnalytics }) {
72
- super(protocolKit);
73
- _Safe4337Pack_instances.add(this);
74
- _Safe4337Pack_BUNDLER_URL.set(this, void 0);
75
- _Safe4337Pack_ENTRYPOINT_ADDRESS.set(this, void 0);
76
- _Safe4337Pack_SAFE_4337_MODULE_ADDRESS.set(this, '0x');
77
- _Safe4337Pack_SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS.set(this, '0x');
78
- _Safe4337Pack_bundlerClient.set(this, void 0);
79
- _Safe4337Pack_chainId.set(this, void 0);
80
- _Safe4337Pack_paymasterOptions.set(this, void 0);
81
- _Safe4337Pack_onchainIdentifier.set(this, ''
82
- /**
83
- * Creates an instance of the Safe4337Pack.
84
- *
85
- * @param {Safe4337Options} options - The initialization parameters.
86
- */
87
- );
88
- __classPrivateFieldSet(this, _Safe4337Pack_BUNDLER_URL, bundlerUrl, "f");
89
- __classPrivateFieldSet(this, _Safe4337Pack_bundlerClient, bundlerClient, "f");
90
- __classPrivateFieldSet(this, _Safe4337Pack_chainId, chainId, "f");
91
- __classPrivateFieldSet(this, _Safe4337Pack_paymasterOptions, paymasterOptions, "f");
92
- __classPrivateFieldSet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, entryPointAddress, "f");
93
- __classPrivateFieldSet(this, _Safe4337Pack_SAFE_4337_MODULE_ADDRESS, safe4337ModuleAddress, "f");
94
- __classPrivateFieldSet(this, _Safe4337Pack_SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS, safeWebAuthnSharedSignerAddress || '0x', "f");
95
- if (onchainAnalytics?.project) {
96
- const { project, platform } = onchainAnalytics;
97
- __classPrivateFieldSet(this, _Safe4337Pack_onchainIdentifier, (0, protocol_kit_1.generateOnChainIdentifier)({
98
- project,
99
- platform,
100
- tool: 'relay-kit',
101
- toolVersion: (0, getRelayKitVersion_1.getRelayKitVersion)()
102
- }), "f");
103
- }
104
- }
105
- /**
106
- * Initializes a Safe4337Pack class.
107
- * This method creates the protocolKit instance based on the input parameters.
108
- * When the Safe address is provided, it will use the existing Safe.
109
- * When the Safe address is not provided, it will use the predictedSafe feature with the provided owners and threshold.
110
- * It will use the correct contract addresses for the fallbackHandler and the module and will add the data to enable the 4337 module.
111
- *
112
- * @param {Safe4337InitOptions} initOptions - The initialization parameters.
113
- * @return {Promise<Safe4337Pack>} The Promise object that will be resolved into an instance of Safe4337Pack.
114
- */
115
- static async init(initOptions) {
116
- const { provider, signer, options, bundlerUrl, customContracts, paymasterOptions, onchainAnalytics } = initOptions;
117
- let protocolKit;
118
- const bundlerClient = (0, utils_1.getEip4337BundlerProvider)(bundlerUrl);
119
- const chainId = await bundlerClient.request({ method: constants_1.RPC_4337_CALLS.CHAIN_ID });
120
- let addModulesLibAddress = customContracts?.addModulesLibAddress;
121
- const network = parseInt(chainId, 16).toString();
122
- const safeModulesVersion = initOptions.safeModulesVersion || constants_1.DEFAULT_SAFE_MODULES_VERSION;
123
- if ((0, satisfies_1.default)(safeModulesVersion, entrypoint_1.EQ_OR_GT_0_3_0)) {
124
- throw new Error(`Incompatibility detected: Safe modules version ${safeModulesVersion} is not supported. The SDK can use 0.2.0 only.`);
125
- }
126
- if (!addModulesLibAddress) {
127
- const addModulesDeployment = (0, safe_modules_deployments_1.getAddModulesLibDeployment)({
128
- released: true,
129
- version: safeModulesVersion,
130
- network
131
- });
132
- addModulesLibAddress = addModulesDeployment?.networkAddresses[network];
133
- }
134
- let safe4337ModuleAddress = customContracts?.safe4337ModuleAddress;
135
- if (!safe4337ModuleAddress) {
136
- const safe4337ModuleDeployment = (0, safe_modules_deployments_1.getSafe4337ModuleDeployment)({
137
- released: true,
138
- version: safeModulesVersion,
139
- network
140
- });
141
- safe4337ModuleAddress = safe4337ModuleDeployment?.networkAddresses[network];
142
- }
143
- if (!addModulesLibAddress || !safe4337ModuleAddress) {
144
- throw new Error(`Safe4337Module and/or AddModulesLib not available for chain ${network} and modules version ${safeModulesVersion}`);
145
- }
146
- let safeWebAuthnSharedSignerAddress = customContracts?.safeWebAuthnSharedSignerAddress;
147
- // Existing Safe
148
- if ('safeAddress' in options) {
149
- protocolKit = await protocol_kit_1.default.init({
150
- provider,
151
- signer,
152
- safeAddress: options.safeAddress
153
- });
154
- const safeVersion = protocolKit.getContractVersion();
155
- const isSafeVersion4337Compatible = (0, satisfies_1.default)(safeVersion, EQ_OR_GT_1_4_1);
156
- if (!isSafeVersion4337Compatible) {
157
- throw new Error(`Incompatibility detected: The current Safe Account version (${safeVersion}) is not supported. EIP-4337 requires the Safe to use at least v1.4.1.`);
158
- }
159
- const safeModules = (await protocolKit.getModules());
160
- const is4337ModulePresent = safeModules.some((module) => module === safe4337ModuleAddress);
161
- if (!is4337ModulePresent) {
162
- throw new Error(`Incompatibility detected: The EIP-4337 module is not enabled in the provided Safe Account. Enable this module (address: ${safe4337ModuleAddress}) to add compatibility.`);
163
- }
164
- const safeFallbackhandler = await protocolKit.getFallbackHandler();
165
- const is4337FallbackhandlerPresent = safeFallbackhandler === safe4337ModuleAddress;
166
- if (!is4337FallbackhandlerPresent) {
167
- throw new Error(`Incompatibility detected: The EIP-4337 fallbackhandler is not attached to the Safe Account. Attach this fallbackhandler (address: ${safe4337ModuleAddress}) to ensure compatibility.`);
168
- }
169
- }
170
- else {
171
- // New Safe will be created based on the provided configuration when bundling a new UserOperation
172
- if (!options.owners || !options.threshold) {
173
- throw new Error('Owners and threshold are required to deploy a new Safe');
174
- }
175
- const safeVersion = options.safeVersion || constants_1.DEFAULT_SAFE_VERSION;
176
- // we need to create a batch to setup the 4337 Safe Account
177
- // first setup transaction: Enable 4337 module
178
- const enable4337ModuleTransaction = {
179
- to: addModulesLibAddress,
180
- value: '0',
181
- data: (0, viem_1.encodeFunctionData)({
182
- abi: constants_1.ABI,
183
- functionName: 'enableModules',
184
- args: [[safe4337ModuleAddress]]
185
- }),
186
- operation: types_kit_1.OperationType.DelegateCall // DelegateCall required for enabling the 4337 module
187
- };
188
- const setupTransactions = [enable4337ModuleTransaction];
189
- const isApproveTransactionRequired = !!paymasterOptions &&
190
- !paymasterOptions.isSponsored &&
191
- !!paymasterOptions.paymasterTokenAddress;
192
- if (isApproveTransactionRequired) {
193
- const { paymasterAddress, amountToApprove = MAX_ERC20_AMOUNT_TO_APPROVE } = paymasterOptions;
194
- // second transaction: approve ERC-20 paymaster token
195
- const approveToPaymasterTransaction = {
196
- to: paymasterOptions.paymasterTokenAddress,
197
- data: (0, viem_1.encodeFunctionData)({
198
- abi: constants_1.ABI,
199
- functionName: 'approve',
200
- args: [paymasterAddress, amountToApprove]
201
- }),
202
- value: '0',
203
- operation: types_kit_1.OperationType.Call // Call for approve
204
- };
205
- setupTransactions.push(approveToPaymasterTransaction);
206
- }
207
- const safeProvider = await protocol_kit_1.SafeProvider.init({ provider, signer, safeVersion });
208
- // third transaction: passkey support via shared signer SafeWebAuthnSharedSigner
209
- // see: https://github.com/safe-global/safe-modules/blob/main/modules/passkey/contracts/4337/experimental/README.md
210
- const isPasskeySigner = await safeProvider.isPasskeySigner();
211
- if (isPasskeySigner) {
212
- if (!safeWebAuthnSharedSignerAddress) {
213
- const safeWebAuthnSharedSignerDeployment = (0, safe_modules_deployments_1.getSafeWebAuthnShareSignerDeployment)({
214
- released: true,
215
- version: '0.2.1',
216
- network
217
- });
218
- safeWebAuthnSharedSignerAddress =
219
- safeWebAuthnSharedSignerDeployment?.networkAddresses[network];
220
- }
221
- if (!safeWebAuthnSharedSignerAddress) {
222
- throw new Error(`safeWebAuthnSharedSignerAddress not available for chain ${network}`);
223
- }
224
- const passkeySigner = (await safeProvider.getExternalSigner());
225
- if (!options.owners.includes(safeWebAuthnSharedSignerAddress)) {
226
- options.owners.push(safeWebAuthnSharedSignerAddress);
227
- }
228
- const sharedSignerTransaction = {
229
- to: safeWebAuthnSharedSignerAddress,
230
- value: '0',
231
- data: passkeySigner.encodeConfigure(),
232
- operation: types_kit_1.OperationType.DelegateCall // DelegateCall required into the SafeWebAuthnSharedSigner instance in order for it to set its configuration.
233
- };
234
- setupTransactions.push(sharedSignerTransaction);
235
- }
236
- let deploymentTo;
237
- let deploymentData;
238
- const isBatch = setupTransactions.length > 1;
239
- if (isBatch) {
240
- const multiSendContract = await (0, protocol_kit_1.getMultiSendContract)({
241
- safeProvider,
242
- safeVersion,
243
- deploymentType: options.deploymentType || undefined
244
- });
245
- const batchData = (0, viem_1.encodeFunctionData)({
246
- abi: constants_1.ABI,
247
- functionName: 'multiSend',
248
- args: [(0, protocol_kit_1.encodeMultiSendData)(setupTransactions)]
249
- });
250
- deploymentTo = multiSendContract.getAddress();
251
- deploymentData = batchData;
252
- }
253
- else {
254
- deploymentTo = enable4337ModuleTransaction.to;
255
- deploymentData = enable4337ModuleTransaction.data;
256
- }
257
- protocolKit = await protocol_kit_1.default.init({
258
- provider,
259
- signer,
260
- predictedSafe: {
261
- safeDeploymentConfig: {
262
- safeVersion,
263
- saltNonce: options.saltNonce || undefined,
264
- deploymentType: options.deploymentType || undefined
265
- },
266
- safeAccountConfig: {
267
- owners: options.owners,
268
- threshold: options.threshold,
269
- to: deploymentTo,
270
- data: deploymentData,
271
- fallbackHandler: safe4337ModuleAddress,
272
- paymentToken: viem_1.zeroAddress,
273
- payment: 0,
274
- paymentReceiver: viem_1.zeroAddress
275
- }
276
- },
277
- onchainAnalytics
278
- });
279
- }
280
- let selectedEntryPoint;
281
- if (customContracts?.entryPointAddress) {
282
- const requiredSafeModulesVersion = (0, entrypoint_1.entryPointToSafeModules)(customContracts?.entryPointAddress);
283
- if (!(0, satisfies_1.default)(safeModulesVersion, requiredSafeModulesVersion))
284
- throw new Error(`The selected entrypoint ${customContracts?.entryPointAddress} is not compatible with version ${safeModulesVersion} of Safe modules`);
285
- selectedEntryPoint = customContracts?.entryPointAddress;
286
- }
287
- else {
288
- const supportedEntryPoints = await bundlerClient.request({
289
- method: constants_1.RPC_4337_CALLS.SUPPORTED_ENTRY_POINTS
290
- });
291
- if (!supportedEntryPoints.length) {
292
- throw new Error('No entrypoint provided or available through the bundler');
293
- }
294
- selectedEntryPoint = supportedEntryPoints.find((entryPoint) => {
295
- const requiredSafeModulesVersion = (0, entrypoint_1.entryPointToSafeModules)(entryPoint);
296
- return (0, satisfies_1.default)(safeModulesVersion, requiredSafeModulesVersion);
297
- });
298
- if (!selectedEntryPoint) {
299
- throw new Error(`Incompatibility detected: None of the entrypoints provided by the bundler is compatible with the Safe modules version ${safeModulesVersion}`);
300
- }
301
- }
302
- return new Safe4337Pack({
303
- chainId: BigInt(chainId),
304
- protocolKit,
305
- bundlerClient,
306
- paymasterOptions,
307
- bundlerUrl,
308
- entryPointAddress: selectedEntryPoint,
309
- safe4337ModuleAddress,
310
- safeWebAuthnSharedSignerAddress,
311
- onchainAnalytics
312
- });
313
- }
314
- /**
315
- * Estimates gas for the SafeOperation.
316
- *
317
- * @param {EstimateFeeProps} props - The parameters for the gas estimation.
318
- * @param {EthSafeOperation} props.safeOperation - The SafeOperation to estimate the gas.
319
- * @param {IFeeEstimator} props.feeEstimator - The function to estimate the gas.
320
- * @return {Promise<EthSafeOperation>} The Promise object that will be resolved into the gas estimation.
321
- */
322
- async getEstimateFee({ safeOperation, feeEstimator = new PimlicoFeeEstimator_1.PimlicoFeeEstimator() }) {
323
- const threshold = await this.protocolKit.getThreshold();
324
- const setupEstimationData = await feeEstimator?.setupEstimation?.({
325
- bundlerUrl: __classPrivateFieldGet(this, _Safe4337Pack_BUNDLER_URL, "f"),
326
- entryPoint: __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f"),
327
- userOperation: safeOperation.toUserOperation()
328
- });
329
- if (setupEstimationData) {
330
- safeOperation.addEstimations(setupEstimationData);
331
- }
332
- const estimateUserOperationGas = await __classPrivateFieldGet(this, _Safe4337Pack_bundlerClient, "f").request({
333
- method: constants_1.RPC_4337_CALLS.ESTIMATE_USER_OPERATION_GAS,
334
- params: [
335
- (0, utils_1.userOperationToHexValues)((0, utils_1.addDummySignature)(safeOperation.toUserOperation(), __classPrivateFieldGet(this, _Safe4337Pack_SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS, "f"), threshold)),
336
- __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f")
337
- ]
338
- });
339
- if (estimateUserOperationGas) {
340
- safeOperation.addEstimations({
341
- preVerificationGas: BigInt(estimateUserOperationGas.preVerificationGas),
342
- verificationGasLimit: BigInt(estimateUserOperationGas.verificationGasLimit),
343
- callGasLimit: BigInt(estimateUserOperationGas.callGasLimit)
344
- });
345
- }
346
- const adjustEstimationData = await feeEstimator?.adjustEstimation?.({
347
- bundlerUrl: __classPrivateFieldGet(this, _Safe4337Pack_BUNDLER_URL, "f"),
348
- entryPoint: __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f"),
349
- userOperation: safeOperation.toUserOperation()
350
- });
351
- if (adjustEstimationData) {
352
- safeOperation.addEstimations(adjustEstimationData);
353
- }
354
- if (__classPrivateFieldGet(this, _Safe4337Pack_paymasterOptions, "f")?.isSponsored) {
355
- if (!__classPrivateFieldGet(this, _Safe4337Pack_paymasterOptions, "f").paymasterUrl) {
356
- throw new Error('No paymaster url provided for a sponsored transaction');
357
- }
358
- const paymasterEstimation = await feeEstimator?.getPaymasterEstimation?.({
359
- userOperation: (0, utils_1.addDummySignature)(safeOperation.toUserOperation(), __classPrivateFieldGet(this, _Safe4337Pack_SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS, "f"), threshold),
360
- paymasterUrl: __classPrivateFieldGet(this, _Safe4337Pack_paymasterOptions, "f").paymasterUrl,
361
- entryPoint: __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f"),
362
- sponsorshipPolicyId: __classPrivateFieldGet(this, _Safe4337Pack_paymasterOptions, "f").sponsorshipPolicyId
363
- });
364
- safeOperation.data.paymasterAndData =
365
- paymasterEstimation?.paymasterAndData || safeOperation.data.paymasterAndData;
366
- if (paymasterEstimation) {
367
- safeOperation.addEstimations(paymasterEstimation);
368
- }
369
- }
370
- return safeOperation;
371
- }
372
- /**
373
- * Creates a relayed transaction based on the provided parameters.
374
- *
375
- * @param {MetaTransactionData[]} transactions - The transactions to batch in a SafeOperation.
376
- * @param options - Optional configuration options for the transaction creation.
377
- * @return {Promise<EthSafeOperation>} The Promise object will resolve a SafeOperation.
378
- */
379
- async createTransaction({ transactions, options = {} }) {
380
- const safeAddress = await this.protocolKit.getAddress();
381
- const nonce = await __classPrivateFieldGet(this, _Safe4337Pack_instances, "m", _Safe4337Pack_getSafeNonceFromEntrypoint).call(this, safeAddress);
382
- const { amountToApprove, validUntil, validAfter, feeEstimator } = options;
383
- if (amountToApprove) {
384
- const paymasterOptions = __classPrivateFieldGet(this, _Safe4337Pack_paymasterOptions, "f");
385
- if (!paymasterOptions.paymasterTokenAddress) {
386
- throw new Error('Paymaster must be initialized');
387
- }
388
- const approveToPaymasterTransaction = {
389
- to: paymasterOptions.paymasterTokenAddress,
390
- data: (0, viem_1.encodeFunctionData)({
391
- abi: constants_1.ABI,
392
- functionName: 'approve',
393
- args: [paymasterOptions.paymasterAddress, amountToApprove]
394
- }),
395
- value: '0',
396
- operation: types_kit_1.OperationType.Call // Call for approve
397
- };
398
- transactions.push(approveToPaymasterTransaction);
399
- }
400
- const isBatch = transactions.length > 1;
401
- const multiSendAddress = this.protocolKit.getMultiSendAddress();
402
- const callData = isBatch
403
- ? __classPrivateFieldGet(this, _Safe4337Pack_instances, "m", _Safe4337Pack_encodeExecuteUserOpCallData).call(this, {
404
- to: multiSendAddress,
405
- value: '0',
406
- data: (0, utils_1.encodeMultiSendCallData)(transactions),
407
- operation: types_kit_1.OperationType.DelegateCall
408
- })
409
- : __classPrivateFieldGet(this, _Safe4337Pack_instances, "m", _Safe4337Pack_encodeExecuteUserOpCallData).call(this, transactions[0]);
410
- const paymasterAndData = __classPrivateFieldGet(this, _Safe4337Pack_paymasterOptions, "f") && 'paymasterAddress' in __classPrivateFieldGet(this, _Safe4337Pack_paymasterOptions, "f")
411
- ? __classPrivateFieldGet(this, _Safe4337Pack_paymasterOptions, "f").paymasterAddress
412
- : '0x';
413
- const userOperation = {
414
- sender: safeAddress,
415
- nonce: nonce,
416
- initCode: '0x',
417
- callData,
418
- callGasLimit: 1n,
419
- verificationGasLimit: 1n,
420
- preVerificationGas: 1n,
421
- maxFeePerGas: 1n,
422
- maxPriorityFeePerGas: 1n,
423
- paymasterAndData,
424
- signature: '0x'
425
- };
426
- if (__classPrivateFieldGet(this, _Safe4337Pack_onchainIdentifier, "f")) {
427
- userOperation.callData += __classPrivateFieldGet(this, _Safe4337Pack_onchainIdentifier, "f");
428
- }
429
- const isSafeDeployed = await this.protocolKit.isSafeDeployed();
430
- if (!isSafeDeployed) {
431
- userOperation.initCode = await this.protocolKit.getInitCode();
432
- }
433
- const safeOperation = new SafeOperation_1.default(userOperation, {
434
- chainId: __classPrivateFieldGet(this, _Safe4337Pack_chainId, "f"),
435
- moduleAddress: __classPrivateFieldGet(this, _Safe4337Pack_SAFE_4337_MODULE_ADDRESS, "f"),
436
- entryPoint: __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f"),
437
- validUntil,
438
- validAfter
439
- });
440
- return await this.getEstimateFee({
441
- safeOperation,
442
- feeEstimator
443
- });
444
- }
445
- /**
446
- * Signs a safe operation.
447
- *
448
- * @param {EthSafeOperation | SafeOperationResponse} safeOperation - The SafeOperation to sign. It can be:
449
- * - A response from the API (Tx Service)
450
- * - An instance of EthSafeOperation
451
- * @param {SigningMethod} signingMethod - The signing method to use.
452
- * @return {Promise<EthSafeOperation>} The Promise object will resolve to the signed SafeOperation.
453
- */
454
- async signSafeOperation(safeOperation, signingMethod = protocol_kit_1.SigningMethod.ETH_SIGN_TYPED_DATA_V4) {
455
- let safeOp;
456
- if ((0, types_kit_1.isSafeOperationResponse)(safeOperation)) {
457
- safeOp = __classPrivateFieldGet(this, _Safe4337Pack_instances, "m", _Safe4337Pack_toSafeOperation).call(this, safeOperation);
458
- }
459
- else {
460
- safeOp = safeOperation;
461
- }
462
- const safeProvider = this.protocolKit.getSafeProvider();
463
- const signerAddress = await safeProvider.getSignerAddress();
464
- const isPasskeySigner = await safeProvider.isPasskeySigner();
465
- if (!signerAddress) {
466
- throw new Error('There is no signer address available to sign the SafeOperation');
467
- }
468
- const isOwner = await this.protocolKit.isOwner(signerAddress);
469
- const isSafeDeployed = await this.protocolKit.isSafeDeployed();
470
- if ((!isOwner && isSafeDeployed) || (!isSafeDeployed && !isPasskeySigner && !isOwner)) {
471
- throw new Error('UserOperations can only be signed by Safe owners');
472
- }
473
- let signature;
474
- if (isPasskeySigner) {
475
- const safeOpHash = safeOp.getHash();
476
- // if the Safe is not deployed we force the Shared Signer signature
477
- if (!isSafeDeployed) {
478
- const passkeySignature = await this.protocolKit.signHash(safeOpHash);
479
- // SafeWebAuthnSharedSigner signature
480
- signature = new protocol_kit_1.EthSafeSignature(__classPrivateFieldGet(this, _Safe4337Pack_SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS, "f"), passkeySignature.data, true // passkeys are contract signatures
481
- );
482
- }
483
- else {
484
- signature = await this.protocolKit.signHash(safeOpHash);
485
- }
486
- }
487
- else {
488
- if (signingMethod in
489
- [
490
- protocol_kit_1.SigningMethod.ETH_SIGN_TYPED_DATA_V4,
491
- protocol_kit_1.SigningMethod.ETH_SIGN_TYPED_DATA_V3,
492
- protocol_kit_1.SigningMethod.ETH_SIGN_TYPED_DATA
493
- ]) {
494
- signature = await (0, utils_1.signSafeOp)(safeOp.data, this.protocolKit.getSafeProvider(), __classPrivateFieldGet(this, _Safe4337Pack_SAFE_4337_MODULE_ADDRESS, "f"));
495
- }
496
- else {
497
- const safeOpHash = safeOp.getHash();
498
- signature = await this.protocolKit.signHash(safeOpHash);
499
- }
500
- }
501
- const signedSafeOperation = new SafeOperation_1.default(safeOp.toUserOperation(), {
502
- chainId: __classPrivateFieldGet(this, _Safe4337Pack_chainId, "f"),
503
- moduleAddress: __classPrivateFieldGet(this, _Safe4337Pack_SAFE_4337_MODULE_ADDRESS, "f"),
504
- entryPoint: __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f"),
505
- validUntil: safeOp.data.validUntil,
506
- validAfter: safeOp.data.validAfter
507
- });
508
- safeOp.signatures.forEach((signature) => {
509
- signedSafeOperation.addSignature(signature);
510
- });
511
- signedSafeOperation.addSignature(signature);
512
- return signedSafeOperation;
513
- }
514
- /**
515
- * Executes the relay transaction.
516
- *
517
- * @param {Safe4337ExecutableProps} props - The parameters for the transaction execution.
518
- * @param {EthSafeOperation | SafeOperationResponse} props.executable - The SafeOperation to execute. It can be:
519
- * - A response from the API (Tx Service)
520
- * - An instance of EthSafeOperation
521
- * @return {Promise<string>} The user operation hash.
522
- */
523
- async executeTransaction({ executable }) {
524
- let safeOperation;
525
- if ((0, types_kit_1.isSafeOperationResponse)(executable)) {
526
- safeOperation = __classPrivateFieldGet(this, _Safe4337Pack_instances, "m", _Safe4337Pack_toSafeOperation).call(this, executable);
527
- }
528
- else {
529
- safeOperation = executable;
530
- }
531
- const userOperation = safeOperation.toUserOperation();
532
- return __classPrivateFieldGet(this, _Safe4337Pack_bundlerClient, "f").request({
533
- method: constants_1.RPC_4337_CALLS.SEND_USER_OPERATION,
534
- params: [(0, utils_1.userOperationToHexValues)(userOperation), __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f")]
535
- });
536
- }
537
- /**
538
- * Return a UserOperation based on a hash (userOpHash) returned by eth_sendUserOperation
539
- *
540
- * @param {string} userOpHash - The hash of the user operation to fetch. Returned from the #sendUserOperation method
541
- * @returns {UserOperation} - null in case the UserOperation is not yet included in a block, or a full UserOperation, with the addition of entryPoint, blockNumber, blockHash and transactionHash
542
- */
543
- async getUserOperationByHash(userOpHash) {
544
- return __classPrivateFieldGet(this, _Safe4337Pack_bundlerClient, "f").request({
545
- method: constants_1.RPC_4337_CALLS.GET_USER_OPERATION_BY_HASH,
546
- params: [userOpHash]
547
- });
548
- }
549
- /**
550
- * Return a UserOperation receipt based on a hash (userOpHash) returned by eth_sendUserOperation
551
- *
552
- * @param {string} userOpHash - The hash of the user operation to fetch. Returned from the #sendUserOperation method
553
- * @returns {UserOperationReceipt} - null in case the UserOperation is not yet included in a block, or UserOperationReceipt object
554
- */
555
- async getUserOperationReceipt(userOpHash) {
556
- return __classPrivateFieldGet(this, _Safe4337Pack_bundlerClient, "f").request({
557
- method: constants_1.RPC_4337_CALLS.GET_USER_OPERATION_RECEIPT,
558
- params: [userOpHash]
559
- });
560
- }
561
- /**
562
- * Returns an array of the entryPoint addresses supported by the client.
563
- * The first element of the array SHOULD be the entryPoint addressed preferred by the client.
564
- *
565
- * @returns {string[]} - The supported entry points.
566
- */
567
- async getSupportedEntryPoints() {
568
- return __classPrivateFieldGet(this, _Safe4337Pack_bundlerClient, "f").request({
569
- method: constants_1.RPC_4337_CALLS.SUPPORTED_ENTRY_POINTS
570
- });
571
- }
572
- /**
573
- * Returns EIP-155 Chain ID.
574
- *
575
- * @returns {string} - The chain id.
576
- */
577
- async getChainId() {
578
- return __classPrivateFieldGet(this, _Safe4337Pack_bundlerClient, "f").request({ method: constants_1.RPC_4337_CALLS.CHAIN_ID });
579
- }
580
- getOnchainIdentifier() {
581
- return __classPrivateFieldGet(this, _Safe4337Pack_onchainIdentifier, "f");
582
- }
583
- }
584
- exports.Safe4337Pack = Safe4337Pack;
585
- _Safe4337Pack_BUNDLER_URL = new WeakMap(), _Safe4337Pack_ENTRYPOINT_ADDRESS = new WeakMap(), _Safe4337Pack_SAFE_4337_MODULE_ADDRESS = new WeakMap(), _Safe4337Pack_SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS = new WeakMap(), _Safe4337Pack_bundlerClient = new WeakMap(), _Safe4337Pack_chainId = new WeakMap(), _Safe4337Pack_paymasterOptions = new WeakMap(), _Safe4337Pack_onchainIdentifier = new WeakMap(), _Safe4337Pack_instances = new WeakSet(), _Safe4337Pack_toSafeOperation = function _Safe4337Pack_toSafeOperation(safeOperationResponse) {
586
- const { validUntil, validAfter, userOperation } = safeOperationResponse;
587
- const paymaster = userOperation?.paymaster || '0x';
588
- const paymasterData = userOperation?.paymasterData || '0x';
589
- const safeOperation = new SafeOperation_1.default({
590
- sender: userOperation?.sender || '0x',
591
- nonce: userOperation?.nonce?.toString() || '0',
592
- initCode: userOperation?.initCode || '',
593
- callData: userOperation?.callData || '',
594
- callGasLimit: BigInt(userOperation?.callGasLimit || 0n),
595
- verificationGasLimit: BigInt(userOperation?.verificationGasLimit || 0),
596
- preVerificationGas: BigInt(userOperation?.preVerificationGas || 0),
597
- maxFeePerGas: BigInt(userOperation?.maxFeePerGas || 0),
598
- maxPriorityFeePerGas: BigInt(userOperation?.maxPriorityFeePerGas || 0),
599
- paymasterAndData: (0, viem_1.concat)([paymaster, paymasterData]),
600
- signature: safeOperationResponse.preparedSignature || '0x'
601
- }, {
602
- chainId: __classPrivateFieldGet(this, _Safe4337Pack_chainId, "f"),
603
- moduleAddress: __classPrivateFieldGet(this, _Safe4337Pack_SAFE_4337_MODULE_ADDRESS, "f"),
604
- entryPoint: userOperation?.entryPoint || __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f"),
605
- validAfter: __classPrivateFieldGet(this, _Safe4337Pack_instances, "m", _Safe4337Pack_timestamp).call(this, validAfter),
606
- validUntil: __classPrivateFieldGet(this, _Safe4337Pack_instances, "m", _Safe4337Pack_timestamp).call(this, validUntil)
607
- });
608
- if (safeOperationResponse.confirmations) {
609
- safeOperationResponse.confirmations.forEach((confirmation) => {
610
- safeOperation.addSignature(new protocol_kit_1.EthSafeSignature(confirmation.owner, confirmation.signature));
611
- });
612
- }
613
- return safeOperation;
614
- }, _Safe4337Pack_timestamp = function _Safe4337Pack_timestamp(date) {
615
- return date ? new Date(date).getTime() / 1000 : undefined;
616
- }, _Safe4337Pack_getSafeNonceFromEntrypoint =
617
- /**
618
- * Gets account nonce from the bundler.
619
- *
620
- * @param {string} safeAddress - Account address for which the nonce is to be fetched.
621
- * @returns {Promise<string>} The Promise object will resolve to the account nonce.
622
- */
623
- async function _Safe4337Pack_getSafeNonceFromEntrypoint(safeAddress) {
624
- const safeProvider = this.protocolKit.getSafeProvider();
625
- const newNonce = await safeProvider.readContract({
626
- address: __classPrivateFieldGet(this, _Safe4337Pack_ENTRYPOINT_ADDRESS, "f") || '0x',
627
- abi: constants_1.ENTRYPOINT_ABI,
628
- functionName: 'getNonce',
629
- args: [safeAddress, 0n]
630
- });
631
- return newNonce.toString();
632
- }, _Safe4337Pack_encodeExecuteUserOpCallData = function _Safe4337Pack_encodeExecuteUserOpCallData(transaction) {
633
- return (0, viem_1.encodeFunctionData)({
634
- abi: constants_1.ABI,
635
- functionName: 'executeUserOp',
636
- args: [
637
- transaction.to,
638
- BigInt(transaction.value),
639
- transaction.data,
640
- transaction.operation || types_kit_1.OperationType.Call
641
- ]
642
- });
643
- };
644
- //# sourceMappingURL=Safe4337Pack.js.map