66 type Client ,
77 getAddress ,
88 InvalidAddressError ,
9+ type IsUndefined ,
910 isAddress ,
11+ type MaybeRequired ,
1012 type Transport ,
1113} from 'viem' ;
1214import { readContract } from 'viem/actions' ;
@@ -24,9 +26,19 @@ export interface GetLinkedAgwReturnType {
2426 agw : Address | undefined ;
2527}
2628
27- export interface GetLinkedAgwParameters {
28- address ?: Address | undefined ;
29- }
29+ export type GetLinkedAgwParameters <
30+ account extends Account | undefined = Account | undefined ,
31+ > = MaybeRequired < { address ?: Address | undefined } , IsUndefined < account > > ;
32+
33+ export type GetLinkedAgwAction <
34+ account extends Account | undefined = Account | undefined ,
35+ > = IsUndefined < account > extends true
36+ ? (
37+ parameters : GetLinkedAgwParameters < account > ,
38+ ) => Promise < GetLinkedAgwReturnType >
39+ : (
40+ parameters ?: GetLinkedAgwParameters < account > ,
41+ ) => Promise < GetLinkedAgwReturnType > ;
3042
3143export interface IsLinkedAccountParameters {
3244 address : Address ;
@@ -63,18 +75,33 @@ export interface IsLinkedAccountParameters {
6375 * }
6476 * ```
6577 *
66- * @param parameters - Parameters for getting the linked AGW
78+ * @param parameters - Parameters for getting the linked AGW. If the client has a connected account, this can be omitted
6779 * @param parameters.address - The Ethereum Mainnet address to check for a linked AGW. If not provided, defaults to the connected account's address
6880 * @returns Object containing the address of the linked AGW, or undefined if no AGW is linked
6981 */
82+ export async function getLinkedAgw <
83+ chain extends Chain | undefined = Chain | undefined ,
84+ > (
85+ client : Client < Transport , chain , undefined > ,
86+ parameters : GetLinkedAgwParameters < undefined > ,
87+ ) : Promise < GetLinkedAgwReturnType > ;
88+ export async function getLinkedAgw <
89+ chain extends Chain | undefined = Chain | undefined ,
90+ account extends Account = Account ,
91+ > (
92+ client : Client < Transport , chain , account > ,
93+ parameters ?: GetLinkedAgwParameters < account > ,
94+ ) : Promise < GetLinkedAgwReturnType > ;
7095export async function getLinkedAgw <
7196 chain extends Chain | undefined = Chain | undefined ,
7297 account extends Account | undefined = Account | undefined ,
7398> (
7499 client : Client < Transport , chain , account > ,
75- parameters : GetLinkedAgwParameters ,
100+ parameters ? : GetLinkedAgwParameters < account > ,
76101) : Promise < GetLinkedAgwReturnType > {
77- const { address = client . account ?. address } = parameters ;
102+ const { address = client . account ?. address } = ( parameters ?? { } ) as {
103+ address ?: Address | undefined ;
104+ } ;
78105
79106 if ( address === undefined ) {
80107 throw new BaseError ( 'No address provided' ) ;
0 commit comments