@account-kit/smart-contracts 4.32.0 → 4.33.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/light-account/abis/OZ_ERC1967Proxy.d.ts +13 -0
- package/dist/esm/src/light-account/abis/OZ_ERC1967Proxy.js +20 -0
- package/dist/esm/src/light-account/abis/OZ_ERC1967Proxy.js.map +1 -0
- package/dist/esm/src/light-account/accounts/account.js +14 -11
- package/dist/esm/src/light-account/accounts/account.js.map +1 -1
- package/dist/esm/src/light-account/accounts/predictAddress.d.ts +9 -0
- package/dist/esm/src/light-account/accounts/predictAddress.js +57 -0
- package/dist/esm/src/light-account/accounts/predictAddress.js.map +1 -0
- package/dist/types/src/light-account/abis/OZ_ERC1967Proxy.d.ts +14 -0
- package/dist/types/src/light-account/abis/OZ_ERC1967Proxy.d.ts.map +1 -0
- package/dist/types/src/light-account/accounts/account.d.ts.map +1 -1
- package/dist/types/src/light-account/accounts/predictAddress.d.ts +10 -0
- package/dist/types/src/light-account/accounts/predictAddress.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/light-account/abis/OZ_ERC1967Proxy.ts +19 -0
- package/src/light-account/accounts/account.ts +18 -14
- package/src/light-account/accounts/predictAddress.ts +95 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const OZ_ERC1967Proxy_ConstructorAbi: readonly [{
|
|
2
|
+
readonly type: "constructor";
|
|
3
|
+
readonly inputs: readonly [{
|
|
4
|
+
readonly name: "_logic";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
readonly internalType: "address";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "_data";
|
|
9
|
+
readonly type: "bytes";
|
|
10
|
+
readonly internalType: "bytes";
|
|
11
|
+
}];
|
|
12
|
+
readonly stateMutability: "payable";
|
|
13
|
+
}];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Trimmed ABI containing only the constructor for the OpenZeppelin ERC1967Proxy contract.
|
|
2
|
+
export const OZ_ERC1967Proxy_ConstructorAbi = [
|
|
3
|
+
{
|
|
4
|
+
type: "constructor",
|
|
5
|
+
inputs: [
|
|
6
|
+
{
|
|
7
|
+
name: "_logic",
|
|
8
|
+
type: "address",
|
|
9
|
+
internalType: "address",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: "_data",
|
|
13
|
+
type: "bytes",
|
|
14
|
+
internalType: "bytes",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
stateMutability: "payable",
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
//# sourceMappingURL=OZ_ERC1967Proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OZ_ERC1967Proxy.js","sourceRoot":"","sources":["../../../../../src/light-account/abis/OZ_ERC1967Proxy.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C;QACE,IAAI,EAAE,aAAa;QACnB,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,SAAS;gBACf,YAAY,EAAE,SAAS;aACxB;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;gBACb,YAAY,EAAE,OAAO;aACtB;SACF;QACD,eAAe,EAAE,SAAS;KAC3B;CACO,CAAC","sourcesContent":["// Trimmed ABI containing only the constructor for the OpenZeppelin ERC1967Proxy contract.\nexport const OZ_ERC1967Proxy_ConstructorAbi = [\n {\n type: \"constructor\",\n inputs: [\n {\n name: \"_logic\",\n type: \"address\",\n internalType: \"address\",\n },\n {\n name: \"_data\",\n type: \"bytes\",\n internalType: \"bytes\",\n },\n ],\n stateMutability: \"payable\",\n },\n] as const;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createBundlerClient,
|
|
1
|
+
import { createBundlerClient, getEntryPoint, } from "@aa-sdk/core";
|
|
2
2
|
import { concatHex, encodeFunctionData, } from "viem";
|
|
3
3
|
import { LightAccountAbi_v1 } from "../abis/LightAccountAbi_v1.js";
|
|
4
4
|
import { LightAccountAbi_v2 } from "../abis/LightAccountAbi_v2.js";
|
|
@@ -6,6 +6,7 @@ import { LightAccountFactoryAbi_v1 } from "../abis/LightAccountFactoryAbi_v1.js"
|
|
|
6
6
|
import { LightAccountFactoryAbi_v2 } from "../abis/LightAccountFactoryAbi_v2.js";
|
|
7
7
|
import { AccountVersionRegistry, LightAccountUnsupported1271Factories, defaultLightAccountVersion, getDefaultLightAccountFactoryAddress, } from "../utils.js";
|
|
8
8
|
import { createLightAccountBase, } from "./base.js";
|
|
9
|
+
import { predictLightAccountAddress } from "./predictAddress.js";
|
|
9
10
|
/**
|
|
10
11
|
* Creates a light account based on the provided parameters such as transport, chain, signer, init code, and more. Ensures that an account is configured and returned with various capabilities, such as transferring ownership and retrieving the owner's address.
|
|
11
12
|
*
|
|
@@ -38,27 +39,29 @@ export async function createLightAccount({ transport, chain, signer, initCode, v
|
|
|
38
39
|
const factoryAbi = version === "v2.0.0"
|
|
39
40
|
? LightAccountFactoryAbi_v1
|
|
40
41
|
: LightAccountFactoryAbi_v2;
|
|
42
|
+
const signerAddress = await signer.getAddress();
|
|
43
|
+
const salt = LightAccountUnsupported1271Factories.has(factoryAddress.toLowerCase())
|
|
44
|
+
? 0n
|
|
45
|
+
: salt_;
|
|
41
46
|
const getAccountInitCode = async () => {
|
|
42
47
|
if (initCode)
|
|
43
48
|
return initCode;
|
|
44
|
-
const salt = LightAccountUnsupported1271Factories.has(factoryAddress.toLowerCase())
|
|
45
|
-
? 0n
|
|
46
|
-
: salt_;
|
|
47
49
|
return concatHex([
|
|
48
50
|
factoryAddress,
|
|
49
51
|
encodeFunctionData({
|
|
50
52
|
abi: factoryAbi,
|
|
51
53
|
functionName: "createAccount",
|
|
52
|
-
args: [
|
|
54
|
+
args: [signerAddress, salt],
|
|
53
55
|
}),
|
|
54
56
|
]);
|
|
55
57
|
};
|
|
56
|
-
const address =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
const address = accountAddress ??
|
|
59
|
+
predictLightAccountAddress({
|
|
60
|
+
factoryAddress,
|
|
61
|
+
salt,
|
|
62
|
+
signerAddress,
|
|
63
|
+
version,
|
|
64
|
+
});
|
|
62
65
|
const account = await createLightAccountBase({
|
|
63
66
|
transport,
|
|
64
67
|
chain,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../../src/light-account/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../../src/light-account/accounts/account.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n createBundlerClient,\n getEntryPoint,\n type Address,\n type EntryPointDef,\n type SmartAccountSigner,\n} from \"@aa-sdk/core\";\nimport {\n concatHex,\n encodeFunctionData,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { LightAccountAbi_v1 } from \"../abis/LightAccountAbi_v1.js\";\nimport { LightAccountAbi_v2 } from \"../abis/LightAccountAbi_v2.js\";\nimport { LightAccountFactoryAbi_v1 } from \"../abis/LightAccountFactoryAbi_v1.js\";\nimport { LightAccountFactoryAbi_v2 } from \"../abis/LightAccountFactoryAbi_v2.js\";\nimport type {\n LightAccountEntryPointVersion,\n LightAccountVersion,\n} from \"../types.js\";\nimport {\n AccountVersionRegistry,\n LightAccountUnsupported1271Factories,\n defaultLightAccountVersion,\n getDefaultLightAccountFactoryAddress,\n} from \"../utils.js\";\nimport {\n createLightAccountBase,\n type CreateLightAccountBaseParams,\n type LightAccountBase,\n} from \"./base.js\";\nimport { predictLightAccountAddress } from \"./predictAddress.js\";\n\nexport type LightAccount<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TLightAccountVersion extends LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">\n> = LightAccountBase<TSigner, \"LightAccount\", TLightAccountVersion> & {\n encodeTransferOwnership: (newOwner: Address) => Hex;\n getOwnerAddress: () => Promise<Address>;\n};\n\n// [!region CreateLightAccountParams]\nexport type CreateLightAccountParams<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TLightAccountVersion extends LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">\n> = Omit<\n CreateLightAccountBaseParams<\n \"LightAccount\",\n TLightAccountVersion,\n TTransport,\n TSigner\n >,\n | \"getAccountInitCode\"\n | \"entryPoint\"\n | \"version\"\n | \"abi\"\n | \"accountAddress\"\n | \"type\"\n> & {\n salt?: bigint;\n initCode?: Hex;\n accountAddress?: Address;\n factoryAddress?: Address;\n version?: TLightAccountVersion;\n entryPoint?: EntryPointDef<\n LightAccountEntryPointVersion<\"LightAccount\", TLightAccountVersion>,\n Chain\n >;\n};\n// [!endregion CreateLightAccountParams]\n\nexport async function createLightAccount<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TLightAccountVersion extends LightAccountVersion<\"LightAccount\"> = \"v2.0.0\"\n>(\n config: CreateLightAccountParams<TTransport, TSigner, TLightAccountVersion>\n): Promise<LightAccount<TSigner, TLightAccountVersion>>;\n\n/**\n * Creates a light account based on the provided parameters such as transport, chain, signer, init code, and more. Ensures that an account is configured and returned with various capabilities, such as transferring ownership and retrieving the owner's address.\n *\n * @example\n * ```ts\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"viem/chains\";\n * import { http, generatePrivateKey } from \"viem\"\n *\n * const account = await createLightAccount({\n * chain: sepolia,\n * transport: http(\"RPC_URL\"),\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n * ```\n *\n * @param {CreateLightAccountParams} config The parameters for creating a light account\n * @returns {Promise<LightAccount>} A promise that resolves to a `LightAccount` object containing the created account information and methods\n */\nexport async function createLightAccount({\n transport,\n chain,\n signer,\n initCode,\n version = defaultLightAccountVersion(),\n entryPoint = getEntryPoint(chain, {\n version: AccountVersionRegistry[\"LightAccount\"][version]\n .entryPointVersion as any,\n }),\n accountAddress,\n factoryAddress = getDefaultLightAccountFactoryAddress(chain, version),\n salt: salt_ = 0n,\n}: CreateLightAccountParams): Promise<LightAccount> {\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const accountAbi =\n version === \"v2.0.0\" ? LightAccountAbi_v2 : LightAccountAbi_v1;\n const factoryAbi =\n version === \"v2.0.0\"\n ? LightAccountFactoryAbi_v1\n : LightAccountFactoryAbi_v2;\n\n const signerAddress = await signer.getAddress();\n\n const salt = LightAccountUnsupported1271Factories.has(\n factoryAddress.toLowerCase() as Address\n )\n ? 0n\n : salt_;\n\n const getAccountInitCode = async () => {\n if (initCode) return initCode;\n\n return concatHex([\n factoryAddress,\n encodeFunctionData({\n abi: factoryAbi,\n functionName: \"createAccount\",\n args: [signerAddress, salt],\n }),\n ]);\n };\n\n const address =\n accountAddress ??\n predictLightAccountAddress({\n factoryAddress,\n salt,\n signerAddress,\n version,\n });\n\n const account = await createLightAccountBase<\n \"LightAccount\",\n LightAccountVersion<\"LightAccount\">,\n Transport,\n SmartAccountSigner\n >({\n transport,\n chain,\n signer,\n abi: accountAbi,\n type: \"LightAccount\",\n version,\n entryPoint,\n accountAddress: address,\n getAccountInitCode,\n });\n\n return {\n ...account,\n\n encodeTransferOwnership: (newOwner: Address) => {\n return encodeFunctionData({\n abi: accountAbi,\n functionName: \"transferOwnership\",\n args: [newOwner],\n });\n },\n async getOwnerAddress(): Promise<Address> {\n const callResult = await client.readContract({\n address,\n abi: accountAbi,\n functionName: \"owner\",\n });\n\n if (callResult == null) {\n throw new Error(\"could not get on-chain owner\");\n }\n\n return callResult;\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { LightAccountVersionConfigs } from "../types";
|
|
3
|
+
export type PredictLightAccountAddressParams = {
|
|
4
|
+
factoryAddress: Address;
|
|
5
|
+
salt: bigint;
|
|
6
|
+
signerAddress: Address;
|
|
7
|
+
version: keyof LightAccountVersionConfigs["LightAccount"];
|
|
8
|
+
};
|
|
9
|
+
export declare function predictLightAccountAddress({ factoryAddress, salt, signerAddress, version, }: PredictLightAccountAddressParams): Address;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { encodeAbiParameters, encodeDeployData, keccak256, getContractAddress, toHex, encodeFunctionData, } from "viem";
|
|
2
|
+
import { OZ_ERC1967Proxy_ConstructorAbi } from "../abis/OZ_ERC1967Proxy.js";
|
|
3
|
+
import { AccountVersionRegistry } from "../utils.js";
|
|
4
|
+
import { LightAccountAbi_v1 } from "../abis/LightAccountAbi_v1.js";
|
|
5
|
+
export function predictLightAccountAddress({ factoryAddress, salt, signerAddress, version, }) {
|
|
6
|
+
const implementationAddress =
|
|
7
|
+
// If we aren't using the default factory address, we compute the implementation address from the factory's `create` deployment.
|
|
8
|
+
// This is accurate for both LA v1 and v2 factories. If we are using the default factory address, we use the implementation address from the registry.
|
|
9
|
+
factoryAddress !==
|
|
10
|
+
AccountVersionRegistry.LightAccount[version].addresses.default.factory
|
|
11
|
+
? getContractAddress({
|
|
12
|
+
from: factoryAddress,
|
|
13
|
+
nonce: 1n,
|
|
14
|
+
})
|
|
15
|
+
: AccountVersionRegistry.LightAccount[version].addresses.default.impl;
|
|
16
|
+
switch (version) {
|
|
17
|
+
case "v1.0.1":
|
|
18
|
+
case "v1.0.2":
|
|
19
|
+
case "v1.1.0":
|
|
20
|
+
// Same proxy initcode for all LA v1 factories
|
|
21
|
+
const LAv1_proxy_bytecode = "0x60406080815261042c908138038061001681610218565b93843982019181818403126102135780516001600160a01b038116808203610213576020838101516001600160401b0394919391858211610213570186601f820112156102135780519061007161006c83610253565b610218565b918083528583019886828401011161021357888661008f930161026e565b813b156101b9577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b031916841790556000927fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a28051158015906101b2575b61010b575b855160e790816103458239f35b855194606086019081118682101761019e578697849283926101889952602788527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c87890152660819985a5b195960ca1b8a8901525190845af4913d15610194573d9061017a61006c83610253565b91825281943d92013e610291565b508038808080806100fe565b5060609250610291565b634e487b7160e01b84526041600452602484fd5b50826100f9565b855162461bcd60e51b815260048101859052602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761023d57604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161023d57601f01601f191660200190565b60005b8381106102815750506000910152565b8181015183820152602001610271565b919290156102f357508151156102a5575090565b3b156102ae5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156103065750805190602001fd5b6044604051809262461bcd60e51b825260206004830152610336815180928160248601526020868601910161026e565b601f01601f19168101030190fdfe60806040523615605f5773ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f35b3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f3fea26469706673582212205da2750cd2b0cadfd354d8a1ca4752ed7f22214c8069d852f7dc6b8e9e5ee66964736f6c63430008150033";
|
|
22
|
+
return getContractAddress({
|
|
23
|
+
from: factoryAddress,
|
|
24
|
+
opcode: "CREATE2",
|
|
25
|
+
salt: toHex(salt, { size: 32 }),
|
|
26
|
+
bytecode: encodeDeployData({
|
|
27
|
+
bytecode: LAv1_proxy_bytecode,
|
|
28
|
+
abi: OZ_ERC1967Proxy_ConstructorAbi,
|
|
29
|
+
args: [
|
|
30
|
+
implementationAddress,
|
|
31
|
+
encodeFunctionData({
|
|
32
|
+
abi: LightAccountAbi_v1,
|
|
33
|
+
functionName: "initialize",
|
|
34
|
+
args: [signerAddress],
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
case "v2.0.0":
|
|
40
|
+
// Logic ported from LA factory v2.0.0
|
|
41
|
+
const combinedSalt = keccak256(encodeAbiParameters([{ type: "address" }, { type: "uint256" }], [signerAddress, salt]));
|
|
42
|
+
// Bytecode from https://github.com/Vectorized/solady/blob/c6e5238e5f3b621789c59e1a443f43b6606394b2/src/utils/LibClone.sol#L721
|
|
43
|
+
const initCode = `0x603d3d8160223d3973${implementationAddress.slice(2)}60095155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3`;
|
|
44
|
+
return getContractAddress({
|
|
45
|
+
from: factoryAddress,
|
|
46
|
+
opcode: "CREATE2",
|
|
47
|
+
salt: combinedSalt,
|
|
48
|
+
bytecode: initCode,
|
|
49
|
+
});
|
|
50
|
+
default:
|
|
51
|
+
assertNeverLightAccountVersion(version);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function assertNeverLightAccountVersion(version) {
|
|
55
|
+
throw new Error(`Unknown light account version: ${version}`);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=predictAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predictAddress.js","sourceRoot":"","sources":["../../../../../src/light-account/accounts/predictAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAGlB,KAAK,EACL,kBAAkB,GACnB,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,8BAA8B,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AASnE,MAAM,UAAU,0BAA0B,CAAC,EACzC,cAAc,EACd,IAAI,EACJ,aAAa,EACb,OAAO,GAC0B;IACjC,MAAM,qBAAqB;IACzB,gIAAgI;IAChI,sJAAsJ;IACtJ,cAAc;QACd,sBAAsB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO;QACpE,CAAC,CAAC,kBAAkB,CAAC;YACjB,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,EAAE;SACV,CAAC;QACJ,CAAC,CAAC,sBAAsB,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;IAE1E,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,8CAA8C;YAC9C,MAAM,mBAAmB,GACvB,4lEAA4lE,CAAC;YAE/lE,OAAO,kBAAkB,CAAC;gBACxB,IAAI,EAAE,cAAc;gBACpB,MAAM,EAAE,SAAS;gBACjB,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;gBAC/B,QAAQ,EAAE,gBAAgB,CAAC;oBACzB,QAAQ,EAAE,mBAAmB;oBAC7B,GAAG,EAAE,8BAA8B;oBACnC,IAAI,EAAE;wBACJ,qBAAqB;wBACrB,kBAAkB,CAAC;4BACjB,GAAG,EAAE,kBAAkB;4BACvB,YAAY,EAAE,YAAY;4BAC1B,IAAI,EAAE,CAAC,aAAa,CAAC;yBACtB,CAAC;qBACH;iBACF,CAAC;aACH,CAAC,CAAC;QAEL,KAAK,QAAQ;YACX,sCAAsC;YACtC,MAAM,YAAY,GAAG,SAAS,CAC5B,mBAAmB,CACjB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAC1C,CAAC,aAAa,EAAE,IAAI,CAAC,CACtB,CACF,CAAC;YAEF,+HAA+H;YAE/H,MAAM,QAAQ,GAAQ,uBAAuB,qBAAqB,CAAC,KAAK,CACtE,CAAC,CACF,sIAAsI,CAAC;YAExI,OAAO,kBAAkB,CAAC;gBACxB,IAAI,EAAE,cAAc;gBACpB,MAAM,EAAE,SAAS;gBACjB,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;QAEL;YACE,8BAA8B,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,SAAS,8BAA8B,CAAC,OAAc;IACpD,MAAM,IAAI,KAAK,CAAC,kCAAkC,OAAO,EAAE,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import {\n encodeAbiParameters,\n encodeDeployData,\n keccak256,\n getContractAddress,\n type Address,\n type Hex,\n toHex,\n encodeFunctionData,\n} from \"viem\";\nimport type { LightAccountVersionConfigs } from \"../types\";\nimport { OZ_ERC1967Proxy_ConstructorAbi } from \"../abis/OZ_ERC1967Proxy.js\";\nimport { AccountVersionRegistry } from \"../utils.js\";\nimport { LightAccountAbi_v1 } from \"../abis/LightAccountAbi_v1.js\";\n\nexport type PredictLightAccountAddressParams = {\n factoryAddress: Address;\n salt: bigint;\n signerAddress: Address;\n version: keyof LightAccountVersionConfigs[\"LightAccount\"];\n};\n\nexport function predictLightAccountAddress({\n factoryAddress,\n salt,\n signerAddress,\n version,\n}: PredictLightAccountAddressParams): Address {\n const implementationAddress =\n // If we aren't using the default factory address, we compute the implementation address from the factory's `create` deployment.\n // This is accurate for both LA v1 and v2 factories. If we are using the default factory address, we use the implementation address from the registry.\n factoryAddress !==\n AccountVersionRegistry.LightAccount[version].addresses.default.factory\n ? getContractAddress({\n from: factoryAddress,\n nonce: 1n,\n })\n : AccountVersionRegistry.LightAccount[version].addresses.default.impl;\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n // Same proxy initcode for all LA v1 factories\n const LAv1_proxy_bytecode: Hex =\n \"0x60406080815261042c908138038061001681610218565b93843982019181818403126102135780516001600160a01b038116808203610213576020838101516001600160401b0394919391858211610213570186601f820112156102135780519061007161006c83610253565b610218565b918083528583019886828401011161021357888661008f930161026e565b813b156101b9577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b031916841790556000927fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a28051158015906101b2575b61010b575b855160e790816103458239f35b855194606086019081118682101761019e578697849283926101889952602788527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c87890152660819985a5b195960ca1b8a8901525190845af4913d15610194573d9061017a61006c83610253565b91825281943d92013e610291565b508038808080806100fe565b5060609250610291565b634e487b7160e01b84526041600452602484fd5b50826100f9565b855162461bcd60e51b815260048101859052602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761023d57604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161023d57601f01601f191660200190565b60005b8381106102815750506000910152565b8181015183820152602001610271565b919290156102f357508151156102a5575090565b3b156102ae5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156103065750805190602001fd5b6044604051809262461bcd60e51b825260206004830152610336815180928160248601526020868601910161026e565b601f01601f19168101030190fdfe60806040523615605f5773ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f35b3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f3fea26469706673582212205da2750cd2b0cadfd354d8a1ca4752ed7f22214c8069d852f7dc6b8e9e5ee66964736f6c63430008150033\";\n\n return getContractAddress({\n from: factoryAddress,\n opcode: \"CREATE2\",\n salt: toHex(salt, { size: 32 }),\n bytecode: encodeDeployData({\n bytecode: LAv1_proxy_bytecode,\n abi: OZ_ERC1967Proxy_ConstructorAbi,\n args: [\n implementationAddress,\n encodeFunctionData({\n abi: LightAccountAbi_v1,\n functionName: \"initialize\",\n args: [signerAddress],\n }),\n ],\n }),\n });\n\n case \"v2.0.0\":\n // Logic ported from LA factory v2.0.0\n const combinedSalt = keccak256(\n encodeAbiParameters(\n [{ type: \"address\" }, { type: \"uint256\" }],\n [signerAddress, salt]\n )\n );\n\n // Bytecode from https://github.com/Vectorized/solady/blob/c6e5238e5f3b621789c59e1a443f43b6606394b2/src/utils/LibClone.sol#L721\n\n const initCode: Hex = `0x603d3d8160223d3973${implementationAddress.slice(\n 2\n )}60095155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3`;\n\n return getContractAddress({\n from: factoryAddress,\n opcode: \"CREATE2\",\n salt: combinedSalt,\n bytecode: initCode,\n });\n\n default:\n assertNeverLightAccountVersion(version);\n }\n}\n\nfunction assertNeverLightAccountVersion(version: never): never {\n throw new Error(`Unknown light account version: ${version}`);\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const OZ_ERC1967Proxy_ConstructorAbi: readonly [{
|
|
2
|
+
readonly type: "constructor";
|
|
3
|
+
readonly inputs: readonly [{
|
|
4
|
+
readonly name: "_logic";
|
|
5
|
+
readonly type: "address";
|
|
6
|
+
readonly internalType: "address";
|
|
7
|
+
}, {
|
|
8
|
+
readonly name: "_data";
|
|
9
|
+
readonly type: "bytes";
|
|
10
|
+
readonly internalType: "bytes";
|
|
11
|
+
}];
|
|
12
|
+
readonly stateMutability: "payable";
|
|
13
|
+
}];
|
|
14
|
+
//# sourceMappingURL=OZ_ERC1967Proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OZ_ERC1967Proxy.d.ts","sourceRoot":"","sources":["../../../../../src/light-account/abis/OZ_ERC1967Proxy.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,8BAA8B;;;;;;;;;;;;EAiBjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../../../src/light-account/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../../../src/light-account/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,KAAK,KAAK,EACV,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAKd,OAAO,KAAK,EACV,6BAA6B,EAC7B,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAOrB,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,gBAAgB,EACtB,MAAM,WAAW,CAAC;AAGnB,MAAM,MAAM,YAAY,CACtB,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EACvD,oBAAoB,SAAS,mBAAmB,CAAC,cAAc,CAAC,GAAG,mBAAmB,CAAC,cAAc,CAAC,IACpG,gBAAgB,CAAC,OAAO,EAAE,cAAc,EAAE,oBAAoB,CAAC,GAAG;IACpE,uBAAuB,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,GAAG,CAAC;IACpD,eAAe,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACzC,CAAC;AAGF,MAAM,MAAM,wBAAwB,CAClC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EACvD,oBAAoB,SAAS,mBAAmB,CAAC,cAAc,CAAC,GAAG,mBAAmB,CAAC,cAAc,CAAC,IACpG,IAAI,CACN,4BAA4B,CAC1B,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,OAAO,CACR,EACC,oBAAoB,GACpB,YAAY,GACZ,SAAS,GACT,KAAK,GACL,gBAAgB,GAChB,MAAM,CACT,GAAG;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,UAAU,CAAC,EAAE,aAAa,CACxB,6BAA6B,CAAC,cAAc,EAAE,oBAAoB,CAAC,EACnE,KAAK,CACN,CAAC;CACH,CAAC;AAGF,wBAAsB,kBAAkB,CACtC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EACvD,oBAAoB,SAAS,mBAAmB,CAAC,cAAc,CAAC,GAAG,QAAQ,EAE3E,MAAM,EAAE,wBAAwB,CAAC,UAAU,EAAE,OAAO,EAAE,oBAAoB,CAAC,GAC1E,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { LightAccountVersionConfigs } from "../types";
|
|
3
|
+
export type PredictLightAccountAddressParams = {
|
|
4
|
+
factoryAddress: Address;
|
|
5
|
+
salt: bigint;
|
|
6
|
+
signerAddress: Address;
|
|
7
|
+
version: keyof LightAccountVersionConfigs["LightAccount"];
|
|
8
|
+
};
|
|
9
|
+
export declare function predictLightAccountAddress({ factoryAddress, salt, signerAddress, version, }: PredictLightAccountAddressParams): Address;
|
|
10
|
+
//# sourceMappingURL=predictAddress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predictAddress.d.ts","sourceRoot":"","sources":["../../../../../src/light-account/accounts/predictAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,OAAO,EAIb,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAK3D,MAAM,MAAM,gCAAgC,GAAG;IAC7C,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,0BAA0B,CAAC,cAAc,CAAC,CAAC;CAC3D,CAAC;AAEF,wBAAgB,0BAA0B,CAAC,EACzC,cAAc,EACd,IAAI,EACJ,aAAa,EACb,OAAO,GACR,EAAE,gCAAgC,GAAG,OAAO,CA+D5C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/smart-contracts",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.33.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.33.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": "ef2c269bcfa2115b6103f342ac4d846f1b4db991",
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@aa-sdk/core": "^4.
|
|
78
|
-
"@account-kit/infra": "^4.
|
|
77
|
+
"@aa-sdk/core": "^4.33.0",
|
|
78
|
+
"@account-kit/infra": "^4.33.0"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"viem": "^2.
|
|
81
|
+
"viem": "^2.29.2"
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Trimmed ABI containing only the constructor for the OpenZeppelin ERC1967Proxy contract.
|
|
2
|
+
export const OZ_ERC1967Proxy_ConstructorAbi = [
|
|
3
|
+
{
|
|
4
|
+
type: "constructor",
|
|
5
|
+
inputs: [
|
|
6
|
+
{
|
|
7
|
+
name: "_logic",
|
|
8
|
+
type: "address",
|
|
9
|
+
internalType: "address",
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: "_data",
|
|
13
|
+
type: "bytes",
|
|
14
|
+
internalType: "bytes",
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
stateMutability: "payable",
|
|
18
|
+
},
|
|
19
|
+
] as const;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createBundlerClient,
|
|
3
|
-
getAccountAddress,
|
|
4
3
|
getEntryPoint,
|
|
5
4
|
type Address,
|
|
6
5
|
type EntryPointDef,
|
|
@@ -32,6 +31,7 @@ import {
|
|
|
32
31
|
type CreateLightAccountBaseParams,
|
|
33
32
|
type LightAccountBase,
|
|
34
33
|
} from "./base.js";
|
|
34
|
+
import { predictLightAccountAddress } from "./predictAddress.js";
|
|
35
35
|
|
|
36
36
|
export type LightAccount<
|
|
37
37
|
TSigner extends SmartAccountSigner = SmartAccountSigner,
|
|
@@ -126,31 +126,35 @@ export async function createLightAccount({
|
|
|
126
126
|
? LightAccountFactoryAbi_v1
|
|
127
127
|
: LightAccountFactoryAbi_v2;
|
|
128
128
|
|
|
129
|
+
const signerAddress = await signer.getAddress();
|
|
130
|
+
|
|
131
|
+
const salt = LightAccountUnsupported1271Factories.has(
|
|
132
|
+
factoryAddress.toLowerCase() as Address
|
|
133
|
+
)
|
|
134
|
+
? 0n
|
|
135
|
+
: salt_;
|
|
136
|
+
|
|
129
137
|
const getAccountInitCode = async () => {
|
|
130
138
|
if (initCode) return initCode;
|
|
131
139
|
|
|
132
|
-
const salt = LightAccountUnsupported1271Factories.has(
|
|
133
|
-
factoryAddress.toLowerCase() as Address
|
|
134
|
-
)
|
|
135
|
-
? 0n
|
|
136
|
-
: salt_;
|
|
137
|
-
|
|
138
140
|
return concatHex([
|
|
139
141
|
factoryAddress,
|
|
140
142
|
encodeFunctionData({
|
|
141
143
|
abi: factoryAbi,
|
|
142
144
|
functionName: "createAccount",
|
|
143
|
-
args: [
|
|
145
|
+
args: [signerAddress, salt],
|
|
144
146
|
}),
|
|
145
147
|
]);
|
|
146
148
|
};
|
|
147
149
|
|
|
148
|
-
const address =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
const address =
|
|
151
|
+
accountAddress ??
|
|
152
|
+
predictLightAccountAddress({
|
|
153
|
+
factoryAddress,
|
|
154
|
+
salt,
|
|
155
|
+
signerAddress,
|
|
156
|
+
version,
|
|
157
|
+
});
|
|
154
158
|
|
|
155
159
|
const account = await createLightAccountBase<
|
|
156
160
|
"LightAccount",
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encodeAbiParameters,
|
|
3
|
+
encodeDeployData,
|
|
4
|
+
keccak256,
|
|
5
|
+
getContractAddress,
|
|
6
|
+
type Address,
|
|
7
|
+
type Hex,
|
|
8
|
+
toHex,
|
|
9
|
+
encodeFunctionData,
|
|
10
|
+
} from "viem";
|
|
11
|
+
import type { LightAccountVersionConfigs } from "../types";
|
|
12
|
+
import { OZ_ERC1967Proxy_ConstructorAbi } from "../abis/OZ_ERC1967Proxy.js";
|
|
13
|
+
import { AccountVersionRegistry } from "../utils.js";
|
|
14
|
+
import { LightAccountAbi_v1 } from "../abis/LightAccountAbi_v1.js";
|
|
15
|
+
|
|
16
|
+
export type PredictLightAccountAddressParams = {
|
|
17
|
+
factoryAddress: Address;
|
|
18
|
+
salt: bigint;
|
|
19
|
+
signerAddress: Address;
|
|
20
|
+
version: keyof LightAccountVersionConfigs["LightAccount"];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function predictLightAccountAddress({
|
|
24
|
+
factoryAddress,
|
|
25
|
+
salt,
|
|
26
|
+
signerAddress,
|
|
27
|
+
version,
|
|
28
|
+
}: PredictLightAccountAddressParams): Address {
|
|
29
|
+
const implementationAddress =
|
|
30
|
+
// If we aren't using the default factory address, we compute the implementation address from the factory's `create` deployment.
|
|
31
|
+
// This is accurate for both LA v1 and v2 factories. If we are using the default factory address, we use the implementation address from the registry.
|
|
32
|
+
factoryAddress !==
|
|
33
|
+
AccountVersionRegistry.LightAccount[version].addresses.default.factory
|
|
34
|
+
? getContractAddress({
|
|
35
|
+
from: factoryAddress,
|
|
36
|
+
nonce: 1n,
|
|
37
|
+
})
|
|
38
|
+
: AccountVersionRegistry.LightAccount[version].addresses.default.impl;
|
|
39
|
+
|
|
40
|
+
switch (version) {
|
|
41
|
+
case "v1.0.1":
|
|
42
|
+
case "v1.0.2":
|
|
43
|
+
case "v1.1.0":
|
|
44
|
+
// Same proxy initcode for all LA v1 factories
|
|
45
|
+
const LAv1_proxy_bytecode: Hex =
|
|
46
|
+
"0x60406080815261042c908138038061001681610218565b93843982019181818403126102135780516001600160a01b038116808203610213576020838101516001600160401b0394919391858211610213570186601f820112156102135780519061007161006c83610253565b610218565b918083528583019886828401011161021357888661008f930161026e565b813b156101b9577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b031916841790556000927fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a28051158015906101b2575b61010b575b855160e790816103458239f35b855194606086019081118682101761019e578697849283926101889952602788527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c87890152660819985a5b195960ca1b8a8901525190845af4913d15610194573d9061017a61006c83610253565b91825281943d92013e610291565b508038808080806100fe565b5060609250610291565b634e487b7160e01b84526041600452602484fd5b50826100f9565b855162461bcd60e51b815260048101859052602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761023d57604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161023d57601f01601f191660200190565b60005b8381106102815750506000910152565b8181015183820152602001610271565b919290156102f357508151156102a5575090565b3b156102ae5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156103065750805190602001fd5b6044604051809262461bcd60e51b825260206004830152610336815180928160248601526020868601910161026e565b601f01601f19168101030190fdfe60806040523615605f5773ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f35b3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f3fea26469706673582212205da2750cd2b0cadfd354d8a1ca4752ed7f22214c8069d852f7dc6b8e9e5ee66964736f6c63430008150033";
|
|
47
|
+
|
|
48
|
+
return getContractAddress({
|
|
49
|
+
from: factoryAddress,
|
|
50
|
+
opcode: "CREATE2",
|
|
51
|
+
salt: toHex(salt, { size: 32 }),
|
|
52
|
+
bytecode: encodeDeployData({
|
|
53
|
+
bytecode: LAv1_proxy_bytecode,
|
|
54
|
+
abi: OZ_ERC1967Proxy_ConstructorAbi,
|
|
55
|
+
args: [
|
|
56
|
+
implementationAddress,
|
|
57
|
+
encodeFunctionData({
|
|
58
|
+
abi: LightAccountAbi_v1,
|
|
59
|
+
functionName: "initialize",
|
|
60
|
+
args: [signerAddress],
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
case "v2.0.0":
|
|
67
|
+
// Logic ported from LA factory v2.0.0
|
|
68
|
+
const combinedSalt = keccak256(
|
|
69
|
+
encodeAbiParameters(
|
|
70
|
+
[{ type: "address" }, { type: "uint256" }],
|
|
71
|
+
[signerAddress, salt]
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Bytecode from https://github.com/Vectorized/solady/blob/c6e5238e5f3b621789c59e1a443f43b6606394b2/src/utils/LibClone.sol#L721
|
|
76
|
+
|
|
77
|
+
const initCode: Hex = `0x603d3d8160223d3973${implementationAddress.slice(
|
|
78
|
+
2
|
|
79
|
+
)}60095155f3363d3d373d3d363d7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc545af43d6000803e6038573d6000fd5b3d6000f3`;
|
|
80
|
+
|
|
81
|
+
return getContractAddress({
|
|
82
|
+
from: factoryAddress,
|
|
83
|
+
opcode: "CREATE2",
|
|
84
|
+
salt: combinedSalt,
|
|
85
|
+
bytecode: initCode,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
default:
|
|
89
|
+
assertNeverLightAccountVersion(version);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function assertNeverLightAccountVersion(version: never): never {
|
|
94
|
+
throw new Error(`Unknown light account version: ${version}`);
|
|
95
|
+
}
|