@safe-global/relay-kit 3.4.1-alpha.1 → 3.4.1

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/src/RelayKitBasePack.d.ts +0 -1
  2. package/dist/src/RelayKitBasePack.js +26 -0
  3. package/dist/src/RelayKitBasePack.js.map +1 -0
  4. package/dist/src/constants.d.ts +0 -1
  5. package/dist/src/constants.js +12 -0
  6. package/dist/src/constants.js.map +1 -0
  7. package/dist/src/deprecated.d.ts +0 -1
  8. package/dist/src/deprecated.js +3 -0
  9. package/dist/src/deprecated.js.map +1 -0
  10. package/dist/src/index.d.ts +0 -2
  11. package/dist/src/index.js +30 -0
  12. package/dist/src/index.js.map +1 -0
  13. package/dist/src/packs/gelato/GelatoRelayPack.d.ts +0 -1
  14. package/dist/src/packs/gelato/GelatoRelayPack.js +327 -0
  15. package/dist/src/packs/gelato/GelatoRelayPack.js.map +1 -0
  16. package/dist/src/packs/gelato/types.d.ts +0 -1
  17. package/dist/src/packs/gelato/types.js +3 -0
  18. package/dist/src/packs/gelato/types.js.map +1 -0
  19. package/dist/src/packs/safe-4337/Safe4337Pack.d.ts +0 -1
  20. package/dist/src/packs/safe-4337/Safe4337Pack.js +644 -0
  21. package/dist/src/packs/safe-4337/Safe4337Pack.js.map +1 -0
  22. package/dist/src/packs/safe-4337/SafeOperation.d.ts +0 -1
  23. package/dist/src/packs/safe-4337/SafeOperation.js +68 -0
  24. package/dist/src/packs/safe-4337/SafeOperation.js.map +1 -0
  25. package/dist/src/packs/safe-4337/constants.d.ts +0 -1
  26. package/dist/src/packs/safe-4337/constants.js +55 -0
  27. package/dist/src/packs/safe-4337/constants.js.map +1 -0
  28. package/dist/src/packs/safe-4337/estimators/PimlicoFeeEstimator.d.ts +0 -1
  29. package/dist/src/packs/safe-4337/estimators/PimlicoFeeEstimator.js +49 -0
  30. package/dist/src/packs/safe-4337/estimators/PimlicoFeeEstimator.js.map +1 -0
  31. package/dist/src/packs/safe-4337/estimators/index.d.ts +0 -1
  32. package/dist/src/packs/safe-4337/estimators/index.js +6 -0
  33. package/dist/src/packs/safe-4337/estimators/index.js.map +1 -0
  34. package/dist/{test-utils → src/packs/safe-4337/testing-utils}/fixtures.d.ts +6 -7
  35. package/dist/src/packs/safe-4337/testing-utils/fixtures.js +128 -0
  36. package/dist/src/packs/safe-4337/testing-utils/fixtures.js.map +1 -0
  37. package/dist/{test-utils → src/packs/safe-4337/testing-utils}/helpers.d.ts +2 -3
  38. package/dist/src/packs/safe-4337/testing-utils/helpers.js +58 -0
  39. package/dist/src/packs/safe-4337/testing-utils/helpers.js.map +1 -0
  40. package/dist/src/packs/safe-4337/types.d.ts +0 -1
  41. package/dist/src/packs/safe-4337/types.js +3 -0
  42. package/dist/src/packs/safe-4337/types.js.map +1 -0
  43. package/dist/src/packs/safe-4337/utils/entrypoint.d.ts +0 -1
  44. package/dist/src/packs/safe-4337/utils/entrypoint.js +23 -0
  45. package/dist/src/packs/safe-4337/utils/entrypoint.js.map +1 -0
  46. package/dist/src/packs/safe-4337/utils/getRelayKitVersion.d.ts +0 -1
  47. package/dist/src/packs/safe-4337/utils/getRelayKitVersion.js +6 -0
  48. package/dist/src/packs/safe-4337/utils/getRelayKitVersion.js.map +1 -0
  49. package/dist/src/packs/safe-4337/utils.d.ts +0 -1
  50. package/dist/src/packs/safe-4337/utils.js +190 -0
  51. package/dist/src/packs/safe-4337/utils.js.map +1 -0
  52. package/dist/tsconfig.build.tsbuildinfo +1 -1
  53. package/package.json +7 -24
  54. package/dist/cjs/src/index.cjs +0 -1323
  55. package/dist/cjs/test-utils/index.cjs +0 -1171
  56. package/dist/esm/src/index.mjs +0 -1326
  57. package/dist/esm/test-utils/index.mjs +0 -1172
  58. package/dist/src/RelayKitBasePack.d.ts.map +0 -1
  59. package/dist/src/constants.d.ts.map +0 -1
  60. package/dist/src/deprecated.d.ts.map +0 -1
  61. package/dist/src/index.d.ts.map +0 -1
  62. package/dist/src/packs/gelato/GelatoRelayPack.d.ts.map +0 -1
  63. package/dist/src/packs/gelato/types.d.ts.map +0 -1
  64. package/dist/src/packs/safe-4337/Safe4337Pack.d.ts.map +0 -1
  65. package/dist/src/packs/safe-4337/SafeOperation.d.ts.map +0 -1
  66. package/dist/src/packs/safe-4337/constants.d.ts.map +0 -1
  67. package/dist/src/packs/safe-4337/estimators/PimlicoFeeEstimator.d.ts.map +0 -1
  68. package/dist/src/packs/safe-4337/estimators/index.d.ts.map +0 -1
  69. package/dist/src/packs/safe-4337/types.d.ts.map +0 -1
  70. package/dist/src/packs/safe-4337/utils/entrypoint.d.ts.map +0 -1
  71. package/dist/src/packs/safe-4337/utils/getRelayKitVersion.d.ts.map +0 -1
  72. package/dist/src/packs/safe-4337/utils.d.ts.map +0 -1
  73. package/dist/test-utils/fixtures.d.ts.map +0 -1
  74. package/dist/test-utils/helpers.d.ts.map +0 -1
  75. package/dist/test-utils/index.d.ts +0 -4
  76. package/dist/test-utils/index.d.ts.map +0 -1
