Skip to content

Commit 6821434

Browse files
committed
Shuffle redelegation actions:
- add Action suffix to action names - remove redelegatePermissionContextActions function - add redelegation actions to erc7710WalletActions
1 parent 1ab7749 commit 6821434

3 files changed

Lines changed: 167 additions & 112 deletions

File tree

packages/smart-accounts-kit/src/actions/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import type {
1616
MetaMaskExtensionClient,
1717
RequestExecutionPermissionsParameters,
1818
} from './erc7715RequestExecutionPermissionsAction';
19+
import {
20+
redelegatePermissionContextAction,
21+
redelegatePermissionContextOpenAction,
22+
type RedelegatePermissionContextOpenParameters,
23+
type RedelegatePermissionContextParameters,
24+
} from './redelegatePermissionContext';
1925

2026
export {
2127
// Individual action functions
@@ -52,9 +58,8 @@ export {
5258

5359
// Redelegation actions
5460
export {
55-
redelegatePermissionContext,
56-
redelegatePermissionContextOpen,
57-
redelegatePermissionContextActions,
61+
redelegatePermissionContextAction,
62+
redelegatePermissionContextOpenAction,
5863
type RedelegatePermissionContextParameters,
5964
type RedelegatePermissionContextOpenParameters,
6065
type RedelegatePermissionContextReturnType,
@@ -116,7 +121,7 @@ export const erc7715ProviderActions = () => (client: Client) => ({
116121
});
117122

118123
/**
119-
* Type for a viem Client extended with ERC-7715 provider actions.
124+
* Type for a viem Client extended with ERC-7710 provider actions.
120125
* Use this to type variables that will be assigned an extended client later.
121126
*
122127
* @example
@@ -138,6 +143,12 @@ export const erc7710WalletActions = () => (client: WalletClient) => ({
138143
sendTransactionWithDelegation: async (
139144
args: SendTransactionWithDelegationParameters,
140145
) => sendTransactionWithDelegationAction(client, args),
146+
redelegatePermissionContext: async (
147+
parameters: RedelegatePermissionContextParameters,
148+
) => redelegatePermissionContextAction(client, parameters),
149+
redelegatePermissionContextOpen: async (
150+
parameters: RedelegatePermissionContextOpenParameters,
151+
) => redelegatePermissionContextOpenAction(client, parameters),
141152
});
142153

143154
export const erc7710BundlerActions = () => (client: Client) => ({

packages/smart-accounts-kit/src/actions/redelegatePermissionContext.ts

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type BaseRedelegatePermissionContextParameters = {
3434
environment: SmartAccountsEnvironment;
3535
/** The permission context to redelegate from (i.e., from ERC-7715 response) */
3636
permissionContext: PermissionContext;
37-
/** The chain ID for the signature */
38-
chainId: number;
37+
/** The chain ID for the signature (falls back to `client.chain.id`) */
38+
chainId?: number;
3939
/** Optional scope - if not provided, inherits from parent */
4040
scope?: ScopeConfig;
4141
/** Additional caveats to apply to the redelegation */
@@ -181,7 +181,8 @@ function resolveRedelegationArgs<
181181
* 4. Prepends it to the delegation chain
182182
* 5. Returns the encoded permission context
183183
*
184-
* Use {@link redelegatePermissionContextOpen} to create an open redelegation
184+
* Use {@link redelegatePermissionContextOpenAction} to create an open
185+
* redelegation
185186
* (delegate set to `ANY_BENEFICIARY`).
186187
*
187188
* @param client - Wallet client with signing capability.
@@ -190,7 +191,7 @@ function resolveRedelegationArgs<
190191
*
191192
* @example
192193
* ```ts
193-
* const result = await redelegatePermissionContext(walletClient, {
194+
* const result = await redelegatePermissionContextAction(walletClient, {
194195
* environment,
195196
* permissionContext: erc7715Response.context,
196197
* chainId: 11155111,
@@ -208,14 +209,15 @@ function resolveRedelegationArgs<
208209
* });
209210
* ```
210211
*/
211-
export async function redelegatePermissionContext<
212+
export async function redelegatePermissionContextAction<
212213
TChain extends Chain | undefined,
213214
TAccount extends Account | undefined,
214215
>(
215216
client: SigningClient<TChain, TAccount>,
216217
parameters: RedelegatePermissionContextParameters,
217218
): Promise<RedelegatePermissionContextReturnType> {
218-
const { environment, chainId, scope, caveats, salt, to } = parameters;
219+
const { environment, scope, caveats, salt, to } = parameters;
220+
const chainId = resolveChainId(client, parameters.chainId);
219221

220222
const { account, delegations, parentDelegation, from } =
221223
resolveRedelegationArgs(client, parameters);
@@ -250,7 +252,7 @@ export async function redelegatePermissionContext<
250252
* existing permission context and returns both the signed delegation and the
251253
* updated permission context.
252254
*
253-
* Use {@link redelegatePermissionContext} when you want to delegate to a
255+
* Use {@link redelegatePermissionContextAction} when you want to delegate to a
254256
* specific address.
255257
*
256258
* @param client - Wallet client with signing capability.
@@ -259,22 +261,23 @@ export async function redelegatePermissionContext<
259261
*
260262
* @example
261263
* ```ts
262-
* const result = await redelegatePermissionContextOpen(walletClient, {
264+
* const result = await redelegatePermissionContextOpenAction(walletClient, {
263265
* environment,
264266
* permissionContext: erc7715Response.context,
265267
* chainId: 11155111,
266268
* caveats: [limitedCallsCaveat],
267269
* });
268270
* ```
269271
*/
270-
export async function redelegatePermissionContextOpen<
272+
export async function redelegatePermissionContextOpenAction<
271273
TChain extends Chain | undefined,
272274
TAccount extends Account | undefined,
273275
>(
274276
client: SigningClient<TChain, TAccount>,
275277
parameters: RedelegatePermissionContextOpenParameters,
276278
): Promise<RedelegatePermissionContextReturnType> {
277-
const { environment, chainId, scope, caveats, salt } = parameters;
279+
const { environment, scope, caveats, salt } = parameters;
280+
const chainId = resolveChainId(client, parameters.chainId);
278281

279282
const { account, delegations, parentDelegation, from } =
280283
resolveRedelegationArgs(client, parameters);
@@ -325,61 +328,3 @@ function resolveChainId(
325328
}
326329
return client.chain.id;
327330
}
328-
329-
/**
330-
* Creates redelegation actions that can be used to extend a wallet client.
331-
*
332-
* Adds two actions:
333-
* - `redelegatePermissionContext` for redelegating to a specific delegate.
334-
* - `redelegatePermissionContextOpen` for creating an open redelegation.
335-
*
336-
* @returns A function that can be used with the wallet client `extend` method.
337-
*
338-
* @example
339-
* ```ts
340-
* const walletClient = createWalletClient({
341-
* chain: sepolia,
342-
* transport: http(),
343-
* }).extend(redelegatePermissionContextActions());
344-
*
345-
* // Specific redelegation
346-
* const specific = await walletClient.redelegatePermissionContext({
347-
* environment,
348-
* permissionContext: erc7715Response.context,
349-
* to: charlie.address,
350-
* });
351-
*
352-
* // Open redelegation
353-
* const open = await walletClient.redelegatePermissionContextOpen({
354-
* environment,
355-
* permissionContext: erc7715Response.context,
356-
* });
357-
* ```
358-
*/
359-
export function redelegatePermissionContextActions() {
360-
return <
361-
TChain extends Chain | undefined,
362-
TAccount extends Account | undefined,
363-
>(
364-
client: SigningClient<TChain, TAccount>,
365-
) => ({
366-
redelegatePermissionContext: async (
367-
parameters: Omit<RedelegatePermissionContextParameters, 'chainId'> & {
368-
chainId?: number;
369-
},
370-
) =>
371-
redelegatePermissionContext(client, {
372-
...parameters,
373-
chainId: resolveChainId(client, parameters.chainId),
374-
}),
375-
redelegatePermissionContextOpen: async (
376-
parameters: Omit<RedelegatePermissionContextOpenParameters, 'chainId'> & {
377-
chainId?: number;
378-
},
379-
) =>
380-
redelegatePermissionContextOpen(client, {
381-
...parameters,
382-
chainId: resolveChainId(client, parameters.chainId),
383-
}),
384-
});
385-
}

0 commit comments

Comments
 (0)