@getpara/aa-alchemy 2.16.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.
@@ -0,0 +1,37 @@
1
+ import { type SmartAccountClient } from '@aa-sdk/core';
2
+ import type { SmartAccount4337, SmartAccount7702 } from '@getpara/viem-v2-integration';
3
+ import type { CreateAlchemySmartAccountParams } from './types.js';
4
+ export type { CreateAlchemySmartAccountParams, AlchemyTransactionOptions } from './types.js';
5
+ /**
6
+ * Creates an Alchemy smart account using Para for signing.
7
+ *
8
+ * Supports both EIP-4337 (modular account) and EIP-7702 (modular account v2) modes.
9
+ * Uses Alchemy's infrastructure for bundler and paymaster via the Account Kit SDK.
10
+ *
11
+ * @param params - Configuration parameters
12
+ * @returns Unified SmartAccount interface wrapping Alchemy client, or null if no EVM wallet exists
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { createAlchemySmartAccount } from '@getpara/aa-alchemy';
17
+ * import { sepolia } from 'viem/chains';
18
+ *
19
+ * const account = await createAlchemySmartAccount({
20
+ * para,
21
+ * apiKey: 'your-alchemy-api-key',
22
+ * chain: sepolia,
23
+ * gasPolicyId: 'your-gas-policy-id',
24
+ * });
25
+ *
26
+ * if (account) {
27
+ * const hash = await account.sendTransaction({ to, data, value });
28
+ * }
29
+ * ```
30
+ */
31
+ export declare function createAlchemySmartAccount(params: CreateAlchemySmartAccountParams & {
32
+ mode: '7702';
33
+ }): Promise<SmartAccount7702<SmartAccountClient> | null>;
34
+ export declare function createAlchemySmartAccount(params: CreateAlchemySmartAccountParams & {
35
+ mode?: '4337';
36
+ }): Promise<SmartAccount4337<SmartAccountClient> | null>;
37
+ export declare function createAlchemySmartAccount(params: CreateAlchemySmartAccountParams): Promise<SmartAccount4337<SmartAccountClient> | SmartAccount7702<SmartAccountClient> | null>;
package/dist/action.js ADDED
@@ -0,0 +1,94 @@
1
+ import { createModularAccountAlchemyClient, createModularAccountV2Client } from "@account-kit/smart-contracts";
2
+ import * as alchemyInfra from "@account-kit/infra";
3
+ import { WalletClientSigner } from "@aa-sdk/core";
4
+ import { createParaAccount } from "@getpara/viem-v2-integration";
5
+ import { SmartAccountError, wrapProviderError, resolveWalletIdentifier } from "@getpara/viem-v2-integration";
6
+ import { createWalletClient, createPublicClient, http } from "viem";
7
+ const ALCHEMY_7702_DELEGATION_ADDRESS = "0x69007702764179f14F51cdce752f4f775d74E139";
8
+ const alchemyChainById = new Map(
9
+ Object.values(alchemyInfra).filter((v) => v !== null && typeof v === "object" && "id" in v && v.rpcUrls?.alchemy).map((v) => [v.id, v])
10
+ );
11
+ function ensureAlchemyChain(chain) {
12
+ if (chain.rpcUrls?.alchemy) return chain;
13
+ const alchemyChain = alchemyChainById.get(chain.id);
14
+ if (alchemyChain) return alchemyChain;
15
+ throw new SmartAccountError({
16
+ code: "INVALID_CONFIG",
17
+ message: `Chain "${chain.name}" (id: ${chain.id}) is not supported by Alchemy. Use a chain from @account-kit/infra or pass one with rpcUrls.alchemy configured via defineAlchemyChain.`,
18
+ provider: "ALCHEMY"
19
+ });
20
+ }
21
+ async function createAlchemySmartAccount(params) {
22
+ const { para, apiKey, chain: rawChain, rpcUrl, gasPolicyId, mode = "4337" } = params;
23
+ const walletAddress = resolveWalletIdentifier(para, params);
24
+ if (!walletAddress) return null;
25
+ const chain = ensureAlchemyChain(rawChain);
26
+ const viemAccount = createParaAccount(para, walletAddress);
27
+ const viemClient = createWalletClient({ account: viemAccount, chain, transport: http(rpcUrl) });
28
+ const publicClient = createPublicClient({ chain, transport: http(rpcUrl) });
29
+ const walletClientSigner = new WalletClientSigner(viemClient, "para");
30
+ let alchemyClient;
31
+ if (mode === "7702") {
32
+ alchemyClient = await createModularAccountV2Client({
33
+ mode: "7702",
34
+ transport: alchemyInfra.alchemy({ apiKey }),
35
+ chain,
36
+ signer: walletClientSigner,
37
+ policyId: gasPolicyId
38
+ });
39
+ } else {
40
+ alchemyClient = await createModularAccountAlchemyClient({
41
+ transport: alchemyInfra.alchemy({ apiKey }),
42
+ chain,
43
+ signer: walletClientSigner,
44
+ policyId: gasPolicyId
45
+ });
46
+ }
47
+ const accountAddress = alchemyClient.account?.address;
48
+ if (!accountAddress) {
49
+ throw new SmartAccountError({
50
+ code: "MISSING_ACCOUNT_ADDRESS",
51
+ message: "Unable to determine account address from Alchemy client",
52
+ provider: "ALCHEMY"
53
+ });
54
+ }
55
+ const sendBatchTransaction = async (calls, txOptions) => {
56
+ const alchemyOptions = txOptions;
57
+ if (!alchemyClient.sendUserOperation) {
58
+ throw new SmartAccountError({
59
+ code: "INVALID_CONFIG",
60
+ message: "sendUserOperation not available on client",
61
+ provider: "ALCHEMY"
62
+ });
63
+ }
64
+ try {
65
+ const result = await alchemyClient.sendUserOperation({
66
+ uo: calls.map((call) => ({
67
+ target: call.to,
68
+ value: call.value || BigInt(0),
69
+ data: call.data || "0x"
70
+ })),
71
+ ...alchemyOptions?.overrides && { overrides: alchemyOptions.overrides }
72
+ });
73
+ const txHash = alchemyClient.waitForUserOperationTransaction ? await alchemyClient.waitForUserOperationTransaction({ hash: result.hash }) : result.hash;
74
+ return publicClient.getTransactionReceipt({ hash: txHash });
75
+ } catch (error) {
76
+ throw wrapProviderError(error, "ALCHEMY");
77
+ }
78
+ };
79
+ const sendTransaction = async (tx, txOptions) => sendBatchTransaction([tx], txOptions);
80
+ return {
81
+ smartAccountAddress: accountAddress,
82
+ signer: viemAccount,
83
+ chain,
84
+ mode,
85
+ provider: "ALCHEMY",
86
+ sendTransaction,
87
+ sendBatchTransaction,
88
+ ...mode === "7702" && { delegationAddress: ALCHEMY_7702_DELEGATION_ADDRESS },
89
+ client: alchemyClient
90
+ };
91
+ }
92
+ export {
93
+ createAlchemySmartAccount
94
+ };
@@ -0,0 +1,2 @@
1
+ export { createAlchemySmartAccount } from './action.js';
2
+ export type { AlchemySmartAccountConfig, CreateAlchemySmartAccountParams, UseAlchemySmartAccountParams, AlchemyTransactionOptions, } from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { createAlchemySmartAccount } from "./action.js";
2
+ export {
3
+ createAlchemySmartAccount
4
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,41 @@
1
+ import type { UserOperationOverrides } from '@aa-sdk/core';
2
+ import type { ApiKeySmartAccountConfig, CreateSmartAccountParams, SmartAccountModeParam } from '@getpara/viem-v2-integration';
3
+ /**
4
+ * Configuration for Alchemy smart account.
5
+ *
6
+ * Supports both EIP-4337 (modular account) and EIP-7702 (modular account v2) modes.
7
+ * Uses Alchemy's Account Kit for bundler and paymaster infrastructure.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const config: AlchemySmartAccountConfig = {
12
+ * apiKey: 'YOUR_ALCHEMY_API_KEY',
13
+ * chain: sepolia,
14
+ * gasPolicyId: 'YOUR_GAS_POLICY_ID',
15
+ * };
16
+ * ```
17
+ */
18
+ export interface AlchemySmartAccountConfig extends ApiKeySmartAccountConfig, SmartAccountModeParam {
19
+ /** Gas policy ID for sponsorship (optional — omit to skip gas sponsorship) */
20
+ gasPolicyId?: string;
21
+ }
22
+ /**
23
+ * Parameters for `createAlchemySmartAccount`.
24
+ * Includes all config fields plus `para` (the Para SDK instance).
25
+ */
26
+ export type CreateAlchemySmartAccountParams = CreateSmartAccountParams<AlchemySmartAccountConfig>;
27
+ /**
28
+ * Parameters for the `useAlchemySmartAccount` hook.
29
+ * Same as {@link AlchemySmartAccountConfig} — `para` is provided automatically via context.
30
+ */
31
+ export type UseAlchemySmartAccountParams = AlchemySmartAccountConfig;
32
+ /**
33
+ * Alchemy-specific transaction options.
34
+ * Pass as the second argument to `sendTransaction` or `sendBatchTransaction`.
35
+ */
36
+ export interface AlchemyTransactionOptions {
37
+ /** Override the gas policy for this specific transaction */
38
+ policyId?: string;
39
+ /** User operation overrides (gas limits, fees, etc.) */
40
+ overrides?: UserOperationOverrides;
41
+ }
package/dist/types.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@getpara/aa-alchemy",
3
+ "version": "2.16.0",
4
+ "description": "Alchemy smart account integration for Para",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "files": [
10
+ "dist",
11
+ "package.json"
12
+ ],
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs",
21
+ "typegen": "tsc --emitDeclarationOnly --outDir dist",
22
+ "test": "vitest run --coverage"
23
+ },
24
+ "dependencies": {
25
+ "@aa-sdk/core": "^4.84.1",
26
+ "@account-kit/infra": "^4.84.1",
27
+ "@account-kit/smart-contracts": "^4.84.1",
28
+ "@getpara/viem-v2-integration": "2.16.0"
29
+ },
30
+ "peerDependencies": {
31
+ "viem": ">=2.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "typescript": "^5.8.3"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "gitHead": "fbe96a062b308d04105213378c12c38ee973c798"
40
+ }