@coinbase/cdp-sdk 1.10.0 → 1.12.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 (159) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +137 -0
  3. package/_cjs/accounts/evm/toEvmServerAccount.js +32 -0
  4. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  5. package/_cjs/accounts/evm/toEvmSmartAccount.js +18 -0
  6. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  7. package/_cjs/actions/evm/fund/Quote.js +63 -0
  8. package/_cjs/actions/evm/fund/Quote.js.map +1 -0
  9. package/_cjs/actions/evm/fund/fund.js +49 -0
  10. package/_cjs/actions/evm/fund/fund.js.map +1 -0
  11. package/_cjs/actions/evm/fund/quoteFund.js +46 -0
  12. package/_cjs/actions/evm/fund/quoteFund.js.map +1 -0
  13. package/_cjs/actions/evm/fund/types.js +3 -0
  14. package/_cjs/actions/evm/fund/types.js.map +1 -0
  15. package/_cjs/actions/evm/fund/waitForFundOperationReceipt.js +64 -0
  16. package/_cjs/actions/evm/fund/waitForFundOperationReceipt.js.map +1 -0
  17. package/_cjs/actions/evm/swap/createSwapQuote.js +126 -0
  18. package/_cjs/actions/evm/swap/createSwapQuote.js.map +1 -0
  19. package/_cjs/actions/evm/swap/getSwapPrice.js +86 -0
  20. package/_cjs/actions/evm/swap/getSwapPrice.js.map +1 -0
  21. package/_cjs/actions/evm/swap/sendSwapTransaction.js +141 -0
  22. package/_cjs/actions/evm/swap/sendSwapTransaction.js.map +1 -0
  23. package/_cjs/actions/evm/swap/types.js +3 -0
  24. package/_cjs/actions/evm/swap/types.js.map +1 -0
  25. package/_cjs/client/evm/evm.js +47 -1
  26. package/_cjs/client/evm/evm.js.map +1 -1
  27. package/_cjs/client/solana/solana.js +4 -1
  28. package/_cjs/client/solana/solana.js.map +1 -1
  29. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +45 -1
  30. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  31. package/_cjs/openapi-client/generated/evm-swaps/evm-swaps.js +26 -0
  32. package/_cjs/openapi-client/generated/evm-swaps/evm-swaps.js.map +1 -0
  33. package/_cjs/openapi-client/generated/evm-swaps/evm-swaps.msw.js +179 -0
  34. package/_cjs/openapi-client/generated/evm-swaps/evm-swaps.msw.js.map +1 -0
  35. package/_cjs/openapi-client/generated/index.msw.js +5 -3
  36. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  37. package/_cjs/openapi-client/generated/payments-alpha/payments-alpha.js +50 -0
  38. package/_cjs/openapi-client/generated/payments-alpha/payments-alpha.js.map +1 -0
  39. package/_cjs/openapi-client/generated/payments-alpha/payments-alpha.msw.js +270 -0
  40. package/_cjs/openapi-client/generated/payments-alpha/payments-alpha.msw.js.map +1 -0
  41. package/_cjs/openapi-client/index.js +7 -0
  42. package/_cjs/openapi-client/index.js.map +1 -1
  43. package/_cjs/version.js +1 -1
  44. package/_esm/accounts/evm/toEvmServerAccount.js +32 -0
  45. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  46. package/_esm/accounts/evm/toEvmSmartAccount.js +18 -0
  47. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  48. package/_esm/actions/evm/fund/Quote.js +59 -0
  49. package/_esm/actions/evm/fund/Quote.js.map +1 -0
  50. package/_esm/actions/evm/fund/fund.js +46 -0
  51. package/_esm/actions/evm/fund/fund.js.map +1 -0
  52. package/_esm/actions/evm/fund/quoteFund.js +43 -0
  53. package/_esm/actions/evm/fund/quoteFund.js.map +1 -0
  54. package/_esm/actions/evm/fund/types.js +2 -0
  55. package/_esm/actions/evm/fund/types.js.map +1 -0
  56. package/_esm/actions/evm/fund/waitForFundOperationReceipt.js +61 -0
  57. package/_esm/actions/evm/fund/waitForFundOperationReceipt.js.map +1 -0
  58. package/_esm/actions/evm/swap/createSwapQuote.js +123 -0
  59. package/_esm/actions/evm/swap/createSwapQuote.js.map +1 -0
  60. package/_esm/actions/evm/swap/getSwapPrice.js +83 -0
  61. package/_esm/actions/evm/swap/getSwapPrice.js.map +1 -0
  62. package/_esm/actions/evm/swap/sendSwapTransaction.js +138 -0
  63. package/_esm/actions/evm/swap/sendSwapTransaction.js.map +1 -0
  64. package/_esm/actions/evm/swap/types.js +2 -0
  65. package/_esm/actions/evm/swap/types.js.map +1 -0
  66. package/_esm/client/evm/evm.js +47 -1
  67. package/_esm/client/evm/evm.js.map +1 -1
  68. package/_esm/client/solana/solana.js +4 -1
  69. package/_esm/client/solana/solana.js.map +1 -1
  70. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +44 -0
  71. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  72. package/_esm/openapi-client/generated/evm-swaps/evm-swaps.js +21 -0
  73. package/_esm/openapi-client/generated/evm-swaps/evm-swaps.js.map +1 -0
  74. package/_esm/openapi-client/generated/evm-swaps/evm-swaps.msw.js +167 -0
  75. package/_esm/openapi-client/generated/evm-swaps/evm-swaps.msw.js.map +1 -0
  76. package/_esm/openapi-client/generated/index.msw.js +5 -3
  77. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  78. package/_esm/openapi-client/generated/payments-alpha/payments-alpha.js +42 -0
  79. package/_esm/openapi-client/generated/payments-alpha/payments-alpha.js.map +1 -0
  80. package/_esm/openapi-client/generated/payments-alpha/payments-alpha.msw.js +250 -0
  81. package/_esm/openapi-client/generated/payments-alpha/payments-alpha.msw.js.map +1 -0
  82. package/_esm/openapi-client/index.js +7 -0
  83. package/_esm/openapi-client/index.js.map +1 -1
  84. package/_esm/version.js +1 -1
  85. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  86. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
  87. package/_types/accounts/evm/types.d.ts +1 -2
  88. package/_types/accounts/evm/types.d.ts.map +1 -1
  89. package/_types/actions/evm/fund/Quote.d.ts +51 -0
  90. package/_types/actions/evm/fund/Quote.d.ts.map +1 -0
  91. package/_types/actions/evm/fund/fund.d.ts +25 -0
  92. package/_types/actions/evm/fund/fund.d.ts.map +1 -0
  93. package/_types/actions/evm/fund/quoteFund.d.ts +25 -0
  94. package/_types/actions/evm/fund/quoteFund.d.ts.map +1 -0
  95. package/_types/actions/evm/fund/types.d.ts +16 -0
  96. package/_types/actions/evm/fund/types.d.ts.map +1 -0
  97. package/_types/actions/evm/fund/waitForFundOperationReceipt.d.ts +68 -0
  98. package/_types/actions/evm/fund/waitForFundOperationReceipt.d.ts.map +1 -0
  99. package/_types/actions/evm/swap/createSwapQuote.d.ts +23 -0
  100. package/_types/actions/evm/swap/createSwapQuote.d.ts.map +1 -0
  101. package/_types/actions/evm/swap/getSwapPrice.d.ts +23 -0
  102. package/_types/actions/evm/swap/getSwapPrice.d.ts.map +1 -0
  103. package/_types/actions/evm/swap/sendSwapTransaction.d.ts +64 -0
  104. package/_types/actions/evm/swap/sendSwapTransaction.d.ts.map +1 -0
  105. package/_types/actions/evm/swap/types.d.ts +80 -0
  106. package/_types/actions/evm/swap/types.d.ts.map +1 -0
  107. package/_types/actions/evm/types.d.ts +151 -0
  108. package/_types/actions/evm/types.d.ts.map +1 -1
  109. package/_types/client/evm/evm.d.ts +39 -1
  110. package/_types/client/evm/evm.d.ts.map +1 -1
  111. package/_types/client/evm/evm.types.d.ts +209 -3
  112. package/_types/client/evm/evm.types.d.ts.map +1 -1
  113. package/_types/client/solana/solana.d.ts.map +1 -1
  114. package/_types/client/solana/solana.types.d.ts +2 -0
  115. package/_types/client/solana/solana.types.d.ts.map +1 -1
  116. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +547 -3
  117. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  118. package/_types/openapi-client/generated/evm-swaps/evm-swaps.d.ts +24 -0
  119. package/_types/openapi-client/generated/evm-swaps/evm-swaps.d.ts.map +1 -0
  120. package/_types/openapi-client/generated/evm-swaps/evm-swaps.msw.d.ts +12 -0
  121. package/_types/openapi-client/generated/evm-swaps/evm-swaps.msw.d.ts.map +1 -0
  122. package/_types/openapi-client/generated/index.msw.d.ts +5 -3
  123. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  124. package/_types/openapi-client/generated/payments-alpha/payments-alpha.d.ts +42 -0
  125. package/_types/openapi-client/generated/payments-alpha/payments-alpha.d.ts.map +1 -0
  126. package/_types/openapi-client/generated/payments-alpha/payments-alpha.msw.d.ts +20 -0
  127. package/_types/openapi-client/generated/payments-alpha/payments-alpha.msw.d.ts.map +1 -0
  128. package/_types/openapi-client/index.d.ts +11 -0
  129. package/_types/openapi-client/index.d.ts.map +1 -1
  130. package/_types/types/misc.d.ts +2 -2
  131. package/_types/types/misc.d.ts.map +1 -1
  132. package/_types/version.d.ts +1 -1
  133. package/accounts/evm/toEvmServerAccount.ts +47 -0
  134. package/accounts/evm/toEvmSmartAccount.ts +26 -0
  135. package/accounts/evm/types.ts +1 -2
  136. package/actions/evm/fund/Quote.ts +83 -0
  137. package/actions/evm/fund/fund.ts +76 -0
  138. package/actions/evm/fund/quoteFund.ts +81 -0
  139. package/actions/evm/fund/types.ts +16 -0
  140. package/actions/evm/fund/waitForFundOperationReceipt.ts +118 -0
  141. package/actions/evm/swap/createSwapQuote.ts +148 -0
  142. package/actions/evm/swap/getSwapPrice.ts +95 -0
  143. package/actions/evm/swap/sendSwapTransaction.ts +173 -0
  144. package/actions/evm/swap/types.ts +94 -0
  145. package/actions/evm/types.ts +161 -0
  146. package/client/evm/evm.ts +59 -1
  147. package/client/evm/evm.types.ts +227 -1
  148. package/client/solana/solana.ts +4 -1
  149. package/client/solana/solana.types.ts +2 -0
  150. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +617 -3
  151. package/openapi-client/generated/evm-swaps/evm-swaps.msw.ts +217 -0
  152. package/openapi-client/generated/evm-swaps/evm-swaps.ts +51 -0
  153. package/openapi-client/generated/index.msw.ts +5 -3
  154. package/openapi-client/generated/payments-alpha/payments-alpha.msw.ts +369 -0
  155. package/openapi-client/generated/payments-alpha/payments-alpha.ts +96 -0
  156. package/openapi-client/index.ts +7 -0
  157. package/package.json +1 -1
  158. package/types/misc.ts +2 -2
  159. package/version.ts +1 -1
