@coinbase/cdp-sdk 1.29.0 → 1.31.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.
Files changed (198) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/_cjs/accounts/evm/networkCapabilities.js +101 -0
  3. package/_cjs/accounts/evm/networkCapabilities.js.map +1 -1
  4. package/_cjs/accounts/evm/toEvmServerAccount.js +11 -0
  5. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  6. package/_cjs/accounts/evm/toEvmSmartAccount.js +11 -0
  7. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  8. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +10 -0
  9. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
  10. package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +10 -0
  11. package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
  12. package/_cjs/accounts/solana/toSolanaAccount.js +11 -1
  13. package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
  14. package/_cjs/actions/evm/getUserOperation.js +1 -0
  15. package/_cjs/actions/evm/getUserOperation.js.map +1 -1
  16. package/_cjs/actions/evm/spend-permissions/account.use.js +33 -0
  17. package/_cjs/actions/evm/spend-permissions/account.use.js.map +1 -0
  18. package/_cjs/actions/evm/spend-permissions/smartAccount.use.js +35 -0
  19. package/_cjs/actions/evm/spend-permissions/smartAccount.use.js.map +1 -0
  20. package/_cjs/actions/evm/spend-permissions/types.js +3 -0
  21. package/_cjs/actions/evm/spend-permissions/types.js.map +1 -0
  22. package/_cjs/actions/solana/sendTransaction.js +1 -0
  23. package/_cjs/actions/solana/sendTransaction.js.map +1 -1
  24. package/_cjs/actions/solana/signTransaction.js +1 -0
  25. package/_cjs/actions/solana/signTransaction.js.map +1 -1
  26. package/_cjs/auth/hooks/axios/withAuth.js +3 -0
  27. package/_cjs/auth/hooks/axios/withAuth.js.map +1 -1
  28. package/_cjs/auth/utils/http.js +2 -1
  29. package/_cjs/auth/utils/http.js.map +1 -1
  30. package/_cjs/client/evm/evm.js +51 -1
  31. package/_cjs/client/evm/evm.js.map +1 -1
  32. package/_cjs/client/solana/solana.js.map +1 -1
  33. package/_cjs/index.js +5 -1
  34. package/_cjs/index.js.map +1 -1
  35. package/_cjs/openapi-client/cdpApiClient.js +37 -0
  36. package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
  37. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +29 -2
  38. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  39. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +35 -1
  40. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
  41. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +160 -1
  42. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  43. package/_cjs/openapi-client/generated/index.msw.js +1 -0
  44. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  45. package/_cjs/openapi-client/generated/onramp/onramp.js +30 -0
  46. package/_cjs/openapi-client/generated/onramp/onramp.js.map +1 -0
  47. package/_cjs/openapi-client/generated/onramp/onramp.msw.js +98 -0
  48. package/_cjs/openapi-client/generated/onramp/onramp.msw.js.map +1 -0
  49. package/_cjs/openapi-client/index.js +1 -0
  50. package/_cjs/openapi-client/index.js.map +1 -1
  51. package/_cjs/spend-permissions/constants.js +716 -0
  52. package/_cjs/spend-permissions/constants.js.map +1 -0
  53. package/_cjs/spend-permissions/types.js +3 -0
  54. package/_cjs/spend-permissions/types.js.map +1 -0
  55. package/_cjs/version.js +1 -1
  56. package/_esm/accounts/evm/networkCapabilities.js +101 -0
  57. package/_esm/accounts/evm/networkCapabilities.js.map +1 -1
  58. package/_esm/accounts/evm/toEvmServerAccount.js +11 -0
  59. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  60. package/_esm/accounts/evm/toEvmSmartAccount.js +11 -0
  61. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  62. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +10 -0
  63. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
  64. package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +10 -0
  65. package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
  66. package/_esm/accounts/solana/toSolanaAccount.js +11 -1
  67. package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
  68. package/_esm/actions/evm/getUserOperation.js +1 -0
  69. package/_esm/actions/evm/getUserOperation.js.map +1 -1
  70. package/_esm/actions/evm/spend-permissions/account.use.js +30 -0
  71. package/_esm/actions/evm/spend-permissions/account.use.js.map +1 -0
  72. package/_esm/actions/evm/spend-permissions/smartAccount.use.js +32 -0
  73. package/_esm/actions/evm/spend-permissions/smartAccount.use.js.map +1 -0
  74. package/_esm/actions/evm/spend-permissions/types.js +2 -0
  75. package/_esm/actions/evm/spend-permissions/types.js.map +1 -0
  76. package/_esm/actions/solana/sendTransaction.js +1 -0
  77. package/_esm/actions/solana/sendTransaction.js.map +1 -1
  78. package/_esm/actions/solana/signTransaction.js +1 -0
  79. package/_esm/actions/solana/signTransaction.js.map +1 -1
  80. package/_esm/auth/hooks/axios/withAuth.js +3 -0
  81. package/_esm/auth/hooks/axios/withAuth.js.map +1 -1
  82. package/_esm/auth/utils/http.js +2 -1
  83. package/_esm/auth/utils/http.js.map +1 -1
  84. package/_esm/client/evm/evm.js +51 -1
  85. package/_esm/client/evm/evm.js.map +1 -1
  86. package/_esm/client/solana/solana.js +2 -2
  87. package/_esm/client/solana/solana.js.map +1 -1
  88. package/_esm/index.js +2 -1
  89. package/_esm/index.js.map +1 -1
  90. package/_esm/openapi-client/cdpApiClient.js +4 -0
  91. package/_esm/openapi-client/cdpApiClient.js.map +1 -1
  92. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +28 -1
  93. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  94. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +31 -0
  95. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
  96. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +153 -0
  97. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  98. package/_esm/openapi-client/generated/index.msw.js +1 -0
  99. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  100. package/_esm/openapi-client/generated/onramp/onramp.js +25 -0
  101. package/_esm/openapi-client/generated/onramp/onramp.js.map +1 -0
  102. package/_esm/openapi-client/generated/onramp/onramp.msw.js +90 -0
  103. package/_esm/openapi-client/generated/onramp/onramp.msw.js.map +1 -0
  104. package/_esm/openapi-client/index.js +1 -0
  105. package/_esm/openapi-client/index.js.map +1 -1
  106. package/_esm/spend-permissions/constants.js +713 -0
  107. package/_esm/spend-permissions/constants.js.map +1 -0
  108. package/_esm/spend-permissions/types.js +2 -0
  109. package/_esm/spend-permissions/types.js.map +1 -0
  110. package/_esm/version.js +1 -1
  111. package/_types/accounts/evm/networkCapabilities.d.ts +101 -0
  112. package/_types/accounts/evm/networkCapabilities.d.ts.map +1 -1
  113. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  114. package/_types/accounts/evm/toEvmSmartAccount.d.ts +1 -1
  115. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
  116. package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
  117. package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
  118. package/_types/accounts/evm/types.d.ts +6 -0
  119. package/_types/accounts/evm/types.d.ts.map +1 -1
  120. package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
  121. package/_types/actions/evm/getUserOperation.d.ts.map +1 -1
  122. package/_types/actions/evm/spend-permissions/account.use.d.ts +15 -0
  123. package/_types/actions/evm/spend-permissions/account.use.d.ts.map +1 -0
  124. package/_types/actions/evm/spend-permissions/smartAccount.use.d.ts +15 -0
  125. package/_types/actions/evm/spend-permissions/smartAccount.use.d.ts.map +1 -0
  126. package/_types/actions/evm/spend-permissions/types.d.ts +13 -0
  127. package/_types/actions/evm/spend-permissions/types.d.ts.map +1 -0
  128. package/_types/actions/evm/types.d.ts +75 -0
  129. package/_types/actions/evm/types.d.ts.map +1 -1
  130. package/_types/actions/solana/sendTransaction.d.ts +8 -2
  131. package/_types/actions/solana/sendTransaction.d.ts.map +1 -1
  132. package/_types/actions/solana/signTransaction.d.ts +8 -2
  133. package/_types/actions/solana/signTransaction.d.ts.map +1 -1
  134. package/_types/actions/solana/types.d.ts +38 -3
  135. package/_types/actions/solana/types.d.ts.map +1 -1
  136. package/_types/auth/hooks/axios/withAuth.d.ts.map +1 -1
  137. package/_types/auth/utils/http.d.ts.map +1 -1
  138. package/_types/client/evm/evm.d.ts +19 -1
  139. package/_types/client/evm/evm.d.ts.map +1 -1
  140. package/_types/client/evm/evm.types.d.ts +49 -2
  141. package/_types/client/evm/evm.types.d.ts.map +1 -1
  142. package/_types/client/solana/solana.d.ts +5 -3
  143. package/_types/client/solana/solana.d.ts.map +1 -1
  144. package/_types/index.d.ts +3 -1
  145. package/_types/index.d.ts.map +1 -1
  146. package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
  147. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +269 -5
  148. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  149. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +19 -1
  150. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
  151. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +7 -1
  152. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -1
  153. package/_types/openapi-client/generated/index.msw.d.ts +1 -0
  154. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  155. package/_types/openapi-client/generated/onramp/onramp.d.ts +28 -0
  156. package/_types/openapi-client/generated/onramp/onramp.d.ts.map +1 -0
  157. package/_types/openapi-client/generated/onramp/onramp.msw.d.ts +8 -0
  158. package/_types/openapi-client/generated/onramp/onramp.msw.d.ts.map +1 -0
  159. package/_types/openapi-client/index.d.ts +7 -0
  160. package/_types/openapi-client/index.d.ts.map +1 -1
  161. package/_types/spend-permissions/constants.d.ts +1357 -0
  162. package/_types/spend-permissions/constants.d.ts.map +1 -0
  163. package/_types/spend-permissions/types.d.ts +30 -0
  164. package/_types/spend-permissions/types.d.ts.map +1 -0
  165. package/_types/version.d.ts +1 -1
  166. package/accounts/evm/networkCapabilities.ts +101 -0
  167. package/accounts/evm/toEvmServerAccount.ts +15 -0
  168. package/accounts/evm/toEvmSmartAccount.ts +19 -4
  169. package/accounts/evm/toNetworkScopedEvmServerAccount.ts +15 -0
  170. package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +15 -0
  171. package/accounts/evm/types.ts +18 -0
  172. package/accounts/solana/toSolanaAccount.ts +17 -3
  173. package/actions/evm/getUserOperation.ts +1 -0
  174. package/actions/evm/spend-permissions/account.use.ts +48 -0
  175. package/actions/evm/spend-permissions/smartAccount.use.ts +49 -0
  176. package/actions/evm/spend-permissions/types.ts +13 -0
  177. package/actions/evm/types.ts +81 -0
  178. package/actions/solana/sendTransaction.ts +10 -2
  179. package/actions/solana/signTransaction.ts +10 -2
  180. package/actions/solana/types.ts +44 -2
  181. package/auth/hooks/axios/withAuth.ts +3 -0
  182. package/auth/utils/http.ts +2 -1
  183. package/client/evm/evm.ts +61 -1
  184. package/client/evm/evm.types.ts +55 -0
  185. package/client/solana/solana.ts +10 -5
  186. package/index.ts +6 -1
  187. package/openapi-client/cdpApiClient.ts +5 -0
  188. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +300 -5
  189. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +203 -0
  190. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +65 -0
  191. package/openapi-client/generated/index.msw.ts +1 -0
  192. package/openapi-client/generated/onramp/onramp.msw.ts +135 -0
  193. package/openapi-client/generated/onramp/onramp.ts +54 -0
  194. package/openapi-client/index.ts +1 -0
  195. package/package.json +2 -1
  196. package/spend-permissions/constants.ts +713 -0
  197. package/spend-permissions/types.ts +42 -0
  198. package/version.ts +1 -1
