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