1
- import { Transport , Chain , PrepareTransactionRequestReturnType , PublicClient } from 'viem' ;
1
+ import { Transport , Chain , PrepareTransactionRequestReturnType , Client , Account } from 'viem' ;
2
2
3
3
import {
4
4
arbOwnerReadContract ,
@@ -13,7 +13,7 @@ import {
13
13
import { ArbOSVersions } from '../contracts' ;
14
14
15
15
export type ArbOwnerPublicActions <
16
- TArbOsVersion extends ArbOSVersions ,
16
+ TArbOsVersion extends ArbOSVersions = 20 ,
17
17
TChain extends Chain | undefined = Chain | undefined ,
18
18
> = {
19
19
arbOwnerReadContract : < TFunctionName extends ArbOwnerPublicFunctionName < TArbOsVersion > > (
@@ -24,26 +24,58 @@ export type ArbOwnerPublicActions<
24
24
TFunctionName extends ArbOwnerPublicFunctionName < TArbOsVersion > ,
25
25
> (
26
26
args : ArbOwnerPrepareTransactionRequestParameters < TArbOsVersion , TFunctionName > ,
27
- ) => Promise < PrepareTransactionRequestReturnType < TChain > & { chainId : number } > ;
27
+ ) => Promise < PrepareTransactionRequestReturnType < TChain > > ;
28
28
} ;
29
29
30
+ const defaultArbOsVersion = 20 ;
31
+
32
+ // arbOsVersion is passed as a parameter `client.extend(arbOwnerPublicActions({ arbOsVersion: 10 }))`
30
33
export function arbOwnerPublicActions <
31
34
TArbOsVersion extends ArbOSVersions ,
32
35
TTransport extends Transport = Transport ,
33
36
TChain extends Chain | undefined = Chain | undefined ,
34
- > ( { arbOsVersion } : { arbOsVersion : TArbOsVersion } ) {
35
- return (
36
- client : PublicClient < TTransport , TChain > ,
37
- ) : ArbOwnerPublicActions < TArbOsVersion , TChain > => {
38
- return {
39
- arbOwnerReadContract : ( args ) => arbOwnerReadContract ( client , { ...args , arbOsVersion } ) ,
40
-
37
+ TAccount extends Account | undefined = Account | undefined ,
38
+ > ( param : {
39
+ arbOsVersion : TArbOsVersion ;
40
+ } ) : ( client : Client ) => ArbOwnerPublicActions < TArbOsVersion , TChain > ;
41
+ // No parameter are passed `client.extend(arbOwnerPublicActions)`
42
+ export function arbOwnerPublicActions <
43
+ TArbOsVersion extends ArbOSVersions ,
44
+ TTransport extends Transport = Transport ,
45
+ TChain extends Chain | undefined = Chain | undefined ,
46
+ TAccount extends Account | undefined = Account | undefined ,
47
+ > ( param : Client < TTransport , TChain , TAccount > ) : ArbOwnerPublicActions < typeof defaultArbOsVersion , TChain > ;
48
+ export function arbOwnerPublicActions <
49
+ TArbOsVersion extends ArbOSVersions ,
50
+ TTransport extends Transport = Transport ,
51
+ TChain extends Chain | undefined = Chain | undefined ,
52
+ TAccount extends Account | undefined = Account | undefined ,
53
+ > ( paramOrClient : { arbOsVersion : TArbOsVersion } | Client < TTransport , TChain , TAccount > ) {
54
+ if ( 'arbOsVersion' in paramOrClient ) {
55
+ const result : ( client : Client ) => ArbOwnerPublicActions < TArbOsVersion , TChain > = ( client ) => ( {
56
+ arbOwnerReadContract : ( args ) =>
57
+ arbOwnerReadContract ( client , { ...args , arbOsVersion : paramOrClient . arbOsVersion } ) ,
41
58
arbOwnerPrepareTransactionRequest : ( args ) =>
42
59
// @ts -ignore (todo: fix viem type issue)
43
60
arbOwnerPrepareTransactionRequest ( client , {
44
61
...args ,
45
- arbOsVersion,
62
+ arbOsVersion : paramOrClient . arbOsVersion ,
46
63
} ) ,
47
- } ;
64
+ } ) ;
65
+
66
+ return result ;
67
+ }
68
+
69
+ const result : ArbOwnerPublicActions < typeof defaultArbOsVersion , TChain > = {
70
+ arbOwnerReadContract : ( args ) =>
71
+ // @ts -ignore (todo: fix viem type issue)
72
+ arbOwnerReadContract ( paramOrClient , { ...args , arbOsVersion : defaultArbOsVersion } ) ,
73
+ arbOwnerPrepareTransactionRequest : ( args ) =>
74
+ // @ts -ignore (todo: fix viem type issue)
75
+ arbOwnerPrepareTransactionRequest ( paramOrClient , {
76
+ ...args ,
77
+ arbOsVersion : defaultArbOsVersion ,
78
+ } ) ,
48
79
} ;
80
+ return result ;
49
81
}
0 commit comments