@@ -1,6 +1,13 @@
1
- import { SendTransactionOptions, TransactionResult } from "../../client/solana/solana.types.js";
1
+ import { SendTransactionOptions } from "../../client/solana/solana.types.js";
2
2
  import { CdpOpenApiClientType } from "../../openapi-client/index.js";
3
3
 
4
+ export interface SendTransactionResult {
5
+ /** The signature of the transaction base58 encoded. */
6
+ transactionSignature: string;
7
+ /** @deprecated Use transactionSignature instead. */
8
+ signature: string;
9
+ }
10
+
4
11
  /**
5
12
  * Sends a Solana transaction using the Coinbase API.
6
13
  *
@@ -23,7 +30,7 @@ import { CdpOpenApiClientType } from "../../openapi-client/index.js";
23
30
  export async function sendTransaction(
24
31
  apiClient: CdpOpenApiClientType,
25
32
  options: SendTransactionOptions,
26
- ): Promise<TransactionResult> {
33
+ ): Promise<SendTransactionResult> {
27
34
  const signature = await apiClient.sendSolanaTransaction(
28
35
  {
29
36
  network: options.network,
@@ -33,6 +40,7 @@ export async function sendTransaction(
33
40
  );
34
41
 
35
42
  return {
43
+ transactionSignature: signature.transactionSignature,
36
44
  signature: signature.transactionSignature,
37
45
  };
38
46
  }
@@ -1,6 +1,13 @@
1
- import { SignTransactionOptions, SignatureResult } from "../../client/solana/solana.types.js";
1
+ import { SignTransactionOptions } from "../../client/solana/solana.types.js";
2
2
  import { CdpOpenApiClientType } from "../../openapi-client/index.js";
3
3
 
4
+ export interface SignTransactionResult {
5
+ /** The signature of the transaction base58 encoded. */
6
+ signedTransaction: string;
7
+ /** @deprecated Use signedTransaction instead. */
8
+ signature: string;
9
+ }
10
+
4
11
  /**
5
12
  * Signs a transaction.
6
13
  *
@@ -38,7 +45,7 @@ import { CdpOpenApiClientType } from "../../openapi-client/index.js";
38
45
  export async function signTransaction(
39
46
  apiClient: CdpOpenApiClientType,
40
47
  options: SignTransactionOptions,
41
- ): Promise<SignatureResult> {
48
+ ): Promise<SignTransactionResult> {
42
49
  const signature = await apiClient.signSolanaTransaction(
43
50
  options.address,
44
51
  {
@@ -48,6 +55,7 @@ export async function signTransaction(
48
55
  );
49
56
 
50
57
  return {
58
+ signedTransaction: signature.signedTransaction,
51
59
  signature: signature.signedTransaction,
52
60
  };
53
61
  }
@@ -1,6 +1,7 @@
1
1
  import { TransferOptions } from "./transfer.js";
2
2
  import {
3
3
  RequestFaucetOptions,
4
+ SendTransactionOptions,
4
5
  SignatureResult,
5
6
  SignMessageOptions,
6
7
  SignTransactionOptions,
@@ -13,6 +14,9 @@ import {
13
14
  } from "../waitForFundOperationReceipt.js";
14
15
  import { SolanaFundOptions } from "./fund/fund.js";
15
16
  import { SolanaQuoteFundOptions } from "./fund/quoteFund.js";
17
+ import { SendTransactionResult } from "./sendTransaction.js";
18
+
19
+ import type { SignTransactionResult } from "./signTransaction.js";
16
20
 
17
21
  export type AccountActions = {
18
22
  /**
@@ -87,12 +91,50 @@ export type AccountActions = {
87
91
  * const transaction = Buffer.from(serializedTransaction).toString("base64");
88
92
  *
89
93
  * // When you want to sign a transaction, you can do so by address and base64 encoded transaction
90
- * const { signature } = await account.signTransaction({
94
+ * const { signedTransaction } = await account.signTransaction({
95
+ * transaction,
96
+ * });
97
+ * ```
98
+ */
99
+ signTransaction: (
100
+ options: Omit<SignTransactionOptions, "address">,
101
+ ) => Promise<SignTransactionResult>;
102
+
103
+ /**
104
+ * Sends a transaction.
105
+ *
106
+ * @param {SendTransactionOptions} options - Parameters for sending the transaction.
107
+ * @param {string} options.address - The address to send the transaction for.
108
+ * @param {string} options.transaction - The transaction to send.
109
+ * @param {string} [options.idempotencyKey] - An idempotency key.
110
+ *
111
+ * @returns A promise that resolves to the transaction signature.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * // Create a Solana account
116
+ * const account = await cdp.solana.createAccount();
117
+ *
118
+ * // Add your transaction instructions here
119
+ * const transaction = new Transaction()
120
+ *
121
+ * // Make sure to set requireAllSignatures to false, since signing will be done through the API
122
+ * const serializedTransaction = transaction.serialize({
123
+ * requireAllSignatures: false,
124
+ * });
125
+ *
126
+ * // Base64 encode the serialized transaction
127
+ * const transaction = Buffer.from(serializedTransaction).toString("base64");
128
+ *
129
+ * // When you want to sign a transaction, you can do so by address and base64 encoded transaction
130
+ * const { transactionSignature } = await account.sendTransaction({
91
131
  * transaction,
92
132
  * });
93
133
  * ```
94
134
  */
