Skip to content

Commit a6caae9

Browse files
authored
Merge pull request #50 from MetaMask/cursor/accept-delegation-object-and-move-client-export-9bcd
Improve api for Caveat Enforcer actions and Client
2 parents e2446ec + 8a7843a commit a6caae9

8 files changed

Lines changed: 1515 additions & 691 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { PublicClient } from 'viem';
2+
3+
import type { DeleGatorEnvironment } from '../types';
4+
import {
5+
caveatEnforcerActions,
6+
type CaveatEnforcerParams,
7+
type PeriodTransferResult,
8+
type StreamingResult,
9+
} from './getCaveatAvailableAmount';
10+
11+
/**
12+
* Type for client extended with caveat enforcer actions.
13+
*/
14+
export type CaveatEnforcerClient = PublicClient &
15+
ReturnType<ReturnType<typeof caveatEnforcerActions>>;
16+
17+
/**
18+
* Create a viem client extended with caveat enforcer actions.
19+
*
20+
* @param params - The parameters object.
21+
* @param params.client - The viem public client.
22+
* @param params.environment - The delegator environment.
23+
* @returns The extended client with caveat enforcer actions.
24+
*/
25+
export function createCaveatEnforcerClient({
26+
client,
27+
environment,
28+
}: {
29+
client: PublicClient;
30+
environment: DeleGatorEnvironment;
31+
}): CaveatEnforcerClient {
32+
return client.extend(caveatEnforcerActions({ environment }));
33+
}
34+
35+
// Re-export types for convenience
36+
export type { CaveatEnforcerParams, PeriodTransferResult, StreamingResult };

0 commit comments

Comments
 (0)