1
- import {
2
- Address ,
3
- PublicClient ,
4
- WalletClient ,
5
- Chain ,
6
- Hex ,
7
- createPublicClient ,
8
- custom ,
9
- http ,
10
- EIP1193Provider
11
- } from 'viem' ;
1
+ import { Address , PublicClient , WalletClient , Chain , Hex } from 'viem' ;
12
2
import SecureOwnableABIJson from '../../abi/SecureOwnable.abi.json' ;
13
3
import { TransactionOptions , TransactionResult } from './interfaces/base.index' ;
14
4
import { ISecureOwnable } from './interfaces/core.access.index' ;
15
5
import { TxRecord , MetaTransaction , MetaTxParams } from './interfaces/lib.index' ;
16
6
import { ExecutionType } from './types/lib.index' ;
17
7
18
- declare global {
19
- interface Window {
20
- ethereum ?: EIP1193Provider ;
21
- }
22
- }
23
-
24
- export interface SecureOwnableConfig {
25
- walletClient ?: WalletClient ;
26
- publicClient ?: PublicClient ;
27
- contractAddress : Address ;
28
- chain : Chain ;
29
- useWalletAsProvider ?: boolean ;
30
- fallbackRpcUrl ?: string ;
31
- }
32
-
33
8
/**
34
9
* @title SecureOwnable
35
- * @notice TypeScript wrapper for SecureOwnable smart contract with optional wallet-based provider
10
+ * @notice TypeScript wrapper for SecureOwnable smart contract
36
11
*/
37
12
export class SecureOwnable implements ISecureOwnable {
38
- protected publicClient : PublicClient ;
39
- protected walletClient ?: WalletClient ;
40
- protected contractAddress : Address ;
41
- protected chain : Chain ;
42
-
43
- constructor ( config : SecureOwnableConfig ) {
44
- this . contractAddress = config . contractAddress ;
45
- this . chain = config . chain ;
46
- this . walletClient = config . walletClient ;
47
-
48
- // Initialize public client based on configuration
49
- if ( config . publicClient ) {
50
- // Use provided public client
51
- this . publicClient = config . publicClient ;
52
- } else if ( typeof window !== 'undefined' && window . ethereum ) {
53
- // Use window.ethereum if available
54
- this . publicClient = createPublicClient ( {
55
- chain : this . chain ,
56
- transport : custom ( window . ethereum )
57
- } ) ;
58
- } else if ( config . fallbackRpcUrl ) {
59
- // Use fallback RPC URL if provided
60
- this . publicClient = createPublicClient ( {
61
- chain : this . chain ,
62
- transport : http ( config . fallbackRpcUrl )
63
- } ) ;
64
- } else {
65
- throw new Error ( 'Either publicClient must be provided, window.ethereum must be available, or fallbackRpcUrl must be provided' ) ;
66
- }
67
- }
13
+ constructor (
14
+ protected client : PublicClient ,
15
+ protected walletClient : WalletClient | undefined ,
16
+ protected contractAddress : Address ,
17
+ protected chain : Chain
18
+ ) { }
68
19
69
20
// Ownership Management
70
21
async transferOwnershipRequest ( options : TransactionOptions ) : Promise < TransactionResult > {
@@ -80,7 +31,7 @@ export class SecureOwnable implements ISecureOwnable {
80
31
81
32
return {
82
33
hash,
83
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
34
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
84
35
} ;
85
36
}
86
37
@@ -98,7 +49,7 @@ export class SecureOwnable implements ISecureOwnable {
98
49
99
50
return {
100
51
hash,
101
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
52
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
102
53
} ;
103
54
}
104
55
@@ -116,7 +67,7 @@ export class SecureOwnable implements ISecureOwnable {
116
67
117
68
return {
118
69
hash,
119
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
70
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
120
71
} ;
121
72
}
122
73
@@ -134,7 +85,7 @@ export class SecureOwnable implements ISecureOwnable {
134
85
135
86
return {
136
87
hash,
137
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
88
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
138
89
} ;
139
90
}
140
91
@@ -152,7 +103,7 @@ export class SecureOwnable implements ISecureOwnable {
152
103
153
104
return {
154
105
hash,
155
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
106
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
156
107
} ;
157
108
}
158
109
@@ -171,7 +122,7 @@ export class SecureOwnable implements ISecureOwnable {
171
122
172
123
return {
173
124
hash,
174
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
125
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
175
126
} ;
176
127
}
177
128
@@ -194,7 +145,7 @@ export class SecureOwnable implements ISecureOwnable {
194
145
console . log ( 'hash' , hash ) ;
195
146
return {
196
147
hash,
197
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
148
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
198
149
} ;
199
150
}
200
151
@@ -212,7 +163,7 @@ export class SecureOwnable implements ISecureOwnable {
212
163
213
164
return {
214
165
hash,
215
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
166
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
216
167
} ;
217
168
}
218
169
@@ -230,7 +181,7 @@ export class SecureOwnable implements ISecureOwnable {
230
181
231
182
return {
232
183
hash,
233
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
184
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
234
185
} ;
235
186
}
236
187
@@ -248,13 +199,13 @@ export class SecureOwnable implements ISecureOwnable {
248
199
249
200
return {
250
201
hash,
251
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
202
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
252
203
} ;
253
204
}
254
205
255
206
// Recovery Management
256
207
async updateRecoveryExecutionOptions ( newRecoveryAddress : Address ) : Promise < Hex > {
257
- return await this . publicClient . readContract ( {
208
+ return await this . client . readContract ( {
258
209
address : this . contractAddress ,
259
210
abi : SecureOwnableABIJson ,
260
211
functionName : 'updateRecoveryExecutionOptions' ,
@@ -276,13 +227,13 @@ export class SecureOwnable implements ISecureOwnable {
276
227
277
228
return {
278
229
hash,
279
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
230
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
280
231
} ;
281
232
}
282
233
283
234
// TimeLock Management
284
235
async updateTimeLockExecutionOptions ( newTimeLockPeriodInMinutes : bigint ) : Promise < Hex > {
285
- return await this . publicClient . readContract ( {
236
+ return await this . client . readContract ( {
286
237
address : this . contractAddress ,
287
238
abi : SecureOwnableABIJson ,
288
239
functionName : 'updateTimeLockExecutionOptions' ,
@@ -304,7 +255,7 @@ export class SecureOwnable implements ISecureOwnable {
304
255
305
256
return {
306
257
hash,
307
- wait : ( ) => this . publicClient . waitForTransactionReceipt ( { hash } )
258
+ wait : ( ) => this . client . waitForTransactionReceipt ( { hash } )
308
259
} ;
309
260
}
310
261
@@ -316,7 +267,7 @@ export class SecureOwnable implements ISecureOwnable {
316
267
maxGasPrice : bigint ,
317
268
signer : Address
318
269
) : Promise < MetaTxParams > {
319
- return await this . publicClient . readContract ( {
270
+ return await this . client . readContract ( {
320
271
address : this . contractAddress ,
321
272
abi : SecureOwnableABIJson ,
322
273
functionName : 'createMetaTxParams' ,
@@ -334,7 +285,7 @@ export class SecureOwnable implements ISecureOwnable {
334
285
executionOptions : Hex ,
335
286
metaTxParams : MetaTxParams
336
287
) : Promise < MetaTransaction > {
337
- return await this . publicClient . readContract ( {
288
+ return await this . client . readContract ( {
338
289
address : this . contractAddress ,
339
290
abi : SecureOwnableABIJson ,
340
291
functionName : 'generateUnsignedMetaTransactionForNew' ,
@@ -355,7 +306,7 @@ export class SecureOwnable implements ISecureOwnable {
355
306
txId : bigint ,
356
307
metaTxParams : MetaTxParams
357
308
) : Promise < MetaTransaction > {
358
- return await this . publicClient . readContract ( {
309
+ return await this . client . readContract ( {
359
310
address : this . contractAddress ,
360
311
abi : SecureOwnableABIJson ,
361
312
functionName : 'generateUnsignedMetaTransactionForExisting' ,
@@ -365,15 +316,15 @@ export class SecureOwnable implements ISecureOwnable {
365
316
366
317
// Getters
367
318
async getOperationHistory ( ) : Promise < TxRecord [ ] > {
368
- return await this . publicClient . readContract ( {
319
+ return await this . client . readContract ( {
369
320
address : this . contractAddress ,
370
321
abi : SecureOwnableABIJson ,
371
322
functionName : 'getOperationHistory'
372
323
} ) as TxRecord [ ] ;
373
324
}
374
325
375
326
async getOperation ( txId : bigint ) : Promise < TxRecord > {
376
- return await this . publicClient . readContract ( {
327
+ return await this . client . readContract ( {
377
328
address : this . contractAddress ,
378
329
abi : SecureOwnableABIJson ,
379
330
functionName : 'getOperation' ,
@@ -382,47 +333,47 @@ export class SecureOwnable implements ISecureOwnable {
382
333
}
383
334
384
335
async getBroadcaster ( ) : Promise < Address > {
385
- return await this . publicClient . readContract ( {
336
+ return await this . client . readContract ( {
386
337
address : this . contractAddress ,
387
338
abi : SecureOwnableABIJson ,
388
339
functionName : 'getBroadcaster'
389
340
} ) as Address ;
390
341
}
391
342
392
343
async getRecoveryAddress ( ) : Promise < Address > {
393
- return await this . publicClient . readContract ( {
344
+ return await this . client . readContract ( {
394
345
address : this . contractAddress ,
395
346
abi : SecureOwnableABIJson ,
396
347
functionName : 'getRecoveryAddress'
397
348
} ) as Address ;
398
349
}
399
350
400
351
async getTimeLockPeriodInMinutes ( ) : Promise < bigint > {
401
- return await this . publicClient . readContract ( {
352
+ return await this . client . readContract ( {
402
353
address : this . contractAddress ,
403
354
abi : SecureOwnableABIJson ,
404
355
functionName : 'getTimeLockPeriodInMinutes'
405
356
} ) as bigint ;
406
357
}
407
358
408
359
async owner ( ) : Promise < Address > {
409
- return await this . publicClient . readContract ( {
360
+ return await this . client . readContract ( {
410
361
address : this . contractAddress ,
411
362
abi : SecureOwnableABIJson ,
412
363
functionName : 'owner'
413
364
} ) as Address ;
414
365
}
415
366
416
367
async getSupportedOperationTypes ( ) : Promise < Array < { operationType : Hex ; name : string } > > {
417
- return await this . publicClient . readContract ( {
368
+ return await this . client . readContract ( {
418
369
address : this . contractAddress ,
419
370
abi : SecureOwnableABIJson ,
420
371
functionName : 'getSupportedOperationTypes'
421
372
} ) as Array < { operationType : Hex ; name : string } > ;
422
373
}
423
374
424
375
async isOperationTypeSupported ( operationType : Hex ) : Promise < boolean > {
425
- return await this . publicClient . readContract ( {
376
+ return await this . client . readContract ( {
426
377
address : this . contractAddress ,
427
378
abi : SecureOwnableABIJson ,
428
379
functionName : 'isOperationTypeSupported' ,
@@ -431,7 +382,7 @@ export class SecureOwnable implements ISecureOwnable {
431
382
}
432
383
433
384
async supportsInterface ( interfaceId : Hex ) : Promise < boolean > {
434
- return await this . publicClient . readContract ( {
385
+ return await this . client . readContract ( {
435
386
address : this . contractAddress ,
436
387
abi : SecureOwnableABIJson ,
437
388
functionName : 'supportsInterface' ,
0 commit comments