95
- signTransaction: (options: Omit<SignTransactionOptions, "address">) => Promise<SignatureResult>;
135
+ sendTransaction: (
136
+ options: Omit<SendTransactionOptions, "address">,
137
+ ) => Promise<SendTransactionResult>;
96
138
 
97
139
  /**
98
140
  * Transfers SOL or SPL tokens between accounts
@@ -84,6 +84,7 @@ export function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOpt
84
84
  });
85
85
 
86
86
  if (options.debug) {
87
+ // eslint-disable-next-line no-console
87
88
  console.log("Request:", {
88
89
  method,
89
90
  url: fullyQualifiedURL,
@@ -98,6 +99,7 @@ export function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOpt
98
99
  if (options.debug) {
99
100
  axiosClient.interceptors.response.use(
100
101
  response => {
102
+ // eslint-disable-next-line no-console
101
103
  console.log("Response:", {
102
104
  status: response.status,
103
105
  statusText: response.statusText,
@@ -117,6 +119,7 @@ export function withAuth(axiosClient: AxiosInstance, options: AuthInterceptorOpt
117
119
  cause: error.cause,
118
120
  };
119
121
 
122
+ // eslint-disable-next-line no-console
120
123
  console.error("Response Error:", errorDetails);
121
124
  return Promise.reject(error);
122
125
  },
@@ -126,7 +126,8 @@ export async function getAuthHeaders(
126
126
  */
