1- import { Transport , Chain , PrepareTransactionRequestReturnType , PublicClient } from 'viem' ;
1+ import { Transport , Chain , PrepareTransactionRequestReturnType , Client , Account } from 'viem' ;
22
33import {
44 arbOwnerReadContract ,
@@ -13,7 +13,7 @@ import {
1313import { ArbOSVersions } from '../contracts' ;
1414
1515export type ArbOwnerPublicActions <
16- TArbOsVersion extends ArbOSVersions ,
16+ TArbOsVersion extends ArbOSVersions = 20 ,
1717 TChain extends Chain | undefined = Chain | undefined ,
1818> = {
1919 arbOwnerReadContract : < TFunctionName extends ArbOwnerPublicFunctionName < TArbOsVersion > > (
@@ -24,26 +24,58 @@ export type ArbOwnerPublicActions<
2424 TFunctionName extends ArbOwnerPublicFunctionName < TArbOsVersion > ,
2525 > (
2626 args : ArbOwnerPrepareTransactionRequestParameters < TArbOsVersion , TFunctionName > ,
27- ) => Promise < PrepareTransactionRequestReturnType < TChain > & { chainId : number } > ;
27+ ) => Promise < PrepareTransactionRequestReturnType < TChain > > ;
2828} ;
2929
30+ const defaultArbOsVersion = 20 ;
31+
32+ // arbOsVersion is passed as a parameter `client.extend(arbOwnerPublicActions({ arbOsVersion: 10 }))`
3033export function arbOwnerPublicActions <
3134 TArbOsVersion extends ArbOSVersions ,
3235 TTransport extends Transport = Transport ,
3336 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 } ) ,
4158 arbOwnerPrepareTransactionRequest : ( args ) =>
4259 // @ts -ignore (todo: fix viem type issue)
4360 arbOwnerPrepareTransactionRequest ( client , {
4461 ...args ,
45- arbOsVersion,
62+ arbOsVersion : paramOrClient . arbOsVersion ,
4663 } ) ,
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+ } ) ,
4879 } ;
80+ return result ;
4981}
0 commit comments