@account-kit/infra 4.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/actions/simulateUserOperationChanges.d.ts +5 -0
- package/dist/cjs/actions/simulateUserOperationChanges.js +24 -0
- package/dist/cjs/actions/simulateUserOperationChanges.js.map +1 -0
- package/dist/cjs/actions/types.d.ts +39 -0
- package/dist/cjs/actions/types.js +17 -0
- package/dist/cjs/actions/types.js.map +1 -0
- package/dist/cjs/chains.d.ts +5 -0
- package/dist/cjs/chains.js +16 -0
- package/dist/cjs/chains.js.map +1 -0
- package/dist/cjs/client/decorators/alchemyEnhancedApis.d.ts +14 -0
- package/dist/cjs/client/decorators/alchemyEnhancedApis.js +26 -0
- package/dist/cjs/client/decorators/alchemyEnhancedApis.js.map +1 -0
- package/dist/cjs/client/decorators/smartAccount.d.ts +7 -0
- package/dist/cjs/client/decorators/smartAccount.js +9 -0
- package/dist/cjs/client/decorators/smartAccount.js.map +1 -0
- package/dist/cjs/client/internal/smartAccountClientFromRpc.d.ts +11 -0
- package/dist/cjs/client/internal/smartAccountClientFromRpc.js +55 -0
- package/dist/cjs/client/internal/smartAccountClientFromRpc.js.map +1 -0
- package/dist/cjs/client/isAlchemySmartAccountClient.d.ts +5539 -0
- package/dist/cjs/client/isAlchemySmartAccountClient.js +9 -0
- package/dist/cjs/client/isAlchemySmartAccountClient.js.map +1 -0
- package/dist/cjs/client/rpcClient.d.ts +8 -0
- package/dist/cjs/client/rpcClient.js +36 -0
- package/dist/cjs/client/rpcClient.js.map +1 -0
- package/dist/cjs/client/smartAccountClient.d.ts +18 -0
- package/dist/cjs/client/smartAccountClient.js +32 -0
- package/dist/cjs/client/smartAccountClient.js.map +1 -0
- package/dist/cjs/client/types.d.ts +76 -0
- package/dist/cjs/client/types.js +3 -0
- package/dist/cjs/client/types.js.map +1 -0
- package/dist/cjs/defaults.d.ts +3 -0
- package/dist/cjs/defaults.js +23 -0
- package/dist/cjs/defaults.js.map +1 -0
- package/dist/cjs/errors/base.d.ts +4 -0
- package/dist/cjs/errors/base.js +18 -0
- package/dist/cjs/errors/base.js.map +1 -0
- package/dist/cjs/errors/rpcUrl.d.ts +10 -0
- package/dist/cjs/errors/rpcUrl.js +26 -0
- package/dist/cjs/errors/rpcUrl.js.map +1 -0
- package/dist/cjs/gas-manager.d.ts +6 -0
- package/dist/cjs/gas-manager.js +35 -0
- package/dist/cjs/gas-manager.js.map +1 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/middleware/feeEstimator.d.ts +3 -0
- package/dist/cjs/middleware/feeEstimator.js +26 -0
- package/dist/cjs/middleware/feeEstimator.js.map +1 -0
- package/dist/cjs/middleware/gasManager.d.ts +29 -0
- package/dist/cjs/middleware/gasManager.js +148 -0
- package/dist/cjs/middleware/gasManager.js.map +1 -0
- package/dist/cjs/middleware/userOperationSimulator.d.ts +3 -0
- package/dist/cjs/middleware/userOperationSimulator.js +21 -0
- package/dist/cjs/middleware/userOperationSimulator.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/schema.d.ts +396 -0
- package/dist/cjs/schema.js +26 -0
- package/dist/cjs/schema.js.map +1 -0
- package/dist/cjs/type.d.ts +3 -0
- package/dist/cjs/type.js +3 -0
- package/dist/cjs/type.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/actions/simulateUserOperationChanges.d.ts +5 -0
- package/dist/esm/actions/simulateUserOperationChanges.js +20 -0
- package/dist/esm/actions/simulateUserOperationChanges.js.map +1 -0
- package/dist/esm/actions/types.d.ts +39 -0
- package/dist/esm/actions/types.js +14 -0
- package/dist/esm/actions/types.js.map +1 -0
- package/dist/esm/chains.d.ts +5 -0
- package/dist/esm/chains.js +12 -0
- package/dist/esm/chains.js.map +1 -0
- package/dist/esm/client/decorators/alchemyEnhancedApis.d.ts +14 -0
- package/dist/esm/client/decorators/alchemyEnhancedApis.js +22 -0
- package/dist/esm/client/decorators/alchemyEnhancedApis.js.map +1 -0
- package/dist/esm/client/decorators/smartAccount.d.ts +7 -0
- package/dist/esm/client/decorators/smartAccount.js +5 -0
- package/dist/esm/client/decorators/smartAccount.js.map +1 -0
- package/dist/esm/client/internal/smartAccountClientFromRpc.d.ts +11 -0
- package/dist/esm/client/internal/smartAccountClientFromRpc.js +50 -0
- package/dist/esm/client/internal/smartAccountClientFromRpc.js.map +1 -0
- package/dist/esm/client/isAlchemySmartAccountClient.d.ts +5539 -0
- package/dist/esm/client/isAlchemySmartAccountClient.js +5 -0
- package/dist/esm/client/isAlchemySmartAccountClient.js.map +1 -0
- package/dist/esm/client/rpcClient.d.ts +8 -0
- package/dist/esm/client/rpcClient.js +32 -0
- package/dist/esm/client/rpcClient.js.map +1 -0
- package/dist/esm/client/smartAccountClient.d.ts +18 -0
- package/dist/esm/client/smartAccountClient.js +31 -0
- package/dist/esm/client/smartAccountClient.js.map +1 -0
- package/dist/esm/client/types.d.ts +76 -0
- package/dist/esm/client/types.js +2 -0
- package/dist/esm/client/types.js.map +1 -0
- package/dist/esm/defaults.d.ts +3 -0
- package/dist/esm/defaults.js +19 -0
- package/dist/esm/defaults.js.map +1 -0
- package/dist/esm/errors/base.d.ts +4 -0
- package/dist/esm/errors/base.js +14 -0
- package/dist/esm/errors/base.js.map +1 -0
- package/dist/esm/errors/rpcUrl.d.ts +10 -0
- package/dist/esm/errors/rpcUrl.js +24 -0
- package/dist/esm/errors/rpcUrl.js.map +1 -0
- package/dist/esm/gas-manager.d.ts +6 -0
- package/dist/esm/gas-manager.js +31 -0
- package/dist/esm/gas-manager.js.map +1 -0
- package/dist/esm/index.d.ts +24 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/middleware/feeEstimator.d.ts +3 -0
- package/dist/esm/middleware/feeEstimator.js +22 -0
- package/dist/esm/middleware/feeEstimator.js.map +1 -0
- package/dist/esm/middleware/gasManager.d.ts +29 -0
- package/dist/esm/middleware/gasManager.js +144 -0
- package/dist/esm/middleware/gasManager.js.map +1 -0
- package/dist/esm/middleware/userOperationSimulator.d.ts +3 -0
- package/dist/esm/middleware/userOperationSimulator.js +17 -0
- package/dist/esm/middleware/userOperationSimulator.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/schema.d.ts +396 -0
- package/dist/esm/schema.js +20 -0
- package/dist/esm/schema.js.map +1 -0
- package/dist/esm/type.d.ts +3 -0
- package/dist/esm/type.js +2 -0
- package/dist/esm/type.js.map +1 -0
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/types/actions/simulateUserOperationChanges.d.ts +6 -0
- package/dist/types/actions/simulateUserOperationChanges.d.ts.map +1 -0
- package/dist/types/actions/types.d.ts +44 -0
- package/dist/types/actions/types.d.ts.map +1 -0
- package/dist/types/chains.d.ts +6 -0
- package/dist/types/chains.d.ts.map +1 -0
- package/dist/types/client/decorators/alchemyEnhancedApis.d.ts +15 -0
- package/dist/types/client/decorators/alchemyEnhancedApis.d.ts.map +1 -0
- package/dist/types/client/decorators/smartAccount.d.ts +8 -0
- package/dist/types/client/decorators/smartAccount.d.ts.map +1 -0
- package/dist/types/client/internal/smartAccountClientFromRpc.d.ts +19 -0
- package/dist/types/client/internal/smartAccountClientFromRpc.d.ts.map +1 -0
- package/dist/types/client/isAlchemySmartAccountClient.d.ts +5540 -0
- package/dist/types/client/isAlchemySmartAccountClient.d.ts.map +1 -0
- package/dist/types/client/rpcClient.d.ts +9 -0
- package/dist/types/client/rpcClient.d.ts.map +1 -0
- package/dist/types/client/smartAccountClient.d.ts +19 -0
- package/dist/types/client/smartAccountClient.d.ts.map +1 -0
- package/dist/types/client/types.d.ts +77 -0
- package/dist/types/client/types.d.ts.map +1 -0
- package/dist/types/defaults.d.ts +4 -0
- package/dist/types/defaults.d.ts.map +1 -0
- package/dist/types/errors/base.d.ts +5 -0
- package/dist/types/errors/base.d.ts.map +1 -0
- package/dist/types/errors/rpcUrl.d.ts +11 -0
- package/dist/types/errors/rpcUrl.d.ts.map +1 -0
- package/dist/types/gas-manager.d.ts +7 -0
- package/dist/types/gas-manager.d.ts.map +1 -0
- package/dist/types/index.d.ts +25 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/middleware/feeEstimator.d.ts +4 -0
- package/dist/types/middleware/feeEstimator.d.ts.map +1 -0
- package/dist/types/middleware/gasManager.d.ts +94 -0
- package/dist/types/middleware/gasManager.d.ts.map +1 -0
- package/dist/types/middleware/userOperationSimulator.d.ts +4 -0
- package/dist/types/middleware/userOperationSimulator.d.ts.map +1 -0
- package/dist/types/schema.d.ts +397 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/type.d.ts +4 -0
- package/dist/types/type.d.ts.map +1 -0
- package/dist/types/version.d.ts +2 -0
- package/dist/types/version.d.ts.map +1 -0
- package/package.json +75 -0
- package/src/actions/simulateUserOperationChanges.ts +49 -0
- package/src/actions/types.ts +49 -0
- package/src/chains.ts +19 -0
- package/src/client/decorators/alchemyEnhancedApis.ts +54 -0
- package/src/client/decorators/smartAccount.ts +37 -0
- package/src/client/internal/smartAccountClientFromRpc.ts +121 -0
- package/src/client/isAlchemySmartAccountClient.ts +19 -0
- package/src/client/rpcClient.ts +50 -0
- package/src/client/smartAccountClient.ts +153 -0
- package/src/client/types.ts +89 -0
- package/src/defaults.ts +34 -0
- package/src/errors/base.ts +7 -0
- package/src/errors/rpcUrl.ts +20 -0
- package/src/gas-manager.ts +53 -0
- package/src/index.ts +24 -0
- package/src/middleware/feeEstimator.ts +40 -0
- package/src/middleware/gasManager.ts +432 -0
- package/src/middleware/userOperationSimulator.ts +26 -0
- package/src/schema.ts +33 -0
- package/src/type.ts +4 -0
- package/src/version.ts +3 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Address,
|
|
3
|
+
ClientMiddlewareConfig,
|
|
4
|
+
ClientMiddlewareFn,
|
|
5
|
+
EntryPointVersion,
|
|
6
|
+
Multiplier,
|
|
7
|
+
UserOperationFeeOptions,
|
|
8
|
+
UserOperationOverrides,
|
|
9
|
+
UserOperationRequest,
|
|
10
|
+
} from "@aa-sdk/core";
|
|
11
|
+
import {
|
|
12
|
+
bypassPaymasterAndDataEmptyHex,
|
|
13
|
+
deepHexlify,
|
|
14
|
+
defaultGasEstimator,
|
|
15
|
+
filterUndefined,
|
|
16
|
+
isBigNumberish,
|
|
17
|
+
isMultiplier,
|
|
18
|
+
resolveProperties,
|
|
19
|
+
} from "@aa-sdk/core";
|
|
20
|
+
import { concat, fromHex, isHex, type Hex } from "viem";
|
|
21
|
+
import type { ClientWithAlchemyMethods } from "../client/types";
|
|
22
|
+
import { getAlchemyPaymasterAddress } from "../gas-manager.js";
|
|
23
|
+
import { alchemyFeeEstimator } from "./feeEstimator.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* overrides value for [`alchemy_requestGasAndPaymasterData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)
|
|
27
|
+
*
|
|
28
|
+
* @template {EntryPointVersion} TEntryPointVersion entry point version type
|
|
29
|
+
*/
|
|
30
|
+
export type RequestGasAndPaymasterAndDataOverrides<
|
|
31
|
+
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
32
|
+
> = Partial<
|
|
33
|
+
{
|
|
34
|
+
maxFeePerGas:
|
|
35
|
+
| UserOperationRequest<TEntryPointVersion>["maxFeePerGas"]
|
|
36
|
+
| Multiplier;
|
|
37
|
+
maxPriorityFeePerGas:
|
|
38
|
+
| UserOperationRequest<TEntryPointVersion>["maxPriorityFeePerGas"]
|
|
39
|
+
| Multiplier;
|
|
40
|
+
callGasLimit:
|
|
41
|
+
| UserOperationRequest<TEntryPointVersion>["callGasLimit"]
|
|
42
|
+
| Multiplier;
|
|
43
|
+
verificationGasLimit:
|
|
44
|
+
| UserOperationRequest<TEntryPointVersion>["verificationGasLimit"]
|
|
45
|
+
| Multiplier;
|
|
46
|
+
preVerificationGas:
|
|
47
|
+
| UserOperationRequest<TEntryPointVersion>["preVerificationGas"]
|
|
48
|
+
| Multiplier;
|
|
49
|
+
} & TEntryPointVersion extends "0.7.0"
|
|
50
|
+
? {
|
|
51
|
+
paymasterVerificationGasLimit:
|
|
52
|
+
| UserOperationRequest<"0.7.0">["paymasterVerificationGasLimit"]
|
|
53
|
+
| Multiplier;
|
|
54
|
+
paymasterPostOpGasLimit:
|
|
55
|
+
| UserOperationRequest<"0.7.0">["paymasterPostOpGasLimit"]
|
|
56
|
+
| Multiplier;
|
|
57
|
+
}
|
|
58
|
+
: {}
|
|
59
|
+
>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* [`alchemy-requestpaymasteranddata`](https://docs.alchemy.com/reference/alchemy-requestpaymasteranddata)
|
|
63
|
+
* response type
|
|
64
|
+
*
|
|
65
|
+
* @template {EntryPointVersion} TEntryPointVersion entry point version type
|
|
66
|
+
*/
|
|
67
|
+
export type RequestPaymasterAndDataResponse<
|
|
68
|
+
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
69
|
+
> = TEntryPointVersion extends "0.6.0"
|
|
70
|
+
? {
|
|
71
|
+
paymasterAndData: UserOperationRequest<"0.6.0">["paymasterAndData"];
|
|
72
|
+
}
|
|
73
|
+
: TEntryPointVersion extends "0.7.0"
|
|
74
|
+
? Pick<UserOperationRequest<"0.7.0">, "paymaster" | "paymasterData">
|
|
75
|
+
: {};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* [`alchemy_requestGasAndPaymasterData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)
|
|
79
|
+
* response type
|
|
80
|
+
*
|
|
81
|
+
* @template {EntryPointVersion} TEntryPointVersion entry point version type
|
|
82
|
+
*/
|
|
83
|
+
export type RequestGasAndPaymasterAndDataResponse<
|
|
84
|
+
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
85
|
+
> = Pick<
|
|
86
|
+
UserOperationRequest,
|
|
87
|
+
| "callGasLimit"
|
|
88
|
+
| "preVerificationGas"
|
|
89
|
+
| "verificationGasLimit"
|
|
90
|
+
| "maxFeePerGas"
|
|
91
|
+
| "maxPriorityFeePerGas"
|
|
92
|
+
> &
|
|
93
|
+
RequestPaymasterAndDataResponse<TEntryPointVersion>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Alchemy gas manager configuration with gas policy id and optional gas estimation options
|
|
97
|
+
*
|
|
98
|
+
* To create a Gas Manager Policy, go to the [gas manager](https://dashboard.alchemy.com/gas-manager?a=embedded-accounts-get-started)
|
|
99
|
+
* page of the Alchemy dashboard and click the “Create new policy” button.
|
|
100
|
+
*/
|
|
101
|
+
export interface AlchemyGasManagerConfig {
|
|
102
|
+
/**
|
|
103
|
+
* the policy id of the gas manager you want to use.
|
|
104
|
+
*
|
|
105
|
+
*/
|
|
106
|
+
policyId: string;
|
|
107
|
+
/**
|
|
108
|
+
* optional option configurable for the gas estimation portion of the Alchemy gas manager
|
|
109
|
+
*
|
|
110
|
+
*/
|
|
111
|
+
gasEstimationOptions?: AlchemyGasEstimationOptions;
|
|
112
|
+
/**
|
|
113
|
+
* paymaster address to use for the gas estimation.
|
|
114
|
+
* If not provided, the default paymaster address for the chain will be used.
|
|
115
|
+
*
|
|
116
|
+
*/
|
|
117
|
+
paymasterAddress?: Address;
|
|
118
|
+
/**
|
|
119
|
+
* dummy paymaster data to use for the gas estimation.
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
dummyData?: Hex;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Alchemy gas manager configuration option configurable for the gas estimation portion of the Alchemy gas manager
|
|
127
|
+
*
|
|
128
|
+
*/
|
|
129
|
+
export interface AlchemyGasEstimationOptions {
|
|
130
|
+
/**
|
|
131
|
+
* disable gas estimation and fallback to the default gas estimation.
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
disableGasEstimation: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* optional fallback gas estimator to use when gas estimation is disabled.
|
|
137
|
+
*
|
|
138
|
+
*/
|
|
139
|
+
fallbackGasEstimator?: ClientMiddlewareFn;
|
|
140
|
+
/**
|
|
141
|
+
* optional fallback fee estimator to use when gas estimation is disabled.
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
fallbackFeeDataGetter?: ClientMiddlewareFn;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* dummy paymaster and data middleware for the alchemy gas manager
|
|
149
|
+
*
|
|
150
|
+
* @template {ClientWithAlchemyMethods} C
|
|
151
|
+
* @param client client with alchemy methods
|
|
152
|
+
* @param config alchemy gas manager configuration
|
|
153
|
+
* @returns the dummyPaymasterAndData middleware for Alchemy gas manager
|
|
154
|
+
*/
|
|
155
|
+
const dummyPaymasterAndData =
|
|
156
|
+
<C extends ClientWithAlchemyMethods>(
|
|
157
|
+
client: C,
|
|
158
|
+
config: AlchemyGasManagerConfig
|
|
159
|
+
) =>
|
|
160
|
+
() => {
|
|
161
|
+
const paymaster =
|
|
162
|
+
config.paymasterAddress ?? getAlchemyPaymasterAddress(client.chain);
|
|
163
|
+
const paymasterData =
|
|
164
|
+
config.dummyData ??
|
|
165
|
+
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
|
|
166
|
+
|
|
167
|
+
return concat([paymaster, paymasterData]); // or you can also return { paymaster, paymasterData }
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Alchemy gas manager middleware used as the paymaster middleware overrides param to the client middleware config
|
|
172
|
+
*
|
|
173
|
+
* @template {ClientWithAlchemyMethods} C
|
|
174
|
+
* @param client client with alchemy methods
|
|
175
|
+
* @param config alchemy gas manager configuration
|
|
176
|
+
* @returns the gas estimator, fee estimator, and paymasterAndData middleware for Alchemy gas manager
|
|
177
|
+
*/
|
|
178
|
+
export function alchemyGasManagerMiddleware<C extends ClientWithAlchemyMethods>(
|
|
179
|
+
client: C,
|
|
180
|
+
config: AlchemyGasManagerConfig
|
|
181
|
+
): Pick<
|
|
182
|
+
ClientMiddlewareConfig,
|
|
183
|
+
"paymasterAndData" | "feeEstimator" | "gasEstimator"
|
|
184
|
+
> {
|
|
185
|
+
const gasEstimationOptions = config.gasEstimationOptions;
|
|
186
|
+
const disableGasEstimation =
|
|
187
|
+
gasEstimationOptions?.disableGasEstimation ?? false;
|
|
188
|
+
const fallbackFeeDataGetter =
|
|
189
|
+
gasEstimationOptions?.fallbackFeeDataGetter ?? alchemyFeeEstimator(client);
|
|
190
|
+
const fallbackGasEstimator =
|
|
191
|
+
gasEstimationOptions?.fallbackGasEstimator ??
|
|
192
|
+
defaultGasEstimator<C>(client);
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
gasEstimator: disableGasEstimation
|
|
196
|
+
? fallbackGasEstimator
|
|
197
|
+
: async (struct, { overrides, account, feeOptions }) => {
|
|
198
|
+
// if user is bypassing paymaster to fallback to having the account to pay the gas (one-off override),
|
|
199
|
+
// we cannot delegate gas estimation to the bundler because paymaster middleware will not be called
|
|
200
|
+
if (bypassPaymasterAndDataEmptyHex(overrides)) {
|
|
201
|
+
return {
|
|
202
|
+
...struct,
|
|
203
|
+
...(await fallbackGasEstimator(struct, {
|
|
204
|
+
overrides,
|
|
205
|
+
account,
|
|
206
|
+
feeOptions,
|
|
207
|
+
client,
|
|
208
|
+
})),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// essentially noop, because the gas estimation will happen in the backend
|
|
213
|
+
return struct;
|
|
214
|
+
},
|
|
215
|
+
feeEstimator: disableGasEstimation
|
|
216
|
+
? fallbackFeeDataGetter
|
|
217
|
+
: async (struct, { overrides, account, feeOptions }) => {
|
|
218
|
+
let maxFeePerGas = await struct.maxFeePerGas;
|
|
219
|
+
let maxPriorityFeePerGas = await struct.maxPriorityFeePerGas;
|
|
220
|
+
|
|
221
|
+
// if user is bypassing paymaster to fallback to having the account to pay the gas (one-off override),
|
|
222
|
+
// we cannot delegate gas estimation to the bundler because paymaster middleware will not be called
|
|
223
|
+
if (bypassPaymasterAndDataEmptyHex(overrides)) {
|
|
224
|
+
const result = await fallbackFeeDataGetter(struct, {
|
|
225
|
+
overrides,
|
|
226
|
+
feeOptions,
|
|
227
|
+
account,
|
|
228
|
+
client,
|
|
229
|
+
});
|
|
230
|
+
maxFeePerGas = (await result.maxFeePerGas) ?? maxFeePerGas;
|
|
231
|
+
maxPriorityFeePerGas =
|
|
232
|
+
(await result.maxPriorityFeePerGas) ?? maxPriorityFeePerGas;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
...struct,
|
|
237
|
+
maxFeePerGas,
|
|
238
|
+
maxPriorityFeePerGas,
|
|
239
|
+
};
|
|
240
|
+
},
|
|
241
|
+
paymasterAndData: disableGasEstimation
|
|
242
|
+
? requestPaymasterAndData(client, config)
|
|
243
|
+
: requestGasAndPaymasterData(client, config),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Utility function to override a field in the user operation request with the overrides or fee options
|
|
249
|
+
*
|
|
250
|
+
* @template {EntryPointVersion} TEntryPointVersion
|
|
251
|
+
* @param field the field to override
|
|
252
|
+
* @param overrides the overrides object
|
|
253
|
+
* @param feeOptions the fee options object from the client
|
|
254
|
+
* @param userOperation the user operation request
|
|
255
|
+
* @returns the overridden field value
|
|
256
|
+
*/
|
|
257
|
+
const overrideField = <
|
|
258
|
+
TEntryPointVersion extends EntryPointVersion = EntryPointVersion
|
|
259
|
+
>(
|
|
260
|
+
field: keyof UserOperationFeeOptions<TEntryPointVersion>,
|
|
261
|
+
overrides: UserOperationOverrides<TEntryPointVersion> | undefined,
|
|
262
|
+
feeOptions: UserOperationFeeOptions<TEntryPointVersion> | undefined,
|
|
263
|
+
userOperation: UserOperationRequest<TEntryPointVersion>
|
|
264
|
+
): Hex | Multiplier | undefined => {
|
|
265
|
+
let _field = field as keyof UserOperationOverrides<TEntryPointVersion>;
|
|
266
|
+
|
|
267
|
+
if (overrides?.[_field] != null) {
|
|
268
|
+
// one-off absolute override
|
|
269
|
+
if (isBigNumberish(overrides[_field])) {
|
|
270
|
+
return deepHexlify(overrides[_field]);
|
|
271
|
+
}
|
|
272
|
+
// one-off multiplier overrides
|
|
273
|
+
else {
|
|
274
|
+
return {
|
|
275
|
+
multiplier: Number((overrides[_field] as Multiplier).multiplier),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// provider level fee options with multiplier
|
|
281
|
+
if (isMultiplier(feeOptions?.[field])) {
|
|
282
|
+
return {
|
|
283
|
+
multiplier: Number((feeOptions![field] as Multiplier).multiplier),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const userOpField =
|
|
288
|
+
userOperation[field as keyof UserOperationRequest<TEntryPointVersion>];
|
|
289
|
+
if (isHex(userOpField) && fromHex(userOpField as Hex, "bigint") > 0n) {
|
|
290
|
+
return userOpField;
|
|
291
|
+
}
|
|
292
|
+
return undefined;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Alchemy gas manager middleware function that returns the paymaster middleware for the client middleware config
|
|
297
|
+
* that calls the [`alchemy_requestGasAndPaymasterAndData`](https://docs.alchemy.com/reference/alchemy-requestgasandpaymasteranddata)
|
|
298
|
+
*
|
|
299
|
+
* @template {ClientWithAlchemyMethods} C
|
|
300
|
+
* @param client client with alchemy methods
|
|
301
|
+
* @param config alchemy gas manager configuration
|
|
302
|
+
* @returns the paymasterAndData middleware for Alchemy gas manager
|
|
303
|
+
*/
|
|
304
|
+
function requestGasAndPaymasterData<C extends ClientWithAlchemyMethods>(
|
|
305
|
+
client: C,
|
|
306
|
+
config: AlchemyGasManagerConfig
|
|
307
|
+
): ClientMiddlewareConfig["paymasterAndData"] {
|
|
308
|
+
return {
|
|
309
|
+
dummyPaymasterAndData: dummyPaymasterAndData(client, config),
|
|
310
|
+
|
|
311
|
+
paymasterAndData: async (
|
|
312
|
+
struct,
|
|
313
|
+
{ overrides: overrides_, feeOptions, account }
|
|
314
|
+
) => {
|
|
315
|
+
const userOperation: UserOperationRequest = deepHexlify(
|
|
316
|
+
await resolveProperties(struct)
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
const overrides: RequestGasAndPaymasterAndDataOverrides = filterUndefined(
|
|
320
|
+
{
|
|
321
|
+
maxFeePerGas: overrideField(
|
|
322
|
+
"maxFeePerGas",
|
|
323
|
+
overrides_ as UserOperationOverrides,
|
|
324
|
+
feeOptions,
|
|
325
|
+
userOperation
|
|
326
|
+
),
|
|
327
|
+
maxPriorityFeePerGas: overrideField(
|
|
328
|
+
"maxPriorityFeePerGas",
|
|
329
|
+
overrides_ as UserOperationOverrides,
|
|
330
|
+
feeOptions,
|
|
331
|
+
userOperation
|
|
332
|
+
),
|
|
333
|
+
callGasLimit: overrideField(
|
|
334
|
+
"callGasLimit",
|
|
335
|
+
overrides_ as UserOperationOverrides,
|
|
336
|
+
feeOptions,
|
|
337
|
+
userOperation
|
|
338
|
+
),
|
|
339
|
+
verificationGasLimit: overrideField(
|
|
340
|
+
"verificationGasLimit",
|
|
341
|
+
overrides_ as UserOperationOverrides,
|
|
342
|
+
feeOptions,
|
|
343
|
+
userOperation
|
|
344
|
+
),
|
|
345
|
+
preVerificationGas: overrideField(
|
|
346
|
+
"preVerificationGas",
|
|
347
|
+
overrides_ as UserOperationOverrides,
|
|
348
|
+
feeOptions,
|
|
349
|
+
userOperation
|
|
350
|
+
),
|
|
351
|
+
}
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
if (account.getEntryPoint().version === "0.7.0") {
|
|
355
|
+
const paymasterVerificationGasLimit = overrideField<"0.7.0">(
|
|
356
|
+
"paymasterVerificationGasLimit",
|
|
357
|
+
overrides_ as UserOperationOverrides<"0.7.0">,
|
|
358
|
+
feeOptions,
|
|
359
|
+
userOperation
|
|
360
|
+
);
|
|
361
|
+
if (paymasterVerificationGasLimit != null) {
|
|
362
|
+
(
|
|
363
|
+
overrides as RequestGasAndPaymasterAndDataOverrides<"0.7.0">
|
|
364
|
+
).paymasterVerificationGasLimit = paymasterVerificationGasLimit;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const paymasterPostOpGasLimit = overrideField<"0.7.0">(
|
|
368
|
+
"paymasterPostOpGasLimit",
|
|
369
|
+
overrides_ as UserOperationOverrides<"0.7.0">,
|
|
370
|
+
feeOptions,
|
|
371
|
+
userOperation
|
|
372
|
+
);
|
|
373
|
+
if (paymasterPostOpGasLimit != null) {
|
|
374
|
+
(
|
|
375
|
+
overrides as RequestGasAndPaymasterAndDataOverrides<"0.7.0">
|
|
376
|
+
).paymasterPostOpGasLimit = paymasterPostOpGasLimit;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const result = await client.request({
|
|
381
|
+
method: "alchemy_requestGasAndPaymasterAndData",
|
|
382
|
+
params: [
|
|
383
|
+
{
|
|
384
|
+
policyId: config.policyId,
|
|
385
|
+
entryPoint: account.getEntryPoint().address,
|
|
386
|
+
userOperation,
|
|
387
|
+
dummySignature: userOperation.signature,
|
|
388
|
+
overrides,
|
|
389
|
+
},
|
|
390
|
+
],
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
return {
|
|
394
|
+
...struct,
|
|
395
|
+
...result,
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Alchemy gas manager middleware function that returns the paymaster middleware for the client middleware config
|
|
403
|
+
* that calls the [`alchemy_requestPaymasterAndData`](https://docs.alchemy.com/reference/alchemy-requestpaymasteranddata)
|
|
404
|
+
* with gas estimation disabled.
|
|
405
|
+
*
|
|
406
|
+
* @param client client with alchemy methods
|
|
407
|
+
* @param config alchemy gas manager configuration
|
|
408
|
+
* @returns the paymasterAndData middleware for Alchemy gas manager with gas estimation disabled
|
|
409
|
+
*/
|
|
410
|
+
const requestPaymasterAndData: <C extends ClientWithAlchemyMethods>(
|
|
411
|
+
client: C,
|
|
412
|
+
config: AlchemyGasManagerConfig
|
|
413
|
+
) => ClientMiddlewareConfig["paymasterAndData"] = (client, config) => ({
|
|
414
|
+
dummyPaymasterAndData: dummyPaymasterAndData(client, config),
|
|
415
|
+
paymasterAndData: async (struct, { account }) => {
|
|
416
|
+
const result = await client.request({
|
|
417
|
+
method: "alchemy_requestPaymasterAndData",
|
|
418
|
+
params: [
|
|
419
|
+
{
|
|
420
|
+
policyId: config.policyId,
|
|
421
|
+
entryPoint: account.getEntryPoint().address,
|
|
422
|
+
userOperation: deepHexlify(await resolveProperties(struct)),
|
|
423
|
+
},
|
|
424
|
+
],
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
...struct,
|
|
429
|
+
...result,
|
|
430
|
+
};
|
|
431
|
+
},
|
|
432
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deepHexlify,
|
|
3
|
+
resolveProperties,
|
|
4
|
+
type ClientMiddlewareFn,
|
|
5
|
+
} from "@aa-sdk/core";
|
|
6
|
+
import type { ClientWithAlchemyMethods } from "../client/types";
|
|
7
|
+
|
|
8
|
+
export function alchemyUserOperationSimulator<
|
|
9
|
+
C extends ClientWithAlchemyMethods
|
|
10
|
+
>(client: C): ClientMiddlewareFn {
|
|
11
|
+
return async (struct, { account }) => {
|
|
12
|
+
const uoSimResult = await client.request({
|
|
13
|
+
method: "alchemy_simulateUserOperationAssetChanges",
|
|
14
|
+
params: [
|
|
15
|
+
deepHexlify(await resolveProperties(struct)),
|
|
16
|
+
account.getEntryPoint().address,
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (uoSimResult.error) {
|
|
21
|
+
throw new Error(uoSimResult.error.message);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return struct;
|
|
25
|
+
};
|
|
26
|
+
}
|
package/src/schema.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChainSchema,
|
|
3
|
+
ConnectionConfigSchema,
|
|
4
|
+
SmartAccountClientOptsSchema,
|
|
5
|
+
getChain,
|
|
6
|
+
} from "@aa-sdk/core";
|
|
7
|
+
import { Alchemy } from "alchemy-sdk";
|
|
8
|
+
import type { Chain } from "viem";
|
|
9
|
+
import z from "zod";
|
|
10
|
+
|
|
11
|
+
export const AlchemyChainSchema = z.custom<Chain>((chain) => {
|
|
12
|
+
const _chain = ChainSchema.parse(chain);
|
|
13
|
+
|
|
14
|
+
let chainObject;
|
|
15
|
+
try {
|
|
16
|
+
chainObject = getChain(_chain.id);
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return chainObject.rpcUrls.alchemy != null;
|
|
22
|
+
}, "chain must include an alchemy rpc url. See `createAlchemyChain` or use the `AlchemyChainMap` exported from `@aa-sdk/core`");
|
|
23
|
+
|
|
24
|
+
export const AlchemyProviderConfigSchema = ConnectionConfigSchema.and(
|
|
25
|
+
z.object({
|
|
26
|
+
chain: AlchemyChainSchema,
|
|
27
|
+
opts: SmartAccountClientOptsSchema.optional().default(
|
|
28
|
+
SmartAccountClientOptsSchema.parse({})
|
|
29
|
+
),
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export const AlchemySdkClientSchema = z.instanceof(Alchemy);
|
package/src/type.ts
ADDED
package/src/version.ts
ADDED