127
127
  function requiresWalletAuth(requestMethod: string, requestPath: string): boolean {
128
128
  return (
129
- requestPath?.includes("/accounts") && (requestMethod === "POST" || requestMethod === "DELETE")
129
+ (requestPath?.includes("/accounts") || requestPath?.includes("/spend-permissions")) &&
130
+ (requestMethod === "POST" || requestMethod === "DELETE" || requestMethod === "PUT")
130
131
  );
131
132
  }
132
133
 
package/client/evm/evm.ts CHANGED
@@ -5,6 +5,7 @@ import { type Address, getTypesForEIP712Domain } from "viem";
5
5
  import {
6
6
  CreateServerAccountOptions,
7
7
  CreateSmartAccountOptions,
8
+ CreateSpendPermissionOptions,
8
9
  CreateSwapQuoteOptions,
9
10
  CreateSwapQuoteResult,
10
11
  EvmClientInterface,
@@ -68,6 +69,7 @@ import {
68
69
  CdpOpenApiClient,
69
70
  EIP712Message as OpenAPIEIP712Message,
70
71
  } from "../../openapi-client/index.js";
72
+ import { SPEND_PERMISSION_MANAGER_ADDRESS } from "../../spend-permissions/constants.js";
71
73
  import { Hex } from "../../types/misc.js";
72
74
  import { decryptWithPrivateKey, generateExportEncryptionKeyPair } from "../../utils/export.js";
73
75
 
@@ -341,9 +343,15 @@ export class EvmClient implements EvmClientInterface {
341
343
  accountType: "evm_smart",
342
344
  });