@@ -1,1171 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // test-utils/index.ts
31
- var test_utils_exports = {};
32
- __export(test_utils_exports, {
33
- ENTRYPOINT_ABI: () => ENTRYPOINT_ABI,
34
- ENTRYPOINT_ADDRESS_V06: () => ENTRYPOINT_ADDRESS_V06,
35
- RPC_4337_CALLS: () => RPC_4337_CALLS,
36
- createSafe4337Pack: () => createSafe4337Pack,
37
- fixtures: () => fixtures_exports,
38
- generateTransferCallData: () => generateTransferCallData
39
- });
40
- module.exports = __toCommonJS(test_utils_exports);
41
-
42
- // test-utils/fixtures.ts
43
- var fixtures_exports = {};
44
- __export(fixtures_exports, {
45
- BUNDLER_URL: () => BUNDLER_URL,
46
- CHAIN_ID: () => CHAIN_ID,
47
- ENTRYPOINTS: () => ENTRYPOINTS,
48
- GAS_ESTIMATION: () => GAS_ESTIMATION,
49
- MODULE_ADDRESS: () => MODULE_ADDRESS,
50
- OWNER_1: () => OWNER_1,
51
- OWNER_2: () => OWNER_2,
52
- PAYMASTER_ADDRESS: () => PAYMASTER_ADDRESS,
53
- PAYMASTER_TOKEN_ADDRESS: () => PAYMASTER_TOKEN_ADDRESS,
54
- PAYMASTER_URL: () => PAYMASTER_URL,
55
- PREDICTED_SAFE_ADDRESS: () => PREDICTED_SAFE_ADDRESS,
56
- RPC_URL: () => RPC_URL,
57
- SAFE_ADDRESS_4337_FALLBACKHANDLER_NOT_ENABLED: () => SAFE_ADDRESS_4337_FALLBACKHANDLER_NOT_ENABLED,
58
- SAFE_ADDRESS_4337_MODULE_NOT_ENABLED: () => SAFE_ADDRESS_4337_MODULE_NOT_ENABLED,
59
- SAFE_ADDRESS_4337_PASSKEY: () => SAFE_ADDRESS_4337_PASSKEY,
60
- SAFE_ADDRESS_v1_3_0: () => SAFE_ADDRESS_v1_3_0,
61
- SAFE_ADDRESS_v1_4_1: () => SAFE_ADDRESS_v1_4_1,
62
- SAFE_MODULES_V0_3_0: () => SAFE_MODULES_V0_3_0,
63
- SAFE_OPERATION_RESPONSE: () => SAFE_OPERATION_RESPONSE,
64
- SPONSORED_GAS_ESTIMATION: () => SPONSORED_GAS_ESTIMATION,
65
- USER_OPERATION: () => USER_OPERATION,
66
- USER_OPERATION_BY_HASH: () => USER_OPERATION_BY_HASH,
67
- USER_OPERATION_GAS_PRICE: () => USER_OPERATION_GAS_PRICE,
68
- USER_OPERATION_HASH: () => USER_OPERATION_HASH,
69
- USER_OPERATION_HEX_VALUES: () => USER_OPERATION_HEX_VALUES,
70
- USER_OPERATION_RECEIPT: () => USER_OPERATION_RECEIPT
71
- });
72
-
73
- // src/packs/safe-4337/constants.ts
74
- var import_viem = require("viem");
75
- var DEFAULT_SAFE_VERSION = "1.4.1";
76
- var DEFAULT_SAFE_MODULES_VERSION = "0.2.0";
77
- var EIP712_SAFE_OPERATION_TYPE = {
78
- SafeOp: [
79
- { type: "address", name: "safe" },
80
- { type: "uint256", name: "nonce" },
81
- { type: "bytes", name: "initCode" },
82
- { type: "bytes", name: "callData" },
83
- { type: "uint256", name: "callGasLimit" },
84
- { type: "uint256", name: "verificationGasLimit" },
85
- { type: "uint256", name: "preVerificationGas" },
86
- { type: "uint256", name: "maxFeePerGas" },
87
- { type: "uint256", name: "maxPriorityFeePerGas" },
88
- { type: "bytes", name: "paymasterAndData" },
89
- { type: "uint48", name: "validAfter" },
90
- { type: "uint48", name: "validUntil" },
91
- { type: "address", name: "entryPoint" }
92
- ]
93
- };
94
- var ABI = (0, import_viem.parseAbi)([
95
- "function enableModules(address[])",
96
- "function multiSend(bytes memory transactions) public payable",
97
- "function executeUserOp(address to, uint256 value, bytes data, uint8 operation)",
98
- "function approve(address _spender, uint256 _value)",
99
- "function configure((uint256 x, uint256 y, uint176 verifiers) signer)"
100
- ]);
101
- var ENTRYPOINT_ABI = [
102
- {
103
- inputs: [
104
- { name: "sender", type: "address" },
105
- { name: "key", type: "uint192" }
106
- ],
107
- name: "getNonce",
108
- outputs: [{ name: "nonce", type: "uint256" }],
109
- stateMutability: "view",
110
- type: "function"
111
- }
112
- ];
113
- var ENTRYPOINT_ADDRESS_V06 = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
114
- var ENTRYPOINT_ADDRESS_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
115
- var RPC_4337_CALLS = /* @__PURE__ */ ((RPC_4337_CALLS2) => {
116
- RPC_4337_CALLS2["ESTIMATE_USER_OPERATION_GAS"] = "eth_estimateUserOperationGas";
117
- RPC_4337_CALLS2["SEND_USER_OPERATION"] = "eth_sendUserOperation";
118
- RPC_4337_CALLS2["GET_USER_OPERATION_BY_HASH"] = "eth_getUserOperationByHash";
119
- RPC_4337_CALLS2["GET_USER_OPERATION_RECEIPT"] = "eth_getUserOperationReceipt";
120
- RPC_4337_CALLS2["SUPPORTED_ENTRY_POINTS"] = "eth_supportedEntryPoints";
121
- RPC_4337_CALLS2["CHAIN_ID"] = "eth_chainId";
122
- RPC_4337_CALLS2["SPONSOR_USER_OPERATION"] = "pm_sponsorUserOperation";
123
- return RPC_4337_CALLS2;
124
- })(RPC_4337_CALLS || {});
125
-
126
- // test-utils/fixtures.ts
127
- var import_types_kit = require("@safe-global/types-kit");
128
- var OWNER_1 = "0xFfAC5578BE8AC1B2B9D13b34cAf4A074B96B8A1b";
129
- var OWNER_2 = "0x3059EfD1BCe33be41eeEfd5fb6D520d7fEd54E43";
130
- var PREDICTED_SAFE_ADDRESS = "0x65e0d294F2d17CB9fB0f65111E9Ac8a00C4049dA";
131
- var SAFE_ADDRESS_v1_4_1 = "0x717f4BB83D8DF2e5a3Cc603Ee27263ac9EFB6c12";
132
- var SAFE_ADDRESS_v1_3_0 = "0x8C35a08Af278518B59D04ddDe3F1b370aD766D22";
133
- var SAFE_ADDRESS_4337_MODULE_NOT_ENABLED = "0xfC82a1e4A045a44527e8b45FC70332C8F66fc32B";
134
- var SAFE_ADDRESS_4337_FALLBACKHANDLER_NOT_ENABLED = "0xA6FDc4e18404E1715D1bC51B07266c91393C6622";
135
- var SAFE_ADDRESS_4337_PASSKEY = "0x02DCbFD25178b6b8eFb45603D30b5123179117DD";
136
- var SAFE_MODULES_V0_3_0 = "0.3.0";
137
- var PAYMASTER_ADDRESS = "0x0000000000325602a77416A16136FDafd04b299f";
138
- var PAYMASTER_TOKEN_ADDRESS = "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238";
139
- var CHAIN_ID = "0xaa36a7";
140
- var MODULE_ADDRESS = "0xa581c4A4DB7175302464fF3C06380BC3270b4037";
141
- var RPC_URL = "https://sepolia.gateway.tenderly.co";
142
- var BUNDLER_URL = "https://bundler.url";
143
- var PAYMASTER_URL = "https://paymaster.url";
144
- var USER_OPERATION_HASH = "0x3cb881d1969036174f38d636d22108d1d032145518b53104fc0b1e1296d2cc9c";
145
- var ENTRYPOINTS = [ENTRYPOINT_ADDRESS_V06, ENTRYPOINT_ADDRESS_V07];
146
- var USER_OPERATION_RECEIPT = {
147
- userOpHash: "0x3cb881d1969036174f38d636d22108d1d032145518b53104fc0b1e1296d2cc9c",
148
- sender: "0x1405B3659a11a16459fc27Fa1925b60388C38Ce1",
149
- nonce: "0x1",
150
- actualGasUsed: "0x27067",
151
- actualGasCost: "0x42f29418377167",
152
- success: true,
153
- logs: [],
154
- receipt: {
155
- transactionHash: "0xef262d20f68e4900aa6380b8ac0f66f9c00a7d988179fa177ad9c9758f0e380e",
156
- transactionIndex: "0x63",
157
- blockHash: "0x65f8249337ffede2067a006a96da47d3d3445ca72492a6a82afa02899f05d2e5",
158
- blockNumber: "0x5378b9",
159
- from: "0x4337001Fff419768e088Ce247456c1B892888084",
160
- to: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
161
- cumulativeGasUsed: "0xc1a846",
162
- gasUsed: "0x25e6c",
163
- contractAddress: null,
164
- logs: [],
165
- logsBloom: "0x000000000000900000000000000000000000000000000000080000000002000000080000000000000402000100000000001000000000000080000200000100000000000000000000000000080000000000000000000000000000002000002000000000000a0000000000000000000800000000000000000000000010000200000000000060100000000000000040000000800000000000000008800000000000000000000000000000400000000000000200000000000000000002000000008000000002000100000001000000000000000000000020000000000000000020010040000000000020000010000008000200000000000000000000000000000000",
166
- status: "0x1",
167
- effectiveGasPrice: "0x1b67f3c201"
168
- }
169
- };
170
- var USER_OPERATION = {
171
- sender: "0x1405B3659a11a16459fc27Fa1925b60388C38Ce1",
172
- nonce: "0x1",
173
- initCode: "0x",
174
- callData: "0x7bb3742800000000000000000000000038869bf66a61cf6bdb996a6ae40d5853fd43b52600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001848d80ff0a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000132001c7d4b196cb0c7b01d743fbc6116a902379c723800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000d725e11588f040d86c4c49d8236e32a5868549f000000000000000000000000000000000000000000000000000000000000186a0001c7d4b196cb0c7b01d743fbc6116a902379c723800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000d725e11588f040d86c4c49d8236e32a5868549f000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
175
- callGasLimit: 120784n,
176
- verificationGasLimit: 83056n,
177
- preVerificationGas: 48568n,
178
- maxFeePerGas: 193584757388n,
179
- maxPriorityFeePerGas: 1380000000n,
180
- paymasterAndData: "0x",
181
- signature: "0x000000000000000000000000a397ca32ee7fb5282256ee3465da0843485930b803d747516aac76e152f834051ac18fd2b3c0565590f9d65085538993c85c9bb189c940d15c15402c7c2885821b"
182
- };
183
- var USER_OPERATION_HEX_VALUES = {
184
- sender: "0x1405B3659a11a16459fc27Fa1925b60388C38Ce1",
185
- nonce: "0x1",
186
- initCode: "0x",
187
- callData: "0x7bb3742800000000000000000000000038869bf66a61cf6bdb996a6ae40d5853fd43b52600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001848d80ff0a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000132001c7d4b196cb0c7b01d743fbc6116a902379c723800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000d725e11588f040d86c4c49d8236e32a5868549f000000000000000000000000000000000000000000000000000000000000186a0001c7d4b196cb0c7b01d743fbc6116a902379c723800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb000000000000000000000000d725e11588f040d86c4c49d8236e32a5868549f000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
188
- callGasLimit: "0x1d7d0",
189
- verificationGasLimit: "0x14470",
190
- preVerificationGas: "0xbdb8",
191
- maxFeePerGas: "0x2d128cfa8c",
192
- maxPriorityFeePerGas: "0x52412100",
193
- paymasterAndData: "0x",
194
- signature: "0x000000000000000000000000a397ca32ee7fb5282256ee3465da0843485930b803d747516aac76e152f834051ac18fd2b3c0565590f9d65085538993c85c9bb189c940d15c15402c7c2885821b"
195
- };
196
- var USER_OPERATION_BY_HASH = {
197
- userOperation: USER_OPERATION_HEX_VALUES,
198
- entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
199
- transactionHash: "0xef262d20f68e4900aa6380b8ac0f66f9c00a7d988179fa177ad9c9758f0e380e",
200
- blockHash: "0x65f8249337ffede2067a006a96da47d3d3445ca72492a6a82afa02899f05d2e5",
201
- blockNumber: "0x5378b9"
202
- };
203
- var GAS_ESTIMATION = {
204
- verificationGasLimit: "0x186A0",
205
- preVerificationGas: "0x186A0",
206
- callGasLimit: "0x186A0"
207
- };
208
- var SAFE_OPERATION_RESPONSE = {
209
- created: "2024-05-31T10:12:21.169031Z",
210
- modified: "2024-05-31T10:12:21.169031Z",
211
- safeOperationHash: "0x5a62b1d61f8fca5f766e9456523bb42765d318058b5f235f967ffe3c2af8b1d7",
212
- validAfter: null,
213
- validUntil: null,
214
- moduleAddress: "0xa581c4A4DB7175302464fF3C06380BC3270b4037",
215
- confirmations: [
216
- {
217
- created: "2024-05-31T10:12:21.184585Z",
218
- modified: "2024-05-31T10:12:21.184585Z",
219
- owner: "0x3059EfD1BCe33be41eeEfd5fb6D520d7fEd54E43",
220
- signature: "0xcb28e74375889e400a4d8aca46b8c59e1cf8825e373c26fa99c2fd7c078080e64fe30eaf1125257bdfe0b358b5caef68aa0420478145f52decc8e74c979d43ab1d",
221
- signatureType: import_types_kit.SignatureTypes.EOA
222
- }
223
- ],
224
- preparedSignature: "0xcb28e74375889e400a4d8aca46b8c59e1cf8825e373c26fa99c2fd7c078080e64fe30eaf1125257bdfe0b358b5caef68aa0420478145f52decc8e74c979d43ab1c",
225
- userOperation: {
226
- ethereumTxHash: null,
227
- sender: "0xE322e721bCe76cE7FCf3A475f139A9314571ad3D",
228
- userOperationHash: "0x5d23b7d96a718582601183b1849a4c76b2a13d3787f15074d62a0b6e4a3f76a1",
229
- nonce: 3,
230
- initCode: "0x",
231
- callData: "0x7bb37428000000000000000000000000e322e721bce76ce7fcf3a475f139a9314571ad3d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
232
- callGasLimit: 122497,
233
- verificationGasLimit: 123498,
234
- preVerificationGas: 50705,
235
- maxFeePerGas: 105183831060,
236
- maxPriorityFeePerGas: 138e7,
237
- paymaster: null,
238
- paymasterData: null,
239
- signature: "0x54158da2d357241ee1c5c8fca9c4e1bfa6b92a60bd0ed1bea56f4092b008435153d6264a8a8c00925383ecaeaf9d839a2dc1ff006703c65b7f05d0ce8cdd57ab1b",
240
- entryPoint: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
241
- }
242
- };
243
- var SPONSORED_GAS_ESTIMATION = {
244
- paymasterAndData: "0x1405B3659a11a16459fc27Fa1925b60388C38Ce1",
245
- ...GAS_ESTIMATION
246
- };
247
- var USER_OPERATION_GAS_PRICE = {
248
- fast: { maxFeePerGas: "0x186A0", maxPriorityFeePerGas: "0x30D40" }
249
- };
250
-
251
- // test-utils/helpers.ts
252
- var import_viem5 = require("viem");
253
-
254
- // src/packs/safe-4337/Safe4337Pack.ts
255
- var import_satisfies = __toESM(require("semver/functions/satisfies.js"));
256
- var import_protocol_kit3 = __toESM(require("@safe-global/protocol-kit"));
257
-
258
- // src/RelayKitBasePack.ts
259
- var RelayKitBasePack = class {
260
- /**
261
- * Creates a new RelayKitBasePack instance.
262
- * The packs implemented using our SDK should extend this class and therefore provide a Safe SDK instance
263
- * @param {Safe} protocolKit - The Safe SDK instance
264
- */
265
- constructor(protocolKit) {
266
- this.protocolKit = protocolKit;
267
- }
268
- };
269
-
270
- // src/packs/safe-4337/Safe4337Pack.ts
271
- var import_types_kit3 = require("@safe-global/types-kit");
272
- var import_safe_modules_deployments = require("@safe-global/safe-modules-deployments");
273
- var import_viem4 = require("viem");
274
-
275
- // src/packs/safe-4337/SafeOperation.ts
276
- var import_viem3 = require("viem");
277
- var import_protocol_kit2 = require("@safe-global/protocol-kit");
278
-
279
- // src/packs/safe-4337/utils.ts
280
- var import_viem2 = require("viem");
281
- var import_types_kit2 = require("@safe-global/types-kit");
282
- var import_protocol_kit = require("@safe-global/protocol-kit");
283
- function getEip4337BundlerProvider(bundlerUrl) {
284
- const provider = (0, import_viem2.createPublicClient)({
285
- transport: (0, import_viem2.http)(bundlerUrl),
286
- rpcSchema: (0, import_viem2.rpcSchema)()
287
- });
288
- return provider;
289
- }
290
- async function signSafeOp(safeUserOperation, safeProvider, safe4337ModuleAddress) {
291
- const signer = await safeProvider.getExternalSigner();
292
- if (!signer) {
293
- throw new Error("No signer found");
294
- }
295
- const chainId = await safeProvider.getChainId();
296
- const signerAddress = signer.account.address;
297
- const signature = await signer.signTypedData({
298
- domain: {
299
- chainId: Number(chainId),
300
- verifyingContract: safe4337ModuleAddress
301
- },
302
- types: EIP712_SAFE_OPERATION_TYPE,
303
- message: {
304
- ...safeUserOperation,
305
- nonce: (0, import_viem2.toHex)(safeUserOperation.nonce),
306
- validAfter: (0, import_viem2.toHex)(safeUserOperation.validAfter),
307
- validUntil: (0, import_viem2.toHex)(safeUserOperation.validUntil),
308
- maxFeePerGas: (0, import_viem2.toHex)(safeUserOperation.maxFeePerGas),
309
- maxPriorityFeePerGas: (0, import_viem2.toHex)(safeUserOperation.maxPriorityFeePerGas)
310
- },
311
- primaryType: "SafeOp"
312
- });
313
- return new import_protocol_kit.EthSafeSignature(signerAddress, signature);
314
- }
315
- function encodeMultiSendCallData(transactions) {
316
- return (0, import_viem2.encodeFunctionData)({
317
- abi: ABI,
318
- functionName: "multiSend",
319
- args: [
320
- (0, import_protocol_kit.encodeMultiSendData)(
321
- transactions.map((tx) => ({ ...tx, operation: tx.operation ?? import_types_kit2.OperationType.Call }))
322
- )
323
- ]
324
- });
325
- }
326
- function calculateSafeUserOperationHash(safeUserOperation, chainId, safe4337ModuleAddress) {
327
- return (0, import_viem2.hashTypedData)({
328
- domain: {
329
- chainId: Number(chainId),
330
- verifyingContract: safe4337ModuleAddress
331
- },
332
- types: EIP712_SAFE_OPERATION_TYPE,
333
- primaryType: "SafeOp",
334
- message: safeUserOperation
335
- });
336
- }
337
- function userOperationToHexValues(userOperation) {
338
- const userOperationWithHexValues = {
339
- ...userOperation,
340
- nonce: (0, import_viem2.toHex)(BigInt(userOperation.nonce)),
341
- callGasLimit: (0, import_viem2.toHex)(userOperation.callGasLimit),
342
- verificationGasLimit: (0, import_viem2.toHex)(userOperation.verificationGasLimit),
343
- preVerificationGas: (0, import_viem2.toHex)(userOperation.preVerificationGas),
344
- maxFeePerGas: (0, import_viem2.toHex)(userOperation.maxFeePerGas),
345
- maxPriorityFeePerGas: (0, import_viem2.toHex)(userOperation.maxPriorityFeePerGas)
346
- };
347
- return userOperationWithHexValues;
348
- }
349
- var DUMMY_CLIENT_DATA_FIELDS = [
350
- `"origin":"https://safe.global"`,
351
- `"padding":"This pads the clientDataJSON so that we can leave room for additional implementation specific fields for a more accurate 'preVerificationGas' estimate."`
352
- ].join(",");
353
- var DUMMY_AUTHENTICATOR_DATA = new Uint8Array(37);
354
- DUMMY_AUTHENTICATOR_DATA.fill(254);
355
- DUMMY_AUTHENTICATOR_DATA[32] = 4;
356
- function addDummySignature(userOperation, signer, threshold) {
357
- const signatures = [];
358
- for (let i = 0; i < threshold; i++) {
359
- const isContractSignature = true;
360
- const passkeySignature = getSignatureBytes({
361
- authenticatorData: DUMMY_AUTHENTICATOR_DATA,
362
- clientDataFields: DUMMY_CLIENT_DATA_FIELDS,
363
- r: BigInt(`0x${"ec".repeat(32)}`),
364
- s: BigInt(`0x${"d5a".repeat(21)}f`)
365
- });
366
- signatures.push(new import_protocol_kit.EthSafeSignature(signer, passkeySignature, isContractSignature));
367
- }
368
- return {
369
- ...userOperation,
370
- signature: (0, import_viem2.encodePacked)(
371
- ["uint48", "uint48", "bytes"],
372
- [0, 0, (0, import_protocol_kit.buildSignatureBytes)(signatures)]
373
- )
374
- };
375
- }
376
- function getSignatureBytes({
377
- authenticatorData,
378
- clientDataFields,
379
- r,
380
- s
381
- }) {
382
- const encodeUint256 = (x) => x.toString(16).padStart(64, "0");
383
- const byteSize = (data) => 32 * (Math.ceil(data.length / 32) + 1);
384
- const encodeBytes = (data) => `${encodeUint256(data.length)}${(0, import_viem2.toHex)(data).slice(2)}`.padEnd(byteSize(data) * 2, "0");
385
- const authenticatorDataOffset = 32 * 4;
386
- const clientDataFieldsOffset = authenticatorDataOffset + byteSize(authenticatorData);
387
- return "0x" + encodeUint256(authenticatorDataOffset) + encodeUint256(clientDataFieldsOffset) + encodeUint256(r) + encodeUint256(s) + encodeBytes(authenticatorData) + encodeBytes(new TextEncoder().encode(clientDataFields));
388
- }
389
-
390
- // src/packs/safe-4337/SafeOperation.ts
391
- var EthSafeOperation = class {
392
- constructor(userOperation, { chainId, entryPoint, validAfter, validUntil, moduleAddress }) {
393
- this.signatures = /* @__PURE__ */ new Map();
394
- this.chainId = chainId;
395
- this.moduleAddress = moduleAddress;
396
- this.data = {
397
- safe: userOperation.sender,
398
- nonce: BigInt(userOperation.nonce),
399
- initCode: userOperation.initCode,
400
- callData: userOperation.callData,
401
- callGasLimit: userOperation.callGasLimit,
402
- verificationGasLimit: userOperation.verificationGasLimit,
403
- preVerificationGas: userOperation.preVerificationGas,
404
- maxFeePerGas: userOperation.maxFeePerGas,
405
- maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas,
406
- paymasterAndData: userOperation.paymasterAndData,
407
- validAfter: validAfter || 0,
408
- validUntil: validUntil || 0,
409
- entryPoint
410
- };
411
- }
412
- getSignature(signer) {
413
- return this.signatures.get(signer.toLowerCase());
414
- }
415
- addSignature(signature) {
416
- this.signatures.set(signature.signer.toLowerCase(), signature);
417
- }
418
- encodedSignatures() {
419
- return (0, import_protocol_kit2.buildSignatureBytes)(Array.from(this.signatures.values()));
420
- }
421
- addEstimations(estimations) {
422
- const keys = [
423
- "maxFeePerGas",
424
- "maxPriorityFeePerGas",
425
- "verificationGasLimit",
426
- "preVerificationGas",
427
- "callGasLimit"
428
- ];
429
- for (const key of keys) {
430
- this.data[key] = BigInt(estimations[key] || this.data[key]);
431
- }
432
- }
433
- toUserOperation() {
434
- return {
435
- sender: this.data.safe,
436
- nonce: (0, import_viem3.toHex)(this.data.nonce),
437
- initCode: this.data.initCode,
438
- callData: this.data.callData,
439
- callGasLimit: this.data.callGasLimit,
440
- verificationGasLimit: this.data.verificationGasLimit,
441
- preVerificationGas: this.data.preVerificationGas,
442
- maxFeePerGas: this.data.maxFeePerGas,
443
- maxPriorityFeePerGas: this.data.maxPriorityFeePerGas,
444
- paymasterAndData: this.data.paymasterAndData,
445
- signature: (0, import_viem3.encodePacked)(
446
- ["uint48", "uint48", "bytes"],
447
- [this.data.validAfter, this.data.validUntil, this.encodedSignatures()]
448
- )
449
- };
450
- }
451
- getHash() {
452
- return calculateSafeUserOperationHash(this.data, this.chainId, this.moduleAddress);
453
- }
454
- };
455
- var SafeOperation_default = EthSafeOperation;
456
-
457
- // src/packs/safe-4337/utils/entrypoint.ts
458
- var EQ_0_2_0 = "0.2.0";
459
- var EQ_OR_GT_0_3_0 = ">=0.3.0";
460
- function entryPointToSafeModules(entryPoint) {
461
- const moduleVersionToEntryPoint = {
462
- [ENTRYPOINT_ADDRESS_V06]: EQ_0_2_0,
463
- [ENTRYPOINT_ADDRESS_V07]: EQ_OR_GT_0_3_0
464
- };
465
- return moduleVersionToEntryPoint[entryPoint];
466
- }
467
-
468
- // src/packs/safe-4337/estimators/PimlicoFeeEstimator.ts
469
- var PimlicoFeeEstimator = class {
470
- async setupEstimation({ bundlerUrl }) {
471
- const bundlerClient = getEip4337BundlerProvider(bundlerUrl);
472
- const feeData = await this.#getFeeData(bundlerClient);
473
- return feeData;
474
- }
475
- async adjustEstimation({ userOperation }) {
476
- return {
477
- callGasLimit: userOperation.callGasLimit + userOperation.callGasLimit / 2n,
478
- // +50%
479
- verificationGasLimit: userOperation.verificationGasLimit * 4n,
480
- // +300%
481
- preVerificationGas: userOperation.preVerificationGas + userOperation.preVerificationGas / 20n
482
- // +5%
483
- };
484
- }
485
- async getPaymasterEstimation({
486
- userOperation,
487
- paymasterUrl,
488
- entryPoint,
489
- sponsorshipPolicyId
490
- }) {
491
- const paymasterClient = getEip4337BundlerProvider(paymasterUrl);
492
- const gasEstimate = await paymasterClient.request({
493
- method: "pm_sponsorUserOperation" /* SPONSOR_USER_OPERATION */,
494
- params: sponsorshipPolicyId ? [userOperationToHexValues(userOperation), entryPoint, { sponsorshipPolicyId }] : [userOperationToHexValues(userOperation), entryPoint]
495
- });
496
- return gasEstimate;
497
- }
498
- async #getFeeData(bundlerClient) {
499
- const {
500
- fast: { maxFeePerGas, maxPriorityFeePerGas }
501
- } = await bundlerClient.request({
502
- method: "pimlico_getUserOperationGasPrice"
503
- });
504
- return {
505
- maxFeePerGas: BigInt(maxFeePerGas),
506
- maxPriorityFeePerGas: BigInt(maxPriorityFeePerGas)
507
- };
508
- }
509
- };
510
-
511
- // src/packs/safe-4337/utils/getRelayKitVersion.ts
512
- var getRelayKitVersion = () => "3.4.1";
513
-
514
- // src/packs/safe-4337/Safe4337Pack.ts
515
- var MAX_ERC20_AMOUNT_TO_APPROVE = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn;
516
- var EQ_OR_GT_1_4_1 = ">=1.4.1";
517
- var Safe4337Pack = class _Safe4337Pack extends RelayKitBasePack {
518
- #BUNDLER_URL;
519
- #ENTRYPOINT_ADDRESS;
520
- #SAFE_4337_MODULE_ADDRESS = "0x";
521
- #SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS = "0x";
522
- #bundlerClient;
523
- #chainId;
524
- #paymasterOptions;
525
- #onchainIdentifier = "";
526
- /**
527
- * Creates an instance of the Safe4337Pack.
528
- *
529
- * @param {Safe4337Options} options - The initialization parameters.
530
- */
531
- constructor({
532
- protocolKit,
533
- bundlerClient,
534
- bundlerUrl,
535
- chainId,
536
- paymasterOptions,
537
- entryPointAddress,
538
- safe4337ModuleAddress,
539
- safeWebAuthnSharedSignerAddress,
540
- onchainAnalytics
541
- }) {
542
- super(protocolKit);
543
- this.#BUNDLER_URL = bundlerUrl;
544
- this.#bundlerClient = bundlerClient;
545
- this.#chainId = chainId;
546
- this.#paymasterOptions = paymasterOptions;
547
- this.#ENTRYPOINT_ADDRESS = entryPointAddress;
548
- this.#SAFE_4337_MODULE_ADDRESS = safe4337ModuleAddress;
549
- this.#SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS = safeWebAuthnSharedSignerAddress || "0x";
550
- if (onchainAnalytics?.project) {
551
- const { project, platform } = onchainAnalytics;
552
- this.#onchainIdentifier = (0, import_protocol_kit3.generateOnChainIdentifier)({
553
- project,
554
- platform,
555
- tool: "relay-kit",
556
- toolVersion: getRelayKitVersion()
557
- });
558
- }
559
- }
560
- /**
561
- * Initializes a Safe4337Pack class.
562
- * This method creates the protocolKit instance based on the input parameters.
563
- * When the Safe address is provided, it will use the existing Safe.
564
- * When the Safe address is not provided, it will use the predictedSafe feature with the provided owners and threshold.
565
- * It will use the correct contract addresses for the fallbackHandler and the module and will add the data to enable the 4337 module.
566
- *
567
- * @param {Safe4337InitOptions} initOptions - The initialization parameters.
568
- * @return {Promise<Safe4337Pack>} The Promise object that will be resolved into an instance of Safe4337Pack.
569
- */
570
- static async init(initOptions) {
571
- const {
572
- provider,
573
- signer,
574
- options,
575
- bundlerUrl,
576
- customContracts,
577
- paymasterOptions,
578
- onchainAnalytics
579
- } = initOptions;
580
- let protocolKit;
581
- const bundlerClient = getEip4337BundlerProvider(bundlerUrl);
582
- const chainId = await bundlerClient.request({ method: "eth_chainId" /* CHAIN_ID */ });
583
- let addModulesLibAddress = customContracts?.addModulesLibAddress;
584
- const network = parseInt(chainId, 16).toString();
585
- const safeModulesVersion = initOptions.safeModulesVersion || DEFAULT_SAFE_MODULES_VERSION;
586
- if ((0, import_satisfies.default)(safeModulesVersion, EQ_OR_GT_0_3_0)) {
587
- throw new Error(
588
- `Incompatibility detected: Safe modules version ${safeModulesVersion} is not supported. The SDK can use 0.2.0 only.`
589
- );
590
- }
591
- if (!addModulesLibAddress) {
592
- const addModulesDeployment = (0, import_safe_modules_deployments.getAddModulesLibDeployment)({
593
- released: true,
594
- version: safeModulesVersion,
595
- network
596
- });
597
- addModulesLibAddress = addModulesDeployment?.networkAddresses[network];
598
- }
599
- let safe4337ModuleAddress = customContracts?.safe4337ModuleAddress;
600
- if (!safe4337ModuleAddress) {
601
- const safe4337ModuleDeployment = (0, import_safe_modules_deployments.getSafe4337ModuleDeployment)({
602
- released: true,
603
- version: safeModulesVersion,
604
- network
605
- });
606
- safe4337ModuleAddress = safe4337ModuleDeployment?.networkAddresses[network];
607
- }
608
- if (!addModulesLibAddress || !safe4337ModuleAddress) {
609
- throw new Error(
610
- `Safe4337Module and/or AddModulesLib not available for chain ${network} and modules version ${safeModulesVersion}`
611
- );
612
- }
613
- let safeWebAuthnSharedSignerAddress = customContracts?.safeWebAuthnSharedSignerAddress;
614
- if ("safeAddress" in options) {
615
- protocolKit = await import_protocol_kit3.default.init({
616
- provider,
617
- signer,
618
- safeAddress: options.safeAddress
619
- });
620
- const safeVersion = protocolKit.getContractVersion();
621
- const isSafeVersion4337Compatible = (0, import_satisfies.default)(safeVersion, EQ_OR_GT_1_4_1);
622
- if (!isSafeVersion4337Compatible) {
623
- throw new Error(
624
- `Incompatibility detected: The current Safe Account version (${safeVersion}) is not supported. EIP-4337 requires the Safe to use at least v1.4.1.`
625
- );
626
- }
627
- const safeModules = await protocolKit.getModules();
628
- const is4337ModulePresent = safeModules.some((module2) => module2 === safe4337ModuleAddress);
629
- if (!is4337ModulePresent) {
630
- throw new Error(
631
- `Incompatibility detected: The EIP-4337 module is not enabled in the provided Safe Account. Enable this module (address: ${safe4337ModuleAddress}) to add compatibility.`
632
- );
633
- }
634
- const safeFallbackhandler = await protocolKit.getFallbackHandler();
635
- const is4337FallbackhandlerPresent = safeFallbackhandler === safe4337ModuleAddress;
636
- if (!is4337FallbackhandlerPresent) {
637
- throw new Error(
638
- `Incompatibility detected: The EIP-4337 fallbackhandler is not attached to the Safe Account. Attach this fallbackhandler (address: ${safe4337ModuleAddress}) to ensure compatibility.`
639
- );
640
- }
641
- } else {
642
- if (!options.owners || !options.threshold) {
643
- throw new Error("Owners and threshold are required to deploy a new Safe");
644
- }
645
- const safeVersion = options.safeVersion || DEFAULT_SAFE_VERSION;
646
- const enable4337ModuleTransaction = {
647
- to: addModulesLibAddress,
648
- value: "0",
649
- data: (0, import_viem4.encodeFunctionData)({
650
- abi: ABI,
651
- functionName: "enableModules",
652
- args: [[safe4337ModuleAddress]]
653
- }),
654
- operation: import_types_kit3.OperationType.DelegateCall
655
- // DelegateCall required for enabling the 4337 module
656
- };
657
- const setupTransactions = [enable4337ModuleTransaction];
658
- const isApproveTransactionRequired = !!paymasterOptions && !paymasterOptions.isSponsored && !!paymasterOptions.paymasterTokenAddress;
659
- if (isApproveTransactionRequired) {
660
- const { paymasterAddress, amountToApprove = MAX_ERC20_AMOUNT_TO_APPROVE } = paymasterOptions;
661
- const approveToPaymasterTransaction = {
662
- to: paymasterOptions.paymasterTokenAddress,
663
- data: (0, import_viem4.encodeFunctionData)({
664
- abi: ABI,
665
- functionName: "approve",
666
- args: [paymasterAddress, amountToApprove]
667
- }),
668
- value: "0",
669
- operation: import_types_kit3.OperationType.Call
670
- // Call for approve
671
- };
672
- setupTransactions.push(approveToPaymasterTransaction);
673
- }
674
- const safeProvider = await import_protocol_kit3.SafeProvider.init({ provider, signer, safeVersion });
675
- const isPasskeySigner = await safeProvider.isPasskeySigner();
676
- if (isPasskeySigner) {
677
- if (!safeWebAuthnSharedSignerAddress) {
678
- const safeWebAuthnSharedSignerDeployment = (0, import_safe_modules_deployments.getSafeWebAuthnShareSignerDeployment)({
679
- released: true,
680
- version: "0.2.1",
681
- network
682
- });
683
- safeWebAuthnSharedSignerAddress = safeWebAuthnSharedSignerDeployment?.networkAddresses[network];
684
- }
685
- if (!safeWebAuthnSharedSignerAddress) {
686
- throw new Error(`safeWebAuthnSharedSignerAddress not available for chain ${network}`);
687
- }
688
- const passkeySigner = await safeProvider.getExternalSigner();
689
- if (!options.owners.includes(safeWebAuthnSharedSignerAddress)) {
690
- options.owners.push(safeWebAuthnSharedSignerAddress);
691
- }
692
- const sharedSignerTransaction = {
693
- to: safeWebAuthnSharedSignerAddress,
694
- value: "0",
695
- data: passkeySigner.encodeConfigure(),
696
- operation: import_types_kit3.OperationType.DelegateCall
697
- // DelegateCall required into the SafeWebAuthnSharedSigner instance in order for it to set its configuration.
698
- };
699
- setupTransactions.push(sharedSignerTransaction);
700
- }
701
- let deploymentTo;
702
- let deploymentData;
703
- const isBatch = setupTransactions.length > 1;
704
- if (isBatch) {
705
- const multiSendContract = await (0, import_protocol_kit3.getMultiSendContract)({
706
- safeProvider,
707
- safeVersion,
708
- deploymentType: options.deploymentType || void 0
709
- });
710
- const batchData = (0, import_viem4.encodeFunctionData)({
711
- abi: ABI,
712
- functionName: "multiSend",
713
- args: [(0, import_protocol_kit3.encodeMultiSendData)(setupTransactions)]
714
- });
715
- deploymentTo = multiSendContract.getAddress();
716
- deploymentData = batchData;
717
- } else {
718
- deploymentTo = enable4337ModuleTransaction.to;
719
- deploymentData = enable4337ModuleTransaction.data;
720
- }
721
- protocolKit = await import_protocol_kit3.default.init({
722
- provider,
723
- signer,
724
- predictedSafe: {
725
- safeDeploymentConfig: {
726
- safeVersion,
727
- saltNonce: options.saltNonce || void 0,
728
- deploymentType: options.deploymentType || void 0
729
- },
730
- safeAccountConfig: {
731
- owners: options.owners,
732
- threshold: options.threshold,
733
- to: deploymentTo,
734
- data: deploymentData,
735
- fallbackHandler: safe4337ModuleAddress,
736
- paymentToken: import_viem4.zeroAddress,
737
- payment: 0,
738
- paymentReceiver: import_viem4.zeroAddress
739
- }
740
- },
741
- onchainAnalytics
742
- });
743
- }
744
- let selectedEntryPoint;
745
- if (customContracts?.entryPointAddress) {
746
- const requiredSafeModulesVersion = entryPointToSafeModules(customContracts?.entryPointAddress);
747
- if (!(0, import_satisfies.default)(safeModulesVersion, requiredSafeModulesVersion))
748
- throw new Error(
749
- `The selected entrypoint ${customContracts?.entryPointAddress} is not compatible with version ${safeModulesVersion} of Safe modules`
750
- );
751
- selectedEntryPoint = customContracts?.entryPointAddress;
752
- } else {
753
- const supportedEntryPoints = await bundlerClient.request({
754
- method: "eth_supportedEntryPoints" /* SUPPORTED_ENTRY_POINTS */
755
- });
756
- if (!supportedEntryPoints.length) {
757
- throw new Error("No entrypoint provided or available through the bundler");
758
- }
759
- selectedEntryPoint = supportedEntryPoints.find((entryPoint) => {
760
- const requiredSafeModulesVersion = entryPointToSafeModules(entryPoint);
761
- return (0, import_satisfies.default)(safeModulesVersion, requiredSafeModulesVersion);
762
- });
763
- if (!selectedEntryPoint) {
764
- throw new Error(
765
- `Incompatibility detected: None of the entrypoints provided by the bundler is compatible with the Safe modules version ${safeModulesVersion}`
766
- );
767
- }
768
- }
769
- return new _Safe4337Pack({
770
- chainId: BigInt(chainId),
771
- protocolKit,
772
- bundlerClient,
773
- paymasterOptions,
774
- bundlerUrl,
775
- entryPointAddress: selectedEntryPoint,
776
- safe4337ModuleAddress,
777
- safeWebAuthnSharedSignerAddress,
778
- onchainAnalytics
779
- });
780
- }
781
- /**
782
- * Estimates gas for the SafeOperation.
783
- *
784
- * @param {EstimateFeeProps} props - The parameters for the gas estimation.
785
- * @param {EthSafeOperation} props.safeOperation - The SafeOperation to estimate the gas.
786
- * @param {IFeeEstimator} props.feeEstimator - The function to estimate the gas.
787
- * @return {Promise<EthSafeOperation>} The Promise object that will be resolved into the gas estimation.
788
- */
789
- async getEstimateFee({
790
- safeOperation,
791
- feeEstimator = new PimlicoFeeEstimator()
792
- }) {
793
- const threshold = await this.protocolKit.getThreshold();
794
- const setupEstimationData = await feeEstimator?.setupEstimation?.({
795
- bundlerUrl: this.#BUNDLER_URL,
796
- entryPoint: this.#ENTRYPOINT_ADDRESS,
797
- userOperation: safeOperation.toUserOperation()
798
- });
799
- if (setupEstimationData) {
800
- safeOperation.addEstimations(setupEstimationData);
801
- }
802
- const estimateUserOperationGas = await this.#bundlerClient.request({
803
- method: "eth_estimateUserOperationGas" /* ESTIMATE_USER_OPERATION_GAS */,
804
- params: [
805
- userOperationToHexValues(
806
- addDummySignature(
807
- safeOperation.toUserOperation(),
808
- this.#SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS,
809
- threshold
810
- )
811
- ),
812
- this.#ENTRYPOINT_ADDRESS
813
- ]
814
- });
815
- if (estimateUserOperationGas) {
816
- safeOperation.addEstimations({
817
- preVerificationGas: BigInt(estimateUserOperationGas.preVerificationGas),
818
- verificationGasLimit: BigInt(estimateUserOperationGas.verificationGasLimit),
819
- callGasLimit: BigInt(estimateUserOperationGas.callGasLimit)
820
- });
821
- }
822
- const adjustEstimationData = await feeEstimator?.adjustEstimation?.({
823
- bundlerUrl: this.#BUNDLER_URL,
824
- entryPoint: this.#ENTRYPOINT_ADDRESS,
825
- userOperation: safeOperation.toUserOperation()
826
- });
827
- if (adjustEstimationData) {
828
- safeOperation.addEstimations(adjustEstimationData);
829
- }
830
- if (this.#paymasterOptions?.isSponsored) {
831
- if (!this.#paymasterOptions.paymasterUrl) {
832
- throw new Error("No paymaster url provided for a sponsored transaction");
833
- }
834
- const paymasterEstimation = await feeEstimator?.getPaymasterEstimation?.({
835
- userOperation: addDummySignature(
836
- safeOperation.toUserOperation(),
837
- this.#SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS,
838
- threshold
839
- ),
840
- paymasterUrl: this.#paymasterOptions.paymasterUrl,
841
- entryPoint: this.#ENTRYPOINT_ADDRESS,
842
- sponsorshipPolicyId: this.#paymasterOptions.sponsorshipPolicyId
843
- });
844
- safeOperation.data.paymasterAndData = paymasterEstimation?.paymasterAndData || safeOperation.data.paymasterAndData;
845
- if (paymasterEstimation) {
846
- safeOperation.addEstimations(paymasterEstimation);
847
- }
848
- }
849
- return safeOperation;
850
- }
851
- /**
852
- * Creates a relayed transaction based on the provided parameters.
853
- *
854
- * @param {MetaTransactionData[]} transactions - The transactions to batch in a SafeOperation.
855
- * @param options - Optional configuration options for the transaction creation.
856
- * @return {Promise<EthSafeOperation>} The Promise object will resolve a SafeOperation.
857
- */
858
- async createTransaction({
859
- transactions,
860
- options = {}
861
- }) {
862
- const safeAddress = await this.protocolKit.getAddress();
863
- const nonce = await this.#getSafeNonceFromEntrypoint(safeAddress);
864
- const { amountToApprove, validUntil, validAfter, feeEstimator } = options;
865
- if (amountToApprove) {
866
- const paymasterOptions = this.#paymasterOptions;
867
- if (!paymasterOptions.paymasterTokenAddress) {
868
- throw new Error("Paymaster must be initialized");
869
- }
870
- const approveToPaymasterTransaction = {
871
- to: paymasterOptions.paymasterTokenAddress,
872
- data: (0, import_viem4.encodeFunctionData)({
873
- abi: ABI,
874
- functionName: "approve",
875
- args: [paymasterOptions.paymasterAddress, amountToApprove]
876
- }),
877
- value: "0",
878
- operation: import_types_kit3.OperationType.Call
879
- // Call for approve
880
- };
881
- transactions.push(approveToPaymasterTransaction);
882
- }
883
- const isBatch = transactions.length > 1;
884
- const multiSendAddress = this.protocolKit.getMultiSendAddress();
885
- const callData = isBatch ? this.#encodeExecuteUserOpCallData({
886
- to: multiSendAddress,
887
- value: "0",
888
- data: encodeMultiSendCallData(transactions),
889
- operation: import_types_kit3.OperationType.DelegateCall
890
- }) : this.#encodeExecuteUserOpCallData(transactions[0]);
891
- const paymasterAndData = this.#paymasterOptions && "paymasterAddress" in this.#paymasterOptions ? this.#paymasterOptions.paymasterAddress : "0x";
892
- const userOperation = {
893
- sender: safeAddress,
894
- nonce,
895
- initCode: "0x",
896
- callData,
897
- callGasLimit: 1n,
898
- verificationGasLimit: 1n,
899
- preVerificationGas: 1n,
900
- maxFeePerGas: 1n,
901
- maxPriorityFeePerGas: 1n,
902
- paymasterAndData,
903
- signature: "0x"
904
- };
905
- if (this.#onchainIdentifier) {
906
- userOperation.callData += this.#onchainIdentifier;
907
- }
908
- const isSafeDeployed = await this.protocolKit.isSafeDeployed();
909
- if (!isSafeDeployed) {
910
- userOperation.initCode = await this.protocolKit.getInitCode();
911
- }
912
- const safeOperation = new SafeOperation_default(userOperation, {
913
- chainId: this.#chainId,
914
- moduleAddress: this.#SAFE_4337_MODULE_ADDRESS,
915
- entryPoint: this.#ENTRYPOINT_ADDRESS,
916
- validUntil,
917
- validAfter
918
- });
919
- return await this.getEstimateFee({
920
- safeOperation,
921
- feeEstimator
922
- });
923
- }
924
- /**
925
- * Converts a SafeOperationResponse to an EthSafeOperation.
926
- *
927
- * @param {SafeOperationResponse} safeOperationResponse - The SafeOperationResponse to convert to EthSafeOperation
928
- * @returns {EthSafeOperation} - The EthSafeOperation object
929
- */
930
- #toSafeOperation(safeOperationResponse) {
931
- const { validUntil, validAfter, userOperation } = safeOperationResponse;
932
- const paymaster = userOperation?.paymaster || "0x";
933
- const paymasterData = userOperation?.paymasterData || "0x";
934
- const safeOperation = new SafeOperation_default(
935
- {
936
- sender: userOperation?.sender || "0x",
937
- nonce: userOperation?.nonce?.toString() || "0",
938
- initCode: userOperation?.initCode || "",
939
- callData: userOperation?.callData || "",
940
- callGasLimit: BigInt(userOperation?.callGasLimit || 0n),
941
- verificationGasLimit: BigInt(userOperation?.verificationGasLimit || 0),
942
- preVerificationGas: BigInt(userOperation?.preVerificationGas || 0),
943
- maxFeePerGas: BigInt(userOperation?.maxFeePerGas || 0),
944
- maxPriorityFeePerGas: BigInt(userOperation?.maxPriorityFeePerGas || 0),
945
- paymasterAndData: (0, import_viem4.concat)([paymaster, paymasterData]),
946
- signature: safeOperationResponse.preparedSignature || "0x"
947
- },
948
- {
949
- chainId: this.#chainId,
950
- moduleAddress: this.#SAFE_4337_MODULE_ADDRESS,
951
- entryPoint: userOperation?.entryPoint || this.#ENTRYPOINT_ADDRESS,
952
- validAfter: this.#timestamp(validAfter),
953
- validUntil: this.#timestamp(validUntil)
954
- }
955
- );
956
- if (safeOperationResponse.confirmations) {
957
- safeOperationResponse.confirmations.forEach((confirmation) => {
958
- safeOperation.addSignature(new import_protocol_kit3.EthSafeSignature(confirmation.owner, confirmation.signature));
959
- });
960
- }
961
- return safeOperation;
962
- }
963
- /**
964
- *
965
- * @param date An ISO string date
966
- * @returns The timestamp in seconds to send to the bundler
967
- */
968
- #timestamp(date) {
969
- return date ? new Date(date).getTime() / 1e3 : void 0;
970
- }
971
- /**
972
- * Signs a safe operation.
973
- *
974
- * @param {EthSafeOperation | SafeOperationResponse} safeOperation - The SafeOperation to sign. It can be:
975
- * - A response from the API (Tx Service)
976
- * - An instance of EthSafeOperation
977
- * @param {SigningMethod} signingMethod - The signing method to use.
978
- * @return {Promise<EthSafeOperation>} The Promise object will resolve to the signed SafeOperation.
979
- */
980
- async signSafeOperation(safeOperation, signingMethod = import_protocol_kit3.SigningMethod.ETH_SIGN_TYPED_DATA_V4) {
981
- let safeOp;
982
- if ((0, import_types_kit3.isSafeOperationResponse)(safeOperation)) {
983
- safeOp = this.#toSafeOperation(safeOperation);
984
- } else {
985
- safeOp = safeOperation;
986
- }
987
- const safeProvider = this.protocolKit.getSafeProvider();
988
- const signerAddress = await safeProvider.getSignerAddress();
989
- const isPasskeySigner = await safeProvider.isPasskeySigner();
990
- if (!signerAddress) {
991
- throw new Error("There is no signer address available to sign the SafeOperation");
992
- }
993
- const isOwner = await this.protocolKit.isOwner(signerAddress);
994
- const isSafeDeployed = await this.protocolKit.isSafeDeployed();
995
- if (!isOwner && isSafeDeployed || !isSafeDeployed && !isPasskeySigner && !isOwner) {
996
- throw new Error("UserOperations can only be signed by Safe owners");
997
- }
998
- let signature;
999
- if (isPasskeySigner) {
1000
- const safeOpHash = safeOp.getHash();
1001
- if (!isSafeDeployed) {
1002
- const passkeySignature = await this.protocolKit.signHash(safeOpHash);
1003
- signature = new import_protocol_kit3.EthSafeSignature(
1004
- this.#SAFE_WEBAUTHN_SHARED_SIGNER_ADDRESS,
1005
- passkeySignature.data,
1006
- true
1007
- // passkeys are contract signatures
1008
- );
1009
- } else {
1010
- signature = await this.protocolKit.signHash(safeOpHash);
1011
- }
1012
- } else {
1013
- if (signingMethod in [
1014
- import_protocol_kit3.SigningMethod.ETH_SIGN_TYPED_DATA_V4,
1015
- import_protocol_kit3.SigningMethod.ETH_SIGN_TYPED_DATA_V3,
1016
- import_protocol_kit3.SigningMethod.ETH_SIGN_TYPED_DATA
1017
- ]) {
1018
- signature = await signSafeOp(
1019
- safeOp.data,
1020
- this.protocolKit.getSafeProvider(),
1021
- this.#SAFE_4337_MODULE_ADDRESS
1022
- );
1023
- } else {
1024
- const safeOpHash = safeOp.getHash();
1025
- signature = await this.protocolKit.signHash(safeOpHash);
1026
- }
1027
- }
1028
- const signedSafeOperation = new SafeOperation_default(safeOp.toUserOperation(), {
1029
- chainId: this.#chainId,
1030
- moduleAddress: this.#SAFE_4337_MODULE_ADDRESS,
1031
- entryPoint: this.#ENTRYPOINT_ADDRESS,
1032
- validUntil: safeOp.data.validUntil,
1033
- validAfter: safeOp.data.validAfter
1034
- });
1035
- safeOp.signatures.forEach((signature2) => {
1036
- signedSafeOperation.addSignature(signature2);
1037
- });
1038
- signedSafeOperation.addSignature(signature);
1039
- return signedSafeOperation;
1040
- }
1041
- /**
1042
- * Executes the relay transaction.
1043
- *
1044
- * @param {Safe4337ExecutableProps} props - The parameters for the transaction execution.
1045
- * @param {EthSafeOperation | SafeOperationResponse} props.executable - The SafeOperation to execute. It can be:
1046
- * - A response from the API (Tx Service)
1047
- * - An instance of EthSafeOperation
1048
- * @return {Promise<string>} The user operation hash.
1049
- */
1050
- async executeTransaction({ executable }) {
1051
- let safeOperation;
1052
- if ((0, import_types_kit3.isSafeOperationResponse)(executable)) {
1053
- safeOperation = this.#toSafeOperation(executable);
1054
- } else {
1055
- safeOperation = executable;
1056
- }
1057
- const userOperation = safeOperation.toUserOperation();
1058
- return this.#bundlerClient.request({
1059
- method: "eth_sendUserOperation" /* SEND_USER_OPERATION */,
1060
- params: [userOperationToHexValues(userOperation), this.#ENTRYPOINT_ADDRESS]
1061
- });
1062
- }
1063
- /**
1064
- * Return a UserOperation based on a hash (userOpHash) returned by eth_sendUserOperation
1065
- *
1066
- * @param {string} userOpHash - The hash of the user operation to fetch. Returned from the #sendUserOperation method
1067
- * @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
1068
- */
1069
- async getUserOperationByHash(userOpHash) {
1070
- return this.#bundlerClient.request({
1071
- method: "eth_getUserOperationByHash" /* GET_USER_OPERATION_BY_HASH */,
1072
- params: [userOpHash]
1073
- });
1074
- }
1075
- /**
1076
- * Return a UserOperation receipt based on a hash (userOpHash) returned by eth_sendUserOperation
1077
- *
1078
- * @param {string} userOpHash - The hash of the user operation to fetch. Returned from the #sendUserOperation method
1079
- * @returns {UserOperationReceipt} - null in case the UserOperation is not yet included in a block, or UserOperationReceipt object
1080
- */
1081
- async getUserOperationReceipt(userOpHash) {
1082
- return this.#bundlerClient.request({
1083
- method: "eth_getUserOperationReceipt" /* GET_USER_OPERATION_RECEIPT */,
1084
- params: [userOpHash]
1085
- });
1086
- }
1087
- /**
1088
- * Returns an array of the entryPoint addresses supported by the client.
1089
- * The first element of the array SHOULD be the entryPoint addressed preferred by the client.
1090
- *
1091
- * @returns {string[]} - The supported entry points.
1092
- */
1093
- async getSupportedEntryPoints() {
1094
- return this.#bundlerClient.request({
1095
- method: "eth_supportedEntryPoints" /* SUPPORTED_ENTRY_POINTS */
1096
- });
1097
- }
1098
- /**
1099
- * Returns EIP-155 Chain ID.
1100
- *
1101
- * @returns {string} - The chain id.
1102
- */
1103
- async getChainId() {
1104
- return this.#bundlerClient.request({ method: "eth_chainId" /* CHAIN_ID */ });
1105
- }
1106
- /**
1107
- * Gets account nonce from the bundler.
1108
- *
1109
- * @param {string} safeAddress - Account address for which the nonce is to be fetched.
1110
- * @returns {Promise<string>} The Promise object will resolve to the account nonce.
1111
- */
1112
- async #getSafeNonceFromEntrypoint(safeAddress) {
1113
- const safeProvider = this.protocolKit.getSafeProvider();
1114
- const newNonce = await safeProvider.readContract({
1115
- address: this.#ENTRYPOINT_ADDRESS || "0x",
1116
- abi: ENTRYPOINT_ABI,
1117
- functionName: "getNonce",
1118
- args: [safeAddress, 0n]
1119
- });
1120
- return newNonce.toString();
1121
- }
1122
- /**
1123
- * Encode the UserOperation execution from a transaction.
1124
- *
1125
- * @param {MetaTransactionData} transaction - The transaction data to encode.
1126
- * @return {string} The encoded call data string.
1127
- */
1128
- #encodeExecuteUserOpCallData(transaction) {
1129
- return (0, import_viem4.encodeFunctionData)({
1130
- abi: ABI,
1131
- functionName: "executeUserOp",
1132
- args: [
1133
- transaction.to,
1134
- BigInt(transaction.value),
1135
- transaction.data,
1136
- transaction.operation || import_types_kit3.OperationType.Call
1137
- ]
1138
- });
1139
- }
1140
- getOnchainIdentifier() {
1141
- return this.#onchainIdentifier;
1142
- }
1143
- };
1144
-
1145
- // test-utils/helpers.ts
1146
- var generateTransferCallData = (to, value) => {
1147
- const functionAbi = (0, import_viem5.parseAbi)(["function transfer(address _to, uint256 _value) returns (bool)"]);
1148
- return (0, import_viem5.encodeFunctionData)({
1149
- abi: functionAbi,
1150
- functionName: "transfer",
1151
- args: [to, value]
1152
- });
1153
- };
1154
- var safe4337PackCache = /* @__PURE__ */ new Map();
1155
- var createSafe4337Pack = async (initOptions) => {
1156
- const key = JSON.stringify(initOptions);
1157
- if (safe4337PackCache.has(key)) {
1158
- return safe4337PackCache.get(key);
1159
- }
1160
- const safe4337Pack = await Safe4337Pack.init({
1161
- provider: RPC_URL,
1162
- signer: process.env.PRIVATE_KEY,
1163
- options: {
1164
- safeAddress: ""
1165
- },
1166
- ...initOptions,
1167
- bundlerUrl: BUNDLER_URL
1168
- });
1169
- safe4337PackCache.set(key, safe4337Pack);
1170
- return safe4337Pack;
1171
- };