@account-kit/infra 4.0.0-beta.0 → 4.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/alchemyTransport.d.ts +69 -0
- package/dist/esm/alchemyTransport.js +139 -0
- package/dist/esm/alchemyTransport.js.map +1 -0
- package/dist/esm/chains.d.ts +1 -0
- package/dist/esm/chains.js +17 -0
- package/dist/esm/chains.js.map +1 -1
- package/dist/esm/client/decorators/alchemyEnhancedApis.d.ts +2 -2
- package/dist/esm/client/decorators/alchemyEnhancedApis.js +3 -7
- package/dist/esm/client/decorators/alchemyEnhancedApis.js.map +1 -1
- package/dist/esm/client/decorators/smartAccount.d.ts +7 -4
- package/dist/esm/client/decorators/smartAccount.js +33 -0
- package/dist/esm/client/decorators/smartAccount.js.map +1 -1
- package/dist/esm/client/isAlchemySmartAccountClient.d.ts +1 -1
- package/dist/esm/client/isAlchemySmartAccountClient.js +2 -6
- package/dist/esm/client/isAlchemySmartAccountClient.js.map +1 -1
- package/dist/esm/client/rpcClient.d.ts +9 -10
- package/dist/esm/client/rpcClient.js +9 -33
- package/dist/esm/client/rpcClient.js.map +1 -1
- package/dist/esm/client/smartAccountClient.d.ts +12 -9
- package/dist/esm/client/smartAccountClient.js +34 -20
- package/dist/esm/client/smartAccountClient.js.map +1 -1
- package/dist/esm/client/types.d.ts +8 -7
- package/dist/esm/client/types.js.map +1 -1
- package/dist/esm/index.d.ts +3 -4
- package/dist/esm/index.js +2 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/metrics.d.ts +12 -0
- package/dist/esm/metrics.js +7 -0
- package/dist/esm/metrics.js.map +1 -0
- package/dist/esm/middleware/feeEstimator.d.ts +10 -6
- package/dist/esm/middleware/feeEstimator.js +11 -6
- package/dist/esm/middleware/feeEstimator.js.map +1 -1
- package/dist/esm/middleware/gasManager.d.ts +5 -6
- package/dist/esm/middleware/gasManager.js +5 -6
- package/dist/esm/middleware/gasManager.js.map +1 -1
- package/dist/esm/middleware/userOperationSimulator.d.ts +11 -7
- package/dist/esm/middleware/userOperationSimulator.js +12 -8
- package/dist/esm/middleware/userOperationSimulator.js.map +1 -1
- package/dist/esm/schema.d.ts +0 -391
- package/dist/esm/schema.js +1 -5
- package/dist/esm/schema.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/alchemyTransport.d.ts +70 -0
- package/dist/types/alchemyTransport.d.ts.map +1 -0
- package/dist/types/chains.d.ts +1 -0
- package/dist/types/chains.d.ts.map +1 -1
- package/dist/types/client/decorators/alchemyEnhancedApis.d.ts +2 -2
- package/dist/types/client/decorators/alchemyEnhancedApis.d.ts.map +1 -1
- package/dist/types/client/decorators/smartAccount.d.ts +7 -4
- package/dist/types/client/decorators/smartAccount.d.ts.map +1 -1
- package/dist/types/client/isAlchemySmartAccountClient.d.ts +1 -1
- package/dist/types/client/isAlchemySmartAccountClient.d.ts.map +1 -1
- package/dist/types/client/rpcClient.d.ts +9 -10
- package/dist/types/client/rpcClient.d.ts.map +1 -1
- package/dist/types/client/smartAccountClient.d.ts +12 -9
- package/dist/types/client/smartAccountClient.d.ts.map +1 -1
- package/dist/types/client/types.d.ts +8 -7
- package/dist/types/client/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/metrics.d.ts +13 -0
- package/dist/types/metrics.d.ts.map +1 -0
- package/dist/types/middleware/feeEstimator.d.ts +10 -6
- package/dist/types/middleware/feeEstimator.d.ts.map +1 -1
- package/dist/types/middleware/gasManager.d.ts +5 -6
- package/dist/types/middleware/gasManager.d.ts.map +1 -1
- package/dist/types/middleware/userOperationSimulator.d.ts +11 -7
- package/dist/types/middleware/userOperationSimulator.d.ts.map +1 -1
- package/dist/types/schema.d.ts +0 -391
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +6 -10
- package/src/alchemyTransport.ts +214 -0
- package/src/chains.ts +18 -0
- package/src/client/decorators/alchemyEnhancedApis.ts +9 -16
- package/src/client/decorators/smartAccount.ts +77 -7
- package/src/client/isAlchemySmartAccountClient.ts +4 -9
- package/src/client/rpcClient.ts +14 -47
- package/src/client/smartAccountClient.ts +64 -57
- package/src/client/types.ts +10 -7
- package/src/index.ts +8 -8
- package/src/metrics.ts +19 -0
- package/src/middleware/feeEstimator.ts +15 -10
- package/src/middleware/gasManager.ts +5 -6
- package/src/middleware/userOperationSimulator.ts +13 -10
- package/src/schema.ts +1 -14
- package/src/version.ts +1 -1
- package/dist/esm/client/internal/smartAccountClientFromRpc.d.ts +0 -18
- package/dist/esm/client/internal/smartAccountClientFromRpc.js +0 -56
- package/dist/esm/client/internal/smartAccountClientFromRpc.js.map +0 -1
- package/dist/esm/type.d.ts +0 -3
- package/dist/esm/type.js +0 -2
- package/dist/esm/type.js.map +0 -1
- package/dist/types/client/internal/smartAccountClientFromRpc.d.ts +0 -19
- package/dist/types/client/internal/smartAccountClientFromRpc.d.ts.map +0 -1
- package/dist/types/type.d.ts +0 -4
- package/dist/types/type.d.ts.map +0 -1
- package/src/client/internal/smartAccountClientFromRpc.ts +0 -125
- package/src/type.ts +0 -4
package/src/chains.ts
CHANGED
|
@@ -310,6 +310,24 @@ export const shape: Chain = defineChain({
|
|
|
310
310
|
},
|
|
311
311
|
});
|
|
312
312
|
|
|
313
|
+
export const beraChainBartio: Chain = defineChain({
|
|
314
|
+
id: 80084,
|
|
315
|
+
name: "BeraChain Bartio",
|
|
316
|
+
network: "BeraChain Bartio",
|
|
317
|
+
nativeCurrency: { name: "Bera", symbol: "BERA", decimals: 18 },
|
|
318
|
+
rpcUrls: {
|
|
319
|
+
default: {
|
|
320
|
+
http: ["https://berachain-bartio.g.alchemy.com/v2"],
|
|
321
|
+
},
|
|
322
|
+
public: {
|
|
323
|
+
http: ["https://berachain-bartio.g.alchemy.com/v2"],
|
|
324
|
+
},
|
|
325
|
+
alchemy: {
|
|
326
|
+
http: ["https://berachain-bartio.g.alchemy.com/v2"],
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
|
|
313
331
|
export const arbitrumNova: Chain = {
|
|
314
332
|
...vabn,
|
|
315
333
|
rpcUrls: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SmartContractAccount } from "@aa-sdk/core";
|
|
2
2
|
import type { Alchemy } from "alchemy-sdk";
|
|
3
|
-
import type { Chain
|
|
3
|
+
import type { Chain } from "viem";
|
|
4
4
|
import { AlchemySdkClientSchema } from "../../schema.js";
|
|
5
5
|
import type { AlchemySmartAccountClient } from "../smartAccountClient.js";
|
|
6
6
|
|
|
@@ -34,30 +34,23 @@ export type AlchemyEnhancedApis = {
|
|
|
34
34
|
export function alchemyEnhancedApiActions(
|
|
35
35
|
alchemy: Alchemy
|
|
36
36
|
): <
|
|
37
|
-
TTransport extends Transport = Transport,
|
|
38
37
|
TChain extends Chain | undefined = Chain | undefined,
|
|
39
38
|
TAccount extends SmartContractAccount | undefined =
|
|
40
39
|
| SmartContractAccount
|
|
41
40
|
| undefined
|
|
42
41
|
>(
|
|
43
|
-
client: AlchemySmartAccountClient<
|
|
42
|
+
client: AlchemySmartAccountClient<TChain, TAccount>
|
|
44
43
|
) => AlchemyEnhancedApis {
|
|
45
44
|
return (client) => {
|
|
46
45
|
const alchemySdk = AlchemySdkClientSchema.parse(alchemy);
|
|
47
46
|
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
client
|
|
54
|
-
|
|
55
|
-
alchemy.config.url !== url
|
|
56
|
-
) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
"Alchemy SDK client JSON-RPC URL must match AlchemyProvider JSON-RPC URL"
|
|
59
|
-
);
|
|
60
|
-
}
|
|
47
|
+
if (
|
|
48
|
+
alchemy.config.url &&
|
|
49
|
+
alchemy.config.url !== client.transport.alchemyRpcUrl
|
|
50
|
+
) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Alchemy SDK client JSON-RPC URL must match AlchemyProvider JSON-RPC URL"
|
|
53
|
+
);
|
|
61
54
|
}
|
|
62
55
|
|
|
63
56
|
return {
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
isSmartAccountWithSigner,
|
|
3
|
+
sendTransaction,
|
|
4
|
+
sendTransactions,
|
|
5
|
+
sendUserOperation,
|
|
6
|
+
type GetEntryPointFromAccount,
|
|
7
|
+
type SendTransactionsParameters,
|
|
8
|
+
type SendUserOperationParameters,
|
|
9
|
+
type SendUserOperationResult,
|
|
10
|
+
type SmartContractAccount,
|
|
11
|
+
type UserOperationContext,
|
|
12
|
+
type UserOperationOverrides,
|
|
5
13
|
} from "@aa-sdk/core";
|
|
6
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
Chain,
|
|
16
|
+
Client,
|
|
17
|
+
Hex,
|
|
18
|
+
SendTransactionParameters,
|
|
19
|
+
Transport,
|
|
20
|
+
} from "viem";
|
|
7
21
|
import { simulateUserOperationChanges } from "../../actions/simulateUserOperationChanges.js";
|
|
8
22
|
import type { SimulateUserOperationAssetChangesResponse } from "../../actions/types.js";
|
|
23
|
+
import { InfraLogger } from "../../metrics.js";
|
|
9
24
|
|
|
10
25
|
export type AlchemySmartAccountClientActions<
|
|
11
26
|
TAccount extends SmartContractAccount | undefined =
|
|
@@ -13,11 +28,28 @@ export type AlchemySmartAccountClientActions<
|
|
|
13
28
|
| undefined,
|
|
14
29
|
TContext extends UserOperationContext | undefined =
|
|
15
30
|
| UserOperationContext
|
|
16
|
-
| undefined
|
|
31
|
+
| undefined,
|
|
32
|
+
TChain extends Chain | undefined = Chain | undefined,
|
|
33
|
+
TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>
|
|
17
34
|
> = {
|
|
18
35
|
simulateUserOperation: (
|
|
19
36
|
args: SendUserOperationParameters<TAccount, TContext>
|
|
20
37
|
) => Promise<SimulateUserOperationAssetChangesResponse>;
|
|
38
|
+
sendUserOperation: (
|
|
39
|
+
args: SendUserOperationParameters<
|
|
40
|
+
TAccount,
|
|
41
|
+
TContext,
|
|
42
|
+
GetEntryPointFromAccount<TAccount>
|
|
43
|
+
>
|
|
44
|
+
) => Promise<SendUserOperationResult<TEntryPointVersion>>;
|
|
45
|
+
sendTransaction: <TChainOverride extends Chain | undefined = undefined>(
|
|
46
|
+
args: SendTransactionParameters<TChain, TAccount, TChainOverride>,
|
|
47
|
+
overrides?: UserOperationOverrides<TEntryPointVersion>,
|
|
48
|
+
context?: TContext
|
|
49
|
+
) => Promise<Hex>;
|
|
50
|
+
sendTransactions: (
|
|
51
|
+
args: SendTransactionsParameters<TAccount, TContext>
|
|
52
|
+
) => Promise<Hex>;
|
|
21
53
|
};
|
|
22
54
|
|
|
23
55
|
/**
|
|
@@ -46,7 +78,45 @@ export const alchemyActions: <
|
|
|
46
78
|
| undefined
|
|
47
79
|
>(
|
|
48
80
|
client: Client<TTransport, TChain, TAccount>
|
|
49
|
-
) => AlchemySmartAccountClientActions<TAccount, TContext> = (
|
|
81
|
+
) => AlchemySmartAccountClientActions<TAccount, TContext, TChain> = (
|
|
82
|
+
client
|
|
83
|
+
) => ({
|
|
50
84
|
simulateUserOperation: async (args) =>
|
|
51
85
|
simulateUserOperationChanges(client, args),
|
|
86
|
+
sendUserOperation: async (args) => {
|
|
87
|
+
const { account = client.account } = args;
|
|
88
|
+
|
|
89
|
+
const result = sendUserOperation(client, args);
|
|
90
|
+
logSendUoEvent(client.chain!.id, account!);
|
|
91
|
+
return result;
|
|
92
|
+
},
|
|
93
|
+
sendTransaction: async (args, overrides, context) => {
|
|
94
|
+
const { account = client.account } = args;
|
|
95
|
+
|
|
96
|
+
const result = await sendTransaction(client, args, overrides, context);
|
|
97
|
+
logSendUoEvent(client.chain!.id, account as SmartContractAccount);
|
|
98
|
+
return result;
|
|
99
|
+
},
|
|
100
|
+
async sendTransactions(args) {
|
|
101
|
+
const { account = client.account } = args;
|
|
102
|
+
|
|
103
|
+
const result = sendTransactions(client, args);
|
|
104
|
+
logSendUoEvent(client.chain!.id, account!);
|
|
105
|
+
return result;
|
|
106
|
+
},
|
|
52
107
|
});
|
|
108
|
+
|
|
109
|
+
function logSendUoEvent(chainId: number, account: SmartContractAccount) {
|
|
110
|
+
const signerType = isSmartAccountWithSigner(account)
|
|
111
|
+
? account.getSigner().signerType
|
|
112
|
+
: "unknown";
|
|
113
|
+
|
|
114
|
+
InfraLogger.trackEvent({
|
|
115
|
+
name: "client_send_uo",
|
|
116
|
+
data: {
|
|
117
|
+
chainId,
|
|
118
|
+
signerType: signerType,
|
|
119
|
+
entryPoint: account.getEntryPoint().address,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type SmartContractAccount } from "@aa-sdk/core";
|
|
2
2
|
import type { Chain, Client, Transport } from "viem";
|
|
3
3
|
import type { AlchemySmartAccountClient } from "./smartAccountClient";
|
|
4
4
|
|
|
@@ -18,17 +18,12 @@ import type { AlchemySmartAccountClient } from "./smartAccountClient";
|
|
|
18
18
|
* @returns {boolean} `true` if the client is an Alchemy Smart Account Client, otherwise `false`
|
|
19
19
|
*/
|
|
20
20
|
export function isAlchemySmartAccountClient<
|
|
21
|
-
TTransport extends Transport = Transport,
|
|
22
21
|
TChain extends Chain | undefined = Chain | undefined,
|
|
23
22
|
TAccount extends SmartContractAccount | undefined =
|
|
24
23
|
| SmartContractAccount
|
|
25
24
|
| undefined
|
|
26
25
|
>(
|
|
27
|
-
client: Client<
|
|
28
|
-
): client is AlchemySmartAccountClient<
|
|
29
|
-
|
|
30
|
-
// we should probably do this by checking the client's transport and configured URL, since alchemy
|
|
31
|
-
// clients have to be RPC clients. this is difficult to do though because the transport might
|
|
32
|
-
// point to a proxy url :/
|
|
33
|
-
return isSmartAccountClient(client);
|
|
26
|
+
client: Client<Transport, TChain, TAccount>
|
|
27
|
+
): client is AlchemySmartAccountClient<TChain, TAccount> {
|
|
28
|
+
return client.transport.type === "alchemy";
|
|
34
29
|
}
|
package/src/client/rpcClient.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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";
|
|
1
|
+
import { createBundlerClient } from "@aa-sdk/core";
|
|
2
|
+
import type { Chain } from "viem";
|
|
3
|
+
import type { AlchemyTransport } from "../alchemyTransport.js";
|
|
9
4
|
import type { ClientWithAlchemyMethods } from "./types.js";
|
|
10
5
|
|
|
11
6
|
/**
|
|
@@ -13,14 +8,14 @@ import type { ClientWithAlchemyMethods } from "./types.js";
|
|
|
13
8
|
*
|
|
14
9
|
* @example
|
|
15
10
|
* ```ts
|
|
16
|
-
* import { createAlchemyPublicRpcClient } from "@account-kit/infra";
|
|
11
|
+
* import { createAlchemyPublicRpcClient, alchemy } from "@account-kit/infra";
|
|
17
12
|
* import { sepolia } from "@account-kit/infra";
|
|
18
13
|
*
|
|
19
14
|
* const client = createAlchemyPublicRpcClient({
|
|
15
|
+
* transport: alchemy({
|
|
16
|
+
* apiKey: "ALCHEMY_API_KEY"
|
|
17
|
+
* }),
|
|
20
18
|
* chain: sepolia,
|
|
21
|
-
* connectionConfig: {
|
|
22
|
-
* apiKey: "your-api-key",
|
|
23
|
-
* }
|
|
24
19
|
* });
|
|
25
20
|
* ```
|
|
26
21
|
*
|
|
@@ -31,42 +26,14 @@ import type { ClientWithAlchemyMethods } from "./types.js";
|
|
|
31
26
|
* @returns {ClientWithAlchemyMethods} A client object tailored with Alchemy methods and capabilities to interact with the blockchain
|
|
32
27
|
*/
|
|
33
28
|
export const createAlchemyPublicRpcClient = ({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fetchOptions = {},
|
|
29
|
+
transport,
|
|
30
|
+
chain,
|
|
37
31
|
}: {
|
|
38
|
-
|
|
39
|
-
chain: Chain;
|
|
40
|
-
fetchOptions?: NoUndefined<HttpTransportConfig["fetchOptions"]>;
|
|
32
|
+
transport: AlchemyTransport;
|
|
33
|
+
chain: Chain | undefined;
|
|
41
34
|
}): ClientWithAlchemyMethods => {
|
|
42
|
-
const chain = AlchemyChainSchema.parse(chain_);
|
|
43
|
-
|
|
44
|
-
const rpcUrl =
|
|
45
|
-
connectionConfig.rpcUrl == null
|
|
46
|
-
? `${chain.rpcUrls.alchemy.http[0]}/${connectionConfig.apiKey ?? ""}`
|
|
47
|
-
: connectionConfig.rpcUrl;
|
|
48
|
-
|
|
49
|
-
fetchOptions.headers = {
|
|
50
|
-
...fetchOptions.headers,
|
|
51
|
-
"Alchemy-AA-Sdk-Version": VERSION,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
if (connectionConfig.jwt != null) {
|
|
55
|
-
fetchOptions.headers = {
|
|
56
|
-
...fetchOptions.headers,
|
|
57
|
-
Authorization: `Bearer ${connectionConfig.jwt}`,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
35
|
return createBundlerClient({
|
|
62
|
-
chain
|
|
63
|
-
transport
|
|
64
|
-
})
|
|
65
|
-
updateHeaders(newHeaders: HeadersInit) {
|
|
66
|
-
fetchOptions.headers = {
|
|
67
|
-
...fetchOptions.headers,
|
|
68
|
-
...newHeaders,
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
}));
|
|
36
|
+
chain,
|
|
37
|
+
transport,
|
|
38
|
+
});
|
|
72
39
|
};
|
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ChainNotFoundError,
|
|
3
|
+
createSmartAccountClient,
|
|
4
|
+
isSmartAccountWithSigner,
|
|
2
5
|
type Prettify,
|
|
3
6
|
type SmartAccountClient,
|
|
4
7
|
type SmartAccountClientActions,
|
|
5
8
|
type SmartAccountClientConfig,
|
|
6
9
|
type SmartAccountClientRpcSchema,
|
|
7
10
|
type SmartContractAccount,
|
|
11
|
+
type SmartContractAccountWithSigner,
|
|
8
12
|
type UserOperationContext,
|
|
9
13
|
} from "@aa-sdk/core";
|
|
10
|
-
import { type Chain
|
|
14
|
+
import { type Chain } from "viem";
|
|
15
|
+
import type { AlchemyTransport } from "../alchemyTransport.js";
|
|
11
16
|
import { getDefaultUserOperationFeeOptions } from "../defaults.js";
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
+
import { alchemyFeeEstimator } from "../middleware/feeEstimator.js";
|
|
18
|
+
import { alchemyGasManagerMiddleware } from "../middleware/gasManager.js";
|
|
19
|
+
import { alchemyUserOperationSimulator } from "../middleware/userOperationSimulator.js";
|
|
20
|
+
import {
|
|
21
|
+
alchemyActions,
|
|
22
|
+
type AlchemySmartAccountClientActions,
|
|
23
|
+
} from "./decorators/smartAccount.js";
|
|
17
24
|
import type { AlchemyRpcSchema } from "./types.js";
|
|
18
25
|
|
|
26
|
+
export function getSignerTypeHeader<
|
|
27
|
+
TAccount extends SmartContractAccountWithSigner
|
|
28
|
+
>(account: TAccount) {
|
|
29
|
+
return { "Alchemy-Aa-Sdk-Signer": account.getSigner().signerType };
|
|
30
|
+
}
|
|
31
|
+
|
|
19
32
|
// #region AlchemySmartAccountClientConfig
|
|
20
33
|
export type AlchemySmartAccountClientConfig<
|
|
21
|
-
transport extends Transport = Transport,
|
|
22
34
|
chain extends Chain | undefined = Chain | undefined,
|
|
23
35
|
account extends SmartContractAccount | undefined =
|
|
24
36
|
| SmartContractAccount
|
|
@@ -30,11 +42,16 @@ export type AlchemySmartAccountClientConfig<
|
|
|
30
42
|
account?: account;
|
|
31
43
|
useSimulation?: boolean;
|
|
32
44
|
policyId?: string;
|
|
33
|
-
} &
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
} & Pick<
|
|
46
|
+
SmartAccountClientConfig<AlchemyTransport, chain, account, context>,
|
|
47
|
+
| "customMiddleware"
|
|
48
|
+
| "feeEstimator"
|
|
49
|
+
| "gasEstimator"
|
|
50
|
+
| "signUserOperation"
|
|
51
|
+
| "transport"
|
|
52
|
+
| "chain"
|
|
53
|
+
| "opts"
|
|
54
|
+
>;
|
|
38
55
|
// #endregion AlchemySmartAccountClientConfig
|
|
39
56
|
|
|
40
57
|
export type BaseAlchemyActions<
|
|
@@ -49,7 +66,6 @@ export type BaseAlchemyActions<
|
|
|
49
66
|
AlchemySmartAccountClientActions<account, context>;
|
|
50
67
|
|
|
51
68
|
export type AlchemySmartAccountClient_Base<
|
|
52
|
-
transport extends Transport = Transport,
|
|
53
69
|
chain extends Chain | undefined = Chain | undefined,
|
|
54
70
|
account extends SmartContractAccount | undefined =
|
|
55
71
|
| SmartContractAccount
|
|
@@ -60,7 +76,7 @@ export type AlchemySmartAccountClient_Base<
|
|
|
60
76
|
| undefined
|
|
61
77
|
> = Prettify<
|
|
62
78
|
SmartAccountClient<
|
|
63
|
-
|
|
79
|
+
AlchemyTransport,
|
|
64
80
|
chain,
|
|
65
81
|
account,
|
|
66
82
|
actions & BaseAlchemyActions<chain, account, context>,
|
|
@@ -70,7 +86,6 @@ export type AlchemySmartAccountClient_Base<
|
|
|
70
86
|
>;
|
|
71
87
|
|
|
72
88
|
export type AlchemySmartAccountClient<
|
|
73
|
-
transport extends Transport = Transport,
|
|
74
89
|
chain extends Chain | undefined = Chain | undefined,
|
|
75
90
|
account extends SmartContractAccount | undefined =
|
|
76
91
|
| SmartContractAccount
|
|
@@ -79,12 +94,9 @@ export type AlchemySmartAccountClient<
|
|
|
79
94
|
context extends UserOperationContext | undefined =
|
|
80
95
|
| UserOperationContext
|
|
81
96
|
| undefined
|
|
82
|
-
> = Prettify<
|
|
83
|
-
AlchemySmartAccountClient_Base<transport, chain, account, actions, context>
|
|
84
|
-
>;
|
|
97
|
+
> = Prettify<AlchemySmartAccountClient_Base<chain, account, actions, context>>;
|
|
85
98
|
|
|
86
99
|
export function createAlchemySmartAccountClient<
|
|
87
|
-
TTransport extends Transport = Transport,
|
|
88
100
|
TChain extends Chain = Chain,
|
|
89
101
|
TAccount extends SmartContractAccount | undefined =
|
|
90
102
|
| SmartContractAccount
|
|
@@ -92,39 +104,21 @@ export function createAlchemySmartAccountClient<
|
|
|
92
104
|
TContext extends UserOperationContext | undefined =
|
|
93
105
|
| UserOperationContext
|
|
94
106
|
| undefined
|
|
95
|
-
>(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
useSimulation,
|
|
99
|
-
feeEstimator,
|
|
100
|
-
customMiddleware,
|
|
101
|
-
gasEstimator,
|
|
102
|
-
signUserOperation,
|
|
103
|
-
...config_
|
|
104
|
-
}: AlchemySmartAccountClientConfig<
|
|
105
|
-
TTransport,
|
|
106
|
-
TChain,
|
|
107
|
-
TAccount,
|
|
108
|
-
TContext
|
|
109
|
-
>): AlchemySmartAccountClient<
|
|
110
|
-
TTransport,
|
|
111
|
-
TChain,
|
|
112
|
-
TAccount,
|
|
113
|
-
Record<string, never>,
|
|
114
|
-
TContext
|
|
115
|
-
>;
|
|
107
|
+
>(
|
|
108
|
+
params: AlchemySmartAccountClientConfig<TChain, TAccount, TContext>
|
|
109
|
+
): AlchemySmartAccountClient<TChain, TAccount, Record<string, never>, TContext>;
|
|
116
110
|
|
|
117
111
|
/**
|
|
118
112
|
* Creates an Alchemy smart account client using the provided configuration options, including account details, gas manager configuration, and custom middleware.
|
|
119
113
|
*
|
|
120
114
|
* @example
|
|
121
115
|
* ```ts
|
|
122
|
-
* import { createAlchemySmartAccountClient } from "@account-kit/infra";
|
|
116
|
+
* import { createAlchemySmartAccountClient, alchemy } from "@account-kit/infra";
|
|
123
117
|
* import { sepolia } from "@account-kit/infra/chain";
|
|
124
118
|
*
|
|
125
119
|
* const client = createAlchemySmartAccountClient({
|
|
126
120
|
* chain: sepolia,
|
|
127
|
-
* apiKey: "your-api-key",
|
|
121
|
+
* transport: alchemy({ apiKey: "your-api-key" }),
|
|
128
122
|
* });
|
|
129
123
|
* ```
|
|
130
124
|
*
|
|
@@ -139,31 +133,44 @@ export function createAlchemySmartAccountClient({
|
|
|
139
133
|
customMiddleware,
|
|
140
134
|
gasEstimator,
|
|
141
135
|
signUserOperation,
|
|
142
|
-
|
|
136
|
+
transport,
|
|
137
|
+
chain,
|
|
138
|
+
opts,
|
|
143
139
|
}: AlchemySmartAccountClientConfig): AlchemySmartAccountClient {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const client = createAlchemyPublicRpcClient({
|
|
148
|
-
chain,
|
|
149
|
-
connectionConfig,
|
|
150
|
-
});
|
|
140
|
+
if (!chain) {
|
|
141
|
+
throw new ChainNotFoundError();
|
|
142
|
+
}
|
|
151
143
|
|
|
152
144
|
const feeOptions =
|
|
153
145
|
opts?.feeOptions ?? getDefaultUserOperationFeeOptions(chain);
|
|
154
146
|
|
|
155
|
-
|
|
156
|
-
client,
|
|
147
|
+
const scaClient = createSmartAccountClient({
|
|
157
148
|
account,
|
|
149
|
+
transport,
|
|
150
|
+
chain,
|
|
151
|
+
type: "AlchemySmartAccountClient",
|
|
158
152
|
opts: {
|
|
159
153
|
...opts,
|
|
160
154
|
feeOptions,
|
|
161
155
|
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
156
|
+
customMiddleware: async (struct, args) => {
|
|
157
|
+
if (isSmartAccountWithSigner(args.account)) {
|
|
158
|
+
transport.updateHeaders(getSignerTypeHeader(args.account));
|
|
159
|
+
}
|
|
160
|
+
return customMiddleware ? customMiddleware(struct, args) : struct;
|
|
161
|
+
},
|
|
162
|
+
feeEstimator: feeEstimator ?? alchemyFeeEstimator(transport),
|
|
163
|
+
userOperationSimulator: useSimulation
|
|
164
|
+
? alchemyUserOperationSimulator(transport)
|
|
165
|
+
: undefined,
|
|
166
166
|
gasEstimator,
|
|
167
|
+
...(policyId && alchemyGasManagerMiddleware(policyId)),
|
|
167
168
|
signUserOperation,
|
|
168
|
-
});
|
|
169
|
+
}).extend(alchemyActions);
|
|
170
|
+
|
|
171
|
+
if (account && isSmartAccountWithSigner(account)) {
|
|
172
|
+
transport.updateHeaders(getSignerTypeHeader(account));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return scaClient;
|
|
169
176
|
}
|
package/src/client/types.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type BundlerClient,
|
|
3
|
+
type Erc7677RpcSchema,
|
|
4
|
+
type UserOperationRequest,
|
|
5
|
+
} from "@aa-sdk/core";
|
|
3
6
|
import type {
|
|
4
7
|
SimulateUserOperationAssetChangesRequest,
|
|
5
8
|
SimulateUserOperationAssetChangesResponse,
|
|
6
9
|
} from "../actions/types";
|
|
10
|
+
import type { AlchemyTransport } from "../alchemyTransport";
|
|
7
11
|
|
|
8
12
|
export type AlchemyRpcSchema = [
|
|
9
13
|
{
|
|
@@ -15,11 +19,12 @@ export type AlchemyRpcSchema = [
|
|
|
15
19
|
Method: "rundler_maxPriorityFeePerGas";
|
|
16
20
|
Parameters: [];
|
|
17
21
|
ReturnType: UserOperationRequest["maxPriorityFeePerGas"];
|
|
18
|
-
}
|
|
22
|
+
},
|
|
23
|
+
...Erc7677RpcSchema<{ policyId: string }>
|
|
19
24
|
];
|
|
20
25
|
|
|
21
|
-
export type ClientWithAlchemyMethods = BundlerClient<
|
|
22
|
-
request: BundlerClient<
|
|
26
|
+
export type ClientWithAlchemyMethods = BundlerClient<AlchemyTransport> & {
|
|
27
|
+
request: BundlerClient<AlchemyTransport>["request"] &
|
|
23
28
|
{
|
|
24
29
|
request(args: {
|
|
25
30
|
method: "alchemy_simulateUserOperationAssetChanges";
|
|
@@ -31,6 +36,4 @@ export type ClientWithAlchemyMethods = BundlerClient<HttpTransport> & {
|
|
|
31
36
|
params: [];
|
|
32
37
|
}): Promise<UserOperationRequest["maxPriorityFeePerGas"]>;
|
|
33
38
|
}["request"];
|
|
34
|
-
} & {
|
|
35
|
-
updateHeaders: (headers: HeadersInit) => void;
|
|
36
39
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export type * from "./actions/simulateUserOperationChanges.js";
|
|
2
2
|
export { simulateUserOperationChanges } from "./actions/simulateUserOperationChanges.js";
|
|
3
3
|
export type * from "./actions/types.js";
|
|
4
|
+
export type * from "./alchemyTransport.js";
|
|
5
|
+
export { alchemy } from "./alchemyTransport.js";
|
|
4
6
|
export type * from "./chains.js";
|
|
5
7
|
export {
|
|
6
8
|
arbitrum,
|
|
7
9
|
arbitrumGoerli,
|
|
8
|
-
arbitrumSepolia,
|
|
9
10
|
arbitrumNova,
|
|
11
|
+
arbitrumSepolia,
|
|
10
12
|
base,
|
|
11
13
|
baseGoerli,
|
|
12
14
|
baseSepolia,
|
|
@@ -22,18 +24,18 @@ export {
|
|
|
22
24
|
polygonAmoy,
|
|
23
25
|
polygonMumbai,
|
|
24
26
|
sepolia,
|
|
25
|
-
zora,
|
|
26
|
-
zoraSepolia,
|
|
27
|
-
worldChain,
|
|
28
|
-
worldChainSepolia,
|
|
29
27
|
shape,
|
|
30
28
|
shapeSepolia,
|
|
29
|
+
worldChain,
|
|
30
|
+
worldChainSepolia,
|
|
31
|
+
zora,
|
|
32
|
+
zoraSepolia,
|
|
33
|
+
beraChainBartio,
|
|
31
34
|
} from "./chains.js";
|
|
32
35
|
export type * from "./client/decorators/alchemyEnhancedApis.js";
|
|
33
36
|
export { alchemyEnhancedApiActions } from "./client/decorators/alchemyEnhancedApis.js";
|
|
34
37
|
export type * from "./client/decorators/smartAccount.js";
|
|
35
38
|
export { alchemyActions } from "./client/decorators/smartAccount.js";
|
|
36
|
-
export { createAlchemySmartAccountClientFromRpcClient as createAlchemySmartAccountClientFromExisting } from "./client/internal/smartAccountClientFromRpc.js";
|
|
37
39
|
export { isAlchemySmartAccountClient } from "./client/isAlchemySmartAccountClient.js";
|
|
38
40
|
export type * from "./client/rpcClient.js";
|
|
39
41
|
export { createAlchemyPublicRpcClient } from "./client/rpcClient.js";
|
|
@@ -47,5 +49,3 @@ export type * from "./middleware/gasManager.js";
|
|
|
47
49
|
export { alchemyGasManagerMiddleware } from "./middleware/gasManager.js";
|
|
48
50
|
export { alchemyUserOperationSimulator } from "./middleware/userOperationSimulator.js";
|
|
49
51
|
export type * from "./schema.js";
|
|
50
|
-
export { AlchemyProviderConfigSchema } from "./schema.js";
|
|
51
|
-
export type { AlchemyProviderConfig } from "./type.js";
|
package/src/metrics.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createLogger } from "@account-kit/logging";
|
|
2
|
+
import type { Address } from "viem";
|
|
3
|
+
import { VERSION } from "./version.js";
|
|
4
|
+
|
|
5
|
+
export type InfraEventsSchema = [
|
|
6
|
+
{
|
|
7
|
+
EventName: "client_send_uo";
|
|
8
|
+
EventData: {
|
|
9
|
+
signerType: string;
|
|
10
|
+
chainId: number;
|
|
11
|
+
entryPoint: Address;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export const InfraLogger = createLogger<InfraEventsSchema>({
|
|
17
|
+
package: "@account-kit/infra",
|
|
18
|
+
version: VERSION,
|
|
19
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClientMiddlewareFn } from "@aa-sdk/core";
|
|
2
2
|
import { applyUserOpOverrideOrFeeOption } from "@aa-sdk/core";
|
|
3
|
-
import type {
|
|
3
|
+
import type { AlchemyTransport } from "../alchemyTransport";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Function that estimates the transaction fees using Alchemy methods for a given client.
|
|
@@ -8,28 +8,33 @@ import type { ClientWithAlchemyMethods } from "../client/types";
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
|
-
* import { alchemyFeeEstimator,
|
|
11
|
+
* import { alchemyFeeEstimator, alchemy } from "@account-kit/infra";
|
|
12
12
|
* import { createSmartAccountClient } from "@aa-sdk/core";
|
|
13
13
|
*
|
|
14
|
-
* const
|
|
14
|
+
* const alchemyTransport = alchemy({
|
|
15
|
+
* chain: sepolia,
|
|
16
|
+
* apiKey: "your-api-key"
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
15
19
|
* const client = createSmartAccountClient({
|
|
16
|
-
* feeEstimator: alchemyFeeEstimator(
|
|
20
|
+
* feeEstimator: alchemyFeeEstimator(alchemyTransport),
|
|
17
21
|
* ...otherParams
|
|
18
22
|
* });
|
|
19
23
|
* ```
|
|
20
24
|
*
|
|
21
|
-
* @param {
|
|
25
|
+
* @param {AlchemyTransport} transport An alchemy transport for making Alchemy specific RPC calls
|
|
22
26
|
* @returns {ClientMiddlewareFn} A middleware function that takes a transaction structure and fee options, and returns the augmented structure with estimated fees
|
|
23
27
|
*/
|
|
24
|
-
export const alchemyFeeEstimator:
|
|
25
|
-
|
|
28
|
+
export const alchemyFeeEstimator: (
|
|
29
|
+
transport: AlchemyTransport
|
|
26
30
|
) => ClientMiddlewareFn =
|
|
27
|
-
(
|
|
28
|
-
async (struct, { overrides, feeOptions }) => {
|
|
31
|
+
(transport) =>
|
|
32
|
+
async (struct, { overrides, feeOptions, client }) => {
|
|
33
|
+
const transport_ = transport({ chain: client.chain });
|
|
29
34
|
let [block, maxPriorityFeePerGasEstimate] = await Promise.all([
|
|
30
35
|
client.getBlock({ blockTag: "latest" }),
|
|
31
36
|
// it is a fair assumption that if someone is using this Alchemy Middleware, then they are using Alchemy RPC
|
|
32
|
-
|
|
37
|
+
transport_.request({
|
|
33
38
|
method: "rundler_maxPriorityFeePerGas",
|
|
34
39
|
params: [],
|
|
35
40
|
}),
|
|
@@ -6,15 +6,14 @@ import { erc7677Middleware } from "@aa-sdk/core";
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
-
*
|
|
10
|
-
* import { sepolia } from "@account-kit/infra";
|
|
9
|
+
* import { sepolia, alchemyErc7677Middleware } from "@account-kit/infra";
|
|
11
10
|
* import { http } from "viem";
|
|
12
11
|
*
|
|
13
12
|
* const client = createSmartAccountClient({
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* transport: http("rpc-url"),
|
|
14
|
+
* chain: sepolia,
|
|
15
|
+
* ...alchemyErc7677Middleware("policyId")
|
|
16
|
+
* });
|
|
18
17
|
* ```
|
|
19
18
|
*
|
|
20
19
|
* @param {string} policyId the policyId for Alchemy's gas manager
|