343
345
 
346
+ const owners = [options.owner.address];
347
+
348
+ if (options.__experimental_enableSpendPermission) {
349
+ owners.push(SPEND_PERMISSION_MANAGER_ADDRESS);
350
+ }
351
+
344
352
  const openApiSmartAccount = await CdpOpenApiClient.createEvmSmartAccount(
345
353
  {
346
- owners: [options.owner.address],
354
+ owners: owners,
347
355
  name: options.name,
348
356
  },
349
357
  options.idempotencyKey,
@@ -359,6 +367,58 @@ export class EvmClient implements EvmClientInterface {
359
367
  return smartAccount;
360
368
  }
361
369
 
370
+ /**
371
+ * Creates a spend permission for a smart account.
372
+ *
373
+ * @param {CreateSpendPermissionOptions} options - Parameters for creating the spend permission.
374
+ * @param {SpendPermission} options.spendPermission - The spend permission to create.
375
+ * @param {string} [options.idempotencyKey] - The idempotency key to use for the spend permission.
376
+ *
377
+ * @returns A promise that resolves to the spend permission.
378
+ *
379
+ * @example
380
+ * ```ts
381
+ * const userOperation = await cdp.evm.createSpendPermission({
382
+ * spendPermission,
383
+ * network: "base-sepolia",
384
+ * });
385
+ * ```
386
+ */
387
+ async createSpendPermission(options: CreateSpendPermissionOptions): Promise<UserOperation> {
388
+ Analytics.trackAction({
389
+ action: "create_spend_permission",
390
+ });
391
+
392
+ const userOperation = await CdpOpenApiClient.createSpendPermission(
393
+ options.spendPermission.account,
394
+ {
395
+ account: options.spendPermission.account,
396
+ spender: options.spendPermission.spender,
397
+ token: options.spendPermission.token,
398
+ allowance: options.spendPermission.allowance.toString(),
399
+ period: options.spendPermission.period.toString(),
400
+ start: options.spendPermission.start.toString(),
401
+ end: options.spendPermission.end.toString(),
402
+ salt: options.spendPermission.salt.toString(),
403
+ extraData: options.spendPermission.extraData,
404
+ network: options.network,
405
+ paymasterUrl: options.paymasterUrl,
406
+ },
407
+ options.idempotencyKey,
408
+ );
409
+
410
+ return {
411
+ network: userOperation.network,
412
+ userOpHash: userOperation.userOpHash as Hex,
413
+ status: userOperation.status,
414
+ calls: userOperation.calls.map(call => ({
415
+ to: call.to as Address,
416
+ value: BigInt(call.value),
417
+ data: call.data as Hex,
418
+ })),
419
+ };
420
+ }
421
+
362
422
  /**
363
423
  * Gets a CDP EVM account.
364
424
  *
@@ -1,3 +1,5 @@
1
+ import { SpendPermission } from "../../spend-permissions/types.js";
2
+
1
3
  import type {
2
4
  EvmAccount as Account,
3
5
  EvmServerAccount as ServerAccount,
@@ -24,6 +26,7 @@ import type {
24
26
  OpenApiEvmMethods,
25
27
  UpdateEvmAccountBody as UpdateEvmAccount,
26
28
  UpdateEvmSmartAccountBody as UpdateEvmSmartAccount,
29
+ UserOperationReceipt,
27
30
  } from "../../openapi-client/index.js";
28
31
  import type { Calls } from "../../types/calls.js";
29
32
  import type { Address, EIP712Message, Hex } from "../../types/misc.js";
@@ -36,6 +39,9 @@ export type EvmClientInterface = Omit<
36
39
  typeof OpenApiEvmMethods,
37
40
  | "createEvmAccount" // mapped to createAccount
38
41
  | "createEvmSmartAccount" // mapped to createSmartAccount
42
+ | "createSpendPermission" // mapped to createSpendPermission
43
+ | "listSpendPermissions" // mapped to listSpendPermissions
44
+ | "revokeSpendPermission" // mapped to revokeSpendPermission
39
45
  | "importEvmAccount" // mapped to importAccount
40
46
  | "exportEvmAccount" // mapped to exportAccount
41
47
  | "exportEvmAccountByName" // mapped to exportAccount
@@ -256,6 +262,39 @@ export interface CreateSwapQuoteResult {
256
262
  execute: (options?: ExecuteSwapQuoteOptions) => Promise<ExecuteSwapQuoteResult>;
257
263
  }
258
264
 
265
+ export interface CreateSpendPermissionOptions {
266
+ /** The spend permission. */
267
+ spendPermission: SpendPermission;
268
+ /** The network. */
269
+ network: EvmUserOperationNetwork;
270
+ /** The paymaster URL. */
271
+ paymasterUrl?: string;
272
+ /** The idempotency key. */
273
+ idempotencyKey?: string;
274
+ }
275
+
276
+ export interface ListSpendPermissionsOptions {
277
+ /** The address of the smart account. */
278
+ address: Address;
279
+ /** The page size to paginate through the spend permissions. */
280
+ pageSize?: number;
281
+ /** The page token to paginate through the spend permissions. */
282
+ pageToken?: string;
283
+ }
284
+
285
+ export interface RevokeSpendPermissionOptions {
286
+ /** The address of the smart account. */
287
+ address: Address;
288
+ /** The hash of the spend permission to revoke. */
289
+ permissionHash: Hex;
290
+ /** The network. */
291
+ network: EvmUserOperationNetwork;
292
+ /** The paymaster URL. */
293
+ paymasterUrl?: string;
294
+ /** The idempotency key. */
295
+ idempotencyKey?: string;
296
+ }
297
+
259
298
  /**
260
299
  * Options for getting a user operation.
261
300
  */
