@nerochain/mpc-sdk 0.1.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/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/aa.d.mts +185 -0
- package/dist/aa.d.ts +185 -0
- package/dist/aa.js +520 -0
- package/dist/aa.js.map +1 -0
- package/dist/aa.mjs +511 -0
- package/dist/aa.mjs.map +1 -0
- package/dist/chain-manager-C3eHsVt9.d.mts +98 -0
- package/dist/chain-manager-C3eHsVt9.d.ts +98 -0
- package/dist/chains.d.mts +17 -0
- package/dist/chains.d.ts +17 -0
- package/dist/chains.js +331 -0
- package/dist/chains.js.map +1 -0
- package/dist/chains.mjs +315 -0
- package/dist/chains.mjs.map +1 -0
- package/dist/index.d.mts +656 -0
- package/dist/index.d.ts +656 -0
- package/dist/index.js +6627 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6502 -0
- package/dist/index.mjs.map +1 -0
- package/dist/modal.d.mts +68 -0
- package/dist/modal.d.ts +68 -0
- package/dist/modal.js +4867 -0
- package/dist/modal.js.map +1 -0
- package/dist/modal.mjs +4850 -0
- package/dist/modal.mjs.map +1 -0
- package/dist/nero-sdk-Cm8gzHZJ.d.mts +684 -0
- package/dist/nero-sdk-IhuTBrXZ.d.ts +684 -0
- package/dist/no-modal.d.mts +56 -0
- package/dist/no-modal.d.ts +56 -0
- package/dist/no-modal.js +4060 -0
- package/dist/no-modal.js.map +1 -0
- package/dist/no-modal.mjs +4041 -0
- package/dist/no-modal.mjs.map +1 -0
- package/dist/react.d.mts +28 -0
- package/dist/react.d.ts +28 -0
- package/dist/react.js +4033 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +4016 -0
- package/dist/react.mjs.map +1 -0
- package/dist/useNeroWallet-PZh940vV.d.ts +164 -0
- package/dist/useNeroWallet-awIYqM6e.d.mts +164 -0
- package/package.json +126 -0
package/dist/aa.mjs
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
2
|
+
import { hexToBytes, bytesToHex } from '@noble/hashes/utils';
|
|
3
|
+
|
|
4
|
+
// src/aa/types.ts
|
|
5
|
+
function userOpToHex(userOp) {
|
|
6
|
+
return {
|
|
7
|
+
sender: userOp.sender,
|
|
8
|
+
nonce: `0x${userOp.nonce.toString(16)}`,
|
|
9
|
+
initCode: userOp.initCode,
|
|
10
|
+
callData: userOp.callData,
|
|
11
|
+
callGasLimit: `0x${userOp.callGasLimit.toString(16)}`,
|
|
12
|
+
verificationGasLimit: `0x${userOp.verificationGasLimit.toString(16)}`,
|
|
13
|
+
preVerificationGas: `0x${userOp.preVerificationGas.toString(16)}`,
|
|
14
|
+
maxFeePerGas: `0x${userOp.maxFeePerGas.toString(16)}`,
|
|
15
|
+
maxPriorityFeePerGas: `0x${userOp.maxPriorityFeePerGas.toString(16)}`,
|
|
16
|
+
paymasterAndData: userOp.paymasterAndData,
|
|
17
|
+
signature: userOp.signature
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function userOpFromHex(userOpHex) {
|
|
21
|
+
return {
|
|
22
|
+
sender: userOpHex.sender,
|
|
23
|
+
nonce: BigInt(userOpHex.nonce),
|
|
24
|
+
initCode: userOpHex.initCode,
|
|
25
|
+
callData: userOpHex.callData,
|
|
26
|
+
callGasLimit: BigInt(userOpHex.callGasLimit),
|
|
27
|
+
verificationGasLimit: BigInt(userOpHex.verificationGasLimit),
|
|
28
|
+
preVerificationGas: BigInt(userOpHex.preVerificationGas),
|
|
29
|
+
maxFeePerGas: BigInt(userOpHex.maxFeePerGas),
|
|
30
|
+
maxPriorityFeePerGas: BigInt(userOpHex.maxPriorityFeePerGas),
|
|
31
|
+
paymasterAndData: userOpHex.paymasterAndData,
|
|
32
|
+
signature: userOpHex.signature
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/aa/bundler-client.ts
|
|
37
|
+
var BundlerClient = class {
|
|
38
|
+
constructor(config) {
|
|
39
|
+
this.requestId = 0;
|
|
40
|
+
this.bundlerUrl = config.bundlerUrl;
|
|
41
|
+
this.entryPointAddress = config.entryPointAddress;
|
|
42
|
+
}
|
|
43
|
+
async sendUserOperation(userOp) {
|
|
44
|
+
const userOpHex = userOpToHex(userOp);
|
|
45
|
+
return this.call("eth_sendUserOperation", [
|
|
46
|
+
userOpHex,
|
|
47
|
+
this.entryPointAddress
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
async estimateUserOperationGas(userOp) {
|
|
51
|
+
const partialOpHex = {};
|
|
52
|
+
if (userOp.sender) partialOpHex.sender = userOp.sender;
|
|
53
|
+
if (userOp.nonce !== void 0)
|
|
54
|
+
partialOpHex.nonce = `0x${userOp.nonce.toString(16)}`;
|
|
55
|
+
if (userOp.initCode) partialOpHex.initCode = userOp.initCode;
|
|
56
|
+
if (userOp.callData) partialOpHex.callData = userOp.callData;
|
|
57
|
+
if (userOp.callGasLimit !== void 0)
|
|
58
|
+
partialOpHex.callGasLimit = `0x${userOp.callGasLimit.toString(16)}`;
|
|
59
|
+
if (userOp.verificationGasLimit !== void 0)
|
|
60
|
+
partialOpHex.verificationGasLimit = `0x${userOp.verificationGasLimit.toString(16)}`;
|
|
61
|
+
if (userOp.preVerificationGas !== void 0)
|
|
62
|
+
partialOpHex.preVerificationGas = `0x${userOp.preVerificationGas.toString(16)}`;
|
|
63
|
+
if (userOp.maxFeePerGas !== void 0)
|
|
64
|
+
partialOpHex.maxFeePerGas = `0x${userOp.maxFeePerGas.toString(16)}`;
|
|
65
|
+
if (userOp.maxPriorityFeePerGas !== void 0)
|
|
66
|
+
partialOpHex.maxPriorityFeePerGas = `0x${userOp.maxPriorityFeePerGas.toString(16)}`;
|
|
67
|
+
if (userOp.paymasterAndData)
|
|
68
|
+
partialOpHex.paymasterAndData = userOp.paymasterAndData;
|
|
69
|
+
if (userOp.signature) partialOpHex.signature = userOp.signature;
|
|
70
|
+
const result = await this.call("eth_estimateUserOperationGas", [partialOpHex, this.entryPointAddress]);
|
|
71
|
+
return {
|
|
72
|
+
preVerificationGas: BigInt(result.preVerificationGas),
|
|
73
|
+
verificationGasLimit: BigInt(result.verificationGasLimit),
|
|
74
|
+
callGasLimit: BigInt(result.callGasLimit)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async getUserOperationByHash(hash) {
|
|
78
|
+
try {
|
|
79
|
+
return await this.call(
|
|
80
|
+
"eth_getUserOperationByHash",
|
|
81
|
+
[hash]
|
|
82
|
+
);
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async getUserOperationReceipt(hash) {
|
|
88
|
+
try {
|
|
89
|
+
return await this.call(
|
|
90
|
+
"eth_getUserOperationReceipt",
|
|
91
|
+
[hash]
|
|
92
|
+
);
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async getSupportedEntryPoints() {
|
|
98
|
+
return this.call("eth_supportedEntryPoints", []);
|
|
99
|
+
}
|
|
100
|
+
async getChainId() {
|
|
101
|
+
const result = await this.call("eth_chainId", []);
|
|
102
|
+
return Number.parseInt(result, 16);
|
|
103
|
+
}
|
|
104
|
+
async waitForUserOperationReceipt(hash, timeout = 6e4, interval = 2e3) {
|
|
105
|
+
const startTime = Date.now();
|
|
106
|
+
while (Date.now() - startTime < timeout) {
|
|
107
|
+
const receipt = await this.getUserOperationReceipt(hash);
|
|
108
|
+
if (receipt) {
|
|
109
|
+
return receipt;
|
|
110
|
+
}
|
|
111
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
112
|
+
}
|
|
113
|
+
throw new Error(`UserOperation ${hash} not confirmed within timeout`);
|
|
114
|
+
}
|
|
115
|
+
async call(method, params) {
|
|
116
|
+
const response = await fetch(this.bundlerUrl, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: { "Content-Type": "application/json" },
|
|
119
|
+
body: JSON.stringify({
|
|
120
|
+
jsonrpc: "2.0",
|
|
121
|
+
id: ++this.requestId,
|
|
122
|
+
method,
|
|
123
|
+
params
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
throw new Error(`Bundler request failed: ${response.status}`);
|
|
128
|
+
}
|
|
129
|
+
const data = await response.json();
|
|
130
|
+
if (data.error) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Bundler error: ${data.error.message} (code: ${data.error.code})`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return data.result;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
function createBundlerClient(config) {
|
|
139
|
+
return new BundlerClient(config);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/aa/paymaster-client.ts
|
|
143
|
+
var PaymasterClient = class {
|
|
144
|
+
constructor(config) {
|
|
145
|
+
this.requestId = 0;
|
|
146
|
+
this.paymasterUrl = config.paymasterUrl;
|
|
147
|
+
this.entryPointAddress = config.entryPointAddress;
|
|
148
|
+
this.chainId = config.chainId;
|
|
149
|
+
}
|
|
150
|
+
async getPaymasterData(userOp, context) {
|
|
151
|
+
const partialOpHex = this.partialUserOpToHex(userOp);
|
|
152
|
+
const result = await this.call(
|
|
153
|
+
"pm_sponsorUserOperation",
|
|
154
|
+
[partialOpHex, this.entryPointAddress, context ?? {}]
|
|
155
|
+
);
|
|
156
|
+
return {
|
|
157
|
+
paymasterAndData: result.paymasterAndData,
|
|
158
|
+
preVerificationGas: result.preVerificationGas ? BigInt(result.preVerificationGas) : void 0,
|
|
159
|
+
verificationGasLimit: result.verificationGasLimit ? BigInt(result.verificationGasLimit) : void 0,
|
|
160
|
+
callGasLimit: result.callGasLimit ? BigInt(result.callGasLimit) : void 0
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
async validatePaymasterUserOp(userOp) {
|
|
164
|
+
const userOpHex = userOpToHex(userOp);
|
|
165
|
+
try {
|
|
166
|
+
const result = await this.call("pm_validatePaymasterUserOp", [userOpHex, this.entryPointAddress]);
|
|
167
|
+
return {
|
|
168
|
+
valid: result.valid,
|
|
169
|
+
validAfter: result.validAfter ? BigInt(result.validAfter) : void 0,
|
|
170
|
+
validUntil: result.validUntil ? BigInt(result.validUntil) : void 0
|
|
171
|
+
};
|
|
172
|
+
} catch {
|
|
173
|
+
return { valid: false };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async getSupportedTokens() {
|
|
177
|
+
try {
|
|
178
|
+
return await this.call("pm_supportedTokens", [this.chainId.toString()]);
|
|
179
|
+
} catch {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async getTokenPaymasterData(userOp, tokenAddress) {
|
|
184
|
+
return this.getPaymasterData(userOp, {
|
|
185
|
+
mode: "erc20",
|
|
186
|
+
token: tokenAddress
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
partialUserOpToHex(userOp) {
|
|
190
|
+
const result = {};
|
|
191
|
+
if (userOp.sender) result.sender = userOp.sender;
|
|
192
|
+
if (userOp.nonce !== void 0)
|
|
193
|
+
result.nonce = `0x${userOp.nonce.toString(16)}`;
|
|
194
|
+
if (userOp.initCode) result.initCode = userOp.initCode;
|
|
195
|
+
if (userOp.callData) result.callData = userOp.callData;
|
|
196
|
+
if (userOp.callGasLimit !== void 0)
|
|
197
|
+
result.callGasLimit = `0x${userOp.callGasLimit.toString(16)}`;
|
|
198
|
+
if (userOp.verificationGasLimit !== void 0)
|
|
199
|
+
result.verificationGasLimit = `0x${userOp.verificationGasLimit.toString(16)}`;
|
|
200
|
+
if (userOp.preVerificationGas !== void 0)
|
|
201
|
+
result.preVerificationGas = `0x${userOp.preVerificationGas.toString(16)}`;
|
|
202
|
+
if (userOp.maxFeePerGas !== void 0)
|
|
203
|
+
result.maxFeePerGas = `0x${userOp.maxFeePerGas.toString(16)}`;
|
|
204
|
+
if (userOp.maxPriorityFeePerGas !== void 0)
|
|
205
|
+
result.maxPriorityFeePerGas = `0x${userOp.maxPriorityFeePerGas.toString(16)}`;
|
|
206
|
+
if (userOp.paymasterAndData)
|
|
207
|
+
result.paymasterAndData = userOp.paymasterAndData;
|
|
208
|
+
if (userOp.signature) result.signature = userOp.signature;
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
async call(method, params) {
|
|
212
|
+
const response = await fetch(this.paymasterUrl, {
|
|
213
|
+
method: "POST",
|
|
214
|
+
headers: { "Content-Type": "application/json" },
|
|
215
|
+
body: JSON.stringify({
|
|
216
|
+
jsonrpc: "2.0",
|
|
217
|
+
id: ++this.requestId,
|
|
218
|
+
method,
|
|
219
|
+
params
|
|
220
|
+
})
|
|
221
|
+
});
|
|
222
|
+
if (!response.ok) {
|
|
223
|
+
throw new Error(`Paymaster request failed: ${response.status}`);
|
|
224
|
+
}
|
|
225
|
+
const data = await response.json();
|
|
226
|
+
if (data.error) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
`Paymaster error: ${data.error.message} (code: ${data.error.code})`
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
return data.result;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
function createPaymasterClient(config) {
|
|
235
|
+
return new PaymasterClient(config);
|
|
236
|
+
}
|
|
237
|
+
var EXECUTE_SELECTOR = "b61d27f6";
|
|
238
|
+
var EXECUTE_BATCH_SELECTOR = "18dfb3c7";
|
|
239
|
+
var CREATE_ACCOUNT_SELECTOR = "5fbfb9cf";
|
|
240
|
+
var GET_ADDRESS_SELECTOR = "8cb84e18";
|
|
241
|
+
var SimpleAccount = class {
|
|
242
|
+
constructor(config) {
|
|
243
|
+
this._accountAddress = null;
|
|
244
|
+
this._isDeployed = null;
|
|
245
|
+
this._cachedNonce = null;
|
|
246
|
+
this.ownerAddress = config.ownerAddress.toLowerCase();
|
|
247
|
+
this.factoryAddress = config.factoryAddress.toLowerCase();
|
|
248
|
+
this.entryPointAddress = config.entryPointAddress.toLowerCase();
|
|
249
|
+
this.salt = config.salt ?? 0n;
|
|
250
|
+
this.chainId = config.chainId;
|
|
251
|
+
this.rpcConnection = config.rpcConnection;
|
|
252
|
+
this.bundlerClient = new BundlerClient({
|
|
253
|
+
bundlerUrl: config.bundlerUrl,
|
|
254
|
+
entryPointAddress: config.entryPointAddress,
|
|
255
|
+
chainId: config.chainId
|
|
256
|
+
});
|
|
257
|
+
this.paymasterClient = config.paymasterUrl ? new PaymasterClient({
|
|
258
|
+
paymasterUrl: config.paymasterUrl,
|
|
259
|
+
entryPointAddress: config.entryPointAddress,
|
|
260
|
+
chainId: config.chainId
|
|
261
|
+
}) : null;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* @deprecated Use getAccountAddress() instead. This sync getter is removed
|
|
265
|
+
* because address derivation now requires an RPC call to the factory.
|
|
266
|
+
*/
|
|
267
|
+
get accountAddress() {
|
|
268
|
+
if (this._accountAddress) {
|
|
269
|
+
return this._accountAddress;
|
|
270
|
+
}
|
|
271
|
+
throw new Error(
|
|
272
|
+
"SimpleAccount.accountAddress is deprecated. Use 'await account.getAccountAddress()' instead. Address derivation now requires an RPC call to factory.getAddress()."
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
async getAccountAddress() {
|
|
276
|
+
if (this._accountAddress) {
|
|
277
|
+
return this._accountAddress;
|
|
278
|
+
}
|
|
279
|
+
this._accountAddress = await this.fetchAccountAddressFromFactory();
|
|
280
|
+
return this._accountAddress;
|
|
281
|
+
}
|
|
282
|
+
async isDeployed() {
|
|
283
|
+
if (this._isDeployed !== null) {
|
|
284
|
+
return this._isDeployed;
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
const code = await this.getAccountCode();
|
|
288
|
+
this._isDeployed = code !== "0x" && code.length > 2;
|
|
289
|
+
return this._isDeployed;
|
|
290
|
+
} catch {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
invalidateDeploymentCache() {
|
|
295
|
+
this._isDeployed = null;
|
|
296
|
+
}
|
|
297
|
+
async buildUserOperation(transactions, options) {
|
|
298
|
+
const txArray = Array.isArray(transactions) ? transactions : [transactions];
|
|
299
|
+
const callData = this.encodeExecute(txArray);
|
|
300
|
+
const accountAddress = await this.getAccountAddress();
|
|
301
|
+
const isDeployed = await this.isDeployed();
|
|
302
|
+
const initCode = isDeployed ? "0x" : this.getInitCode();
|
|
303
|
+
const nonce = await this.getNonce();
|
|
304
|
+
let userOp = {
|
|
305
|
+
sender: accountAddress,
|
|
306
|
+
nonce,
|
|
307
|
+
initCode,
|
|
308
|
+
callData,
|
|
309
|
+
callGasLimit: 0n,
|
|
310
|
+
verificationGasLimit: 0n,
|
|
311
|
+
preVerificationGas: 0n,
|
|
312
|
+
maxFeePerGas: 0n,
|
|
313
|
+
maxPriorityFeePerGas: 0n,
|
|
314
|
+
paymasterAndData: "0x",
|
|
315
|
+
signature: this.getDummySignature()
|
|
316
|
+
};
|
|
317
|
+
const gasEstimate = await this.estimateGas(userOp);
|
|
318
|
+
const feeData = await this.getFeeData();
|
|
319
|
+
userOp = {
|
|
320
|
+
...userOp,
|
|
321
|
+
callGasLimit: gasEstimate.callGasLimit,
|
|
322
|
+
verificationGasLimit: gasEstimate.verificationGasLimit,
|
|
323
|
+
preVerificationGas: gasEstimate.preVerificationGas,
|
|
324
|
+
maxFeePerGas: feeData.maxFeePerGas,
|
|
325
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas
|
|
326
|
+
};
|
|
327
|
+
if (options?.usePaymaster && this.paymasterClient) {
|
|
328
|
+
const paymasterData = await this.paymasterClient.getPaymasterData(
|
|
329
|
+
userOp,
|
|
330
|
+
options.paymasterContext
|
|
331
|
+
);
|
|
332
|
+
userOp.paymasterAndData = paymasterData.paymasterAndData;
|
|
333
|
+
if (paymasterData.preVerificationGas) {
|
|
334
|
+
userOp.preVerificationGas = paymasterData.preVerificationGas;
|
|
335
|
+
}
|
|
336
|
+
if (paymasterData.verificationGasLimit) {
|
|
337
|
+
userOp.verificationGasLimit = paymasterData.verificationGasLimit;
|
|
338
|
+
}
|
|
339
|
+
if (paymasterData.callGasLimit) {
|
|
340
|
+
userOp.callGasLimit = paymasterData.callGasLimit;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
userOp.signature = "0x";
|
|
344
|
+
return userOp;
|
|
345
|
+
}
|
|
346
|
+
computeUserOpHash(userOp) {
|
|
347
|
+
const packed = this.packUserOp(userOp);
|
|
348
|
+
const userOpHash = keccak_256(packed);
|
|
349
|
+
const finalHash = keccak_256(
|
|
350
|
+
hexToBytes(
|
|
351
|
+
bytesToHex(userOpHash) + this.entryPointAddress.slice(2).padStart(64, "0") + this.chainId.toString(16).padStart(64, "0")
|
|
352
|
+
)
|
|
353
|
+
);
|
|
354
|
+
return `0x${bytesToHex(finalHash)}`;
|
|
355
|
+
}
|
|
356
|
+
async sendUserOperation(userOp) {
|
|
357
|
+
const userOpHash = await this.bundlerClient.sendUserOperation(userOp);
|
|
358
|
+
return {
|
|
359
|
+
userOpHash,
|
|
360
|
+
wait: async () => {
|
|
361
|
+
await this.bundlerClient.waitForUserOperationReceipt(userOpHash);
|
|
362
|
+
this._isDeployed = true;
|
|
363
|
+
this.invalidateNonceCache();
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
async fetchAccountAddressFromFactory() {
|
|
368
|
+
const ownerPadded = this.ownerAddress.slice(2).padStart(64, "0");
|
|
369
|
+
const saltPadded = this.salt.toString(16).padStart(64, "0");
|
|
370
|
+
const result = await this.rpcConnection.call("eth_call", [
|
|
371
|
+
{
|
|
372
|
+
to: this.factoryAddress,
|
|
373
|
+
data: `0x${GET_ADDRESS_SELECTOR}${ownerPadded}${saltPadded}`
|
|
374
|
+
},
|
|
375
|
+
"latest"
|
|
376
|
+
]);
|
|
377
|
+
return `0x${result.slice(-40)}`;
|
|
378
|
+
}
|
|
379
|
+
getInitCode() {
|
|
380
|
+
const ownerPadded = this.ownerAddress.slice(2).padStart(64, "0");
|
|
381
|
+
const saltPadded = this.salt.toString(16).padStart(64, "0");
|
|
382
|
+
return this.factoryAddress + CREATE_ACCOUNT_SELECTOR + ownerPadded + saltPadded;
|
|
383
|
+
}
|
|
384
|
+
encodeExecute(transactions) {
|
|
385
|
+
if (transactions.length === 1) {
|
|
386
|
+
const tx = transactions[0];
|
|
387
|
+
const to = tx.to.slice(2).toLowerCase().padStart(64, "0");
|
|
388
|
+
const value = (tx.value ?? 0n).toString(16).padStart(64, "0");
|
|
389
|
+
const dataOffset = "60".padStart(64, "0");
|
|
390
|
+
const data = tx.data?.slice(2) ?? "";
|
|
391
|
+
const dataLength = (data.length / 2).toString(16).padStart(64, "0");
|
|
392
|
+
return `0x${EXECUTE_SELECTOR}${to}${value}${dataOffset}${dataLength}${data}`;
|
|
393
|
+
}
|
|
394
|
+
const n = transactions.length;
|
|
395
|
+
const destArraySize = 32 + n * 32;
|
|
396
|
+
const valueArraySize = 32 + n * 32;
|
|
397
|
+
const destOffset = 96;
|
|
398
|
+
const valueOffset = destOffset + destArraySize;
|
|
399
|
+
const funcOffset = valueOffset + valueArraySize;
|
|
400
|
+
let encoded = EXECUTE_BATCH_SELECTOR;
|
|
401
|
+
encoded += destOffset.toString(16).padStart(64, "0");
|
|
402
|
+
encoded += valueOffset.toString(16).padStart(64, "0");
|
|
403
|
+
encoded += funcOffset.toString(16).padStart(64, "0");
|
|
404
|
+
encoded += n.toString(16).padStart(64, "0");
|
|
405
|
+
for (const tx of transactions) {
|
|
406
|
+
encoded += tx.to.slice(2).toLowerCase().padStart(64, "0");
|
|
407
|
+
}
|
|
408
|
+
encoded += n.toString(16).padStart(64, "0");
|
|
409
|
+
for (const tx of transactions) {
|
|
410
|
+
encoded += (tx.value ?? 0n).toString(16).padStart(64, "0");
|
|
411
|
+
}
|
|
412
|
+
const funcDatas = transactions.map((tx) => {
|
|
413
|
+
const data = tx.data ?? "0x";
|
|
414
|
+
return data.startsWith("0x") ? data.slice(2) : data;
|
|
415
|
+
});
|
|
416
|
+
const funcElementOffsets = [];
|
|
417
|
+
let currentOffset = 32 + n * 32;
|
|
418
|
+
for (const funcData of funcDatas) {
|
|
419
|
+
funcElementOffsets.push(currentOffset);
|
|
420
|
+
const dataLen = funcData.length / 2;
|
|
421
|
+
const paddedLen = Math.ceil(dataLen / 32) * 32;
|
|
422
|
+
currentOffset += 32 + paddedLen;
|
|
423
|
+
}
|
|
424
|
+
encoded += n.toString(16).padStart(64, "0");
|
|
425
|
+
for (const offset of funcElementOffsets) {
|
|
426
|
+
encoded += offset.toString(16).padStart(64, "0");
|
|
427
|
+
}
|
|
428
|
+
for (const funcData of funcDatas) {
|
|
429
|
+
const dataLen = funcData.length / 2;
|
|
430
|
+
encoded += dataLen.toString(16).padStart(64, "0");
|
|
431
|
+
if (funcData.length > 0) {
|
|
432
|
+
const paddedLen = Math.ceil(dataLen / 32) * 32;
|
|
433
|
+
encoded += funcData.padEnd(paddedLen * 2, "0");
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return `0x${encoded}`;
|
|
437
|
+
}
|
|
438
|
+
packUserOp(userOp) {
|
|
439
|
+
const initCodeHash = keccak_256(hexToBytes(userOp.initCode.slice(2) || ""));
|
|
440
|
+
const callDataHash = keccak_256(hexToBytes(userOp.callData.slice(2) || ""));
|
|
441
|
+
const paymasterAndDataHash = keccak_256(
|
|
442
|
+
hexToBytes(userOp.paymasterAndData.slice(2) || "")
|
|
443
|
+
);
|
|
444
|
+
const packed = userOp.sender.slice(2).toLowerCase().padStart(64, "0") + userOp.nonce.toString(16).padStart(64, "0") + bytesToHex(initCodeHash) + bytesToHex(callDataHash) + userOp.callGasLimit.toString(16).padStart(64, "0") + userOp.verificationGasLimit.toString(16).padStart(64, "0") + userOp.preVerificationGas.toString(16).padStart(64, "0") + userOp.maxFeePerGas.toString(16).padStart(64, "0") + userOp.maxPriorityFeePerGas.toString(16).padStart(64, "0") + bytesToHex(paymasterAndDataHash);
|
|
445
|
+
return hexToBytes(packed);
|
|
446
|
+
}
|
|
447
|
+
getDummySignature() {
|
|
448
|
+
return `0x${"00".repeat(65)}`;
|
|
449
|
+
}
|
|
450
|
+
async getNonce() {
|
|
451
|
+
const isDeployed = await this.isDeployed();
|
|
452
|
+
if (!isDeployed) {
|
|
453
|
+
return 0n;
|
|
454
|
+
}
|
|
455
|
+
if (this._cachedNonce !== null) {
|
|
456
|
+
return this._cachedNonce;
|
|
457
|
+
}
|
|
458
|
+
const accountAddress = await this.getAccountAddress();
|
|
459
|
+
const nonceKey = 0n;
|
|
460
|
+
const nonceData = await this.rpcConnection.call("eth_call", [
|
|
461
|
+
{
|
|
462
|
+
to: this.entryPointAddress,
|
|
463
|
+
data: `0x35567e1a${accountAddress.slice(2).padStart(64, "0")}${nonceKey.toString(16).padStart(64, "0")}`
|
|
464
|
+
},
|
|
465
|
+
"latest"
|
|
466
|
+
]);
|
|
467
|
+
const nonce = BigInt(nonceData);
|
|
468
|
+
this._cachedNonce = nonce;
|
|
469
|
+
return nonce;
|
|
470
|
+
}
|
|
471
|
+
invalidateNonceCache() {
|
|
472
|
+
this._cachedNonce = null;
|
|
473
|
+
}
|
|
474
|
+
async estimateGas(userOp) {
|
|
475
|
+
try {
|
|
476
|
+
return await this.bundlerClient.estimateUserOperationGas(userOp);
|
|
477
|
+
} catch {
|
|
478
|
+
const isDeployed = await this.isDeployed();
|
|
479
|
+
return {
|
|
480
|
+
preVerificationGas: 50000n,
|
|
481
|
+
verificationGasLimit: isDeployed ? 100000n : 400000n,
|
|
482
|
+
callGasLimit: 200000n
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
async getFeeData() {
|
|
487
|
+
try {
|
|
488
|
+
const gasPrice = await this.rpcConnection.getGasPrice();
|
|
489
|
+
return {
|
|
490
|
+
maxFeePerGas: gasPrice * 2n,
|
|
491
|
+
maxPriorityFeePerGas: gasPrice / 10n
|
|
492
|
+
};
|
|
493
|
+
} catch {
|
|
494
|
+
return {
|
|
495
|
+
maxFeePerGas: 1000000000n,
|
|
496
|
+
maxPriorityFeePerGas: 1000000000n
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
async getAccountCode() {
|
|
501
|
+
const accountAddress = await this.getAccountAddress();
|
|
502
|
+
return this.rpcConnection.getCode(accountAddress);
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
function createSimpleAccount(config) {
|
|
506
|
+
return new SimpleAccount(config);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export { BundlerClient, PaymasterClient, SimpleAccount, createBundlerClient, createPaymasterClient, createSimpleAccount, userOpFromHex, userOpToHex };
|
|
510
|
+
//# sourceMappingURL=aa.mjs.map
|
|
511
|
+
//# sourceMappingURL=aa.mjs.map
|
package/dist/aa.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/aa/types.ts","../src/aa/bundler-client.ts","../src/aa/paymaster-client.ts","../src/aa/simple-account.ts"],"names":[],"mappings":";;;;AA+EO,SAAS,YAAY,MAAA,EAAyC;AACpE,EAAA,OAAO;AAAA,IACN,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,OAAO,CAAA,EAAA,EAAK,MAAA,CAAO,KAAA,CAAM,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA;AAAA,IACrC,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,cAAc,CAAA,EAAA,EAAK,MAAA,CAAO,YAAA,CAAa,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA;AAAA,IACnD,sBAAsB,CAAA,EAAA,EAAK,MAAA,CAAO,oBAAA,CAAqB,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA;AAAA,IACnE,oBAAoB,CAAA,EAAA,EAAK,MAAA,CAAO,kBAAA,CAAmB,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA;AAAA,IAC/D,cAAc,CAAA,EAAA,EAAK,MAAA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,wBAAA,CAAyB,MAAM,CAAA;AAAA,IAChE,CAAA,CAAA,MAAQ;AACP,MAAA,MAAM,UAAA,GAAa,MAAM,IAAA,CAAK,UAAA,EAAW;AACzC,MAAA,OAAO;AAAA,QACN,kBAAA,EAAoB,MAAA;AAAA,QACpB,oBAAA,EAAsB,aAAa,OAAA,GAAU,OAAA;AAAA,QAC7C,YAAA,EAAc;AAAA,OACf;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAc,UAAA,GAGX;AACF,IAAA,IAAI;AACH,MAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,aAAA,CAAc,WAAA,EAAY;AACtD,MAAA,OAAO;AAAA,QACN,cAAc,QAAA,GAAW,EAAA;AAAA,QACzB,sBAAsB,QAAA,GAAW;AAAA,OAClC;AAAA,IACD,CAAA,CAAA,MAAQ;AACP,MAAA,OAAO;AAAA,QACN,YAAA,EAAc,WAAA;AAAA,QACd,oBAAA,EAAsB;AAAA,OACvB;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAc,cAAA,GAAkC;AAC/C,IAAA,MAAM,cAAA,GAAiB,MAAM,IAAA,CAAK,iBAAA,EAAkB;AACpD,IAAA,OAAO,IAAA,CAAK,aAAA,CAAc,OAAA,CAAQ,cAAc,CAAA;AAAA,EACjD;AACD;AAEO,SAAS,oBACf,MAAA,EACgB;AAChB,EAAA,OAAO,IAAI,cAAc,MAAM,CAAA;AAChC","file":"aa.mjs","sourcesContent":["export interface UserOperation {\n\tsender: string;\n\tnonce: bigint;\n\tinitCode: string;\n\tcallData: string;\n\tcallGasLimit: bigint;\n\tverificationGasLimit: bigint;\n\tpreVerificationGas: bigint;\n\tmaxFeePerGas: bigint;\n\tmaxPriorityFeePerGas: bigint;\n\tpaymasterAndData: string;\n\tsignature: string;\n}\n\nexport interface UserOperationHex {\n\tsender: string;\n\tnonce: string;\n\tinitCode: string;\n\tcallData: string;\n\tcallGasLimit: string;\n\tverificationGasLimit: string;\n\tpreVerificationGas: string;\n\tmaxFeePerGas: string;\n\tmaxPriorityFeePerGas: string;\n\tpaymasterAndData: string;\n\tsignature: string;\n}\n\nexport interface GasEstimate {\n\tpreVerificationGas: bigint;\n\tverificationGasLimit: bigint;\n\tcallGasLimit: bigint;\n}\n\nexport interface UserOperationReceipt {\n\tuserOpHash: string;\n\tentryPoint: string;\n\tsender: string;\n\tnonce: string;\n\tpaymaster: string;\n\tactualGasCost: string;\n\tactualGasUsed: string;\n\tsuccess: boolean;\n\tlogs: Array<{\n\t\taddress: string;\n\t\ttopics: string[];\n\t\tdata: string;\n\t}>;\n\treceipt: {\n\t\ttransactionHash: string;\n\t\ttransactionIndex: string;\n\t\tblockHash: string;\n\t\tblockNumber: string;\n\t\tfrom: string;\n\t\tto: string;\n\t\tgasUsed: string;\n\t\tstatus: string;\n\t};\n}\n\nexport interface PaymasterResult {\n\tpaymasterAndData: string;\n\tpreVerificationGas?: bigint;\n\tverificationGasLimit?: bigint;\n\tcallGasLimit?: bigint;\n}\n\nexport interface PaymasterContext {\n\tmode?: \"free\" | \"sponsored\" | \"erc20\";\n\ttoken?: string;\n\tsponsorId?: string;\n}\n\nexport interface SimpleAccountFactoryData {\n\tfactoryAddress: string;\n\townerAddress: string;\n\tsalt: bigint;\n}\n\nexport function userOpToHex(userOp: UserOperation): UserOperationHex {\n\treturn {\n\t\tsender: userOp.sender,\n\t\tnonce: `0x${userOp.nonce.toString(16)}`,\n\t\tinitCode: userOp.initCode,\n\t\tcallData: userOp.callData,\n\t\tcallGasLimit: `0x${userOp.callGasLimit.toString(16)}`,\n\t\tverificationGasLimit: `0x${userOp.verificationGasLimit.toString(16)}`,\n\t\tpreVerificationGas: `0x${userOp.preVerificationGas.toString(16)}`,\n\t\tmaxFeePerGas: `0x${userOp.maxFeePerGas.toString(16)}`,\n\t\tmaxPriorityFeePerGas: `0x${userOp.maxPriorityFeePerGas.toString(16)}`,\n\t\tpaymasterAndData: userOp.paymasterAndData,\n\t\tsignature: userOp.signature,\n\t};\n}\n\nexport function userOpFromHex(userOpHex: UserOperationHex): UserOperation {\n\treturn {\n\t\tsender: userOpHex.sender,\n\t\tnonce: BigInt(userOpHex.nonce),\n\t\tinitCode: userOpHex.initCode,\n\t\tcallData: userOpHex.callData,\n\t\tcallGasLimit: BigInt(userOpHex.callGasLimit),\n\t\tverificationGasLimit: BigInt(userOpHex.verificationGasLimit),\n\t\tpreVerificationGas: BigInt(userOpHex.preVerificationGas),\n\t\tmaxFeePerGas: BigInt(userOpHex.maxFeePerGas),\n\t\tmaxPriorityFeePerGas: BigInt(userOpHex.maxPriorityFeePerGas),\n\t\tpaymasterAndData: userOpHex.paymasterAndData,\n\t\tsignature: userOpHex.signature,\n\t};\n}\n","import type {\n\tGasEstimate,\n\tUserOperation,\n\tUserOperationHex,\n\tUserOperationReceipt,\n} from \"./types\";\nimport { userOpToHex } from \"./types\";\n\nexport interface BundlerClientConfig {\n\tbundlerUrl: string;\n\tentryPointAddress: string;\n\tchainId: number;\n}\n\ninterface JsonRpcResponse<T> {\n\tjsonrpc: string;\n\tid: number;\n\tresult?: T;\n\terror?: {\n\t\tcode: number;\n\t\tmessage: string;\n\t\tdata?: unknown;\n\t};\n}\n\nexport class BundlerClient {\n\tprivate bundlerUrl: string;\n\tprivate entryPointAddress: string;\n\tprivate requestId = 0;\n\n\tconstructor(config: BundlerClientConfig) {\n\t\tthis.bundlerUrl = config.bundlerUrl;\n\t\tthis.entryPointAddress = config.entryPointAddress;\n\t}\n\n\tasync sendUserOperation(userOp: UserOperation): Promise<string> {\n\t\tconst userOpHex = userOpToHex(userOp);\n\t\treturn this.call<string>(\"eth_sendUserOperation\", [\n\t\t\tuserOpHex,\n\t\t\tthis.entryPointAddress,\n\t\t]);\n\t}\n\n\tasync estimateUserOperationGas(\n\t\tuserOp: Partial<UserOperation>,\n\t): Promise<GasEstimate> {\n\t\tconst partialOpHex: Partial<UserOperationHex> = {};\n\n\t\tif (userOp.sender) partialOpHex.sender = userOp.sender;\n\t\tif (userOp.nonce !== undefined)\n\t\t\tpartialOpHex.nonce = `0x${userOp.nonce.toString(16)}`;\n\t\tif (userOp.initCode) partialOpHex.initCode = userOp.initCode;\n\t\tif (userOp.callData) partialOpHex.callData = userOp.callData;\n\t\tif (userOp.callGasLimit !== undefined)\n\t\t\tpartialOpHex.callGasLimit = `0x${userOp.callGasLimit.toString(16)}`;\n\t\tif (userOp.verificationGasLimit !== undefined)\n\t\t\tpartialOpHex.verificationGasLimit = `0x${userOp.verificationGasLimit.toString(16)}`;\n\t\tif (userOp.preVerificationGas !== undefined)\n\t\t\tpartialOpHex.preVerificationGas = `0x${userOp.preVerificationGas.toString(16)}`;\n\t\tif (userOp.maxFeePerGas !== undefined)\n\t\t\tpartialOpHex.maxFeePerGas = `0x${userOp.maxFeePerGas.toString(16)}`;\n\t\tif (userOp.maxPriorityFeePerGas !== undefined)\n\t\t\tpartialOpHex.maxPriorityFeePerGas = `0x${userOp.maxPriorityFeePerGas.toString(16)}`;\n\t\tif (userOp.paymasterAndData)\n\t\t\tpartialOpHex.paymasterAndData = userOp.paymasterAndData;\n\t\tif (userOp.signature) partialOpHex.signature = userOp.signature;\n\n\t\tconst result = await this.call<{\n\t\t\tpreVerificationGas: string;\n\t\t\tverificationGasLimit: string;\n\t\t\tcallGasLimit: string;\n\t\t}>(\"eth_estimateUserOperationGas\", [partialOpHex, this.entryPointAddress]);\n\n\t\treturn {\n\t\t\tpreVerificationGas: BigInt(result.preVerificationGas),\n\t\t\tverificationGasLimit: BigInt(result.verificationGasLimit),\n\t\t\tcallGasLimit: BigInt(result.callGasLimit),\n\t\t};\n\t}\n\n\tasync getUserOperationByHash(\n\t\thash: string,\n\t): Promise<UserOperationReceipt | null> {\n\t\ttry {\n\t\t\treturn await this.call<UserOperationReceipt | null>(\n\t\t\t\t\"eth_getUserOperationByHash\",\n\t\t\t\t[hash],\n\t\t\t);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tasync getUserOperationReceipt(\n\t\thash: string,\n\t): Promise<UserOperationReceipt | null> {\n\t\ttry {\n\t\t\treturn await this.call<UserOperationReceipt | null>(\n\t\t\t\t\"eth_getUserOperationReceipt\",\n\t\t\t\t[hash],\n\t\t\t);\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tasync getSupportedEntryPoints(): Promise<string[]> {\n\t\treturn this.call<string[]>(\"eth_supportedEntryPoints\", []);\n\t}\n\n\tasync getChainId(): Promise<number> {\n\t\tconst result = await this.call<string>(\"eth_chainId\", []);\n\t\treturn Number.parseInt(result, 16);\n\t}\n\n\tasync waitForUserOperationReceipt(\n\t\thash: string,\n\t\ttimeout = 60000,\n\t\tinterval = 2000,\n\t): Promise<UserOperationReceipt> {\n\t\tconst startTime = Date.now();\n\n\t\twhile (Date.now() - startTime < timeout) {\n\t\t\tconst receipt = await this.getUserOperationReceipt(hash);\n\t\t\tif (receipt) {\n\t\t\t\treturn receipt;\n\t\t\t}\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, interval));\n\t\t}\n\n\t\tthrow new Error(`UserOperation ${hash} not confirmed within timeout`);\n\t}\n\n\tprivate async call<T>(method: string, params: unknown[]): Promise<T> {\n\t\tconst response = await fetch(this.bundlerUrl, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\tid: ++this.requestId,\n\t\t\t\tmethod,\n\t\t\t\tparams,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Bundler request failed: ${response.status}`);\n\t\t}\n\n\t\tconst data: JsonRpcResponse<T> = await response.json();\n\n\t\tif (data.error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Bundler error: ${data.error.message} (code: ${data.error.code})`,\n\t\t\t);\n\t\t}\n\n\t\treturn data.result as T;\n\t}\n}\n\nexport function createBundlerClient(\n\tconfig: BundlerClientConfig,\n): BundlerClient {\n\treturn new BundlerClient(config);\n}\n","import type {\n\tPaymasterContext,\n\tPaymasterResult,\n\tUserOperation,\n\tUserOperationHex,\n} from \"./types\";\nimport { userOpToHex } from \"./types\";\n\nexport interface PaymasterClientConfig {\n\tpaymasterUrl: string;\n\tentryPointAddress: string;\n\tchainId: number;\n}\n\ninterface JsonRpcResponse<T> {\n\tjsonrpc: string;\n\tid: number;\n\tresult?: T;\n\terror?: {\n\t\tcode: number;\n\t\tmessage: string;\n\t\tdata?: unknown;\n\t};\n}\n\ninterface SponsorUserOperationResult {\n\tpaymasterAndData: string;\n\tpreVerificationGas?: string;\n\tverificationGasLimit?: string;\n\tcallGasLimit?: string;\n}\n\nexport class PaymasterClient {\n\tprivate paymasterUrl: string;\n\tprivate entryPointAddress: string;\n\tprivate chainId: number;\n\tprivate requestId = 0;\n\n\tconstructor(config: PaymasterClientConfig) {\n\t\tthis.paymasterUrl = config.paymasterUrl;\n\t\tthis.entryPointAddress = config.entryPointAddress;\n\t\tthis.chainId = config.chainId;\n\t}\n\n\tasync getPaymasterData(\n\t\tuserOp: Partial<UserOperation>,\n\t\tcontext?: PaymasterContext,\n\t): Promise<PaymasterResult> {\n\t\tconst partialOpHex = this.partialUserOpToHex(userOp);\n\n\t\tconst result = await this.call<SponsorUserOperationResult>(\n\t\t\t\"pm_sponsorUserOperation\",\n\t\t\t[partialOpHex, this.entryPointAddress, context ?? {}],\n\t\t);\n\n\t\treturn {\n\t\t\tpaymasterAndData: result.paymasterAndData,\n\t\t\tpreVerificationGas: result.preVerificationGas\n\t\t\t\t? BigInt(result.preVerificationGas)\n\t\t\t\t: undefined,\n\t\t\tverificationGasLimit: result.verificationGasLimit\n\t\t\t\t? BigInt(result.verificationGasLimit)\n\t\t\t\t: undefined,\n\t\t\tcallGasLimit: result.callGasLimit\n\t\t\t\t? BigInt(result.callGasLimit)\n\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\tasync validatePaymasterUserOp(\n\t\tuserOp: UserOperation,\n\t): Promise<{ valid: boolean; validAfter?: bigint; validUntil?: bigint }> {\n\t\tconst userOpHex = userOpToHex(userOp);\n\n\t\ttry {\n\t\t\tconst result = await this.call<{\n\t\t\t\tvalid: boolean;\n\t\t\t\tvalidAfter?: string;\n\t\t\t\tvalidUntil?: string;\n\t\t\t}>(\"pm_validatePaymasterUserOp\", [userOpHex, this.entryPointAddress]);\n\n\t\t\treturn {\n\t\t\t\tvalid: result.valid,\n\t\t\t\tvalidAfter: result.validAfter ? BigInt(result.validAfter) : undefined,\n\t\t\t\tvalidUntil: result.validUntil ? BigInt(result.validUntil) : undefined,\n\t\t\t};\n\t\t} catch {\n\t\t\treturn { valid: false };\n\t\t}\n\t}\n\n\tasync getSupportedTokens(): Promise<\n\t\tArray<{ address: string; symbol: string; decimals: number }>\n\t> {\n\t\ttry {\n\t\t\treturn await this.call<\n\t\t\t\tArray<{ address: string; symbol: string; decimals: number }>\n\t\t\t>(\"pm_supportedTokens\", [this.chainId.toString()]);\n\t\t} catch {\n\t\t\treturn [];\n\t\t}\n\t}\n\n\tasync getTokenPaymasterData(\n\t\tuserOp: Partial<UserOperation>,\n\t\ttokenAddress: string,\n\t): Promise<PaymasterResult> {\n\t\treturn this.getPaymasterData(userOp, {\n\t\t\tmode: \"erc20\",\n\t\t\ttoken: tokenAddress,\n\t\t});\n\t}\n\n\tprivate partialUserOpToHex(\n\t\tuserOp: Partial<UserOperation>,\n\t): Partial<UserOperationHex> {\n\t\tconst result: Partial<UserOperationHex> = {};\n\n\t\tif (userOp.sender) result.sender = userOp.sender;\n\t\tif (userOp.nonce !== undefined)\n\t\t\tresult.nonce = `0x${userOp.nonce.toString(16)}`;\n\t\tif (userOp.initCode) result.initCode = userOp.initCode;\n\t\tif (userOp.callData) result.callData = userOp.callData;\n\t\tif (userOp.callGasLimit !== undefined)\n\t\t\tresult.callGasLimit = `0x${userOp.callGasLimit.toString(16)}`;\n\t\tif (userOp.verificationGasLimit !== undefined)\n\t\t\tresult.verificationGasLimit = `0x${userOp.verificationGasLimit.toString(16)}`;\n\t\tif (userOp.preVerificationGas !== undefined)\n\t\t\tresult.preVerificationGas = `0x${userOp.preVerificationGas.toString(16)}`;\n\t\tif (userOp.maxFeePerGas !== undefined)\n\t\t\tresult.maxFeePerGas = `0x${userOp.maxFeePerGas.toString(16)}`;\n\t\tif (userOp.maxPriorityFeePerGas !== undefined)\n\t\t\tresult.maxPriorityFeePerGas = `0x${userOp.maxPriorityFeePerGas.toString(16)}`;\n\t\tif (userOp.paymasterAndData)\n\t\t\tresult.paymasterAndData = userOp.paymasterAndData;\n\t\tif (userOp.signature) result.signature = userOp.signature;\n\n\t\treturn result;\n\t}\n\n\tprivate async call<T>(method: string, params: unknown[]): Promise<T> {\n\t\tconst response = await fetch(this.paymasterUrl, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\t\tbody: JSON.stringify({\n\t\t\t\tjsonrpc: \"2.0\",\n\t\t\t\tid: ++this.requestId,\n\t\t\t\tmethod,\n\t\t\t\tparams,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new Error(`Paymaster request failed: ${response.status}`);\n\t\t}\n\n\t\tconst data: JsonRpcResponse<T> = await response.json();\n\n\t\tif (data.error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Paymaster error: ${data.error.message} (code: ${data.error.code})`,\n\t\t\t);\n\t\t}\n\n\t\treturn data.result as T;\n\t}\n}\n\nexport function createPaymasterClient(\n\tconfig: PaymasterClientConfig,\n): PaymasterClient {\n\treturn new PaymasterClient(config);\n}\n","import { keccak_256 } from \"@noble/hashes/sha3\";\nimport { bytesToHex, hexToBytes } from \"@noble/hashes/utils\";\nimport type { RpcConnection } from \"../chains/chain-manager\";\nimport { BundlerClient } from \"./bundler-client\";\nimport { PaymasterClient } from \"./paymaster-client\";\nimport type { GasEstimate, UserOperation } from \"./types\";\nimport type { PaymasterContext } from \"./types\";\n\nexport interface SimpleAccountConfig {\n\townerAddress: string;\n\tfactoryAddress: string;\n\tentryPointAddress: string;\n\tbundlerUrl: string;\n\tpaymasterUrl?: string;\n\tchainId: number;\n\tsalt?: bigint;\n\trpcConnection: RpcConnection;\n}\n\nexport interface TransactionRequest {\n\tto: string;\n\tvalue?: bigint;\n\tdata?: string;\n}\n\nconst EXECUTE_SELECTOR = \"b61d27f6\";\nconst EXECUTE_BATCH_SELECTOR = \"18dfb3c7\";\nconst CREATE_ACCOUNT_SELECTOR = \"5fbfb9cf\";\nconst GET_ADDRESS_SELECTOR = \"8cb84e18\";\n\nexport class SimpleAccount {\n\tprivate ownerAddress: string;\n\tprivate factoryAddress: string;\n\tprivate entryPointAddress: string;\n\tprivate salt: bigint;\n\tprivate bundlerClient: BundlerClient;\n\tprivate paymasterClient: PaymasterClient | null;\n\tprivate chainId: number;\n\tprivate rpcConnection: RpcConnection;\n\n\tprivate _accountAddress: string | null = null;\n\tprivate _isDeployed: boolean | null = null;\n\tprivate _cachedNonce: bigint | null = null;\n\n\tconstructor(config: SimpleAccountConfig) {\n\t\tthis.ownerAddress = config.ownerAddress.toLowerCase();\n\t\tthis.factoryAddress = config.factoryAddress.toLowerCase();\n\t\tthis.entryPointAddress = config.entryPointAddress.toLowerCase();\n\t\tthis.salt = config.salt ?? 0n;\n\t\tthis.chainId = config.chainId;\n\t\tthis.rpcConnection = config.rpcConnection;\n\n\t\tthis.bundlerClient = new BundlerClient({\n\t\t\tbundlerUrl: config.bundlerUrl,\n\t\t\tentryPointAddress: config.entryPointAddress,\n\t\t\tchainId: config.chainId,\n\t\t});\n\n\t\tthis.paymasterClient = config.paymasterUrl\n\t\t\t? new PaymasterClient({\n\t\t\t\t\tpaymasterUrl: config.paymasterUrl,\n\t\t\t\t\tentryPointAddress: config.entryPointAddress,\n\t\t\t\t\tchainId: config.chainId,\n\t\t\t\t})\n\t\t\t: null;\n\t}\n\n\t/**\n\t * @deprecated Use getAccountAddress() instead. This sync getter is removed\n\t * because address derivation now requires an RPC call to the factory.\n\t */\n\tget accountAddress(): string {\n\t\tif (this._accountAddress) {\n\t\t\treturn this._accountAddress;\n\t\t}\n\t\tthrow new Error(\n\t\t\t\"SimpleAccount.accountAddress is deprecated. \" +\n\t\t\t\t\"Use 'await account.getAccountAddress()' instead. \" +\n\t\t\t\t\"Address derivation now requires an RPC call to factory.getAddress().\",\n\t\t);\n\t}\n\n\tasync getAccountAddress(): Promise<string> {\n\t\tif (this._accountAddress) {\n\t\t\treturn this._accountAddress;\n\t\t}\n\n\t\tthis._accountAddress = await this.fetchAccountAddressFromFactory();\n\t\treturn this._accountAddress;\n\t}\n\n\tasync isDeployed(): Promise<boolean> {\n\t\tif (this._isDeployed !== null) {\n\t\t\treturn this._isDeployed;\n\t\t}\n\n\t\ttry {\n\t\t\tconst code = await this.getAccountCode();\n\t\t\tthis._isDeployed = code !== \"0x\" && code.length > 2;\n\t\t\treturn this._isDeployed;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tinvalidateDeploymentCache(): void {\n\t\tthis._isDeployed = null;\n\t}\n\n\tasync buildUserOperation(\n\t\ttransactions: TransactionRequest | TransactionRequest[],\n\t\toptions?: {\n\t\t\tusePaymaster?: boolean;\n\t\t\tpaymasterContext?: PaymasterContext;\n\t\t},\n\t): Promise<UserOperation> {\n\t\tconst txArray = Array.isArray(transactions) ? transactions : [transactions];\n\t\tconst callData = this.encodeExecute(txArray);\n\n\t\tconst accountAddress = await this.getAccountAddress();\n\t\tconst isDeployed = await this.isDeployed();\n\t\tconst initCode = isDeployed ? \"0x\" : this.getInitCode();\n\n\t\tconst nonce = await this.getNonce();\n\n\t\tlet userOp: UserOperation = {\n\t\t\tsender: accountAddress,\n\t\t\tnonce,\n\t\t\tinitCode,\n\t\t\tcallData,\n\t\t\tcallGasLimit: 0n,\n\t\t\tverificationGasLimit: 0n,\n\t\t\tpreVerificationGas: 0n,\n\t\t\tmaxFeePerGas: 0n,\n\t\t\tmaxPriorityFeePerGas: 0n,\n\t\t\tpaymasterAndData: \"0x\",\n\t\t\tsignature: this.getDummySignature(),\n\t\t};\n\n\t\tconst gasEstimate = await this.estimateGas(userOp);\n\t\tconst feeData = await this.getFeeData();\n\n\t\tuserOp = {\n\t\t\t...userOp,\n\t\t\tcallGasLimit: gasEstimate.callGasLimit,\n\t\t\tverificationGasLimit: gasEstimate.verificationGasLimit,\n\t\t\tpreVerificationGas: gasEstimate.preVerificationGas,\n\t\t\tmaxFeePerGas: feeData.maxFeePerGas,\n\t\t\tmaxPriorityFeePerGas: feeData.maxPriorityFeePerGas,\n\t\t};\n\n\t\tif (options?.usePaymaster && this.paymasterClient) {\n\t\t\tconst paymasterData = await this.paymasterClient.getPaymasterData(\n\t\t\t\tuserOp,\n\t\t\t\toptions.paymasterContext,\n\t\t\t);\n\t\t\tuserOp.paymasterAndData = paymasterData.paymasterAndData;\n\n\t\t\tif (paymasterData.preVerificationGas) {\n\t\t\t\tuserOp.preVerificationGas = paymasterData.preVerificationGas;\n\t\t\t}\n\t\t\tif (paymasterData.verificationGasLimit) {\n\t\t\t\tuserOp.verificationGasLimit = paymasterData.verificationGasLimit;\n\t\t\t}\n\t\t\tif (paymasterData.callGasLimit) {\n\t\t\t\tuserOp.callGasLimit = paymasterData.callGasLimit;\n\t\t\t}\n\t\t}\n\n\t\tuserOp.signature = \"0x\";\n\n\t\treturn userOp;\n\t}\n\n\tcomputeUserOpHash(userOp: UserOperation): string {\n\t\tconst packed = this.packUserOp(userOp);\n\t\tconst userOpHash = keccak_256(packed);\n\n\t\tconst finalHash = keccak_256(\n\t\t\thexToBytes(\n\t\t\t\tbytesToHex(userOpHash) +\n\t\t\t\t\tthis.entryPointAddress.slice(2).padStart(64, \"0\") +\n\t\t\t\t\tthis.chainId.toString(16).padStart(64, \"0\"),\n\t\t\t),\n\t\t);\n\n\t\treturn `0x${bytesToHex(finalHash)}`;\n\t}\n\n\tasync sendUserOperation(\n\t\tuserOp: UserOperation,\n\t): Promise<{ userOpHash: string; wait: () => Promise<void> }> {\n\t\tconst userOpHash = await this.bundlerClient.sendUserOperation(userOp);\n\n\t\treturn {\n\t\t\tuserOpHash,\n\t\t\twait: async () => {\n\t\t\t\tawait this.bundlerClient.waitForUserOperationReceipt(userOpHash);\n\t\t\t\tthis._isDeployed = true;\n\t\t\t\tthis.invalidateNonceCache();\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async fetchAccountAddressFromFactory(): Promise<string> {\n\t\tconst ownerPadded = this.ownerAddress.slice(2).padStart(64, \"0\");\n\t\tconst saltPadded = this.salt.toString(16).padStart(64, \"0\");\n\n\t\tconst result = await this.rpcConnection.call<string>(\"eth_call\", [\n\t\t\t{\n\t\t\t\tto: this.factoryAddress,\n\t\t\t\tdata: `0x${GET_ADDRESS_SELECTOR}${ownerPadded}${saltPadded}`,\n\t\t\t},\n\t\t\t\"latest\",\n\t\t]);\n\n\t\treturn `0x${result.slice(-40)}`;\n\t}\n\n\tprivate getInitCode(): string {\n\t\tconst ownerPadded = this.ownerAddress.slice(2).padStart(64, \"0\");\n\t\tconst saltPadded = this.salt.toString(16).padStart(64, \"0\");\n\n\t\treturn (\n\t\t\tthis.factoryAddress + CREATE_ACCOUNT_SELECTOR + ownerPadded + saltPadded\n\t\t);\n\t}\n\n\tprivate encodeExecute(transactions: TransactionRequest[]): string {\n\t\tif (transactions.length === 1) {\n\t\t\tconst tx = transactions[0];\n\t\t\tconst to = tx.to.slice(2).toLowerCase().padStart(64, \"0\");\n\t\t\tconst value = (tx.value ?? 0n).toString(16).padStart(64, \"0\");\n\t\t\tconst dataOffset = \"60\".padStart(64, \"0\");\n\t\t\tconst data = tx.data?.slice(2) ?? \"\";\n\t\t\tconst dataLength = (data.length / 2).toString(16).padStart(64, \"0\");\n\n\t\t\treturn `0x${EXECUTE_SELECTOR}${to}${value}${dataOffset}${dataLength}${data}`;\n\t\t}\n\n\t\tconst n = transactions.length;\n\n\t\tconst destArraySize = 32 + n * 32;\n\t\tconst valueArraySize = 32 + n * 32;\n\n\t\tconst destOffset = 96;\n\t\tconst valueOffset = destOffset + destArraySize;\n\t\tconst funcOffset = valueOffset + valueArraySize;\n\n\t\tlet encoded = EXECUTE_BATCH_SELECTOR;\n\n\t\tencoded += destOffset.toString(16).padStart(64, \"0\");\n\t\tencoded += valueOffset.toString(16).padStart(64, \"0\");\n\t\tencoded += funcOffset.toString(16).padStart(64, \"0\");\n\n\t\tencoded += n.toString(16).padStart(64, \"0\");\n\t\tfor (const tx of transactions) {\n\t\t\tencoded += tx.to.slice(2).toLowerCase().padStart(64, \"0\");\n\t\t}\n\n\t\tencoded += n.toString(16).padStart(64, \"0\");\n\t\tfor (const tx of transactions) {\n\t\t\tencoded += (tx.value ?? 0n).toString(16).padStart(64, \"0\");\n\t\t}\n\n\t\tconst funcDatas: string[] = transactions.map((tx) => {\n\t\t\tconst data = tx.data ?? \"0x\";\n\t\t\treturn data.startsWith(\"0x\") ? data.slice(2) : data;\n\t\t});\n\n\t\tconst funcElementOffsets: number[] = [];\n\t\tlet currentOffset = 32 + n * 32;\n\t\tfor (const funcData of funcDatas) {\n\t\t\tfuncElementOffsets.push(currentOffset);\n\t\t\tconst dataLen = funcData.length / 2;\n\t\t\tconst paddedLen = Math.ceil(dataLen / 32) * 32;\n\t\t\tcurrentOffset += 32 + paddedLen;\n\t\t}\n\n\t\tencoded += n.toString(16).padStart(64, \"0\");\n\t\tfor (const offset of funcElementOffsets) {\n\t\t\tencoded += offset.toString(16).padStart(64, \"0\");\n\t\t}\n\n\t\tfor (const funcData of funcDatas) {\n\t\t\tconst dataLen = funcData.length / 2;\n\t\t\tencoded += dataLen.toString(16).padStart(64, \"0\");\n\t\t\tif (funcData.length > 0) {\n\t\t\t\tconst paddedLen = Math.ceil(dataLen / 32) * 32;\n\t\t\t\tencoded += funcData.padEnd(paddedLen * 2, \"0\");\n\t\t\t}\n\t\t}\n\n\t\treturn `0x${encoded}`;\n\t}\n\n\tprivate packUserOp(userOp: UserOperation): Uint8Array {\n\t\tconst initCodeHash = keccak_256(hexToBytes(userOp.initCode.slice(2) || \"\"));\n\t\tconst callDataHash = keccak_256(hexToBytes(userOp.callData.slice(2) || \"\"));\n\t\tconst paymasterAndDataHash = keccak_256(\n\t\t\thexToBytes(userOp.paymasterAndData.slice(2) || \"\"),\n\t\t);\n\n\t\tconst packed =\n\t\t\tuserOp.sender.slice(2).toLowerCase().padStart(64, \"0\") +\n\t\t\tuserOp.nonce.toString(16).padStart(64, \"0\") +\n\t\t\tbytesToHex(initCodeHash) +\n\t\t\tbytesToHex(callDataHash) +\n\t\t\tuserOp.callGasLimit.toString(16).padStart(64, \"0\") +\n\t\t\tuserOp.verificationGasLimit.toString(16).padStart(64, \"0\") +\n\t\t\tuserOp.preVerificationGas.toString(16).padStart(64, \"0\") +\n\t\t\tuserOp.maxFeePerGas.toString(16).padStart(64, \"0\") +\n\t\t\tuserOp.maxPriorityFeePerGas.toString(16).padStart(64, \"0\") +\n\t\t\tbytesToHex(paymasterAndDataHash);\n\n\t\treturn hexToBytes(packed);\n\t}\n\n\tprivate getDummySignature(): string {\n\t\treturn `0x${\"00\".repeat(65)}`;\n\t}\n\n\tprivate async getNonce(): Promise<bigint> {\n\t\tconst isDeployed = await this.isDeployed();\n\t\tif (!isDeployed) {\n\t\t\treturn 0n;\n\t\t}\n\n\t\tif (this._cachedNonce !== null) {\n\t\t\treturn this._cachedNonce;\n\t\t}\n\n\t\tconst accountAddress = await this.getAccountAddress();\n\t\tconst nonceKey = 0n;\n\t\tconst nonceData = await this.rpcConnection.call<string>(\"eth_call\", [\n\t\t\t{\n\t\t\t\tto: this.entryPointAddress,\n\t\t\t\tdata: `0x35567e1a${accountAddress.slice(2).padStart(64, \"0\")}${nonceKey.toString(16).padStart(64, \"0\")}`,\n\t\t\t},\n\t\t\t\"latest\",\n\t\t]);\n\n\t\tconst nonce = BigInt(nonceData);\n\t\tthis._cachedNonce = nonce;\n\t\treturn nonce;\n\t}\n\n\tinvalidateNonceCache(): void {\n\t\tthis._cachedNonce = null;\n\t}\n\n\tprivate async estimateGas(userOp: UserOperation): Promise<GasEstimate> {\n\t\ttry {\n\t\t\treturn await this.bundlerClient.estimateUserOperationGas(userOp);\n\t\t} catch {\n\t\t\tconst isDeployed = await this.isDeployed();\n\t\t\treturn {\n\t\t\t\tpreVerificationGas: 50000n,\n\t\t\t\tverificationGasLimit: isDeployed ? 100000n : 400000n,\n\t\t\t\tcallGasLimit: 200000n,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate async getFeeData(): Promise<{\n\t\tmaxFeePerGas: bigint;\n\t\tmaxPriorityFeePerGas: bigint;\n\t}> {\n\t\ttry {\n\t\t\tconst gasPrice = await this.rpcConnection.getGasPrice();\n\t\t\treturn {\n\t\t\t\tmaxFeePerGas: gasPrice * 2n,\n\t\t\t\tmaxPriorityFeePerGas: gasPrice / 10n,\n\t\t\t};\n\t\t} catch {\n\t\t\treturn {\n\t\t\t\tmaxFeePerGas: 1000000000n,\n\t\t\t\tmaxPriorityFeePerGas: 1000000000n,\n\t\t\t};\n\t\t}\n\t}\n\n\tprivate async getAccountCode(): Promise<string> {\n\t\tconst accountAddress = await this.getAccountAddress();\n\t\treturn this.rpcConnection.getCode(accountAddress);\n\t}\n}\n\nexport function createSimpleAccount(\n\tconfig: SimpleAccountConfig,\n): SimpleAccount {\n\treturn new SimpleAccount(config);\n}\n"]}
|