@account-kit/smart-contracts 4.12.1-alpha.0 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/src/index.d.ts +5 -0
- package/dist/esm/src/index.js +2 -0
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.d.ts +39 -0
- package/dist/esm/src/ma-v2/account/{semiModularAccountV2.js → common/modularAccountV2Base.js} +32 -61
- package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js.map +1 -0
- package/dist/esm/src/ma-v2/account/modularAccountV2.d.ts +16 -0
- package/dist/esm/src/ma-v2/account/modularAccountV2.js +113 -0
- package/dist/esm/src/ma-v2/account/modularAccountV2.js.map +1 -0
- package/dist/esm/src/ma-v2/account/nativeSMASigner.d.ts +1 -1
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js +1 -1
- package/dist/esm/src/ma-v2/account/nativeSMASigner.js.map +1 -1
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.d.ts +11 -9
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.js +43 -23
- package/dist/esm/src/ma-v2/actions/install-validation/installValidation.js.map +1 -1
- package/dist/esm/src/ma-v2/client/client.d.ts +7 -6
- package/dist/esm/src/ma-v2/client/client.js +21 -18
- package/dist/esm/src/ma-v2/client/client.js.map +1 -1
- package/dist/esm/src/ma-v2/index.d.ts +0 -4
- package/dist/esm/src/ma-v2/index.js +0 -2
- package/dist/esm/src/ma-v2/index.js.map +1 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.d.ts +1 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js +1 -1
- package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js.map +1 -1
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts +40 -0
- package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -0
- package/dist/types/src/ma-v2/account/modularAccountV2.d.ts +17 -0
- package/dist/types/src/ma-v2/account/modularAccountV2.d.ts.map +1 -0
- package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts +1 -1
- package/dist/types/src/ma-v2/actions/install-validation/installValidation.d.ts +11 -9
- package/dist/types/src/ma-v2/actions/install-validation/installValidation.d.ts.map +1 -1
- package/dist/types/src/ma-v2/client/client.d.ts +7 -6
- package/dist/types/src/ma-v2/client/client.d.ts.map +1 -1
- package/dist/types/src/ma-v2/index.d.ts +0 -4
- package/dist/types/src/ma-v2/index.d.ts.map +1 -1
- package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts +1 -1
- package/package.json +6 -6
- package/src/index.ts +7 -0
- package/src/ma-v2/account/{semiModularAccountV2.ts → common/modularAccountV2Base.ts} +62 -105
- package/src/ma-v2/account/modularAccountV2.ts +193 -0
- package/src/ma-v2/account/nativeSMASigner.ts +1 -1
- package/src/ma-v2/actions/install-validation/installValidation.ts +75 -36
- package/src/ma-v2/client/client.ts +54 -34
- package/src/ma-v2/index.ts +0 -5
- package/src/ma-v2/modules/single-signer-validation/signer.ts +1 -1
- package/dist/esm/src/ma-v2/account/semiModularAccountV2.d.ts +0 -41
- package/dist/esm/src/ma-v2/account/semiModularAccountV2.js.map +0 -1
- package/dist/types/src/ma-v2/account/semiModularAccountV2.d.ts +0 -42
- package/dist/types/src/ma-v2/account/semiModularAccountV2.d.ts.map +0 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { type SmartAccountClient, type SmartAccountSigner, type SmartAccountClientConfig, type NotType } from "@aa-sdk/core";
|
|
2
2
|
import { type Chain, type Transport } from "viem";
|
|
3
|
-
import { type
|
|
3
|
+
import { type CreateModularAccountV2Params } from "../account/modularAccountV2.js";
|
|
4
4
|
import { type AlchemySmartAccountClientConfig, type AlchemyTransport } from "@account-kit/infra";
|
|
5
5
|
import type { LightAccount } from "../../light-account/accounts/account.js";
|
|
6
|
-
|
|
7
|
-
export type
|
|
8
|
-
export type
|
|
6
|
+
import type { ModularAccountV2 } from "../account/common/modularAccountV2Base.js";
|
|
7
|
+
export type ModularAccountV2Client<TSigner extends SmartAccountSigner = SmartAccountSigner, TChain extends Chain = Chain, TTransport extends Transport | AlchemyTransport = Transport> = SmartAccountClient<TTransport, TChain, ModularAccountV2<TSigner>>;
|
|
8
|
+
export type CreateModularAccountV2ClientParams<TTransport extends Transport = Transport, TChain extends Chain = Chain, TSigner extends SmartAccountSigner = SmartAccountSigner> = CreateModularAccountV2Params<TTransport, TSigner> & Omit<SmartAccountClientConfig<TTransport, TChain>, "transport" | "account" | "chain">;
|
|
9
|
+
export type CreateModularAccountV2AlchemyClientParams<TTransport extends Transport = Transport, TChain extends Chain = Chain, TSigner extends SmartAccountSigner = SmartAccountSigner> = Omit<CreateModularAccountV2ClientParams<TTransport, TChain, TSigner>, "transport"> & Omit<AlchemySmartAccountClientConfig<TChain, LightAccount<TSigner>>, "account"> & {
|
|
9
10
|
paymasterAndData?: never;
|
|
10
11
|
dummyPaymasterAndData?: never;
|
|
11
12
|
};
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function createModularAccountV2Client<TChain extends Chain = Chain, TSigner extends SmartAccountSigner = SmartAccountSigner>(args: CreateModularAccountV2AlchemyClientParams<AlchemyTransport, TChain, TSigner>): Promise<ModularAccountV2Client<TSigner, TChain, AlchemyTransport>>;
|
|
14
|
+
export declare function createModularAccountV2Client<TTransport extends Transport = Transport, TChain extends Chain = Chain, TSigner extends SmartAccountSigner = SmartAccountSigner>(args: CreateModularAccountV2ClientParams<TTransport, TChain, TSigner> & NotType<TTransport, AlchemyTransport>): Promise<ModularAccountV2Client<TSigner, TChain>>;
|
|
14
15
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/ma-v2/client/client.ts"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EACxC,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,IACrD,IAAI,CACN,kCAAkC,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAC/D,WAAW,CACZ,GACC,IAAI,CACF,+BAA+B,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,EAC9D,SAAS,CACV,GAAG;IAAE,gBAAgB,CAAC,EAAE,KAAK,CAAC;IAAC,qBAAqB,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAElE,wBAAgB,4BAA4B,CAC1C,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EAEvD,IAAI,EAAE,yCAAyC,CAC7C,gBAAgB,EAChB,MAAM,EACN,OAAO,CACR,GACA,OAAO,CAAC,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAEtE,wBAAgB,4BAA4B,CAC1C,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EAEvD,IAAI,EAAE,kCAAkC,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,GACnE,OAAO,CAAC,UAAU,EAAE,gBAAgB,CAAC,GACtC,OAAO,CAAC,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC"}
|
|
@@ -3,15 +3,11 @@ export { modularAccountAbi } from "./abis/modularAccountAbi.js";
|
|
|
3
3
|
export { semiModularAccountBytecodeAbi } from "./abis/semiModularAccountBytecodeAbi.js";
|
|
4
4
|
export { semiModularAccountStorageAbi } from "./abis/semiModularAccountStorageAbi.js";
|
|
5
5
|
export { nativeSMASigner } from "./account/nativeSMASigner.js";
|
|
6
|
-
export type * from "./account/semiModularAccountV2.js";
|
|
7
|
-
export { createSMAV2Account } from "./account/semiModularAccountV2.js";
|
|
8
6
|
export type { ModuleEntity, ValidationConfig, HookConfig, ValidationData, } from "./actions/common/types.js";
|
|
9
7
|
export { HookType } from "./actions/common/types.js";
|
|
10
8
|
export { serializeValidationConfig, serializeHookConfig, serializeModuleEntity, } from "./actions/common/utils.js";
|
|
11
9
|
export type * from "./actions/install-validation/installValidation.js";
|
|
12
10
|
export { installValidationActions } from "./actions/install-validation/installValidation.js";
|
|
13
|
-
export type * from "./client/client.js";
|
|
14
|
-
export { createSMAV2AccountClient } from "./client/client.js";
|
|
15
11
|
export { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddress, getDefaultPaymasterGuardModuleAddress, getDefaultSingleSignerValidationModuleAddress, getDefaultTimeRangeModuleAddress, getDefaultWebauthnValidationModuleAddress, } from "./modules/utils.js";
|
|
16
12
|
export { allowlistModuleAbi } from "./modules/allowlist-module/abis/allowlistModuleAbi.js";
|
|
17
13
|
export { AllowlistModule } from "./modules/allowlist-module/module.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAEtF,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAA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*
|
|
14
|
-
* const account =
|
|
14
|
+
* const account = createModularAccountV2({ config });
|
|
15
15
|
*
|
|
16
16
|
* const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);
|
|
17
17
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/smart-contracts",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "aa-sdk compatible interfaces for Alchemy Smart Accounts",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"test:run": "vitest run"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@account-kit/plugingen": "^4.
|
|
55
|
+
"@account-kit/plugingen": "^4.13.0",
|
|
56
56
|
"change-case": "^5.1.2",
|
|
57
57
|
"dedent": "^1.5.1",
|
|
58
58
|
"dotenv": "^16.3.1",
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
73
73
|
},
|
|
74
74
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "6865bd7b49bc7db064bca7026914e4299febdb34",
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@aa-sdk/core": "^4.
|
|
78
|
-
"@account-kit/infra": "^4.
|
|
77
|
+
"@aa-sdk/core": "^4.13.0",
|
|
78
|
+
"@account-kit/infra": "^4.13.0"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"viem": "^2.
|
|
81
|
+
"viem": "^2.22.6"
|
|
82
82
|
}
|
|
83
83
|
}
|
package/src/index.ts
CHANGED
|
@@ -115,3 +115,10 @@ export {
|
|
|
115
115
|
getMAInitializationData,
|
|
116
116
|
getMSCAUpgradeToData,
|
|
117
117
|
} from "./msca/utils.js";
|
|
118
|
+
|
|
119
|
+
// ma v2 types
|
|
120
|
+
export type * from "./ma-v2/account/modularAccountV2.js";
|
|
121
|
+
export type * from "./ma-v2/account/common/modularAccountV2Base.js";
|
|
122
|
+
export { createModularAccountV2 } from "./ma-v2/account/modularAccountV2.js";
|
|
123
|
+
export type * from "./ma-v2/client/client.js";
|
|
124
|
+
export { createModularAccountV2Client } from "./ma-v2/client/client.js";
|
|
@@ -1,41 +1,33 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
EntryPointDef,
|
|
3
|
-
SmartAccountSigner,
|
|
4
|
-
AccountOp,
|
|
5
|
-
SmartContractAccountWithSigner,
|
|
6
|
-
ToSmartContractAccountParams,
|
|
7
|
-
} from "@aa-sdk/core";
|
|
8
1
|
import {
|
|
9
2
|
createBundlerClient,
|
|
10
3
|
getEntryPoint,
|
|
11
|
-
toSmartContractAccount,
|
|
12
4
|
InvalidEntityIdError,
|
|
13
5
|
InvalidNonceKeyError,
|
|
14
|
-
|
|
6
|
+
toSmartContractAccount,
|
|
7
|
+
type AccountOp,
|
|
8
|
+
type SmartAccountSigner,
|
|
9
|
+
type SmartContractAccountWithSigner,
|
|
10
|
+
type ToSmartContractAccountParams,
|
|
15
11
|
} from "@aa-sdk/core";
|
|
12
|
+
import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js";
|
|
16
13
|
import {
|
|
17
|
-
|
|
18
|
-
encodeFunctionData,
|
|
19
|
-
getContract,
|
|
20
|
-
maxUint32,
|
|
21
|
-
maxUint152,
|
|
22
|
-
zeroAddress,
|
|
14
|
+
type Hex,
|
|
23
15
|
type Address,
|
|
24
16
|
type Chain,
|
|
25
|
-
type Hex,
|
|
26
17
|
type Transport,
|
|
18
|
+
encodeFunctionData,
|
|
19
|
+
maxUint32,
|
|
20
|
+
zeroAddress,
|
|
21
|
+
getContract,
|
|
22
|
+
concatHex,
|
|
23
|
+
maxUint152,
|
|
27
24
|
} from "viem";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} from "../utils.js";
|
|
33
|
-
import { singleSignerMessageSigner } from "../modules/single-signer-validation/signer.js";
|
|
34
|
-
import { nativeSMASigner } from "./nativeSMASigner.js";
|
|
35
|
-
import { modularAccountAbi } from "../abis/modularAccountAbi.js";
|
|
36
|
-
import { serializeModuleEntity } from "../actions/common/utils.js";
|
|
25
|
+
import { modularAccountAbi } from "../../abis/modularAccountAbi.js";
|
|
26
|
+
import { serializeModuleEntity } from "../../actions/common/utils.js";
|
|
27
|
+
import { nativeSMASigner } from "../nativeSMASigner.js";
|
|
28
|
+
import { singleSignerMessageSigner } from "../../modules/single-signer-validation/signer.js";
|
|
37
29
|
|
|
38
|
-
const executeUserOpSelector: Hex = "0x8DD7712F";
|
|
30
|
+
export const executeUserOpSelector: Hex = "0x8DD7712F";
|
|
39
31
|
|
|
40
32
|
export type SignerEntity = {
|
|
41
33
|
isGlobalValidation: boolean;
|
|
@@ -66,9 +58,9 @@ export type ValidationDataParams =
|
|
|
66
58
|
entityId: number;
|
|
67
59
|
};
|
|
68
60
|
|
|
69
|
-
export type
|
|
61
|
+
export type ModularAccountV2<
|
|
70
62
|
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
71
|
-
> = SmartContractAccountWithSigner<"
|
|
63
|
+
> = SmartContractAccountWithSigner<"ModularAccountV2", TSigner, "0.7.0"> & {
|
|
72
64
|
signerEntity: SignerEntity;
|
|
73
65
|
getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;
|
|
74
66
|
getValidationData: (
|
|
@@ -77,48 +69,35 @@ export type MAV2Account<
|
|
|
77
69
|
encodeCallData: (callData: Hex) => Promise<Hex>;
|
|
78
70
|
};
|
|
79
71
|
|
|
80
|
-
export type
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
> =
|
|
84
|
-
ToSmartContractAccountParams<"
|
|
85
|
-
|
|
72
|
+
export type CreateMAV2BaseParams<
|
|
73
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner,
|
|
74
|
+
TTransport extends Transport = Transport
|
|
75
|
+
> = Omit<
|
|
76
|
+
ToSmartContractAccountParams<"ModularAccountV2", TTransport, Chain, "0.7.0">,
|
|
77
|
+
// Implements the following methods required by `toSmartContractAccount`, and passes through any other parameters.
|
|
78
|
+
| "encodeExecute"
|
|
79
|
+
| "encodeBatchExecute"
|
|
80
|
+
| "getNonce"
|
|
81
|
+
| "signMessage"
|
|
82
|
+
| "signTypedData"
|
|
83
|
+
| "getDummySignature"
|
|
86
84
|
> & {
|
|
87
85
|
signer: TSigner;
|
|
88
|
-
salt?: bigint;
|
|
89
|
-
factoryAddress?: Address;
|
|
90
|
-
initCode?: Hex;
|
|
91
|
-
initialOwner?: Address;
|
|
92
|
-
entryPoint?: EntryPointDef<"0.7.0", Chain>;
|
|
93
86
|
signerEntity?: SignerEntity;
|
|
87
|
+
accountAddress: Address;
|
|
94
88
|
};
|
|
95
89
|
|
|
96
|
-
export
|
|
97
|
-
TTransport extends Transport = Transport,
|
|
90
|
+
export type CreateMAV2BaseReturnType<
|
|
98
91
|
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
99
|
-
>
|
|
100
|
-
config: CreateSMAV2AccountParams<TTransport, TSigner>
|
|
101
|
-
): Promise<MAV2Account<TSigner>>;
|
|
92
|
+
> = Promise<ModularAccountV2<TSigner>>;
|
|
102
93
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
* @param {CreateSMAV2AccountParams} config Configuration parameters for creating an SMAV2 account. Includes chain details, signer, salt, factory address, and more.
|
|
108
|
-
* @returns {Promise<MAV2Account>} A promise that resolves to an `MAV2Account` providing methods for nonce retrieval, transaction execution, and more.
|
|
109
|
-
*/
|
|
110
|
-
export async function createSMAV2Account(
|
|
111
|
-
config: CreateSMAV2AccountParams
|
|
112
|
-
): Promise<MAV2Account> {
|
|
94
|
+
export async function createMAv2Base<
|
|
95
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
96
|
+
>(config: CreateMAV2BaseParams<TSigner>): CreateMAV2BaseReturnType<TSigner> {
|
|
113
97
|
const {
|
|
114
98
|
transport,
|
|
115
99
|
chain,
|
|
116
100
|
signer,
|
|
117
|
-
salt = 0n,
|
|
118
|
-
factoryAddress = getDefaultMAV2FactoryAddress(chain),
|
|
119
|
-
initCode,
|
|
120
|
-
initialOwner,
|
|
121
|
-
accountAddress,
|
|
122
101
|
entryPoint = getEntryPoint(chain, { version: "0.7.0" }),
|
|
123
102
|
signerEntity = {
|
|
124
103
|
isGlobalValidation: true,
|
|
@@ -128,6 +107,8 @@ export async function createSMAV2Account(
|
|
|
128
107
|
isGlobalValidation = true,
|
|
129
108
|
entityId = DEFAULT_OWNER_ENTITY_ID,
|
|
130
109
|
} = {},
|
|
110
|
+
accountAddress,
|
|
111
|
+
...remainingToSmartContractAccountParams
|
|
131
112
|
} = config;
|
|
132
113
|
|
|
133
114
|
if (entityId > Number(maxUint32)) {
|
|
@@ -139,24 +120,6 @@ export async function createSMAV2Account(
|
|
|
139
120
|
chain,
|
|
140
121
|
});
|
|
141
122
|
|
|
142
|
-
const getAccountInitCode = async () => {
|
|
143
|
-
if (initCode) {
|
|
144
|
-
return initCode;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// If an initial owner is not provided, use the signer's address
|
|
148
|
-
const ownerAddress = initialOwner ?? (await signer.getAddress());
|
|
149
|
-
|
|
150
|
-
return concatHex([
|
|
151
|
-
factoryAddress,
|
|
152
|
-
encodeFunctionData({
|
|
153
|
-
abi: accountFactoryAbi,
|
|
154
|
-
functionName: "createSemiModularAccount",
|
|
155
|
-
args: [ownerAddress, salt],
|
|
156
|
-
}),
|
|
157
|
-
]);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
123
|
const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({
|
|
161
124
|
target,
|
|
162
125
|
data,
|
|
@@ -185,29 +148,10 @@ export async function createSMAV2Account(
|
|
|
185
148
|
})
|
|
186
149
|
);
|
|
187
150
|
|
|
188
|
-
const
|
|
189
|
-
client
|
|
190
|
-
entryPoint,
|
|
191
|
-
accountAddress,
|
|
192
|
-
getAccountInitCode,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
const baseAccount = await toSmartContractAccount({
|
|
196
|
-
transport,
|
|
197
|
-
chain,
|
|
198
|
-
entryPoint,
|
|
199
|
-
accountAddress: _accountAddress,
|
|
200
|
-
source: `MAV2Account`,
|
|
201
|
-
encodeExecute,
|
|
202
|
-
encodeBatchExecute,
|
|
203
|
-
getAccountInitCode,
|
|
204
|
-
...(entityId === DEFAULT_OWNER_ENTITY_ID
|
|
205
|
-
? nativeSMASigner(signer, chain, _accountAddress)
|
|
206
|
-
: singleSignerMessageSigner(signer, chain, _accountAddress, entityId)),
|
|
207
|
-
});
|
|
208
|
-
|
|
151
|
+
const isAccountDeployed: () => Promise<boolean> = async () =>
|
|
152
|
+
!!(await client.getCode({ address: accountAddress }));
|
|
209
153
|
// TODO: add deferred action flag
|
|
210
|
-
const
|
|
154
|
+
const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {
|
|
211
155
|
if (nonceKey > maxUint152) {
|
|
212
156
|
throw new InvalidNonceKeyError(nonceKey);
|
|
213
157
|
}
|
|
@@ -220,23 +164,23 @@ export async function createSMAV2Account(
|
|
|
220
164
|
|
|
221
165
|
const fullNonceKey: bigint =
|
|
222
166
|
(nonceKey << 40n) +
|
|
223
|
-
BigInt(entityId <<
|
|
167
|
+
(BigInt(entityId) << 8n) +
|
|
224
168
|
(isGlobalValidation ? 1n : 0n);
|
|
225
169
|
|
|
226
170
|
return entryPointContract.read.getNonce([
|
|
227
|
-
|
|
171
|
+
accountAddress,
|
|
228
172
|
fullNonceKey,
|
|
229
173
|
]) as Promise<bigint>;
|
|
230
174
|
};
|
|
231
175
|
|
|
232
176
|
const accountContract = getContract({
|
|
233
|
-
address:
|
|
177
|
+
address: accountAddress,
|
|
234
178
|
abi: modularAccountAbi,
|
|
235
179
|
client,
|
|
236
180
|
});
|
|
237
181
|
|
|
238
182
|
const getExecutionData = async (selector: Hex) => {
|
|
239
|
-
if (!(await
|
|
183
|
+
if (!(await isAccountDeployed())) {
|
|
240
184
|
return {
|
|
241
185
|
module: zeroAddress,
|
|
242
186
|
skipRuntimeValidation: false,
|
|
@@ -249,7 +193,7 @@ export async function createSMAV2Account(
|
|
|
249
193
|
};
|
|
250
194
|
|
|
251
195
|
const getValidationData = async (args: ValidationDataParams) => {
|
|
252
|
-
if (!(await
|
|
196
|
+
if (!(await isAccountDeployed())) {
|
|
253
197
|
return {
|
|
254
198
|
validationHooks: [],
|
|
255
199
|
executionHooks: [],
|
|
@@ -277,9 +221,22 @@ export async function createSMAV2Account(
|
|
|
277
221
|
: callData;
|
|
278
222
|
};
|
|
279
223
|
|
|
224
|
+
const baseAccount = await toSmartContractAccount({
|
|
225
|
+
...remainingToSmartContractAccountParams,
|
|
226
|
+
transport,
|
|
227
|
+
chain,
|
|
228
|
+
entryPoint,
|
|
229
|
+
accountAddress,
|
|
230
|
+
encodeExecute,
|
|
231
|
+
encodeBatchExecute,
|
|
232
|
+
getNonce,
|
|
233
|
+
...(entityId === DEFAULT_OWNER_ENTITY_ID
|
|
234
|
+
? nativeSMASigner(signer, chain, accountAddress)
|
|
235
|
+
: singleSignerMessageSigner(signer, chain, accountAddress, entityId)),
|
|
236
|
+
});
|
|
237
|
+
|
|
280
238
|
return {
|
|
281
239
|
...baseAccount,
|
|
282
|
-
getAccountNonce,
|
|
283
240
|
getSigner: () => signer,
|
|
284
241
|
signerEntity,
|
|
285
242
|
getExecutionData,
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
EntryPointDef,
|
|
3
|
+
SmartAccountSigner,
|
|
4
|
+
ToSmartContractAccountParams,
|
|
5
|
+
} from "@aa-sdk/core";
|
|
6
|
+
import {
|
|
7
|
+
createBundlerClient,
|
|
8
|
+
getEntryPoint,
|
|
9
|
+
getAccountAddress,
|
|
10
|
+
EntityIdOverrideError,
|
|
11
|
+
InvalidModularAccountV2Mode,
|
|
12
|
+
} from "@aa-sdk/core";
|
|
13
|
+
import {
|
|
14
|
+
concatHex,
|
|
15
|
+
encodeFunctionData,
|
|
16
|
+
type Address,
|
|
17
|
+
type Chain,
|
|
18
|
+
type Hex,
|
|
19
|
+
type Transport,
|
|
20
|
+
} from "viem";
|
|
21
|
+
import { accountFactoryAbi } from "../abis/accountFactoryAbi.js";
|
|
22
|
+
import { getDefaultMAV2FactoryAddress } from "../utils.js";
|
|
23
|
+
import {
|
|
24
|
+
type SignerEntity,
|
|
25
|
+
type ModularAccountV2,
|
|
26
|
+
createMAv2Base,
|
|
27
|
+
} from "./common/modularAccountV2Base.js";
|
|
28
|
+
import { DEFAULT_OWNER_ENTITY_ID } from "../utils.js";
|
|
29
|
+
|
|
30
|
+
export type CreateModularAccountV2Params<
|
|
31
|
+
TTransport extends Transport = Transport,
|
|
32
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
33
|
+
> = (Pick<
|
|
34
|
+
ToSmartContractAccountParams<"ModularAccountV2", TTransport, Chain, "0.7.0">,
|
|
35
|
+
"transport" | "chain" | "accountAddress"
|
|
36
|
+
> & {
|
|
37
|
+
signer: TSigner;
|
|
38
|
+
entryPoint?: EntryPointDef<"0.7.0", Chain>;
|
|
39
|
+
signerEntity?: SignerEntity;
|
|
40
|
+
}) &
|
|
41
|
+
(
|
|
42
|
+
| {
|
|
43
|
+
mode?: "default";
|
|
44
|
+
salt?: bigint;
|
|
45
|
+
factoryAddress?: Address;
|
|
46
|
+
initCode?: Hex;
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
mode: "7702";
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export async function createModularAccountV2<
|
|
54
|
+
TTransport extends Transport = Transport,
|
|
55
|
+
TSigner extends SmartAccountSigner = SmartAccountSigner
|
|
56
|
+
>(
|
|
57
|
+
config: CreateModularAccountV2Params<TTransport, TSigner>
|
|
58
|
+
): Promise<ModularAccountV2<TSigner>>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Creates a ModularAccount V2 account, with the mode depending on the provided "mode" field.
|
|
62
|
+
* Possible modes include: "default", which is SMA Bytecode, and "7702", which is SMA 7702.
|
|
63
|
+
* Handles nonce generation, transaction encoding, and mode variant-specific behavior like initcode construction.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts twoslash
|
|
67
|
+
* import { createModularAccountV2 } from "@account-kit/smart-contracts";
|
|
68
|
+
* import { LocalAccountSigner } from "@aa-sdk/core";
|
|
69
|
+
* import { alchemy, sepolia } from "@account-kit/infra";
|
|
70
|
+
*
|
|
71
|
+
* const MNEMONIC = "...";
|
|
72
|
+
* const RPC_URL = "...";
|
|
73
|
+
*
|
|
74
|
+
* const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);
|
|
75
|
+
*
|
|
76
|
+
* const chain = sepolia;
|
|
77
|
+
*
|
|
78
|
+
* const transport = alchemy({ rpcUrl: RPC_URL });
|
|
79
|
+
*
|
|
80
|
+
*
|
|
81
|
+
* const modularAccountV2 = await createModularAccountV2({
|
|
82
|
+
* mode: "default", // or "7702"
|
|
83
|
+
* chain,
|
|
84
|
+
* signer,
|
|
85
|
+
* transport,
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @param {CreateModularAccountV2Params} config Configuration parameters for creating a Modular Account V2.
|
|
90
|
+
* @returns {Promise<ModularAccountV2>} A promise that resolves to an `ModularAccountV2` providing methods for nonce retrieval, transaction execution, and more.
|
|
91
|
+
*/
|
|
92
|
+
export async function createModularAccountV2(
|
|
93
|
+
config: CreateModularAccountV2Params
|
|
94
|
+
): Promise<ModularAccountV2> {
|
|
95
|
+
const {
|
|
96
|
+
transport,
|
|
97
|
+
chain,
|
|
98
|
+
signer,
|
|
99
|
+
accountAddress: _accountAddress,
|
|
100
|
+
entryPoint = getEntryPoint(chain, { version: "0.7.0" }),
|
|
101
|
+
signerEntity = {
|
|
102
|
+
isGlobalValidation: true,
|
|
103
|
+
entityId: DEFAULT_OWNER_ENTITY_ID,
|
|
104
|
+
},
|
|
105
|
+
signerEntity: { entityId = DEFAULT_OWNER_ENTITY_ID } = {},
|
|
106
|
+
} = config;
|
|
107
|
+
|
|
108
|
+
const client = createBundlerClient({
|
|
109
|
+
transport,
|
|
110
|
+
chain,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const accountFunctions = await (async () => {
|
|
114
|
+
switch (config.mode) {
|
|
115
|
+
case "7702": {
|
|
116
|
+
const getAccountInitCode = async (): Promise<Hex> => {
|
|
117
|
+
return "0x";
|
|
118
|
+
};
|
|
119
|
+
const signerAddress = await signer.getAddress();
|
|
120
|
+
const accountAddress = _accountAddress ?? signerAddress;
|
|
121
|
+
if (
|
|
122
|
+
entityId === DEFAULT_OWNER_ENTITY_ID &&
|
|
123
|
+
signerAddress !== accountAddress
|
|
124
|
+
) {
|
|
125
|
+
throw new EntityIdOverrideError();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const implementation: Address =
|
|
129
|
+
"0x69007702764179f14F51cdce752f4f775d74E139";
|
|
130
|
+
|
|
131
|
+
const getImplementationAddress = async () => implementation;
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
getAccountInitCode,
|
|
135
|
+
accountAddress,
|
|
136
|
+
getImplementationAddress,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
case "default":
|
|
140
|
+
case undefined: {
|
|
141
|
+
const {
|
|
142
|
+
salt = 0n,
|
|
143
|
+
factoryAddress = getDefaultMAV2FactoryAddress(chain),
|
|
144
|
+
initCode,
|
|
145
|
+
} = config;
|
|
146
|
+
|
|
147
|
+
const getAccountInitCode = async () => {
|
|
148
|
+
if (initCode) {
|
|
149
|
+
return initCode;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return concatHex([
|
|
153
|
+
factoryAddress,
|
|
154
|
+
encodeFunctionData({
|
|
155
|
+
abi: accountFactoryAbi,
|
|
156
|
+
functionName: "createSemiModularAccount",
|
|
157
|
+
args: [await signer.getAddress(), salt],
|
|
158
|
+
}),
|
|
159
|
+
]);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const accountAddress = await getAccountAddress({
|
|
163
|
+
client,
|
|
164
|
+
entryPoint,
|
|
165
|
+
accountAddress: _accountAddress,
|
|
166
|
+
getAccountInitCode,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
getAccountInitCode,
|
|
171
|
+
accountAddress,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
default:
|
|
175
|
+
assertNever(config);
|
|
176
|
+
}
|
|
177
|
+
})();
|
|
178
|
+
|
|
179
|
+
return createMAv2Base({
|
|
180
|
+
source: "ModularAccountV2",
|
|
181
|
+
transport,
|
|
182
|
+
chain,
|
|
183
|
+
signer,
|
|
184
|
+
entryPoint,
|
|
185
|
+
signerEntity,
|
|
186
|
+
...accountFunctions,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// If we add more valid modes, the switch case branch's mode will no longer be `never`, which will cause a compile time error here and ensure we handle the new type.
|
|
191
|
+
function assertNever(_valid: never): never {
|
|
192
|
+
throw new InvalidModularAccountV2Mode();
|
|
193
|
+
}
|