@gitmyabi/coval 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.
@@ -0,0 +1,506 @@
1
+ import type { Abi, Address, PublicClient, WalletClient, GetContractReturnType } from 'viem';
2
+ import { getContract } from 'viem';
3
+
4
+ /**
5
+ * AdminUpgradeabilityProxy ABI
6
+ *
7
+ * This ABI is typed using viem's type system for full type safety.
8
+ */
9
+ export const AdminUpgradeabilityProxyAbi = [
10
+ {
11
+ "constant": false,
12
+ "inputs": [
13
+ {
14
+ "name": "newImplementation",
15
+ "type": "address"
16
+ }
17
+ ],
18
+ "name": "upgradeTo",
19
+ "outputs": [],
20
+ "payable": false,
21
+ "stateMutability": "nonpayable",
22
+ "type": "function"
23
+ },
24
+ {
25
+ "constant": false,
26
+ "inputs": [
27
+ {
28
+ "name": "newImplementation",
29
+ "type": "address"
30
+ },
31
+ {
32
+ "name": "data",
33
+ "type": "bytes"
34
+ }
35
+ ],
36
+ "name": "upgradeToAndCall",
37
+ "outputs": [],
38
+ "payable": true,
39
+ "stateMutability": "payable",
40
+ "type": "function"
41
+ },
42
+ {
43
+ "constant": false,
44
+ "inputs": [],
45
+ "name": "implementation",
46
+ "outputs": [
47
+ {
48
+ "name": "",
49
+ "type": "address"
50
+ }
51
+ ],
52
+ "payable": false,
53
+ "stateMutability": "nonpayable",
54
+ "type": "function"
55
+ },
56
+ {
57
+ "constant": false,
58
+ "inputs": [
59
+ {
60
+ "name": "newAdmin",
61
+ "type": "address"
62
+ }
63
+ ],
64
+ "name": "changeAdmin",
65
+ "outputs": [],
66
+ "payable": false,
67
+ "stateMutability": "nonpayable",
68
+ "type": "function"
69
+ },
70
+ {
71
+ "constant": false,
72
+ "inputs": [],
73
+ "name": "admin",
74
+ "outputs": [
75
+ {
76
+ "name": "",
77
+ "type": "address"
78
+ }
79
+ ],
80
+ "payable": false,
81
+ "stateMutability": "nonpayable",
82
+ "type": "function"
83
+ },
84
+ {
85
+ "inputs": [
86
+ {
87
+ "name": "_logic",
88
+ "type": "address"
89
+ },
90
+ {
91
+ "name": "_admin",
92
+ "type": "address"
93
+ },
94
+ {
95
+ "name": "_data",
96
+ "type": "bytes"
97
+ }
98
+ ],
99
+ "payable": true,
100
+ "stateMutability": "payable",
101
+ "type": "constructor"
102
+ },
103
+ {
104
+ "payable": true,
105
+ "stateMutability": "payable",
106
+ "type": "fallback"
107
+ },
108
+ {
109
+ "anonymous": false,
110
+ "inputs": [
111
+ {
112
+ "indexed": false,
113
+ "name": "previousAdmin",
114
+ "type": "address"
115
+ },
116
+ {
117
+ "indexed": false,
118
+ "name": "newAdmin",
119
+ "type": "address"
120
+ }
121
+ ],
122
+ "name": "AdminChanged",
123
+ "type": "event"
124
+ },
125
+ {
126
+ "anonymous": false,
127
+ "inputs": [
128
+ {
129
+ "indexed": true,
130
+ "name": "implementation",
131
+ "type": "address"
132
+ }
133
+ ],
134
+ "name": "Upgraded",
135
+ "type": "event"
136
+ }
137
+ ] as const satisfies Abi;
138
+
139
+ /**
140
+ * Type-safe ABI for AdminUpgradeabilityProxy
141
+ */
142
+ export type AdminUpgradeabilityProxyAbi = typeof AdminUpgradeabilityProxyAbi;
143
+
144
+ /**
145
+ * Contract instance type for AdminUpgradeabilityProxy
146
+ */
147
+ // Use any for contract type to avoid complex viem type issues
148
+ // The runtime behavior is type-safe through viem's ABI typing
149
+ export type AdminUpgradeabilityProxyContract = any;
150
+
151
+ /**
152
+ * AdminUpgradeabilityProxy Contract Class
153
+ *
154
+ * Provides a class-based API similar to TypeChain for interacting with the contract.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * import { createPublicClient, createWalletClient, http } from 'viem';
159
+ * import { mainnet } from 'viem/chains';
160
+ * import { AdminUpgradeabilityProxy } from 'AdminUpgradeabilityProxy';
161
+ *
162
+ * const publicClient = createPublicClient({ chain: mainnet, transport: http() });
163
+ * const walletClient = createWalletClient({ chain: mainnet, transport: http() });
164
+ *
165
+ * const contract = new AdminUpgradeabilityProxy('0x...', { publicClient, walletClient });
166
+ *
167
+ * // Read functions
168
+ * const result = await contract.balanceOf('0x...');
169
+ *
170
+ * // Write functions
171
+ * const hash = await contract.transfer('0x...', 1000n);
172
+ *
173
+ * // Simulate transactions (dry-run)
174
+ * const simulation = await contract.simulate.transfer('0x...', 1000n);
175
+ * console.log('Gas estimate:', simulation.request.gas);
176
+ *
177
+ * // Watch events
178
+ * const unwatch = contract.watch.Transfer((event) => {
179
+ * console.log('Transfer event:', event);
180
+ * });
181
+ * ```
182
+ */
183
+ export class AdminUpgradeabilityProxy {
184
+ private contract: AdminUpgradeabilityProxyContract;
185
+ private contractAddress: Address;
186
+ private publicClient: PublicClient;
187
+
188
+ constructor(
189
+ address: Address,
190
+ clients: {
191
+ publicClient: PublicClient;
192
+ walletClient?: WalletClient;
193
+ }
194
+ ) {
195
+ this.contractAddress = address;
196
+ this.publicClient = clients.publicClient;
197
+ this.contract = getContract({
198
+ address,
199
+ abi: AdminUpgradeabilityProxyAbi,
200
+ client: {
201
+ public: clients.publicClient,
202
+ wallet: clients.walletClient,
203
+ },
204
+ });
205
+ }
206
+
207
+ /**
208
+ * Get the contract address
209
+ */
210
+ get address(): Address {
211
+ return this.contractAddress;
212
+ }
213
+
214
+ /**
215
+ * Get the underlying viem contract instance.
216
+ */
217
+ getContract(): AdminUpgradeabilityProxyContract {
218
+ return this.contract;
219
+ }
220
+
221
+ // No read functions
222
+
223
+ /**
224
+ * upgradeTo
225
+ * nonpayable
226
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
227
+ */
228
+ async upgradeTo(newImplementation: `0x${string}`, options?: {
229
+ accessList?: import('viem').AccessList;
230
+ authorizationList?: import('viem').AuthorizationList;
231
+ chain?: import('viem').Chain | null;
232
+ dataSuffix?: `0x${string}`;
233
+ gas?: bigint;
234
+ gasPrice?: bigint;
235
+ maxFeePerGas?: bigint;
236
+ maxPriorityFeePerGas?: bigint;
237
+ nonce?: number;
238
+ value?: bigint;
239
+ }): Promise<`0x${string}`> {
240
+ if (!this.contract.write) {
241
+ throw new Error('Wallet client is required for write operations');
242
+ }
243
+ return this.contract.write.upgradeTo([newImplementation] as const, options) as Promise<`0x${string}`>;
244
+ }
245
+
246
+ /**
247
+ * upgradeToAndCall
248
+ * payable
249
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
250
+ */
251
+ async upgradeToAndCall(newImplementation: `0x${string}`, data: `0x${string}`, options?: {
252
+ accessList?: import('viem').AccessList;
253
+ authorizationList?: import('viem').AuthorizationList;
254
+ chain?: import('viem').Chain | null;
255
+ dataSuffix?: `0x${string}`;
256
+ gas?: bigint;
257
+ gasPrice?: bigint;
258
+ maxFeePerGas?: bigint;
259
+ maxPriorityFeePerGas?: bigint;
260
+ nonce?: number;
261
+ value?: bigint;
262
+ }): Promise<`0x${string}`> {
263
+ if (!this.contract.write) {
264
+ throw new Error('Wallet client is required for write operations');
265
+ }
266
+ return this.contract.write.upgradeToAndCall([newImplementation, data] as const, options) as Promise<`0x${string}`>;
267
+ }
268
+
269
+ /**
270
+ * implementation
271
+ * nonpayable
272
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
273
+ */
274
+ async implementation(options?: {
275
+ accessList?: import('viem').AccessList;
276
+ authorizationList?: import('viem').AuthorizationList;
277
+ chain?: import('viem').Chain | null;
278
+ dataSuffix?: `0x${string}`;
279
+ gas?: bigint;
280
+ gasPrice?: bigint;
281
+ maxFeePerGas?: bigint;
282
+ maxPriorityFeePerGas?: bigint;
283
+ nonce?: number;
284
+ value?: bigint;
285
+ }): Promise<`0x${string}`> {
286
+ if (!this.contract.write) {
287
+ throw new Error('Wallet client is required for write operations');
288
+ }
289
+ return this.contract.write.implementation(options) as Promise<`0x${string}`>;
290
+ }
291
+
292
+ /**
293
+ * changeAdmin
294
+ * nonpayable
295
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
296
+ */
297
+ async changeAdmin(newAdmin: `0x${string}`, options?: {
298
+ accessList?: import('viem').AccessList;
299
+ authorizationList?: import('viem').AuthorizationList;
300
+ chain?: import('viem').Chain | null;
301
+ dataSuffix?: `0x${string}`;
302
+ gas?: bigint;
303
+ gasPrice?: bigint;
304
+ maxFeePerGas?: bigint;
305
+ maxPriorityFeePerGas?: bigint;
306
+ nonce?: number;
307
+ value?: bigint;
308
+ }): Promise<`0x${string}`> {
309
+ if (!this.contract.write) {
310
+ throw new Error('Wallet client is required for write operations');
311
+ }
312
+ return this.contract.write.changeAdmin([newAdmin] as const, options) as Promise<`0x${string}`>;
313
+ }
314
+
315
+ /**
316
+ * admin
317
+ * nonpayable
318
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
319
+ */
320
+ async admin(options?: {
321
+ accessList?: import('viem').AccessList;
322
+ authorizationList?: import('viem').AuthorizationList;
323
+ chain?: import('viem').Chain | null;
324
+ dataSuffix?: `0x${string}`;
325
+ gas?: bigint;
326
+ gasPrice?: bigint;
327
+ maxFeePerGas?: bigint;
328
+ maxPriorityFeePerGas?: bigint;
329
+ nonce?: number;
330
+ value?: bigint;
331
+ }): Promise<`0x${string}`> {
332
+ if (!this.contract.write) {
333
+ throw new Error('Wallet client is required for write operations');
334
+ }
335
+ return this.contract.write.admin(options) as Promise<`0x${string}`>;
336
+ }
337
+
338
+
339
+
340
+ /**
341
+ * Simulate contract write operations (dry-run without sending transaction)
342
+ *
343
+ * @example
344
+ * const result = await contract.simulate.transfer('0x...', 1000n);
345
+ * console.log('Gas estimate:', result.request.gas);
346
+ * console.log('Would succeed:', result.result);
347
+ */
348
+ get simulate() {
349
+ const contract = this.contract;
350
+ if (!contract.simulate) {
351
+ throw new Error('Public client is required for simulation');
352
+ }
353
+ return {
354
+ /**
355
+ * Simulate upgradeTo
356
+ * Returns gas estimate and result without sending transaction
357
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
358
+ */
359
+ async upgradeTo(newImplementation: `0x${string}`, options?: {
360
+ accessList?: import('viem').AccessList;
361
+ authorizationList?: import('viem').AuthorizationList;
362
+ chain?: import('viem').Chain | null;
363
+ dataSuffix?: `0x${string}`;
364
+ gas?: bigint;
365
+ gasPrice?: bigint;
366
+ maxFeePerGas?: bigint;
367
+ maxPriorityFeePerGas?: bigint;
368
+ nonce?: number;
369
+ value?: bigint;
370
+ }): Promise<void> {
371
+ return contract.simulate.upgradeTo([newImplementation] as const, options) as Promise<void>;
372
+ },
373
+ /**
374
+ * Simulate upgradeToAndCall
375
+ * Returns gas estimate and result without sending transaction
376
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
377
+ */
378
+ async upgradeToAndCall(newImplementation: `0x${string}`, data: `0x${string}`, options?: {
379
+ accessList?: import('viem').AccessList;
380
+ authorizationList?: import('viem').AuthorizationList;
381
+ chain?: import('viem').Chain | null;
382
+ dataSuffix?: `0x${string}`;
383
+ gas?: bigint;
384
+ gasPrice?: bigint;
385
+ maxFeePerGas?: bigint;
386
+ maxPriorityFeePerGas?: bigint;
387
+ nonce?: number;
388
+ value?: bigint;
389
+ }): Promise<void> {
390
+ return contract.simulate.upgradeToAndCall([newImplementation, data] as const, options) as Promise<void>;
391
+ },
392
+ /**
393
+ * Simulate implementation
394
+ * Returns gas estimate and result without sending transaction
395
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
396
+ */
397
+ async implementation(options?: {
398
+ accessList?: import('viem').AccessList;
399
+ authorizationList?: import('viem').AuthorizationList;
400
+ chain?: import('viem').Chain | null;
401
+ dataSuffix?: `0x${string}`;
402
+ gas?: bigint;
403
+ gasPrice?: bigint;
404
+ maxFeePerGas?: bigint;
405
+ maxPriorityFeePerGas?: bigint;
406
+ nonce?: number;
407
+ value?: bigint;
408
+ }): Promise<`0x${string}`> {
409
+ return contract.simulate.implementation(options) as Promise<`0x${string}`>;
410
+ },
411
+ /**
412
+ * Simulate changeAdmin
413
+ * Returns gas estimate and result without sending transaction
414
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
415
+ */
416
+ async changeAdmin(newAdmin: `0x${string}`, options?: {
417
+ accessList?: import('viem').AccessList;
418
+ authorizationList?: import('viem').AuthorizationList;
419
+ chain?: import('viem').Chain | null;
420
+ dataSuffix?: `0x${string}`;
421
+ gas?: bigint;
422
+ gasPrice?: bigint;
423
+ maxFeePerGas?: bigint;
424
+ maxPriorityFeePerGas?: bigint;
425
+ nonce?: number;
426
+ value?: bigint;
427
+ }): Promise<void> {
428
+ return contract.simulate.changeAdmin([newAdmin] as const, options) as Promise<void>;
429
+ },
430
+ /**
431
+ * Simulate admin
432
+ * Returns gas estimate and result without sending transaction
433
+ * @param options Optional transaction parameters (value, gas, nonce, etc.)
434
+ */
435
+ async admin(options?: {
436
+ accessList?: import('viem').AccessList;
437
+ authorizationList?: import('viem').AuthorizationList;
438
+ chain?: import('viem').Chain | null;
439
+ dataSuffix?: `0x${string}`;
440
+ gas?: bigint;
441
+ gasPrice?: bigint;
442
+ maxFeePerGas?: bigint;
443
+ maxPriorityFeePerGas?: bigint;
444
+ nonce?: number;
445
+ value?: bigint;
446
+ }): Promise<`0x${string}`> {
447
+ return contract.simulate.admin(options) as Promise<`0x${string}`>;
448
+ }
449
+ };
450
+ }
451
+
452
+ /**
453
+ * Watch contract events
454
+ *
455
+ * @example
456
+ * // Watch all Transfer events
457
+ * const unwatch = contract.watch.Transfer((event) => {
458
+ * console.log('Transfer:', event);
459
+ * });
460
+ *
461
+ * // Stop watching
462
+ * unwatch();
463
+ */
464
+ get watch() {
465
+ return {
466
+ /**
467
+ * Watch AdminChanged events
468
+ * @param callback Function to call when event is emitted
469
+ * @param filter Optional filter for indexed parameters
470
+ * @returns Unwatch function to stop listening
471
+ */
472
+ AdminChanged: (callback: (event: { previousAdmin: `0x${string}`; newAdmin: `0x${string}` }) => void) => {
473
+ return this.publicClient.watchContractEvent({
474
+ address: this.contractAddress,
475
+ abi: AdminUpgradeabilityProxyAbi,
476
+ eventName: 'AdminChanged',
477
+
478
+ onLogs: (logs: any[]) => {
479
+ logs.forEach((log: any) => {
480
+ callback(log.args as any);
481
+ });
482
+ },
483
+ }) as () => void;
484
+ },
485
+ /**
486
+ * Watch Upgraded events
487
+ * @param callback Function to call when event is emitted
488
+ * @param filter Optional filter for indexed parameters
489
+ * @returns Unwatch function to stop listening
490
+ */
491
+ Upgraded: (callback: (event: { implementation: `0x${string}` }) => void, filter?: { implementation?: `0x${string}` | `0x${string}`[] | null }) => {
492
+ return this.publicClient.watchContractEvent({
493
+ address: this.contractAddress,
494
+ abi: AdminUpgradeabilityProxyAbi,
495
+ eventName: 'Upgraded',
496
+ args: filter as any,
497
+ onLogs: (logs: any[]) => {
498
+ logs.forEach((log: any) => {
499
+ callback(log.args as any);
500
+ });
501
+ },
502
+ }) as () => void;
503
+ }
504
+ };
505
+ }
506
+ }