Skip to content

Commit a29c9f7

Browse files
committed
chore: deleted public client from caveatEnforcerClient
1 parent a22ecb5 commit a29c9f7

2 files changed

Lines changed: 27 additions & 18 deletions

File tree

packages/delegation-toolkit/src/actions/caveatEnforcerClient.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PublicClient } from 'viem';
1+
import type { Client, Transport, Chain, Account } from 'viem';
22

33
import type { DeleGatorEnvironment } from '../types';
44
import {
@@ -10,25 +10,34 @@ import {
1010

1111
/**
1212
* Type for client extended with caveat enforcer actions.
13+
* This extends the base Client type to avoid pollution from PublicClient actions.
1314
*/
14-
export type CaveatEnforcerClient = PublicClient &
15+
export type CaveatEnforcerClient<
16+
TTransport extends Transport = Transport,
17+
TChain extends Chain | undefined = Chain | undefined,
18+
TAccount extends Account | undefined = Account | undefined,
19+
> = Client<TTransport, TChain, TAccount> &
1520
ReturnType<ReturnType<typeof caveatEnforcerActions>>;
1621

1722
/**
1823
* Create a viem client extended with caveat enforcer actions.
1924
*
2025
* @param params - The parameters object.
21-
* @param params.client - The viem public client.
26+
* @param params.client - The viem client (can be any client type).
2227
* @param params.environment - The delegator environment.
2328
* @returns The extended client with caveat enforcer actions.
2429
*/
25-
export function createCaveatEnforcerClient({
30+
export function createCaveatEnforcerClient<
31+
TTransport extends Transport = Transport,
32+
TChain extends Chain | undefined = Chain | undefined,
33+
TAccount extends Account | undefined = Account | undefined,
34+
>({
2635
client,
2736
environment,
2837
}: {
29-
client: PublicClient;
38+
client: Client<TTransport, TChain, TAccount>;
3039
environment: DeleGatorEnvironment;
31-
}): CaveatEnforcerClient {
40+
}): CaveatEnforcerClient<TTransport, TChain, TAccount> {
3241
return client.extend(caveatEnforcerActions({ environment }));
3342
}
3443

packages/delegation-toolkit/src/actions/getCaveatAvailableAmount.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Address, Hex, PublicClient } from 'viem';
1+
import type { Address, Hex, Client } from 'viem';
22

33
import { getDelegationHashOffchain } from '../delegation';
44
import * as ERC20PeriodTransferEnforcer from '../DelegationFramework/ERC20PeriodTransferEnforcer';
@@ -114,13 +114,13 @@ function getEnforcerAddress({
114114
/**
115115
* Get available amount for ERC20 period transfer enforcer.
116116
*
117-
* @param client - The viem public client.
117+
* @param client - The viem client.
118118
* @param environment - The delegator environment.
119119
* @param params - The parameters for the ERC20 period transfer enforcer.
120120
* @returns Promise resolving to the period transfer result.
121121
*/
122122
export async function getErc20PeriodTransferEnforcerAvailableAmount(
123-
client: PublicClient,
123+
client: Client,
124124
environment: DeleGatorEnvironment,
125125
params: CaveatEnforcerParams,
126126
): Promise<PeriodTransferResult> {
@@ -151,13 +151,13 @@ export async function getErc20PeriodTransferEnforcerAvailableAmount(
151151
/**
152152
* Get available amount for ERC20 streaming enforcer.
153153
*
154-
* @param client - The viem public client.
154+
* @param client - The viem client.
155155
* @param environment - The delegator environment.
156156
* @param params - The parameters for the ERC20 streaming enforcer.
157157
* @returns Promise resolving to the streaming result.
158158
*/
159159
export async function getErc20StreamingEnforcerAvailableAmount(
160-
client: PublicClient,
160+
client: Client,
161161
environment: DeleGatorEnvironment,
162162
params: CaveatEnforcerParams,
163163
): Promise<StreamingResult> {
@@ -187,13 +187,13 @@ export async function getErc20StreamingEnforcerAvailableAmount(
187187
/**
188188
* Get available amount for multi-token period enforcer.
189189
*
190-
* @param client - The viem public client.
190+
* @param client - The viem client.
191191
* @param environment - The delegator environment.
192192
* @param params - The parameters for the multi-token period enforcer.
193193
* @returns Promise resolving to the period transfer result.
194194
*/
195195
export async function getMultiTokenPeriodEnforcerAvailableAmount(
196-
client: PublicClient,
196+
client: Client,
197197
environment: DeleGatorEnvironment,
198198
params: CaveatEnforcerParams,
199199
): Promise<PeriodTransferResult> {
@@ -224,13 +224,13 @@ export async function getMultiTokenPeriodEnforcerAvailableAmount(
224224
/**
225225
* Get available amount for native token period transfer enforcer.
226226
*
227-
* @param client - The viem public client.
227+
* @param client - The viem client.
228228
* @param environment - The delegator environment.
229229
* @param params - The parameters for the native token period transfer enforcer.
230230
* @returns Promise resolving to the period transfer result.
231231
*/
232232
export async function getNativeTokenPeriodTransferEnforcerAvailableAmount(
233-
client: PublicClient,
233+
client: Client,
234234
environment: DeleGatorEnvironment,
235235
params: CaveatEnforcerParams,
236236
): Promise<PeriodTransferResult> {
@@ -260,13 +260,13 @@ export async function getNativeTokenPeriodTransferEnforcerAvailableAmount(
260260
/**
261261
* Get available amount for native token streaming enforcer.
262262
*
263-
* @param client - The viem public client.
263+
* @param client - The viem client.
264264
* @param environment - The delegator environment.
265265
* @param params - The parameters for the native token streaming enforcer.
266266
* @returns Promise resolving to the streaming result.
267267
*/
268268
export async function getNativeTokenStreamingEnforcerAvailableAmount(
269-
client: PublicClient,
269+
client: Client,
270270
environment: DeleGatorEnvironment,
271271
params: CaveatEnforcerParams,
272272
): Promise<StreamingResult> {
@@ -302,7 +302,7 @@ export async function getNativeTokenStreamingEnforcerAvailableAmount(
302302
*/
303303
export const caveatEnforcerActions =
304304
({ environment }: { environment: DeleGatorEnvironment }) =>
305-
(client: PublicClient) => ({
305+
(client: Client) => ({
306306
/**
307307
* Get available amount for ERC20 period transfer enforcer.
308308
*

0 commit comments

Comments
 (0)