@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # CDP SDK Changelog
2
2
 
3
+ ## 1.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#220](https://github.com/coinbase/cdp-sdk/pull/220) [`c91b8da`](https://github.com/coinbase/cdp-sdk/commit/c91b8da383f747de683019a011cbe3453684d6aa) Thanks [@sammccord](https://github.com/sammccord)! - Added support for `EvmDataCriterion` in policies, which can restrict smart contract interactions
8
+
9
+ ## 1.16.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#165](https://github.com/coinbase/cdp-sdk/pull/165) [`b39c739`](https://github.com/coinbase/cdp-sdk/commit/b39c739979e92f97f7dd232e2932442bd0251436) Thanks [@derek-cb](https://github.com/derek-cb)! - Added swap support for EVM Smart Accounts.
14
+
15
+ - [#165](https://github.com/coinbase/cdp-sdk/pull/165) [`b39c739`](https://github.com/coinbase/cdp-sdk/commit/b39c739979e92f97f7dd232e2932442bd0251436) Thanks [@derek-cb](https://github.com/derek-cb)! - Added idempotency support for getSwapPrice and createSwapQuote
16
+
17
+ ### Patch Changes
18
+
19
+ - [#165](https://github.com/coinbase/cdp-sdk/pull/165) [`b39c739`](https://github.com/coinbase/cdp-sdk/commit/b39c739979e92f97f7dd232e2932442bd0251436) Thanks [@derek-cb](https://github.com/derek-cb)! - Fix usage of optional idempotency keys for one-line swap approach.
20
+
21
+ - [#211](https://github.com/coinbase/cdp-sdk/pull/211) [`3a497cf`](https://github.com/coinbase/cdp-sdk/commit/3a497cfee26cd5f143940cb067fa5d438e79c590) Thanks [@0xRAG](https://github.com/0xRAG)! - Updated types for signTypedData to fix TypeError when wrapping CDP Account in viem's toAccount helper
22
+
3
23
  ## 1.15.0
4
24
 
5
25
  ### Minor Changes
package/README.md CHANGED
@@ -393,7 +393,7 @@ const userOperation = await cdp.sendUserOperation({
393
393
 
394
394
  ### EVM Swaps
395
395
 
396
- You can use the CDP SDK to swap tokens on EVM networks.
396
+ You can use the CDP SDK to swap tokens on EVM networks using both regular accounts (EOAs) and smart accounts.
397
397
 
398
398
  The SDK provides three approaches for performing token swaps:
399
399
 
@@ -401,6 +401,7 @@ The SDK provides three approaches for performing token swaps:
401
401
 
402
402
  The simplest approach for performing swaps. Creates and executes the swap in a single line of code:
403
403
 
404
+ **Regular Account (EOA):**
404
405
  ```typescript
405
406
  // Retrieve an existing EVM account with funds already in it
406
407
  const account = await cdp.evm.getOrCreateAccount({ name: "MyExistingFundedAccount" });
@@ -417,6 +418,29 @@ const { transactionHash } = await account.swap({
417
418
  console.log(`Swap executed: ${transactionHash}`);
418
419
  ```
419
420
 
421
+ **Smart Account:**
422
+ ```typescript
423
+ // Create or retrieve a smart account with funds already in it
424
+ const owner = await cdp.evm.getOrCreateAccount({ name: "MyOwnerAccount" });
425
+ const smartAccount = await cdp.evm.getOrCreateSmartAccount({ name: "MyExistingFundedSmartAccount", owner });
426
+
427
+ // Execute a swap directly on a smart account in one line
428
+ const { userOpHash } = await smartAccount.swap({
429
+ network: "base",
430
+ toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
431
+ fromToken: "0x4200000000000000000000000000000000000006", // WETH on Base
432
+ fromAmount: BigInt("1000000000000000000"), // 1 WETH in wei
433
+ slippageBps: 100, // 1% slippage tolerance
434
+ // Optional: paymasterUrl: "https://paymaster.example.com" // For gas sponsorship
435
+ });
436
+
437
+ console.log(`Smart account swap executed: ${userOpHash}`);
438
+
439
+ // Wait for the user operation to complete
440
+ const receipt = await smartAccount.waitForUserOperation({ userOpHash });
441
+ console.log(`Status: ${receipt.status}`);
442
+ ```
443
+
420
444
  #### 2. Get pricing information
421
445
 
422
446
  Use `getSwapPrice` for quick price estimates and display purposes. This is ideal for showing exchange rates without committing to a swap:
@@ -440,10 +464,11 @@ if (swapPrice.liquidityAvailable) {
440
464
 
441
465
  #### 3. Create and execute separately
442
466
 
443
- Use `createSwapQuote` when you need full control over the swap process. This returns complete transaction data for execution:
467
+ Use `account.quoteSwap()` / `smartAccount.quoteSwap()` when you need full control over the swap process. This returns complete transaction data for execution:
444
468
 
445
- **Important:** `createSwapQuote` signals a soft commitment to swap and may reserve funds on-chain. It is rate-limited more strictly than `getSwapPrice` to prevent abuse.
469
+ **Important:** `quoteSwap()` signals a soft commitment to swap and may reserve funds on-chain. It is rate-limited more strictly than `getSwapPrice` to prevent abuse.
446
470
 
471
+ **Regular Account (EOA):**
447
472
  ```typescript
448
473
  // Retrieve an existing EVM account with funds already in it
449
474
  const account = await cdp.evm.getOrCreateAccount({ name: "MyExistingFundedAccount" });
@@ -463,21 +488,51 @@ if (!swapQuote.liquidityAvailable) {
463
488
  return;
464
489
  }
465
490
 
466
- // Step 3: Execute using the quote (two options)
467
- // Option 3A: Use the execute method on the quote
468
- const { transactionHash } = await swapQuote.execute({});
491
+ // Step 3: Execute using the quote
492
+ const { transactionHash } = await swapQuote.execute();
493
+ ```
469
494
 
470
- // Option 3B: Pass the quote to account.swap()
471
- const { transactionHash } = await account.swap({
472
- swapQuote: swapQuote
495
+ **Smart Account:**
496
+ ```typescript
497
+ // Create or retrieve a smart account with funds already in it
498
+ const owner = await cdp.evm.getOrCreateAccount({ name: "MyOwnerAccount" });
499
+ const smartAccount = await cdp.evm.getOrCreateSmartAccount({ name: "MyExistingFundedSmartAccount", owner });
500
+
501
+ // Step 1: Create a swap quote with full transaction details for smart account
502
+ const swapQuote = await smartAccount.quoteSwap({
503
+ network: "base",
504
+ toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC
505
+ fromToken: "0x4200000000000000000000000000000000000006", // WETH
506
+ fromAmount: BigInt("1000000000000000000"), // 1 WETH in wei
507
+ slippageBps: 100, // 1% slippage tolerance
473
508
  });
509
+
510
+ // Step 2: Check if liquidity is available, and/or perform other analysis on the swap quote
511
+ if (!swapQuote.liquidityAvailable) {
512
+ console.error("Insufficient liquidity for swap");
513
+ return;
514
+ }
515
+
516
+ // Step 3: Execute using the quote
517
+ const { userOpHash } = await swapQuote.execute();
518
+
519
+ // Wait for the user operation to complete
520
+ const receipt = await smartAccount.waitForUserOperation({ userOpHash });
521
+ console.log(`Status: ${receipt.status}`);
474
522
  ```
475
523
 
476
524
  #### When to use each approach:
477
525
 
478
- - **All-in-one (`account.swap()`)**: Best for most use cases. Simple, handles everything automatically.
526
+ - **All-in-one (`account.swap()` / `smartAccount.swap()`)**: Best for most use cases. Simple, handles everything automatically.
479
527
  - **Price only (`getSwapPrice`)**: For displaying exchange rates, building price calculators, or checking liquidity without executing. Suitable when frequent price updates are needed - although the data may be slightly less precise.
480
- - **Create then execute (`createSwapQuote`)**: When you need to inspect swap details, implement custom logic, or handle complex scenarios before execution. Note: May reserve funds on-chain and is more strictly rate-limited.
528
+ - **Create then execute (`account.quoteSwap()` / `smartAccount.quoteSwap()`)**: When you need to inspect swap details, implement custom logic, or handle complex scenarios before execution. Note: May reserve funds on-chain and is more strictly rate-limited.
529
+
530
+ #### Key differences between Regular Accounts (EOAs) and Smart Accounts:
531
+
532
+ - **Regular accounts (EOAs)** return `transactionHash` and execute immediately on-chain
533
+ - **Smart accounts** return `userOpHash` and execute via user operations with optional gas sponsorship through paymasters
534
+ - **Smart accounts** require an owner account for signing operations
535
+ - **Smart accounts** support batch operations and advanced account abstraction features
481
536
 
482
537
  All approaches handle Permit2 signatures automatically for ERC20 token swaps. Make sure tokens have proper allowances set for the Permit2 contract before swapping.
483
538
 
@@ -485,18 +540,25 @@ All approaches handle Permit2 signatures automatically for ERC20 token swaps. Ma
485
540
 
486
541
  To help you get started with token swaps in your application, we provide the following fully-working examples demonstrating different scenarios:
487
542
 
488
- **Core swap patterns:**
489
- - [Get a swap price estimate](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/getSwapPrice.ts) - Price estimation without commitment
490
- - [Create a concrete swap quote for execution](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/createSwapQuote.ts) - Direct API usage with explicit taker
491
- - [Execute a swap transaction using CDP Wallets (RECOMMENDED)](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/account.swap.ts) - All-in-one swap execution
492
-
493
- **Account-based swap examples:**
543
+ **Regular account (EOA) swap examples:**
544
+ - [Execute a swap transaction using account (RECOMMENDED)](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/account.swap.ts) - All-in-one regular account swap execution
494
545
  - [Quote swap using account convenience method](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/account.quoteSwap.ts) - Account convenience method for creating quotes
495
546
  - [Two-step quote and execute process](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/account.quoteSwapAndExecute.ts) - Detailed two-step approach with analysis
496
547
 
497
- **External wallet integration:**
498
- - [Execute a swap transaction using an external account (Viem)](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/viem.swap.ts) - Full swap execution with viem wallets
499
- - [Create swap quotes using Viem wallets](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/viem.quoteSwap.ts) - Quote creation with external wallets
548
+ **Smart account swap examples:**
549
+ - [Execute a swap transaction using smart account (RECOMMENDED)](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/smartAccount.swap.ts) - All-in-one smart account swap execution with user operations and optional paymaster support
550
+ - [Quote swap using smart account convenience method](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/smartAccount.quoteSwap.ts) - Smart account convenience method for creating quotes
551
+ - [Two-step quote and execute process](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/smartAccount.quoteSwapAndExecute.ts) - Detailed two-step approach with analysis
552
+
553
+ **BYO wallet (viem) regular account (EOA) swap examples:**
554
+ - [Execute a swap transaction using viem account](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/viem.account.swap.ts) - All-in-one swap execution with viem wallets
555
+ - [Two-step quote and execute process using viem account](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/viem.account.quoteSwapAndExecute.ts) - Detailed two-step approach with viem wallets
556
+
557
+ **BYO wallet (viem + account abstraction) smart account swap examples:**
558
+ - [Execute a swap transaction using viem smart account](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/viem.smartAccount.swap.ts) - All-in-one smart account swap with custom bundler/paymaster setup
559
+ - [Two-step quote and execute process using viem smart account](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/viem.smartAccount.quoteSwapAndExecute.ts) - Advanced account abstraction integration
560
+
561
+ **Note:** The viem smart account examples require additional dependencies (`permissionless` package) and external service setup (bundler, optional paymaster). For simpler smart account usage, consider CDP's built-in smart account features instead.
500
562
 
501
563
  ### Transferring tokens
502
564
 
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toEvmServerAccount = toEvmServerAccount;
4
4
  const viem_1 = require("viem");
5
+ const toNetworkScopedEvmServerAccount_js_1 = require("./toNetworkScopedEvmServerAccount.js");
5
6
  const fund_js_1 = require("../../actions/evm/fund/fund.js");
6
7
  const quoteFund_js_1 = require("../../actions/evm/fund/quoteFund.js");
7
8
  const waitForFundOperationReceipt_js_1 = require("../../actions/evm/fund/waitForFundOperationReceipt.js");
@@ -42,13 +43,19 @@ function toEvmServerAccount(apiClient, options) {
42
43
  });
43
44
  return result.signedTransaction;
44
45
  },
45
- async signTypedData(message) {
46
- if (!message.types.EIP712Domain) {
47
- message.types.EIP712Domain = (0, viem_1.getTypesForEIP712Domain)({
48
- domain: message.domain,
49
- });
50
- }
51
- const result = await apiClient.signEvmTypedData(options.account.address, message);
46
+ async signTypedData(parameters) {
47
+ const { domain = {}, message, primaryType } = parameters;
48
+ const types = {
49
+ EIP712Domain: (0, viem_1.getTypesForEIP712Domain)({ domain }),
50
+ ...parameters.types,
51
+ };
52
+ const openApiMessage = {
53
+ domain: domain,
54
+ types,
55
+ primaryType,
56
+ message,
57
+ };
58
+ const result = await apiClient.signEvmTypedData(options.account.address, openApiMessage);
52
59
  return result.signature;
53
60
  },
54
61
  async transfer(transferArgs) {
@@ -103,6 +110,12 @@ function toEvmServerAccount(apiClient, options) {
103
110
  name: options.account.name,
104
111
  type: "evm-server",
105
112
  policies: options.account.policies,
113
+ __experimental_useNetwork: async (networkOrRpcUrl) => {
114
+ return (0, toNetworkScopedEvmServerAccount_js_1.toNetworkScopedEvmServerAccount)(apiClient, {
115
+ account,
116
+ network: networkOrRpcUrl,
117
+ });
118
+ },
106
119
  };
107
120
  return account;
108
121
  }
@@ -1 +1 @@
1
- {"version":3,"file":"toEvmServerAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmServerAccount.ts"],"names":[],"mappings":";;AA0DA,gDAiGC;AA3JD,+BAAmG;AAEnG,4DAAmE;AAEnE,sEAAkF;AAElF,0GAI+D;AAC/D,iFAIgD;AAChD,yEAI4C;AAC5C,6EAAuE;AACvE,kFAA4E;AAC5E,0FAAoF;AACpF,sGAAgG;AAChG,wEAAkE;AAwBlE;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,SAA+B,EAC/B,OAAkC;IAElC,MAAM,OAAO,GAAqB;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAkB;QAC3C,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE;YAC3B,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE;gBACrE,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;aAC5B,CAAC,CAAC;YACH,OAAO,MAAM,CAAC,SAAgB,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,UAA0B;YACnC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE;gBAClE,IAAI,EAAE,UAAU,CAAC,IAAI;aACtB,CAAC,CAAC;YACH,OAAO,MAAM,CAAC,SAAgB,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,eAAe,CAAC,WAAoC;YACxD,MAAM,MAAM,GAA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,EAAE,OAAO,CAAC,CAAC;QACzD,CAAC;QACD,KAAK,CAAC,SAAS,CAAC,OAAgC;YAC9C,OAAO,IAAA,oCAAe,EAAC,SAAS,EAAE;gBAChC,GAAG,OAAO;gBACV,KAAK,EAAE,IAAI,CAAC,OAAO;aACpB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,OAA2B;YACpC,OAAO,IAAA,4CAAmB,EAAC,SAAS,EAAE;gBACpC,GAAG,OAAO;gBACV,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,wCAAwC;aAC9D,CAAC,CAAC;QACL,CAAC;QACD,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAC1B,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;QAClC,yBAAyB,EAAE,KAAK,EAAE,eAAuB,EAAE,EAAE;YAC3D,OAAO,IAAA,oEAA+B,EAAC,SAAS,EAAE;gBAChD,OAAO;gBACP,OAAO,EAAE,eAAe;aACzB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toEvmSmartAccount = toEvmSmartAccount;
4
+ const toNetworkScopedEvmSmartAccount_js_1 = require("./toNetworkScopedEvmSmartAccount.js");
4
5
  const fund_js_1 = require("../../actions/evm/fund/fund.js");
5
6
  const quoteFund_js_1 = require("../../actions/evm/fund/quoteFund.js");
6
7
  const waitForFundOperationReceipt_js_1 = require("../../actions/evm/fund/waitForFundOperationReceipt.js");
@@ -8,6 +9,8 @@ const getUserOperation_js_1 = require("../../actions/evm/getUserOperation.js");
8
9
  const listTokenBalances_js_1 = require("../../actions/evm/listTokenBalances.js");
9
10
  const requestFaucet_js_1 = require("../../actions/evm/requestFaucet.js");
10
11
  const sendUserOperation_js_1 = require("../../actions/evm/sendUserOperation.js");
12
+ const createSwapQuote_js_1 = require("../../actions/evm/swap/createSwapQuote.js");
13
+ const sendSwapOperation_js_1 = require("../../actions/evm/swap/sendSwapOperation.js");
11
14
  const smartAccountTransferStrategy_js_1 = require("../../actions/evm/transfer/smartAccountTransferStrategy.js");
12
15
  const transfer_js_1 = require("../../actions/evm/transfer/transfer.js");
13
16
  const waitForUserOperation_js_1 = require("../../actions/evm/waitForUserOperation.js");
@@ -75,8 +78,31 @@ function toEvmSmartAccount(apiClient, options) {
75
78
  async waitForFundOperationReceipt(options) {
76
79
  return (0, waitForFundOperationReceipt_js_1.waitForFundOperationReceipt)(apiClient, options);
77
80
  },
81
+ async quoteSwap(options) {
82
+ return (0, createSwapQuote_js_1.createSwapQuote)(apiClient, {
83
+ ...options,
84
+ taker: this.address, // Always use smart account's address as taker
85
+ signerAddress: this.owners[0].address, // Always use owner's address as signer
86
+ smartAccount: account, // Pass smart account for execute method support
87
+ });
88
+ },
89
+ async swap(options) {
90
+ return (0, sendSwapOperation_js_1.sendSwapOperation)(apiClient, {
91
+ ...options,
92
+ smartAccount: account,
93
+ taker: this.address, // Always use smart account's address as taker
94
+ signerAddress: this.owners[0].address, // Always use owner's address as signer
95
+ });
96
+ },
78
97
  name: options.smartAccount.name,
79
98
  type: "evm-smart",
99
+ __experimental_useNetwork: async (networkOrRpcUrl) => {
100
+ return (0, toNetworkScopedEvmSmartAccount_js_1.toNetworkScopedEvmSmartAccount)(apiClient, {
101
+ smartAccount: account,
102
+ owner: options.owner,
103
+ network: networkOrRpcUrl,
104
+ });
105
+ },
80
106
  };
81
107
  return account;
82
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"toEvmSmartAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmSmartAccount.ts"],"names":[],"mappings":";;AA+DA,8CAwEC;AAvID,4DAAmE;AAEnE,sEAAkF;AAElF,0GAI+D;AAC/D,+EAAyE;AACzE,iFAIgD;AA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D,KAAK,CAAC,SAAS,CAAC,OAAqC;YACnD,OAAO,IAAA,oCAAe,EAAC,SAAS,EAAE;gBAChC,GAAG,OAAO;gBACV,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,8CAA8C;gBACnE,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,uCAAuC;gBAC9E,YAAY,EAAE,OAAO,EAAE,gDAAgD;aACxE,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,OAAgC;YACzC,OAAO,IAAA,wCAAiB,EAAC,SAAS,EAAE;gBAClC,GAAG,OAAO;gBACV,YAAY,EAAE,OAAO;gBACrB,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,8CAA8C;gBACnE,aAAa,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,uCAAuC;aAC/E,CAAC,CAAC;QACL,CAAC;QAED,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI;QAC/B,IAAI,EAAE,WAAW;QACjB,yBAAyB,EAAE,KAAK,EAAE,eAAuB,EAAE,EAAE;YAC3D,OAAO,IAAA,kEAA8B,EAAC,SAAS,EAAE;gBAC/C,YAAY,EAAE,OAAO;gBACrB,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,OAAO,EAAE,eAAe;aACzB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toNetworkScopedEvmServerAccount = toNetworkScopedEvmServerAccount;
4
+ /**
5
+ * Creates a Network-scoped Server-managed EvmAccount instance from an existing EvmAccount.
6
+ * Use this to interact with previously deployed EvmAccounts on a specific network.
7
+ *
8
+ * @param {CdpOpenApiClientType} apiClient - The API client.
9
+ * @param {ToNetworkScopedEvmServerAccountOptions} options - Configuration options.
10
+ * @param {EvmServerAccount} options.account - The EvmServerAccount that was previously created.
11
+ * @param {string} options.network - The network to scope the account to.
12
+ * @returns {NetworkScopedEvmServerAccount} A configured NetworkScopedEvmServerAccount instance ready for signing.
13
+ */
14
+ function toNetworkScopedEvmServerAccount(apiClient, options) {
15
+ const account = {
16
+ address: options.account.address,
17
+ network: options.network,
18
+ signMessage: options.account.signMessage,
19
+ sign: options.account.sign,
20
+ signTransaction: options.account.signTransaction,
21
+ signTypedData: options.account.signTypedData,
22
+ name: options.account.name,
23
+ type: "evm-server",
24
+ policies: options.account.policies,
25
+ };
26
+ return account;
27
+ }
28
+ //# sourceMappingURL=toNetworkScopedEvmServerAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toNetworkScopedEvmServerAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toNetworkScopedEvmServerAccount.ts"],"names":[],"mappings":";;AAwBA,0EAiBC;AA3BD;;;;;;;;;GASG;AACH,SAAgB,+BAA+B,CAC7C,SAA+B,EAC/B,OAA+C;IAE/C,MAAM,OAAO,GAAkC;QAC7C,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAkB;QAC3C,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW;QACxC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAC1B,eAAe,EAAE,OAAO,CAAC,OAAO,CAAC,eAAe;QAChD,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa;QAC5C,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAC1B,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;KACnC,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toNetworkScopedEvmSmartAccount = toNetworkScopedEvmSmartAccount;
4
+ /**
5
+ * Creates a NetworkScopedEvmSmartAccount instance from an existing EvmSmartAccount and owner.
6
+ * Use this to interact with previously deployed EvmSmartAccounts, rather than creating new ones.
7
+ *
8
+ * The owner must be the original owner of the evm smart account.
9
+ *
10
+ * @param {CdpOpenApiClientType} apiClient - The API client.
11
+ * @param {ToEvmSmartAccountOptions} options - Configuration options.
12
+ * @param {EvmSmartAccount} options.smartAccount - The deployed evm smart account.
13
+ * @param {EvmAccount} options.owner - The owner which signs for the smart account.
14
+ * @returns {NetworkScopedEvmSmartAccount} A configured NetworkScopedEvmSmartAccount instance ready for user operation submission.
15
+ */
16
+ function toNetworkScopedEvmSmartAccount(apiClient, options) {
17
+ const account = {
18
+ address: options.smartAccount.address,
19
+ network: options.network,
20
+ owners: [options.owner],
21
+ name: options.smartAccount.name,
22
+ type: "evm-smart",
23
+ };
24
+ return account;
25
+ }
26
+ //# sourceMappingURL=toNetworkScopedEvmSmartAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toNetworkScopedEvmSmartAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toNetworkScopedEvmSmartAccount.ts"],"names":[],"mappings":";;AA2BA,wEAaC;AAzBD;;;;;;;;;;;GAWG;AACH,SAAgB,8BAA8B,CAC5C,SAA+B,EAC/B,OAAiC;IAEjC,MAAM,OAAO,GAAiC;QAC5C,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,OAAO;QACrC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QACvB,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI;QAC/B,IAAI,EAAE,WAAW;KAClB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signAndWrapTypedDataForSmartAccount = signAndWrapTypedDataForSmartAccount;
4
+ exports.createReplaySafeTypedData = createReplaySafeTypedData;
5
+ exports.createSmartAccountSignatureWrapper = createSmartAccountSignatureWrapper;
6
+ const viem_1 = require("viem");
7
+ /**
8
+ * Signs and wraps an EIP-712 message for a smart account using the required Coinbase Smart Wallet signature format.
9
+ *
10
+ * **Important: Coinbase Smart Wallet Contract Requirements**
11
+ *
12
+ * Due to the Coinbase Smart Wallet contract implementation (ERC-1271), CDP Smart Wallets have
13
+ * specific requirements for EIP-712 message signing:
14
+ *
15
+ * 1. **Replay-Safe Hashing**: All typed messages must be wrapped in a replay-safe hash that
16
+ * includes the chain ID and smart account address. This prevents the same signature from
17
+ * being valid across different chains or accounts.
18
+ *
19
+ * 2. **Signature Wrapping**: The resulting signature must be wrapped in a `SignatureWrapper`
20
+ * struct that identifies which owner signed and contains the signature data in the format
21
+ * expected by the smart contract's `isValidSignature()` method.
22
+ *
23
+ * This function handles both requirements automatically, making it safe and convenient for
24
+ * developers to sign EIP-712 messages with CDP Smart Wallets.
25
+ *
26
+ * @param {CdpOpenApiClientType} client - The CDP API client
27
+ * @param {SignAndWrapTypedDataForSmartAccountOptions} options - Parameters for signing and wrapping the EIP-712 message.
28
+ * @returns A promise that resolves to the signature that can be used with smart contracts.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const result = await signAndWrapTypedDataForSmartAccount(client, {
33
+ * smartAccount: smartAccount,
34
+ * chainId: 1n,
35
+ * typedData: {
36
+ * domain: {
37
+ * name: "Permit2",
38
+ * chainId: 1,
39
+ * verifyingContract: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
40
+ * },
41
+ * types: {
42
+ * EIP712Domain: [
43
+ * { name: "name", type: "string" },
44
+ * { name: "chainId", type: "uint256" },
45
+ * { name: "verifyingContract", type: "address" },
46
+ * ],
47
+ * PermitTransferFrom: [
48
+ * { name: "permitted", type: "TokenPermissions" },
49
+ * { name: "spender", type: "address" },
50
+ * { name: "nonce", type: "uint256" },
51
+ * { name: "deadline", type: "uint256" },
52
+ * ],
53
+ * TokenPermissions: [
54
+ * { name: "token", type: "address" },
55
+ * { name: "amount", type: "uint256" },
56
+ * ],
57
+ * },
58
+ * primaryType: "PermitTransferFrom",
59
+ * message: {
60
+ * permitted: {
61
+ * token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
62
+ * amount: "1000000",
63
+ * },
64
+ * spender: "0xFfFfFfFFfFFfFFfFFfFFFFFffFFFffffFfFFFfFf",
65
+ * nonce: "0",
66
+ * deadline: "1717123200",
67
+ * },
68
+ * },
69
+ * });
70
+ *
71
+ * // Use result.signature for smart contract calls
72
+ * console.log(`Signature: ${result.signature}`);
73
+ * ```
74
+ */
75
+ async function signAndWrapTypedDataForSmartAccount(client, options) {
76
+ const { smartAccount, chainId, typedData, ownerIndex = 0n } = options;
77
+ // Create the replay-safe typed data
78
+ const replaySafeTypedData = createReplaySafeTypedData({
79
+ typedData,
80
+ chainId,
81
+ smartAccountAddress: smartAccount.address,
82
+ });
83
+ // Sign the replay-safe typed data with the smart account owner
84
+ const owner = smartAccount.owners[Number(ownerIndex)];
85
+ const signature = await client.signEvmTypedData(owner.address, replaySafeTypedData, options.idempotencyKey);
86
+ // Wrap the signature in the format expected by the smart contract
87
+ const wrappedSignature = createSmartAccountSignatureWrapper({
88
+ signatureHex: signature.signature,
89
+ ownerIndex,
90
+ });
91
+ return {
92
+ signature: wrappedSignature,
93
+ };
94
+ }
95
+ /**
96
+ * Creates a replay-safe EIP-712 typed data structure by wrapping the original typed data with
97
+ * chain ID and smart account address.
98
+ *
99
+ * **Coinbase Smart Wallet Requirement**: Due to the Coinbase Smart Wallet contract's ERC-1271
100
+ * implementation, all EIP-712 messages must be wrapped in a replay-safe hash before signing.
101
+ * This prevents signature replay attacks across different chains or smart account addresses.
102
+ *
103
+ * The smart contract's `isValidSignature()` method expects signatures to be validated against
104
+ * this replay-safe hash, not the original message hash.
105
+ *
106
+ * @param params - The replay-safe hash parameters
107
+ * @param params.typedData - The original EIP-712 typed data to make replay-safe
108
+ * @param params.chainId - The chain ID for replay protection
109
+ * @param params.smartAccountAddress - The smart account address for additional context
110
+ * @returns The EIP-712 typed data structure for the replay-safe hash
111
+ */
112
+ function createReplaySafeTypedData({ typedData, chainId, smartAccountAddress, }) {
113
+ // First hash the original typed data
114
+ const originalHash = (0, viem_1.hashTypedData)(typedData);
115
+ // Create and return the replay-safe typed data structure
116
+ return {
117
+ domain: {
118
+ name: "Coinbase Smart Wallet",
119
+ version: "1",
120
+ chainId: Number(chainId),
121
+ verifyingContract: smartAccountAddress,
122
+ },
123
+ types: {
124
+ EIP712Domain: [
125
+ { name: "name", type: "string" },
126
+ { name: "version", type: "string" },
127
+ { name: "chainId", type: "uint256" },
128
+ { name: "verifyingContract", type: "address" },
129
+ ],
130
+ CoinbaseSmartWalletMessage: [{ name: "hash", type: "bytes32" }],
131
+ },
132
+ primaryType: "CoinbaseSmartWalletMessage",
133
+ message: {
134
+ hash: originalHash,
135
+ },
136
+ };
137
+ }
138
+ /**
139
+ * Builds a signature wrapper for Coinbase Smart Wallets by decomposing a hex signature
140
+ * into r, s, v components and encoding them in the format expected by the smart contract.
141
+ *
142
+ * All signatures on Coinbase Smart Wallets must be wrapped in this format to identify
143
+ * which owner signed and provide the signature data.
144
+ *
145
+ * @param params - The signature parameters
146
+ * @param params.signatureHex - The hex signature to wrap (65 bytes: r + s + v)
147
+ * @param params.ownerIndex - The index of the owner that signed (from MultiOwnable.ownerAtIndex)
148
+ * @returns The encoded signature wrapper in the format expected by the smart contract
149
+ */
150
+ function createSmartAccountSignatureWrapper({ signatureHex, ownerIndex, }) {
151
+ // Decompose 65-byte hex signature into r (32 bytes), s (32 bytes), v (1 byte)
152
+ const r = (0, viem_1.sliceHex)(signatureHex, 0, 32);
153
+ const s = (0, viem_1.sliceHex)(signatureHex, 32, 64);
154
+ const v = Number(`0x${signatureHex.slice(130, 132)}`); // 130 = 2 + 64 + 64
155
+ const signatureData = (0, viem_1.encodePacked)(["bytes32", "bytes32", "uint8"], [r, s, v]);
156
+ return (0, viem_1.encodeAbiParameters)([SignatureWrapperStruct], [
157
+ {
158
+ ownerIndex: Number(ownerIndex),
159
+ signatureData,
160
+ },
161
+ ]);
162
+ }
163
+ /**
164
+ * The ABI structure for the SignatureWrapper struct expected by Coinbase Smart Wallets.
165
+ * This matches the struct defined in the smart contract:
166
+ *
167
+ * struct SignatureWrapper {
168
+ * uint256 ownerIndex;
169
+ * bytes signatureData;
170
+ * }
171
+ */
172
+ const SignatureWrapperStruct = {
173
+ components: [
174
+ {
175
+ name: "ownerIndex",
176
+ type: "uint8",
177
+ },
178
+ {
179
+ name: "signatureData",
180
+ type: "bytes",
181
+ },
182
+ ],
183
+ name: "SignatureWrapper",
184
+ type: "tuple",
185
+ };
186
+ //# sourceMappingURL=signAndWrapTypedDataForSmartAccount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signAndWrapTypedDataForSmartAccount.js","sourceRoot":"","sources":["../../../actions/evm/signAndWrapTypedDataForSmartAccount.ts"],"names":[],"mappings":";;AAqGA,kFA8BC;AAmBD,8DAkCC;AAcD,gFAuBC;AA7ND,+BAAkF;AAiClF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACI,KAAK,UAAU,mCAAmC,CACvD,MAA4B,EAC5B,OAAmD;IAEnD,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAEtE,oCAAoC;IACpC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;QACpD,SAAS;QACT,OAAO;QACP,mBAAmB,EAAE,YAAY,CAAC,OAAc;KACjD,CAAC,CAAC;IAEH,+DAA+D;IAC/D,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAC7C,KAAK,CAAC,OAAO,EACb,m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ACxC,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,YAAY,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACzC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,oBAAoB;IAE3E,MAAM,aAAa,GAAG,IAAA,mBAAY,EAAC,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAE/E,OAAO,IAAA,0BAAmB,EACxB,CAAC,sBAAsB,CAAC,EACxB;QACE;YACE,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;YAC9B,aAAa;SACd;KACF,CACK,CAAC;AACX,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,sBAAsB,GAAG;IAC7B,UAAU,EAAE;QACV;YACE,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,OAAO;SACd;QACD;YACE,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,OAAO;SACd;KACF;IACD,IAAI,EAAE,kBAAkB;IACxB,IAAI,EAAE,OAAO;CACL,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSwapQuote = createSwapQuote;
4
+ const sendSwapOperation_js_1 = require("./sendSwapOperation.js");
4
5
  const sendSwapTransaction_js_1 = require("./sendSwapTransaction.js");
5
6
  /**
6
7
  * Creates a quote for a swap between two tokens on an EVM network.
@@ -38,7 +39,7 @@ async function createSwapQuote(client, options) {
38
39
  signerAddress: options.signerAddress,
39
40
  gasPrice: options.gasPrice?.toString(),
40
41
  slippageBps: options.slippageBps,
41
- });
42
+ }, options.idempotencyKey);
42
43
  // Check if liquidity is unavailable
43
44
  if (!response.liquidityAvailable) {
44
45
  // Return the SwapUnavailableResult
@@ -112,13 +113,30 @@ async function createSwapQuote(client, options) {
112
113
  : undefined,
113
114
  // Add the execute method
114
115
  execute: async (executeOptions = {}) => {
115
- const { transactionHash } = await (0, sendSwapTransaction_js_1.sendSwapTransaction)(client, {
116
- address: options.signerAddress || taker, // Use signerAddress for smart accounts, taker for EOAs
117
- network: result.network,
118
- swapQuote: result,
119
- idempotencyKey: executeOptions.idempotencyKey,
120
- });
121
- return { transactionHash };
116
+ if (options.smartAccount) {
117
+ // Smart account execution - use sendSwapOperation
118
+ const userOpResult = await (0, sendSwapOperation_js_1.sendSwapOperation)(client, {
119
+ smartAccount: options.smartAccount,
120
+ network: result.network,
121
+ swapQuote: result,
122
+ idempotencyKey: executeOptions.idempotencyKey,
123
+ });
124
+ return {
125
+ userOpHash: userOpResult.userOpHash,
126
+ smartAccountAddress: userOpResult.smartAccountAddress,
127
+ status: userOpResult.status,
128
+ };
129
+ }
130
+ else {
131
+ // EOA execution - use sendSwapTransaction
132
+ const { transactionHash } = await (0, sendSwapTransaction_js_1.sendSwapTransaction)(client, {
133
+ address: taker,
134
+ network: result.network,
135
+ swapQuote: result,
136
+ idempotencyKey: executeOptions.idempotencyKey,
137
+ });
138
+ return { transactionHash };
139
+ }
122
140
  },
123
141
  };
124
142
  return result;