@coinbase/cdp-sdk 1.15.0 → 1.17.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 (145) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +82 -20
  3. package/_cjs/accounts/evm/toEvmServerAccount.js +20 -7
  4. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  5. package/_cjs/accounts/evm/toEvmSmartAccount.js +26 -0
  6. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  7. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +28 -0
  8. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -0
  9. package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +26 -0
  10. package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -0
  11. package/_cjs/actions/evm/signAndWrapTypedDataForSmartAccount.js +186 -0
  12. package/_cjs/actions/evm/signAndWrapTypedDataForSmartAccount.js.map +1 -0
  13. package/_cjs/actions/evm/swap/createSwapQuote.js +26 -8
  14. package/_cjs/actions/evm/swap/createSwapQuote.js.map +1 -1
  15. package/_cjs/actions/evm/swap/getSwapPrice.js +3 -2
  16. package/_cjs/actions/evm/swap/getSwapPrice.js.map +1 -1
  17. package/_cjs/actions/evm/swap/sendSwapOperation.js +153 -0
  18. package/_cjs/actions/evm/swap/sendSwapOperation.js.map +1 -0
  19. package/_cjs/actions/evm/swap/sendSwapTransaction.js +16 -2
  20. package/_cjs/actions/evm/swap/sendSwapTransaction.js.map +1 -1
  21. package/_cjs/client/evm/evm.js +13 -6
  22. package/_cjs/client/evm/evm.js.map +1 -1
  23. package/_cjs/client/policies/policies.js +6 -2
  24. package/_cjs/client/policies/policies.js.map +1 -1
  25. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +45 -1
  26. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  27. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +48 -0
  28. package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
  29. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +35 -0
  30. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  31. package/_cjs/openapi-client/generated/index.msw.js +5 -5
  32. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  33. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +342 -1
  34. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
  35. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +40 -0
  36. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
  37. package/_cjs/policies/schema.js +83 -2
  38. package/_cjs/policies/schema.js.map +1 -1
  39. package/_cjs/utils/uuidV4.js +26 -0
  40. package/_cjs/utils/uuidV4.js.map +1 -0
  41. package/_cjs/version.js +1 -1
  42. package/_esm/accounts/evm/toEvmServerAccount.js +21 -8
  43. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  44. package/_esm/accounts/evm/toEvmSmartAccount.js +26 -0
  45. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  46. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +25 -0
  47. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -0
  48. package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +23 -0
  49. package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -0
  50. package/_esm/actions/evm/signAndWrapTypedDataForSmartAccount.js +181 -0
  51. package/_esm/actions/evm/signAndWrapTypedDataForSmartAccount.js.map +1 -0
  52. package/_esm/actions/evm/swap/createSwapQuote.js +26 -8
  53. package/_esm/actions/evm/swap/createSwapQuote.js.map +1 -1
  54. package/_esm/actions/evm/swap/getSwapPrice.js +3 -2
  55. package/_esm/actions/evm/swap/getSwapPrice.js.map +1 -1
  56. package/_esm/actions/evm/swap/sendSwapOperation.js +150 -0
  57. package/_esm/actions/evm/swap/sendSwapOperation.js.map +1 -0
  58. package/_esm/actions/evm/swap/sendSwapTransaction.js +16 -2
  59. package/_esm/actions/evm/swap/sendSwapTransaction.js.map +1 -1
  60. package/_esm/client/evm/evm.js +14 -7
  61. package/_esm/client/evm/evm.js.map +1 -1
  62. package/_esm/client/policies/policies.js +7 -3
  63. package/_esm/client/policies/policies.js.map +1 -1
  64. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +44 -0
  65. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  66. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +48 -0
  67. package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
  68. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +35 -0
  69. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  70. package/_esm/openapi-client/generated/index.msw.js +5 -5
  71. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  72. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +321 -0
  73. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
  74. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +40 -0
  75. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
  76. package/_esm/policies/schema.js +83 -2
  77. package/_esm/policies/schema.js.map +1 -1
  78. package/_esm/utils/uuidV4.js +23 -0
  79. package/_esm/utils/uuidV4.js.map +1 -0
  80. package/_esm/version.js +1 -1
  81. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  82. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
  83. package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts +23 -0
  84. package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -0
  85. package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts +27 -0
  86. package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -0
  87. package/_types/accounts/evm/types.d.ts +26 -9
  88. package/_types/accounts/evm/types.d.ts.map +1 -1
  89. package/_types/actions/evm/signAndWrapTypedDataForSmartAccount.d.ts +133 -0
  90. package/_types/actions/evm/signAndWrapTypedDataForSmartAccount.d.ts.map +1 -0
  91. package/_types/actions/evm/swap/createSwapQuote.d.ts.map +1 -1
  92. package/_types/actions/evm/swap/getSwapPrice.d.ts +2 -1
  93. package/_types/actions/evm/swap/getSwapPrice.d.ts.map +1 -1
  94. package/_types/actions/evm/swap/sendSwapOperation.d.ts +64 -0
  95. package/_types/actions/evm/swap/sendSwapOperation.d.ts.map +1 -0
  96. package/_types/actions/evm/swap/sendSwapTransaction.d.ts.map +1 -1
  97. package/_types/actions/evm/swap/types.d.ts +131 -5
  98. package/_types/actions/evm/swap/types.d.ts.map +1 -1
  99. package/_types/actions/evm/types.d.ts +112 -21
  100. package/_types/actions/evm/types.d.ts.map +1 -1
  101. package/_types/client/evm/evm.d.ts.map +1 -1
  102. package/_types/client/evm/evm.types.d.ts +33 -7
  103. package/_types/client/evm/evm.types.d.ts.map +1 -1
  104. package/_types/client/policies/policies.d.ts.map +1 -1
  105. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +182 -2
  106. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  107. package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
  108. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -1
  109. package/_types/openapi-client/generated/index.msw.d.ts +5 -5
  110. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  111. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +21 -1
  112. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
  113. package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
  114. package/_types/openapi-client/index.d.ts.map +1 -1
  115. package/_types/policies/schema.d.ts +3780 -7
  116. package/_types/policies/schema.d.ts.map +1 -1
  117. package/_types/utils/uuidV4.d.ts +10 -0
  118. package/_types/utils/uuidV4.d.ts.map +1 -0
  119. package/_types/version.d.ts +1 -1
  120. package/accounts/evm/toEvmServerAccount.ts +40 -15
  121. package/accounts/evm/toEvmSmartAccount.ts +33 -0
  122. package/accounts/evm/toNetworkScopedEvmServerAccount.ts +42 -0
  123. package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +41 -0
  124. package/accounts/evm/types.ts +46 -17
  125. package/actions/evm/signAndWrapTypedDataForSmartAccount.ts +246 -0
  126. package/actions/evm/swap/createSwapQuote.ts +42 -17
  127. package/actions/evm/swap/getSwapPrice.ts +15 -11
  128. package/actions/evm/swap/sendSwapOperation.ts +182 -0
  129. package/actions/evm/swap/sendSwapTransaction.ts +18 -2
  130. package/actions/evm/swap/types.ts +154 -5
  131. package/actions/evm/types.ts +123 -21
  132. package/client/evm/evm.ts +19 -8
  133. package/client/evm/evm.types.ts +34 -7
  134. package/client/policies/policies.ts +12 -3
  135. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +221 -2
  136. package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +48 -0
  137. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +35 -0
  138. package/openapi-client/generated/faucets/faucets.ts +4 -4
  139. package/openapi-client/generated/index.msw.ts +5 -5
  140. package/openapi-client/generated/policy-engine/policy-engine.msw.ts +434 -0
  141. package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +40 -0
  142. package/package.json +1 -1
  143. package/policies/schema.ts +94 -6
  144. package/utils/uuidV4.ts +23 -0
  145. package/version.ts +1 -1