@@ -1,3 +1,11 @@
1
+ import { FundOptions } from "./fund/fund.js";
2
+ import { Quote } from "./fund/Quote.js";
3
+ import { QuoteFundOptions } from "./fund/quoteFund.js";
4
+ import { FundOperationResult } from "./fund/types.js";
5
+ import {
6
+ WaitForFundOperationOptions,
7
+ WaitForFundOperationResult,
8
+ } from "./fund/waitForFundOperationReceipt.js";
1
9
  import { SendUserOperationOptions, SendUserOperationReturnType } from "./sendUserOperation.js";
2
10
  import { GetUserOperationOptions, UserOperation } from "../../client/evm/evm.types.js";
3
11
  import { Hex } from "../../types/misc.js";
@@ -5,6 +13,7 @@ import { Hex } from "../../types/misc.js";
5
13
  import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "./listTokenBalances.js";
6
14
  import type { RequestFaucetOptions, RequestFaucetResult } from "./requestFaucet.js";
7
15
  import type { SendTransactionOptions, TransactionResult } from "./sendTransaction.js";
16
+ import type { SwapOptions, SwapResult, QuoteSwapOptions, QuoteSwapResult } from "./swap/types.js";
8
17
  import type { TransferOptions } from "./transfer/types.js";
9
18
  import type {
10
19
  WaitForUserOperationOptions,
@@ -50,6 +59,71 @@ type Actions = {
50
59
  * ```
51
60
  */
52
61
  requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<RequestFaucetResult>;
62
+
63
+ /**
64
+ * Gets a quote to fund an EVM account.
65
+ *
66
+ * @param options - The options for the quote fund.
67
+ * @param options.network - The network to fund the account on.
68
+ * @param options.token - The token to fund the account with.
69
+ * @param options.amount - The amount of the token to fund represented as an atomic unit.
70
+ * It's common to use `parseUnits` utils from viem to convert to atomic units.
71
+ * Otherwise, you can pass atomic units directly.
72
+ *
73
+ * @returns A promise that resolves to a Quote object containing details about the funding operation.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const quote = await account.quoteFund({
78
+ * network: "base",
79
+ * token: "usdc",
80
+ * amount: 1000000n,
81
+ * });
82
+ * ```
83
+ */
84
+ quoteFund: (options: Omit<QuoteFundOptions, "address">) => Promise<Quote>;
85
+
86
+ /**
87
+ * Funds an EVM account with the specified token amount.
88
+ *
89
+ * @param options - The options for the fund operation.
90
+ * @param options.network - The network to fund the account on.
91
+ * @param options.token - The token to fund the account with (e.g., 'usdc').
92
+ * @param options.amount - The amount of the token to fund represented as an atomic unit.
93
+ * It's common to use `parseUnits` utils from viem to convert to atomic units.
94
+ * Otherwise, you can pass atomic units directly.
95
+ *
96
+ * @returns A promise that resolves to the fund operation result containing the transfer details.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * const fundOperation = await account.fund({
101
+ * network: "base",
102
+ * token: "usdc",
103
+ * amount: 1000000n,
104
+ * });
105
+ * ```
106
+ */
107
+ fund: (options: Omit<FundOptions, "address">) => Promise<FundOperationResult>;
108
+
109
+ /**
110
+ * Waits for a fund operation to complete and returns the transfer receipt.
111
+ *
112
+ * @param options - The options for the wait for fund operation.
113
+ * @param options.transferId - The ID of the transfer to wait for.
114
+ *
115
+ * @returns A promise that resolves to the completed transfer receipt containing details about the funding operation.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const completedTransfer = await account.waitForFundOperationReceipt({
120
+ * transferId: "transfer_123",
121
+ * });
122
+ * ```
123
+ */
124
+ waitForFundOperationReceipt(
125
+ options: WaitForFundOperationOptions,
126
+ ): Promise<WaitForFundOperationResult>;
53
127
  };
54
128
 
55
129
  export type AccountActions = Actions & {
@@ -176,6 +250,93 @@ export type AccountActions = Actions & {
176
250
  * ```
177
251
  */
178
252
  sendTransaction: (options: Omit<SendTransactionOptions, "address">) => Promise<TransactionResult>;
253
+
254
+ /**
255
+ * Creates a swap quote without executing the transaction.
256
+ * This is useful when you need to get swap details before executing the swap.
257
+ * The taker is automatically set to the account's address.
258
+ *
259
+ * @param {QuoteSwapOptions} options - Configuration options for creating the swap quote.
260
+ * @param {string} options.network - The network to create the quote on
261
+ * @param {string} options.fromToken - The token address to sell
262
+ * @param {string} options.toToken - The token address to buy
263
+ * @param {bigint} options.fromAmount - The amount of fromToken to sell
264
+ * @param {string} [options.signerAddress] - The signer address (only needed if taker is a smart contract)
265
+ * @param {bigint} [options.gasPrice] - The gas price in Wei
266
+ * @param {number} [options.slippageBps] - The slippage tolerance in basis points (0-10000)
267
+ *
268
+ * @returns A promise that resolves to the swap quote or a response indicating that liquidity is unavailable.
269
+ *
270
+ * @example
271
+ * ```ts
272
+ * const swapQuote = await account.quoteSwap({
273
+ * network: "base",
274
+ * fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
275
+ * toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
276
+ * fromAmount: BigInt("1000000000000000000"), // 1 WETH in wei
277
+ * });
278
+ *
279
+ * if (swapQuote.liquidityAvailable) {
280
+ * console.log(`Can swap for ${swapQuote.toAmount} USDC`);
281
+ * }
282
+ * ```
283
+ */
284
+ quoteSwap: (options: QuoteSwapOptions) => Promise<QuoteSwapResult>;
285
+
286
+ /**
287
+ * Executes a token swap on the specified network.
288
+ * This method handles all the steps required for a swap, including Permit2 signatures if needed.
289
+ *
290
+ * @param {SwapOptions} options - Configuration options for the swap.
291
+ * @param {string} [options.network] - The network to execute the swap on
292
+ * @param {CreateSwapQuoteResult} [options.swapQuote] - The swap quote returned by the createSwapQuote method.
293
+ * @param {CreateSwapQuoteOptions} [options.swapOptions] - Options to create a swap quote. The function will call createSwapQuote internally.
294
+ * @param {string} [options.idempotencyKey] - Optional idempotency key for the request.
295
+ *
296
+ * @returns A promise that resolves to the transaction hash.
297
+ *
298
+ * @throws {Error} If liquidity is not available when using swapOptions.
299
+ *
300
+ * @example **Using a pre-created swap quote**
301
+ * ```ts
302
+ * // First create a swap quote
303
+ * const swapQuote = await cdp.evm.createSwapQuote({
304
+ * network: "base",
305
+ * buyToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
306
+ * sellToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
307
+ * sellAmount: BigInt("1000000000000000000"), // 1 WETH in wei
308
+ * taker: account.address
309
+ * });
310
+ *
311
+ * // Check if liquidity is available
312
+ * if (!swapQuote.liquidityAvailable) {
313
+ * console.error("Insufficient liquidity for swap");
314
+ * return;
315
+ * }
316
+ *
317
+ * // Execute the swap
318
+ * const { transactionHash } = await account.swap({
319
+ * swapQuote: swapQuote
320
+ * });
321
+ *
322
+ * console.log(`Swap executed with transaction hash: ${transactionHash}`);
323
+ * ```
324
+ *
325
+ * @example **Using swap options (all-in-one)**
326
+ * ```ts
327
+ * // Create and execute swap in one call
328
+ * const { transactionHash } = await account.swap({
329
+ * network: "base",
330
+ * buyToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
331
+ * sellToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
332
+ * sellAmount: BigInt("1000000000000000000"), // 1 WETH in wei
333
+ * taker: account.address
334
+ * });
335
+ *
336
+ * console.log(`Swap executed with transaction hash: ${transactionHash}`);
337
+ * ```
338
+ */
339
+ swap: (options: SwapOptions) => Promise<SwapResult>;
179
340
  };
180
341
 
181
342
  export type SmartAccountActions = Actions & {
package/client/evm/evm.ts CHANGED
@@ -27,6 +27,11 @@ import {
27
27
  SignTypedDataOptions,
28
28
  UpdateEvmAccountOptions,
29
29
  ImportServerAccountOptions,
30
+ GetSwapPriceOptions,
31
+ CreateSwapQuoteOptions,
32
+ GetSwapPriceResult,
33
+ CreateSwapQuoteResult,
34
+ SwapUnavailableResult,
30
35
  } from "./evm.types.js";
31
36
  import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
32
37
  import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
@@ -47,6 +52,8 @@ import {
47
52
  SendUserOperationOptions,
48
53
  SendUserOperationReturnType,
49
54
  } from "../../actions/evm/sendUserOperation.js";
55
+ import { createSwapQuote } from "../../actions/evm/swap/createSwapQuote.js";
56
+ import { getSwapPrice } from "../../actions/evm/swap/getSwapPrice.js";
50
57
  import {
51
58
  waitForUserOperation,
52
59
  WaitForUserOperationReturnType,
@@ -103,6 +110,7 @@ export class EvmClient implements EvmClientInterface {
103
110
  const openApiAccount = await CdpOpenApiClient.createEvmAccount(
104
111
  {
105
112
  name: options.name,
113
+ accountPolicy: options.accountPolicy,
106
114
  },
107
115
  options.idempotencyKey,
108
116
  );
@@ -159,6 +167,8 @@ export class EvmClient implements EvmClientInterface {
159
167
  * ```
160
168
  */
161
169
  async importAccount(options: ImportServerAccountOptions): Promise<ServerAccount> {
170
+ const encryptionPublicKey = options.encryptionPublicKey || ImportEvmAccountPublicRSAKey;
171
+
162
172
  const privateKeyHex = options.privateKey.startsWith("0x")
163
173
  ? options.privateKey.slice(2)
164
174
  : options.privateKey;
@@ -172,7 +182,7 @@ export class EvmClient implements EvmClientInterface {
172
182
 
173
183
  const encryptedPrivateKey = publicEncrypt(
174
184
  {
175
- key: ImportEvmAccountPublicRSAKey,
185
+ key: encryptionPublicKey,
176
186
  padding: constants.RSA_PKCS1_OAEP_PADDING,
177
187
  oaepHash: "sha256",
178
188
  },
@@ -385,6 +395,54 @@ export class EvmClient implements EvmClientInterface {
385
395
  }
386
396
  }
387
397
 
398
+ /**
399
+ * Gets the price for a swap between two tokens on an EVM network.
400
+ *
401
+ * @param {GetSwapPriceOptions} options - The options for getting a swap price.
402
+ *
403
+ * @returns {Promise<GetSwapPriceResult | SwapUnavailableResult>} A promise that resolves to the swap price result or a response indicating that liquidity is unavailable.
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * const price = await cdp.evm.getSwapPrice({
408
+ * network: "ethereum-mainnet",
409
+ * toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
410
+ * fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
411
+ * fromAmount: BigInt("1000000000000000000"), // 1 WETH
412
+ * taker: "0x1234567890123456789012345678901234567890"
413
+ * });
414
+ * ```
415
+ */
416
+ async getSwapPrice(
417
+ options: GetSwapPriceOptions,
418
+ ): Promise<GetSwapPriceResult | SwapUnavailableResult> {
419
+ return getSwapPrice(CdpOpenApiClient, options);
420
+ }
421
+
422
+ /**
423
+ * Creates a quote for a swap between two tokens on an EVM network.
424
+ *
425
+ * @param {CreateSwapQuoteOptions} options - The options for creating a swap quote.
426
+ *
427
+ * @returns {Promise<CreateSwapQuoteResult | SwapUnavailableResult>} A promise that resolves to the swap quote result or a response indicating that liquidity is unavailable.
428
+ *
429
+ * @example
430
+ * ```typescript
431
+ * const swapQuote = await cdp.evm.createSwapQuote({
432
+ * network: "ethereum",
433
+ * toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
434
+ * fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
435
+ * fromAmount: BigInt("1000000000000000000"), // 1 WETH
436
+ * taker: "0x1234567890123456789012345678901234567890"
437
+ * });
438
+ * ```
439
+ */
440
+ async createSwapQuote(
441
+ options: CreateSwapQuoteOptions,
442
+ ): Promise<CreateSwapQuoteResult | SwapUnavailableResult> {
443
+ return createSwapQuote(CdpOpenApiClient, options);
444
+ }
445
+
388
446
  /**
389
447
  * Gets a user operation for a smart account by user operation hash.
390
448
  *
@@ -18,6 +18,7 @@ import type {
18
18
  } from "../../actions/evm/sendUserOperation.js";
19
19
  import type { SmartAccountActions } from "../../actions/evm/types.js";
20
20
  import type {
21
+ EvmSwapsNetwork,
21
22
  EvmUserOperationNetwork,
22
23
  EvmUserOperationStatus,
23
24
  OpenApiEvmMethods,
@@ -38,6 +39,8 @@ export type EvmClientInterface = Omit<
38
39
  | "getEvmAccount" // mapped to getAccount
39
40
  | "getEvmAccountByName" // mapped to getAccount
40
41
  | "getEvmSmartAccount" // mapped to getSmartAccount
42
+ | "getEvmSwapPrice" // mapped to getSwapPrice
43
+ | "createEvmSwapQuote" // mapped to createSwapQuote
41
44
  | "getUserOperation"
42
45
  | "updateEvmAccount" // mapped to updateAccount
43
46
  | "listEvmAccounts" // mapped to listAccounts
@@ -59,6 +62,12 @@ export type EvmClientInterface = Omit<
59
62
  importAccount: (options: ImportServerAccountOptions) => Promise<ServerAccount>;
60
63
  getAccount: (options: GetServerAccountOptions) => Promise<ServerAccount>;
61
64
  getSmartAccount: (options: GetSmartAccountOptions) => Promise<SmartAccount>;
65
+ getSwapPrice: (
66
+ options: GetSwapPriceOptions,
67
+ ) => Promise<GetSwapPriceResult | SwapUnavailableResult>;
68
+ createSwapQuote: (
69
+ options: CreateSwapQuoteOptions,
70
+ ) => Promise<CreateSwapQuoteResult | SwapUnavailableResult>;
62
71
  getOrCreateAccount: (options: GetOrCreateServerAccountOptions) => Promise<ServerAccount>;
63
72
  getUserOperation: (options: GetUserOperationOptions) => Promise<UserOperation>;
64
73
  updateAccount: (options: UpdateEvmAccountOptions) => Promise<ServerAccount>;
@@ -79,6 +88,153 @@ export type EvmClientInterface = Omit<
79
88
 
80
89
  export type { ServerAccount, SmartAccount };
81
90
 
91
+ /**
92
+ * Options for creating a swap quote between two tokens on an EVM network.
93
+ */
94
+ export interface CreateSwapQuoteOptions {
95
+ /** The network to create a swap quote on. */
96
+ network: EvmSwapsNetwork;
97
+ /** The token to receive (destination token). */
98
+ toToken: Address;
99
+ /** The token to send (source token). */
100
+ fromToken: Address;
101
+ /** The amount to send in atomic units of the token. */
102
+ fromAmount: bigint;
103
+ /** The address that will perform the swap. */
104
+ taker?: Address;
105
+ /** The signer address (only needed if taker is a smart contract). */
106
+ signerAddress?: Address;
107
+ /** The gas price in Wei. */
108
+ gasPrice?: bigint;
109
+ /** The slippage tolerance in basis points (0-10000). */
110
+ slippageBps?: number;
111
+ }
112
+
113
+ /**
114
+ * Options for getting a swap price.
115
+ */
116
+ export interface GetSwapPriceOptions {
117
+ /** The network to get a price from. */
118
+ network: EvmSwapsNetwork;
119
+ /** The token to receive (destination token). */
120
+ toToken: Address;
121
+ /** The token to send (source token). */
122
+ fromToken: Address;
123
+ /** The amount to send in atomic units of the token. */
124
+ fromAmount: bigint;
125
+ /** The address that will perform the swap. */
126
+ taker: Address;
127
+ /** The signer address (only needed if taker is a smart contract). */
128
+ signerAddress?: Address;
129
+ /** The gas price in Wei. */
130
+ gasPrice?: bigint;
131
+ /** The slippage tolerance in basis points (0-10000). */
132
+ slippageBps?: number;
133
+ }
134
+
135
+ /**
136
+ * Result of getting a swap price.
137
+ */
138
+ export interface GetSwapPriceResult {
139
+ /** Whether liquidity is available for the swap. */
140
+ liquidityAvailable: true;
141
+ /** The token to receive (destination token). */
142
+ toToken: Address;
143
+ /** The token to send (source token). */
144
+ fromToken: Address;
145
+ /** The amount to send in atomic units of the token. */
146
+ fromAmount: bigint;
147
+ /** The amount to receive in atomic units of the token. */
148
+ toAmount: bigint;
149
+ /** The minimum amount to receive after slippage in atomic units of the token. */
150
+ minToAmount: bigint;
151
+ /** The block number at which the liquidity conditions were examined. */
152
+ blockNumber: bigint;
153
+ /** The estimated fees for the swap. */
154
+ fees: SwapFees;
155
+ /** Potential issues discovered during validation. */
156
+ issues: SwapIssues;
157
+ /** The gas estimate for the swap. */
158
+ gas?: bigint;
159
+ /** The gas price in Wei. */
160
+ gasPrice?: bigint;
161
+ }
162
+
163
+ /**
164
+ * Result when liquidity is unavailable for a swap.
165
+ */
166
+ export interface SwapUnavailableResult {
167
+ /** Whether liquidity is available for the swap. */
168
+ liquidityAvailable: false;
169
+ }
170
+
171
+ /**
172
+ * Options for executing a swap quote.
173
+ */
174
+ export interface ExecuteSwapQuoteOptions {
175
+ /** Optional idempotency key for the request. */
176
+ idempotencyKey?: string;
177
+ }
178
+
179
+ /**
180
+ * Result of executing a swap quote.
181
+ */
182
+ export interface ExecuteSwapQuoteResult {
183
+ /** The transaction hash of the executed swap. */
184
+ transactionHash: Hex;
185
+ }
186
+
187
+ /**
188
+ * Result of creating a swap quote.
189
+ */
190
+ export interface CreateSwapQuoteResult {
191
+ /** Whether liquidity is available for the swap. */
192
+ liquidityAvailable: true;
193
+ /** The network for which this swap quote was created. */
194
+ network: EvmSwapsNetwork;
195
+ /** The token to receive (destination token). */
196
+ toToken: Address;
197
+ /** The token to send (source token). */
198
+ fromToken: Address;
199
+ /** The amount to send in atomic units of the token. */
200
+ fromAmount: bigint;
201
+ /** The amount to receive in atomic units of the token. */
202
+ toAmount: bigint;
203
+ /** The minimum amount to receive after slippage in atomic units of the token. */
204
+ minToAmount: bigint;
205
+ /** The block number at which the liquidity conditions were examined. */
206
+ blockNumber: bigint;
207
+ /** The estimated fees for the swap. */
208
+ fees: SwapFees;
209
+ /** Potential issues discovered during validation. */
210
+ issues: SwapIssues;
211
+ /** The transaction to execute the swap. */
212
+ transaction?: {
213
+ /** The contract address to send the transaction to. */
214
+ to: Address;
215
+ /** The transaction data. */
216
+ data: Hex;
217
+ /** The value to send with the transaction in Wei. */
218
+ value: bigint;
219
+ /** The gas limit for the transaction. */
220
+ gas: bigint;
221
+ /** The gas price for the transaction in Wei. */
222
+ gasPrice: bigint;
223
+ };
224
+ /** Permit2 data if required for the swap. */
225
+ permit2?: {
226
+ /** EIP-712 typed data for signing. */
227
+ eip712: EIP712Message;
228
+ };
229
+ /**
230
+ * Execute the swap using the quote.
231
+ *
232
+ * @param {ExecuteSwapQuoteOptions} options - Options for executing the swap.
233
+ * @returns {Promise<ExecuteSwapQuoteResult>} A promise that resolves to the swap execution result.
234
+ */
235
+ execute: (options?: ExecuteSwapQuoteOptions) => Promise<ExecuteSwapQuoteResult>;
236
+ }
237
+
82
238
  /**
83
239
  * Options for getting a user operation.
84
240
  */
@@ -145,6 +301,8 @@ export interface UserOperation {
145
301
  export interface CreateServerAccountOptions {
146
302
  /** The name of the account. */
147
303
  name?: string;
304
+ /** The policy ID to apply to the account. */
305
+ accountPolicy?: string;
148
306
  /** The idempotency key. */
149
307
  idempotencyKey?: string;
150
308
  }
@@ -153,6 +311,8 @@ export interface CreateServerAccountOptions {
153
311
  * Options for importing an EVM server account.
154
312
  */
155
313
  export interface ImportServerAccountOptions {
314
+ /** The public RSA key used to encrypt the private key when importing an EVM account. */
315
+ encryptionPublicKey?: string;
156
316
  /** The name of the account. */
157
317
  name?: string;
158
318
  /** The idempotency key. */
@@ -293,7 +453,7 @@ export interface SignMessageOptions {
293
453
  }
294
454
 
295
455
  /**
296
- * Options for signing an EVM message.
456
+ * Options for signing an EVM typed data message.
297
457
  */
298
458
  export interface SignTypedDataOptions {
299
459
  /** The address of the account. */
@@ -330,6 +490,60 @@ export interface SignatureResult {
330
490
  signature: Hex;
331
491
  }
332
492
 
493
+ /**
494
+ * A fee in a specific token.
495
+ */
496
+ export interface TokenFee {
497
+ /** The amount of the fee in atomic units of the token. */
498
+ amount: bigint;
499
+ /** The contract address of the token that the fee is paid in. */
500
+ token: Address;
501
+ }
502
+
503
+ /**
504
+ * The estimated fees for a swap.
505
+ */
506
+ export interface SwapFees {
507
+ /** The estimated gas fee for the swap. */
508
+ gasFee?: TokenFee;
509
+ /** The estimated protocol fee for the swap. */
510
+ protocolFee?: TokenFee;
511
+ }
512
+
513
+ /**
514
+ * Details of allowance issues for a swap.
515
+ */
516
+ export interface SwapAllowanceIssue {
517
+ /** The current allowance of the fromToken by the taker. */
518
+ currentAllowance: bigint;
519
+ /** The address to set the allowance on. */
520
+ spender: Address;
521
+ }
522
+
523
+ /**
524
+ * Details of balance issues for a swap.
525
+ */
526
+ export interface SwapBalanceIssue {
527
+ /** The contract address of the token. */
528
+ token: Address;
529
+ /** The current balance of the fromToken by the taker. */
530
+ currentBalance: bigint;
531
+ /** The amount of the token that the taker must hold. */
532
+ requiredBalance: bigint;
533
+ }
534
+
535
+ /**
536
+ * Potential issues discovered during swap validation.
537
+ */
538
+ export interface SwapIssues {
539
+ /** Details of the allowances that the taker must set. Null if no allowance is required. */
540
+ allowance?: SwapAllowanceIssue;
541
+ /** Details of the balance of the fromToken that the taker must hold. Null if sufficient balance. */
542
+ balance?: SwapBalanceIssue;
543
+ /** True when the transaction cannot be validated (e.g., insufficient balance). */
544
+ simulationIncomplete: boolean;
545
+ }
546
+
333
547
  /**
334
548
  * Options for waiting for a user operation.
335
549
  */
@@ -341,3 +555,15 @@ export interface WaitForUserOperationOptions {
341
555
  /** The wait options. */
342
556
  waitOptions?: WaitOptions;
343
557
  }
558
+
559
+ /**
560
+ * Legacy type aliases for backwards compatibility.
561
+ *
562
+ * @deprecated Use the new type names instead.
563
+ */
564
+ export type CreateSwapOptions = CreateSwapQuoteOptions;
565
+ export type CreateSwapResult = CreateSwapQuoteResult;
566
+ export type GetSwapQuoteOptions = GetSwapPriceOptions;
567
+ export type GetSwapQuoteResult = GetSwapPriceResult;
568
+ export type SwapQuoteUnavailableResult = SwapUnavailableResult;
569
+ export type SwapPriceUnavailableResult = SwapUnavailableResult;
@@ -56,7 +56,10 @@ export class SolanaClient implements SolanaClientInterface {
56
56
  */
57
57
  async createAccount(options: CreateAccountOptions = {}): Promise<SolanaAccount> {
58
58
  const openApiAccount = await CdpOpenApiClient.createSolanaAccount(
59
- options,
59
+ {
60
+ name: options.name,
61
+ accountPolicy: options.accountPolicy,
62
+ },
60
63
  options.idempotencyKey,
61
64
  );
62
65
 
@@ -40,6 +40,8 @@ export interface SignatureResult {
40
40
  export interface CreateAccountOptions {
41
41
  /** The name of the account. */
42
42
  name?: string;
43
+ /** The policy ID to apply to the account. */
44
+ accountPolicy?: string;
43
45
  /** The idempotency key. */
44
46
  idempotencyKey?: string;
45
47
  }