Skip to content

Commit 6efeda1

Browse files
committed
feat: add parsing utility, removing deferred action mode from accounts
1 parent 1e9cc80 commit 6efeda1

File tree

8 files changed

+22
-55
lines changed

8 files changed

+22
-55
lines changed

aa-sdk/core/src/errors/client.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,6 @@ export class InvalidModularAccountV2Mode extends BaseError {
118118
}
119119
}
120120

121-
/**
122-
* Error class denoting that the deferred action mode used is invalid.
123-
*/
124-
export class InvalidDeferredActionMode extends BaseError {
125-
override name = "InvalidDeferredActionMode";
126-
127-
/**
128-
* Initializes a new instance of the error message with a default message indicating that the provided deferred action mode is invalid.
129-
*/
130-
constructor() {
131-
super(`The provided deferred action mode is invalid`);
132-
}
133-
}
134-
135121
/**
136122
* Error class denoting that the deferred action nonce used is invalid.
137123
*/

aa-sdk/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export {
7777
InvalidNonceKeyError,
7878
EntityIdOverrideError,
7979
InvalidModularAccountV2Mode,
80-
InvalidDeferredActionMode,
8180
InvalidDeferredActionNonce,
8281
} from "./errors/client.js";
8382
export {

account-kit/smart-contracts/src/ma-v2/account/common/modularAccountV2Base.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import {
44
InvalidEntityIdError,
55
InvalidNonceKeyError,
66
InvalidDeferredActionNonce,
7-
InvalidDeferredActionMode,
87
toSmartContractAccount,
98
type AccountOp,
109
type SmartAccountSigner,
1110
type SmartContractAccountWithSigner,
1211
type ToSmartContractAccountParams,
1312
} from "@aa-sdk/core";
14-
import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js";
13+
import { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from "../../utils.js";
1514
import {
1615
type Hex,
1716
type Address,
@@ -136,9 +135,9 @@ export async function createMAv2Base<
136135
let hasAssociatedExecHooks: boolean = false;
137136

138137
if (deferredAction) {
139-
if (deferredAction.slice(2, 4) !== "00") {
140-
throw new InvalidDeferredActionMode();
141-
}
138+
({ nonce, deferredActionData, hasAssociatedExecHooks } =
139+
parseDeferredAction(deferredAction));
140+
142141
// Set these values if the deferred action has not been consumed. We check this with the EP
143142
const nextNonceForDeferredAction: bigint =
144143
(await entryPointContract.read.getNonce([
@@ -148,10 +147,7 @@ export async function createMAv2Base<
148147

149148
// we only add the deferred action in if the nonce has not been consumed
150149
if (nonce === nextNonceForDeferredAction) {
151-
nonce = BigInt(`0x${deferredAction.slice(6, 70)}`);
152150
useDeferredAction = true;
153-
deferredActionData = `0x${deferredAction.slice(70)}`;
154-
hasAssociatedExecHooks = deferredAction[5] === "1";
155151
} else if (nonce > nextNonceForDeferredAction) {
156152
throw new InvalidDeferredActionNonce();
157153
}

account-kit/smart-contracts/src/ma-v2/actions/deferralActions.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,6 @@ import { alchemyGasAndPaymasterAndDataMiddleware } from "@account-kit/infra";
2828
describe("MA v2 deferral actions tests", async () => {
2929
const instance = local070Instance;
3030

31-
let client: ReturnType<typeof instance.getClient> &
32-
ReturnType<typeof publicActions> &
33-
TestActions;
34-
35-
beforeAll(async () => {
36-
client = instance
37-
.getClient()
38-
.extend(publicActions)
39-
.extend(testActions({ mode: "anvil" }));
40-
});
41-
4231
const signer: SmartAccountSigner = new LocalAccountSigner(
4332
accounts.fundedAccountOwner
4433
);

account-kit/smart-contracts/src/ma-v2/client/client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ describe("MA v2 Tests", async () => {
619619

620620
// version 00, preExecHooks 00, nonce, deferredActionDigest
621621
const fullDeferredAction = concatHex([
622-
"0x0000",
622+
"0x00",
623623
toHex(nonce, { size: 32 }),
624624
deferredActionDigest,
625625
]);

account-kit/smart-contracts/src/ma-v2/permissionBuilder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ export class PermissionBuilder {
377377
).buildPreSignatureDeferredActionDigest({ typedData });
378378

379379
// Encode additional information to build the full pre-signature digest
380-
const fullPreSignatureDeferredActionDigest: `0x${string}` = `0x00${
381-
this.hasAssociatedExecHooks ? "01" : "00"
380+
const fullPreSignatureDeferredActionDigest: `0x${string}` = `0x0${
381+
this.hasAssociatedExecHooks ? "1" : "0"
382382
}${toHex(this.nonce, {
383383
size: 32,
384384
}).slice(2)}${preSignatureDigest.slice(2)}`;

account-kit/smart-contracts/src/ma-v2/utils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,18 @@ export const buildFullNonceKey = ({
263263
(isGlobalValidation ? 1n : 0n)
264264
);
265265
};
266+
267+
// Parses out the 3 components from a deferred action
268+
export const parseDeferredAction = (
269+
deferredAction: Hex
270+
): {
271+
nonce: bigint;
272+
deferredActionData: Hex;
273+
hasAssociatedExecHooks: boolean;
274+
} => {
275+
return {
276+
nonce: BigInt(`0x${deferredAction.slice(4, 68)}`),
277+
deferredActionData: `0x${deferredAction.slice(68)}`,
278+
hasAssociatedExecHooks: deferredAction[3] === "1",
279+
};
280+
};

site/pages/reference/aa-sdk/core/classes/InvalidDeferredActionMode/constructor.mdx

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)