@aa-sdk/core 4.0.0-alpha.4 → 4.0.0-alpha.6
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/cjs/account/smartContractAccount.d.ts +9 -3
- package/dist/cjs/account/smartContractAccount.js +11 -6
- package/dist/cjs/account/smartContractAccount.js.map +1 -1
- package/dist/cjs/actions/smartAccount/buildUserOperationFromTx.js.map +1 -1
- package/dist/cjs/actions/smartAccount/buildUserOperationFromTxs.js.map +1 -1
- package/dist/cjs/actions/smartAccount/checkGasSponsorshipEligibility.js.map +1 -1
- package/dist/cjs/actions/smartAccount/estimateUserOperationGas.js.map +1 -1
- package/dist/cjs/actions/smartAccount/internal/initUserOperation.js.map +1 -1
- package/dist/cjs/actions/smartAccount/internal/runMiddlewareStack.js.map +1 -1
- package/dist/cjs/actions/smartAccount/internal/sendUserOperation.js.map +1 -1
- package/dist/cjs/actions/smartAccount/sendUserOperation.js.map +1 -1
- package/dist/cjs/client/bundlerClient.js.map +1 -1
- package/dist/cjs/client/decorators/bundlerClient.js.map +1 -1
- package/dist/cjs/client/isSmartAccountClient.js.map +1 -1
- package/dist/cjs/client/types.d.ts +2 -7
- package/dist/cjs/client/types.js.map +1 -1
- package/dist/cjs/errors/account.js.map +1 -1
- package/dist/cjs/errors/client.js.map +1 -1
- package/dist/cjs/errors/entrypoint.js.map +1 -1
- package/dist/cjs/errors/signer.js.map +1 -1
- package/dist/cjs/errors/transaction.js.map +1 -1
- package/dist/cjs/errors/useroperation.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -5
- package/dist/cjs/index.js +6 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/logger.js.map +1 -1
- package/dist/cjs/middleware/actions.js +2 -18
- package/dist/cjs/middleware/actions.js.map +1 -1
- package/dist/cjs/middleware/defaults/gasEstimator.js +3 -2
- package/dist/cjs/middleware/defaults/gasEstimator.js.map +1 -1
- package/dist/cjs/middleware/erc7677middleware.d.ts +40 -0
- package/dist/cjs/middleware/erc7677middleware.js +77 -0
- package/dist/cjs/middleware/erc7677middleware.js.map +1 -0
- package/dist/cjs/middleware/noopMiddleware.d.ts +2 -1
- package/dist/cjs/middleware/noopMiddleware.js.map +1 -1
- package/dist/cjs/middleware/types.d.ts +3 -2
- package/dist/cjs/middleware/types.js.map +1 -1
- package/dist/cjs/signer/local-account.d.ts +46 -46
- package/dist/cjs/signer/local-account.js.map +1 -1
- package/dist/cjs/signer/wallet-client.d.ts +46 -46
- package/dist/cjs/signer/wallet-client.js.map +1 -1
- package/dist/cjs/transport/split.js.map +1 -1
- package/dist/cjs/utils/bigint.js.map +1 -1
- package/dist/cjs/utils/bytes.js.map +1 -1
- package/dist/cjs/utils/defaults.d.ts +1 -3
- package/dist/cjs/utils/defaults.js +1 -41
- package/dist/cjs/utils/defaults.js.map +1 -1
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/types.js.map +1 -1
- package/dist/cjs/utils/userop.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/account/smartContractAccount.d.ts +9 -3
- package/dist/esm/account/smartContractAccount.js +6 -1
- package/dist/esm/account/smartContractAccount.js.map +1 -1
- package/dist/esm/actions/smartAccount/buildUserOperationFromTx.js.map +1 -1
- package/dist/esm/actions/smartAccount/buildUserOperationFromTxs.js.map +1 -1
- package/dist/esm/actions/smartAccount/checkGasSponsorshipEligibility.js.map +1 -1
- package/dist/esm/actions/smartAccount/estimateUserOperationGas.js.map +1 -1
- package/dist/esm/actions/smartAccount/internal/initUserOperation.js.map +1 -1
- package/dist/esm/actions/smartAccount/internal/runMiddlewareStack.js.map +1 -1
- package/dist/esm/actions/smartAccount/internal/sendUserOperation.js.map +1 -1
- package/dist/esm/actions/smartAccount/sendUserOperation.js.map +1 -1
- package/dist/esm/client/bundlerClient.js.map +1 -1
- package/dist/esm/client/decorators/bundlerClient.js.map +1 -1
- package/dist/esm/client/isSmartAccountClient.js.map +1 -1
- package/dist/esm/client/types.d.ts +2 -7
- package/dist/esm/client/types.js.map +1 -1
- package/dist/esm/errors/account.js.map +1 -1
- package/dist/esm/errors/client.js.map +1 -1
- package/dist/esm/errors/entrypoint.js.map +1 -1
- package/dist/esm/errors/signer.js.map +1 -1
- package/dist/esm/errors/transaction.js.map +1 -1
- package/dist/esm/errors/useroperation.js.map +1 -1
- package/dist/esm/index.d.ts +3 -5
- package/dist/esm/index.js +2 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/middleware/actions.js +3 -18
- package/dist/esm/middleware/actions.js.map +1 -1
- package/dist/esm/middleware/defaults/gasEstimator.js +3 -2
- package/dist/esm/middleware/defaults/gasEstimator.js.map +1 -1
- package/dist/esm/middleware/erc7677middleware.d.ts +40 -0
- package/dist/esm/middleware/erc7677middleware.js +73 -0
- package/dist/esm/middleware/erc7677middleware.js.map +1 -0
- package/dist/esm/middleware/noopMiddleware.d.ts +2 -1
- package/dist/esm/middleware/noopMiddleware.js.map +1 -1
- package/dist/esm/middleware/types.d.ts +3 -2
- package/dist/esm/middleware/types.js.map +1 -1
- package/dist/esm/signer/local-account.d.ts +46 -46
- package/dist/esm/signer/local-account.js.map +1 -1
- package/dist/esm/signer/wallet-client.d.ts +46 -46
- package/dist/esm/signer/wallet-client.js.map +1 -1
- package/dist/esm/transport/split.js.map +1 -1
- package/dist/esm/utils/bigint.js.map +1 -1
- package/dist/esm/utils/bytes.js.map +1 -1
- package/dist/esm/utils/defaults.d.ts +1 -3
- package/dist/esm/utils/defaults.js +1 -40
- package/dist/esm/utils/defaults.js.map +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/types.js.map +1 -1
- package/dist/esm/utils/userop.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/account/smartContractAccount.d.ts +17 -11
- package/dist/types/account/smartContractAccount.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/buildUserOperationFromTx.d.ts +33 -33
- package/dist/types/actions/smartAccount/buildUserOperationFromTxs.d.ts +43 -59
- package/dist/types/actions/smartAccount/buildUserOperationFromTxs.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/checkGasSponsorshipEligibility.d.ts +18 -18
- package/dist/types/actions/smartAccount/estimateUserOperationGas.d.ts +3 -3
- package/dist/types/actions/smartAccount/internal/initUserOperation.d.ts +3 -4
- package/dist/types/actions/smartAccount/internal/initUserOperation.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/internal/runMiddlewareStack.d.ts +0 -14
- package/dist/types/actions/smartAccount/internal/runMiddlewareStack.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/internal/sendUserOperation.d.ts +0 -7
- package/dist/types/actions/smartAccount/internal/sendUserOperation.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/sendUserOperation.d.ts +17 -3
- package/dist/types/actions/smartAccount/sendUserOperation.d.ts.map +1 -1
- package/dist/types/client/bundlerClient.d.ts +2 -2
- package/dist/types/client/decorators/bundlerClient.d.ts +8 -8
- package/dist/types/client/isSmartAccountClient.d.ts +4 -4
- package/dist/types/client/types.d.ts +2 -7
- package/dist/types/client/types.d.ts.map +1 -1
- package/dist/types/errors/account.d.ts +53 -4
- package/dist/types/errors/account.d.ts.map +1 -1
- package/dist/types/errors/client.d.ts +15 -0
- package/dist/types/errors/client.d.ts.map +1 -1
- package/dist/types/errors/entrypoint.d.ts +12 -0
- package/dist/types/errors/entrypoint.d.ts.map +1 -1
- package/dist/types/errors/signer.d.ts +5 -0
- package/dist/types/errors/signer.d.ts.map +1 -1
- package/dist/types/errors/transaction.d.ts +8 -1
- package/dist/types/errors/transaction.d.ts.map +1 -1
- package/dist/types/errors/useroperation.d.ts +5 -5
- package/dist/types/errors/useroperation.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/logger.d.ts +88 -0
- package/dist/types/logger.d.ts.map +1 -1
- package/dist/types/middleware/actions.d.ts +3 -3
- package/dist/types/middleware/actions.d.ts.map +1 -1
- package/dist/types/middleware/defaults/gasEstimator.d.ts +2 -2
- package/dist/types/middleware/defaults/gasEstimator.d.ts.map +1 -1
- package/dist/types/middleware/erc7677middleware.d.ts +62 -0
- package/dist/types/middleware/erc7677middleware.d.ts.map +1 -0
- package/dist/types/middleware/noopMiddleware.d.ts +4 -4
- package/dist/types/middleware/noopMiddleware.d.ts.map +1 -1
- package/dist/types/middleware/types.d.ts +3 -2
- package/dist/types/middleware/types.d.ts.map +1 -1
- package/dist/types/signer/local-account.d.ts +139 -47
- package/dist/types/signer/local-account.d.ts.map +1 -1
- package/dist/types/signer/wallet-client.d.ts +135 -46
- package/dist/types/signer/wallet-client.d.ts.map +1 -1
- package/dist/types/transport/split.d.ts +2 -2
- package/dist/types/utils/bigint.d.ts +14 -14
- package/dist/types/utils/bigint.d.ts.map +1 -1
- package/dist/types/utils/bytes.d.ts +5 -5
- package/dist/types/utils/defaults.d.ts +1 -11
- package/dist/types/utils/defaults.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +12 -12
- package/dist/types/utils/types.d.ts +2 -2
- package/dist/types/utils/userop.d.ts +33 -33
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -2
- package/src/account/smartContractAccount.ts +19 -12
- package/src/actions/smartAccount/buildUserOperationFromTx.ts +35 -35
- package/src/actions/smartAccount/buildUserOperationFromTxs.ts +44 -60
- package/src/actions/smartAccount/checkGasSponsorshipEligibility.ts +19 -19
- package/src/actions/smartAccount/estimateUserOperationGas.ts +3 -3
- package/src/actions/smartAccount/internal/initUserOperation.ts +3 -4
- package/src/actions/smartAccount/internal/runMiddlewareStack.ts +0 -22
- package/src/actions/smartAccount/internal/sendUserOperation.ts +0 -7
- package/src/actions/smartAccount/sendUserOperation.ts +17 -3
- package/src/client/bundlerClient.ts +2 -2
- package/src/client/decorators/bundlerClient.ts +8 -8
- package/src/client/isSmartAccountClient.ts +4 -4
- package/src/client/types.ts +2 -15
- package/src/errors/account.ts +64 -4
- package/src/errors/client.ts +18 -0
- package/src/errors/entrypoint.ts +12 -0
- package/src/errors/signer.ts +6 -0
- package/src/errors/transaction.ts +10 -1
- package/src/errors/useroperation.ts +5 -6
- package/src/index.ts +2 -8
- package/src/logger.ts +88 -0
- package/src/middleware/actions.ts +6 -27
- package/src/middleware/defaults/gasEstimator.ts +8 -5
- package/src/middleware/erc7677middleware.ts +201 -0
- package/src/middleware/noopMiddleware.ts +6 -4
- package/src/middleware/types.ts +16 -7
- package/src/signer/local-account.ts +94 -2
- package/src/signer/wallet-client.ts +89 -0
- package/src/transport/split.ts +2 -2
- package/src/utils/bigint.ts +15 -15
- package/src/utils/bytes.ts +5 -5
- package/src/utils/defaults.ts +2 -74
- package/src/utils/index.ts +12 -12
- package/src/utils/types.ts +2 -2
- package/src/utils/userop.ts +33 -33
- package/src/version.ts +1 -1
- package/dist/cjs/account/base.d.ts +0 -49
- package/dist/cjs/account/base.js +0 -257
- package/dist/cjs/account/base.js.map +0 -1
- package/dist/cjs/account/schema.d.ts +0 -100
- package/dist/cjs/account/schema.js +0 -43
- package/dist/cjs/account/schema.js.map +0 -1
- package/dist/cjs/account/simple.d.ts +0 -14
- package/dist/cjs/account/simple.js +0 -119
- package/dist/cjs/account/simple.js.map +0 -1
- package/dist/cjs/account/types.d.ts +0 -30
- package/dist/cjs/account/types.js +0 -3
- package/dist/cjs/account/types.js.map +0 -1
- package/dist/esm/account/base.d.ts +0 -49
- package/dist/esm/account/base.js +0 -253
- package/dist/esm/account/base.js.map +0 -1
- package/dist/esm/account/schema.d.ts +0 -100
- package/dist/esm/account/schema.js +0 -35
- package/dist/esm/account/schema.js.map +0 -1
- package/dist/esm/account/simple.d.ts +0 -14
- package/dist/esm/account/simple.js +0 -115
- package/dist/esm/account/simple.js.map +0 -1
- package/dist/esm/account/types.d.ts +0 -30
- package/dist/esm/account/types.js +0 -2
- package/dist/esm/account/types.js.map +0 -1
- package/dist/types/account/base.d.ts +0 -128
- package/dist/types/account/base.d.ts.map +0 -1
- package/dist/types/account/schema.d.ts +0 -101
- package/dist/types/account/schema.d.ts.map +0 -1
- package/dist/types/account/simple.d.ts +0 -15
- package/dist/types/account/simple.d.ts.map +0 -1
- package/dist/types/account/types.d.ts +0 -144
- package/dist/types/account/types.d.ts.map +0 -1
- package/src/account/base.ts +0 -415
- package/src/account/schema.ts +0 -51
- package/src/account/simple.ts +0 -221
- package/src/account/types.ts +0 -184
package/dist/esm/account/base.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { getContract, http, trim, } from "viem";
|
|
2
|
-
import { EntryPointAbi_v6 as EntryPointAbi } from "../abis/EntryPointAbi_v6.js";
|
|
3
|
-
import { createBundlerClient, } from "../client/bundlerClient.js";
|
|
4
|
-
import { getEntryPoint } from "../entrypoint/index.js";
|
|
5
|
-
import { BatchExecutionNotSupportedError, FailedToGetStorageSlotError, GetCounterFactualAddressError, UpgradeToAndCallNotSupportedError, } from "../errors/account.js";
|
|
6
|
-
import { InvalidRpcUrlError } from "../errors/client.js";
|
|
7
|
-
import { Logger } from "../logger.js";
|
|
8
|
-
import { wrapSignatureWith6492 } from "../signer/utils.js";
|
|
9
|
-
import { createBaseSmartAccountParamsSchema } from "./schema.js";
|
|
10
|
-
export var DeploymentState;
|
|
11
|
-
(function (DeploymentState) {
|
|
12
|
-
DeploymentState["UNDEFINED"] = "0x0";
|
|
13
|
-
DeploymentState["NOT_DEPLOYED"] = "0x1";
|
|
14
|
-
DeploymentState["DEPLOYED"] = "0x2";
|
|
15
|
-
})(DeploymentState || (DeploymentState = {}));
|
|
16
|
-
export class BaseSmartContractAccount {
|
|
17
|
-
constructor(params_) {
|
|
18
|
-
Object.defineProperty(this, "factoryAddress", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "deploymentState", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: DeploymentState.UNDEFINED
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(this, "accountAddress", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(this, "accountInitCode", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
configurable: true,
|
|
39
|
-
writable: true,
|
|
40
|
-
value: void 0
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(this, "signer", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true,
|
|
46
|
-
value: void 0
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(this, "entryPoint", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(this, "entryPointAddress", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true,
|
|
58
|
-
value: void 0
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(this, "rpcProvider", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
configurable: true,
|
|
63
|
-
writable: true,
|
|
64
|
-
value: void 0
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(this, "encodeUpgradeToAndCall", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: async (_upgradeToImplAddress, _upgradeToInitData) => {
|
|
71
|
-
throw new UpgradeToAndCallNotSupportedError("BaseAccount");
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(this, "extend", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: (fn) => {
|
|
79
|
-
const extended = fn(this);
|
|
80
|
-
for (const key in this) {
|
|
81
|
-
delete extended[key];
|
|
82
|
-
}
|
|
83
|
-
return Object.assign(this, extended);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
const params = createBaseSmartAccountParamsSchema().parse(params_);
|
|
87
|
-
this.entryPointAddress =
|
|
88
|
-
params.entryPointAddress ?? getEntryPoint(params.chain).address;
|
|
89
|
-
const rpcUrl = typeof params.rpcClient === "string"
|
|
90
|
-
? params.rpcClient
|
|
91
|
-
: params.rpcClient.transport.type === "http"
|
|
92
|
-
? params.rpcClient.transport.url || params.chain.rpcUrls.default.http[0]
|
|
93
|
-
: undefined;
|
|
94
|
-
const fetchOptions = typeof params.rpcClient === "string"
|
|
95
|
-
? undefined
|
|
96
|
-
: params.rpcClient.transport.type === "http"
|
|
97
|
-
? params.rpcClient.transport.fetchOptions
|
|
98
|
-
: undefined;
|
|
99
|
-
this.rpcProvider = rpcUrl
|
|
100
|
-
? createBundlerClient({
|
|
101
|
-
chain: params.chain,
|
|
102
|
-
transport: http(rpcUrl, {
|
|
103
|
-
fetchOptions: {
|
|
104
|
-
...fetchOptions,
|
|
105
|
-
headers: {
|
|
106
|
-
...fetchOptions?.headers,
|
|
107
|
-
...(rpcUrl.toLowerCase().indexOf("alchemy") > -1
|
|
108
|
-
? {
|
|
109
|
-
"Alchemy-Aa-Sdk-Signer": params.signer?.signerType || "unknown",
|
|
110
|
-
"Alchemy-Aa-Sdk-Factory-Address": params.factoryAddress,
|
|
111
|
-
}
|
|
112
|
-
: undefined),
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
}),
|
|
116
|
-
})
|
|
117
|
-
: params.rpcClient;
|
|
118
|
-
this.accountAddress = params.accountAddress;
|
|
119
|
-
this.factoryAddress = params.factoryAddress;
|
|
120
|
-
this.signer = params.signer;
|
|
121
|
-
this.accountInitCode = params.initCode;
|
|
122
|
-
this.entryPoint = getContract({
|
|
123
|
-
address: this.entryPointAddress,
|
|
124
|
-
abi: EntryPointAbi,
|
|
125
|
-
client: this.rpcProvider,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
async signUserOperationHash(uoHash) {
|
|
129
|
-
return this.signMessage(uoHash);
|
|
130
|
-
}
|
|
131
|
-
async signTypedData(_params) {
|
|
132
|
-
throw new Error("signTypedData not supported");
|
|
133
|
-
}
|
|
134
|
-
async signMessageWith6492(msg) {
|
|
135
|
-
const [isDeployed, signature] = await Promise.all([
|
|
136
|
-
this.isAccountDeployed(),
|
|
137
|
-
this.signMessage(msg),
|
|
138
|
-
]);
|
|
139
|
-
return this.create6492Signature(isDeployed, signature);
|
|
140
|
-
}
|
|
141
|
-
async signTypedDataWith6492(params) {
|
|
142
|
-
const [isDeployed, signature] = await Promise.all([
|
|
143
|
-
this.isAccountDeployed(),
|
|
144
|
-
this.signTypedData(params),
|
|
145
|
-
]);
|
|
146
|
-
return this.create6492Signature(isDeployed, signature);
|
|
147
|
-
}
|
|
148
|
-
async encodeBatchExecute(_txs) {
|
|
149
|
-
throw new BatchExecutionNotSupportedError("BaseAccount");
|
|
150
|
-
}
|
|
151
|
-
async getNonce() {
|
|
152
|
-
if (!(await this.isAccountDeployed())) {
|
|
153
|
-
return 0n;
|
|
154
|
-
}
|
|
155
|
-
const address = await this.getAddress();
|
|
156
|
-
return this.entryPoint.read.getNonce([address, BigInt(0)]);
|
|
157
|
-
}
|
|
158
|
-
async getInitCode() {
|
|
159
|
-
if (this.deploymentState === DeploymentState.DEPLOYED) {
|
|
160
|
-
return "0x";
|
|
161
|
-
}
|
|
162
|
-
const contractCode = await this.rpcProvider.getBytecode({
|
|
163
|
-
address: await this.getAddress(),
|
|
164
|
-
});
|
|
165
|
-
if ((contractCode?.length ?? 0) > 2) {
|
|
166
|
-
this.deploymentState = DeploymentState.DEPLOYED;
|
|
167
|
-
return "0x";
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
this.deploymentState = DeploymentState.NOT_DEPLOYED;
|
|
171
|
-
}
|
|
172
|
-
return this._getAccountInitCode();
|
|
173
|
-
}
|
|
174
|
-
async getAddress() {
|
|
175
|
-
if (!this.accountAddress) {
|
|
176
|
-
const initCode = await this._getAccountInitCode();
|
|
177
|
-
Logger.verbose("[BaseSmartContractAccount](getAddress) initCode: ", initCode);
|
|
178
|
-
try {
|
|
179
|
-
await this.entryPoint.simulate.getSenderAddress([initCode]);
|
|
180
|
-
}
|
|
181
|
-
catch (err) {
|
|
182
|
-
Logger.verbose("[BaseSmartContractAccount](getAddress) getSenderAddress err: ", err);
|
|
183
|
-
if (err.cause?.data?.errorName === "SenderAddressResult") {
|
|
184
|
-
this.accountAddress = err.cause.data.args[0];
|
|
185
|
-
Logger.verbose("[BaseSmartContractAccount](getAddress) entryPoint.getSenderAddress result:", this.accountAddress);
|
|
186
|
-
return this.accountAddress;
|
|
187
|
-
}
|
|
188
|
-
if (err.details === "Invalid URL") {
|
|
189
|
-
throw new InvalidRpcUrlError();
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
throw new GetCounterFactualAddressError();
|
|
193
|
-
}
|
|
194
|
-
return this.accountAddress;
|
|
195
|
-
}
|
|
196
|
-
getSigner() {
|
|
197
|
-
return this.signer;
|
|
198
|
-
}
|
|
199
|
-
getFactoryAddress() {
|
|
200
|
-
return this.factoryAddress;
|
|
201
|
-
}
|
|
202
|
-
getEntryPointAddress() {
|
|
203
|
-
return this.entryPointAddress;
|
|
204
|
-
}
|
|
205
|
-
async isAccountDeployed() {
|
|
206
|
-
return (await this.getDeploymentState()) === DeploymentState.DEPLOYED;
|
|
207
|
-
}
|
|
208
|
-
async getDeploymentState() {
|
|
209
|
-
if (this.deploymentState === DeploymentState.UNDEFINED) {
|
|
210
|
-
const initCode = await this.getInitCode();
|
|
211
|
-
return initCode === "0x"
|
|
212
|
-
? DeploymentState.DEPLOYED
|
|
213
|
-
: DeploymentState.NOT_DEPLOYED;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
return this.deploymentState;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
async parseFactoryAddressFromAccountInitCode() {
|
|
220
|
-
const initCode = await this._getAccountInitCode();
|
|
221
|
-
const factoryAddress = `0x${initCode.substring(2, 42)}`;
|
|
222
|
-
const factoryCalldata = `0x${initCode.substring(42)}`;
|
|
223
|
-
return [factoryAddress, factoryCalldata];
|
|
224
|
-
}
|
|
225
|
-
async getImplementationAddress() {
|
|
226
|
-
const accountAddress = await this.getAddress();
|
|
227
|
-
const storage = await this.rpcProvider.getStorageAt({
|
|
228
|
-
address: accountAddress,
|
|
229
|
-
slot: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
|
|
230
|
-
});
|
|
231
|
-
if (storage == null) {
|
|
232
|
-
throw new FailedToGetStorageSlotError("0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc", "Proxy Implementation Address");
|
|
233
|
-
}
|
|
234
|
-
return trim(storage);
|
|
235
|
-
}
|
|
236
|
-
async _getAccountInitCode() {
|
|
237
|
-
return this.accountInitCode ?? this.getAccountInitCode();
|
|
238
|
-
}
|
|
239
|
-
async create6492Signature(isDeployed, signature) {
|
|
240
|
-
if (isDeployed) {
|
|
241
|
-
return signature;
|
|
242
|
-
}
|
|
243
|
-
const [factoryAddress, factoryCalldata] = await this.parseFactoryAddressFromAccountInitCode();
|
|
244
|
-
Logger.verbose(`[BaseSmartContractAccount](create6492Signature)\
|
|
245
|
-
factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`);
|
|
246
|
-
return wrapSignatureWith6492({
|
|
247
|
-
factoryAddress,
|
|
248
|
-
factoryCalldata,
|
|
249
|
-
signature,
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
//# sourceMappingURL=base.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":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AAmB,CAC/B,UAAmB,EACnB,SAAe;QAEf,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,CAAC,cAAc,EAAE,eAAe,CAAC,GACrC,MAAM,IAAI,CAAC,sCAAsC,EAAE,CAAC;QAEtD,MAAM,CAAC,OAAO,CACZ;0BACoB,cAAc,sBAAsB,eAAe,EAAE,CAC1E,CAAC;QAEF,OAAO,qBAAqB,CAAC;YAC3B,cAAc;YACd,eAAe;YACf,SAAS;SACV,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { Address } from \"abitype\";\nimport {\n getContract,\n http,\n trim,\n type GetContractReturnType,\n type Hash,\n type Hex,\n type HttpTransport,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport { EntryPointAbi_v6 as EntryPointAbi } from \"../abis/EntryPointAbi_v6.js\";\nimport {\n createBundlerClient,\n type BundlerClient,\n} from \"../client/bundlerClient.js\";\nimport { getEntryPoint } from \"../entrypoint/index.js\";\nimport {\n BatchExecutionNotSupportedError,\n FailedToGetStorageSlotError,\n GetCounterFactualAddressError,\n UpgradeToAndCallNotSupportedError,\n} from \"../errors/account.js\";\nimport { InvalidRpcUrlError } from \"../errors/client.js\";\nimport { Logger } from \"../logger.js\";\nimport type { SmartAccountSigner } from \"../signer/types.js\";\nimport { wrapSignatureWith6492 } from \"../signer/utils.js\";\nimport type { BatchUserOperationCallData, NullAddress } from \"../types.js\";\nimport { createBaseSmartAccountParamsSchema } from \"./schema.js\";\nimport type {\n BaseSmartAccountParams,\n ISmartContractAccount,\n SignTypedDataParams,\n} from \"./types.js\";\n\nexport enum DeploymentState {\n UNDEFINED = \"0x0\",\n NOT_DEPLOYED = \"0x1\",\n DEPLOYED = \"0x2\",\n}\n\n/**\n * @deprecated use `toSmartContractAccount` instead for creating SmartAccountInstances\n */\nexport abstract class BaseSmartContractAccount<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> implements ISmartContractAccount<TTransport, TSigner>\n{\n protected factoryAddress: Address;\n protected deploymentState: DeploymentState = DeploymentState.UNDEFINED;\n protected accountAddress?: Address;\n protected accountInitCode?: Hex;\n protected signer: TSigner;\n protected entryPoint: GetContractReturnType<\n typeof EntryPointAbi,\n PublicClient\n >;\n protected entryPointAddress: Address;\n readonly rpcProvider:\n | BundlerClient<TTransport>\n | BundlerClient<HttpTransport>;\n\n constructor(params_: BaseSmartAccountParams<TTransport, TSigner>) {\n const params = createBaseSmartAccountParamsSchema<\n TTransport,\n TSigner\n >().parse(params_);\n\n this.entryPointAddress =\n params.entryPointAddress ?? getEntryPoint(params.chain).address;\n\n const rpcUrl =\n typeof params.rpcClient === \"string\"\n ? params.rpcClient\n : params.rpcClient.transport.type === \"http\"\n ? (\n params.rpcClient.transport as ReturnType<HttpTransport>[\"config\"] &\n ReturnType<HttpTransport>[\"value\"]\n ).url || params.chain.rpcUrls.default.http[0]\n : undefined;\n\n const fetchOptions =\n typeof params.rpcClient === \"string\"\n ? undefined\n : params.rpcClient.transport.type === \"http\"\n ? (\n params.rpcClient.transport as ReturnType<HttpTransport>[\"config\"] &\n ReturnType<HttpTransport>[\"value\"]\n ).fetchOptions\n : undefined;\n\n this.rpcProvider = rpcUrl\n ? createBundlerClient({\n chain: params.chain,\n transport: http(rpcUrl, {\n fetchOptions: {\n ...fetchOptions,\n headers: {\n ...fetchOptions?.headers,\n ...(rpcUrl.toLowerCase().indexOf(\"alchemy\") > -1\n ? {\n \"Alchemy-Aa-Sdk-Signer\":\n params.signer?.signerType || \"unknown\",\n \"Alchemy-Aa-Sdk-Factory-Address\": params.factoryAddress,\n }\n : undefined),\n },\n },\n }),\n })\n : (params.rpcClient as BundlerClient<TTransport>);\n\n this.accountAddress = params.accountAddress;\n this.factoryAddress = params.factoryAddress;\n this.signer = params.signer as TSigner;\n this.accountInitCode = params.initCode as Hex;\n\n this.entryPoint = getContract({\n address: this.entryPointAddress,\n abi: EntryPointAbi,\n client: this.rpcProvider as PublicClient,\n });\n }\n\n //#region abstract-methods\n\n /**\n * This method should return a signature that will not `revert` during validation.\n * It does not have to pass validation, just not cause the contract to revert.\n * This is required for gas estimation so that the gas estimate are accurate.\n *\n */\n abstract getDummySignature(): Hex | Promise<Hex>;\n\n /**\n * this method should return the abi encoded function data for a call to your contract's `execute` method\n *\n * @param target -- equivalent to `to` in a normal transaction\n * @param value -- equivalent to `value` in a normal transaction\n * @param data -- equivalent to `data` in a normal transaction\n * @returns abi encoded function data for a call to your contract's `execute` method\n */\n abstract encodeExecute(\n target: string,\n value: bigint,\n data: string\n ): Promise<Hash>;\n\n /**\n * this should return an ERC-191 compliant message and is used to sign UO Hashes\n *\n * @param msg -- the message to sign\n */\n abstract signMessage(msg: string | Uint8Array): Promise<Hash>;\n\n /**\n * this should return the init code that will be used to create an account if one does not exist.\n * This is the concatenation of the account's factory address and the abi encoded function data of the account factory's `createAccount` method.\n * https://github.com/eth-infinitism/account-abstraction/blob/abff2aca61a8f0934e533d0d352978055fddbd96/contracts/core/SenderCreator.sol#L12\n */\n protected abstract getAccountInitCode(): Promise<Hash>;\n\n //#endregion abstract-methods\n\n //#region optional-methods\n\n /**\n * If your account handles 1271 signatures of personal_sign differently\n * than it does UserOperations, you can implement two different approaches to signing\n *\n * @param uoHash -- The hash of the UserOperation to sign\n * @returns the signature of the UserOperation\n */\n async signUserOperationHash(uoHash: Hash): Promise<Hash> {\n return this.signMessage(uoHash);\n }\n\n /**\n * If your contract supports signing and verifying typed data,\n * you should implement this method.\n *\n * @param _params -- Typed Data params to sign\n */\n async signTypedData(_params: SignTypedDataParams): Promise<`0x${string}`> {\n throw new Error(\"signTypedData not supported\");\n }\n\n /**\n * This method should wrap the result of `signMessage` as per\n * [EIP-6492](https://eips.ethereum.org/EIPS/eip-6492)\n *\n * @param msg -- the message to sign\n * @returns the signature wrapped in 6492 format\n */\n async signMessageWith6492(msg: string | Uint8Array): Promise<`0x${string}`> {\n const [isDeployed, signature] = await Promise.all([\n this.isAccountDeployed(),\n this.signMessage(msg),\n ]);\n\n return this.create6492Signature(isDeployed, signature);\n }\n\n /**\n * Similar to the signMessageWith6492 method above,\n * this method should wrap the result of `signTypedData` as per\n * [EIP-6492](https://eips.ethereum.org/EIPS/eip-6492)\n *\n * @param params -- Typed Data params to sign\n * @returns the signature wrapped in 6492 format\n */\n async signTypedDataWith6492(\n params: SignTypedDataParams\n ): Promise<`0x${string}`> {\n const [isDeployed, signature] = await Promise.all([\n this.isAccountDeployed(),\n this.signTypedData(params),\n ]);\n\n return this.create6492Signature(isDeployed, signature);\n }\n\n /**\n * Not all contracts support batch execution.\n * If your contract does, this method should encode a list of\n * transactions into the call data that will be passed to your\n * contract's batch execution method.\n *\n * @param _txs -- the transactions to batch execute\n */\n async encodeBatchExecute(\n _txs: BatchUserOperationCallData\n ): Promise<`0x${string}`> {\n throw new BatchExecutionNotSupportedError(\"BaseAccount\");\n }\n\n /**\n * If your contract supports UUPS, you can implement this method which can be\n * used to upgrade the implementation of the account.\n *\n * @param _upgradeToImplAddress -- the implementation address of the contract you want to upgrade to\n * @param _upgradeToInitData -- the initialization data required by that account\n */\n encodeUpgradeToAndCall = async (\n _upgradeToImplAddress: Address,\n _upgradeToInitData: Hex\n ): Promise<Hex> => {\n throw new UpgradeToAndCallNotSupportedError(\"BaseAccount\");\n };\n //#endregion optional-methods\n\n // Extra implementations\n async getNonce(): Promise<bigint> {\n if (!(await this.isAccountDeployed())) {\n return 0n;\n }\n const address = await this.getAddress();\n return this.entryPoint.read.getNonce([address, BigInt(0)]);\n }\n\n async getInitCode(): Promise<Hex> {\n if (this.deploymentState === DeploymentState.DEPLOYED) {\n return \"0x\";\n }\n\n const contractCode = await this.rpcProvider.getBytecode({\n address: await this.getAddress(),\n });\n\n if ((contractCode?.length ?? 0) > 2) {\n this.deploymentState = DeploymentState.DEPLOYED;\n return \"0x\";\n } else {\n this.deploymentState = DeploymentState.NOT_DEPLOYED;\n }\n\n return this._getAccountInitCode();\n }\n\n async getAddress(): Promise<Address> {\n if (!this.accountAddress) {\n const initCode = await this._getAccountInitCode();\n Logger.verbose(\n \"[BaseSmartContractAccount](getAddress) initCode: \",\n initCode\n );\n try {\n await this.entryPoint.simulate.getSenderAddress([initCode]);\n } catch (err: any) {\n Logger.verbose(\n \"[BaseSmartContractAccount](getAddress) getSenderAddress err: \",\n err\n );\n\n if (err.cause?.data?.errorName === \"SenderAddressResult\") {\n this.accountAddress = err.cause.data.args[0] as Address;\n Logger.verbose(\n \"[BaseSmartContractAccount](getAddress) entryPoint.getSenderAddress result:\",\n this.accountAddress\n );\n return this.accountAddress;\n }\n\n if (err.details === \"Invalid URL\") {\n throw new InvalidRpcUrlError();\n }\n }\n\n throw new GetCounterFactualAddressError();\n }\n\n return this.accountAddress;\n }\n\n extend = <R>(fn: (self: this) => R): this & R => {\n const extended = fn(this) as any;\n // this should make it so extensions can't overwrite the base methods\n for (const key in this) {\n delete extended[key];\n }\n return Object.assign(this, extended);\n };\n\n getSigner(): TSigner {\n return this.signer;\n }\n\n getFactoryAddress(): Address {\n return this.factoryAddress;\n }\n\n getEntryPointAddress(): Address {\n return this.entryPointAddress;\n }\n\n async isAccountDeployed(): Promise<boolean> {\n return (await this.getDeploymentState()) === DeploymentState.DEPLOYED;\n }\n\n async getDeploymentState(): Promise<DeploymentState> {\n if (this.deploymentState === DeploymentState.UNDEFINED) {\n const initCode = await this.getInitCode();\n return initCode === \"0x\"\n ? DeploymentState.DEPLOYED\n : DeploymentState.NOT_DEPLOYED;\n } else {\n return this.deploymentState;\n }\n }\n\n /**\n * https://eips.ethereum.org/EIPS/eip-4337#first-time-account-creation\n * The initCode field (if non-zero length) is parsed as a 20-byte address,\n * followed by calldata to pass to this address.\n * The factory address is the first 40 char after the 0x, and the callData is the rest.\n *\n * @returns [factoryAddress, factoryCalldata]\n */\n protected async parseFactoryAddressFromAccountInitCode(): Promise<\n [Address, Hex]\n > {\n const initCode = await this._getAccountInitCode();\n const factoryAddress: Address = `0x${initCode.substring(2, 42)}`;\n const factoryCalldata: Hex = `0x${initCode.substring(42)}`;\n return [factoryAddress, factoryCalldata];\n }\n\n protected async getImplementationAddress(): Promise<NullAddress | Address> {\n const accountAddress = await this.getAddress();\n\n const storage = await this.rpcProvider.getStorageAt({\n address: accountAddress,\n // This is the default slot for the implementation address for Proxies\n slot: \"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc\",\n });\n\n if (storage == null) {\n throw new FailedToGetStorageSlotError(\n \"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc\",\n \"Proxy Implementation Address\"\n );\n }\n\n return trim(storage);\n }\n\n private async _getAccountInitCode(): Promise<Hash> {\n return this.accountInitCode ?? this.getAccountInitCode();\n }\n\n private async create6492Signature(\n isDeployed: boolean,\n signature: Hash\n ): Promise<Hash> {\n if (isDeployed) {\n return signature;\n }\n\n const [factoryAddress, factoryCalldata] =\n await this.parseFactoryAddressFromAccountInitCode();\n\n Logger.verbose(\n `[BaseSmartContractAccount](create6492Signature)\\\n factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`\n );\n\n return wrapSignatureWith6492({\n factoryAddress,\n factoryCalldata,\n signature,\n });\n }\n}\n"]}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { type Transport } from "viem";
|
|
2
|
-
import z from "zod";
|
|
3
|
-
import type { SmartAccountSigner } from "../signer/types.js";
|
|
4
|
-
export declare const createBaseSmartAccountParamsSchema: <TTransport extends Transport = Transport, TSigner extends SmartAccountSigner<any> = SmartAccountSigner<any>>() => z.ZodObject<{
|
|
5
|
-
rpcClient: z.ZodUnion<[z.ZodString, z.ZodType<import("../index.js").BundlerClient<TTransport>, z.ZodTypeDef, import("../index.js").BundlerClient<TTransport>>]>;
|
|
6
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
7
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
8
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
9
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
10
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
11
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
12
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
13
|
-
}, "strip", z.ZodTypeAny, { [k_1 in keyof z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
14
|
-
rpcClient: z.ZodUnion<[z.ZodString, z.ZodType<import("../index.js").BundlerClient<TTransport>, z.ZodTypeDef, import("../index.js").BundlerClient<TTransport>>]>;
|
|
15
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
16
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
17
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
18
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
19
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
20
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
21
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
22
|
-
}>, "chain" | "factoryAddress" | "rpcClient" | (undefined extends TSigner ? never : "signer")>]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
23
|
-
rpcClient: z.ZodUnion<[z.ZodString, z.ZodType<import("../index.js").BundlerClient<TTransport>, z.ZodTypeDef, import("../index.js").BundlerClient<TTransport>>]>;
|
|
24
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
25
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
26
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
27
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
28
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
29
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
30
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
31
|
-
}>, "chain" | "factoryAddress" | "rpcClient" | (undefined extends TSigner ? never : "signer")>[k_1]; }, { [k_2 in keyof z.baseObjectInputType<{
|
|
32
|
-
rpcClient: z.ZodUnion<[z.ZodString, z.ZodType<import("../index.js").BundlerClient<TTransport>, z.ZodTypeDef, import("../index.js").BundlerClient<TTransport>>]>;
|
|
33
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
34
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
35
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
36
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
37
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
38
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
39
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
40
|
-
}>]: z.baseObjectInputType<{
|
|
41
|
-
rpcClient: z.ZodUnion<[z.ZodString, z.ZodType<import("../index.js").BundlerClient<TTransport>, z.ZodTypeDef, import("../index.js").BundlerClient<TTransport>>]>;
|
|
42
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
43
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
44
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
45
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
46
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
47
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
48
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
49
|
-
}>[k_2]; }>;
|
|
50
|
-
export declare const SimpleSmartAccountParamsSchema: <TTransport extends Transport = Transport, TSigner extends SmartAccountSigner<any> = SmartAccountSigner<any>>() => z.ZodObject<{
|
|
51
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
52
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
53
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
54
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
55
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
56
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
57
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
58
|
-
transport: z.ZodType<TTransport, z.ZodTypeDef, TTransport>;
|
|
59
|
-
salt: z.ZodOptional<z.ZodBigInt>;
|
|
60
|
-
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
61
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
62
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
63
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
64
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
65
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
66
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
67
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
68
|
-
transport: z.ZodType<TTransport, z.ZodTypeDef, TTransport>;
|
|
69
|
-
salt: z.ZodOptional<z.ZodBigInt>;
|
|
70
|
-
}>, "chain" | "factoryAddress" | (undefined extends TTransport ? never : "transport") | (undefined extends TSigner ? never : "signer")> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
71
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
72
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
73
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
74
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
75
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
76
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
77
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
78
|
-
transport: z.ZodType<TTransport, z.ZodTypeDef, TTransport>;
|
|
79
|
-
salt: z.ZodOptional<z.ZodBigInt>;
|
|
80
|
-
}>, "chain" | "factoryAddress" | (undefined extends TTransport ? never : "transport") | (undefined extends TSigner ? never : "signer")>[k]; } : never, z.baseObjectInputType<{
|
|
81
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
82
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
83
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
84
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
85
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
86
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
87
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
88
|
-
transport: z.ZodType<TTransport, z.ZodTypeDef, TTransport>;
|
|
89
|
-
salt: z.ZodOptional<z.ZodBigInt>;
|
|
90
|
-
}> extends infer T_1 ? { [k_1 in keyof T_1]: z.baseObjectInputType<{
|
|
91
|
-
initCode: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
|
|
92
|
-
chain: z.ZodType<import("viem").Chain, z.ZodTypeDef, import("viem").Chain>;
|
|
93
|
-
factoryAddress: z.ZodEffects<z.ZodString, `0x${string}`, string>;
|
|
94
|
-
signer: z.ZodType<TSigner, z.ZodTypeDef, TSigner>;
|
|
95
|
-
entryPointAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
96
|
-
accountAddress: z.ZodOptional<z.ZodEffects<z.ZodString, `0x${string}`, string>>;
|
|
97
|
-
entryPointVersion: z.ZodOptional<z.ZodType<keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>, z.ZodTypeDef, keyof import("../entrypoint/types.js").EntryPointRegistryBase<unknown>>>;
|
|
98
|
-
transport: z.ZodType<TTransport, z.ZodTypeDef, TTransport>;
|
|
99
|
-
salt: z.ZodOptional<z.ZodBigInt>;
|
|
100
|
-
}>[k_1]; } : never>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Address } from "abitype/zod";
|
|
2
|
-
import { isHex } from "viem";
|
|
3
|
-
import z from "zod";
|
|
4
|
-
import { createPublicErc4337ClientSchema } from "../client/schema.js";
|
|
5
|
-
import { isEntryPointVersion } from "../entrypoint/index.js";
|
|
6
|
-
import { isSigner } from "../signer/schema.js";
|
|
7
|
-
import { ChainSchema } from "../utils/index.js";
|
|
8
|
-
export const createBaseSmartAccountParamsSchema = () => z.object({
|
|
9
|
-
rpcClient: z.union([
|
|
10
|
-
z.string(),
|
|
11
|
-
createPublicErc4337ClientSchema(),
|
|
12
|
-
]),
|
|
13
|
-
factoryAddress: Address,
|
|
14
|
-
signer: z.custom(isSigner),
|
|
15
|
-
entryPointAddress: Address.optional(),
|
|
16
|
-
chain: ChainSchema,
|
|
17
|
-
accountAddress: Address.optional().describe("Optional override for the account address."),
|
|
18
|
-
initCode: z
|
|
19
|
-
.string()
|
|
20
|
-
.refine((x) => isHex(x, { strict: true }), "initCode must be a valid hex.")
|
|
21
|
-
.optional()
|
|
22
|
-
.describe("Optional override for the account init code."),
|
|
23
|
-
entryPointVersion: z
|
|
24
|
-
.custom(isEntryPointVersion)
|
|
25
|
-
.optional(),
|
|
26
|
-
});
|
|
27
|
-
export const SimpleSmartAccountParamsSchema = () => createBaseSmartAccountParamsSchema()
|
|
28
|
-
.omit({
|
|
29
|
-
rpcClient: true,
|
|
30
|
-
})
|
|
31
|
-
.extend({
|
|
32
|
-
transport: z.custom(),
|
|
33
|
-
salt: z.bigint().optional(),
|
|
34
|
-
});
|
|
35
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/account/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,KAAK,EAAkB,MAAM,MAAM,CAAC;AAC7C,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,+BAA+B,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,CAAC,MAAM,kCAAkC,GAAG,GAG9C,EAAE,CACJ,CAAC,CAAC,MAAM,CAAC;IACP,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC;QACjB,CAAC,CAAC,MAAM,EAAE;QACV,+BAA+B,EAAc;KAC9C,CAAC;IACF,cAAc,EAAE,OAAO;IACvB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAU,QAAQ,CAAC;IACnC,iBAAiB,EAAE,OAAO,CAAC,QAAQ,EAAE;IACrC,KAAK,EAAE,WAAW;IAClB,cAAc,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,CACzC,4CAA4C,CAC7C;IACD,QAAQ,EAAE,CAAC;SACR,MAAM,EAAE;SACR,MAAM,CACL,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EACjC,+BAA+B,CAChC;SACA,QAAQ,EAAE;SACV,QAAQ,CAAC,8CAA8C,CAAC;IAC3D,iBAAiB,EAAE,CAAC;SACjB,MAAM,CAAoB,mBAAmB,CAAC;SAC9C,QAAQ,EAAE;CACd,CAAC,CAAC;AAEL,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAG1C,EAAE,CACJ,kCAAkC,EAAuB;KACtD,IAAI,CAAC;IACJ,SAAS,EAAE,IAAI;CAChB,CAAC;KACD,MAAM,CAAC;IACN,SAAS,EAAE,CAAC,CAAC,MAAM,EAAc;IACjC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC5B,CAAC,CAAC","sourcesContent":["import { Address } from \"abitype/zod\";\nimport { isHex, type Transport } from \"viem\";\nimport z from \"zod\";\nimport { createPublicErc4337ClientSchema } from \"../client/schema.js\";\nimport { isEntryPointVersion } from \"../entrypoint/index.js\";\nimport type { EntryPointVersion } from \"../entrypoint/types.js\";\nimport { isSigner } from \"../signer/schema.js\";\nimport type { SmartAccountSigner } from \"../signer/types.js\";\nimport { ChainSchema } from \"../utils/index.js\";\n\nexport const createBaseSmartAccountParamsSchema = <\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner\n>() =>\n z.object({\n rpcClient: z.union([\n z.string(),\n createPublicErc4337ClientSchema<TTransport>(),\n ]),\n factoryAddress: Address,\n signer: z.custom<TSigner>(isSigner),\n entryPointAddress: Address.optional(),\n chain: ChainSchema,\n accountAddress: Address.optional().describe(\n \"Optional override for the account address.\"\n ),\n initCode: z\n .string()\n .refine(\n (x) => isHex(x, { strict: true }),\n \"initCode must be a valid hex.\"\n )\n .optional()\n .describe(\"Optional override for the account init code.\"),\n entryPointVersion: z\n .custom<EntryPointVersion>(isEntryPointVersion)\n .optional(),\n });\n\nexport const SimpleSmartAccountParamsSchema = <\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner\n>() =>\n createBaseSmartAccountParamsSchema<TTransport, TSigner>()\n .omit({\n rpcClient: true,\n })\n .extend({\n transport: z.custom<TTransport>(),\n salt: z.bigint().optional(),\n });\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Address } from "abitype";
|
|
2
|
-
import { type Chain, type Hex, type Transport } from "viem";
|
|
3
|
-
import type { DefaultEntryPointVersion, EntryPointParameter, EntryPointVersion } from "../entrypoint/types.js";
|
|
4
|
-
import type { SmartAccountSigner } from "../signer/types.js";
|
|
5
|
-
import { type SmartContractAccountWithSigner, type ToSmartContractAccountParams } from "./smartContractAccount.js";
|
|
6
|
-
export type SimpleSmartAccount<TSigner extends SmartAccountSigner = SmartAccountSigner, TEntryPointVersion extends EntryPointVersion = EntryPointVersion> = SmartContractAccountWithSigner<"SimpleAccount", TSigner, TEntryPointVersion>;
|
|
7
|
-
export type CreateSimpleAccountParams<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner, TEntryPointVersion extends EntryPointVersion = DefaultEntryPointVersion> = Pick<ToSmartContractAccountParams<"SimpleAccount", TTransport, Chain, TEntryPointVersion>, "chain" | "transport"> & {
|
|
8
|
-
signer: TSigner;
|
|
9
|
-
salt?: bigint;
|
|
10
|
-
accountAddress?: Address;
|
|
11
|
-
factoryAddress?: Address;
|
|
12
|
-
initCode?: Hex;
|
|
13
|
-
} & EntryPointParameter<TEntryPointVersion, Chain>;
|
|
14
|
-
export declare function createSimpleSmartAccount<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner, TEntryPointVersion extends EntryPointVersion = DefaultEntryPointVersion>(config: CreateSimpleAccountParams<TTransport, TSigner, TEntryPointVersion>): Promise<SimpleSmartAccount<TSigner, TEntryPointVersion>>;
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { concatHex, encodeFunctionData, isHex, } from "viem";
|
|
2
|
-
import { SimpleAccountAbi_v6 } from "../abis/SimpleAccountAbi_v6.js";
|
|
3
|
-
import { SimpleAccountAbi_v7 } from "../abis/SimpleAccountAbi_v7.js";
|
|
4
|
-
import { SimpleAccountFactoryAbi } from "../abis/SimpleAccountFactoryAbi.js";
|
|
5
|
-
import { createBundlerClient } from "../client/bundlerClient.js";
|
|
6
|
-
import { defaultEntryPointVersion, getEntryPoint, } from "../entrypoint/index.js";
|
|
7
|
-
import { AccountRequiresOwnerError } from "../errors/account.js";
|
|
8
|
-
import { getDefaultSimpleAccountFactoryAddress } from "../utils/defaults.js";
|
|
9
|
-
import { BaseSmartContractAccount } from "./base.js";
|
|
10
|
-
import { SimpleSmartAccountParamsSchema } from "./schema.js";
|
|
11
|
-
import { toSmartContractAccount, } from "./smartContractAccount.js";
|
|
12
|
-
class SimpleSmartContractAccount extends BaseSmartContractAccount {
|
|
13
|
-
constructor(params) {
|
|
14
|
-
SimpleSmartAccountParamsSchema().parse(params);
|
|
15
|
-
const client = createBundlerClient({
|
|
16
|
-
transport: params.transport,
|
|
17
|
-
chain: params.chain,
|
|
18
|
-
});
|
|
19
|
-
super({ ...params, rpcClient: client });
|
|
20
|
-
Object.defineProperty(this, "index", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: void 0
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(this, "entryPointVersion", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
configurable: true,
|
|
29
|
-
writable: true,
|
|
30
|
-
value: void 0
|
|
31
|
-
});
|
|
32
|
-
this.signer = params.signer;
|
|
33
|
-
this.index = params.salt ?? 0n;
|
|
34
|
-
this.entryPointVersion =
|
|
35
|
-
params.entryPointVersion ?? defaultEntryPointVersion;
|
|
36
|
-
}
|
|
37
|
-
getDummySignature() {
|
|
38
|
-
return "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
|
|
39
|
-
}
|
|
40
|
-
async encodeExecute(target, value, data) {
|
|
41
|
-
return encodeFunctionData({
|
|
42
|
-
abi: this.entryPointVersion === "0.6.0"
|
|
43
|
-
? SimpleAccountAbi_v6
|
|
44
|
-
: SimpleAccountAbi_v7,
|
|
45
|
-
functionName: "execute",
|
|
46
|
-
args: [target, value, data],
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
async encodeBatchExecute(txs) {
|
|
50
|
-
const [targets, datas] = txs.reduce((accum, curr) => {
|
|
51
|
-
accum[0].push(curr.target);
|
|
52
|
-
accum[1].push(curr.data);
|
|
53
|
-
return accum;
|
|
54
|
-
}, [[], []]);
|
|
55
|
-
return encodeFunctionData({
|
|
56
|
-
abi: this.entryPointVersion === "0.6.0"
|
|
57
|
-
? SimpleAccountAbi_v6
|
|
58
|
-
: SimpleAccountAbi_v7,
|
|
59
|
-
functionName: "executeBatch",
|
|
60
|
-
args: [targets, datas],
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
signMessage(msg) {
|
|
64
|
-
return this.signer.signMessage(typeof msg === "string" && !isHex(msg) ? msg : { raw: msg });
|
|
65
|
-
}
|
|
66
|
-
async getAccountInitCode() {
|
|
67
|
-
return concatHex([
|
|
68
|
-
this.factoryAddress,
|
|
69
|
-
encodeFunctionData({
|
|
70
|
-
abi: SimpleAccountFactoryAbi,
|
|
71
|
-
functionName: "createAccount",
|
|
72
|
-
args: [await this.signer.getAddress(), this.index],
|
|
73
|
-
}),
|
|
74
|
-
]);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
export async function createSimpleSmartAccount({ chain, entryPoint = getEntryPoint(chain), factoryAddress = getDefaultSimpleAccountFactoryAddress(chain, entryPoint.version), ...params }) {
|
|
78
|
-
if (!params.signer)
|
|
79
|
-
throw new AccountRequiresOwnerError("SimpleAccount");
|
|
80
|
-
const simpleAccount = new SimpleSmartContractAccount(SimpleSmartAccountParamsSchema().parse({
|
|
81
|
-
chain,
|
|
82
|
-
entryPointAddress: entryPoint.address,
|
|
83
|
-
factoryAddress,
|
|
84
|
-
...params,
|
|
85
|
-
}));
|
|
86
|
-
const parsedParams = SimpleSmartAccountParamsSchema().parse({
|
|
87
|
-
chain,
|
|
88
|
-
entryPointAddress: entryPoint.address,
|
|
89
|
-
entryPointVersion: entryPoint.version,
|
|
90
|
-
factoryAddress,
|
|
91
|
-
...params,
|
|
92
|
-
});
|
|
93
|
-
const base = await toSmartContractAccount({
|
|
94
|
-
source: "SimpleAccount",
|
|
95
|
-
transport: params.transport,
|
|
96
|
-
chain,
|
|
97
|
-
encodeBatchExecute: simpleAccount.encodeBatchExecute.bind(simpleAccount),
|
|
98
|
-
encodeExecute: (tx) => simpleAccount.encodeExecute.bind(simpleAccount)(tx.target, tx.value ?? 0n, tx.data),
|
|
99
|
-
entryPoint,
|
|
100
|
-
getAccountInitCode: async () => {
|
|
101
|
-
if (parsedParams.initCode)
|
|
102
|
-
return parsedParams.initCode;
|
|
103
|
-
return simpleAccount.getAccountInitCode();
|
|
104
|
-
},
|
|
105
|
-
getDummySignature: simpleAccount.getDummySignature.bind(simpleAccount),
|
|
106
|
-
signMessage: ({ message }) => simpleAccount.signMessage(typeof message === "string" ? message : message.raw),
|
|
107
|
-
signTypedData: simpleAccount.signTypedData.bind(simpleAccount),
|
|
108
|
-
accountAddress: parsedParams.accountAddress,
|
|
109
|
-
});
|
|
110
|
-
return {
|
|
111
|
-
...base,
|
|
112
|
-
getSigner: () => simpleAccount.getSigner(),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=simple.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"simple.js","sourceRoot":"","sources":["../../../src/account/simple.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,KAAK,GAKN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,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AAC,IAAI,CAAC,aAAa,CAAC;QACtE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAC3B,aAAa,CAAC,WAAW,CACvB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CACpD;QAEH,aAAa,EAAE,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC;QAC9D,cAAc,EAAE,YAAY,CAAC,cAAc;KAC5C,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE;KAC3C,CAAC;AACJ,CAAC","sourcesContent":["import type { Address } from \"abitype\";\nimport {\n concatHex,\n encodeFunctionData,\n isHex,\n type Chain,\n type FallbackTransport,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { SimpleAccountAbi_v6 } from \"../abis/SimpleAccountAbi_v6.js\";\nimport { SimpleAccountAbi_v7 } from \"../abis/SimpleAccountAbi_v7.js\";\nimport { SimpleAccountFactoryAbi } from \"../abis/SimpleAccountFactoryAbi.js\";\nimport { createBundlerClient } from \"../client/bundlerClient.js\";\nimport {\n defaultEntryPointVersion,\n getEntryPoint,\n} from \"../entrypoint/index.js\";\nimport type {\n DefaultEntryPointVersion,\n EntryPointParameter,\n EntryPointVersion,\n} from \"../entrypoint/types.js\";\nimport { AccountRequiresOwnerError } from \"../errors/account.js\";\nimport type { SmartAccountSigner } from \"../signer/types.js\";\nimport type { BatchUserOperationCallData } from \"../types.js\";\nimport { getDefaultSimpleAccountFactoryAddress } from \"../utils/defaults.js\";\nimport { BaseSmartContractAccount } from \"./base.js\";\nimport { SimpleSmartAccountParamsSchema } from \"./schema.js\";\nimport {\n toSmartContractAccount,\n type SmartContractAccountWithSigner,\n type ToSmartContractAccountParams,\n} from \"./smartContractAccount.js\";\nimport type { SimpleSmartAccountParams } from \"./types.js\";\n\nclass SimpleSmartContractAccount<\n TTransport extends Transport | FallbackTransport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> extends BaseSmartContractAccount<TTransport, TSigner> {\n protected index: bigint;\n protected entryPointVersion: EntryPointVersion;\n\n constructor(params: SimpleSmartAccountParams<TTransport, TSigner>) {\n SimpleSmartAccountParamsSchema().parse(params);\n\n // This is a hack for now, we should kill the SimpleSmart Account when we kill Base Account\n const client = createBundlerClient({\n transport: params.transport as TTransport,\n chain: params.chain,\n });\n\n // @ts-expect-error zod custom type not recognized as required params for signers\n super({ ...params, rpcClient: client });\n this.signer = params.signer as TSigner;\n this.index = params.salt ?? 0n;\n this.entryPointVersion =\n params.entryPointVersion ?? defaultEntryPointVersion;\n }\n\n getDummySignature(): `0x${string}` {\n return \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n }\n\n async encodeExecute(\n target: Hex,\n value: bigint,\n data: Hex\n ): Promise<`0x${string}`> {\n return encodeFunctionData({\n abi:\n this.entryPointVersion === \"0.6.0\"\n ? SimpleAccountAbi_v6\n : SimpleAccountAbi_v7,\n functionName: \"execute\",\n args: [target, value, data],\n });\n }\n\n override async encodeBatchExecute(\n txs: BatchUserOperationCallData\n ): Promise<`0x${string}`> {\n const [targets, datas] = txs.reduce(\n (accum, curr) => {\n accum[0].push(curr.target);\n accum[1].push(curr.data);\n\n return accum;\n },\n [[], []] as [Address[], Hex[]]\n );\n\n return encodeFunctionData({\n abi:\n this.entryPointVersion === \"0.6.0\"\n ? SimpleAccountAbi_v6\n : SimpleAccountAbi_v7,\n functionName: \"executeBatch\",\n args: [targets, datas],\n });\n }\n\n signMessage(msg: Uint8Array | string): Promise<`0x${string}`> {\n return this.signer.signMessage(\n typeof msg === \"string\" && !isHex(msg) ? msg : { raw: msg }\n );\n }\n\n public async getAccountInitCode(): Promise<`0x${string}`> {\n return concatHex([\n this.factoryAddress,\n encodeFunctionData({\n abi: SimpleAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [await this.signer.getAddress(), this.index],\n }),\n ]);\n }\n}\n\nexport type SimpleSmartAccount<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TEntryPointVersion extends EntryPointVersion = EntryPointVersion\n> = SmartContractAccountWithSigner<\n \"SimpleAccount\",\n TSigner,\n TEntryPointVersion\n>;\n\nexport type CreateSimpleAccountParams<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TEntryPointVersion extends EntryPointVersion = DefaultEntryPointVersion\n> = Pick<\n ToSmartContractAccountParams<\n \"SimpleAccount\",\n TTransport,\n Chain,\n TEntryPointVersion\n >,\n \"chain\" | \"transport\"\n> & {\n signer: TSigner;\n salt?: bigint;\n accountAddress?: Address;\n factoryAddress?: Address;\n initCode?: Hex;\n} & EntryPointParameter<TEntryPointVersion, Chain>;\n\nexport async function createSimpleSmartAccount<\n TTransport extends Transport = Transport,\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n TEntryPointVersion extends EntryPointVersion = DefaultEntryPointVersion\n>(\n config: CreateSimpleAccountParams<TTransport, TSigner, TEntryPointVersion>\n): Promise<SimpleSmartAccount<TSigner, TEntryPointVersion>>;\n\n/**\n * Creates a simple smart account using the provided parameters, including chain, entry point, factory address, and additional parameters. This function also ensures that a signer is provided.\n *\n * @param {CreateSimpleAccountParams} config The parameters for creating a simple smart account\n * @returns {Promise<SimpleSmartAccount>} A promise that resolves to a `SimpleSmartAccount` object containing the created account information and methods\n */\nexport async function createSimpleSmartAccount({\n chain,\n entryPoint = getEntryPoint(chain),\n factoryAddress = getDefaultSimpleAccountFactoryAddress(\n chain,\n entryPoint.version\n ),\n ...params\n}: CreateSimpleAccountParams): Promise<SimpleSmartAccount> {\n if (!params.signer) throw new AccountRequiresOwnerError(\"SimpleAccount\");\n const simpleAccount = new SimpleSmartContractAccount(\n SimpleSmartAccountParamsSchema().parse({\n chain,\n entryPointAddress: entryPoint.address,\n factoryAddress,\n ...params,\n })\n );\n\n const parsedParams = SimpleSmartAccountParamsSchema().parse({\n chain,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n factoryAddress,\n ...params,\n });\n\n const base = await toSmartContractAccount({\n source: \"SimpleAccount\",\n transport: params.transport,\n chain,\n encodeBatchExecute: simpleAccount.encodeBatchExecute.bind(simpleAccount),\n encodeExecute: (tx) =>\n simpleAccount.encodeExecute.bind(simpleAccount)(\n tx.target,\n tx.value ?? 0n,\n tx.data\n ),\n entryPoint,\n getAccountInitCode: async () => {\n if (parsedParams.initCode) return parsedParams.initCode as Hex;\n return simpleAccount.getAccountInitCode();\n },\n getDummySignature: simpleAccount.getDummySignature.bind(simpleAccount),\n signMessage: ({ message }) =>\n simpleAccount.signMessage(\n typeof message === \"string\" ? message : message.raw\n ),\n // @ts-expect-error these types still represent the same thing, but they are just a little off in there definitions\n signTypedData: simpleAccount.signTypedData.bind(simpleAccount),\n accountAddress: parsedParams.accountAddress,\n });\n\n return {\n ...base,\n getSigner: () => simpleAccount.getSigner(),\n };\n}\n"]}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Address } from "abitype";
|
|
2
|
-
import type { Hash, Hex, HttpTransport, Transport } from "viem";
|
|
3
|
-
import type { SignTypedDataParameters } from "viem/accounts";
|
|
4
|
-
import type { z } from "zod";
|
|
5
|
-
import type { BundlerClient } from "../client/bundlerClient";
|
|
6
|
-
import type { SmartAccountSigner } from "../signer/types";
|
|
7
|
-
import type { BatchUserOperationCallData } from "../types";
|
|
8
|
-
import type { SimpleSmartAccountParamsSchema, createBaseSmartAccountParamsSchema } from "./schema";
|
|
9
|
-
export type SignTypedDataParams = Omit<SignTypedDataParameters, "privateKey">;
|
|
10
|
-
export type BaseSmartAccountParams<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner> = z.input<ReturnType<typeof createBaseSmartAccountParamsSchema<TTransport, TSigner>>>;
|
|
11
|
-
export type SimpleSmartAccountParams<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner> = z.input<ReturnType<typeof SimpleSmartAccountParamsSchema<TTransport, TSigner>>>;
|
|
12
|
-
export interface ISmartContractAccount<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner> {
|
|
13
|
-
readonly rpcProvider: BundlerClient<TTransport> | BundlerClient<HttpTransport>;
|
|
14
|
-
getInitCode(): Promise<Hex>;
|
|
15
|
-
getDummySignature(): Hex | Promise<Hex>;
|
|
16
|
-
encodeExecute(target: string, value: bigint, data: string): Promise<Hex>;
|
|
17
|
-
encodeBatchExecute(txs: BatchUserOperationCallData): Promise<Hex>;
|
|
18
|
-
getNonce(): Promise<bigint>;
|
|
19
|
-
signUserOperationHash(uoHash: Hash): Promise<Hash>;
|
|
20
|
-
signMessage(msg: string | Uint8Array | Hex): Promise<Hex>;
|
|
21
|
-
signTypedData(params: SignTypedDataParams): Promise<Hash>;
|
|
22
|
-
signMessageWith6492(msg: string | Uint8Array | Hex): Promise<Hex>;
|
|
23
|
-
signTypedDataWith6492(params: SignTypedDataParams): Promise<Hash>;
|
|
24
|
-
getAddress(): Promise<Address>;
|
|
25
|
-
getSigner(): TSigner;
|
|
26
|
-
getFactoryAddress(): Address;
|
|
27
|
-
getEntryPointAddress(): Address;
|
|
28
|
-
extend: <R>(extendFn: (self: this) => R) => this & R;
|
|
29
|
-
encodeUpgradeToAndCall: (upgradeToImplAddress: Address, upgradeToInitData: Hex) => Promise<Hex>;
|
|
30
|
-
}
|