@alchemy/smart-accounts 5.0.0-beta.2 → 5.0.0-beta.21
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/README.md +0 -2
- package/dist/esm/index.d.ts +3 -6
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/light-account/accounts/base.js +0 -1
- package/dist/esm/light-account/accounts/base.js.map +1 -1
- package/dist/esm/light-account/accounts/calldataCodec.d.ts +17 -0
- package/dist/esm/light-account/accounts/calldataCodec.js +17 -0
- package/dist/esm/light-account/accounts/calldataCodec.js.map +1 -1
- package/dist/esm/light-account/utils.js +0 -5
- package/dist/esm/light-account/utils.js.map +1 -1
- package/dist/esm/ma-v1/accounts/base.js +6 -50
- package/dist/esm/ma-v1/accounts/base.js.map +1 -1
- package/dist/esm/ma-v1/accounts/calldataCodec.d.ts +20 -0
- package/dist/esm/ma-v1/accounts/calldataCodec.js +69 -0
- package/dist/esm/ma-v1/accounts/calldataCodec.js.map +1 -0
- package/dist/esm/ma-v1/mav1StaticImpl.d.ts +0 -2
- package/dist/esm/ma-v1/mav1StaticImpl.js +0 -2
- package/dist/esm/ma-v1/mav1StaticImpl.js.map +1 -1
- package/dist/esm/ma-v2/accounts/account.js +1 -1
- package/dist/esm/ma-v2/accounts/account.js.map +1 -1
- package/dist/esm/ma-v2/accounts/base.js +7 -54
- package/dist/esm/ma-v2/accounts/base.js.map +1 -1
- package/dist/esm/ma-v2/accounts/calldataCodec.d.ts +20 -0
- package/dist/esm/ma-v2/accounts/calldataCodec.js +77 -0
- package/dist/esm/ma-v2/accounts/calldataCodec.js.map +1 -0
- package/dist/esm/ma-v2/decorators/installValidation.d.ts +8 -20
- package/dist/esm/ma-v2/decorators/installValidation.js +7 -58
- package/dist/esm/ma-v2/decorators/installValidation.js.map +1 -1
- package/dist/esm/ma-v2/mav2StaticImpl.d.ts +0 -4
- package/dist/esm/ma-v2/mav2StaticImpl.js +0 -4
- package/dist/esm/ma-v2/mav2StaticImpl.js.map +1 -1
- package/dist/esm/ma-v2/utils/account.js +0 -2
- package/dist/esm/ma-v2/utils/account.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/index.d.ts +3 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/light-account/accounts/base.d.ts.map +1 -1
- package/dist/types/light-account/accounts/calldataCodec.d.ts +17 -0
- package/dist/types/light-account/accounts/calldataCodec.d.ts.map +1 -1
- package/dist/types/light-account/utils.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/calldataCodec.d.ts +21 -0
- package/dist/types/ma-v1/accounts/calldataCodec.d.ts.map +1 -0
- package/dist/types/ma-v1/mav1StaticImpl.d.ts +0 -2
- package/dist/types/ma-v1/mav1StaticImpl.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/calldataCodec.d.ts +21 -0
- package/dist/types/ma-v2/accounts/calldataCodec.d.ts.map +1 -0
- package/dist/types/ma-v2/decorators/installValidation.d.ts +8 -20
- package/dist/types/ma-v2/decorators/installValidation.d.ts.map +1 -1
- package/dist/types/ma-v2/mav2StaticImpl.d.ts +0 -4
- package/dist/types/ma-v2/mav2StaticImpl.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/account.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +15 -13
- package/src/light-account/accounts/base.ts +0 -1
- package/src/light-account/accounts/calldataCodec.ts +17 -0
- package/src/light-account/utils.ts +0 -6
- package/src/ma-v1/accounts/base.ts +4 -55
- package/src/ma-v1/accounts/calldataCodec.ts +80 -0
- package/src/ma-v1/mav1StaticImpl.ts +0 -2
- package/src/ma-v2/accounts/account.ts +2 -2
- package/src/ma-v2/accounts/base.ts +6 -68
- package/src/ma-v2/accounts/calldataCodec.ts +89 -0
- package/src/ma-v2/decorators/installValidation.ts +8 -83
- package/src/ma-v2/mav2StaticImpl.ts +0 -4
- package/src/ma-v2/utils/account.ts +0 -2
- package/src/version.ts +1 -1
- package/dist/esm/light-account/decorators/multiOwner.d.ts +0 -17
- package/dist/esm/light-account/decorators/multiOwner.js +0 -39
- package/dist/esm/light-account/decorators/multiOwner.js.map +0 -1
- package/dist/esm/light-account/decorators/singleOwner.d.ts +0 -16
- package/dist/esm/light-account/decorators/singleOwner.js +0 -35
- package/dist/esm/light-account/decorators/singleOwner.js.map +0 -1
- package/dist/esm/ma-v1/decorators/multiOwner.d.ts +0 -17
- package/dist/esm/ma-v1/decorators/multiOwner.js +0 -39
- package/dist/esm/ma-v1/decorators/multiOwner.js.map +0 -1
- package/dist/types/light-account/decorators/multiOwner.d.ts +0 -18
- package/dist/types/light-account/decorators/multiOwner.d.ts.map +0 -1
- package/dist/types/light-account/decorators/singleOwner.d.ts +0 -17
- package/dist/types/light-account/decorators/singleOwner.d.ts.map +0 -1
- package/dist/types/ma-v1/decorators/multiOwner.d.ts +0 -18
- package/dist/types/ma-v1/decorators/multiOwner.d.ts.map +0 -1
- package/src/light-account/decorators/multiOwner.ts +0 -72
- package/src/light-account/decorators/singleOwner.ts +0 -63
- package/src/ma-v1/decorators/multiOwner.ts +0 -72
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mav1StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v1/mav1StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AAC/F,OAAO,EAAE,4BAA4B,EAAE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,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,cAAc,EAAE,IAAI,CAAC,MAAM;YAC3B,cAAc,EAAE,kBAAkB,CAAC,wBAAwB;SAC5D,CAAC,CAAC;IACL,CAAC;CACF,CAAC","sourcesContent":["import { type Address, encodeFunctionData } from \"viem\";\nimport { entryPoint06Abi, entryPoint06Address } from \"viem/account-abstraction\";\nimport { lowerAddress } from \"@alchemy/common\";\nimport type { StaticSmartAccountImplementation } from \"../types\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"./abis/MultiOwnerModularAccountFactory.js\";\nimport { UpgradeableModularAccountAbi } from \"./abis/UpgradeableModularAccount.js\";\nimport { DefaultMaV1Address } from \"./account.js\";\nimport { predictMultiOwnerModularAccountV1Address } from \"./predictAddress.js\";\n\nexport type MultiOwnerModularAccountV1FactoryArgs = {\n owners: Address[];\n salt: bigint;\n};\n\n/**\n * Static implementation logic for ModularAccountV1.\n */\nexport const multiOwnerModularAccountStaticImpl: StaticSmartAccountImplementation<\n false,\n \"0.6\",\n MultiOwnerModularAccountV1FactoryArgs,\n typeof entryPoint06Abi,\n typeof UpgradeableModularAccountAbi,\n typeof MultiOwnerModularAccountFactoryAbi\n> = {\n entryPoint: {\n abi: entryPoint06Abi,\n address: entryPoint06Address,\n version: \"0.6\",\n },\n accountAbi: UpgradeableModularAccountAbi,\n factoryAbi: MultiOwnerModularAccountFactoryAbi,\n getFactoryData: (factoryArgs: MultiOwnerModularAccountV1FactoryArgs) => {\n return encodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [factoryArgs.salt, factoryArgs.owners],\n });\n },\n accountImplementation: lowerAddress(\n DefaultMaV1Address.IMPLEMENTATION_ADDRESS,\n ),\n factoryAddress: lowerAddress(DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY),\n predictAccountAddress: (args) => {\n return predictMultiOwnerModularAccountV1Address({\n salt: args.salt,\n ownerAddresses: args.owners,\n factoryAddress: DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n });\n },\n};\n"]}
|
|
@@ -109,7 +109,7 @@ export async function toModularAccountV2({ client, owner, deferredAction, signer
|
|
|
109
109
|
});
|
|
110
110
|
return {
|
|
111
111
|
...base,
|
|
112
|
-
//
|
|
112
|
+
// This may be extended in the future with additional MAv2-specific methods.
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
//# sourceMappingURL=account.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GASnB,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EACL,yCAAyC,EACzC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqCzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAA4B,EAClE,MAAM,EACN,KAAK,EACL,cAAc,EACd,YAAY,EACZ,cAAc,EAAE,eAAe,EAC/B,IAAI,GAAG,EAAE,EACT,OAAO,EACP,WAAW,EAAE,YAAY,EACzB,qBAAqB,EAAE,sBAAsB,EAC7C,IAAI,GAC4B;IAChC,MAAM,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC;IAE/B,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE;QACvC,SAAS,EAAE,KAAK,CAA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,KAAK,CAAC,uCAAuC,EAAE;gBACpD,SAAS,EAAE,KAAK,CAAC,IAAI;aACtB,CAAC,CAAC;YACH,MAAM,IAAI,iBAAiB,CACzB,iBAAiB,KAAK,CAAC,IAAI,gCAAgC,CAC5D,CAAC;QACJ,CAAC;QACD,IAAI,KAAK,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;YACpC,MAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAC7D,MAAM,IAAI,iBAAiB,CACzB,qEAAqE,CACtE,CAAC;QACJ,CAAC;QACD,IACE,QAAQ,KAAK,uBAAuB;YACpC,KAAK,CAAC,OAAO,KAAK,cAAc,EAChC,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;YACtD,MAAM,IAAI,qBAAqB,EAAE,CAAC;QACpC,CAAC;QACD,aAAa,GAAG;YACd,iEAAiE;YACjE,+DAA+D;YAC/D,wCAAwC;YACxC,OAAO,EAAE,KAA0B;YACnC,OAAO,EAAE,cAAc,CAAC,UAAU;SACnC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,sBAAsB,CAAC;QACxC,MAAM;QACN,KAAK;QACL,cAAc;QACd,cAAc;QACd,YAAY;QACZ,cAAc;QACd,aAAa;KACd,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,4EAA4E;KAC7E,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type PrivateKeyAccount,\n type Transport,\n} from \"viem\";\nimport {\n type ToSmartAccountParameters,\n entryPoint07Address,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport {\n getModularAccountV2AddressFromFactoryData,\n predictModularAccountV2Address,\n} from \"../predictAddress.js\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// This may be extended in the future with additional MAv2-specific methods.\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factory?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n factory?: Address;\n implementationAddress?: Address;\n } & (\n | {\n salt?: bigint;\n factoryData?: never;\n }\n | {\n salt?: never;\n factoryData?: Hex;\n }\n ));\n\n/**\n * Creates a MAv2 account.\n *\n * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.\n * @returns {Promise<ModularAccountV2>} A MAv2 account.\n */\nexport async function toModularAccountV2<TMode extends Mode = Mode>({\n client,\n owner,\n deferredAction,\n signerEntity,\n accountAddress: accountAddress_,\n salt = 0n,\n factory,\n factoryData: factoryData_,\n implementationAddress: implementationAddress_,\n mode,\n}: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2> {\n const is7702 = mode === \"7702\";\n\n LOGGER.debug(\"toModularAccountV2:start\", {\n ownerType: owner.type,\n mode,\n hasDeferredAction: !!deferredAction,\n hasAccountAddress: !!accountAddress_,\n });\n\n const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;\n\n const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);\n\n const getFactoryArgs = async () => {\n if (is7702) {\n // This is only for EP 0.8.0.\n // return {\n // factory: \"0x7702\",\n // factoryData: \"0x\",\n // } as const;\n return {\n factory: undefined,\n factoryData: undefined,\n } as const;\n }\n\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [owner.address, salt],\n }),\n };\n };\n\n const accountAddress =\n accountAddress_ ??\n (is7702\n ? owner.address\n : factoryData_\n ? await getModularAccountV2AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData: factoryData_,\n implementationAddress,\n entryPoint: {\n version: \"0.7\",\n address: entryPoint07Address,\n },\n })\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: owner.address,\n }));\n\n LOGGER.debug(\"toModularAccountV2:address-resolved\", {\n accountAddress,\n is7702,\n });\n\n let authorization: ToSmartAccountParameters[\"authorization\"];\n if (is7702) {\n LOGGER.debug(\"toModularAccountV2:7702-mode\");\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // This may be extended in the future with additional MAv2-specific methods.\n };\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { concat, concatHex,
|
|
1
|
+
import { concat, concatHex, hashMessage, hashTypedData, maxUint32, maxUint152, zeroAddress, } from "viem";
|
|
2
2
|
import { entryPoint07Abi, entryPoint07Address, getUserOperationHash, toSmartAccount, } from "viem/account-abstraction";
|
|
3
3
|
import { getCode, readContract, signMessage, signTypedData, } from "viem/actions";
|
|
4
4
|
import { assertNever, BaseError } from "@alchemy/common";
|
|
5
5
|
import { SignaturePrefix, } from "../types.js";
|
|
6
6
|
import { modularAccountAbi } from "../abis/modularAccountAbi.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getAction, isAddressEqual } from "viem/utils";
|
|
8
8
|
import { DEFAULT_OWNER_ENTITY_ID, DefaultModuleAddress, EXECUTE_USER_OP_SELECTOR, serializeModuleEntity, } from "../utils/account.js";
|
|
9
9
|
import { parseDeferredAction } from "../utils/deferredActions.js";
|
|
10
10
|
import { pack1271Signature, toReplaySafeTypedData, packUOSignature, } from "../utils/signature.js";
|
|
@@ -12,6 +12,7 @@ import { InvalidDeferredActionNonceError } from "../../errors/InvalidDeferredAct
|
|
|
12
12
|
import { InvalidNonceKeyError } from "../../errors/InvalidNonceKeyError.js";
|
|
13
13
|
import { InvalidEntityIdError } from "../../errors/InvalidEntityIdError.js";
|
|
14
14
|
import { is7702Delegated } from "../../utils.js";
|
|
15
|
+
import { encodeCallsMAv2, decodeCallsMAv2 } from "./calldataCodec.js";
|
|
15
16
|
/**
|
|
16
17
|
* Creates a ModularAccountV2Base instance.
|
|
17
18
|
*
|
|
@@ -191,64 +192,16 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
191
192
|
const call = calls[0];
|
|
192
193
|
if (isAddressEqual(call.to, accountAddress)) {
|
|
193
194
|
// If the call is to the account itself, we need to avoid wrapping it in an `execute` call.
|
|
194
|
-
if (call.data
|
|
195
|
+
if (call.data == null) {
|
|
195
196
|
throw new BaseError("Data is required for an account self-call.");
|
|
196
197
|
}
|
|
197
198
|
return encodeCallData(call.data);
|
|
198
199
|
}
|
|
199
|
-
return encodeCallData(encodeFunctionData({
|
|
200
|
-
abi: modularAccountAbi,
|
|
201
|
-
functionName: "execute",
|
|
202
|
-
args: [call.to, call.value ?? 0n, call.data ?? "0x"],
|
|
203
|
-
}));
|
|
204
200
|
}
|
|
205
|
-
return encodeCallData(
|
|
206
|
-
abi: modularAccountAbi,
|
|
207
|
-
functionName: "executeBatch",
|
|
208
|
-
args: [
|
|
209
|
-
calls.map((call) => ({
|
|
210
|
-
target: call.to,
|
|
211
|
-
data: call.data ?? "0x",
|
|
212
|
-
value: call.value ?? 0n,
|
|
213
|
-
})),
|
|
214
|
-
],
|
|
215
|
-
}));
|
|
201
|
+
return encodeCallData(encodeCallsMAv2(calls));
|
|
216
202
|
},
|
|
217
203
|
async decodeCalls(data) {
|
|
218
|
-
|
|
219
|
-
// Trim the EXECUTE_USER_OP_SELECTOR if it is present.
|
|
220
|
-
const trimmedData = data
|
|
221
|
-
.toLowerCase()
|
|
222
|
-
.startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())
|
|
223
|
-
? sliceHex(data, 4)
|
|
224
|
-
: data;
|
|
225
|
-
const decoded = decodeFunctionData({
|
|
226
|
-
abi: modularAccountAbi,
|
|
227
|
-
data: trimmedData,
|
|
228
|
-
});
|
|
229
|
-
if (decoded.functionName === "execute") {
|
|
230
|
-
return [
|
|
231
|
-
{
|
|
232
|
-
to: decoded.args[0],
|
|
233
|
-
value: decoded.args[1],
|
|
234
|
-
data: decoded.args[2],
|
|
235
|
-
},
|
|
236
|
-
];
|
|
237
|
-
}
|
|
238
|
-
if (decoded.functionName === "executeBatch") {
|
|
239
|
-
return decoded.args[0].map((call) => ({
|
|
240
|
-
to: call.target,
|
|
241
|
-
value: call.value,
|
|
242
|
-
data: call.data,
|
|
243
|
-
}));
|
|
244
|
-
}
|
|
245
|
-
// If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.
|
|
246
|
-
return [
|
|
247
|
-
{
|
|
248
|
-
to: accountAddress,
|
|
249
|
-
data,
|
|
250
|
-
},
|
|
251
|
-
];
|
|
204
|
+
return decodeCallsMAv2(data, accountAddress);
|
|
252
205
|
},
|
|
253
206
|
async getStubSignature() {
|
|
254
207
|
const sig = packUOSignature({
|
|
@@ -276,7 +229,7 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
|
|
|
276
229
|
td.domain.verifyingContract === accountAddress;
|
|
277
230
|
const { data } = await prepareSignature({
|
|
278
231
|
type: "eth_signTypedData_v4",
|
|
279
|
-
data: td,
|
|
232
|
+
data: td,
|
|
280
233
|
});
|
|
281
234
|
const action = getAction(client, signTypedData, "signTypedData");
|
|
282
235
|
const signature = await action({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,aAAa,EAEb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EAEf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACL,eAAe,GAIhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,uBAAuB,EACv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,EAAE,cAAc;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YAExE,MAAM,mBAAmB,GAAG,MAAM,iBAAiB,CAAC;gBAClD,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;aACvB,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,eAAe,CAAC;gBACtC,mBAAmB;aACpB,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,kBAAkB;gBAClC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;gBAClD,CAAC,CAAC,eAAe,CAAC;YAEpB,kBAAkB,GAAG,SAAS,CAAC,CAAC,kBAAkB;YAClD,sBAAsB,GAAG,KAAK,CAAC,CAAC,+BAA+B;YAE/D,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,kBAA2B;YAC7C,YAAY,EAAE;gBACZ,QAAQ;gBACR,kBAAkB;aACnB;YACD,cAAc;YACd,gBAAgB;YAChB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Chain,\n type Client,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n concat,\n concatHex,\n encodeFunctionData,\n hashMessage,\n hashTypedData,\n type TypedDataDefinition,\n maxUint32,\n maxUint152,\n zeroAddress,\n} from \"viem\";\nimport {\n entryPoint07Abi,\n type SmartAccountImplementation,\n entryPoint07Address,\n getUserOperationHash,\n toSmartAccount,\n type ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport {\n getCode,\n readContract,\n signMessage,\n signTypedData,\n} from \"viem/actions\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport {\n SignaturePrefix,\n type ExecutionDataView,\n type SignerEntity,\n type ValidationDataView,\n} from \"../types.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport {\n decodeFunctionData,\n getAction,\n isAddressEqual,\n sliceHex,\n} from \"viem/utils\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n DefaultModuleAddress,\n EXECUTE_USER_OP_SELECTOR,\n serializeModuleEntity,\n} from \"../utils/account.js\";\nimport { parseDeferredAction } from \"../utils/deferredActions.js\";\nimport {\n pack1271Signature,\n toReplaySafeTypedData,\n packUOSignature,\n} from \"../utils/signature.js\";\nimport { InvalidDeferredActionNonceError } from \"../../errors/InvalidDeferredActionNonceError.js\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { InvalidEntityIdError } from \"../../errors/InvalidEntityIdError.js\";\nimport { is7702Delegated } from \"../../utils.js\";\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type BaseModularAccountV2Implementation = SmartAccountImplementation<\n typeof entryPoint07Abi,\n \"0.7\",\n {\n smartAccountType: \"ModularAccountV2\";\n signerEntity: SignerEntity;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n boolean\n>;\n\nexport type ModularAccountV2Base =\n SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;\n\nexport type ToModularAccountV2BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n accountAddress: Address;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n signerEntity?: SignerEntity;\n deferredAction?: Hex;\n authorization?: ToSmartAccountParameters[\"authorization\"];\n};\n\n/**\n * Creates a ModularAccountV2Base instance.\n *\n * @param {ToModularAccountV2BaseParams<TTransport>} params - The parameters for creating a ModularAccountV2Base instance.\n * @returns {Promise<ModularAccountV2Base>} A promise that resolves to a ModularAccountV2Base instance.\n */\nexport async function toModularAccountV2Base<\n TTransport extends Transport = Transport,\n>({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n deferredAction,\n authorization,\n}: ToModularAccountV2BaseParams<TTransport>): Promise<ModularAccountV2Base> {\n let { isGlobalValidation, entityId } = signerEntity;\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address as Address,\n version: \"0.7\" as const,\n };\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n let isDeployed = false;\n\n const isAccountDeployed: () => Promise<boolean> = async () => {\n if (isDeployed) {\n return true;\n }\n const action = getAction(client, getCode, \"getCode\");\n const code = await action({ address: accountAddress });\n isDeployed = authorization\n ? is7702Delegated(authorization.address, code)\n : !!code;\n return isDeployed;\n };\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n // Set these values if the deferred action has not been consumed. We check this with the EP.\n const nextNonceForDeferredAction: bigint = await readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, deferredActionNonce >> 64n],\n });\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonceError();\n }\n }\n\n const getNonce = async (\n params?: { key?: bigint | undefined } | undefined,\n ): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n const nonceKey = params?.key ?? 0n;\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n return readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, fullNonceKey],\n });\n };\n\n const accountContract = {\n address: accountAddress,\n abi: modularAccountAbi,\n };\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return readContract(client, {\n ...accountContract,\n functionName: \"getExecutionData\",\n args: [selector],\n });\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n const readContractAction = getAction(client, readContract, \"readContract\");\n return readContractAction({\n ...accountContract,\n functionName: \"getValidationData\",\n args: [\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ],\n });\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n return callData;\n };\n\n const prepareSignature = async (\n request: SignatureRequest,\n ): Promise<Extract<SignatureRequest, { type: \"eth_signTypedData_v4\" }>> => {\n const isDeferredAction =\n request.type === \"eth_signTypedData_v4\" &&\n request.data?.primaryType === \"DeferredAction\" &&\n request.data?.domain?.verifyingContract === accountAddress;\n\n if (isDeferredAction && entityId === DEFAULT_OWNER_ENTITY_ID) {\n return request;\n }\n\n const hash =\n request.type === \"personal_sign\"\n ? hashMessage(request.data)\n : request.type === \"eth_signTypedData_v4\"\n ? hashTypedData(request.data)\n : assertNever(request, \"Unexpected signature request type\");\n\n return {\n type: \"eth_signTypedData_v4\",\n data: toReplaySafeTypedData({\n chainId: client.chain.id,\n hash,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? { address: accountAddress }\n : {\n address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }),\n }),\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return pack1271Signature({\n entityId,\n validationSignaturePrefix: SignaturePrefix.EOA,\n validationSignature: signature,\n });\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n getNonce,\n authorization,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length === 1) {\n const call = calls[0];\n\n if (isAddressEqual(call.to, accountAddress)) {\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n\n if (call.data === undefined) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n }),\n );\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n data: call.data ?? \"0x\",\n value: call.value ?? 0n,\n })),\n ],\n }),\n );\n },\n\n async decodeCalls(data) {\n // Inverse of `encodeCalls`.\n // Trim the EXECUTE_USER_OP_SELECTOR if it is present.\n const trimmedData = data\n .toLowerCase()\n .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())\n ? sliceHex(data, 4)\n : data;\n\n const decoded = decodeFunctionData({\n abi: modularAccountAbi,\n data: trimmedData,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n },\n\n async getStubSignature() {\n const sig = packUOSignature({\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n async signMessage({ message }) {\n const { data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return formatSignature(signature);\n },\n\n async signTypedData(td) {\n const isDeferredAction =\n td.primaryType === \"DeferredAction\" &&\n td.domain &&\n typeof td.domain === \"object\" &&\n \"verifyingContract\" in td.domain &&\n td.domain.verifyingContract === accountAddress;\n\n const { data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: td as TypedDataDefinition, // TODO(v5): Try harder to satisfy this w/o casting.\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return isDeferredAction\n ? concat([SignaturePrefix.EOA, signature])\n : formatSignature(signature);\n },\n\n async signUserOperation(uo) {\n const hash = getUserOperationHash({\n chainId: uo.chainId ?? client.chain.id,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...uo,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const validationSignature = await signMessageAction({\n account: owner,\n message: { raw: hash },\n });\n\n const packedSignature = packUOSignature({\n validationSignature,\n });\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, packedSignature])\n : packedSignature;\n\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n\n return signature;\n },\n\n extend: {\n smartAccountType: \"ModularAccountV2\" as const,\n signerEntity: {\n entityId,\n isGlobalValidation,\n },\n encodeCallData,\n getExecutionData,\n getValidationData,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EACN,SAAS,EACT,WAAW,EACX,aAAa,EAEb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EAEf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACL,eAAe,GAIhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mB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,eAAe,CAAC;gBACtC,mBAAmB;aACpB,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,kBAAkB;gBAClC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;gBAClD,CAAC,CAAC,eAAe,CAAC;YAEpB,kBAAkB,GAAG,SAAS,CAAC,CAAC,kBAAkB;YAClD,sBAAsB,GAAG,KAAK,CAAC,CAAC,+BAA+B;YAE/D,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,kBAA2B;YAC7C,YAAY,EAAE;gBACZ,QAAQ;gBACR,kBAAkB;aACnB;YACD,cAAc;YACd,gBAAgB;YAChB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Chain,\n type Client,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n concat,\n concatHex,\n hashMessage,\n hashTypedData,\n type TypedDataDefinition,\n maxUint32,\n maxUint152,\n zeroAddress,\n} from \"viem\";\nimport {\n entryPoint07Abi,\n type SmartAccountImplementation,\n entryPoint07Address,\n getUserOperationHash,\n toSmartAccount,\n type ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport {\n getCode,\n readContract,\n signMessage,\n signTypedData,\n} from \"viem/actions\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport {\n SignaturePrefix,\n type ExecutionDataView,\n type SignerEntity,\n type ValidationDataView,\n} from \"../types.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { getAction, isAddressEqual } from \"viem/utils\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n DefaultModuleAddress,\n EXECUTE_USER_OP_SELECTOR,\n serializeModuleEntity,\n} from \"../utils/account.js\";\nimport { parseDeferredAction } from \"../utils/deferredActions.js\";\nimport {\n pack1271Signature,\n toReplaySafeTypedData,\n packUOSignature,\n} from \"../utils/signature.js\";\nimport { InvalidDeferredActionNonceError } from \"../../errors/InvalidDeferredActionNonceError.js\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { InvalidEntityIdError } from \"../../errors/InvalidEntityIdError.js\";\nimport { is7702Delegated } from \"../../utils.js\";\nimport { encodeCallsMAv2, decodeCallsMAv2 } from \"./calldataCodec.js\";\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type BaseModularAccountV2Implementation = SmartAccountImplementation<\n typeof entryPoint07Abi,\n \"0.7\",\n {\n smartAccountType: \"ModularAccountV2\";\n signerEntity: SignerEntity;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n boolean\n>;\n\nexport type ModularAccountV2Base =\n SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;\n\nexport type ToModularAccountV2BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n accountAddress: Address;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n signerEntity?: SignerEntity;\n deferredAction?: Hex;\n authorization?: ToSmartAccountParameters[\"authorization\"];\n};\n\n/**\n * Creates a ModularAccountV2Base instance.\n *\n * @param {ToModularAccountV2BaseParams<TTransport>} params - The parameters for creating a ModularAccountV2Base instance.\n * @returns {Promise<ModularAccountV2Base>} A promise that resolves to a ModularAccountV2Base instance.\n */\nexport async function toModularAccountV2Base<\n TTransport extends Transport = Transport,\n>({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n deferredAction,\n authorization,\n}: ToModularAccountV2BaseParams<TTransport>): Promise<ModularAccountV2Base> {\n let { isGlobalValidation, entityId } = signerEntity;\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address as Address,\n version: \"0.7\" as const,\n };\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n let isDeployed = false;\n\n const isAccountDeployed: () => Promise<boolean> = async () => {\n if (isDeployed) {\n return true;\n }\n const action = getAction(client, getCode, \"getCode\");\n const code = await action({ address: accountAddress });\n isDeployed = authorization\n ? is7702Delegated(authorization.address, code)\n : !!code;\n return isDeployed;\n };\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n // Set these values if the deferred action has not been consumed. We check this with the EP.\n const nextNonceForDeferredAction: bigint = await readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, deferredActionNonce >> 64n],\n });\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonceError();\n }\n }\n\n const getNonce = async (\n params?: { key?: bigint | undefined } | undefined,\n ): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n const nonceKey = params?.key ?? 0n;\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n return readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, fullNonceKey],\n });\n };\n\n const accountContract = {\n address: accountAddress,\n abi: modularAccountAbi,\n };\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return readContract(client, {\n ...accountContract,\n functionName: \"getExecutionData\",\n args: [selector],\n });\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n const readContractAction = getAction(client, readContract, \"readContract\");\n return readContractAction({\n ...accountContract,\n functionName: \"getValidationData\",\n args: [\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ],\n });\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n return callData;\n };\n\n const prepareSignature = async (\n request: SignatureRequest,\n ): Promise<Extract<SignatureRequest, { type: \"eth_signTypedData_v4\" }>> => {\n const isDeferredAction =\n request.type === \"eth_signTypedData_v4\" &&\n request.data?.primaryType === \"DeferredAction\" &&\n request.data?.domain?.verifyingContract === accountAddress;\n\n if (isDeferredAction && entityId === DEFAULT_OWNER_ENTITY_ID) {\n return request;\n }\n\n const hash =\n request.type === \"personal_sign\"\n ? hashMessage(request.data)\n : request.type === \"eth_signTypedData_v4\"\n ? hashTypedData(request.data)\n : assertNever(request, \"Unexpected signature request type\");\n\n return {\n type: \"eth_signTypedData_v4\",\n data: toReplaySafeTypedData({\n chainId: client.chain.id,\n hash,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? { address: accountAddress }\n : {\n address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }),\n }),\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return pack1271Signature({\n entityId,\n validationSignaturePrefix: SignaturePrefix.EOA,\n validationSignature: signature,\n });\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n getNonce,\n authorization,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length === 1) {\n const call = calls[0];\n\n if (isAddressEqual(call.to, accountAddress)) {\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n\n if (call.data == null) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n }\n\n return encodeCallData(encodeCallsMAv2(calls));\n },\n\n async decodeCalls(data) {\n return decodeCallsMAv2(data, accountAddress);\n },\n\n async getStubSignature() {\n const sig = packUOSignature({\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n async signMessage({ message }) {\n const { data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return formatSignature(signature);\n },\n\n async signTypedData(td) {\n const isDeferredAction =\n td.primaryType === \"DeferredAction\" &&\n td.domain &&\n typeof td.domain === \"object\" &&\n \"verifyingContract\" in td.domain &&\n td.domain.verifyingContract === accountAddress;\n\n const { data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: td as TypedDataDefinition,\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return isDeferredAction\n ? concat([SignaturePrefix.EOA, signature])\n : formatSignature(signature);\n },\n\n async signUserOperation(uo) {\n const hash = getUserOperationHash({\n chainId: uo.chainId ?? client.chain.id,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...uo,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const validationSignature = await signMessageAction({\n account: owner,\n message: { raw: hash },\n });\n\n const packedSignature = packUOSignature({\n validationSignature,\n });\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, packedSignature])\n : packedSignature;\n\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n\n return signature;\n },\n\n extend: {\n smartAccountType: \"ModularAccountV2\" as const,\n signerEntity: {\n entityId,\n isGlobalValidation,\n },\n encodeCallData,\n getExecutionData,\n getValidationData,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type Address, type Call, type Hex } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Encodes an array of calls into ModularAccountV2 calldata for `execute` or `executeBatch`.
|
|
4
|
+
* Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed
|
|
5
|
+
* directly unless you have an advanced use case.
|
|
6
|
+
*
|
|
7
|
+
* @param {Call[]} calls The calls to encode.
|
|
8
|
+
* @returns {Hex} The encoded calldata.
|
|
9
|
+
*/
|
|
10
|
+
export declare function encodeCallsMAv2(calls: readonly Call[]): Hex;
|
|
11
|
+
/**
|
|
12
|
+
* Decodes ModularAccountV2 calldata back into an array of calls. Strips the `EXECUTE_USER_OP_SELECTOR` prefix if present.
|
|
13
|
+
* Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed
|
|
14
|
+
* directly unless you have an advanced use case.
|
|
15
|
+
*
|
|
16
|
+
* @param {Hex} data The calldata to decode.
|
|
17
|
+
* @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.
|
|
18
|
+
* @returns {Call[]} The decoded calls.
|
|
19
|
+
*/
|
|
20
|
+
export declare function decodeCallsMAv2(data: Hex, accountAddress: Address): Call[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { decodeFunctionData, encodeFunctionData, } from "viem";
|
|
2
|
+
import { sliceHex } from "viem/utils";
|
|
3
|
+
import { modularAccountAbi } from "../abis/modularAccountAbi.js";
|
|
4
|
+
import { EXECUTE_USER_OP_SELECTOR } from "../utils/account.js";
|
|
5
|
+
/**
|
|
6
|
+
* Encodes an array of calls into ModularAccountV2 calldata for `execute` or `executeBatch`.
|
|
7
|
+
* Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed
|
|
8
|
+
* directly unless you have an advanced use case.
|
|
9
|
+
*
|
|
10
|
+
* @param {Call[]} calls The calls to encode.
|
|
11
|
+
* @returns {Hex} The encoded calldata.
|
|
12
|
+
*/
|
|
13
|
+
export function encodeCallsMAv2(calls) {
|
|
14
|
+
if (calls.length === 1) {
|
|
15
|
+
return encodeFunctionData({
|
|
16
|
+
abi: modularAccountAbi,
|
|
17
|
+
functionName: "execute",
|
|
18
|
+
args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? "0x"],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return encodeFunctionData({
|
|
22
|
+
abi: modularAccountAbi,
|
|
23
|
+
functionName: "executeBatch",
|
|
24
|
+
args: [
|
|
25
|
+
calls.map((call) => ({
|
|
26
|
+
target: call.to,
|
|
27
|
+
data: call.data ?? "0x",
|
|
28
|
+
value: call.value ?? 0n,
|
|
29
|
+
})),
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Decodes ModularAccountV2 calldata back into an array of calls. Strips the `EXECUTE_USER_OP_SELECTOR` prefix if present.
|
|
35
|
+
* Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed
|
|
36
|
+
* directly unless you have an advanced use case.
|
|
37
|
+
*
|
|
38
|
+
* @param {Hex} data The calldata to decode.
|
|
39
|
+
* @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.
|
|
40
|
+
* @returns {Call[]} The decoded calls.
|
|
41
|
+
*/
|
|
42
|
+
export function decodeCallsMAv2(data, accountAddress) {
|
|
43
|
+
// Strip the EXECUTE_USER_OP_SELECTOR prefix if present.
|
|
44
|
+
const trimmedData = data
|
|
45
|
+
.toLowerCase()
|
|
46
|
+
.startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())
|
|
47
|
+
? sliceHex(data, 4)
|
|
48
|
+
: data;
|
|
49
|
+
const decoded = decodeFunctionData({
|
|
50
|
+
abi: modularAccountAbi,
|
|
51
|
+
data: trimmedData,
|
|
52
|
+
});
|
|
53
|
+
if (decoded.functionName === "execute") {
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
to: decoded.args[0],
|
|
57
|
+
value: decoded.args[1],
|
|
58
|
+
data: decoded.args[2],
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
if (decoded.functionName === "executeBatch") {
|
|
63
|
+
return decoded.args[0].map((call) => ({
|
|
64
|
+
to: call.target,
|
|
65
|
+
value: call.value,
|
|
66
|
+
data: call.data,
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
// If the data is not for an `execute` or `executeBatch` call, treat it as a single call to the account itself.
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
to: accountAddress,
|
|
73
|
+
data,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=calldataCodec.js.map
|
|
@@ -0,0 +1 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CAAC;QACnD,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QACnB,CAAC,CAAC,IAAI,CAAC;IAET,MAAM,OAAO,GAAG,kBAAkB,CAAC;QACjC,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,WAAW;KAClB,CAAC,CAAC;IAEH,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO;YACL;gBACE,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;gBACnB,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;gBACtB,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;aACtB;SACF,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,CAAC,YAAY,KAAK,cAAc,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACpC,EAAE,EAAE,IAAI,CAAC,MAAM;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC,CAAC,CAAC;IACN,CAAC;IAED,+GAA+G;IAC/G,OAAO;QACL;YACE,EAAE,EAAE,cAAc;YAClB,IAAI;SACL;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n decodeFunctionData,\n encodeFunctionData,\n type Address,\n type Call,\n type Hex,\n} from \"viem\";\nimport { sliceHex } from \"viem/utils\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport { EXECUTE_USER_OP_SELECTOR } from \"../utils/account.js\";\n\n/**\n * Encodes an array of calls into ModularAccountV2 calldata for `execute` or `executeBatch`.\n * Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed\n * directly unless you have an advanced use case.\n *\n * @param {Call[]} calls The calls to encode.\n * @returns {Hex} The encoded calldata.\n */\nexport function encodeCallsMAv2(calls: readonly Call[]): Hex {\n if (calls.length === 1) {\n return encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [calls[0].to, calls[0].value ?? 0n, calls[0].data ?? \"0x\"],\n });\n }\n\n return encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n data: call.data ?? \"0x\",\n value: call.value ?? 0n,\n })),\n ],\n });\n}\n\n/**\n * Decodes ModularAccountV2 calldata back into an array of calls. Strips the `EXECUTE_USER_OP_SELECTOR` prefix if present.\n * Used internally by the ModularAccountV2 SmartAccount implementation. Typically not needed\n * directly unless you have an advanced use case.\n *\n * @param {Hex} data The calldata to decode.\n * @param {Address} accountAddress The account address, used as the `to` for unrecognized selectors.\n * @returns {Call[]} The decoded calls.\n */\nexport function decodeCallsMAv2(data: Hex, accountAddress: Address): Call[] {\n // Strip the EXECUTE_USER_OP_SELECTOR prefix if present.\n const trimmedData = data\n .toLowerCase()\n .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())\n ? sliceHex(data, 4)\n : data;\n\n const decoded = decodeFunctionData({\n abi: modularAccountAbi,\n data: trimmedData,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { type Address, type Client, type Hex, type IsUndefined, type Chain, type
|
|
|
2
2
|
import type { HookConfig, ValidationConfig } from "../types.js";
|
|
3
3
|
import type { ModularAccountV2 } from "../accounts/account.js";
|
|
4
4
|
import type { GetAccountParameter } from "../../types.js";
|
|
5
|
-
import {
|
|
5
|
+
import type { SmartAccount } from "viem/account-abstraction";
|
|
6
6
|
export type InstallValidationParams<TAccount extends SmartAccount | undefined = SmartAccount | undefined> = {
|
|
7
7
|
validationConfig: ValidationConfig;
|
|
8
8
|
selectors: Hex[];
|
|
@@ -20,27 +20,23 @@ export type UninstallValidationParams<TAccount extends SmartAccount | undefined
|
|
|
20
20
|
} & GetAccountParameter<TAccount, ModularAccountV2>;
|
|
21
21
|
export type InstallValidationActions<TAccount extends SmartAccount | undefined = SmartAccount | undefined> = {
|
|
22
22
|
encodeInstallValidation: (args: InstallValidationParams<TAccount>) => Promise<Hex>;
|
|
23
|
-
installValidation: (args: InstallValidationParams<TAccount>) => Promise<Hex>;
|
|
24
23
|
encodeUninstallValidation: (args: UninstallValidationParams<TAccount>) => Promise<Hex>;
|
|
25
|
-
uninstallValidation: (args: UninstallValidationParams<TAccount>) => Promise<Hex>;
|
|
26
24
|
};
|
|
27
25
|
/**
|
|
28
|
-
* Provides validation installation and uninstallation functionalities for a MA v2 client
|
|
26
|
+
* Provides validation installation and uninstallation encoding functionalities for a MA v2 client.
|
|
29
27
|
*
|
|
30
28
|
* @example
|
|
31
29
|
* ```ts
|
|
32
|
-
* import {
|
|
30
|
+
* import { installValidationActions, SingleSignerValidationModule } from "@alchemy/smart-accounts";
|
|
33
31
|
* import { Address } from "viem";
|
|
34
32
|
*
|
|
35
33
|
* const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);
|
|
36
34
|
* const sessionKeyAddress: Address = "0x1234";
|
|
37
35
|
* const sessionKeyEntityId: number = 1;
|
|
38
36
|
*
|
|
39
|
-
* await client.
|
|
37
|
+
* const callData = await client.encodeInstallValidation({
|
|
40
38
|
* validationConfig: {
|
|
41
|
-
* moduleAddress: getDefaultSingleSignerValidationModuleAddress(
|
|
42
|
-
* client.chain
|
|
43
|
-
* ),
|
|
39
|
+
* moduleAddress: getDefaultSingleSignerValidationModuleAddress(client.chain),
|
|
44
40
|
* entityId: sessionKeyEntityId,
|
|
45
41
|
* isGlobal: true,
|
|
46
42
|
* isSignatureValidation: false,
|
|
@@ -54,18 +50,10 @@ export type InstallValidationActions<TAccount extends SmartAccount | undefined =
|
|
|
54
50
|
* hooks: [],
|
|
55
51
|
* });
|
|
56
52
|
*
|
|
57
|
-
* await client.
|
|
58
|
-
* moduleAddress: sessionKeyAddress,
|
|
59
|
-
* entityId: sessionKeyEntityId,
|
|
60
|
-
* uninstallData: SingleSignerValidationModule.encodeOnUninstallData({
|
|
61
|
-
* entityId: sessionKeyEntityId,
|
|
62
|
-
* }),
|
|
63
|
-
* hookUninstallDatas: [],
|
|
64
|
-
* });
|
|
65
|
-
*
|
|
53
|
+
* await client.sendUserOperation({ callData, account });
|
|
66
54
|
* ```
|
|
67
55
|
*
|
|
68
|
-
* @param {object} client - The client instance which provides account
|
|
69
|
-
* @returns {object} - An object containing
|
|
56
|
+
* @param {object} client - The client instance which provides account functionality.
|
|
57
|
+
* @returns {object} - An object containing `encodeInstallValidation` and `encodeUninstallValidation`.
|
|
70
58
|
*/
|
|
71
59
|
export declare function installValidationActions<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartAccount | undefined = SmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>): InstallValidationActions<IsUndefined<TAccount> extends true ? undefined : ModularAccountV2>;
|
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
import { zeroAddress, concatHex, encodeFunctionData, } from "viem";
|
|
2
2
|
import { semiModularAccountBytecodeAbi } from "../abis/semiModularAccountBytecodeAbi.js";
|
|
3
|
-
import { sendUserOperation } from "viem/account-abstraction";
|
|
4
|
-
import { getAction } from "viem/utils";
|
|
5
3
|
import { AccountNotFoundError } from "@alchemy/common";
|
|
6
4
|
import { EntityIdOverrideError } from "../../errors/EntityIdOverrideError.js";
|
|
7
5
|
import { serializeHookConfig, serializeValidationConfig, } from "../utils/hooks.js";
|
|
8
6
|
import { DEFAULT_OWNER_ENTITY_ID, isModularAccountV2, serializeModuleEntity, } from "../utils/account.js";
|
|
9
|
-
// TODO(v5): update jsdoc
|
|
10
7
|
/**
|
|
11
|
-
* Provides validation installation and uninstallation functionalities for a MA v2 client
|
|
8
|
+
* Provides validation installation and uninstallation encoding functionalities for a MA v2 client.
|
|
12
9
|
*
|
|
13
10
|
* @example
|
|
14
11
|
* ```ts
|
|
15
|
-
* import {
|
|
12
|
+
* import { installValidationActions, SingleSignerValidationModule } from "@alchemy/smart-accounts";
|
|
16
13
|
* import { Address } from "viem";
|
|
17
14
|
*
|
|
18
15
|
* const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);
|
|
19
16
|
* const sessionKeyAddress: Address = "0x1234";
|
|
20
17
|
* const sessionKeyEntityId: number = 1;
|
|
21
18
|
*
|
|
22
|
-
* await client.
|
|
19
|
+
* const callData = await client.encodeInstallValidation({
|
|
23
20
|
* validationConfig: {
|
|
24
|
-
* moduleAddress: getDefaultSingleSignerValidationModuleAddress(
|
|
25
|
-
* client.chain
|
|
26
|
-
* ),
|
|
21
|
+
* moduleAddress: getDefaultSingleSignerValidationModuleAddress(client.chain),
|
|
27
22
|
* entityId: sessionKeyEntityId,
|
|
28
23
|
* isGlobal: true,
|
|
29
24
|
* isSignatureValidation: false,
|
|
@@ -37,19 +32,11 @@ import { DEFAULT_OWNER_ENTITY_ID, isModularAccountV2, serializeModuleEntity, } f
|
|
|
37
32
|
* hooks: [],
|
|
38
33
|
* });
|
|
39
34
|
*
|
|
40
|
-
* await client.
|
|
41
|
-
* moduleAddress: sessionKeyAddress,
|
|
42
|
-
* entityId: sessionKeyEntityId,
|
|
43
|
-
* uninstallData: SingleSignerValidationModule.encodeOnUninstallData({
|
|
44
|
-
* entityId: sessionKeyEntityId,
|
|
45
|
-
* }),
|
|
46
|
-
* hookUninstallDatas: [],
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
35
|
+
* await client.sendUserOperation({ callData, account });
|
|
49
36
|
* ```
|
|
50
37
|
*
|
|
51
|
-
* @param {object} client - The client instance which provides account
|
|
52
|
-
* @returns {object} - An object containing
|
|
38
|
+
* @param {object} client - The client instance which provides account functionality.
|
|
39
|
+
* @returns {object} - An object containing `encodeInstallValidation` and `encodeUninstallValidation`.
|
|
53
40
|
*/
|
|
54
41
|
export function installValidationActions(client) {
|
|
55
42
|
const encodeInstallValidation = async (args) => {
|
|
@@ -94,44 +81,6 @@ export function installValidationActions(client) {
|
|
|
94
81
|
return {
|
|
95
82
|
encodeInstallValidation,
|
|
96
83
|
encodeUninstallValidation,
|
|
97
|
-
installValidation: async (args) => {
|
|
98
|
-
const { validationConfig, selectors, installData, hooks, account = client.account, } = args;
|
|
99
|
-
if (!account || !isModularAccountV2(account)) {
|
|
100
|
-
throw new AccountNotFoundError();
|
|
101
|
-
}
|
|
102
|
-
const callData = await encodeInstallValidation({
|
|
103
|
-
validationConfig,
|
|
104
|
-
selectors,
|
|
105
|
-
installData,
|
|
106
|
-
hooks,
|
|
107
|
-
account,
|
|
108
|
-
});
|
|
109
|
-
const action = getAction(client, sendUserOperation, "sendUserOperation");
|
|
110
|
-
const result = await action({
|
|
111
|
-
callData,
|
|
112
|
-
account,
|
|
113
|
-
});
|
|
114
|
-
return result;
|
|
115
|
-
},
|
|
116
|
-
uninstallValidation: async (args) => {
|
|
117
|
-
const { moduleAddress, entityId, uninstallData, hookUninstallDatas, account = client.account, } = args;
|
|
118
|
-
if (!account || !isModularAccountV2(account)) {
|
|
119
|
-
throw new AccountNotFoundError();
|
|
120
|
-
}
|
|
121
|
-
const callData = await encodeUninstallValidation({
|
|
122
|
-
moduleAddress,
|
|
123
|
-
entityId,
|
|
124
|
-
uninstallData,
|
|
125
|
-
hookUninstallDatas,
|
|
126
|
-
account,
|
|
127
|
-
});
|
|
128
|
-
const action = getAction(client, sendUserOperation, "sendUserOperation");
|
|
129
|
-
const result = await action({
|
|
130
|
-
callData,
|
|
131
|
-
account,
|
|
132
|
-
});
|
|
133
|
-
return result;
|
|
134
|
-
},
|
|
135
84
|
};
|
|
136
85
|
}
|
|
137
86
|
//# sourceMappingURL=installValidation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"installValidation.js","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/installValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,kBAAkB,GACnB,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AACzF,OAAO,EAAqB,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAsC7B,yBAAyB;AACzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,wBAAwB,CAKtC,MAA4C;IAI5C,MAAM,uBAAuB,GAAG,KAAK,EACnC,IAEC,EACD,EAAE;QACF,MAAM,EACJ,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,KAAK,EACL,OAAO,GAAG,MAAM,CAAC,OAAO,GACzB,GAAG,IAAI,CAAC;QAET,IAAI,CAAC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,4GAA4G;QAC5G,IACE,gBAAgB,CAAC,QAAQ,KAAK,uBAAuB;YACrD,gBAAgB,CAAC,aAAa,KAAK,WAAW,EAC9C,CAAC;YACD,MAAM,IAAI,qBAAqB,EAAE,CAAC;QACpC,CAAC;QAED,OAAO,OAAO,CAAC,cAAc,CAC3B,kBAAkB,CAAC;YACjB,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M,QAAQ,GAAG,MAAM,uBAAuB,CAAC;gBAC7C,gBAAgB;gBAChB,SAAS;gBACT,WAAW;gBACX,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;YACzE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC;gBAC1B,QAAQ;gBACR,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,mBAAmB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAClC,MAAM,EACJ,aAAa,EACb,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,OAAO,GAAG,MAAM,CAAC,OAAO,GACzB,GAAG,IAAI,CAAC;YAET,IAAI,CAAC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC7C,MAAM,IAAI,oBAAoB,EAAE,CAAC;YACnC,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,yBAAyB,CAAC;gBAC/C,aAAa;gBACb,QAAQ;gBACR,aAAa;gBACb,kBAAkB;gBAClB,OAAO;aACR,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,mBAAmB,CAAC,CAAC;YACzE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC;gBAC1B,QAAQ;gBACR,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Address,\n type Client,\n type Hex,\n type IsUndefined,\n type Chain,\n type Transport,\n zeroAddress,\n concatHex,\n encodeFunctionData,\n} from \"viem\";\nimport type { HookConfig, ValidationConfig } from \"../types.js\";\nimport type { ModularAccountV2 } from \"../accounts/account.js\";\nimport type { GetAccountParameter } from \"../../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"../abis/semiModularAccountBytecodeAbi.js\";\nimport { type SmartAccount, sendUserOperation } from \"viem/account-abstraction\";\nimport { getAction } from \"viem/utils\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport {\n serializeHookConfig,\n serializeValidationConfig,\n} from \"../utils/hooks.js\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n isModularAccountV2,\n serializeModuleEntity,\n} from \"../utils/account.js\";\n\nexport type InstallValidationParams<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n validationConfig: ValidationConfig;\n selectors: Hex[];\n installData: Hex;\n hooks: {\n hookConfig: HookConfig;\n initData: Hex;\n }[];\n} & GetAccountParameter<TAccount, ModularAccountV2>;\n\nexport type UninstallValidationParams<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n moduleAddress: Address;\n entityId: number;\n uninstallData: Hex;\n hookUninstallDatas: Hex[];\n} & GetAccountParameter<TAccount, ModularAccountV2>;\n\nexport type InstallValidationActions<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n encodeInstallValidation: (\n args: InstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n installValidation: (args: InstallValidationParams<TAccount>) => Promise<Hex>;\n encodeUninstallValidation: (\n args: UninstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n uninstallValidation: (\n args: UninstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n};\n\n// TODO(v5): update jsdoc\n/**\n * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @example\n * ```ts\n * import { createModularAccountV2Client, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from \"@alchemy/smart-accounts\";\n * import { Address } from \"viem\";\n *\n * const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);\n * const sessionKeyAddress: Address = \"0x1234\";\n * const sessionKeyEntityId: number = 1;\n *\n * await client.installValidation({\n * validationConfig: {\n * moduleAddress: getDefaultSingleSignerValidationModuleAddress(\n * client.chain\n * ),\n * entityId: sessionKeyEntityId,\n * isGlobal: true,\n * isSignatureValidation: false,\n * isUserOpValidation: true,\n * },\n * selectors: [],\n * installData: SingleSignerValidationModule.encodeOnInstallData({\n * entityId: sessionKeyEntityId,\n * signer: sessionKeyAddress,\n * }),\n * hooks: [],\n * });\n *\n * await client.uninstallValidation({\n * moduleAddress: sessionKeyAddress,\n * entityId: sessionKeyEntityId,\n * uninstallData: SingleSignerValidationModule.encodeOnUninstallData({\n * entityId: sessionKeyEntityId,\n * }),\n * hookUninstallDatas: [],\n * });\n *\n * ```\n *\n * @param {object} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.\n */\nexport function installValidationActions<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): InstallValidationActions<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n> {\n const encodeInstallValidation = async (\n args: InstallValidationParams<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n >,\n ) => {\n const {\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n // An entityId of zero is only allowed if we're installing or uninstalling hooks on the fallback validation.\n if (\n validationConfig.entityId === DEFAULT_OWNER_ENTITY_ID &&\n validationConfig.moduleAddress !== zeroAddress\n ) {\n throw new EntityIdOverrideError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"installValidation\",\n args: [\n serializeValidationConfig(validationConfig),\n selectors,\n installData,\n hooks.map((hook: { hookConfig: HookConfig; initData: Hex }) =>\n concatHex([serializeHookConfig(hook.hookConfig), hook.initData]),\n ),\n ],\n }),\n );\n };\n\n const encodeUninstallValidation = async (\n args: UninstallValidationParams<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n >,\n ) => {\n const {\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"uninstallValidation\",\n args: [\n serializeModuleEntity({\n moduleAddress,\n entityId,\n }),\n uninstallData,\n hookUninstallDatas,\n ],\n }),\n );\n };\n\n return {\n encodeInstallValidation,\n encodeUninstallValidation,\n installValidation: async (args) => {\n const {\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n const callData = await encodeInstallValidation({\n validationConfig,\n selectors,\n installData,\n hooks,\n account,\n });\n\n const action = getAction(client, sendUserOperation, \"sendUserOperation\");\n const result = await action({\n callData,\n account,\n });\n\n return result;\n },\n\n uninstallValidation: async (args) => {\n const {\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n const callData = await encodeUninstallValidation({\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account,\n });\n\n const action = getAction(client, sendUserOperation, \"sendUserOperation\");\n const result = await action({\n callData,\n account,\n });\n\n return result;\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"installValidation.js","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/installValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,WAAW,EACX,SAAS,EACT,kBAAkB,GACnB,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,6BAA6B,EAAE,MAAM,0CAA0C,CAAC;AAEzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EA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kB,EAClB,OAAO,GAAG,MAAM,CAAC,OAAO,GACzB,GAAG,IAAI,CAAC;QAET,IAAI,CAAC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,OAAO,OAAO,CAAC,cAAc,CAC3B,kBAAkB,CAAC;YACjB,GAAG,EAAE,6BAA6B;YAClC,YAAY,EAAE,qBAAqB;YACnC,IAAI,EAAE;gBACJ,qBAAqB,CAAC;oBACpB,aAAa;oBACb,QAAQ;iBACT,CAAC;gBACF,aAAa;gBACb,kBAAkB;aACnB;SACF,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,uBAAuB;QACvB,yBAAyB;KAC1B,CAAC;AACJ,CAAC","sourcesContent":["import {\n type Address,\n type Client,\n type Hex,\n type IsUndefined,\n type Chain,\n type Transport,\n zeroAddress,\n concatHex,\n encodeFunctionData,\n} from \"viem\";\nimport type { HookConfig, ValidationConfig } from \"../types.js\";\nimport type { ModularAccountV2 } from \"../accounts/account.js\";\nimport type { GetAccountParameter } from \"../../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"../abis/semiModularAccountBytecodeAbi.js\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { AccountNotFoundError } from \"@alchemy/common\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport {\n serializeHookConfig,\n serializeValidationConfig,\n} from \"../utils/hooks.js\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n isModularAccountV2,\n serializeModuleEntity,\n} from \"../utils/account.js\";\n\nexport type InstallValidationParams<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n validationConfig: ValidationConfig;\n selectors: Hex[];\n installData: Hex;\n hooks: {\n hookConfig: HookConfig;\n initData: Hex;\n }[];\n} & GetAccountParameter<TAccount, ModularAccountV2>;\n\nexport type UninstallValidationParams<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n moduleAddress: Address;\n entityId: number;\n uninstallData: Hex;\n hookUninstallDatas: Hex[];\n} & GetAccountParameter<TAccount, ModularAccountV2>;\n\nexport type InstallValidationActions<\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = {\n encodeInstallValidation: (\n args: InstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n encodeUninstallValidation: (\n args: UninstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n};\n\n/**\n * Provides validation installation and uninstallation encoding functionalities for a MA v2 client.\n *\n * @example\n * ```ts\n * import { installValidationActions, SingleSignerValidationModule } from \"@alchemy/smart-accounts\";\n * import { Address } from \"viem\";\n *\n * const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);\n * const sessionKeyAddress: Address = \"0x1234\";\n * const sessionKeyEntityId: number = 1;\n *\n * const callData = await client.encodeInstallValidation({\n * validationConfig: {\n * moduleAddress: getDefaultSingleSignerValidationModuleAddress(client.chain),\n * entityId: sessionKeyEntityId,\n * isGlobal: true,\n * isSignatureValidation: false,\n * isUserOpValidation: true,\n * },\n * selectors: [],\n * installData: SingleSignerValidationModule.encodeOnInstallData({\n * entityId: sessionKeyEntityId,\n * signer: sessionKeyAddress,\n * }),\n * hooks: [],\n * });\n *\n * await client.sendUserOperation({ callData, account });\n * ```\n *\n * @param {object} client - The client instance which provides account functionality.\n * @returns {object} - An object containing `encodeInstallValidation` and `encodeUninstallValidation`.\n */\nexport function installValidationActions<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): InstallValidationActions<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n> {\n const encodeInstallValidation = async (\n args: InstallValidationParams<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n >,\n ) => {\n const {\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n // An entityId of zero is only allowed if we're installing or uninstalling hooks on the fallback validation.\n if (\n validationConfig.entityId === DEFAULT_OWNER_ENTITY_ID &&\n validationConfig.moduleAddress !== zeroAddress\n ) {\n throw new EntityIdOverrideError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"installValidation\",\n args: [\n serializeValidationConfig(validationConfig),\n selectors,\n installData,\n hooks.map((hook: { hookConfig: HookConfig; initData: Hex }) =>\n concatHex([serializeHookConfig(hook.hookConfig), hook.initData]),\n ),\n ],\n }),\n );\n };\n\n const encodeUninstallValidation = async (\n args: UninstallValidationParams<\n IsUndefined<TAccount> extends true ? undefined : ModularAccountV2\n >,\n ) => {\n const {\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n } = args;\n\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"uninstallValidation\",\n args: [\n serializeModuleEntity({\n moduleAddress,\n entityId,\n }),\n uninstallData,\n hookUninstallDatas,\n ],\n }),\n );\n };\n\n return {\n encodeInstallValidation,\n encodeUninstallValidation,\n };\n}\n"]}
|
|
@@ -10,14 +10,10 @@ export type SemiModularAccountV2FactoryArgs = {
|
|
|
10
10
|
export type SemiModularAccountV2StaticImpl = StaticSmartAccountImplementation<false, "0.7", SemiModularAccountV2FactoryArgs, typeof entryPoint07Abi, typeof semiModularAccountBytecodeAbi, typeof accountFactoryAbi>;
|
|
11
11
|
/**
|
|
12
12
|
* Static implementation logic for SemiModularAccountV2.
|
|
13
|
-
*
|
|
14
|
-
* TODO(v5): update JSDoc format when doc-gen supports structs or records.
|
|
15
13
|
*/
|
|
16
14
|
export declare const semiModularAccountV2StaticImpl: SemiModularAccountV2StaticImpl;
|
|
17
15
|
export type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<true, "0.7", SemiModularAccountV2FactoryArgs, typeof entryPoint07Abi, typeof semiModularAccountBytecodeAbi, typeof accountFactoryAbi>;
|
|
18
16
|
/**
|
|
19
17
|
* Static implementation logic for SemiModularAccount7702.
|
|
20
|
-
*
|
|
21
|
-
* TODO(v5): update JSDoc format when doc-gen supports structs or records.
|
|
22
18
|
*/
|
|
23
19
|
export declare const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl;
|