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