@@ -13,7 +13,16 @@ import { Hex } from "../../types/misc.js";
13
13
  import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "./listTokenBalances.js";
14
14
  import type { RequestFaucetOptions, RequestFaucetResult } from "./requestFaucet.js";
15
15
  import type { SendTransactionOptions, TransactionResult } from "./sendTransaction.js";
16
- import type { SwapOptions, SwapResult, QuoteSwapOptions, QuoteSwapResult } from "./swap/types.js";
16
+ import type {
17
+ AccountSwapOptions,
18
+ AccountSwapResult,
19
+ AccountQuoteSwapOptions,
20
+ AccountQuoteSwapResult,
21
+ SmartAccountSwapOptions,
22
+ SmartAccountSwapResult,
23
+ SmartAccountQuoteSwapOptions,
24
+ SmartAccountQuoteSwapResult,
25
+ } from "./swap/types.js";
17
26
  import type { TransferOptions } from "./transfer/types.js";
18
27
  import type {
19
28
  WaitForUserOperationOptions,
@@ -256,11 +265,11 @@ export type AccountActions = Actions & {
256
265
  * This is useful when you need to get swap details before executing the swap.
257
266
  * The taker is automatically set to the account's address.
258
267
  *
259
- * @param {QuoteSwapOptions} options - Configuration options for creating the swap quote.
268
+ * @param {AccountQuoteSwapOptions} options - Configuration options for creating the swap quote.
260
269
  * @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
270
+ * @param {string} options.fromToken - The token address to send
271
+ * @param {string} options.toToken - The token address to receive
272
+ * @param {bigint} options.fromAmount - The amount of fromToken to send
264
273
  * @param {string} [options.signerAddress] - The signer address (only needed if taker is a smart contract)
265
274
  * @param {bigint} [options.gasPrice] - The gas price in Wei
266
275
  * @param {number} [options.slippageBps] - The slippage tolerance in basis points (0-10000)
@@ -281,30 +290,33 @@ export type AccountActions = Actions & {
281
290
  * }
282
291
  * ```
283
292
  */
284
- quoteSwap: (options: QuoteSwapOptions) => Promise<QuoteSwapResult>;
293
+ quoteSwap: (options: AccountQuoteSwapOptions) => Promise<AccountQuoteSwapResult>;
285
294
 
286
295
  /**
287
296
  * Executes a token swap on the specified network.
288
297
  * This method handles all the steps required for a swap, including Permit2 signatures if needed.
298
+ * The taker is automatically set to the account's address.
289
299
  *
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.
300
+ * @param {AccountSwapOptions} options - Configuration options for the swap.
301
+ * @param {string} [options.network] - The network to execute the swap on (required for inline swaps)
302
+ * @param {CreateSwapQuoteResult} [options.swapQuote] - The swap quote returned by the createSwapQuote method
303
+ * @param {string} [options.fromToken] - The token address to send (required for inline swaps)
304
+ * @param {string} [options.toToken] - The token address to receive (required for inline swaps)
305
+ * @param {bigint} [options.fromAmount] - The amount of fromToken to send (required for inline swaps)
306
+ * @param {string} [options.idempotencyKey] - Optional idempotency key for the request
295
307
  *
296
308
  * @returns A promise that resolves to the transaction hash.
297
309
  *
298
- * @throws {Error} If liquidity is not available when using swapOptions.
310
+ * @throws {Error} If liquidity is not available when using inline options.
299
311
  *
300
312
  * @example **Using a pre-created swap quote**
301
313
  * ```ts
302
314
  * // First create a swap quote
303
315
  * const swapQuote = await cdp.evm.createSwapQuote({
304
316
  * network: "base",
305
- * buyToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
306
- * sellToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
307
- * sellAmount: BigInt("1000000000000000000"), // 1 WETH in wei
317
+ * toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
318
+ * fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
319
+ * fromAmount: BigInt("1000000000000000000"), // 1 WETH in wei
308
320
  * taker: account.address
309
321
  * });
310
322
  *
@@ -322,21 +334,20 @@ export type AccountActions = Actions & {
322
334
  * console.log(`Swap executed with transaction hash: ${transactionHash}`);
323
335
  * ```
324
336
  *
325
- * @example **Using swap options (all-in-one)**
337
+ * @example **Using inline options (all-in-one)**
326
338
  * ```ts
327
339
  * // Create and execute swap in one call
328
340
  * const { transactionHash } = await account.swap({
329
341
  * network: "base",
330
- * buyToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
331
- * sellToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
332
- * sellAmount: BigInt("1000000000000000000"), // 1 WETH in wei
333
- * taker: account.address
342
+ * toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
343
+ * fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
344
+ * fromAmount: BigInt("1000000000000000000"), // 1 WETH in wei
334
345
  * });
335
346
  *
336
347
  * console.log(`Swap executed with transaction hash: ${transactionHash}`);
337
348
  * ```
338
349
  */
339
- swap: (options: SwapOptions) => Promise<SwapResult>;
350
+ swap: (options: AccountSwapOptions) => Promise<AccountSwapResult>;
340
351
  };
341
352
 
342
353
  export type SmartAccountActions = Actions & {
@@ -499,4 +510,95 @@ export type SmartAccountActions = Actions & {
499
510
  getUserOperation: (
500
511
  options: Omit<GetUserOperationOptions, "smartAccount">,
501
512
  ) => Promise<UserOperation>;
513
+
514
+ /**
515
+ * Creates a swap quote without executing the transaction.
516
+ * This is useful when you need to get swap details before executing the swap.
517
+ * The taker is automatically set to the smart account's address.
518
+ *
519
+ * @param {SmartAccountQuoteSwapOptions} options - Configuration options for creating the swap quote.
520
+ * @param {string} options.network - The network to create the quote on
521
+ * @param {string} options.fromToken - The token address to send
522
+ * @param {string} options.toToken - The token address to receive
523
+ * @param {bigint} options.fromAmount - The amount of fromToken to send
524
+ * @param {string} [options.signerAddress] - The signer address (only needed if taker is a smart contract)
525
+ * @param {bigint} [options.gasPrice] - The gas price in Wei
526
+ * @param {number} [options.slippageBps] - The slippage tolerance in basis points (0-10000)
527
+ *
528
+ * @returns A promise that resolves to the swap quote or a response indicating that liquidity is unavailable.
529
+ *
530
+ * @example
531
+ * ```ts
532
+ * const swapQuote = await smartAccount.quoteSwap({
533
+ * network: "base",
534
+ * fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
535
+ * toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
536
+ * fromAmount: BigInt("1000000000000000000"), // 1 WETH in wei
537
+ * });
538
+ *
539
+ * if (swapQuote.liquidityAvailable) {
540
+ * console.log(`Can swap for ${swapQuote.toAmount} USDC`);
541
+ * }
542
+ * ```
543
+ */
544
+ quoteSwap: (options: SmartAccountQuoteSwapOptions) => Promise<SmartAccountQuoteSwapResult>;
545
+
546
+ /**
547
+ * Executes a token swap on the specified network via a user operation.
548
+ * This method handles all the steps required for a swap, including Permit2 signatures if needed.
549
+ * The taker is automatically set to the smart account's address.
550
+ *
551
+ * @param {SmartAccountSwapOptions} options - Configuration options for the swap.
552
+ * @param {string} [options.network] - The network to execute the swap on (required for inline swaps)
553
+ * @param {CreateSwapQuoteResult} [options.swapQuote] - The swap quote returned by the createSwapQuote method
554
+ * @param {string} [options.fromToken] - The token address to send (required for inline swaps)
555
+ * @param {string} [options.toToken] - The token address to receive (required for inline swaps)
556
+ * @param {bigint} [options.fromAmount] - The amount of fromToken to send (required for inline swaps)
557
+ * @param {string} [options.paymasterUrl] - Optional paymaster URL for gas sponsorship
558
+ * @param {string} [options.idempotencyKey] - Optional idempotency key for the request
559
+ *
560
+ * @returns A promise that resolves to the user operation result.
561
+ *
562
+ * @throws {Error} If liquidity is not available when using inline options.
563
+ *
564
+ * @example **Using a pre-created swap quote**
565
+ * ```ts
566
+ * // First create a swap quote
567
+ * const swapQuote = await cdp.evm.createSwapQuote({
568
+ * network: "base",
569
+ * toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
570
+ * fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
571
+ * fromAmount: BigInt("1000000000000000000"), // 1 WETH in wei
572
+ * taker: smartAccount.address,
573
+ * signerAddress: smartAccount.owners[0].address
574
+ * });
575
+ *
576
+ * // Check if liquidity is available
577
+ * if (!swapQuote.liquidityAvailable) {
578
+ * console.error("Insufficient liquidity for swap");
579
+ * return;
580
+ * }
581
+ *
582
+ * // Execute the swap
583
+ * const { userOpHash } = await smartAccount.swap({
584
+ * swapQuote: swapQuote
585
+ * });
586
+ *
587
+ * console.log(`Swap executed with user op hash: ${userOpHash}`);
588
+ * ```
589
+ *
590
+ * @example **Using inline options (all-in-one)**
591
+ * ```ts
592
+ * // Create and execute swap in one call
593
+ * const { userOpHash } = await smartAccount.swap({
594
+ * network: "base",
595
+ * toToken: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
596
+ * fromToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH
597
+ * fromAmount: BigInt("1000000000000000000"), // 1 WETH in wei
598
+ * });
599
+ *
600
+ * console.log(`Swap executed with user op hash: ${userOpHash}`);
601
+ * ```
602
+ */
603
+ swap: (options: SmartAccountSwapOptions) => Promise<SmartAccountSwapResult>;
502
604
  };
package/client/evm/evm.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { constants, publicEncrypt } from "crypto";
2
2
 
3
- import { Address } from "viem";
3
+ import { type Address, getTypesForEIP712Domain } from "viem";
4
4
 
5
5
  import { ImportEvmAccountPublicRSAKey } from "./constants.js";
6
6
  import {
@@ -62,7 +62,10 @@ import {
62
62
  } from "../../actions/evm/waitForUserOperation.js";
63
63
  import { Analytics } from "../../analytics.js";
64
64
  import { APIError } from "../../openapi-client/errors.js";
65
- import { CdpOpenApiClient } from "../../openapi-client/index.js";
65
+ import {
66
+ CdpOpenApiClient,
67
+ EIP712Message as OpenAPIEIP712Message,
68
+ } from "../../openapi-client/index.js";
66
69
  import { Hex } from "../../types/misc.js";
67
70
  import { decryptWithPrivateKey, generateExportEncryptionKeyPair } from "../../utils/export.js";
68
71
 
@@ -978,14 +981,22 @@ export class EvmClient implements EvmClientInterface {
978
981
  * ```
979
982
  */
980
983
  async signTypedData(options: SignTypedDataOptions): Promise<SignatureResult> {
984
+ const { domain, message, primaryType } = options;
985
+ const types = {
986
+ EIP712Domain: getTypesForEIP712Domain({ domain }),
987
+ ...options.types,
988
+ };
989
+
990
+ const openApiMessage: OpenAPIEIP712Message = {
991
+ domain,
992
+ types,
993
+ primaryType,
994
+ message,
995
+ };
996
+
981
997
  const signature = await CdpOpenApiClient.signEvmTypedData(
982
998
  options.address,
983
- {
984
- domain: options.domain,
985
- types: options.types,
986
- primaryType: options.primaryType,
987
- message: options.message,
988
- },
999
+ openApiMessage,
989
1000
  options.idempotencyKey,
990
1001
  );
991
1002
 
@@ -106,14 +106,18 @@ export interface CreateSwapQuoteOptions {
106
106
  fromToken: Address;
107
107
  /** The amount to send in atomic units of the token. */
108
108
  fromAmount: bigint;
109
- /** The address that will perform the swap. */
110
- taker?: Address;
111
- /** The signer address (only needed if taker is a smart contract). */
109
+ /** The address receiving the output of the swap. */
110
+ taker: Address;
111
+ /** The address signing the swap (only needed if taker is a smart contract, i.e. for smart account swaps). */
112
112
  signerAddress?: Address;
113
- /** The gas price in Wei. */
113
+ /** The smart account object (required for smart account execution context only). */
114
+ smartAccount?: SmartAccount;
115
+ /** The price per unit of gas in wei. */
114
116
  gasPrice?: bigint;
115
117
  /** The slippage tolerance in basis points (0-10000). */
116
118
  slippageBps?: number;
119
+ /** The idempotency key. */
120
+ idempotencyKey?: string;
117
121
  }
118
122
 
119
123
  /**
@@ -136,6 +140,8 @@ export interface GetSwapPriceOptions {
136
140
  gasPrice?: bigint;
137
141
  /** The slippage tolerance in basis points (0-10000). */
138
142
  slippageBps?: number;
143
+ /** The idempotency key. */
144
+ idempotencyKey?: string;
139
145
  }
140
146
 
141
147
  /**
@@ -186,8 +192,14 @@ export interface ExecuteSwapQuoteOptions {
186
192
  * Result of executing a swap quote.
187
193
  */
188
194
  export interface ExecuteSwapQuoteResult {
189
- /** The transaction hash of the executed swap. */
190
- transactionHash: Hex;
195
+ /** The transaction hash of the executed swap (for EOA swaps). */
196
+ transactionHash?: Hex;
197
+ /** The user operation hash of the executed swap (for smart account swaps). */
198
+ userOpHash?: Hex;
199
+ /** The address of the smart account (for smart account swaps). */
200
+ smartAccountAddress?: Address;
201
+ /** The status of the user operation (for smart accounts swaps). */
202
+ status?: typeof EvmUserOperationStatus.broadcast;
191
203
  }
192
204
 
193
205
  /**
@@ -393,7 +405,7 @@ export interface ListServerAccountsOptions {
393
405
  * A smart account that only contains the owner address.
394
406
  */
395
407
  export interface ReadonlySmartAccount
396
- extends Omit<SmartAccount, "owners" | keyof SmartAccountActions> {
408
+ extends Omit<SmartAccount, "owners" | keyof SmartAccountActions | "__experimental_useNetwork"> {
397
409
  /** The owners of the smart account. */
398
410
  owners: Address[];
399
411
  }
@@ -599,3 +611,18 @@ export type GetSwapQuoteOptions = GetSwapPriceOptions;
599
611
  export type GetSwapQuoteResult = GetSwapPriceResult;
600
612
  export type SwapQuoteUnavailableResult = SwapUnavailableResult;
601
613
  export type SwapPriceUnavailableResult = SwapUnavailableResult;
614
+
615
+ /**
616
+ * Options for signing and wrapping EIP-712 typed data with a smart account.
617
+ * This method handles the full smart account signature flow including replay-safe hashing.
618
+ */
619
+ export interface SmartAccountSignAndWrapTypedDataOptions {
620
+ /** The chain ID for the signature (used for replay protection). */
621
+ chainId: bigint;
622
+ /** The EIP-712 typed data message to sign. */
623
+ typedData: EIP712Message;
624
+ /** The index of the owner to sign with (defaults to 0). */
625
+ ownerIndex?: bigint;
626
+ /** Optional idempotency key for the signing request. */
627
+ idempotencyKey?: string;
628
+ }
@@ -7,7 +7,11 @@ import {
7
7
  DeletePolicyOptions,
8
8
  UpdatePolicyOptions,
9
9
  } from "./policies.types.js";
10
- import { CdpOpenApiClient } from "../../openapi-client/index.js";
10
+ import {
11
+ CdpOpenApiClient,
12
+ CreatePolicyBody,
13
+ UpdatePolicyBody,
14
+ } from "../../openapi-client/index.js";
11
15
  import { CreatePolicyBodySchema, UpdatePolicyBodySchema } from "../../policies/schema.js";
12
16
  import { Policy } from "../../policies/types.js";
13
17
 
@@ -126,7 +130,11 @@ export class PoliciesClient implements PoliciesClientInterface {
126
130
  */
127
131
  async createPolicy(options: CreatePolicyOptions): Promise<Policy> {
128
132
  CreatePolicyBodySchema.parse(options.policy);
129
- return CdpOpenApiClient.createPolicy(options.policy, options.idempotencyKey) as Promise<Policy>;
133
+ return CdpOpenApiClient.createPolicy(
134
+ // There are arbitrary differences between the abitype Abi and the openapi Abi
135
+ options.policy as CreatePolicyBody,
136
+ options.idempotencyKey,
137
+ ) as Promise<Policy>;
130
138
  }
131
139
 
132
140
  /**
@@ -239,7 +247,8 @@ export class PoliciesClient implements PoliciesClientInterface {
239
247
  UpdatePolicyBodySchema.parse(options.policy);
240
248
  return CdpOpenApiClient.updatePolicy(
241
249
  options.id,
242
- options.policy,
250
+ // There are arbitrary differences between the abitype Abi and the openapi Abi
251
+ options.policy as UpdatePolicyBody,
243
252
  options.idempotencyKey,
244
253
  ) as Promise<Policy>;
245
254
  }
@@ -20,6 +20,10 @@ Account names are guaranteed to be unique across all EVM accounts in the develop
20
20
  name?: string;
21
21
  /** The list of policy IDs that apply to the account. This will include both the project-level policy and the account-level policy, if one exists. */
22
22
  policies?: string[];
23
+ /** The UTC ISO 8601 timestamp at which the account was created. */
24
+ createdAt?: string;
25
+ /** The UTC ISO 8601 timestamp at which the account was last updated. */
26
+ updatedAt?: string;
23
27
  }
24
28
 
25
29
  export interface ListResponse {
@@ -44,6 +48,7 @@ export const ErrorType = {
44
48
  invalid_signature: "invalid_signature",
45
49
  malformed_transaction: "malformed_transaction",
46
50
  not_found: "not_found",
51
+ payment_method_required: "payment_method_required",
47
52
  rate_limit_exceeded: "rate_limit_exceeded",
48
53
  request_canceled: "request_canceled",
49
54
  service_unavailable: "service_unavailable",
@@ -129,6 +134,10 @@ Account names are guaranteed to be unique across all Smart Accounts in the devel
129
134
  * @pattern ^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$
130
135
  */
131
136
  name?: string;
137
+ /** The UTC ISO 8601 timestamp at which the account was created. */
138
+ createdAt?: string;
139
+ /** The UTC ISO 8601 timestamp at which the account was last updated. */
140
+ updatedAt?: string;
132
141
  }
133
142
 
134
143
  export interface EvmCall {
@@ -170,6 +179,7 @@ export const EvmUserOperationStatus = {
170
179
  signed: "signed",
171
180
  broadcast: "broadcast",
172
181
  complete: "complete",
182
+ dropped: "dropped",
173
183
  failed: "failed",
174
184
  } as const;
175
185
 
@@ -601,7 +611,201 @@ export interface EvmAddressCriterion {
601
611
  operator: EvmAddressCriterionOperator;
602
612
  }
603
613
 
604
- export type SignEvmTransactionCriteriaItem = EthValueCriterion | EvmAddressCriterion;
614
+ /**
615
+ * A reference to an established EIP standard. When referencing a `KnownAbiType` within a policy rule configuring an `EvmDataCriterion`, criteria will only decode function data officially documented in the standard. For more information on supported token standards, see the links below.
616
+ - [erc20 - Token Standard](https://eips.ethereum.org/EIPS/eip-20).
617
+ - [erc721 - Non-Fungible Token Standard](https://eips.ethereum.org/EIPS/eip-721).
618
+ - [erc1155 - Multi Token Standard](https://eips.ethereum.org/EIPS/eip-1155).
619
+ */
620
+ export type KnownAbiType = (typeof KnownAbiType)[keyof typeof KnownAbiType];
621
+
622
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
623
+ export const KnownAbiType = {
624
+ erc20: "erc20",
625
+ erc721: "erc721",
626
+ erc1155: "erc1155",
627
+ } as const;
628
+
629
+ /**
630
+ * Parameter definition for ABI functions, errors, and constructors.
631
+ */
632
+ export interface AbiParameter {
633
+ /** The name of the parameter. */
634
+ name?: string;
635
+ /** The canonical type of the parameter. */
636
+ type: string;
637
+ /** The internal Solidity type used by the compiler. */
638
+ internalType?: string;
639
+ /** Used for tuple types. */
640
+ components?: AbiParameter[];
641
+ }
642
+
643
+ /**
644
+ * State mutability of a function in Solidity.
645
+ */
646
+ export type AbiStateMutability = (typeof AbiStateMutability)[keyof typeof AbiStateMutability];
647
+
648
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
649
+ export const AbiStateMutability = {
650
+ pure: "pure",
651
+ view: "view",
652
+ nonpayable: "nonpayable",
653
+ payable: "payable",
654
+ } as const;
655
+
656
+ /**
657
+ * The type of the ABI item, must be `function`.
658
+ */
659
+ export type AbiFunctionType = (typeof AbiFunctionType)[keyof typeof AbiFunctionType];
660
+
661
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
662
+ export const AbiFunctionType = {
663
+ function: "function",
664
+ } as const;
665
+
666
+ /**
667
+ * ABI function type for contract functions.
668
+ */
669
+ export interface AbiFunction {
670
+ /** The type of the ABI item, must be `function`. */
671
+ type: AbiFunctionType;
672
+ /** The name of the ABI function. */
673
+ name: string;
674
+ /** The list of ABI parameters used for this function. */
675
+ inputs: AbiParameter[];
676
+ /** The values returned by this function. */
677
+ outputs: AbiParameter[];
678
+ /** Deprecated. Use pure or view from stateMutability instead. */
679
+ constant?: boolean;
680
+ /** Deprecated. Use payable or nonpayable from `stateMutability` instead. */
681
+ payable?: boolean;
682
+ stateMutability: AbiStateMutability;
683
+ /** Deprecated. Vyper used to provide gas estimates. */
684
+ gas?: number;
685
+ }
686
+
687
+ /**
688
+ * The type of the ABI item.
689
+ */
690
+ export type AbiInputType = (typeof AbiInputType)[keyof typeof AbiInputType];
691
+
692
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
693
+ export const AbiInputType = {
694
+ constructor: "constructor",
695
+ error: "error",
696
+ event: "event",
697
+ fallback: "fallback",
698
+ receive: "receive",
699
+ } as const;
700
+
701
+ /**
702
+ * Generic ABI item type encapsulating all other types besides `function`.
703
+ */
704
+ export interface AbiInput {
705
+ /** The type of the ABI item. */
706
+ type: AbiInputType;
707
+ /** For additional information on the ABI JSON specification, see [the Solidity documentation](https://docs.soliditylang.org/en/latest/abi-spec.html#json). */
708
+ additionalProperties?: unknown;
709
+ }
710
+
711
+ export type AbiItem = AbiFunction | AbiInput;
712
+
713
+ /**
714
+ * Contract ABI Specification following Solidity's external JSON interface format.
715
+ */
716
+ export type Abi = AbiItem[];
717
+
718
+ /**
719
+ * The operator to use for the comparison. The value resolved at the `name` will be on the left-hand side of the operator, and the `value` field will be on the right-hand side.
720
+ */
721
+ export type EvmDataParameterConditionOperator =
722
+ (typeof EvmDataParameterConditionOperator)[keyof typeof EvmDataParameterConditionOperator];
723
+
724
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
725
+ export const EvmDataParameterConditionOperator = {
726
+ ">": ">",
727
+ ">=": ">=",
728
+ "<": "<",
729
+ "<=": "<=",
730
+ "==": "==",
731
+ } as const;
732
+
733
+ export interface EvmDataParameterCondition {
734
+ /** The name of the parameter to check against a transaction's calldata. If name is unknown, or is not named, you may supply an array index, e.g., `0` for first parameter. */
735
+ name: string;
736
+ /** The operator to use for the comparison. The value resolved at the `name` will be on the left-hand side of the operator, and the `value` field will be on the right-hand side. */
737
+ operator: EvmDataParameterConditionOperator;
738
+ /** A single value to compare the value resolved at `name` to. All values are encoded as strings. Refer to the table in the documentation for how values should be encoded, and which operators are supported for each type. */
739
+ value: string;
740
+ }
741
+
742
+ /**
743
+ * The operator to use for the comparison. The value resolved at the `name` will be on the left-hand side of the operator, and the `values` field will be on the right-hand side.
744
+ */
745
+ export type EvmDataParameterConditionListOperator =
746
+ (typeof EvmDataParameterConditionListOperator)[keyof typeof EvmDataParameterConditionListOperator];
747
+
748
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
749
+ export const EvmDataParameterConditionListOperator = {
750
+ in: "in",
751
+ not_in: "not in",
752
+ } as const;
753
+
754
+ export interface EvmDataParameterConditionList {
755
+ /** The name of the parameter to check against a transaction's calldata. If name is unknown, or is not named, you may supply an array index, e.g., `0` for first parameter. */
756
+ name: string;
757
+ /** The operator to use for the comparison. The value resolved at the `name` will be on the left-hand side of the operator, and the `values` field will be on the right-hand side. */
758
+ operator: EvmDataParameterConditionListOperator;
759
+ /** Values to compare against the resolved `name` value. All values are encoded as strings. Refer to the table in the documentation for how values should be encoded, and which operators are supported for each type. */
760
+ values: string[];
761
+ }
762
+
763
+ /**
764
+ * A list of parameter conditions to apply against encoded arguments in the transaction's `data` field.
765
+ */
766
+ export type EvmDataConditionParamsItem = EvmDataParameterCondition | EvmDataParameterConditionList;
767
+
768
+ /**
769
+ * A single condition to apply against the function and encoded arguments in the transaction's `data` field. Each `parameter` configuration must be successfully evaluated against the corresponding function argument in order for a policy to be accepted.
770
+ */
771
+ export interface EvmDataCondition {
772
+ /** The name of a smart contract function being called. */
773
+ function: string;
774
+ /** An optional list of parameter conditions to apply against encoded arguments in the transaction's `data` field. */
775
+ params?: EvmDataConditionParamsItem[];
776
+ }
777
+
778
+ /**
779
+ * The type of criterion to use. This should be `evmData`.
780
+ */
781
+ export type EvmDataCriterionType = (typeof EvmDataCriterionType)[keyof typeof EvmDataCriterionType];
782
+
783
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
784
+ export const EvmDataCriterionType = {
785
+ evmData: "evmData",
786
+ } as const;
787
+
788
+ /**
789
+ * The ABI of the smart contract being called. This can be a partial structure with only specific functions.
790
+ */
791
+ export type EvmDataCriterionAbi = KnownAbiType | Abi;
792
+
793
+ /**
794
+ * A schema for specifying a criterion for the `data` field of an EVM transaction.
795
+ */
796
+ export interface EvmDataCriterion {
797
+ /** The type of criterion to use. This should be `evmData`. */
798
+ type: EvmDataCriterionType;
799
+ /** The ABI of the smart contract being called. This can be a partial structure with only specific functions. */
800
+ abi: EvmDataCriterionAbi;
801
+ /** A list of conditions to apply against the function and encoded arguments in the transaction's `data` field. Each condition must be met in order for this policy to be accepted or rejected. */
802
+ conditions: EvmDataCondition[];
803
+ }
804
+
805
+ export type SignEvmTransactionCriteriaItem =
806
+ | EthValueCriterion
807
+ | EvmAddressCriterion
808
+ | EvmDataCriterion;
605
809
 
606
810
  /**
607
811
  * A schema for specifying criteria for the SignEvmTransaction operation.
@@ -689,7 +893,8 @@ export interface EvmNetworkCriterion {
689
893
  export type SendEvmTransactionCriteriaItem =
690
894
  | EthValueCriterion
691
895
  | EvmAddressCriterion
692
- | EvmNetworkCriterion;
896
+ | EvmNetworkCriterion
897
+ | EvmDataCriterion;
693
898
 
694
899
  /**
695
900
  * A schema for specifying criteria for the SignEvmTransaction operation.
@@ -943,6 +1148,10 @@ Account names are guaranteed to be unique across all Solana accounts in the deve
943
1148
  name?: string;
944
1149
  /** The list of policy IDs that apply to the account. This will include both the project-level policy and the account-level policy, if one exists. */
945
1150
  policies?: string[];
1151
+ /** The ISO 8601 UTC timestamp at which the account was created. */
1152
+ createdAt?: string;
1153
+ /** The ISO 8601 UTC timestamp at which the account was last updated. */
1154
+ updatedAt?: string;
946
1155
  }
947
1156
 
948
1157
  /**
@@ -1190,6 +1399,11 @@ export type BadGatewayErrorResponse = Error;
1190
1399
  */
1191
1400
  export type ServiceUnavailableErrorResponse = Error;
1192
1401
 
1402
+ /**
1403
+ * A payment method is required to complete this operation.
1404
+ */
1405
+ export type PaymentMethodRequiredErrorResponse = Error;
1406
+
1193
1407
  /**
1194
1408
  * Idempotency key conflict.
1195
1409
  */
@@ -1363,6 +1577,11 @@ Account names must be unique across all EVM accounts in the developer's CDP Proj
1363
1577
  * @pattern ^[A-Za-z0-9][A-Za-z0-9-]{0,34}[A-Za-z0-9]$
1364
1578
  */
1365
1579
  name?: string;
1580
+ /**
1581
+ * The ID of the account-level policy to apply to the account.
1582
+ * @pattern ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
1583
+ */
1584
+ accountPolicy?: string;
1366
1585
  };
1367
1586
 
1368
1587
  export type ExportEvmAccountBody = {