@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/src/utils/index.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { RecordableKeys } from "./types.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* Utility function that allows for piping a series of async functions together
|
|
7
7
|
*
|
|
8
|
-
* @param fns - functions to pipe
|
|
9
|
-
* @returns result of the pipe
|
|
8
|
+
* @param {((s: S, o?: O, f?: F) => Promise<S>)[]} fns - functions to pipe
|
|
9
|
+
* @returns {S} result of the pipe
|
|
10
10
|
*/
|
|
11
11
|
export const asyncPipe =
|
|
12
12
|
<S, O, F>(...fns: ((s: S, o?: O, f?: F) => Promise<S>)[]) =>
|
|
@@ -24,10 +24,10 @@ export type Deferrable<T> = {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* Await all of the properties of a
|
|
27
|
+
* Await all of the properties of a Deferrable object
|
|
28
28
|
*
|
|
29
|
-
* @param object - a
|
|
30
|
-
* @returns the object with its properties resolved
|
|
29
|
+
* @param {Deferrable<T>} object - a Deferrable object
|
|
30
|
+
* @returns {Promise<T>} the object with its properties resolved
|
|
31
31
|
*/
|
|
32
32
|
export async function resolveProperties<T>(object: Deferrable<T>): Promise<T> {
|
|
33
33
|
const promises = Object.keys(object).map((key) => {
|
|
@@ -48,8 +48,8 @@ export async function resolveProperties<T>(object: Deferrable<T>): Promise<T> {
|
|
|
48
48
|
/**
|
|
49
49
|
* Recursively converts all values in an object to hex strings
|
|
50
50
|
*
|
|
51
|
-
* @param obj - obj to deep hexlify
|
|
52
|
-
* @returns object with all of its values hexlified
|
|
51
|
+
* @param {any} obj - obj to deep hexlify
|
|
52
|
+
* @returns {any} object with all of its values hexlified
|
|
53
53
|
*/
|
|
54
54
|
export function deepHexlify(obj: any): any {
|
|
55
55
|
if (typeof obj === "function") {
|
|
@@ -126,8 +126,8 @@ export function pick(obj: Record<string, unknown>, keys: string | string[]) {
|
|
|
126
126
|
/**
|
|
127
127
|
* Utility method for checking if the passed in values are all equal (strictly)
|
|
128
128
|
*
|
|
129
|
-
* @param params - values to check
|
|
130
|
-
* @returns a boolean indicating if all values are the same
|
|
129
|
+
* @param {...any[]} params - values to check
|
|
130
|
+
* @returns {boolean} a boolean indicating if all values are the same
|
|
131
131
|
* @throws if no values are passed in
|
|
132
132
|
*/
|
|
133
133
|
export const allEqual = (...params: any[]): boolean => {
|
|
@@ -140,9 +140,9 @@ export const allEqual = (...params: any[]): boolean => {
|
|
|
140
140
|
/**
|
|
141
141
|
* Utility method for checking the condition and return the value if condition holds true, undefined if not.
|
|
142
142
|
*
|
|
143
|
-
* @param condition - condition to check
|
|
144
|
-
* @param value - value to return when condition holds true
|
|
145
|
-
* @returns the value if condition holds true, undefined if not
|
|
143
|
+
* @param {Promise<boolean>} condition - condition to check
|
|
144
|
+
* @param {() => Promise<T>} value - value to return when condition holds true
|
|
145
|
+
* @returns {Promise<T | undefined>} the value if condition holds true, undefined if not
|
|
146
146
|
*/
|
|
147
147
|
export const conditionalReturn = <T>(
|
|
148
148
|
condition: Promise<boolean>,
|
package/src/utils/types.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
export type NoUndefined<T> = T extends undefined ? never : T;
|
|
11
11
|
// borrowed from viem
|
|
12
12
|
/**
|
|
13
|
-
* @description Checks if
|
|
13
|
+
* @description Checks if T is `undefined`
|
|
14
14
|
* @param T - Type to check
|
|
15
15
|
* @example
|
|
16
16
|
* type Result = IsUndefined<undefined>
|
|
@@ -27,7 +27,7 @@ export type RequiredBy<TType, TKeys extends keyof TType> = Required<
|
|
|
27
27
|
/**
|
|
28
28
|
* @description Combines members of an intersection into a readable type.
|
|
29
29
|
*
|
|
30
|
-
* @see
|
|
30
|
+
* @see https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg
|
|
31
31
|
* @example
|
|
32
32
|
* Prettify<{ a: string } & { b: string } & { c: number, d: bigint }>
|
|
33
33
|
* => { a: string, b: string, c: number, d: bigint }
|
package/src/utils/userop.ts
CHANGED
|
@@ -14,10 +14,10 @@ import { bigIntClamp, bigIntMultiply } from "./bigint.js";
|
|
|
14
14
|
import { allEqual, isBigNumberish } from "./index.js";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Utility method for asserting a
|
|
17
|
+
* Utility method for asserting a UserOperationStruct has valid fields for the given entry point version
|
|
18
18
|
*
|
|
19
|
-
* @param request a
|
|
20
|
-
* @returns a type guard that asserts the
|
|
19
|
+
* @param {UserOperationStruct} request a UserOperationStruct to validate
|
|
20
|
+
* @returns {boolean} a type guard that asserts the UserOperationRequest is valid
|
|
21
21
|
*/
|
|
22
22
|
export function isValidRequest<
|
|
23
23
|
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
@@ -37,10 +37,10 @@ export function isValidRequest<
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* Utility method for asserting a
|
|
40
|
+
* Utility method for asserting a UserOperationRequest has valid fields for the paymaster data
|
|
41
41
|
*
|
|
42
|
-
* @param request a
|
|
43
|
-
* @returns a type guard that asserts the
|
|
42
|
+
* @param {UserOperationRequest} request a UserOperationRequest to validate
|
|
43
|
+
* @returns {boolean} a type guard that asserts the UserOperationRequest is a UserOperationRequest
|
|
44
44
|
*/
|
|
45
45
|
export function isValidPaymasterAndData<
|
|
46
46
|
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
@@ -59,10 +59,10 @@ export function isValidPaymasterAndData<
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Utility method for asserting a
|
|
62
|
+
* Utility method for asserting a UserOperationStruct has valid fields for the paymaster data
|
|
63
63
|
*
|
|
64
|
-
* @param request a
|
|
65
|
-
* @returns a type guard that asserts the
|
|
64
|
+
* @param {UserOperationRequest} request a UserOperationRequest to validate
|
|
65
|
+
* @returns {boolean} a type guard that asserts the UserOperationStruct is a UserOperationRequest
|
|
66
66
|
*/
|
|
67
67
|
export function isValidFactoryAndData<
|
|
68
68
|
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
@@ -80,12 +80,12 @@ export function isValidFactoryAndData<
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Utility method for applying a
|
|
83
|
+
* Utility method for applying a UserOperationOverrides field value
|
|
84
84
|
* over the current value set for the field
|
|
85
85
|
*
|
|
86
|
-
* @param value the current value of the field
|
|
87
|
-
* @param override the override value to apply
|
|
88
|
-
* @returns the new value of the field after applying the override
|
|
86
|
+
* @param {BigNumberish} value the current value of the field
|
|
87
|
+
* @param {BigNumberish | Multiplier} override the override value to apply
|
|
88
|
+
* @returns {BigNumberish} the new value of the field after applying the override
|
|
89
89
|
*/
|
|
90
90
|
export function applyUserOpOverride<TValue extends BigNumberish | undefined>(
|
|
91
91
|
value: TValue,
|
|
@@ -106,12 +106,12 @@ export function applyUserOpOverride<TValue extends BigNumberish | undefined>(
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
* Utility method for applying a
|
|
109
|
+
* Utility method for applying a UserOperationFeeOptionsField value
|
|
110
110
|
* over the current value set for the field
|
|
111
111
|
*
|
|
112
|
-
* @param value the current value of the field
|
|
113
|
-
* @param feeOption the
|
|
114
|
-
* @returns the new value of the field after applying the
|
|
112
|
+
* @param {BigNumberish} value the current value of the field
|
|
113
|
+
* @param {UserOperationFeeOptionsField} feeOption the override value to apply
|
|
114
|
+
* @returns {BigNumberish} the new value of the field after applying the override
|
|
115
115
|
*/
|
|
116
116
|
export function applyUserOpFeeOption<TValue extends BigNumberish | undefined>(
|
|
117
117
|
value: TValue,
|
|
@@ -133,14 +133,14 @@ export function applyUserOpFeeOption<TValue extends BigNumberish | undefined>(
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
|
-
* Utility method for applying a
|
|
137
|
-
* a
|
|
136
|
+
* Utility method for applying a UserOperationOverrides field value and
|
|
137
|
+
* a UserOperationFeeOptionsField value over the current value set for the field,
|
|
138
138
|
* with the override taking precedence over the fee option
|
|
139
139
|
*
|
|
140
|
-
* @param value the current value of the field
|
|
141
|
-
* @param [override] the override value to apply
|
|
142
|
-
* @param [feeOption] the fee option field value to apply
|
|
143
|
-
* @returns the new value of the field after applying the override or fee option
|
|
140
|
+
* @param {BigNumberish} value the current value of the field
|
|
141
|
+
* @param {BigNumberish | Multiplier} [override] the override value to apply
|
|
142
|
+
* @param {UserOperationFeeOptionsField} [feeOption] the fee option field value to apply
|
|
143
|
+
* @returns {BigNumberish} the new value of the field after applying the override or fee option
|
|
144
144
|
*/
|
|
145
145
|
export function applyUserOpOverrideOrFeeOption<
|
|
146
146
|
TValue extends BigNumberish | undefined
|
|
@@ -160,8 +160,8 @@ export function applyUserOpOverrideOrFeeOption<
|
|
|
160
160
|
* either because the UserOp is paying for its own gas, or passing a specific paymaster
|
|
161
161
|
*
|
|
162
162
|
* @template EntryPointVersion TEntryPointVersion
|
|
163
|
-
* @param overrides the user operation overrides to check
|
|
164
|
-
* @returns whether the paymaster middleware should be bypassed
|
|
163
|
+
* @param {UserOperationOverrides<TEntryPointVersion> | undefined} overrides the user operation overrides to check
|
|
164
|
+
* @returns {boolean} whether the paymaster middleware should be bypassed
|
|
165
165
|
*/
|
|
166
166
|
export const bypassPaymasterAndData = <
|
|
167
167
|
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
@@ -177,8 +177,8 @@ export const bypassPaymasterAndData = <
|
|
|
177
177
|
* pay for its own gas
|
|
178
178
|
*
|
|
179
179
|
* @template EntryPointVersion TEntryPointVersion
|
|
180
|
-
* @param overrides the user operation overrides to check
|
|
181
|
-
* @returns whether the paymaster middleware should be bypassed
|
|
180
|
+
* @param {UserOperationOverrides<TEntryPointVersion> | undefined} overrides the user operation overrides to check
|
|
181
|
+
* @returns {boolean} whether the paymaster middleware should be bypassed
|
|
182
182
|
*/
|
|
183
183
|
export const bypassPaymasterAndDataEmptyHex = <
|
|
184
184
|
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
@@ -192,9 +192,9 @@ export const bypassPaymasterAndDataEmptyHex = <
|
|
|
192
192
|
/**
|
|
193
193
|
* Utility method for parsing the paymaster address and paymasterData from the paymasterAndData hex string
|
|
194
194
|
*
|
|
195
|
-
* @param paymasterAndData the paymaster and data hex string to parse.
|
|
195
|
+
* @param {Hex} paymasterAndData the paymaster and data hex string to parse.
|
|
196
196
|
* The hex string refers to the paymasterAndData field of entrypoint v0.6 user operation request
|
|
197
|
-
* @returns the parsed paymaster and paymasterData fields of entrypoint v0.7 user operation request paymaster and paymasterData field
|
|
197
|
+
* @returns {{ paymaster: Hex; paymasterData: Hex}} the parsed paymaster and paymasterData fields of entrypoint v0.7 user operation request paymaster and paymasterData field
|
|
198
198
|
*/
|
|
199
199
|
export const parsePaymasterAndData = (
|
|
200
200
|
paymasterAndData: Hex
|
|
@@ -207,11 +207,11 @@ export const parsePaymasterAndData = (
|
|
|
207
207
|
* Utility method for converting the object containing the paymaster address and paymaster data
|
|
208
208
|
* to the paymaster and data concatenated hex string
|
|
209
209
|
*
|
|
210
|
-
* @param paymasterAndData the object containing the picked paymaster and paymasterData fields of
|
|
210
|
+
* @param {{ paymaster: Hex; paymasterData: Hex}} paymasterAndData the object containing the picked paymaster and paymasterData fields of
|
|
211
211
|
* entrypoint v0.7 user operation request
|
|
212
|
-
* @param paymasterAndData.paymaster the paymaster address
|
|
213
|
-
* @param paymasterAndData.paymasterData the paymaster data
|
|
214
|
-
* @returns the paymasterAndData hex value of entrypoint v0.6 user operation request paymasterAndData field
|
|
212
|
+
* @param {Hex} paymasterAndData.paymaster the paymaster address
|
|
213
|
+
* @param {Hex} paymasterAndData.paymasterData the paymaster data
|
|
214
|
+
* @returns {Hex} the paymasterAndData hex value of entrypoint v0.6 user operation request paymasterAndData field
|
|
215
215
|
*/
|
|
216
216
|
export const concatPaymasterAndData = ({
|
|
217
217
|
paymaster = "0x",
|
package/src/version.ts
CHANGED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Address } from "abitype";
|
|
2
|
-
import { type GetContractReturnType, type Hash, type Hex, type HttpTransport, type PublicClient, type Transport } from "viem";
|
|
3
|
-
import { EntryPointAbi_v6 as EntryPointAbi } from "../abis/EntryPointAbi_v6.js";
|
|
4
|
-
import { type BundlerClient } from "../client/bundlerClient.js";
|
|
5
|
-
import type { SmartAccountSigner } from "../signer/types.js";
|
|
6
|
-
import type { BatchUserOperationCallData, NullAddress } from "../types.js";
|
|
7
|
-
import type { BaseSmartAccountParams, ISmartContractAccount, SignTypedDataParams } from "./types.js";
|
|
8
|
-
export declare enum DeploymentState {
|
|
9
|
-
UNDEFINED = "0x0",
|
|
10
|
-
NOT_DEPLOYED = "0x1",
|
|
11
|
-
DEPLOYED = "0x2"
|
|
12
|
-
}
|
|
13
|
-
export declare abstract class BaseSmartContractAccount<TTransport extends Transport = Transport, TSigner extends SmartAccountSigner = SmartAccountSigner> implements ISmartContractAccount<TTransport, TSigner> {
|
|
14
|
-
protected factoryAddress: Address;
|
|
15
|
-
protected deploymentState: DeploymentState;
|
|
16
|
-
protected accountAddress?: Address;
|
|
17
|
-
protected accountInitCode?: Hex;
|
|
18
|
-
protected signer: TSigner;
|
|
19
|
-
protected entryPoint: GetContractReturnType<typeof EntryPointAbi, PublicClient>;
|
|
20
|
-
protected entryPointAddress: Address;
|
|
21
|
-
readonly rpcProvider: BundlerClient<TTransport> | BundlerClient<HttpTransport>;
|
|
22
|
-
constructor(params_: BaseSmartAccountParams<TTransport, TSigner>);
|
|
23
|
-
abstract getDummySignature(): Hex | Promise<Hex>;
|
|
24
|
-
abstract encodeExecute(target: string, value: bigint, data: string): Promise<Hash>;
|
|
25
|
-
abstract signMessage(msg: string | Uint8Array): Promise<Hash>;
|
|
26
|
-
protected abstract getAccountInitCode(): Promise<Hash>;
|
|
27
|
-
signUserOperationHash(uoHash: Hash): Promise<Hash>;
|
|
28
|
-
signTypedData(_params: SignTypedDataParams): Promise<`0x${string}`>;
|
|
29
|
-
signMessageWith6492(msg: string | Uint8Array): Promise<`0x${string}`>;
|
|
30
|
-
signTypedDataWith6492(params: SignTypedDataParams): Promise<`0x${string}`>;
|
|
31
|
-
encodeBatchExecute(_txs: BatchUserOperationCallData): Promise<`0x${string}`>;
|
|
32
|
-
encodeUpgradeToAndCall: (_upgradeToImplAddress: Address, _upgradeToInitData: Hex) => Promise<Hex>;
|
|
33
|
-
getNonce(): Promise<bigint>;
|
|
34
|
-
getInitCode(): Promise<Hex>;
|
|
35
|
-
getAddress(): Promise<Address>;
|
|
36
|
-
extend: <R>(fn: (self: this) => R) => this & R;
|
|
37
|
-
getSigner(): TSigner;
|
|
38
|
-
getFactoryAddress(): Address;
|
|
39
|
-
getEntryPointAddress(): Address;
|
|
40
|
-
isAccountDeployed(): Promise<boolean>;
|
|
41
|
-
getDeploymentState(): Promise<DeploymentState>;
|
|
42
|
-
protected parseFactoryAddressFromAccountInitCode(): Promise<[
|
|
43
|
-
Address,
|
|
44
|
-
Hex
|
|
45
|
-
]>;
|
|
46
|
-
protected getImplementationAddress(): Promise<NullAddress | Address>;
|
|
47
|
-
private _getAccountInitCode;
|
|
48
|
-
private create6492Signature;
|
|
49
|
-
}
|
package/dist/cjs/account/base.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseSmartContractAccount = exports.DeploymentState = void 0;
|
|
4
|
-
const viem_1 = require("viem");
|
|
5
|
-
const EntryPointAbi_v6_js_1 = require("../abis/EntryPointAbi_v6.js");
|
|
6
|
-
const bundlerClient_js_1 = require("../client/bundlerClient.js");
|
|
7
|
-
const index_js_1 = require("../entrypoint/index.js");
|
|
8
|
-
const account_js_1 = require("../errors/account.js");
|
|
9
|
-
const client_js_1 = require("../errors/client.js");
|
|
10
|
-
const logger_js_1 = require("../logger.js");
|
|
11
|
-
const utils_js_1 = require("../signer/utils.js");
|
|
12
|
-
const schema_js_1 = require("./schema.js");
|
|
13
|
-
var DeploymentState;
|
|
14
|
-
(function (DeploymentState) {
|
|
15
|
-
DeploymentState["UNDEFINED"] = "0x0";
|
|
16
|
-
DeploymentState["NOT_DEPLOYED"] = "0x1";
|
|
17
|
-
DeploymentState["DEPLOYED"] = "0x2";
|
|
18
|
-
})(DeploymentState || (exports.DeploymentState = DeploymentState = {}));
|
|
19
|
-
class BaseSmartContractAccount {
|
|
20
|
-
constructor(params_) {
|
|
21
|
-
Object.defineProperty(this, "factoryAddress", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: void 0
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "deploymentState", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: DeploymentState.UNDEFINED
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "accountAddress", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: void 0
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(this, "accountInitCode", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(this, "signer", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value: void 0
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(this, "entryPoint", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
value: void 0
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(this, "entryPointAddress", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: void 0
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(this, "rpcProvider", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: void 0
|
|
68
|
-
});
|
|
69
|
-
Object.defineProperty(this, "encodeUpgradeToAndCall", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: true,
|
|
72
|
-
writable: true,
|
|
73
|
-
value: async (_upgradeToImplAddress, _upgradeToInitData) => {
|
|
74
|
-
throw new account_js_1.UpgradeToAndCallNotSupportedError("BaseAccount");
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
Object.defineProperty(this, "extend", {
|
|
78
|
-
enumerable: true,
|
|
79
|
-
configurable: true,
|
|
80
|
-
writable: true,
|
|
81
|
-
value: (fn) => {
|
|
82
|
-
const extended = fn(this);
|
|
83
|
-
for (const key in this) {
|
|
84
|
-
delete extended[key];
|
|
85
|
-
}
|
|
86
|
-
return Object.assign(this, extended);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
const params = (0, schema_js_1.createBaseSmartAccountParamsSchema)().parse(params_);
|
|
90
|
-
this.entryPointAddress =
|
|
91
|
-
params.entryPointAddress ?? (0, index_js_1.getEntryPoint)(params.chain).address;
|
|
92
|
-
const rpcUrl = typeof params.rpcClient === "string"
|
|
93
|
-
? params.rpcClient
|
|
94
|
-
: params.rpcClient.transport.type === "http"
|
|
95
|
-
? params.rpcClient.transport.url || params.chain.rpcUrls.default.http[0]
|
|
96
|
-
: undefined;
|
|
97
|
-
const fetchOptions = typeof params.rpcClient === "string"
|
|
98
|
-
? undefined
|
|
99
|
-
: params.rpcClient.transport.type === "http"
|
|
100
|
-
? params.rpcClient.transport.fetchOptions
|
|
101
|
-
: undefined;
|
|
102
|
-
this.rpcProvider = rpcUrl
|
|
103
|
-
? (0, bundlerClient_js_1.createBundlerClient)({
|
|
104
|
-
chain: params.chain,
|
|
105
|
-
transport: (0, viem_1.http)(rpcUrl, {
|
|
106
|
-
fetchOptions: {
|
|
107
|
-
...fetchOptions,
|
|
108
|
-
headers: {
|
|
109
|
-
...fetchOptions?.headers,
|
|
110
|
-
...(rpcUrl.toLowerCase().indexOf("alchemy") > -1
|
|
111
|
-
? {
|
|
112
|
-
"Alchemy-Aa-Sdk-Signer": params.signer?.signerType || "unknown",
|
|
113
|
-
"Alchemy-Aa-Sdk-Factory-Address": params.factoryAddress,
|
|
114
|
-
}
|
|
115
|
-
: undefined),
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
}),
|
|
119
|
-
})
|
|
120
|
-
: params.rpcClient;
|
|
121
|
-
this.accountAddress = params.accountAddress;
|
|
122
|
-
this.factoryAddress = params.factoryAddress;
|
|
123
|
-
this.signer = params.signer;
|
|
124
|
-
this.accountInitCode = params.initCode;
|
|
125
|
-
this.entryPoint = (0, viem_1.getContract)({
|
|
126
|
-
address: this.entryPointAddress,
|
|
127
|
-
abi: EntryPointAbi_v6_js_1.EntryPointAbi_v6,
|
|
128
|
-
client: this.rpcProvider,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
async signUserOperationHash(uoHash) {
|
|
132
|
-
return this.signMessage(uoHash);
|
|
133
|
-
}
|
|
134
|
-
async signTypedData(_params) {
|
|
135
|
-
throw new Error("signTypedData not supported");
|
|
136
|
-
}
|
|
137
|
-
async signMessageWith6492(msg) {
|
|
138
|
-
const [isDeployed, signature] = await Promise.all([
|
|
139
|
-
this.isAccountDeployed(),
|
|
140
|
-
this.signMessage(msg),
|
|
141
|
-
]);
|
|
142
|
-
return this.create6492Signature(isDeployed, signature);
|
|
143
|
-
}
|
|
144
|
-
async signTypedDataWith6492(params) {
|
|
145
|
-
const [isDeployed, signature] = await Promise.all([
|
|
146
|
-
this.isAccountDeployed(),
|
|
147
|
-
this.signTypedData(params),
|
|
148
|
-
]);
|
|
149
|
-
return this.create6492Signature(isDeployed, signature);
|
|
150
|
-
}
|
|
151
|
-
async encodeBatchExecute(_txs) {
|
|
152
|
-
throw new account_js_1.BatchExecutionNotSupportedError("BaseAccount");
|
|
153
|
-
}
|
|
154
|
-
async getNonce() {
|
|
155
|
-
if (!(await this.isAccountDeployed())) {
|
|
156
|
-
return 0n;
|
|
157
|
-
}
|
|
158
|
-
const address = await this.getAddress();
|
|
159
|
-
return this.entryPoint.read.getNonce([address, BigInt(0)]);
|
|
160
|
-
}
|
|
161
|
-
async getInitCode() {
|
|
162
|
-
if (this.deploymentState === DeploymentState.DEPLOYED) {
|
|
163
|
-
return "0x";
|
|
164
|
-
}
|
|
165
|
-
const contractCode = await this.rpcProvider.getBytecode({
|
|
166
|
-
address: await this.getAddress(),
|
|
167
|
-
});
|
|
168
|
-
if ((contractCode?.length ?? 0) > 2) {
|
|
169
|
-
this.deploymentState = DeploymentState.DEPLOYED;
|
|
170
|
-
return "0x";
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
this.deploymentState = DeploymentState.NOT_DEPLOYED;
|
|
174
|
-
}
|
|
175
|
-
return this._getAccountInitCode();
|
|
176
|
-
}
|
|
177
|
-
async getAddress() {
|
|
178
|
-
if (!this.accountAddress) {
|
|
179
|
-
const initCode = await this._getAccountInitCode();
|
|
180
|
-
logger_js_1.Logger.verbose("[BaseSmartContractAccount](getAddress) initCode: ", initCode);
|
|
181
|
-
try {
|
|
182
|
-
await this.entryPoint.simulate.getSenderAddress([initCode]);
|
|
183
|
-
}
|
|
184
|
-
catch (err) {
|
|
185
|
-
logger_js_1.Logger.verbose("[BaseSmartContractAccount](getAddress) getSenderAddress err: ", err);
|
|
186
|
-
if (err.cause?.data?.errorName === "SenderAddressResult") {
|
|
187
|
-
this.accountAddress = err.cause.data.args[0];
|
|
188
|
-
logger_js_1.Logger.verbose("[BaseSmartContractAccount](getAddress) entryPoint.getSenderAddress result:", this.accountAddress);
|
|
189
|
-
return this.accountAddress;
|
|
190
|
-
}
|
|
191
|
-
if (err.details === "Invalid URL") {
|
|
192
|
-
throw new client_js_1.InvalidRpcUrlError();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
throw new account_js_1.GetCounterFactualAddressError();
|
|
196
|
-
}
|
|
197
|
-
return this.accountAddress;
|
|
198
|
-
}
|
|
199
|
-
getSigner() {
|
|
200
|
-
return this.signer;
|
|
201
|
-
}
|
|
202
|
-
getFactoryAddress() {
|
|
203
|
-
return this.factoryAddress;
|
|
204
|
-
}
|
|
205
|
-
getEntryPointAddress() {
|
|
206
|
-
return this.entryPointAddress;
|
|
207
|
-
}
|
|
208
|
-
async isAccountDeployed() {
|
|
209
|
-
return (await this.getDeploymentState()) === DeploymentState.DEPLOYED;
|
|
210
|
-
}
|
|
211
|
-
async getDeploymentState() {
|
|
212
|
-
if (this.deploymentState === DeploymentState.UNDEFINED) {
|
|
213
|
-
const initCode = await this.getInitCode();
|
|
214
|
-
return initCode === "0x"
|
|
215
|
-
? DeploymentState.DEPLOYED
|
|
216
|
-
: DeploymentState.NOT_DEPLOYED;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
return this.deploymentState;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
async parseFactoryAddressFromAccountInitCode() {
|
|
223
|
-
const initCode = await this._getAccountInitCode();
|
|
224
|
-
const factoryAddress = `0x${initCode.substring(2, 42)}`;
|
|
225
|
-
const factoryCalldata = `0x${initCode.substring(42)}`;
|
|
226
|
-
return [factoryAddress, factoryCalldata];
|
|
227
|
-
}
|
|
228
|
-
async getImplementationAddress() {
|
|
229
|
-
const accountAddress = await this.getAddress();
|
|
230
|
-
const storage = await this.rpcProvider.getStorageAt({
|
|
231
|
-
address: accountAddress,
|
|
232
|
-
slot: "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
|
|
233
|
-
});
|
|
234
|
-
if (storage == null) {
|
|
235
|
-
throw new account_js_1.FailedToGetStorageSlotError("0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc", "Proxy Implementation Address");
|
|
236
|
-
}
|
|
237
|
-
return (0, viem_1.trim)(storage);
|
|
238
|
-
}
|
|
239
|
-
async _getAccountInitCode() {
|
|
240
|
-
return this.accountInitCode ?? this.getAccountInitCode();
|
|
241
|
-
}
|
|
242
|
-
async create6492Signature(isDeployed, signature) {
|
|
243
|
-
if (isDeployed) {
|
|
244
|
-
return signature;
|
|
245
|
-
}
|
|
246
|
-
const [factoryAddress, factoryCalldata] = await this.parseFactoryAddressFromAccountInitCode();
|
|
247
|
-
logger_js_1.Logger.verbose(`[BaseSmartContractAccount](create6492Signature)\
|
|
248
|
-
factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`);
|
|
249
|
-
return (0, utils_js_1.wrapSignatureWith6492)({
|
|
250
|
-
factoryAddress,
|
|
251
|
-
factoryCalldata,
|
|
252
|
-
signature,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
exports.BaseSmartContractAccount = BaseSmartContractAccount;
|
|
257
|
-
//# sourceMappingURL=base.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/account/base.ts"],"names":[],"mappings":";;;AACA,+BAUc;AACd,qEAAgF;AAChF,iEAGoC;AACpC,qDAAuD;AACvD,qDAK8B;AAC9B,mDAAyD;AACzD,4CAAsC;AAEtC,iDAA2D;AAE3D,2CAAiE;AAOjE,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IAC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;QAC3D,OAAO,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IAC3C,CAAC;IAES,KAAK,CAAC,wBAAwB;QACtC,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAE/C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC;YAClD,OAAO,EAAE,cAAc;YAEvB,IAAI,EAAE,oEAAoE;SAC3E,CAAC,CAAC;QAEH,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YACpB,MAAM,IAAI,wCAA2B,CACnC,oEAAoE,EACpE,8BAA8B,CAC/B,CAAC;QACJ,CAAC;QAED,OAAO,IAAA,WAAI,EAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IAEO,KAAK,CAAC,mBAAmB;QAC/B,OAAO,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC3D,CAAC;IAEO,KAAK,CAAC,mBAAmB,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,kBAAM,CAAC,OAAO,CACZ;0BACoB,cAAc,sBAAsB,eAAe,EAAE,CAC1E,CAAC;QAEF,OAAO,IAAA,gCAAqB,EAAC;YAC3B,cAAc;YACd,eAAe;YACf,SAAS;SACV,CAAC,CAAC;IACL,CAAC;CACF;AAjXD,4DAiXC","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"]}
|