@alchemy/wallet-apis 5.0.0-beta.3 → 5.0.0-beta.31

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.
Files changed (201) hide show
  1. package/README.md +3 -1
  2. package/dist/esm/actions/prepareCalls.d.ts +8 -3
  3. package/dist/esm/actions/prepareCalls.js +8 -0
  4. package/dist/esm/actions/prepareCalls.js.map +1 -1
  5. package/dist/esm/actions/requestAccount.d.ts +4 -3
  6. package/dist/esm/actions/requestAccount.js.map +1 -1
  7. package/dist/esm/actions/sendCalls.d.ts +5 -2
  8. package/dist/esm/actions/sendCalls.js +5 -2
  9. package/dist/esm/actions/sendCalls.js.map +1 -1
  10. package/dist/esm/actions/sendPreparedCalls.d.ts +3 -1
  11. package/dist/esm/actions/sendPreparedCalls.js.map +1 -1
  12. package/dist/esm/actions/signPreparedCalls.d.ts +2 -0
  13. package/dist/esm/actions/signPreparedCalls.js +14 -1
  14. package/dist/esm/actions/signPreparedCalls.js.map +1 -1
  15. package/dist/esm/actions/signSignatureRequest.d.ts +4 -4
  16. package/dist/esm/actions/signSignatureRequest.js +1 -1
  17. package/dist/esm/actions/signSignatureRequest.js.map +1 -1
  18. package/dist/esm/actions/signTypedData.d.ts +14 -4
  19. package/dist/esm/actions/signTypedData.js.map +1 -1
  20. package/dist/esm/actions/solana/getCallsStatus.d.ts +24 -0
  21. package/dist/esm/actions/solana/getCallsStatus.js +44 -0
  22. package/dist/esm/actions/solana/getCallsStatus.js.map +1 -0
  23. package/dist/esm/actions/solana/prepareCalls.d.ts +46 -0
  24. package/dist/esm/actions/solana/prepareCalls.js +70 -0
  25. package/dist/esm/actions/solana/prepareCalls.js.map +1 -0
  26. package/dist/esm/actions/solana/sendCalls.d.ts +34 -0
  27. package/dist/esm/actions/solana/sendCalls.js +44 -0
  28. package/dist/esm/actions/solana/sendCalls.js.map +1 -0
  29. package/dist/esm/actions/solana/sendPreparedCalls.d.ts +24 -0
  30. package/dist/esm/actions/solana/sendPreparedCalls.js +32 -0
  31. package/dist/esm/actions/solana/sendPreparedCalls.js.map +1 -0
  32. package/dist/esm/actions/solana/signPreparedCalls.d.ts +23 -0
  33. package/dist/esm/actions/solana/signPreparedCalls.js +24 -0
  34. package/dist/esm/actions/solana/signPreparedCalls.js.map +1 -0
  35. package/dist/esm/actions/solana/signSignatureRequest.d.ts +10 -0
  36. package/dist/esm/actions/solana/signSignatureRequest.js +33 -0
  37. package/dist/esm/actions/solana/signSignatureRequest.js.map +1 -0
  38. package/dist/esm/actions/solana/waitForCallsStatus.d.ts +24 -0
  39. package/dist/esm/actions/solana/waitForCallsStatus.js +46 -0
  40. package/dist/esm/actions/solana/waitForCallsStatus.js.map +1 -0
  41. package/dist/esm/actions/undelegateAccount.d.ts +37 -0
  42. package/dist/esm/actions/undelegateAccount.js +49 -0
  43. package/dist/esm/actions/undelegateAccount.js.map +1 -0
  44. package/dist/esm/adapters/SolanaSignerError.d.ts +4 -0
  45. package/dist/esm/adapters/SolanaSignerError.js +13 -0
  46. package/dist/esm/adapters/SolanaSignerError.js.map +1 -0
  47. package/dist/esm/adapters/fromKeypair.d.ts +21 -0
  48. package/dist/esm/adapters/fromKeypair.js +46 -0
  49. package/dist/esm/adapters/fromKeypair.js.map +1 -0
  50. package/dist/esm/adapters/fromKitSigner.d.ts +21 -0
  51. package/dist/esm/adapters/fromKitSigner.js +61 -0
  52. package/dist/esm/adapters/fromKitSigner.js.map +1 -0
  53. package/dist/esm/adapters/fromWalletAdapter.d.ts +26 -0
  54. package/dist/esm/adapters/fromWalletAdapter.js +45 -0
  55. package/dist/esm/adapters/fromWalletAdapter.js.map +1 -0
  56. package/dist/esm/adapters/fromWalletStandard.d.ts +31 -0
  57. package/dist/esm/adapters/fromWalletStandard.js +53 -0
  58. package/dist/esm/adapters/fromWalletStandard.js.map +1 -0
  59. package/dist/esm/adapters/resolveSignerSlot.d.ts +10 -0
  60. package/dist/esm/adapters/resolveSignerSlot.js +39 -0
  61. package/dist/esm/adapters/resolveSignerSlot.js.map +1 -0
  62. package/dist/esm/client.d.ts +29 -14
  63. package/dist/esm/client.js +63 -19
  64. package/dist/esm/client.js.map +1 -1
  65. package/dist/esm/decorators/smartWalletActions.d.ts +2 -0
  66. package/dist/esm/decorators/smartWalletActions.js +4 -2
  67. package/dist/esm/decorators/smartWalletActions.js.map +1 -1
  68. package/dist/esm/decorators/solanaSmartWalletActions.d.ts +16 -0
  69. package/dist/esm/decorators/solanaSmartWalletActions.js +16 -0
  70. package/dist/esm/decorators/solanaSmartWalletActions.js.map +1 -0
  71. package/dist/esm/experimental/actions/requestQuoteV0.d.ts +48 -11
  72. package/dist/esm/experimental/actions/requestQuoteV0.js +8 -4
  73. package/dist/esm/experimental/actions/requestQuoteV0.js.map +1 -1
  74. package/dist/esm/experimental/swapActionsDecorator.d.ts +3 -0
  75. package/dist/esm/experimental/swapActionsDecorator.js.map +1 -1
  76. package/dist/esm/exports/index.d.ts +5 -3
  77. package/dist/esm/exports/index.js +1 -0
  78. package/dist/esm/exports/index.js.map +1 -1
  79. package/dist/esm/exports/solana.d.ts +24 -0
  80. package/dist/esm/exports/solana.js +15 -0
  81. package/dist/esm/exports/solana.js.map +1 -0
  82. package/dist/esm/types.d.ts +28 -4
  83. package/dist/esm/types.js.map +1 -1
  84. package/dist/esm/utils/assertions.d.ts +4 -2
  85. package/dist/esm/utils/assertions.js +6 -0
  86. package/dist/esm/utils/assertions.js.map +1 -1
  87. package/dist/esm/utils/capabilities.d.ts +22 -6
  88. package/dist/esm/utils/capabilities.js +19 -2
  89. package/dist/esm/utils/capabilities.js.map +1 -1
  90. package/dist/esm/utils/format.d.ts +2 -2
  91. package/dist/esm/utils/format.js +4 -3
  92. package/dist/esm/utils/format.js.map +1 -1
  93. package/dist/esm/utils/schema.d.ts +14 -14
  94. package/dist/esm/utils/schema.js +35 -39
  95. package/dist/esm/utils/schema.js.map +1 -1
  96. package/dist/esm/version.d.ts +1 -1
  97. package/dist/esm/version.js +1 -1
  98. package/dist/esm/version.js.map +1 -1
  99. package/dist/types/actions/prepareCalls.d.ts +8 -3
  100. package/dist/types/actions/prepareCalls.d.ts.map +1 -1
  101. package/dist/types/actions/requestAccount.d.ts +4 -3
  102. package/dist/types/actions/requestAccount.d.ts.map +1 -1
  103. package/dist/types/actions/sendCalls.d.ts +5 -2
  104. package/dist/types/actions/sendCalls.d.ts.map +1 -1
  105. package/dist/types/actions/sendPreparedCalls.d.ts +3 -1
  106. package/dist/types/actions/sendPreparedCalls.d.ts.map +1 -1
  107. package/dist/types/actions/signPreparedCalls.d.ts +2 -0
  108. package/dist/types/actions/signPreparedCalls.d.ts.map +1 -1
  109. package/dist/types/actions/signSignatureRequest.d.ts +4 -4
  110. package/dist/types/actions/signSignatureRequest.d.ts.map +1 -1
  111. package/dist/types/actions/signTypedData.d.ts +14 -4
  112. package/dist/types/actions/signTypedData.d.ts.map +1 -1
  113. package/dist/types/actions/solana/getCallsStatus.d.ts +25 -0
  114. package/dist/types/actions/solana/getCallsStatus.d.ts.map +1 -0
  115. package/dist/types/actions/solana/prepareCalls.d.ts +47 -0
  116. package/dist/types/actions/solana/prepareCalls.d.ts.map +1 -0
  117. package/dist/types/actions/solana/sendCalls.d.ts +35 -0
  118. package/dist/types/actions/solana/sendCalls.d.ts.map +1 -0
  119. package/dist/types/actions/solana/sendPreparedCalls.d.ts +25 -0
  120. package/dist/types/actions/solana/sendPreparedCalls.d.ts.map +1 -0
  121. package/dist/types/actions/solana/signPreparedCalls.d.ts +24 -0
  122. package/dist/types/actions/solana/signPreparedCalls.d.ts.map +1 -0
  123. package/dist/types/actions/solana/signSignatureRequest.d.ts +11 -0
  124. package/dist/types/actions/solana/signSignatureRequest.d.ts.map +1 -0
  125. package/dist/types/actions/solana/waitForCallsStatus.d.ts +25 -0
  126. package/dist/types/actions/solana/waitForCallsStatus.d.ts.map +1 -0
  127. package/dist/types/actions/undelegateAccount.d.ts +38 -0
  128. package/dist/types/actions/undelegateAccount.d.ts.map +1 -0
  129. package/dist/types/adapters/SolanaSignerError.d.ts +5 -0
  130. package/dist/types/adapters/SolanaSignerError.d.ts.map +1 -0
  131. package/dist/types/adapters/fromKeypair.d.ts +22 -0
  132. package/dist/types/adapters/fromKeypair.d.ts.map +1 -0
  133. package/dist/types/adapters/fromKitSigner.d.ts +22 -0
  134. package/dist/types/adapters/fromKitSigner.d.ts.map +1 -0
  135. package/dist/types/adapters/fromWalletAdapter.d.ts +27 -0
  136. package/dist/types/adapters/fromWalletAdapter.d.ts.map +1 -0
  137. package/dist/types/adapters/fromWalletStandard.d.ts +32 -0
  138. package/dist/types/adapters/fromWalletStandard.d.ts.map +1 -0
  139. package/dist/types/adapters/resolveSignerSlot.d.ts +11 -0
  140. package/dist/types/adapters/resolveSignerSlot.d.ts.map +1 -0
  141. package/dist/types/client.d.ts +29 -14
  142. package/dist/types/client.d.ts.map +1 -1
  143. package/dist/types/decorators/smartWalletActions.d.ts +2 -0
  144. package/dist/types/decorators/smartWalletActions.d.ts.map +1 -1
  145. package/dist/types/decorators/solanaSmartWalletActions.d.ts +17 -0
  146. package/dist/types/decorators/solanaSmartWalletActions.d.ts.map +1 -0
  147. package/dist/types/experimental/actions/requestQuoteV0.d.ts +48 -11
  148. package/dist/types/experimental/actions/requestQuoteV0.d.ts.map +1 -1
  149. package/dist/types/experimental/swapActionsDecorator.d.ts +3 -0
  150. package/dist/types/experimental/swapActionsDecorator.d.ts.map +1 -1
  151. package/dist/types/exports/index.d.ts +5 -3
  152. package/dist/types/exports/index.d.ts.map +1 -1
  153. package/dist/types/exports/solana.d.ts +25 -0
  154. package/dist/types/exports/solana.d.ts.map +1 -0
  155. package/dist/types/types.d.ts +28 -4
  156. package/dist/types/types.d.ts.map +1 -1
  157. package/dist/types/utils/assertions.d.ts +4 -2
  158. package/dist/types/utils/assertions.d.ts.map +1 -1
  159. package/dist/types/utils/capabilities.d.ts +22 -6
  160. package/dist/types/utils/capabilities.d.ts.map +1 -1
  161. package/dist/types/utils/format.d.ts +2 -2
  162. package/dist/types/utils/format.d.ts.map +1 -1
  163. package/dist/types/utils/schema.d.ts +14 -14
  164. package/dist/types/utils/schema.d.ts.map +1 -1
  165. package/dist/types/version.d.ts +1 -1
  166. package/dist/types/version.d.ts.map +1 -1
  167. package/package.json +29 -11
  168. package/src/actions/prepareCalls.ts +21 -3
  169. package/src/actions/requestAccount.ts +7 -5
  170. package/src/actions/sendCalls.ts +5 -2
  171. package/src/actions/sendPreparedCalls.ts +4 -1
  172. package/src/actions/signPreparedCalls.ts +15 -2
  173. package/src/actions/signSignatureRequest.ts +8 -8
  174. package/src/actions/signTypedData.ts +15 -7
  175. package/src/actions/solana/getCallsStatus.ts +79 -0
  176. package/src/actions/solana/prepareCalls.ts +120 -0
  177. package/src/actions/solana/sendCalls.ts +66 -0
  178. package/src/actions/solana/sendPreparedCalls.ts +65 -0
  179. package/src/actions/solana/signPreparedCalls.ts +50 -0
  180. package/src/actions/solana/signSignatureRequest.ts +63 -0
  181. package/src/actions/solana/waitForCallsStatus.ts +84 -0
  182. package/src/actions/undelegateAccount.ts +68 -0
  183. package/src/adapters/SolanaSignerError.ts +5 -0
  184. package/src/adapters/fromKeypair.ts +58 -0
  185. package/src/adapters/fromKitSigner.ts +82 -0
  186. package/src/adapters/fromWalletAdapter.ts +58 -0
  187. package/src/adapters/fromWalletStandard.ts +100 -0
  188. package/src/adapters/resolveSignerSlot.ts +46 -0
  189. package/src/client.ts +131 -18
  190. package/src/decorators/smartWalletActions.ts +11 -2
  191. package/src/decorators/solanaSmartWalletActions.ts +62 -0
  192. package/src/experimental/actions/requestQuoteV0.ts +40 -15
  193. package/src/experimental/swapActionsDecorator.ts +3 -0
  194. package/src/exports/index.ts +10 -4
  195. package/src/exports/solana.ts +36 -0
  196. package/src/types.ts +38 -7
  197. package/src/utils/assertions.ts +17 -2
  198. package/src/utils/capabilities.ts +40 -8
  199. package/src/utils/format.ts +8 -3
  200. package/src/utils/schema.ts +58 -69
  201. package/src/version.ts +1 -1