@@ -314,6 +353,10 @@ export interface UserOperation {
314
353
  * The hash of the transaction that included this particular user operation. This gets set after the user operation is broadcasted and the transaction is included in a block.
315
354
  */
316
355
  transactionHash?: Hex;
356
+ /**
357
+ * The receipts associated with the broadcasted user operation.
358
+ */
359
+ receipts?: UserOperationReceipt[];
317
360
  }
318
361
 
319
362
  /**
@@ -392,6 +435,12 @@ export interface GetOrCreateSmartAccountOptions {
392
435
  name: string;
393
436
  /** The owner of the account. */
394
437
  owner: Account;
438
+ /**
439
+ * @deprecated Experimental! This method name will change, and is subject to other breaking changes.
440
+ *
441
+ * The flag to enable spend permission.
442
+ */
443
+ __experimental_enableSpendPermission?: boolean;
395
444
  }
396
445
 
397
446
  /**
@@ -487,6 +536,12 @@ export interface CreateSmartAccountOptions {
487
536
  idempotencyKey?: string;
488
537
  /** The name of the account. */
489
538
  name?: string;
539
+ /**
540
+ * @deprecated Experimental! This method name will change, and is subject to other breaking changes.
541
+ *
542
+ * The flag to enable spend permission.
543
+ */
544
+ __experimental_enableSpendPermission?: boolean;
490
545
  }
