Skip to content

Commit 16e1a5e

Browse files
authored
fix: detect if 7702 account is delgated to unexpected addr (#2149)
* fix: detect if 7702 account is delgated to unexpected addr * fix: make isAccountDeployed case-insensitive
1 parent 8ed87c1 commit 16e1a5e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
BaseError,
23
createBundlerClient,
34
getEntryPoint,
45
InvalidDeferredActionNonce,
@@ -236,8 +237,31 @@ export async function createMAv2Base<
236237
}),
237238
);
238239

239-
const isAccountDeployed: () => Promise<boolean> = async () =>
240-
!!(await client.getCode({ address: accountAddress }));
240+
const isAccountDeployed: () => Promise<boolean> = async () => {
241+
const code = (
242+
await client.getCode({ address: accountAddress })
243+
)?.toLowerCase();
244+
const is7702Delegated = code?.startsWith("0xef0100");
245+
246+
if (!is7702Delegated) {
247+
return !!code;
248+
}
249+
250+
if (!config.getImplementationAddress) {
251+
// Edge case where account is already delegated to a 3rd party
252+
// implementation, but the MAv2 client is initialized using its
253+
// address without specifying 7702 mode.
254+
throw new BaseError(
255+
"Account is an already-delegated 7702 account, but client is missing implementation address. Be sure to initialize the client in 7702 mode.",
256+
);
257+
}
258+
259+
const expectedCode = concatHex([
260+
"0xef0100",
261+
await config.getImplementationAddress(),
262+
]).toLowerCase();
263+
return code === expectedCode;
264+
};
241265

242266
const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {
243267
if (nonce) {

0 commit comments

Comments
 (0)