@@ -0,0 +1,58 @@
1
+ import type { SolanaSigner } from "../types.js";
2
+ import type { VersionedTransaction } from "@solana/web3.js";
3
+ import { SolanaSignerError } from "./SolanaSignerError.js";
4
+
5
+ /** Any signer with a `publicKey` and `signTransaction(VersionedTransaction)` method — matches `useWallet()` from `@solana/wallet-adapter-react` and injected wallet providers like `window.phantom.solana`. */
6
+ export interface WalletAdapterSigner {
7
+ publicKey: { toBase58(): string };
8
+ signTransaction: <T extends VersionedTransaction>(
9
+ transaction: T,
10
+ ) => Promise<T>;
11
+ }
12
+
13
+ /**
14
+ * Adapts a wallet that signs `VersionedTransaction` objects into a {@link SolanaSigner}.
15
+ *
16
+ * Works with `useWallet()` from `@solana/wallet-adapter-react` and injected
17
+ * browser wallet providers (e.g. `window.phantom.solana`). Handles the
18
+ * `Uint8Array` ↔ `VersionedTransaction` conversion internally.
19
+ *
20
+ * For `@solana/kit` signers, use {@link fromKitSigner}. For raw Ed25519
21
+ * keypairs, use {@link fromKeypair}. For wallet-standard wallets, use
22
+ * {@link fromWalletStandard}.
23
+ *
24
+ * Requires `@solana/web3.js` as a peer dependency.
25
+ *
26
+ * @param {WalletAdapterSigner} signer - The wallet adapter signer
27
+ * @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`
28
+ */
29
+ export function fromWalletAdapter(signer: WalletAdapterSigner): SolanaSigner {
30
+ return {
31
+ address: signer.publicKey.toBase58(),
32
+ async signTransaction({ transaction }) {
33
+ let tx: VersionedTransaction;
34
+ try {
35
+ const web3 = await import("@solana/web3.js");
36
+ tx = web3.VersionedTransaction.deserialize(transaction);
37
+ } catch (e) {
38
+ throw new SolanaSignerError("Failed to deserialize transaction", {
39
+ cause: e as Error,
40
+ });
41
+ }
42
+
43
+ let signed: VersionedTransaction;
44
+ try {
45
+ signed = await signer.signTransaction(tx);
46
+ } catch (e) {
47
+ throw new SolanaSignerError(
48
+ "Wallet adapter failed to sign transaction",
49
+ {
50
+ cause: e as Error,
51
+ },
52
+ );
53
+ }
54
+
55
+ return { signedTransaction: new Uint8Array(signed.serialize()) };
56
+ },
57
+ };
58
+ }
@@ -0,0 +1,100 @@
1
+ import { SolanaSignerError } from "./SolanaSignerError.js";
2
+ import type { SolanaSigner } from "../types.js";
3
+
4
+ const SIGN_TRANSACTION = "solana:signTransaction";
5
+
6
+ /** Minimal structural shape of a wallet-standard account. */
7
+ export interface WalletStandardAccount {
8
+ address: string;
9
+ publicKey?: Uint8Array;
10
+ chains?: readonly string[];
11
+ features?: readonly string[];
12
+ [key: string]: unknown;
13
+ }
14
+
15
+ /** Minimal structural shape of a wallet-standard wallet. */
16
+ export interface WalletStandardWallet {
17
+ features: { readonly [name: string]: unknown };
18
+ }
19
+
20
+ interface SolanaSignTransactionFeature {
21
+ readonly signTransaction: (
22
+ ...inputs: readonly {
23
+ account: WalletStandardAccount;
24
+ transaction: Uint8Array;
25
+ }[]
26
+ ) => Promise<readonly { signedTransaction: Uint8Array }[]>;
27
+ }
28
+
29
+ function isSolanaSignTransactionFeature(
30
+ feature: unknown,
31
+ ): feature is SolanaSignTransactionFeature {
32
+ return (
33
+ typeof feature === "object" &&
34
+ feature !== null &&
35
+ "signTransaction" in feature &&
36
+ typeof (feature as { signTransaction?: unknown }).signTransaction ===
37
+ "function"
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Adapts a Wallet Standard wallet into a {@link SolanaSigner}.
43
+ *
44
+ * Works with any wallet that implements the `solana:signTransaction` feature
45
+ * from the Wallet Standard spec (Phantom, Solflare, etc.). No peer dependency
46
+ * required — the interface uses `Uint8Array` directly.
47
+ *
48
+ * For `@solana/wallet-adapter-react` wallets, use {@link fromWalletAdapter}.
49
+ * For `@solana/kit` signers, use {@link fromKitSigner}. For raw Ed25519
50
+ * keypairs, use {@link fromKeypair}.
51
+ *
52
+ * @param {WalletStandardWallet} wallet - The wallet-standard wallet object
53
+ * @param {WalletStandardAccount} account - The account to sign with
54
+ * @returns {SolanaSigner} A SolanaSigner compatible with `createSmartWalletClient`
55
+ */
56
+ export function fromWalletStandard(
57
+ wallet: WalletStandardWallet,
58
+ account: WalletStandardAccount,
59
+ ): SolanaSigner {
60
+ const feature = wallet.features[SIGN_TRANSACTION];
61
+
62
+ if (!isSolanaSignTransactionFeature(feature)) {
63
+ throw new SolanaSignerError(
64
+ `Wallet does not support the "${SIGN_TRANSACTION}" feature.`,
65
+ );
66
+ }
67
+
68
+ if (account.features && !account.features.includes(SIGN_TRANSACTION)) {
69
+ throw new SolanaSignerError(
70
+ `Account ${account.address} does not support the "${SIGN_TRANSACTION}" feature.`,
71
+ );
72
+ }
73
+
74
+ return {
75
+ address: account.address,
76
+ async signTransaction({ transaction }) {
77
+ let output: { signedTransaction: Uint8Array } | undefined;
78
+ try {
79
+ [output] = await feature.signTransaction({ account, transaction });
80
+ } catch (e) {
81
+ throw new SolanaSignerError(
82
+ "Wallet standard wallet failed to sign transaction",
83
+ { cause: e as Error },
84
+ );
85
+ }
86
+
87
+ if (!output) {
88
+ throw new SolanaSignerError("Wallet returned no signed transaction.");
89
+ }
90
+
91
+ if (!(output.signedTransaction instanceof Uint8Array)) {
92
+ throw new SolanaSignerError(
93
+ "Wallet returned an invalid signed transaction.",
94
+ );
95
+ }
96
+
97
+ return output;
98
+ },
99
+ };
100
+ }
@@ -0,0 +1,46 @@
1
+ import { SolanaSignerError } from "./SolanaSignerError.js";
2
+
3
+ /**
4
+ * Finds the signature slot index for `signerAddress` by decoding the
5
+ * transaction message and looking up the address in the account keys.
6
+ * Tries `@solana/kit` first, falls back to `@solana/web3.js`.
7
+ *
8
+ * @param {Uint8Array} transaction - The serialized Solana transaction bytes
9
+ * @param {string} signerAddress - The base58-encoded address of the signer
10
+ * @returns {Promise<number>} The slot index, or -1 if the address is not a required signer
11
+ */
12
+ export async function findSignerSlot(
13
+ transaction: Uint8Array,
14
+ signerAddress: string,
15
+ ): Promise<number> {
16
+ let accounts: readonly string[];
17
+ let numRequiredSigners: number;
18
+
19
+ try {
20
+ const { getCompiledTransactionMessageDecoder } = await import(
21
+ "@solana/kit"
22
+ );
23
+ const numSigs = transaction[0];
24
+ const messageBytes = transaction.slice(1 + numSigs * 64);
25
+ const decoded = getCompiledTransactionMessageDecoder().decode(messageBytes);
26
+ accounts = decoded.staticAccounts as readonly string[];
27
+ numRequiredSigners = decoded.header.numSignerAccounts;
28
+ } catch {
29
+ try {
30
+ const { VersionedTransaction } = await import("@solana/web3.js");
31
+ const vtx = VersionedTransaction.deserialize(transaction);
32
+ accounts = vtx.message.staticAccountKeys.map((k) => k.toBase58());
33
+ numRequiredSigners = vtx.message.header.numRequiredSignatures;
34
+ } catch {
35
+ throw new SolanaSignerError(
36
+ "Failed to decode transaction: install @solana/kit or @solana/web3.js",
37
+ );
38
+ }
39
+ }
40
+
41
+ const slotIndex = accounts.indexOf(signerAddress);
42
+ if (slotIndex < 0 || slotIndex >= numRequiredSigners) {
43
+ return -1;
44
+ }
45
+ return slotIndex;
46
+ }
package/src/client.ts CHANGED
@@ -1,11 +1,51 @@
1
- import { createClient, type Address, type Chain } from "viem";
1
+ import { BaseError } from "@alchemy/common";
2
+ import { createClient, defineChain, type Address, type Chain } from "viem";
2
3
  import { smartWalletActions } from "./decorators/smartWalletActions.js";
3
- import type { SmartWalletClient, SmartWalletSigner } from "./types.js";
4
+ import { solanaSmartWalletActions } from "./decorators/solanaSmartWalletActions.js";
5
+ import type {
6
+ SmartWalletClient,
7
+ SmartWalletSigner,
8
+ SolanaSmartWalletClient,
9
+ SolanaSigner,
10
+ SolanaChainDef,
11
+ } from "./types.js";
4
12
  import { createInternalState } from "./internal.js";
5
13
  import { isLocalAccount } from "./utils/assertions.js";
6
14
  import type { AlchemyWalletTransport } from "./transport.js";
15
+ import type { SolanaChainId } from "@alchemy/wallet-api-types";
7
16
 
8
- export type CreateSmartWalletClientParams = {
17
+ // ── Solana chain definitions ────────────────────────────────────────────
18
+
19
+ const solanaMainnet: SolanaChainDef = {
20
+ ...defineChain({
21
+ id: 0,
22
+ name: "Solana Mainnet",
23
+ nativeCurrency: { name: "SOL", symbol: "SOL", decimals: 9 },
24
+ rpcUrls: { default: { http: [] } },
25
+ }),
26
+ solanaChainId: "solana:mainnet",
27
+ };
28
+
29
+ const solanaDevnet: SolanaChainDef = {
30
+ ...defineChain({
31
+ id: 0,
32
+ name: "Solana Devnet",
33
+ nativeCurrency: { name: "SOL", symbol: "SOL", decimals: 9 },
34
+ rpcUrls: { default: { http: [] } },
35
+ }),
36
+ solanaChainId: "solana:devnet",
37
+ };
38
+
39
+ export const SOLANA_CHAINS: Record<SolanaChainId, SolanaChainDef> = {
40
+ "solana:mainnet": solanaMainnet,
41
+ "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": solanaMainnet,
42
+ "solana:devnet": solanaDevnet,
43
+ "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1": solanaDevnet,
44
+ };
45
+
46
+ // ── Param types ─────────────────────────────────────────────────────────
47
+
48
+ export type CreateEvmSmartWalletClientParams = {
9
49
  signer: SmartWalletSigner;
10
50
  transport: AlchemyWalletTransport;
11
51
  chain: Chain;
@@ -16,30 +56,71 @@ export type CreateSmartWalletClientParams = {
16
56
  };
17
57
  };
18
58
 
59
+ export type CreateSolanaSmartWalletClientParams = {
60
+ signer: SolanaSigner;
61
+ transport: AlchemyWalletTransport;
62
+ chain: SolanaChainId;
63
+ account?: string;
64
+ paymaster?: {
65
+ policyId: string;
66
+ };
67
+ };
68
+
69
+ /** Either {@link CreateEvmSmartWalletClientParams} or {@link CreateSolanaSmartWalletClientParams}. */
70
+ export type CreateSmartWalletClientParams =
71
+ | CreateEvmSmartWalletClientParams
72
+ | CreateSolanaSmartWalletClientParams;
73
+
74
+ // ── Factory ─────────────────────────────────────────────────────────────
75
+
76
+ function isSolanaParams(
77
+ params: CreateSmartWalletClientParams,
78
+ ): params is CreateSolanaSmartWalletClientParams {
79
+ return typeof params.chain === "string" && params.chain.startsWith("solana:");
80
+ }
81
+
19
82
  /**
20
- * Creates a smart wallet client with wallet API actions.
83
+ * Creates a smart wallet client for EVM chains with actions for preparing,
84
+ * signing, and sending user operations.
21
85
  *
22
- * By default, the client uses EIP-7702 with the signer's address, allowing you to call
23
- * `prepareCalls` or `sendCalls` directly without first calling `requestAccount`.
24
- * Use `requestAccount` only if you need a non-7702 smart account.
86
+ * @param {CreateEvmSmartWalletClientParams} params - EVM client configuration
87
+ * @returns {SmartWalletClient} An EVM smart wallet client with smart wallet actions
88
+ */
89
+ export function createSmartWalletClient(
90
+ params: CreateEvmSmartWalletClientParams,
91
+ ): SmartWalletClient;
92
+ /**
93
+ * Creates a smart wallet client for Solana chains with actions for preparing,
94
+ * signing, and sending transactions.
25
95
  *
26
- * @param {CreateSmartWalletClientParams} params - Parameters for creating the smart wallet client.
27
- * @param {SmartWalletSigner} params.signer - The signer to use for signing transactions.
28
- * @param {AlchemyWalletTransport} params.transport - The transport to use for RPC calls.
29
- * @param {Chain} params.chain - The blockchain network to connect to.
30
- * @param {AccountParam} [params.account] - Optional account. Can be an address string or an object with an `address` property. Defaults to the signer's address (EIP-7702).
31
- * @param {object} [params.paymaster] - Optional paymaster configuration with policy IDs.
32
- * @returns {SmartWalletClient} A wallet client extended with smart wallet actions.
96
+ * Solana-specific adapters are in `@alchemy/wallet-apis/solana`.
97
+ *
98
+ * @param {CreateSolanaSmartWalletClientParams} params - Solana client configuration
99
+ * @returns {SolanaSmartWalletClient} A Solana smart wallet client with Solana smart wallet actions
33
100
  */
34
- export const createSmartWalletClient = ({
101
+ export function createSmartWalletClient(
102
+ params: CreateSolanaSmartWalletClientParams,
103
+ ): SolanaSmartWalletClient;
104
+ export function createSmartWalletClient(
105
+ params: CreateSmartWalletClientParams,
106
+ ): SmartWalletClient | SolanaSmartWalletClient {
107
+ if (isSolanaParams(params)) {
108
+ return createSolanaClient(params);
109
+ }
110
+ return createEvmClient(params);
111
+ }
112
+
113
+ // ── EVM path ────────────────────────────────────────────────────────────
114
+
115
+ function createEvmClient({
35
116
  signer,
36
117
  transport,
37
118
  chain,
38
119
  account,
39
120
  paymaster,
40
- }: CreateSmartWalletClientParams): SmartWalletClient => {
121
+ }: CreateEvmSmartWalletClientParams): SmartWalletClient {
41
122
  const _policyIds = [
42
- ...(paymaster?.policyId ? [paymaster?.policyId] : []),
123
+ ...(paymaster?.policyId ? [paymaster.policyId] : []),
43
124
  ...(paymaster?.policyIds ?? []),
44
125
  ];
45
126
 
@@ -60,4 +141,36 @@ export const createSmartWalletClient = ({
60
141
  owner: signer,
61
142
  }))
62
143
  .extend(smartWalletActions);
63
- };
144
+ }
145
+
146
+ // ── Solana path ─────────────────────────────────────────────────────────
147
+
148
+ function createSolanaClient({
149
+ signer,
150
+ transport,
151
+ chain,
152
+ account,
153
+ paymaster,
154
+ }: CreateSolanaSmartWalletClientParams): SolanaSmartWalletClient {
155
+ const _policyIds = paymaster?.policyId ? [paymaster.policyId] : [];
156
+
157
+ const _account = account ?? signer.address;
158
+
159
+ const _chain = SOLANA_CHAINS[chain];
160
+ if (!_chain) {
161
+ throw new BaseError(`Unsupported Solana chain: ${chain}`);
162
+ }
163
+
164
+ return createClient({
165
+ transport,
166
+ chain: _chain,
167
+ name: "alchemySolanaSmartWalletClient",
168
+ })
169
+ .extend(() => ({
170
+ policyIds: _policyIds,
171
+ internal: createInternalState(),
172
+ owner: signer,
173
+ solanaAccount: _account,
174
+ }))
175
+ .extend(solanaSmartWalletActions);
176
+ }
@@ -49,6 +49,11 @@ import {
49
49
  type GetCapabilitiesParams,
50
50
  type GetCapabilitiesResult,
51
51
  } from "../actions/getCapabilities.js";
52
+ import {
53
+ undelegateAccount,
54
+ type UndelegateAccountParams,
55
+ type UndelegateAccountResult,
56
+ } from "../actions/undelegateAccount.js";
52
57
  import type { InnerWalletApiClient } from "../types.js";
53
58
  import {
54
59
  getCallsStatus,
@@ -89,6 +94,9 @@ export type SmartWalletActions = {
89
94
  getCapabilities: (
90
95
  params?: GetCapabilitiesParams | undefined,
91
96
  ) => Promise<GetCapabilitiesResult>;
97
+ undelegateAccount: (
98
+ params?: UndelegateAccountParams,
99
+ ) => Promise<UndelegateAccountResult>;
92
100
  };
93
101
 
94
102
  /**
@@ -101,7 +109,7 @@ export type SmartWalletActions = {
101
109
  export const smartWalletActions = (
102
110
  client: InnerWalletApiClient,
103
111
  ): SmartWalletActions => ({
104
- // Alchemy methods.
112
+ // Alchemy actions.
105
113
  requestAccount: (params) => requestAccount(client, params),
106
114
  prepareCalls: (params) => prepareCalls(client, params),
107
115
  listAccounts: (params) => listAccounts(client, params),
@@ -113,7 +121,8 @@ export const smartWalletActions = (
113
121
  signTypedData: (params) => signTypedData(client, params),
114
122
  grantPermissions: (params) => grantPermissions(client, params),
115
123
  getCapabilities: (params) => getCapabilities(client, params),
116
- // Viem methods.
124
+ undelegateAccount: (params) => undelegateAccount(client, params),
125
+ // Viem actions.
117
126
  getCallsStatus: (params) => getCallsStatus(client, params),
118
127
  waitForCallsStatus: (params) => waitForCallsStatus(client, params),
119
128
  });
@@ -0,0 +1,62 @@
1
+ import type { InnerSolanaWalletApiClient } from "../types.js";
2
+ import {
3
+ prepareCalls,
4
+ type SolanaPrepareCallsParams,
5
+ type SolanaPrepareCallsResult,
6
+ } from "../actions/solana/prepareCalls.js";
7
+ import {
8
+ signPreparedCalls,
9
+ type SolanaSignPreparedCallsParams,
10
+ type SolanaSignPreparedCallsResult,
11
+ } from "../actions/solana/signPreparedCalls.js";
12
+ import {
13
+ sendPreparedCalls,
14
+ type SolanaSendPreparedCallsParams,
15
+ type SolanaSendPreparedCallsResult,
16
+ } from "../actions/solana/sendPreparedCalls.js";
17
+ import {
18
+ sendCalls,
19
+ type SolanaSendCallsParams,
20
+ type SolanaSendCallsResult,
21
+ } from "../actions/solana/sendCalls.js";
22
+ import {
23
+ getCallsStatus,
24
+ type SolanaGetCallsStatusParams,
25
+ type SolanaGetCallsStatusResult,
26
+ } from "../actions/solana/getCallsStatus.js";
27
+ import {
28
+ waitForCallsStatus,
29
+ type SolanaWaitForCallsStatusParams,
30
+ type SolanaWaitForCallsStatusResult,
31
+ } from "../actions/solana/waitForCallsStatus.js";
32
+
33
+ export type SolanaSmartWalletActions = {
34
+ prepareCalls: (
35
+ params: SolanaPrepareCallsParams,
36
+ ) => Promise<SolanaPrepareCallsResult>;
37
+ signPreparedCalls: (
38
+ params: SolanaSignPreparedCallsParams,
39
+ ) => Promise<SolanaSignPreparedCallsResult>;
40
+ sendPreparedCalls: (
41
+ params: SolanaSendPreparedCallsParams,
42
+ ) => Promise<SolanaSendPreparedCallsResult>;
43
+ sendCalls: (params: SolanaSendCallsParams) => Promise<SolanaSendCallsResult>;
44
+ getCallsStatus: (
45
+ params: SolanaGetCallsStatusParams,
46
+ ) => Promise<SolanaGetCallsStatusResult>;
47
+ waitForCallsStatus: (
48
+ params: SolanaWaitForCallsStatusParams,
49
+ ) => Promise<SolanaWaitForCallsStatusResult>;
50
+ };
51
+
52
+ export const solanaSmartWalletActions = (
53
+ client: InnerSolanaWalletApiClient,
54
+ ): SolanaSmartWalletActions => ({
55
+ prepareCalls: (params) => prepareCalls(client, params),
56
+ signPreparedCalls: (params) => signPreparedCalls(client, params),
57
+ sendPreparedCalls: (params) => sendPreparedCalls(client, params),
58
+ sendCalls: (params) => sendCalls(client, params),
59
+ // Note that status actions from Viem don't work since the chain ID is not hex.
60
+ getCallsStatus: (params) => getCallsStatus(client, params),
61
+ waitForCallsStatus: (params) => waitForCallsStatus(client, params),
62
+ });
@@ -1,11 +1,10 @@
1
- import type { Address, Prettify } from "viem";
2
- import type { DistributiveOmit, InnerWalletApiClient } from "../../types.ts";
1
+ import type { Address, Hex, Prettify } from "viem";
2
+ import type { InnerWalletApiClient } from "../../types.ts";
3
3
  import {
4
4
  fromRpcCapabilities,
5
5
  mergeClientCapabilities,
6
6
  toRpcCapabilities,
7
7
  type PrepareCallsCapabilities,
8
- type WithCapabilities,
9
8
  } from "../../utils/capabilities.js";
10
9
  import { resolveAddress, type AccountParam } from "../../utils/resolve.js";
11
10
  import { wallet_requestQuote_v0 as MethodSchema } from "@alchemy/wallet-api-types/rpc";
@@ -13,21 +12,40 @@ import {
13
12
  methodSchema,
14
13
  encode,
15
14
  decode,
16
- type MethodParams,
17
15
  type MethodResponse,
18
16
  } from "../../utils/schema.js";
19
17
 
20
18
  const schema = methodSchema(MethodSchema);
21
- type BaseRequestQuoteV0Params = MethodParams<typeof MethodSchema>;
22
19
  type RequestQuoteV0Response = MethodResponse<typeof MethodSchema>;
23
20
 
24
- export type RequestQuoteV0Params = Prettify<
25
- WithCapabilities<
26
- DistributiveOmit<BaseRequestQuoteV0Params, "from" | "chainId"> & {
27
- account?: AccountParam;
28
- chainId?: number;
21
+ type SwapAmountParams =
22
+ | { fromAmount: bigint; minimumToAmount?: never }
23
+ | { fromAmount?: never; minimumToAmount: bigint };
24
+
25
+ type SwapChainParams =
26
+ | {
27
+ toChainId?: never;
28
+ postCalls?: Array<{ to: Address; data?: Hex; value?: bigint }>;
29
29
  }
30
- >
30
+ | { toChainId: number; postCalls?: never };
31
+
32
+ type SwapExecutionParams =
33
+ | { returnRawCalls?: false; capabilities?: PrepareCallsCapabilities }
34
+ | { returnRawCalls: true; capabilities?: never };
35
+
36
+ /**
37
+ * Parameters accepted by the experimental `requestQuoteV0` action.
38
+ */
39
+ export type RequestQuoteV0Params = Prettify<
40
+ {
41
+ fromToken: Address;
42
+ toToken: Address;
43
+ slippage?: bigint;
44
+ account?: AccountParam;
45
+ chainId?: number;
46
+ } & SwapAmountParams &
47
+ SwapChainParams &
48
+ SwapExecutionParams
31
49
  >;
32
50
 
33
51
  /** The modifiedRequest in client format: `account` instead of `from`, SDK capabilities. */
@@ -44,6 +62,9 @@ type ClientModifiedRequest = Prettify<
44
62
  }
45
63
  >;
46
64
 
65
+ /**
66
+ * Result returned by the experimental `requestQuoteV0` action.
67
+ */
47
68
  export type RequestQuoteV0Result =
48
69
  | Exclude<RequestQuoteV0Response, { type: "paymaster-permit" }>
49
70
  | (Omit<
@@ -61,13 +82,15 @@ export type RequestQuoteV0Result =
61
82
  * @param {RequestQuoteV0Params} params - Parameters for requesting a swap quote
62
83
  * @param {Address} params.fromToken - The address of the token to swap from
63
84
  * @param {Address} params.toToken - The address of the token to swap to
64
- * @param {Hex} [params.fromAmount] - The amount to swap from (mutually exclusive with minimumToAmount)
65
- * @param {Hex} [params.minimumToAmount] - The minimum amount to receive (mutually exclusive with fromAmount)
85
+ * @param {bigint} [params.fromAmount] - The amount to swap from (mutually exclusive with minimumToAmount)
86
+ * @param {bigint} [params.minimumToAmount] - The minimum amount to receive (mutually exclusive with fromAmount)
66
87
  * @param {AccountParam} [params.account] - The account to execute the swap from. Can be an address string or an object with an `address` property. Defaults to the client's account (signer address via EIP-7702).
67
- * @param {Hex} [params.slippage] - The maximum acceptable slippage percentage
88
+ * @param {number} [params.chainId] - The source chain ID. Defaults to the wallet client's chain.
89
+ * @param {number} [params.toChainId] - The destination chain ID for cross-chain swaps. Omit for same-chain swaps.
90
+ * @param {bigint} [params.slippage] - The maximum acceptable slippage in basis points.
68
91
  * @param {boolean} [params.returnRawCalls] - Whether to return raw calls for EOA wallets (defaults to false for smart wallets)
69
92
  * @param {object} [params.capabilities] - Optional capabilities to include with the request (only available when returnRawCalls is false)
70
- * @param {Array<{to: Address, data?: Hex, value?: Hex}>} [params.postCalls] - Optional calls to execute after the swap
93
+ * @param {Array<{ to: Address; data?: Hex; value?: bigint }>} [params.postCalls] - Optional calls to execute after the swap
71
94
  * @returns {Promise<RequestQuoteV0Result>} A Promise that resolves to either prepared calls or raw calls depending on returnRawCalls
72
95
  *
73
96
  * @example
@@ -77,6 +100,7 @@ export type RequestQuoteV0Result =
77
100
  * fromToken: "0xA0b86a33E6441e1d6a8E8C7a8E8E8E8E8E8E8E8E",
78
101
  * toToken: "0xB0b86a33E6441e1d6a8E8C7a8E8E8E8E8E8E8E8E",
79
102
  * fromAmount: 1000000000000000000n, // 1 ETH
103
+ * chainId: 42161, // Arbitrum
80
104
  * capabilities: {
81
105
  * paymaster: { policyId: "your-policy-id" }
82
106
  * }
@@ -87,6 +111,7 @@ export type RequestQuoteV0Result =
87
111
  * fromToken: "0xA0b86a33E6441e1d6a8E8C7a8E8E8E8E8E8E8E8E",
88
112
  * toToken: "0xB0b86a33E6441e1d6a8E8C7a8E8E8E8E8E8E8E8E",
89
113
  * fromAmount: 1000000000000000000n,
114
+ * chainId: 42161,
90
115
  * returnRawCalls: true
91
116
  * });
92
117
  * ```
@@ -5,6 +5,9 @@ import {
5
5
  } from "./actions/requestQuoteV0.js";
6
6
  import type { BaseWalletClient, InnerWalletApiClient } from "../types.js";
7
7
 
8
+ /**
9
+ * Experimental swap actions for wallet API clients.
10
+ */
8
11
  export type SwapActions = {
9
12
  requestQuoteV0: (
10
13
  params: RequestQuoteV0Params,
@@ -25,18 +25,24 @@ export type * from "../actions/signSignatureRequest.js";
25
25
  export { signSignatureRequest } from "../actions/signSignatureRequest.js";
26
26
  export type * from "../actions/signTypedData.js";
27
27
  export { signTypedData } from "../actions/signTypedData.js";
28
+ export type * from "../actions/undelegateAccount.js";
29
+ export { undelegateAccount } from "../actions/undelegateAccount.js";
28
30
 
29
31
  // Decorators.
30
- export type * from "../decorators/smartWalletActions.js";
32
+ export type { SmartWalletActions } from "../decorators/smartWalletActions.js";
31
33
  export { smartWalletActions } from "../decorators/smartWalletActions.js";
32
34
 
33
35
  // Client.
34
36
  export type {
35
- BaseWalletClient,
36
- SignerClient,
37
37
  SmartWalletClient,
38
+ SolanaSmartWalletClient,
39
+ SolanaSigner,
38
40
  } from "../types.js";
39
- export type * from "../client.js";
41
+ export type {
42
+ CreateEvmSmartWalletClientParams,
43
+ CreateSolanaSmartWalletClientParams,
44
+ CreateSmartWalletClientParams,
45
+ } from "../client.js";
40
46
  export { createSmartWalletClient } from "../client.js";
41
47
 
42
48
  // Transport.
@@ -0,0 +1,36 @@
1
+ // Actions.
2
+ export type * from "../actions/solana/prepareCalls.js";
3
+ export { prepareCalls } from "../actions/solana/prepareCalls.js";
4
+ export type * from "../actions/solana/signPreparedCalls.js";
5
+ export { signPreparedCalls } from "../actions/solana/signPreparedCalls.js";
6
+ export type * from "../actions/solana/sendPreparedCalls.js";
7
+ export { sendPreparedCalls } from "../actions/solana/sendPreparedCalls.js";
8
+ export type * from "../actions/solana/sendCalls.js";
9
+ export { sendCalls } from "../actions/solana/sendCalls.js";
10
+ export type * from "../actions/solana/getCallsStatus.js";
11
+ export { getCallsStatus } from "../actions/solana/getCallsStatus.js";
12
+ export type * from "../actions/solana/waitForCallsStatus.js";
13
+ export { waitForCallsStatus } from "../actions/solana/waitForCallsStatus.js";
14
+
15
+ // Decorator.
16
+ export type { SolanaSmartWalletActions } from "../decorators/solanaSmartWalletActions.js";
17
+ export { solanaSmartWalletActions } from "../decorators/solanaSmartWalletActions.js";
18
+
19
+ // Errors.
20
+ export { SolanaSignerError } from "../adapters/SolanaSignerError.js";
21
+
22
+ // Adapters.
23
+ export { fromKeypair } from "../adapters/fromKeypair.js";
24
+ export type { SolanaKeypairSigner } from "../adapters/fromKeypair.js";
25
+ export { fromKitSigner } from "../adapters/fromKitSigner.js";
26
+ export type { SolanaTransactionPartialSigner } from "../adapters/fromKitSigner.js";
27
+ export { fromWalletAdapter } from "../adapters/fromWalletAdapter.js";
28
+ export type { WalletAdapterSigner } from "../adapters/fromWalletAdapter.js";
29
+ export { fromWalletStandard } from "../adapters/fromWalletStandard.js";
30
+ export type {
31
+ WalletStandardWallet,
32
+ WalletStandardAccount,
33
+ } from "../adapters/fromWalletStandard.js";
34
+
35
+ // Types.
36
+ export type { SolanaSigner, SolanaSmartWalletClient } from "../types.js";