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