diff --git a/aa-sdk/core/src/errors/client.ts b/aa-sdk/core/src/errors/client.ts index ec76004af1..f0d3b4b9e6 100644 --- a/aa-sdk/core/src/errors/client.ts +++ b/aa-sdk/core/src/errors/client.ts @@ -118,20 +118,6 @@ export class InvalidModularAccountV2Mode extends BaseError { } } -/** - * Error class denoting that the deferred action mode used is invalid. - */ -export class InvalidDeferredActionMode extends BaseError { - override name = "InvalidDeferredActionMode"; - - /** - * Initializes a new instance of the error message with a default message indicating that the provided deferred action mode is invalid. - */ - constructor() { - super(`The provided deferred action mode is invalid`); - } -} - /** * Error class denoting that the deferred action nonce used is invalid. */ diff --git a/aa-sdk/core/src/index.ts b/aa-sdk/core/src/index.ts index 14f3c24234..08511784c4 100644 --- a/aa-sdk/core/src/index.ts +++ b/aa-sdk/core/src/index.ts @@ -77,7 +77,6 @@ export { InvalidNonceKeyError, EntityIdOverrideError, InvalidModularAccountV2Mode, - InvalidDeferredActionMode, InvalidDeferredActionNonce, } from "./errors/client.js"; export { diff --git a/account-kit/smart-contracts/src/ma-v2/account/common/modularAccountV2Base.ts b/account-kit/smart-contracts/src/ma-v2/account/common/modularAccountV2Base.ts index b621410982..eced575534 100644 --- a/account-kit/smart-contracts/src/ma-v2/account/common/modularAccountV2Base.ts +++ b/account-kit/smart-contracts/src/ma-v2/account/common/modularAccountV2Base.ts @@ -4,14 +4,13 @@ import { InvalidEntityIdError, InvalidNonceKeyError, InvalidDeferredActionNonce, - InvalidDeferredActionMode, toSmartContractAccount, type AccountOp, type SmartAccountSigner, type SmartContractAccountWithSigner, type ToSmartContractAccountParams, } from "@aa-sdk/core"; -import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js"; +import { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from "../../utils.js"; import { type Hex, type Address, @@ -136,9 +135,9 @@ export async function createMAv2Base< let hasAssociatedExecHooks: boolean = false; if (deferredAction) { - if (deferredAction.slice(2, 4) !== "00") { - throw new InvalidDeferredActionMode(); - } + ({ nonce, deferredActionData, hasAssociatedExecHooks } = + parseDeferredAction(deferredAction)); + // Set these values if the deferred action has not been consumed. We check this with the EP const nextNonceForDeferredAction: bigint = (await entryPointContract.read.getNonce([ @@ -148,10 +147,7 @@ export async function createMAv2Base< // we only add the deferred action in if the nonce has not been consumed if (nonce === nextNonceForDeferredAction) { - nonce = BigInt(`0x${deferredAction.slice(6, 70)}`); useDeferredAction = true; - deferredActionData = `0x${deferredAction.slice(70)}`; - hasAssociatedExecHooks = deferredAction[5] === "1"; } else if (nonce > nextNonceForDeferredAction) { throw new InvalidDeferredActionNonce(); } diff --git a/account-kit/smart-contracts/src/ma-v2/client/client.test.ts b/account-kit/smart-contracts/src/ma-v2/client/client.test.ts index 02f7c75b4e..e31ad17bc2 100644 --- a/account-kit/smart-contracts/src/ma-v2/client/client.test.ts +++ b/account-kit/smart-contracts/src/ma-v2/client/client.test.ts @@ -613,7 +613,7 @@ describe("MA v2 Tests", async () => { // version 00, preExecHooks 00, nonce, deferredActionDigest const fullDeferredAction = concatHex([ - "0x0000", + "0x00", toHex(nonce, { size: 32 }), deferredActionDigest, ]); diff --git a/account-kit/smart-contracts/src/ma-v2/permissionBuilder.ts b/account-kit/smart-contracts/src/ma-v2/permissionBuilder.ts index 082fc30855..68bc0d018a 100644 --- a/account-kit/smart-contracts/src/ma-v2/permissionBuilder.ts +++ b/account-kit/smart-contracts/src/ma-v2/permissionBuilder.ts @@ -369,8 +369,8 @@ export class PermissionBuilder { ).buildPreSignatureDeferredActionDigest({ typedData }); // Encode additional information to build the full pre-signature digest - const fullPreSignatureDeferredActionDigest: `0x${string}` = `0x00${ - this.hasAssociatedExecHooks ? "01" : "00" + const fullPreSignatureDeferredActionDigest: `0x${string}` = `0x0${ + this.hasAssociatedExecHooks ? "1" : "0" }${toHex(this.nonce, { size: 32, }).slice(2)}${preSignatureDigest.slice(2)}`; diff --git a/account-kit/smart-contracts/src/ma-v2/utils.ts b/account-kit/smart-contracts/src/ma-v2/utils.ts index 8db63c71d3..69dd41b72d 100644 --- a/account-kit/smart-contracts/src/ma-v2/utils.ts +++ b/account-kit/smart-contracts/src/ma-v2/utils.ts @@ -263,3 +263,18 @@ export const buildFullNonceKey = ({ (isGlobalValidation ? 1n : 0n) ); }; + +// Parses out the 3 components from a deferred action +export const parseDeferredAction = ( + deferredAction: Hex +): { + nonce: bigint; + deferredActionData: Hex; + hasAssociatedExecHooks: boolean; +} => { + return { + nonce: BigInt(`0x${deferredAction.slice(4, 68)}`), + deferredActionData: `0x${deferredAction.slice(68)}`, + hasAssociatedExecHooks: deferredAction[3] === "1", + }; +}; diff --git a/site/pages/reference/aa-sdk/core/classes/InvalidDeferredActionMode/constructor.mdx b/site/pages/reference/aa-sdk/core/classes/InvalidDeferredActionMode/constructor.mdx deleted file mode 100644 index 83fb5560e7..0000000000 --- a/site/pages/reference/aa-sdk/core/classes/InvalidDeferredActionMode/constructor.mdx +++ /dev/null @@ -1,18 +0,0 @@ ---- -# This file is autogenerated -title: InvalidDeferredActionMode -description: Overview of the InvalidDeferredActionMode method ---- - -# InvalidDeferredActionMode - -Initializes a new instance of the error message with a default message indicating that the provided deferred action mode is invalid. -:::note -`InvalidDeferredActionMode` extends `BaseError`, see the docs for BaseError for all supported methods. -::: - -## Import - -```ts -import { InvalidDeferredActionMode } from "@aa-sdk/core"; -```