-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: extend msca account with account loupe decorators (#302)
* refactor: move required by types to aa-core utils types folder * feat: extend msca account with account loupe decorators * feat: move extend method on account from msca to base account * Update packages/core/src/account/types.ts Co-authored-by: Michael Moldoveanu <[email protected]> * Update packages/core/src/account/types.ts Co-authored-by: Michael Moldoveanu <[email protected]> * Update packages/core/src/account/types.ts Co-authored-by: Michael Moldoveanu <[email protected]> * Update packages/accounts/src/msca/account-loupe/decorator.ts Co-authored-by: Michael Moldoveanu <[email protected]> * fix: fix lint and build --------- Co-authored-by: Michael Moldoveanu <[email protected]>
- Loading branch information
Showing
11 changed files
with
314 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
export const IAccountLoupeAbi = [ | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "bytes4", | ||
name: "selector", | ||
type: "bytes4", | ||
}, | ||
], | ||
name: "getExecutionFunctionConfig", | ||
outputs: [ | ||
{ | ||
components: [ | ||
{ | ||
internalType: "address", | ||
name: "plugin", | ||
type: "address", | ||
}, | ||
{ | ||
internalType: "FunctionReference", | ||
name: "userOpValidationFunction", | ||
type: "bytes21", | ||
}, | ||
{ | ||
internalType: "FunctionReference", | ||
name: "runtimeValidationFunction", | ||
type: "bytes21", | ||
}, | ||
], | ||
internalType: "struct IAccountLoupe.ExecutionFunctionConfig", | ||
name: "", | ||
type: "tuple", | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "bytes4", | ||
name: "selector", | ||
type: "bytes4", | ||
}, | ||
], | ||
name: "getExecutionHooks", | ||
outputs: [ | ||
{ | ||
components: [ | ||
{ | ||
internalType: "FunctionReference", | ||
name: "preExecHook", | ||
type: "bytes21", | ||
}, | ||
{ | ||
internalType: "FunctionReference", | ||
name: "postExecHook", | ||
type: "bytes21", | ||
}, | ||
], | ||
internalType: "struct IAccountLoupe.ExecutionHooks[]", | ||
name: "", | ||
type: "tuple[]", | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [], | ||
name: "getInstalledPlugins", | ||
outputs: [ | ||
{ | ||
internalType: "address[]", | ||
name: "", | ||
type: "address[]", | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "address", | ||
name: "callingPlugin", | ||
type: "address", | ||
}, | ||
{ | ||
internalType: "bytes4", | ||
name: "selector", | ||
type: "bytes4", | ||
}, | ||
], | ||
name: "getPermittedCallHooks", | ||
outputs: [ | ||
{ | ||
components: [ | ||
{ | ||
internalType: "FunctionReference", | ||
name: "preExecHook", | ||
type: "bytes21", | ||
}, | ||
{ | ||
internalType: "FunctionReference", | ||
name: "postExecHook", | ||
type: "bytes21", | ||
}, | ||
], | ||
internalType: "struct IAccountLoupe.ExecutionHooks[]", | ||
name: "", | ||
type: "tuple[]", | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: "bytes4", | ||
name: "selector", | ||
type: "bytes4", | ||
}, | ||
], | ||
name: "getPreValidationHooks", | ||
outputs: [ | ||
{ | ||
internalType: "FunctionReference[]", | ||
name: "preUserOpValidationHooks", | ||
type: "bytes21[]", | ||
}, | ||
{ | ||
internalType: "FunctionReference[]", | ||
name: "preRuntimeValidationHooks", | ||
type: "bytes21[]", | ||
}, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
] as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { Address } from "@alchemy/aa-core"; | ||
import type { Hash } from "viem"; | ||
import { IAccountLoupeAbi } from "../abis/IAccountLoupe.js"; | ||
import type { IMSCA } from "../builder.js"; | ||
import type { FunctionReference, IAccountLoupe } from "./types.js"; | ||
|
||
export const accountLoupeDecorators = ( | ||
account: IMSCA<any, any> | ||
): IAccountLoupe => ({ | ||
getExecutionFunctionConfig: async (selector: FunctionReference) => | ||
account.rpcProvider.readContract({ | ||
address: await account.getAddress(), | ||
abi: IAccountLoupeAbi, | ||
functionName: "getExecutionFunctionConfig", | ||
args: [selector], | ||
}), | ||
|
||
getExecutionHooks: async (selector: FunctionReference) => | ||
account.rpcProvider.readContract({ | ||
address: await account.getAddress(), | ||
abi: IAccountLoupeAbi, | ||
functionName: "getExecutionHooks", | ||
args: [selector], | ||
}), | ||
|
||
getPermittedCallHooks: async (callingPlugin: Address, selector: Hash) => | ||
account.rpcProvider.readContract({ | ||
address: await account.getAddress(), | ||
abi: IAccountLoupeAbi, | ||
functionName: "getPermittedCallHooks", | ||
args: [callingPlugin, selector], | ||
}), | ||
|
||
getPreValidationHooks: async (selector: Hash) => | ||
account.rpcProvider.readContract({ | ||
address: await account.getAddress(), | ||
abi: IAccountLoupeAbi, | ||
functionName: "getPreValidationHooks", | ||
args: [selector], | ||
}), | ||
|
||
getInstalledPlugins: async () => | ||
account.rpcProvider.readContract({ | ||
address: await account.getAddress(), | ||
abi: IAccountLoupeAbi, | ||
functionName: "getInstalledPlugins", | ||
}), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import type { Address, Hash, Hex } from "viem"; | ||
|
||
// Treats the first 20 bytes as an address, and the last byte as a identifier. | ||
export type FunctionReference = Hex; | ||
|
||
export type ExecutionFunctionConfig = { | ||
plugin: Address; | ||
userOpValidationFunction: FunctionReference; | ||
runtimeValidationFunction: FunctionReference; | ||
}; | ||
|
||
export type ExecutionHooks = { | ||
preExecHook: FunctionReference; | ||
postExecHook: FunctionReference; | ||
}; | ||
|
||
export type PreValidationHooks = [ | ||
readonly FunctionReference[], | ||
readonly FunctionReference[] | ||
]; | ||
|
||
export interface IAccountLoupe { | ||
/// @notice Gets the validation functions and plugin address for a selector | ||
/// @dev If the selector is a native function, the plugin address will be the address of the account | ||
/// @param selector The selector to get the configuration for | ||
/// @return The configuration for this selector | ||
getExecutionFunctionConfig( | ||
selector: FunctionReference | ||
): Promise<ExecutionFunctionConfig>; | ||
|
||
/// @notice Gets the pre and post execution hooks for a selector | ||
/// @param selector The selector to get the hooks for | ||
/// @return The pre and post execution hooks for this selector | ||
getExecutionHooks( | ||
selector: FunctionReference | ||
): Promise<ReadonlyArray<ExecutionHooks>>; | ||
|
||
/// @notice Gets the pre and post permitted call hooks applied for a plugin calling this selector | ||
/// @param callingPlugin The plugin that is calling the selector | ||
/// @param selector The selector the plugin is calling | ||
/// @return The pre and post permitted call hooks for this selector | ||
getPermittedCallHooks( | ||
callingPlugin: Address, | ||
selector: Hash | ||
): Promise<ReadonlyArray<ExecutionHooks>>; | ||
|
||
/// @notice Gets the pre user op and runtime validation hooks associated with a selector | ||
/// @param selector The selector to get the hooks for | ||
/// @return preUserOpValidationHooks The pre user op validation hooks for this selector | ||
/// @return preRuntimeValidationHooks The pre runtime validation hooks for this selector | ||
getPreValidationHooks(selector: Hash): Promise<Readonly<PreValidationHooks>>; | ||
|
||
/// @notice Gets an array of all installed plugins | ||
/// @return The addresses of all installed plugins | ||
getInstalledPlugins(): Promise<ReadonlyArray<Address>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.