@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,37 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SendUserOperationParameters,
|
|
3
|
+
SmartContractAccount,
|
|
4
|
+
UserOperationContext,
|
|
5
|
+
} from "@aa-sdk/core";
|
|
6
|
+
import type { Chain, Client, Transport } from "viem";
|
|
7
|
+
import { simulateUserOperationChanges } from "../../actions/simulateUserOperationChanges.js";
|
|
8
|
+
import type { SimulateUserOperationAssetChangesResponse } from "../../actions/types.js";
|
|
9
|
+
|
|
10
|
+
export type AlchemySmartAccountClientActions<
|
|
11
|
+
TAccount extends SmartContractAccount | undefined =
|
|
12
|
+
| SmartContractAccount
|
|
13
|
+
| undefined,
|
|
14
|
+
TContext extends UserOperationContext | undefined =
|
|
15
|
+
| UserOperationContext
|
|
16
|
+
| undefined
|
|
17
|
+
> = {
|
|
18
|
+
simulateUserOperation: (
|
|
19
|
+
args: SendUserOperationParameters<TAccount, TContext>
|
|
20
|
+
) => Promise<SimulateUserOperationAssetChangesResponse>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const alchemyActions: <
|
|
24
|
+
TTransport extends Transport = Transport,
|
|
25
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
26
|
+
TAccount extends SmartContractAccount | undefined =
|
|
27
|
+
| SmartContractAccount
|
|
28
|
+
| undefined,
|
|
29
|
+
TContext extends UserOperationContext | undefined =
|
|
30
|
+
| UserOperationContext
|
|
31
|
+
| undefined
|
|
32
|
+
>(
|
|
33
|
+
client: Client<TTransport, TChain, TAccount>
|
|
34
|
+
) => AlchemySmartAccountClientActions<TAccount, TContext> = (client) => ({
|
|
35
|
+
simulateUserOperation: async (args) =>
|
|
36
|
+
simulateUserOperationChanges(client, args),
|
|
37
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSmartAccountClientFromExisting,
|
|
3
|
+
getDefaultUserOperationFeeOptions,
|
|
4
|
+
isSmartAccountWithSigner,
|
|
5
|
+
type SmartContractAccount,
|
|
6
|
+
type SmartContractAccountWithSigner,
|
|
7
|
+
type UserOperationContext,
|
|
8
|
+
} from "@aa-sdk/core";
|
|
9
|
+
import type { Chain, CustomTransport, Transport } from "viem";
|
|
10
|
+
import { alchemyFeeEstimator } from "../../middleware/feeEstimator.js";
|
|
11
|
+
import { alchemyGasManagerMiddleware } from "../../middleware/gasManager.js";
|
|
12
|
+
import { alchemyUserOperationSimulator } from "../../middleware/userOperationSimulator.js";
|
|
13
|
+
import { alchemyActions } from "../decorators/smartAccount.js";
|
|
14
|
+
import type {
|
|
15
|
+
AlchemySmartAccountClient,
|
|
16
|
+
AlchemySmartAccountClientConfig,
|
|
17
|
+
} from "../smartAccountClient.js";
|
|
18
|
+
import type { ClientWithAlchemyMethods } from "../types.js";
|
|
19
|
+
|
|
20
|
+
export type CreateAlchemySmartAccountClientFromRpcClient<
|
|
21
|
+
TAccount extends SmartContractAccount | undefined =
|
|
22
|
+
| SmartContractAccount
|
|
23
|
+
| undefined,
|
|
24
|
+
TContext extends UserOperationContext | undefined =
|
|
25
|
+
| UserOperationContext
|
|
26
|
+
| undefined
|
|
27
|
+
> = Omit<
|
|
28
|
+
AlchemySmartAccountClientConfig<Transport, Chain, TAccount, TContext>,
|
|
29
|
+
"rpcUrl" | "chain" | "apiKey" | "jwt"
|
|
30
|
+
> & { client: ClientWithAlchemyMethods };
|
|
31
|
+
|
|
32
|
+
export function getSignerTypeHeader<
|
|
33
|
+
TAccount extends SmartContractAccountWithSigner
|
|
34
|
+
>(account: TAccount) {
|
|
35
|
+
return { "Alchemy-Aa-Sdk-Signer": account.getSigner().signerType };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Helper method meant to be used internally to create an alchemy smart account client
|
|
40
|
+
* from an existing Alchemy Rpc Client
|
|
41
|
+
*
|
|
42
|
+
* @param args configuration for the client
|
|
43
|
+
* @returns a smart account client configured to use Alchemy's RPC
|
|
44
|
+
*/
|
|
45
|
+
export function createAlchemySmartAccountClientFromRpcClient<
|
|
46
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
47
|
+
TAccount extends SmartContractAccount | undefined =
|
|
48
|
+
| SmartContractAccount
|
|
49
|
+
| undefined,
|
|
50
|
+
TContext extends UserOperationContext | undefined =
|
|
51
|
+
| UserOperationContext
|
|
52
|
+
| undefined
|
|
53
|
+
>(
|
|
54
|
+
args: CreateAlchemySmartAccountClientFromRpcClient<TAccount, TContext>
|
|
55
|
+
): AlchemySmartAccountClient<
|
|
56
|
+
CustomTransport,
|
|
57
|
+
TChain,
|
|
58
|
+
TAccount,
|
|
59
|
+
Record<string, never>,
|
|
60
|
+
TContext
|
|
61
|
+
>;
|
|
62
|
+
|
|
63
|
+
export function createAlchemySmartAccountClientFromRpcClient({
|
|
64
|
+
opts,
|
|
65
|
+
account,
|
|
66
|
+
useSimulation,
|
|
67
|
+
gasManagerConfig,
|
|
68
|
+
feeEstimator,
|
|
69
|
+
gasEstimator,
|
|
70
|
+
customMiddleware,
|
|
71
|
+
signUserOperation,
|
|
72
|
+
client,
|
|
73
|
+
}: CreateAlchemySmartAccountClientFromRpcClient): AlchemySmartAccountClient {
|
|
74
|
+
const feeOptions =
|
|
75
|
+
opts?.feeOptions ?? getDefaultUserOperationFeeOptions(client.chain);
|
|
76
|
+
|
|
77
|
+
const scaClient = createSmartAccountClientFromExisting({
|
|
78
|
+
account,
|
|
79
|
+
client,
|
|
80
|
+
type: "AlchemySmartAccountClient",
|
|
81
|
+
opts: {
|
|
82
|
+
...opts,
|
|
83
|
+
feeOptions,
|
|
84
|
+
},
|
|
85
|
+
customMiddleware: async (struct, args) => {
|
|
86
|
+
if (isSmartAccountWithSigner(args.account)) {
|
|
87
|
+
client.updateHeaders(getSignerTypeHeader(args.account));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return customMiddleware ? customMiddleware(struct, args) : struct;
|
|
91
|
+
},
|
|
92
|
+
feeEstimator: feeEstimator ?? alchemyFeeEstimator(client),
|
|
93
|
+
userOperationSimulator: useSimulation
|
|
94
|
+
? alchemyUserOperationSimulator(client)
|
|
95
|
+
: undefined,
|
|
96
|
+
gasEstimator,
|
|
97
|
+
...(gasManagerConfig &&
|
|
98
|
+
alchemyGasManagerMiddleware(client, {
|
|
99
|
+
...gasManagerConfig,
|
|
100
|
+
gasEstimationOptions: {
|
|
101
|
+
...gasManagerConfig.gasEstimationOptions,
|
|
102
|
+
disableGasEstimation:
|
|
103
|
+
gasManagerConfig.gasEstimationOptions?.disableGasEstimation ??
|
|
104
|
+
false,
|
|
105
|
+
fallbackFeeDataGetter:
|
|
106
|
+
gasManagerConfig.gasEstimationOptions?.fallbackFeeDataGetter ??
|
|
107
|
+
feeEstimator,
|
|
108
|
+
fallbackGasEstimator:
|
|
109
|
+
gasManagerConfig.gasEstimationOptions?.fallbackGasEstimator ??
|
|
110
|
+
gasEstimator,
|
|
111
|
+
},
|
|
112
|
+
})),
|
|
113
|
+
signUserOperation,
|
|
114
|
+
}).extend(alchemyActions);
|
|
115
|
+
|
|
116
|
+
if (account && isSmartAccountWithSigner(account)) {
|
|
117
|
+
client.updateHeaders(getSignerTypeHeader(account));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return scaClient;
|
|
121
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isSmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
+
import type { Chain, Client, Transport } from "viem";
|
|
3
|
+
import type { AlchemySmartAccountClient } from "./smartAccountClient";
|
|
4
|
+
|
|
5
|
+
export const isAlchemySmartAccountClient = <
|
|
6
|
+
TTransport extends Transport = Transport,
|
|
7
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
8
|
+
TAccount extends SmartContractAccount | undefined =
|
|
9
|
+
| SmartContractAccount
|
|
10
|
+
| undefined
|
|
11
|
+
>(
|
|
12
|
+
client: Client<TTransport, TChain, TAccount>
|
|
13
|
+
): client is AlchemySmartAccountClient<TTransport, TChain, TAccount> => {
|
|
14
|
+
// TODO: the goal of this check is to make sure that the client supports certain RPC methods
|
|
15
|
+
// we should probably do this by checking the client's transport and configured URL, since alchemy
|
|
16
|
+
// clients have to be RPC clients. this is difficult to do though because the transport might
|
|
17
|
+
// point to a proxy url :/
|
|
18
|
+
return isSmartAccountClient(client);
|
|
19
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBundlerClient,
|
|
3
|
+
type ConnectionConfig,
|
|
4
|
+
type NoUndefined,
|
|
5
|
+
} from "@aa-sdk/core";
|
|
6
|
+
import { http, type Chain, type HttpTransportConfig } from "viem";
|
|
7
|
+
import { AlchemyChainSchema } from "../schema.js";
|
|
8
|
+
import { VERSION } from "../version.js";
|
|
9
|
+
import type { ClientWithAlchemyMethods } from "./types.js";
|
|
10
|
+
|
|
11
|
+
export const createAlchemyPublicRpcClient = ({
|
|
12
|
+
chain: chain_,
|
|
13
|
+
connectionConfig,
|
|
14
|
+
fetchOptions = {},
|
|
15
|
+
}: {
|
|
16
|
+
connectionConfig: ConnectionConfig;
|
|
17
|
+
chain: Chain;
|
|
18
|
+
fetchOptions?: NoUndefined<HttpTransportConfig["fetchOptions"]>;
|
|
19
|
+
}): ClientWithAlchemyMethods => {
|
|
20
|
+
const chain = AlchemyChainSchema.parse(chain_);
|
|
21
|
+
|
|
22
|
+
const rpcUrl =
|
|
23
|
+
connectionConfig.rpcUrl == null
|
|
24
|
+
? `${chain.rpcUrls.alchemy.http[0]}/${connectionConfig.apiKey ?? ""}`
|
|
25
|
+
: connectionConfig.rpcUrl;
|
|
26
|
+
|
|
27
|
+
fetchOptions.headers = {
|
|
28
|
+
...fetchOptions.headers,
|
|
29
|
+
"Alchemy-AA-Sdk-Version": VERSION,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if (connectionConfig.jwt != null) {
|
|
33
|
+
fetchOptions.headers = {
|
|
34
|
+
...fetchOptions.headers,
|
|
35
|
+
Authorization: `Bearer ${connectionConfig.jwt}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return createBundlerClient({
|
|
40
|
+
chain: chain,
|
|
41
|
+
transport: http(rpcUrl, { fetchOptions }),
|
|
42
|
+
}).extend(() => ({
|
|
43
|
+
updateHeaders(newHeaders: HeadersInit) {
|
|
44
|
+
fetchOptions.headers = {
|
|
45
|
+
...fetchOptions.headers,
|
|
46
|
+
...newHeaders,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Prettify,
|
|
3
|
+
type SmartAccountClient,
|
|
4
|
+
type SmartAccountClientActions,
|
|
5
|
+
type SmartAccountClientConfig,
|
|
6
|
+
type SmartAccountClientRpcSchema,
|
|
7
|
+
type SmartContractAccount,
|
|
8
|
+
type UserOperationContext,
|
|
9
|
+
} from "@aa-sdk/core";
|
|
10
|
+
import { type Chain, type Transport } from "viem";
|
|
11
|
+
import { getDefaultUserOperationFeeOptions } from "../defaults.js";
|
|
12
|
+
import { type AlchemyGasManagerConfig } from "../middleware/gasManager.js";
|
|
13
|
+
import { AlchemyProviderConfigSchema } from "../schema.js";
|
|
14
|
+
import type { AlchemyProviderConfig } from "../type.js";
|
|
15
|
+
import type { AlchemySmartAccountClientActions } from "./decorators/smartAccount.js";
|
|
16
|
+
import { createAlchemySmartAccountClientFromRpcClient } from "./internal/smartAccountClientFromRpc.js";
|
|
17
|
+
import { createAlchemyPublicRpcClient } from "./rpcClient.js";
|
|
18
|
+
import type { AlchemyRpcSchema } from "./types.js";
|
|
19
|
+
|
|
20
|
+
// #region AlchemySmartAccountClientConfig
|
|
21
|
+
export type AlchemySmartAccountClientConfig<
|
|
22
|
+
transport extends Transport = Transport,
|
|
23
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
24
|
+
account extends SmartContractAccount | undefined =
|
|
25
|
+
| SmartContractAccount
|
|
26
|
+
| undefined,
|
|
27
|
+
context extends UserOperationContext | undefined =
|
|
28
|
+
| UserOperationContext
|
|
29
|
+
| undefined
|
|
30
|
+
> = {
|
|
31
|
+
account?: account;
|
|
32
|
+
useSimulation?: boolean;
|
|
33
|
+
gasManagerConfig?: AlchemyGasManagerConfig;
|
|
34
|
+
} & AlchemyProviderConfig &
|
|
35
|
+
Pick<
|
|
36
|
+
SmartAccountClientConfig<transport, chain, account, context>,
|
|
37
|
+
"customMiddleware" | "feeEstimator" | "gasEstimator" | "signUserOperation"
|
|
38
|
+
>;
|
|
39
|
+
// #endregion AlchemySmartAccountClientConfig
|
|
40
|
+
|
|
41
|
+
export type BaseAlchemyActions<
|
|
42
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
43
|
+
account extends SmartContractAccount | undefined =
|
|
44
|
+
| SmartContractAccount
|
|
45
|
+
| undefined,
|
|
46
|
+
context extends UserOperationContext | undefined =
|
|
47
|
+
| UserOperationContext
|
|
48
|
+
| undefined
|
|
49
|
+
> = SmartAccountClientActions<chain, account, context> &
|
|
50
|
+
AlchemySmartAccountClientActions<account, context>;
|
|
51
|
+
|
|
52
|
+
export type AlchemySmartAccountClient_Base<
|
|
53
|
+
transport extends Transport = Transport,
|
|
54
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
55
|
+
account extends SmartContractAccount | undefined =
|
|
56
|
+
| SmartContractAccount
|
|
57
|
+
| undefined,
|
|
58
|
+
actions extends Record<string, unknown> = Record<string, unknown>,
|
|
59
|
+
context extends UserOperationContext | undefined =
|
|
60
|
+
| UserOperationContext
|
|
61
|
+
| undefined
|
|
62
|
+
> = Prettify<
|
|
63
|
+
SmartAccountClient<
|
|
64
|
+
transport,
|
|
65
|
+
chain,
|
|
66
|
+
account,
|
|
67
|
+
actions & BaseAlchemyActions<chain, account, context>,
|
|
68
|
+
[...SmartAccountClientRpcSchema, ...AlchemyRpcSchema],
|
|
69
|
+
context
|
|
70
|
+
>
|
|
71
|
+
>;
|
|
72
|
+
|
|
73
|
+
export type AlchemySmartAccountClient<
|
|
74
|
+
transport extends Transport = Transport,
|
|
75
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
76
|
+
account extends SmartContractAccount | undefined =
|
|
77
|
+
| SmartContractAccount
|
|
78
|
+
| undefined,
|
|
79
|
+
actions extends Record<string, unknown> = Record<string, unknown>,
|
|
80
|
+
context extends UserOperationContext | undefined =
|
|
81
|
+
| UserOperationContext
|
|
82
|
+
| undefined
|
|
83
|
+
> = Prettify<
|
|
84
|
+
AlchemySmartAccountClient_Base<transport, chain, account, actions, context>
|
|
85
|
+
>;
|
|
86
|
+
|
|
87
|
+
export function createAlchemySmartAccountClient<
|
|
88
|
+
TTransport extends Transport = Transport,
|
|
89
|
+
TChain extends Chain = Chain,
|
|
90
|
+
TAccount extends SmartContractAccount | undefined =
|
|
91
|
+
| SmartContractAccount
|
|
92
|
+
| undefined,
|
|
93
|
+
TContext extends UserOperationContext | undefined =
|
|
94
|
+
| UserOperationContext
|
|
95
|
+
| undefined
|
|
96
|
+
>({
|
|
97
|
+
account,
|
|
98
|
+
gasManagerConfig,
|
|
99
|
+
useSimulation,
|
|
100
|
+
feeEstimator,
|
|
101
|
+
customMiddleware,
|
|
102
|
+
gasEstimator,
|
|
103
|
+
signUserOperation,
|
|
104
|
+
...config_
|
|
105
|
+
}: AlchemySmartAccountClientConfig<
|
|
106
|
+
TTransport,
|
|
107
|
+
TChain,
|
|
108
|
+
TAccount,
|
|
109
|
+
TContext
|
|
110
|
+
>): AlchemySmartAccountClient<
|
|
111
|
+
TTransport,
|
|
112
|
+
TChain,
|
|
113
|
+
TAccount,
|
|
114
|
+
Record<string, never>,
|
|
115
|
+
TContext
|
|
116
|
+
>;
|
|
117
|
+
|
|
118
|
+
export function createAlchemySmartAccountClient({
|
|
119
|
+
account,
|
|
120
|
+
gasManagerConfig,
|
|
121
|
+
useSimulation,
|
|
122
|
+
feeEstimator,
|
|
123
|
+
customMiddleware,
|
|
124
|
+
gasEstimator,
|
|
125
|
+
signUserOperation,
|
|
126
|
+
...config_
|
|
127
|
+
}: AlchemySmartAccountClientConfig): AlchemySmartAccountClient {
|
|
128
|
+
const config = AlchemyProviderConfigSchema.parse(config_);
|
|
129
|
+
const { chain, opts, ...connectionConfig } = config;
|
|
130
|
+
|
|
131
|
+
const client = createAlchemyPublicRpcClient({
|
|
132
|
+
chain,
|
|
133
|
+
connectionConfig,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const feeOptions =
|
|
137
|
+
opts?.feeOptions ?? getDefaultUserOperationFeeOptions(chain);
|
|
138
|
+
|
|
139
|
+
return createAlchemySmartAccountClientFromRpcClient({
|
|
140
|
+
client,
|
|
141
|
+
account,
|
|
142
|
+
opts: {
|
|
143
|
+
...opts,
|
|
144
|
+
feeOptions,
|
|
145
|
+
},
|
|
146
|
+
gasManagerConfig,
|
|
147
|
+
useSimulation,
|
|
148
|
+
feeEstimator,
|
|
149
|
+
customMiddleware,
|
|
150
|
+
gasEstimator,
|
|
151
|
+
signUserOperation,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type BundlerClient, type UserOperationRequest } from "@aa-sdk/core";
|
|
2
|
+
import type { Address, Hex, HttpTransport } from "viem";
|
|
3
|
+
import type {
|
|
4
|
+
SimulateUserOperationAssetChangesRequest,
|
|
5
|
+
SimulateUserOperationAssetChangesResponse,
|
|
6
|
+
} from "../actions/types";
|
|
7
|
+
import type {
|
|
8
|
+
RequestGasAndPaymasterAndDataOverrides,
|
|
9
|
+
RequestGasAndPaymasterAndDataResponse,
|
|
10
|
+
RequestPaymasterAndDataResponse,
|
|
11
|
+
} from "../middleware/gasManager";
|
|
12
|
+
|
|
13
|
+
export type AlchemyRpcSchema = [
|
|
14
|
+
{
|
|
15
|
+
Method: "alchemy_requestPaymasterAndData";
|
|
16
|
+
Parameters: [
|
|
17
|
+
{
|
|
18
|
+
policyId: string;
|
|
19
|
+
entryPoint: Address;
|
|
20
|
+
userOperation: UserOperationRequest;
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
ReturnType: RequestPaymasterAndDataResponse;
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
Method: "alchemy_requestGasAndPaymasterAndData";
|
|
27
|
+
Parameters: [
|
|
28
|
+
{
|
|
29
|
+
policyId: string;
|
|
30
|
+
entryPoint: Address;
|
|
31
|
+
userOperation: UserOperationRequest;
|
|
32
|
+
dummySignature: Hex;
|
|
33
|
+
overrides?: RequestGasAndPaymasterAndDataOverrides;
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
ReturnType: RequestGasAndPaymasterAndDataResponse;
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
Method: "alchemy_simulateUserOperationAssetChanges";
|
|
40
|
+
Parameters: SimulateUserOperationAssetChangesRequest;
|
|
41
|
+
ReturnType: SimulateUserOperationAssetChangesResponse;
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
Method: "rundler_maxPriorityFeePerGas";
|
|
45
|
+
Parameters: [];
|
|
46
|
+
ReturnType: UserOperationRequest["maxPriorityFeePerGas"];
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export type ClientWithAlchemyMethods = BundlerClient<HttpTransport> & {
|
|
51
|
+
request: BundlerClient<HttpTransport>["request"] &
|
|
52
|
+
{
|
|
53
|
+
request(args: {
|
|
54
|
+
method: "alchemy_requestPaymasterAndData";
|
|
55
|
+
params: [
|
|
56
|
+
{
|
|
57
|
+
policyId: string;
|
|
58
|
+
entryPoint: Address;
|
|
59
|
+
userOperation: UserOperationRequest;
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
}): Promise<RequestPaymasterAndDataResponse>;
|
|
63
|
+
|
|
64
|
+
request(args: {
|
|
65
|
+
method: "alchemy_requestGasAndPaymasterAndData";
|
|
66
|
+
params: [
|
|
67
|
+
{
|
|
68
|
+
policyId: string;
|
|
69
|
+
entryPoint: Address;
|
|
70
|
+
userOperation: UserOperationRequest;
|
|
71
|
+
dummySignature: Hex;
|
|
72
|
+
overrides?: RequestGasAndPaymasterAndDataOverrides;
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
}): Promise<RequestGasAndPaymasterAndDataResponse>;
|
|
76
|
+
|
|
77
|
+
request(args: {
|
|
78
|
+
method: "alchemy_simulateUserOperationAssetChanges";
|
|
79
|
+
params: SimulateUserOperationAssetChangesRequest;
|
|
80
|
+
}): Promise<SimulateUserOperationAssetChangesResponse>;
|
|
81
|
+
|
|
82
|
+
request(args: {
|
|
83
|
+
method: "rundler_maxPriorityFeePerGas";
|
|
84
|
+
params: [];
|
|
85
|
+
}): Promise<UserOperationRequest["maxPriorityFeePerGas"]>;
|
|
86
|
+
}["request"];
|
|
87
|
+
} & {
|
|
88
|
+
updateHeaders: (headers: HeadersInit) => void;
|
|
89
|
+
};
|
package/src/defaults.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
arbitrum,
|
|
3
|
+
arbitrumGoerli,
|
|
4
|
+
arbitrumSepolia,
|
|
5
|
+
optimism,
|
|
6
|
+
optimismGoerli,
|
|
7
|
+
optimismSepolia,
|
|
8
|
+
type UserOperationFeeOptions,
|
|
9
|
+
} from "@aa-sdk/core";
|
|
10
|
+
import type { Chain } from "viem";
|
|
11
|
+
|
|
12
|
+
export const getDefaultUserOperationFeeOptions = (
|
|
13
|
+
chain: Chain
|
|
14
|
+
): UserOperationFeeOptions => {
|
|
15
|
+
const feeOptions: UserOperationFeeOptions = {
|
|
16
|
+
maxFeePerGas: { multiplier: 1.5 },
|
|
17
|
+
maxPriorityFeePerGas: { multiplier: 1.05 },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
new Set<number>([
|
|
22
|
+
arbitrum.id,
|
|
23
|
+
arbitrumGoerli.id,
|
|
24
|
+
arbitrumSepolia.id,
|
|
25
|
+
optimism.id,
|
|
26
|
+
optimismGoerli.id,
|
|
27
|
+
optimismSepolia.id,
|
|
28
|
+
]).has(chain.id)
|
|
29
|
+
) {
|
|
30
|
+
feeOptions.preVerificationGas = { multiplier: 1.05 };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return feeOptions;
|
|
34
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseError as CoreBaseError } from "@aa-sdk/core";
|
|
2
|
+
import { VERSION } from "../version.js";
|
|
3
|
+
|
|
4
|
+
export abstract class BaseError extends CoreBaseError {
|
|
5
|
+
// This version could be different from the aa-core version so we overwrite this here.
|
|
6
|
+
override version = VERSION;
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ConnectionConfig } from "@aa-sdk/core";
|
|
2
|
+
import { type Chain } from "viem";
|
|
3
|
+
import { BaseError } from "./base.js";
|
|
4
|
+
|
|
5
|
+
export class InvalidRpcUrlError extends BaseError {
|
|
6
|
+
override name = "InvalidRpcUrlError";
|
|
7
|
+
|
|
8
|
+
constructor(context: { chain: Chain; connectionConfig: ConnectionConfig }) {
|
|
9
|
+
super(["RPC Url not provided"].join("\n"), {
|
|
10
|
+
details: [
|
|
11
|
+
"If you are passing in a chain object and only an API key, make sure to use the chain object exported from @aa-sdk/core",
|
|
12
|
+
"Otherwise, pass in an RPC URL directly",
|
|
13
|
+
].join("\n"),
|
|
14
|
+
metaMessages: [
|
|
15
|
+
`Chain: ${JSON.stringify(context.chain, null, 2)}`,
|
|
16
|
+
`ConnectionConfig: ${JSON.stringify(context.connectionConfig)}`,
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Address, Chain } from "viem";
|
|
2
|
+
import {
|
|
3
|
+
arbitrum,
|
|
4
|
+
arbitrumSepolia,
|
|
5
|
+
base,
|
|
6
|
+
baseSepolia,
|
|
7
|
+
mainnet,
|
|
8
|
+
sepolia,
|
|
9
|
+
optimism,
|
|
10
|
+
optimismSepolia,
|
|
11
|
+
polygon,
|
|
12
|
+
polygonAmoy,
|
|
13
|
+
polygonMumbai,
|
|
14
|
+
fraxtal,
|
|
15
|
+
fraxtalSepolia,
|
|
16
|
+
zora,
|
|
17
|
+
zoraSepolia,
|
|
18
|
+
} from "@aa-sdk/core";
|
|
19
|
+
|
|
20
|
+
export const AlchemyPaymasterAddressV3 =
|
|
21
|
+
"0x4f84a207A80c39E9e8BaE717c1F25bA7AD1fB08F";
|
|
22
|
+
export const AlchemyPaymasterAddressV2 =
|
|
23
|
+
"0x4Fd9098af9ddcB41DA48A1d78F91F1398965addc";
|
|
24
|
+
export const ArbSepoliaPaymasterAddress =
|
|
25
|
+
"0x0804Afe6EEFb73ce7F93CD0d5e7079a5a8068592";
|
|
26
|
+
export const AlchemyPaymasterAddressV1 =
|
|
27
|
+
"0xc03aac639bb21233e0139381970328db8bceeb67";
|
|
28
|
+
|
|
29
|
+
export const getAlchemyPaymasterAddress = (chain: Chain): Address => {
|
|
30
|
+
switch (chain.id) {
|
|
31
|
+
case polygonAmoy.id:
|
|
32
|
+
case optimismSepolia.id:
|
|
33
|
+
case baseSepolia.id:
|
|
34
|
+
case zora.id:
|
|
35
|
+
case zoraSepolia.id:
|
|
36
|
+
case fraxtal.id:
|
|
37
|
+
case fraxtalSepolia.id:
|
|
38
|
+
return AlchemyPaymasterAddressV3;
|
|
39
|
+
case mainnet.id:
|
|
40
|
+
case arbitrum.id:
|
|
41
|
+
case optimism.id:
|
|
42
|
+
case polygon.id:
|
|
43
|
+
case base.id:
|
|
44
|
+
return AlchemyPaymasterAddressV2;
|
|
45
|
+
case arbitrumSepolia.id:
|
|
46
|
+
return ArbSepoliaPaymasterAddress;
|
|
47
|
+
case sepolia.id:
|
|
48
|
+
case polygonMumbai.id:
|
|
49
|
+
return AlchemyPaymasterAddressV1;
|
|
50
|
+
default:
|
|
51
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
52
|
+
}
|
|
53
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type * from "./actions/simulateUserOperationChanges.js";
|
|
2
|
+
export { simulateUserOperationChanges } from "./actions/simulateUserOperationChanges.js";
|
|
3
|
+
export type * from "./actions/types.js";
|
|
4
|
+
export { defineAlchemyChain } from "./chains.js";
|
|
5
|
+
export type * from "./client/decorators/alchemyEnhancedApis.js";
|
|
6
|
+
export { alchemyEnhancedApiActions } from "./client/decorators/alchemyEnhancedApis.js";
|
|
7
|
+
export type * from "./client/decorators/smartAccount.js";
|
|
8
|
+
export { alchemyActions } from "./client/decorators/smartAccount.js";
|
|
9
|
+
export { createAlchemySmartAccountClientFromRpcClient as createAlchemySmartAccountClientFromExisting } from "./client/internal/smartAccountClientFromRpc.js";
|
|
10
|
+
export { isAlchemySmartAccountClient } from "./client/isAlchemySmartAccountClient.js";
|
|
11
|
+
export type * from "./client/rpcClient.js";
|
|
12
|
+
export { createAlchemyPublicRpcClient } from "./client/rpcClient.js";
|
|
13
|
+
export type * from "./client/smartAccountClient.js";
|
|
14
|
+
export { createAlchemySmartAccountClient } from "./client/smartAccountClient.js";
|
|
15
|
+
export type * from "./client/types.js";
|
|
16
|
+
export { getDefaultUserOperationFeeOptions } from "./defaults.js";
|
|
17
|
+
export { getAlchemyPaymasterAddress } from "./gas-manager.js";
|
|
18
|
+
export { alchemyFeeEstimator } from "./middleware/feeEstimator.js";
|
|
19
|
+
export type * from "./middleware/gasManager.js";
|
|
20
|
+
export { alchemyGasManagerMiddleware } from "./middleware/gasManager.js";
|
|
21
|
+
export { alchemyUserOperationSimulator } from "./middleware/userOperationSimulator.js";
|
|
22
|
+
export type * from "./schema.js";
|
|
23
|
+
export { AlchemyProviderConfigSchema } from "./schema.js";
|
|
24
|
+
export type { AlchemyProviderConfig } from "./type.js";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ClientMiddlewareFn } from "@aa-sdk/core";
|
|
2
|
+
import { applyUserOpOverrideOrFeeOption } from "@aa-sdk/core";
|
|
3
|
+
import type { ClientWithAlchemyMethods } from "../client/types";
|
|
4
|
+
|
|
5
|
+
export const alchemyFeeEstimator: <C extends ClientWithAlchemyMethods>(
|
|
6
|
+
client: C
|
|
7
|
+
) => ClientMiddlewareFn =
|
|
8
|
+
(client) =>
|
|
9
|
+
async (struct, { overrides, feeOptions }) => {
|
|
10
|
+
let [block, maxPriorityFeePerGasEstimate] = await Promise.all([
|
|
11
|
+
client.getBlock({ blockTag: "latest" }),
|
|
12
|
+
// it is a fair assumption that if someone is using this Alchemy Middleware, then they are using Alchemy RPC
|
|
13
|
+
client.request({
|
|
14
|
+
method: "rundler_maxPriorityFeePerGas",
|
|
15
|
+
params: [],
|
|
16
|
+
}),
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
const baseFeePerGas = block.baseFeePerGas;
|
|
20
|
+
if (baseFeePerGas == null) {
|
|
21
|
+
throw new Error("baseFeePerGas is null");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const maxPriorityFeePerGas = applyUserOpOverrideOrFeeOption(
|
|
25
|
+
maxPriorityFeePerGasEstimate,
|
|
26
|
+
overrides?.maxPriorityFeePerGas,
|
|
27
|
+
feeOptions?.maxPriorityFeePerGas
|
|
28
|
+
);
|
|
29
|
+
const maxFeePerGas = applyUserOpOverrideOrFeeOption(
|
|
30
|
+
baseFeePerGas + BigInt(maxPriorityFeePerGas),
|
|
31
|
+
overrides?.maxFeePerGas,
|
|
32
|
+
feeOptions?.maxFeePerGas
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
...struct,
|
|
37
|
+
maxPriorityFeePerGas,
|
|
38
|
+
maxFeePerGas,
|
|
39
|
+
};
|
|
40
|
+
};
|