@gitmyabi/statecommitmentchain 0.0.0-stage → 1.0.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/README.md +107 -2
- package/contracts/StateCommitmentChain.d.ts +527 -0
- package/contracts/StateCommitmentChain.js +607 -0
- package/contracts/StateCommitmentChain.ts +709 -0
- package/contracts/index.d.ts +2 -0
- package/contracts/index.js +7 -0
- package/contracts/index.ts +3 -0
- package/index.d.ts +1 -0
- package/index.js +19 -0
- package/package.json +40 -3
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
import type { Abi, Address, PublicClient, WalletClient, GetContractReturnType } from 'viem';
|
|
2
|
+
import { getContract } from 'viem';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Lib.OVMCodec.ChainBatchHeader struct type
|
|
7
|
+
*/
|
|
8
|
+
export type Lib_OVMCodec_ChainBatchHeader = {
|
|
9
|
+
batchIndex: bigint;
|
|
10
|
+
batchRoot: `0x${string}`;
|
|
11
|
+
batchSize: bigint;
|
|
12
|
+
prevTotalElements: bigint;
|
|
13
|
+
extraData: `0x${string}`;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Lib.OVMCodec.ChainInclusionProof struct type
|
|
18
|
+
*/
|
|
19
|
+
export type Lib_OVMCodec_ChainInclusionProof = {
|
|
20
|
+
index: bigint;
|
|
21
|
+
siblings: `0x${string}`[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* StateCommitmentChain ABI
|
|
25
|
+
*
|
|
26
|
+
* This ABI is typed using viem's type system for full type safety.
|
|
27
|
+
*/
|
|
28
|
+
export const StateCommitmentChainAbi = [
|
|
29
|
+
{
|
|
30
|
+
"inputs": [
|
|
31
|
+
{
|
|
32
|
+
"internalType": "address",
|
|
33
|
+
"name": "_libAddressManager",
|
|
34
|
+
"type": "address"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"internalType": "uint256",
|
|
38
|
+
"name": "_fraudProofWindow",
|
|
39
|
+
"type": "uint256"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"internalType": "uint256",
|
|
43
|
+
"name": "_sequencerPublishWindow",
|
|
44
|
+
"type": "uint256"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"stateMutability": "nonpayable",
|
|
48
|
+
"type": "constructor"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"anonymous": false,
|
|
52
|
+
"inputs": [
|
|
53
|
+
{
|
|
54
|
+
"indexed": true,
|
|
55
|
+
"internalType": "uint256",
|
|
56
|
+
"name": "_batchIndex",
|
|
57
|
+
"type": "uint256"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"indexed": false,
|
|
61
|
+
"internalType": "bytes32",
|
|
62
|
+
"name": "_batchRoot",
|
|
63
|
+
"type": "bytes32"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"indexed": false,
|
|
67
|
+
"internalType": "uint256",
|
|
68
|
+
"name": "_batchSize",
|
|
69
|
+
"type": "uint256"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"indexed": false,
|
|
73
|
+
"internalType": "uint256",
|
|
74
|
+
"name": "_prevTotalElements",
|
|
75
|
+
"type": "uint256"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"indexed": false,
|
|
79
|
+
"internalType": "bytes",
|
|
80
|
+
"name": "_extraData",
|
|
81
|
+
"type": "bytes"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"name": "StateBatchAppended",
|
|
85
|
+
"type": "event"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"anonymous": false,
|
|
89
|
+
"inputs": [
|
|
90
|
+
{
|
|
91
|
+
"indexed": true,
|
|
92
|
+
"internalType": "uint256",
|
|
93
|
+
"name": "_batchIndex",
|
|
94
|
+
"type": "uint256"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"indexed": false,
|
|
98
|
+
"internalType": "bytes32",
|
|
99
|
+
"name": "_batchRoot",
|
|
100
|
+
"type": "bytes32"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"name": "StateBatchDeleted",
|
|
104
|
+
"type": "event"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"inputs": [],
|
|
108
|
+
"name": "FRAUD_PROOF_WINDOW",
|
|
109
|
+
"outputs": [
|
|
110
|
+
{
|
|
111
|
+
"internalType": "uint256",
|
|
112
|
+
"name": "",
|
|
113
|
+
"type": "uint256"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"stateMutability": "view",
|
|
117
|
+
"type": "function"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"inputs": [],
|
|
121
|
+
"name": "SEQUENCER_PUBLISH_WINDOW",
|
|
122
|
+
"outputs": [
|
|
123
|
+
{
|
|
124
|
+
"internalType": "uint256",
|
|
125
|
+
"name": "",
|
|
126
|
+
"type": "uint256"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"stateMutability": "view",
|
|
130
|
+
"type": "function"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"inputs": [
|
|
134
|
+
{
|
|
135
|
+
"internalType": "bytes32[]",
|
|
136
|
+
"name": "_batch",
|
|
137
|
+
"type": "bytes32[]"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"internalType": "uint256",
|
|
141
|
+
"name": "_shouldStartAtElement",
|
|
142
|
+
"type": "uint256"
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
"name": "appendStateBatch",
|
|
146
|
+
"outputs": [],
|
|
147
|
+
"stateMutability": "nonpayable",
|
|
148
|
+
"type": "function"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"inputs": [],
|
|
152
|
+
"name": "batches",
|
|
153
|
+
"outputs": [
|
|
154
|
+
{
|
|
155
|
+
"internalType": "contract IChainStorageContainer",
|
|
156
|
+
"name": "",
|
|
157
|
+
"type": "address"
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
"stateMutability": "view",
|
|
161
|
+
"type": "function"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"inputs": [
|
|
165
|
+
{
|
|
166
|
+
"components": [
|
|
167
|
+
{
|
|
168
|
+
"internalType": "uint256",
|
|
169
|
+
"name": "batchIndex",
|
|
170
|
+
"type": "uint256"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"internalType": "bytes32",
|
|
174
|
+
"name": "batchRoot",
|
|
175
|
+
"type": "bytes32"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"internalType": "uint256",
|
|
179
|
+
"name": "batchSize",
|
|
180
|
+
"type": "uint256"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"internalType": "uint256",
|
|
184
|
+
"name": "prevTotalElements",
|
|
185
|
+
"type": "uint256"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"internalType": "bytes",
|
|
189
|
+
"name": "extraData",
|
|
190
|
+
"type": "bytes"
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
"internalType": "struct Lib_OVMCodec.ChainBatchHeader",
|
|
194
|
+
"name": "_batchHeader",
|
|
195
|
+
"type": "tuple"
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
"name": "deleteStateBatch",
|
|
199
|
+
"outputs": [],
|
|
200
|
+
"stateMutability": "nonpayable",
|
|
201
|
+
"type": "function"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"inputs": [],
|
|
205
|
+
"name": "getLastSequencerTimestamp",
|
|
206
|
+
"outputs": [
|
|
207
|
+
{
|
|
208
|
+
"internalType": "uint256",
|
|
209
|
+
"name": "_lastSequencerTimestamp",
|
|
210
|
+
"type": "uint256"
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
"stateMutability": "view",
|
|
214
|
+
"type": "function"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"inputs": [],
|
|
218
|
+
"name": "getTotalBatches",
|
|
219
|
+
"outputs": [
|
|
220
|
+
{
|
|
221
|
+
"internalType": "uint256",
|
|
222
|
+
"name": "_totalBatches",
|
|
223
|
+
"type": "uint256"
|
|
224
|
+
}
|
|
225
|
+
],
|
|
226
|
+
"stateMutability": "view",
|
|
227
|
+
"type": "function"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"inputs": [],
|
|
231
|
+
"name": "getTotalElements",
|
|
232
|
+
"outputs": [
|
|
233
|
+
{
|
|
234
|
+
"internalType": "uint256",
|
|
235
|
+
"name": "_totalElements",
|
|
236
|
+
"type": "uint256"
|
|
237
|
+
}
|
|
238
|
+
],
|
|
239
|
+
"stateMutability": "view",
|
|
240
|
+
"type": "function"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"inputs": [
|
|
244
|
+
{
|
|
245
|
+
"components": [
|
|
246
|
+
{
|
|
247
|
+
"internalType": "uint256",
|
|
248
|
+
"name": "batchIndex",
|
|
249
|
+
"type": "uint256"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"internalType": "bytes32",
|
|
253
|
+
"name": "batchRoot",
|
|
254
|
+
"type": "bytes32"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"internalType": "uint256",
|
|
258
|
+
"name": "batchSize",
|
|
259
|
+
"type": "uint256"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"internalType": "uint256",
|
|
263
|
+
"name": "prevTotalElements",
|
|
264
|
+
"type": "uint256"
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
"internalType": "bytes",
|
|
268
|
+
"name": "extraData",
|
|
269
|
+
"type": "bytes"
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
"internalType": "struct Lib_OVMCodec.ChainBatchHeader",
|
|
273
|
+
"name": "_batchHeader",
|
|
274
|
+
"type": "tuple"
|
|
275
|
+
}
|
|
276
|
+
],
|
|
277
|
+
"name": "insideFraudProofWindow",
|
|
278
|
+
"outputs": [
|
|
279
|
+
{
|
|
280
|
+
"internalType": "bool",
|
|
281
|
+
"name": "_inside",
|
|
282
|
+
"type": "bool"
|
|
283
|
+
}
|
|
284
|
+
],
|
|
285
|
+
"stateMutability": "view",
|
|
286
|
+
"type": "function"
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"inputs": [],
|
|
290
|
+
"name": "libAddressManager",
|
|
291
|
+
"outputs": [
|
|
292
|
+
{
|
|
293
|
+
"internalType": "contract Lib_AddressManager",
|
|
294
|
+
"name": "",
|
|
295
|
+
"type": "address"
|
|
296
|
+
}
|
|
297
|
+
],
|
|
298
|
+
"stateMutability": "view",
|
|
299
|
+
"type": "function"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
"inputs": [
|
|
303
|
+
{
|
|
304
|
+
"internalType": "string",
|
|
305
|
+
"name": "_name",
|
|
306
|
+
"type": "string"
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
"name": "resolve",
|
|
310
|
+
"outputs": [
|
|
311
|
+
{
|
|
312
|
+
"internalType": "address",
|
|
313
|
+
"name": "",
|
|
314
|
+
"type": "address"
|
|
315
|
+
}
|
|
316
|
+
],
|
|
317
|
+
"stateMutability": "view",
|
|
318
|
+
"type": "function"
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
"inputs": [
|
|
322
|
+
{
|
|
323
|
+
"internalType": "bytes32",
|
|
324
|
+
"name": "_element",
|
|
325
|
+
"type": "bytes32"
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
"components": [
|
|
329
|
+
{
|
|
330
|
+
"internalType": "uint256",
|
|
331
|
+
"name": "batchIndex",
|
|
332
|
+
"type": "uint256"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"internalType": "bytes32",
|
|
336
|
+
"name": "batchRoot",
|
|
337
|
+
"type": "bytes32"
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
"internalType": "uint256",
|
|
341
|
+
"name": "batchSize",
|
|
342
|
+
"type": "uint256"
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"internalType": "uint256",
|
|
346
|
+
"name": "prevTotalElements",
|
|
347
|
+
"type": "uint256"
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
"internalType": "bytes",
|
|
351
|
+
"name": "extraData",
|
|
352
|
+
"type": "bytes"
|
|
353
|
+
}
|
|
354
|
+
],
|
|
355
|
+
"internalType": "struct Lib_OVMCodec.ChainBatchHeader",
|
|
356
|
+
"name": "_batchHeader",
|
|
357
|
+
"type": "tuple"
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
"components": [
|
|
361
|
+
{
|
|
362
|
+
"internalType": "uint256",
|
|
363
|
+
"name": "index",
|
|
364
|
+
"type": "uint256"
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
"internalType": "bytes32[]",
|
|
368
|
+
"name": "siblings",
|
|
369
|
+
"type": "bytes32[]"
|
|
370
|
+
}
|
|
371
|
+
],
|
|
372
|
+
"internalType": "struct Lib_OVMCodec.ChainInclusionProof",
|
|
373
|
+
"name": "_proof",
|
|
374
|
+
"type": "tuple"
|
|
375
|
+
}
|
|
376
|
+
],
|
|
377
|
+
"name": "verifyStateCommitment",
|
|
378
|
+
"outputs": [
|
|
379
|
+
{
|
|
380
|
+
"internalType": "bool",
|
|
381
|
+
"name": "",
|
|
382
|
+
"type": "bool"
|
|
383
|
+
}
|
|
384
|
+
],
|
|
385
|
+
"stateMutability": "view",
|
|
386
|
+
"type": "function"
|
|
387
|
+
}
|
|
388
|
+
] as const satisfies Abi;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Type-safe ABI for StateCommitmentChain
|
|
392
|
+
*/
|
|
393
|
+
export type StateCommitmentChainAbi = typeof StateCommitmentChainAbi;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Contract instance type for StateCommitmentChain
|
|
397
|
+
*/
|
|
398
|
+
// Use any for contract type to avoid complex viem type issues
|
|
399
|
+
// The runtime behavior is type-safe through viem's ABI typing
|
|
400
|
+
export type StateCommitmentChainContract = any;
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* StateCommitmentChain Contract Class
|
|
404
|
+
*
|
|
405
|
+
* Provides a class-based API similar to TypeChain for interacting with the contract.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```typescript
|
|
409
|
+
* import { createPublicClient, createWalletClient, http } from 'viem';
|
|
410
|
+
* import { mainnet } from 'viem/chains';
|
|
411
|
+
* import { StateCommitmentChain } from 'StateCommitmentChain';
|
|
412
|
+
*
|
|
413
|
+
* const publicClient = createPublicClient({ chain: mainnet, transport: http() });
|
|
414
|
+
* const walletClient = createWalletClient({ chain: mainnet, transport: http() });
|
|
415
|
+
*
|
|
416
|
+
* const contract = new StateCommitmentChain('0x...', { publicClient, walletClient });
|
|
417
|
+
*
|
|
418
|
+
* // Read functions
|
|
419
|
+
* const result = await contract.balanceOf('0x...');
|
|
420
|
+
*
|
|
421
|
+
* // Write functions
|
|
422
|
+
* const hash = await contract.transfer('0x...', 1000n);
|
|
423
|
+
*
|
|
424
|
+
* // Simulate transactions (dry-run)
|
|
425
|
+
* const simulation = await contract.simulate.transfer('0x...', 1000n);
|
|
426
|
+
* console.log('Gas estimate:', simulation.request.gas);
|
|
427
|
+
*
|
|
428
|
+
* // Watch events
|
|
429
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
430
|
+
* console.log('Transfer event:', event);
|
|
431
|
+
* });
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
export class StateCommitmentChain {
|
|
435
|
+
private contract: StateCommitmentChainContract;
|
|
436
|
+
private contractAddress: Address;
|
|
437
|
+
private publicClient: PublicClient;
|
|
438
|
+
|
|
439
|
+
constructor(
|
|
440
|
+
address: Address,
|
|
441
|
+
clients: {
|
|
442
|
+
publicClient: PublicClient;
|
|
443
|
+
walletClient?: WalletClient;
|
|
444
|
+
}
|
|
445
|
+
) {
|
|
446
|
+
this.contractAddress = address;
|
|
447
|
+
this.publicClient = clients.publicClient;
|
|
448
|
+
this.contract = getContract({
|
|
449
|
+
address,
|
|
450
|
+
abi: StateCommitmentChainAbi,
|
|
451
|
+
client: {
|
|
452
|
+
public: clients.publicClient,
|
|
453
|
+
wallet: clients.walletClient,
|
|
454
|
+
},
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Get the contract address
|
|
460
|
+
*/
|
|
461
|
+
get address(): Address {
|
|
462
|
+
return this.contractAddress;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Get the underlying viem contract instance.
|
|
467
|
+
*/
|
|
468
|
+
getContract(): StateCommitmentChainContract {
|
|
469
|
+
return this.contract;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* FRAUD_PROOF_WINDOW
|
|
474
|
+
* view
|
|
475
|
+
*/
|
|
476
|
+
async FRAUD_PROOF_WINDOW(): Promise<bigint> {
|
|
477
|
+
return this.contract.read.FRAUD_PROOF_WINDOW() as Promise<bigint>;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* SEQUENCER_PUBLISH_WINDOW
|
|
482
|
+
* view
|
|
483
|
+
*/
|
|
484
|
+
async SEQUENCER_PUBLISH_WINDOW(): Promise<bigint> {
|
|
485
|
+
return this.contract.read.SEQUENCER_PUBLISH_WINDOW() as Promise<bigint>;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* batches
|
|
490
|
+
* view
|
|
491
|
+
*/
|
|
492
|
+
async batches(): Promise<`0x${string}`> {
|
|
493
|
+
return this.contract.read.batches() as Promise<`0x${string}`>;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* getLastSequencerTimestamp
|
|
498
|
+
* view
|
|
499
|
+
*/
|
|
500
|
+
async getLastSequencerTimestamp(): Promise<bigint> {
|
|
501
|
+
return this.contract.read.getLastSequencerTimestamp() as Promise<bigint>;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* getTotalBatches
|
|
506
|
+
* view
|
|
507
|
+
*/
|
|
508
|
+
async getTotalBatches(): Promise<bigint> {
|
|
509
|
+
return this.contract.read.getTotalBatches() as Promise<bigint>;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* getTotalElements
|
|
514
|
+
* view
|
|
515
|
+
*/
|
|
516
|
+
async getTotalElements(): Promise<bigint> {
|
|
517
|
+
return this.contract.read.getTotalElements() as Promise<bigint>;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* insideFraudProofWindow
|
|
522
|
+
* view
|
|
523
|
+
*/
|
|
524
|
+
async insideFraudProofWindow(_batchHeader: Lib_OVMCodec_ChainBatchHeader): Promise<boolean> {
|
|
525
|
+
return this.contract.read.insideFraudProofWindow([_batchHeader] as const) as Promise<boolean>;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* libAddressManager
|
|
530
|
+
* view
|
|
531
|
+
*/
|
|
532
|
+
async libAddressManager(): Promise<`0x${string}`> {
|
|
533
|
+
return this.contract.read.libAddressManager() as Promise<`0x${string}`>;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* resolve
|
|
538
|
+
* view
|
|
539
|
+
*/
|
|
540
|
+
async resolve(_name: string): Promise<`0x${string}`> {
|
|
541
|
+
return this.contract.read.resolve([_name] as const) as Promise<`0x${string}`>;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* verifyStateCommitment
|
|
546
|
+
* view
|
|
547
|
+
*/
|
|
548
|
+
async verifyStateCommitment(_element: `0x${string}`, _batchHeader: Lib_OVMCodec_ChainBatchHeader, _proof: Lib_OVMCodec_ChainInclusionProof): Promise<boolean> {
|
|
549
|
+
return this.contract.read.verifyStateCommitment([_element, _batchHeader, _proof] as const) as Promise<boolean>;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* appendStateBatch
|
|
554
|
+
* nonpayable
|
|
555
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
556
|
+
*/
|
|
557
|
+
async appendStateBatch(_batch: `0x${string}`[], _shouldStartAtElement: bigint, options?: {
|
|
558
|
+
accessList?: import('viem').AccessList;
|
|
559
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
560
|
+
chain?: import('viem').Chain | null;
|
|
561
|
+
dataSuffix?: `0x${string}`;
|
|
562
|
+
gas?: bigint;
|
|
563
|
+
gasPrice?: bigint;
|
|
564
|
+
maxFeePerGas?: bigint;
|
|
565
|
+
maxPriorityFeePerGas?: bigint;
|
|
566
|
+
nonce?: number;
|
|
567
|
+
value?: bigint;
|
|
568
|
+
}): Promise<`0x${string}`> {
|
|
569
|
+
if (!this.contract.write) {
|
|
570
|
+
throw new Error('Wallet client is required for write operations');
|
|
571
|
+
}
|
|
572
|
+
return this.contract.write.appendStateBatch([_batch, _shouldStartAtElement] as const, options) as Promise<`0x${string}`>;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* deleteStateBatch
|
|
577
|
+
* nonpayable
|
|
578
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
579
|
+
*/
|
|
580
|
+
async deleteStateBatch(_batchHeader: Lib_OVMCodec_ChainBatchHeader, options?: {
|
|
581
|
+
accessList?: import('viem').AccessList;
|
|
582
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
583
|
+
chain?: import('viem').Chain | null;
|
|
584
|
+
dataSuffix?: `0x${string}`;
|
|
585
|
+
gas?: bigint;
|
|
586
|
+
gasPrice?: bigint;
|
|
587
|
+
maxFeePerGas?: bigint;
|
|
588
|
+
maxPriorityFeePerGas?: bigint;
|
|
589
|
+
nonce?: number;
|
|
590
|
+
value?: bigint;
|
|
591
|
+
}): Promise<`0x${string}`> {
|
|
592
|
+
if (!this.contract.write) {
|
|
593
|
+
throw new Error('Wallet client is required for write operations');
|
|
594
|
+
}
|
|
595
|
+
return this.contract.write.deleteStateBatch([_batchHeader] as const, options) as Promise<`0x${string}`>;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Simulate contract write operations (dry-run without sending transaction)
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* const result = await contract.simulate.transfer('0x...', 1000n);
|
|
605
|
+
* console.log('Gas estimate:', result.request.gas);
|
|
606
|
+
* console.log('Would succeed:', result.result);
|
|
607
|
+
*/
|
|
608
|
+
get simulate() {
|
|
609
|
+
const contract = this.contract;
|
|
610
|
+
if (!contract.simulate) {
|
|
611
|
+
throw new Error('Public client is required for simulation');
|
|
612
|
+
}
|
|
613
|
+
return {
|
|
614
|
+
/**
|
|
615
|
+
* Simulate appendStateBatch
|
|
616
|
+
* Returns gas estimate and result without sending transaction
|
|
617
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
618
|
+
*/
|
|
619
|
+
async appendStateBatch(_batch: `0x${string}`[], _shouldStartAtElement: bigint, options?: {
|
|
620
|
+
accessList?: import('viem').AccessList;
|
|
621
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
622
|
+
chain?: import('viem').Chain | null;
|
|
623
|
+
dataSuffix?: `0x${string}`;
|
|
624
|
+
gas?: bigint;
|
|
625
|
+
gasPrice?: bigint;
|
|
626
|
+
maxFeePerGas?: bigint;
|
|
627
|
+
maxPriorityFeePerGas?: bigint;
|
|
628
|
+
nonce?: number;
|
|
629
|
+
value?: bigint;
|
|
630
|
+
}): Promise<void> {
|
|
631
|
+
return contract.simulate.appendStateBatch([_batch, _shouldStartAtElement] as const, options) as Promise<void>;
|
|
632
|
+
},
|
|
633
|
+
/**
|
|
634
|
+
* Simulate deleteStateBatch
|
|
635
|
+
* Returns gas estimate and result without sending transaction
|
|
636
|
+
* @param options Optional transaction parameters (value, gas, nonce, etc.)
|
|
637
|
+
*/
|
|
638
|
+
async deleteStateBatch(_batchHeader: Lib_OVMCodec_ChainBatchHeader, options?: {
|
|
639
|
+
accessList?: import('viem').AccessList;
|
|
640
|
+
authorizationList?: import('viem').AuthorizationList;
|
|
641
|
+
chain?: import('viem').Chain | null;
|
|
642
|
+
dataSuffix?: `0x${string}`;
|
|
643
|
+
gas?: bigint;
|
|
644
|
+
gasPrice?: bigint;
|
|
645
|
+
maxFeePerGas?: bigint;
|
|
646
|
+
maxPriorityFeePerGas?: bigint;
|
|
647
|
+
nonce?: number;
|
|
648
|
+
value?: bigint;
|
|
649
|
+
}): Promise<void> {
|
|
650
|
+
return contract.simulate.deleteStateBatch([_batchHeader] as const, options) as Promise<void>;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Watch contract events
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* // Watch all Transfer events
|
|
660
|
+
* const unwatch = contract.watch.Transfer((event) => {
|
|
661
|
+
* console.log('Transfer:', event);
|
|
662
|
+
* });
|
|
663
|
+
*
|
|
664
|
+
* // Stop watching
|
|
665
|
+
* unwatch();
|
|
666
|
+
*/
|
|
667
|
+
get watch() {
|
|
668
|
+
return {
|
|
669
|
+
/**
|
|
670
|
+
* Watch StateBatchAppended events
|
|
671
|
+
* @param callback Function to call when event is emitted
|
|
672
|
+
* @param filter Optional filter for indexed parameters
|
|
673
|
+
* @returns Unwatch function to stop listening
|
|
674
|
+
*/
|
|
675
|
+
StateBatchAppended: (callback: (event: { _batchIndex: bigint; _batchRoot: `0x${string}`; _batchSize: bigint; _prevTotalElements: bigint; _extraData: `0x${string}` }) => void, filter?: { _batchIndex?: bigint | bigint[] | null }) => {
|
|
676
|
+
return this.publicClient.watchContractEvent({
|
|
677
|
+
address: this.contractAddress,
|
|
678
|
+
abi: StateCommitmentChainAbi,
|
|
679
|
+
eventName: 'StateBatchAppended',
|
|
680
|
+
args: filter as any,
|
|
681
|
+
onLogs: (logs: any[]) => {
|
|
682
|
+
logs.forEach((log: any) => {
|
|
683
|
+
callback(log.args as any);
|
|
684
|
+
});
|
|
685
|
+
},
|
|
686
|
+
}) as () => void;
|
|
687
|
+
},
|
|
688
|
+
/**
|
|
689
|
+
* Watch StateBatchDeleted events
|
|
690
|
+
* @param callback Function to call when event is emitted
|
|
691
|
+
* @param filter Optional filter for indexed parameters
|
|
692
|
+
* @returns Unwatch function to stop listening
|
|
693
|
+
*/
|
|
694
|
+
StateBatchDeleted: (callback: (event: { _batchIndex: bigint; _batchRoot: `0x${string}` }) => void, filter?: { _batchIndex?: bigint | bigint[] | null }) => {
|
|
695
|
+
return this.publicClient.watchContractEvent({
|
|
696
|
+
address: this.contractAddress,
|
|
697
|
+
abi: StateCommitmentChainAbi,
|
|
698
|
+
eventName: 'StateBatchDeleted',
|
|
699
|
+
args: filter as any,
|
|
700
|
+
onLogs: (logs: any[]) => {
|
|
701
|
+
logs.forEach((log: any) => {
|
|
702
|
+
callback(log.args as any);
|
|
703
|
+
});
|
|
704
|
+
},
|
|
705
|
+
}) as () => void;
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateCommitmentChain = exports.StateCommitmentChainAbi = void 0;
|
|
4
|
+
// Auto-generated exports for all contracts
|
|
5
|
+
var StateCommitmentChain_1 = require("./StateCommitmentChain");
|
|
6
|
+
Object.defineProperty(exports, "StateCommitmentChainAbi", { enumerable: true, get: function () { return StateCommitmentChain_1.StateCommitmentChainAbi; } });
|
|
7
|
+
Object.defineProperty(exports, "StateCommitmentChain", { enumerable: true, get: function () { return StateCommitmentChain_1.StateCommitmentChain; } });
|