@gitmyabi/storage 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.
@@ -0,0 +1,414 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Storage_json = exports.Storage_jsonAbi = void 0;
4
+ const viem_1 = require("viem");
5
+ /**
6
+ * Storage_json ABI
7
+ *
8
+ * This ABI is typed using viem's type system for full type safety.
9
+ */
10
+ exports.Storage_jsonAbi = [
11
+ {
12
+ "inputs": [],
13
+ "name": "InvalidOwner",
14
+ "type": "error"
15
+ },
16
+ {
17
+ "inputs": [],
18
+ "name": "InvalidSessionId",
19
+ "type": "error"
20
+ },
21
+ {
22
+ "inputs": [
23
+ {
24
+ "internalType": "address",
25
+ "name": "validator",
26
+ "type": "address"
27
+ }
28
+ ],
29
+ "name": "InvalidValidator",
30
+ "type": "error"
31
+ },
32
+ {
33
+ "anonymous": false,
34
+ "inputs": [
35
+ {
36
+ "indexed": false,
37
+ "internalType": "uint256",
38
+ "name": "utilisedNonce",
39
+ "type": "uint256"
40
+ }
41
+ ],
42
+ "name": "NonceConsumed",
43
+ "type": "event"
44
+ },
45
+ {
46
+ "anonymous": false,
47
+ "inputs": [
48
+ {
49
+ "indexed": false,
50
+ "internalType": "uint256",
51
+ "name": "id",
52
+ "type": "uint256"
53
+ }
54
+ ],
55
+ "name": "SessionRevoked",
56
+ "type": "event"
57
+ },
58
+ {
59
+ "anonymous": false,
60
+ "inputs": [
61
+ {
62
+ "indexed": false,
63
+ "internalType": "address",
64
+ "name": "validator",
65
+ "type": "address"
66
+ },
67
+ {
68
+ "indexed": false,
69
+ "internalType": "bool",
70
+ "name": "status",
71
+ "type": "bool"
72
+ }
73
+ ],
74
+ "name": "ValidatorStatusUpdated",
75
+ "type": "event"
76
+ },
77
+ {
78
+ "inputs": [],
79
+ "name": "getNonce",
80
+ "outputs": [
81
+ {
82
+ "internalType": "uint256",
83
+ "name": "",
84
+ "type": "uint256"
85
+ }
86
+ ],
87
+ "stateMutability": "view",
88
+ "type": "function"
89
+ },
90
+ {
91
+ "inputs": [],
92
+ "name": "getOwner",
93
+ "outputs": [
94
+ {
95
+ "internalType": "address",
96
+ "name": "",
97
+ "type": "address"
98
+ }
99
+ ],
100
+ "stateMutability": "view",
101
+ "type": "function"
102
+ },
103
+ {
104
+ "inputs": [
105
+ {
106
+ "internalType": "address",
107
+ "name": "validator",
108
+ "type": "address"
109
+ }
110
+ ],
111
+ "name": "readAndUpdateNonce",
112
+ "outputs": [
113
+ {
114
+ "internalType": "uint256",
115
+ "name": "",
116
+ "type": "uint256"
117
+ }
118
+ ],
119
+ "stateMutability": "nonpayable",
120
+ "type": "function"
121
+ },
122
+ {
123
+ "inputs": [
124
+ {
125
+ "internalType": "uint256",
126
+ "name": "id",
127
+ "type": "uint256"
128
+ }
129
+ ],
130
+ "name": "revokeSession",
131
+ "outputs": [],
132
+ "stateMutability": "nonpayable",
133
+ "type": "function"
134
+ },
135
+ {
136
+ "inputs": [
137
+ {
138
+ "internalType": "address",
139
+ "name": "validator",
140
+ "type": "address"
141
+ },
142
+ {
143
+ "internalType": "bool",
144
+ "name": "isValid",
145
+ "type": "bool"
146
+ }
147
+ ],
148
+ "name": "setValidatorStatus",
149
+ "outputs": [],
150
+ "stateMutability": "nonpayable",
151
+ "type": "function"
152
+ },
153
+ {
154
+ "inputs": [
155
+ {
156
+ "internalType": "uint256",
157
+ "name": "id",
158
+ "type": "uint256"
159
+ },
160
+ {
161
+ "internalType": "address",
162
+ "name": "validator",
163
+ "type": "address"
164
+ }
165
+ ],
166
+ "name": "validateSession",
167
+ "outputs": [],
168
+ "stateMutability": "view",
169
+ "type": "function"
170
+ },
171
+ {
172
+ "inputs": [
173
+ {
174
+ "internalType": "address",
175
+ "name": "validator",
176
+ "type": "address"
177
+ }
178
+ ],
179
+ "name": "validateValidator",
180
+ "outputs": [],
181
+ "stateMutability": "view",
182
+ "type": "function"
183
+ }
184
+ ];
185
+ /**
186
+ * Storage_json Contract Class
187
+ *
188
+ * Provides a class-based API similar to TypeChain for interacting with the contract.
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * import { createPublicClient, createWalletClient, http } from 'viem';
193
+ * import { mainnet } from 'viem/chains';
194
+ * import { Storage_json } from 'Storage_json';
195
+ *
196
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
197
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
198
+ *
199
+ * const contract = new Storage_json('0x...', { publicClient, walletClient });
200
+ *
201
+ * // Read functions
202
+ * const result = await contract.balanceOf('0x...');
203
+ *
204
+ * // Write functions
205
+ * const hash = await contract.transfer('0x...', 1000n);
206
+ *
207
+ * // Simulate transactions (dry-run)
208
+ * const simulation = await contract.simulate.transfer('0x...', 1000n);
209
+ * console.log('Gas estimate:', simulation.request.gas);
210
+ *
211
+ * // Watch events
212
+ * const unwatch = contract.watch.Transfer((event) => {
213
+ * console.log('Transfer event:', event);
214
+ * });
215
+ * ```
216
+ */
217
+ class Storage_json {
218
+ constructor(address, clients) {
219
+ this.contractAddress = address;
220
+ this.publicClient = clients.publicClient;
221
+ this.contract = (0, viem_1.getContract)({
222
+ address,
223
+ abi: exports.Storage_jsonAbi,
224
+ client: {
225
+ public: clients.publicClient,
226
+ wallet: clients.walletClient,
227
+ },
228
+ });
229
+ }
230
+ /**
231
+ * Get the contract address
232
+ */
233
+ get address() {
234
+ return this.contractAddress;
235
+ }
236
+ /**
237
+ * Get the underlying viem contract instance
238
+ */
239
+ getContract() {
240
+ return this.contract;
241
+ }
242
+ /**
243
+ * getNonce
244
+ * view
245
+ */
246
+ async getNonce() {
247
+ return this.contract.read.getNonce();
248
+ }
249
+ /**
250
+ * getOwner
251
+ * view
252
+ */
253
+ async getOwner() {
254
+ return this.contract.read.getOwner();
255
+ }
256
+ /**
257
+ * validateSession
258
+ * view
259
+ */
260
+ async validateSession(id, validator) {
261
+ return this.contract.read.validateSession([id, validator]);
262
+ }
263
+ /**
264
+ * validateValidator
265
+ * view
266
+ */
267
+ async validateValidator(validator) {
268
+ return this.contract.read.validateValidator([validator]);
269
+ }
270
+ /**
271
+ * readAndUpdateNonce
272
+ * nonpayable
273
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
274
+ */
275
+ async readAndUpdateNonce(validator, options) {
276
+ if (!this.contract.write) {
277
+ throw new Error('Wallet client is required for write operations');
278
+ }
279
+ return this.contract.write.readAndUpdateNonce([validator], options);
280
+ }
281
+ /**
282
+ * revokeSession
283
+ * nonpayable
284
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
285
+ */
286
+ async revokeSession(id, options) {
287
+ if (!this.contract.write) {
288
+ throw new Error('Wallet client is required for write operations');
289
+ }
290
+ return this.contract.write.revokeSession([id], options);
291
+ }
292
+ /**
293
+ * setValidatorStatus
294
+ * nonpayable
295
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
296
+ */
297
+ async setValidatorStatus(validator, isValid, options) {
298
+ if (!this.contract.write) {
299
+ throw new Error('Wallet client is required for write operations');
300
+ }
301
+ return this.contract.write.setValidatorStatus([validator, isValid], options);
302
+ }
303
+ /**
304
+ * Simulate contract write operations (dry-run without sending transaction)
305
+ *
306
+ * @example
307
+ * const result = await contract.simulate.transfer('0x...', 1000n);
308
+ * console.log('Gas estimate:', result.request.gas);
309
+ * console.log('Would succeed:', result.result);
310
+ */
311
+ get simulate() {
312
+ const contract = this.contract;
313
+ if (!contract.simulate) {
314
+ throw new Error('Public client is required for simulation');
315
+ }
316
+ return {
317
+ /**
318
+ * Simulate readAndUpdateNonce
319
+ * Returns gas estimate and result without sending transaction
320
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
321
+ */
322
+ async readAndUpdateNonce(validator, options) {
323
+ return contract.simulate.readAndUpdateNonce([validator], options);
324
+ },
325
+ /**
326
+ * Simulate revokeSession
327
+ * Returns gas estimate and result without sending transaction
328
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
329
+ */
330
+ async revokeSession(id, options) {
331
+ return contract.simulate.revokeSession([id], options);
332
+ },
333
+ /**
334
+ * Simulate setValidatorStatus
335
+ * Returns gas estimate and result without sending transaction
336
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
337
+ */
338
+ async setValidatorStatus(validator, isValid, options) {
339
+ return contract.simulate.setValidatorStatus([validator, isValid], options);
340
+ }
341
+ };
342
+ }
343
+ /**
344
+ * Watch contract events
345
+ *
346
+ * @example
347
+ * // Watch all Transfer events
348
+ * const unwatch = contract.watch.Transfer((event) => {
349
+ * console.log('Transfer:', event);
350
+ * });
351
+ *
352
+ * // Stop watching
353
+ * unwatch();
354
+ */
355
+ get watch() {
356
+ return {
357
+ /**
358
+ * Watch NonceConsumed events
359
+ * @param callback Function to call when event is emitted
360
+ * @param filter Optional filter for indexed parameters
361
+ * @returns Unwatch function to stop listening
362
+ */
363
+ NonceConsumed: (callback) => {
364
+ return this.publicClient.watchContractEvent({
365
+ address: this.contractAddress,
366
+ abi: exports.Storage_jsonAbi,
367
+ eventName: 'NonceConsumed',
368
+ onLogs: (logs) => {
369
+ logs.forEach((log) => {
370
+ callback(log.args);
371
+ });
372
+ },
373
+ });
374
+ },
375
+ /**
376
+ * Watch SessionRevoked events
377
+ * @param callback Function to call when event is emitted
378
+ * @param filter Optional filter for indexed parameters
379
+ * @returns Unwatch function to stop listening
380
+ */
381
+ SessionRevoked: (callback) => {
382
+ return this.publicClient.watchContractEvent({
383
+ address: this.contractAddress,
384
+ abi: exports.Storage_jsonAbi,
385
+ eventName: 'SessionRevoked',
386
+ onLogs: (logs) => {
387
+ logs.forEach((log) => {
388
+ callback(log.args);
389
+ });
390
+ },
391
+ });
392
+ },
393
+ /**
394
+ * Watch ValidatorStatusUpdated events
395
+ * @param callback Function to call when event is emitted
396
+ * @param filter Optional filter for indexed parameters
397
+ * @returns Unwatch function to stop listening
398
+ */
399
+ ValidatorStatusUpdated: (callback) => {
400
+ return this.publicClient.watchContractEvent({
401
+ address: this.contractAddress,
402
+ abi: exports.Storage_jsonAbi,
403
+ eventName: 'ValidatorStatusUpdated',
404
+ onLogs: (logs) => {
405
+ logs.forEach((log) => {
406
+ callback(log.args);
407
+ });
408
+ },
409
+ });
410
+ }
411
+ };
412
+ }
413
+ }
414
+ exports.Storage_json = Storage_json;