491
546
 
492
547
  /**
@@ -18,15 +18,20 @@ import {
18
18
  SignMessageOptions,
19
19
  SignTransactionOptions,
20
20
  SolanaClientInterface,
21
- TransactionResult,
22
21
  UpdateSolanaAccountOptions,
23
22
  } from "./solana.types.js";
24
23
  import { toSolanaAccount } from "../../accounts/solana/toSolanaAccount.js";
25
24
  import { SolanaAccount } from "../../accounts/solana/types.js";
26
25
  import { requestFaucet } from "../../actions/solana/requestFaucet.js";
27
- import { sendTransaction } from "../../actions/solana/sendTransaction.js";
26
+ import {
27
+ sendTransaction,
28
+ type SendTransactionResult,
29
+ } from "../../actions/solana/sendTransaction.js";
28
30
  import { signMessage } from "../../actions/solana/signMessage.js";
29
- import { signTransaction } from "../../actions/solana/signTransaction.js";
31
+ import {
32
+ signTransaction,
33
+ type SignTransactionResult,
34
+ } from "../../actions/solana/signTransaction.js";
30
35
  import { Analytics } from "../../analytics.js";
31
36
  import { ImportAccountPublicRSAKey } from "../../constants.js";
32
37
  import { UserInputValidationError } from "../../errors.js";
@@ -485,7 +490,7 @@ export class SolanaClient implements SolanaClientInterface {
485
490
  * });
486
491
  * ```
487
492
  */
488
- async signTransaction(options: SignTransactionOptions): Promise<SignatureResult> {
493
+ async signTransaction(options: SignTransactionOptions): Promise<SignTransactionResult> {
489
494
  Analytics.trackAction({
490
495
  action: "sign_transaction",
491
496
  accountType: "solana",
@@ -574,7 +579,7 @@ export class SolanaClient implements SolanaClientInterface {
574
579
  * });
575
580
  * ```
576
581
  */
577
- async sendTransaction(options: SendTransactionOptions): Promise<TransactionResult> {
582
+ async sendTransaction(options: SendTransactionOptions): Promise<SendTransactionResult> {
578
583
  Analytics.trackAction({
579
584
  action: "send_transaction",
580
585
  accountType: "solana",
package/index.ts CHANGED
@@ -8,5 +8,10 @@ export {
8
8
  type UpdatePolicyBody,
9
9
  } from "./policies/schema.js";
10
10
  export { NetworkError } from "./openapi-client/errors.js";
11
+ export type { SpendPermission } from "./spend-permissions/types.js";
12
+ export {
13
+ SPEND_PERMISSION_MANAGER_ABI as spendPermissionManagerAbi,
14
+ SPEND_PERMISSION_MANAGER_ADDRESS as spendPermissionManagerAddress,
15
+ } from "./spend-permissions/constants.js";
11
16
 
12
- export { parseEther } from "viem";
17
+ export { parseEther, parseUnits } from "viem";
@@ -1,5 +1,6 @@
1
1
  // eslint-disable-next-line import/no-named-as-default
2
2
  import Axios, { AxiosInstance, AxiosRequestConfig } from "axios";
3
+ import axiosRetry, { exponentialDelay } from "axios-retry";
3
4
 
4
5
  import { withAuth } from "../auth/hooks/axios/index.js";
5
6
  import { ERROR_DOCS_PAGE_URL } from "../constants.js";
@@ -70,6 +71,10 @@ export const configure = (options: CdpOptions) => {
70
71
  baseURL,
71
72
  });
72
73
 
74
+ axiosRetry(axiosInstance, {
75
+ retryDelay: exponentialDelay,
76
+ });
77
+
73
78
  axiosInstance = withAuth(axiosInstance, {
74
79
  apiKeyId: options.apiKeyId,
75
80
  apiKeySecret: options.apiKeySecret,