@coinbase/cdp-sdk 1.8.0 → 1.9.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 (113) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +182 -105
  3. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  4. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  5. package/_cjs/accounts/solana/toSolanaAccount.js +7 -0
  6. package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
  7. package/_cjs/actions/evm/transfer/accountTransferStrategy.js +30 -63
  8. package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  9. package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
  10. package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
  11. package/_cjs/actions/evm/transfer/transfer.js +2 -39
  12. package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
  13. package/_cjs/actions/evm/transfer/utils.js +0 -12
  14. package/_cjs/actions/evm/transfer/utils.js.map +1 -1
  15. package/_cjs/actions/solana/constants.js +9 -0
  16. package/_cjs/actions/solana/constants.js.map +1 -0
  17. package/_cjs/actions/solana/transfer.js +117 -0
  18. package/_cjs/actions/solana/transfer.js.map +1 -0
  19. package/_cjs/actions/solana/utils.js +66 -0
  20. package/_cjs/actions/solana/utils.js.map +1 -0
  21. package/_cjs/analytics.js +2 -0
  22. package/_cjs/analytics.js.map +1 -1
  23. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +35 -4
  24. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  25. package/_cjs/openapi-client/generated/index.msw.js +3 -3
  26. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  27. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +121 -36
  28. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
  29. package/_cjs/policies/schema.js +60 -1
  30. package/_cjs/policies/schema.js.map +1 -1
  31. package/_cjs/version.js +1 -1
  32. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  33. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  34. package/_esm/accounts/solana/toSolanaAccount.js +7 -0
  35. package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
  36. package/_esm/actions/evm/transfer/accountTransferStrategy.js +31 -64
  37. package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  38. package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
  39. package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
  40. package/_esm/actions/evm/transfer/transfer.js +2 -39
  41. package/_esm/actions/evm/transfer/transfer.js.map +1 -1
  42. package/_esm/actions/evm/transfer/utils.js +0 -11
  43. package/_esm/actions/evm/transfer/utils.js.map +1 -1
  44. package/_esm/actions/solana/constants.js +6 -0
  45. package/_esm/actions/solana/constants.js.map +1 -0
  46. package/_esm/actions/solana/transfer.js +114 -0
  47. package/_esm/actions/solana/transfer.js.map +1 -0
  48. package/_esm/actions/solana/utils.js +61 -0
  49. package/_esm/actions/solana/utils.js.map +1 -0
  50. package/_esm/analytics.js +2 -0
  51. package/_esm/analytics.js.map +1 -1
  52. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +34 -3
  53. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  54. package/_esm/openapi-client/generated/index.msw.js +3 -3
  55. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  56. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +116 -35
  57. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
  58. package/_esm/policies/schema.js +59 -0
  59. package/_esm/policies/schema.js.map +1 -1
  60. package/_esm/version.js +1 -1
  61. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  62. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
  63. package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
  64. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +2 -2
  65. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
  66. package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +2 -2
  67. package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
  68. package/_types/actions/evm/transfer/transfer.d.ts +6 -4
  69. package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
  70. package/_types/actions/evm/transfer/types.d.ts +7 -52
  71. package/_types/actions/evm/transfer/types.d.ts.map +1 -1
  72. package/_types/actions/evm/transfer/utils.d.ts +0 -619
  73. package/_types/actions/evm/transfer/utils.d.ts.map +1 -1
  74. package/_types/actions/evm/types.d.ts +140 -68
  75. package/_types/actions/evm/types.d.ts.map +1 -1
  76. package/_types/actions/solana/constants.d.ts +6 -0
  77. package/_types/actions/solana/constants.d.ts.map +1 -0
  78. package/_types/actions/solana/transfer.d.ts +36 -0
  79. package/_types/actions/solana/transfer.d.ts.map +1 -0
  80. package/_types/actions/solana/types.d.ts +27 -0
  81. package/_types/actions/solana/types.d.ts.map +1 -1
  82. package/_types/actions/solana/utils.d.ts +34 -0
  83. package/_types/actions/solana/utils.d.ts.map +1 -0
  84. package/_types/analytics.d.ts.map +1 -1
  85. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +95 -17
  86. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  87. package/_types/openapi-client/generated/index.msw.d.ts +3 -3
  88. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  89. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +5 -1
  90. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
  91. package/_types/policies/schema.d.ts +630 -0
  92. package/_types/policies/schema.d.ts.map +1 -1
  93. package/_types/version.d.ts +1 -1
  94. package/accounts/evm/toEvmServerAccount.ts +7 -6
  95. package/accounts/evm/toEvmSmartAccount.ts +1 -2
  96. package/accounts/solana/toSolanaAccount.ts +7 -0
  97. package/actions/evm/transfer/accountTransferStrategy.ts +38 -78
  98. package/actions/evm/transfer/smartAccountTransferStrategy.ts +43 -63
  99. package/actions/evm/transfer/transfer.ts +10 -51
  100. package/actions/evm/transfer/types.ts +8 -66
  101. package/actions/evm/transfer/utils.ts +0 -13
  102. package/actions/evm/types.ts +143 -78
  103. package/actions/solana/constants.ts +6 -0
  104. package/actions/solana/transfer.ts +219 -0
  105. package/actions/solana/types.ts +28 -0
  106. package/actions/solana/utils.ts +79 -0
  107. package/analytics.ts +2 -0
  108. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +134 -18
  109. package/openapi-client/generated/index.msw.ts +3 -3
  110. package/openapi-client/generated/policy-engine/policy-engine.msw.ts +199 -56
  111. package/package.json +2 -1
  112. package/policies/schema.ts +83 -0
  113. package/version.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CDP SDK Changelog
2
2
 
3
+ ## 1.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#128](https://github.com/coinbase/cdp-sdk/pull/128) [`bd4d1d6`](https://github.com/coinbase/cdp-sdk/commit/bd4d1d6855627e24bd4b51937e40df27a2595559) Thanks [@0xRAG](https://github.com/0xRAG)! - Added transfer method to Solana account to easily send tokens on Solana
8
+
9
+ - [#133](https://github.com/coinbase/cdp-sdk/pull/133) [`438d967`](https://github.com/coinbase/cdp-sdk/commit/438d967401c06469bfc44c581a6c0994f77c0f9e) Thanks [@0xRAG](https://github.com/0xRAG)! - Updated Transfer API to allow users to wait for receipt and pass in a parsed amount to transfer
10
+
11
+ - [#141](https://github.com/coinbase/cdp-sdk/pull/141) [`c0273f9`](https://github.com/coinbase/cdp-sdk/commit/c0273f96769f74c78cddbbf0b109dc47cc16b7ca) Thanks [@sammccord](https://github.com/sammccord)! - Added SendEvmTransactionRule to Policy Rules
12
+
3
13
  ## 1.8.0
4
14
 
5
15
  ### Minor Changes
package/README.md CHANGED
@@ -137,8 +137,8 @@ const account = await cdp.evm.updateAccount({
137
137
  addresss: account.address,
138
138
  update: {
139
139
  name: "Updated name",
140
- accountPolicy: "1622d4b7-9d60-44a2-9a6a-e9bbb167e412"
141
- }
140
+ accountPolicy: "1622d4b7-9d60-44a2-9a6a-e9bbb167e412",
141
+ },
142
142
  });
143
143
  ```
144
144
 
@@ -149,8 +149,8 @@ const account = await cdp.solana.updateAccount({
149
149
  addresss: account.address,
150
150
  update: {
151
151
  name: "Updated name",
152
- accountPolicy: "1622d4b7-9d60-44a2-9a6a-e9bbb167e412"
153
- }
152
+ accountPolicy: "1622d4b7-9d60-44a2-9a6a-e9bbb167e412",
153
+ },
154
154
  });
155
155
  ```
156
156
 
@@ -316,21 +316,37 @@ const userOperation = await cdp.sendUserOperation({
316
316
 
317
317
  ### Transferring tokens
318
318
 
319
- For complete examples, check out [transfer.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/transfer.ts) and [transferWithSmartWallet.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/transferWithSmartWallet.ts).
319
+ #### EVM
320
+
321
+ For complete examples, check out [evm/account.transfer.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/account.transfer.ts) and [evm/smartAccount.transfer.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/smartAccount.transfer.ts).
320
322
 
321
323
  You can transfer tokens between accounts using the `transfer` function:
322
324
 
323
325
  ```typescript
324
326
  const sender = await cdp.evm.createAccount({ name: "Sender" });
325
327
 
326
- const { status } = await sender.transfer({
328
+ const { transactionHash } = await sender.transfer({
327
329
  to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
328
- amount: "0.01",
330
+ amount: 10000n, // equivalent to 0.01 USDC
329
331
  token: "usdc",
330
332
  network: "base-sepolia",
331
333
  });
332
334
  ```
333
335
 
336
+ You can then [wait for the transaction receipt with a viem Public Client](https://viem.sh/docs/actions/public/waitForTransactionReceipt#waitfortransactionreceipt):
337
+
338
+ ```typescript
339
+ import { createPublicClient, http } from "viem";
340
+ import { baseSepolia } from "viem/chains";
341
+
342
+ const publicClient = createPublicClient({
343
+ chain: baseSepolia,
344
+ transport: http(),
345
+ });
346
+
347
+ const receipt = await publicClient.waitForTransactionReceipt({ hash: transactionHash });
348
+ ```
349
+
334
350
  Smart Accounts also have a `transfer` function:
335
351
 
336
352
  ```typescript
@@ -339,36 +355,48 @@ const sender = await cdp.evm.createSmartAccount({
339
355
  });
340
356
  console.log("Created smart account", sender);
341
357
 
342
- const { status } = await sender.transfer({
358
+ const { userOpHash } = await sender.transfer({
343
359
  to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
344
- amount: "0.01",
360
+ amount: 10000n, // equivalent to 0.01 USDC
345
361
  token: "usdc",
346
362
  network: "base-sepolia",
347
363
  });
348
364
  ```
349
365
 
350
- Using Smart Accounts, you can also specify a paymaster URL and wait options:
366
+ One difference is that the `transfer` function returns the user operation hash, which is different from the transaction hash. You can use the returned user operation hash in a call to `waitForUserOperation` to get the result of the transaction:
367
+
368
+ ```typescript
369
+ const receipt = await sender.waitForUserOperation({
370
+ hash: userOpHash,
371
+ });
372
+
373
+ if (receipt.status === "complete") {
374
+ console.log(
375
+ `Transfer successful! Explorer link: https://sepolia.basescan.org/tx/${receipt.userOpHash}`,
376
+ );
377
+ } else {
378
+ console.log(`Something went wrong! User operation hash: ${receipt.userOpHash}`);
379
+ }
380
+ ```
381
+
382
+ Using Smart Accounts, you can also specify a paymaster URL:
351
383
 
352
384
  ```typescript
353
- const { status } = await sender.transfer({
385
+ await sender.transfer({
354
386
  to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
355
387
  amount: "0.01",
356
388
  token: "usdc",
357
389
  network: "base-sepolia",
358
390
  paymasterUrl: "https://some-paymaster-url.com",
359
- waitOptions: {
360
- timeout: 30,
361
- interval: 2,
362
- },
363
391
  });
364
392
  ```
365
393
 
366
- If you pass a decimal amount in a string, the SDK will parse it into a bigint based on the token's decimals. You can also pass a bigint directly:
394
+ Transfer amount must be passed as a bigint. To convert common tokens from whole units, you can use utilities such as [`parseEther`](https://viem.sh/docs/utilities/parseEther#parseether) and [`parseUnits`](https://viem.sh/docs/utilities/parseUnits#parseunits) from viem.
367
395
 
368
396
  ```typescript
369
- const { status } = await sender.transfer({
397
+ await sender.transfer({
370
398
  to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
371
- amount: 10000n, // equivalent to 0.01 usdc
399
+ amount: parseUnits("0.01", 6), // USDC has 6 decimals
372
400
  token: "usdc",
373
401
  network: "base-sepolia",
374
402
  });
@@ -377,9 +405,9 @@ const { status } = await sender.transfer({
377
405
  You can pass `usdc` or `eth` as the token to transfer, or you can pass a contract address directly:
378
406
 
379
407
  ```typescript
380
- const { status } = await sender.transfer({
408
+ await sender.transfer({
381
409
  to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
382
- amount: "0.000001",
410
+ amount: parseUnits("0.000001", 18), // WETH has 18 decimals. equivalent to calling `parseEther("0.000001")`
383
411
  token: "0x4200000000000000000000000000000000000006", // WETH on Base Sepolia
384
412
  network: "base-sepolia",
385
413
  });
@@ -391,26 +419,77 @@ You can also pass another account as the `to` parameter:
391
419
  const sender = await cdp.evm.createAccount({ name: "Sender" });
392
420
  const receiver = await cdp.evm.createAccount({ name: "Receiver" });
393
421
 
394
- const { status } = await sender.transfer({
422
+ await sender.transfer({
395
423
  to: receiver,
396
- amount: "0.01",
424
+ amount: 10000n, // equivalent to 0.01 USDC
397
425
  token: "usdc",
398
426
  network: "base-sepolia",
399
427
  });
400
428
  ```
401
429
 
402
- You can also pass wait options to the `transfer` function:
430
+ #### Solana
431
+
432
+ For complete examples, check out [solana/account.transfer.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/solana/account.transfer.ts).
433
+
434
+ You can transfer tokens between accounts using the `transfer` function, and wait for the transaction to be confirmed using the `confirmTransaction` function from `@solana/web3.js`:
403
435
 
404
436
  ```typescript
405
- const { status } = await sender.transfer({
406
- to: receiver,
437
+ import { LAMPORTS_PER_SOL } from "@solana/web3.js";
438
+
439
+ const sender = await cdp.solana.createAccount();
440
+
441
+ const connection = new Connection("https://api.devnet.solana.com");
442
+
443
+ const { signature } = await sender.transfer({
444
+ to: "3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE",
445
+ amount: 0.01 * LAMPORTS_PER_SOL,
446
+ token: "sol",
447
+ network: connection,
448
+ });
449
+
450
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
451
+
452
+ const confirmation = await connection.confirmTransaction(
453
+ {
454
+ signature,
455
+ blockhash,
456
+ lastValidBlockHeight,
457
+ },
458
+ "confirmed",
459
+ );
460
+
461
+ if (confirmation.value.err) {
462
+ console.log(`Something went wrong! Error: ${confirmation.value.err.toString()}`);
463
+ } else {
464
+ console.log(
465
+ `Transaction confirmed: Link: https://explorer.solana.com/tx/${signature}?cluster=devnet`,
466
+ );
467
+ }
468
+ ```
469
+
470
+ You can also easily send USDC:
471
+
472
+ ```typescript
473
+ const { signature } = await sender.transfer({
474
+ to: "3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE",
407
475
  amount: "0.01",
408
476
  token: "usdc",
409
- network: "base-sepolia",
410
- waitOptions: {
411
- timeout: 30,
412
- interval: 2,
413
- },
477
+ network: "devnet",
478
+ });
479
+ ```
480
+
481
+ If you want to use your own Connection, you can pass one to the `network` parameter:
482
+
483
+ ```typescript
484
+ import { Connection } from "@solana/web3.js";
485
+
486
+ const connection = new Connection("YOUR_RPC_URL");
487
+
488
+ const { signature } = await sender.transfer({
489
+ to: "3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE",
490
+ amount: "0.01",
491
+ token: "usdc",
492
+ network: connection,
414
493
  });
415
494
  ```
416
495
 
@@ -471,7 +550,7 @@ You can use the `signMessage` action:
471
550
  ```typescript
472
551
  const account = await cdp.solana.createAccount();
473
552
  const { signature } = await account.signMessage({
474
- message: "Hello, world!"
553
+ message: "Hello, world!",
475
554
  });
476
555
  ```
477
556
 
@@ -481,7 +560,6 @@ SolanaAccount supports the following actions:
481
560
  - `signMessage`
482
561
  - `signTransaction`
483
562
 
484
-
485
563
  ## Policy Management
486
564
 
487
565
  You can use the policies SDK to manage sets of rules that govern the behavior of accounts and projects, such as enforce allowlists and denylists.
@@ -493,27 +571,27 @@ This policy will accept any account sending less than a specific amount of ETH t
493
571
  ```typescript
494
572
  const policy = await cdp.policies.createPolicy({
495
573
  policy: {
496
- scope: 'project',
497
- description: 'Project-wide Allowlist Policy',
574
+ scope: "project",
575
+ description: "Project-wide Allowlist Policy",
498
576
  rules: [
499
577
  {
500
- action: 'accept',
501
- operation: 'signEvmTransaction',
578
+ action: "accept",
579
+ operation: "signEvmTransaction",
502
580
  criteria: [
503
581
  {
504
- type: 'ethValue',
505
- ethValue: '1000000000000000000',
506
- operator: '<='
582
+ type: "ethValue",
583
+ ethValue: "1000000000000000000",
584
+ operator: "<=",
507
585
  },
508
586
  {
509
- type: 'evmAddress',
587
+ type: "evmAddress",
510
588
  addresses: ["0x000000000000000000000000000000000000dEaD"],
511
- operator: 'in'
512
- }
513
- ]
514
- }
515
- ]
516
- }
589
+ operator: "in",
590
+ },
591
+ ],
592
+ },
593
+ ],
594
+ },
517
595
  });
518
596
  ```
519
597
 
@@ -524,27 +602,27 @@ This policy will accept any transaction with a value less than or equal to 1 ETH
524
602
  ```typescript
525
603
  const policy = await cdp.policies.createPolicy({
526
604
  policy: {
527
- scope: 'account',
528
- description: 'Account Allowlist Policy',
605
+ scope: "account",
606
+ description: "Account Allowlist Policy",
529
607
  rules: [
530
608
  {
531
- action: 'accept',
532
- operation: 'signEvmTransaction',
609
+ action: "accept",
610
+ operation: "signEvmTransaction",
533
611
  criteria: [
534
612
  {
535
- type: 'ethValue',
536
- ethValue: '1000000000000000000',
537
- operator: '<='
613
+ type: "ethValue",
614
+ ethValue: "1000000000000000000",
615
+ operator: "<=",
538
616
  },
539
617
  {
540
- type: 'evmAddress',
618
+ type: "evmAddress",
541
619
  addresses: ["0x000000000000000000000000000000000000dEaD"],
542
- operator: 'in'
543
- }
544
- ]
545
- }
546
- ]
547
- }
620
+ operator: "in",
621
+ },
622
+ ],
623
+ },
624
+ ],
625
+ },
548
626
  });
549
627
  ```
550
628
 
@@ -553,22 +631,22 @@ const policy = await cdp.policies.createPolicy({
553
631
  ```typescript
554
632
  const policy = await cdp.policies.createPolicy({
555
633
  policy: {
556
- scope: 'account',
557
- description: 'Account Allowlist Policy',
634
+ scope: "account",
635
+ description: "Account Allowlist Policy",
558
636
  rules: [
559
637
  {
560
- action: 'accept',
561
- operation: 'signSolTransaction',
638
+ action: "accept",
639
+ operation: "signSolTransaction",
562
640
  criteria: [
563
641
  {
564
- type: 'solAddress',
642
+ type: "solAddress",
565
643
  addresses: ["DtdSSG8ZJRZVv5Jx7K1MeWp7Zxcu19GD5wQRGRpQ9uMF"],
566
- operator: 'in'
567
- }
568
- ]
569
- }
570
- ]
571
- }
644
+ operator: "in",
645
+ },
646
+ ],
647
+ },
648
+ ],
649
+ },
572
650
  });
573
651
  ```
574
652
 
@@ -578,7 +656,7 @@ You can filter by account:
578
656
 
579
657
  ```typescript
580
658
  const policy = await cdp.policies.listPolicies({
581
- scope: 'account'
659
+ scope: "account",
582
660
  });
583
661
  ```
584
662
 
@@ -586,7 +664,7 @@ You can also filter by project:
586
664
 
587
665
  ```typescript
588
666
  const policy = await cdp.policies.listPolicies({
589
- scope: 'project'
667
+ scope: "project",
590
668
  });
591
669
  ```
592
670
 
@@ -594,7 +672,7 @@ const policy = await cdp.policies.listPolicies({
594
672
 
595
673
  ```typescript
596
674
  const policy = await cdp.policies.getPolicyById({
597
- id: '__POLICY_ID__'
675
+ id: "__POLICY_ID__",
598
676
  });
599
677
  ```
600
678
 
@@ -604,34 +682,33 @@ This policy will update an existing policy to accept transactions to any address
604
682
 
605
683
  ```typescript
606
684
  const policy = await cdp.policies.updatePolicy({
607
- id: '__POLICY_ID__',
685
+ id: "__POLICY_ID__",
608
686
  policy: {
609
- description: 'Updated Account Denylist Policy',
687
+ description: "Updated Account Denylist Policy",
610
688
  rules: [
611
689
  {
612
- action: 'accept',
613
- operation: 'signEvmTransaction',
690
+ action: "accept",
691
+ operation: "signEvmTransaction",
614
692
  criteria: [
615
693
  {
616
- type: 'evmAddress',
694
+ type: "evmAddress",
617
695
  addresses: ["0x000000000000000000000000000000000000dEaD"],
618
- operator: 'not in'
619
- }
620
- ]
621
- }
622
- ]
623
- }
696
+ operator: "not in",
697
+ },
698
+ ],
699
+ },
700
+ ],
701
+ },
624
702
  });
625
703
  ```
626
704
 
627
705
  ### Delete a Policy
628
706
 
629
- > [!WARNING]
630
- > Attempting to delete an account-level policy in-use by at least one account will fail.
707
+ > [!WARNING] Attempting to delete an account-level policy in-use by at least one account will fail.
631
708
 
632
709
  ```typescript
633
710
  const policy = await cdp.policies.deletePolicy({
634
- id: '__POLICY_ID__'
711
+ id: "__POLICY_ID__",
635
712
  });
636
713
  ```
637
714
 
@@ -645,35 +722,35 @@ import { CreatePolicyBodySchema, UpdatePolicyBodySchema } from "@coinbase/cdp-sd
645
722
  // Validate a new Policy with many issues, will throw a ZodError with actionable validation errors
646
723
  try {
647
724
  CreatePolicyBodySchema.parse({
648
- description: 'Bad description with !#@ characters, also is wayyyyy toooooo long!!',
725
+ description: "Bad description with !#@ characters, also is wayyyyy toooooo long!!",
649
726
  rules: [
650
727
  {
651
- action: 'acept',
652
- operation: 'unknownOperation',
728
+ action: "acept",
729
+ operation: "unknownOperation",
653
730
  criteria: [
654
731
  {
655
- type: 'ethValue',
656
- ethValue: 'not a number',
657
- operator: '<='
732
+ type: "ethValue",
733
+ ethValue: "not a number",
734
+ operator: "<=",
658
735
  },
659
736
  {
660
- type: 'evmAddress',
737
+ type: "evmAddress",
661
738
  addresses: ["not an address"],
662
- operator: 'in'
739
+ operator: "in",
663
740
  },
664
741
  {
665
- type: 'evmAddress',
742
+ type: "evmAddress",
666
743
  addresses: ["not an address"],
667
- operator: 'invalid operator'
668
- }
669
- ]
744
+ operator: "invalid operator",
745
+ },
746
+ ],
670
747
  },
671
- ]
672
- })
673
- } catch(e) {
674
- console.error(e)
748
+ ],
749
+ });
750
+ } catch (e) {
751
+ console.error(e);
675
752
  }
676
- ````
753
+ ```
677
754
 
678
755
  ## Authentication tools
679
756
 
@@ -1 +1 @@
1
- {"version":3,"file":"toEvmServerAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmServerAccount.ts"],"names":[],"mappings":";;AAuCA,gDA+DC;AAtGD,+BAAoF;AAEpF,iFAIgD;AAChD,yEAI4C;AAC5C,6EAAuE;AACvE,sGAAgG;AAChG,wEAAkE;AAgBlE;;;;;;;;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,MAA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AC,KAAK,CAAC;QACvB,KAAK,CAAC,QAAQ,CAAC,YAAY;YACzB,OAAO,IAAA,sBAAQ,EAAC,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,8DAA4B,CAAC,CAAC;QAClF,CAAC;QACD,KAAK,CAAC,iBAAiB,CACrB,OAAkD;YAElD,OAAO,IAAA,wCAAiB,EAAC,SAAS,EAAE;gBAClC,GAAG,OAAO;gBACV,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,iBAAiB,CACrB,OAAkE;YAElE,OAAO,IAAA,wCAAiB,EAAC,SAAS,EAAE;gBAClC,GAAG,OAAO;gBACV,YAAY,EAAE,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,oBAAoB,CACxB,OAAiE;YAEjE,OAAO,IAAA,8CAAoB,EAAC,SAAS,EAAE;gBACrC,GAAG,OAAO;gBACV,mBAAmB,EAAE,OAAO,CAAC,OAAO;aACrC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,gBAAgB,CACpB,OAAsD;YAEtD,OAAO,IAAA,sCAAgB,EAAC,SAAS,EAAE;gBACjC,GAAG,OAAO;gBACV,YAAY,EAAE,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,aAAa,CACjB,OAA8C;YAE9C,OAAO,IAAA,gCAAa,EAAC,SAAS,EAAE;gBAC9B,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI;QAC/B,IAAI,EAAE,WAAW;KAClB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"toEvmSmartAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmSmartAccount.ts"],"names":[],"mappings":";;AAsDA,8CAuDC;AA7GD,+EAAyE;AACzE,iFAIgD;A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IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI;QAC/B,IAAI,EAAE,WAAW;KAClB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -4,6 +4,7 @@ exports.toSolanaAccount = toSolanaAccount;
4
4
  const requestFaucet_js_1 = require("../../actions/solana/requestFaucet.js");
5
5
  const signMessage_js_1 = require("../../actions/solana/signMessage.js");
6
6
  const signTransaction_js_1 = require("../../actions/solana/signTransaction.js");
7
+ const transfer_js_1 = require("../../actions/solana/transfer.js");
7
8
  /**
8
9
  * Creates a Solana account instance with actions from an existing Solana account.
9
10
  * Use this to interact with previously deployed Solana accounts, rather than creating new ones.
@@ -36,6 +37,12 @@ function toSolanaAccount(apiClient, options) {
36
37
  });
37
38
  },
38
39
  policies: options.account.policies,
40
+ async transfer(options) {
41
+ return (0, transfer_js_1.transfer)(apiClient, {
42
+ ...options,
43
+ from: account.address,
44
+ });
45
+ },
39
46
  };
40
47
  return account;
41
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"toSolanaAccount.js","sourceRoot":"","sources":["../../../accounts/solana/toSolanaAccount.ts"],"names":[],"mappings":";;AA4BA,0CA+BC;AA1DD,4EAAsE;AACtE,wEAAkE;AAClE,gFAA0E;AAgB1E;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,SAA+B,EAC/B,OAA+B;IAE/B,MAAM,OAAO,GAAkB;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;QAChC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAC1B,KAAK,CAAC,aAAa,CAAC,OAA8C;YAChE,OAAO,IAAA,gCAAa,EAAC,SAAS,EAAE;gBAC9B,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,WAAW,CAAC,OAA4C;YAC5D,OAAO,IAAA,4BAAW,EAAC,SAAS,EAAE;gBAC5B,GAAG,OAA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Q;QAClC,KAAK,CAAC,QAAQ,CAAC,OAAsC;YACnD,OAAO,IAAA,sBAAQ,EAAC,SAAS,EAAE;gBACzB,GAAG,OAAO;gBACV,IAAI,EAAE,OAAO,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -6,71 +6,38 @@ const utils_js_1 = require("./utils.js");
6
6
  const serializeTransaction_js_1 = require("../../../utils/serializeTransaction.js");
7
7
  exports.accountTransferStrategy = {
8
8
  executeTransfer: async ({ apiClient, from, to, value, token, network }) => {
9
- const transactionHash = await (async () => {
10
- if (token === "eth") {
11
- const result = await apiClient.sendEvmTransaction(from.address, {
12
- transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
13
- value,
14
- to,
15
- }),
16
- network,
17
- });
18
- return result.transactionHash;
19
- }
20
- else {
21
- const erc20Address = (0, utils_js_1.getErc20Address)(token, network);
22
- await apiClient.sendEvmTransaction(from.address, {
23
- transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
24
- to: erc20Address,
25
- data: (0, viem_1.encodeFunctionData)({
26
- abi: viem_1.erc20Abi,
27
- functionName: "approve",
28
- args: [to, value],
29
- }),
30
- }),
31
- network,
32
- });
33
- const result = await apiClient.sendEvmTransaction(from.address, {
34
- transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
35
- to: erc20Address,
36
- data: (0, viem_1.encodeFunctionData)({
37
- abi: viem_1.erc20Abi,
38
- functionName: "transfer",
39
- args: [to, value],
40
- }),
41
- }),
42
- network,
43
- });
44
- return result.transactionHash;
45
- }
46
- })();
47
- return transactionHash;
48
- },
49
- waitForResult: async ({ publicClient, hash, waitOptions }) => {
50
- let receipt;
51
- try {
52
- receipt = await publicClient.waitForTransactionReceipt({
53
- hash,
54
- pollingInterval: waitOptions?.intervalSeconds
55
- ? waitOptions.intervalSeconds * 1000
56
- : undefined,
57
- timeout: waitOptions?.timeoutSeconds ? waitOptions.timeoutSeconds * 1000 : undefined,
9
+ if (token === "eth") {
10
+ return apiClient.sendEvmTransaction(from.address, {
11
+ transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
12
+ value,
13
+ to,
14
+ }),
15
+ network,
58
16
  });
59
17
  }
60
- catch (error) {
61
- if (error instanceof viem_1.WaitForTransactionReceiptTimeoutError) {
62
- throw new Error(`Transaction timed out. Check the transaction on the explorer: ${publicClient.chain.blockExplorers?.default.url}/tx/${hash}`);
63
- }
64
- else {
65
- throw error;
66
- }
67
- }
68
- if (receipt.status === "success") {
69
- return { status: receipt.status, transactionHash: hash };
70
- }
71
- else {
72
- throw new Error(`Transaction failed. Check the transaction on the explorer: ${publicClient.chain.blockExplorers?.default.url}/tx/${hash}`);
73
- }
18
+ const erc20Address = (0, utils_js_1.getErc20Address)(token, network);
19
+ await apiClient.sendEvmTransaction(from.address, {
20
+ transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
21
+ to: erc20Address,
22
+ data: (0, viem_1.encodeFunctionData)({
23
+ abi: viem_1.erc20Abi,
24
+ functionName: "approve",
25
+ args: [to, value],
26
+ }),
27
+ }),
28
+ network,
29
+ });
30
+ return apiClient.sendEvmTransaction(from.address, {
31
+ transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
32
+ to: erc20Address,
33
+ data: (0, viem_1.encodeFunctionData)({
34
+ abi: viem_1.erc20Abi,
35
+ functionName: "transfer",
36
+ args: [to, value],
37
+ }),
38
+ }),
39
+ network,
40
+ });
74
41
  },
75
42
  };
76
43
  //# sourceMappingURL=accountTransferStrategy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":";;;AAAA,+BAMc;AAGd,yCAA6C;AAE7C,oFAAqF;AAExE,QAAA,uBAAuB,GAA0C;IAC5E,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE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AEL,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,aAAa,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE;QAC3D,IAAI,OAA2B,CAAC;QAChC,IAAI,CAAC;YACH,OAAO,GAAG,MAAM,YAAY,CAAC,yBAAyB,CAAC;gBACrD,IAAI;gBACJ,eAAe,EAAE,WAAW,EAAE,eAAe;oBAC3C,CAAC,CAAC,WAAW,CAAC,eAAe,GAAG,IAAI;oBACpC,CAAC,CAAC,SAAS;gBACb,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC,WAAW,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC,CAAC,SAAS;aACrF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,4CAAqC,EAAE,CAAC;gBAC3D,MAAM,IAAI,KAAK,CACb,iEAAiE,YAAY,CAAC,KAAK,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,OAAO,IAAI,EAAE,CAC7H,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;QAC3D,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,8DAA8D,YAAY,CAAC,KAAK,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,OAAO,IAAI,EAAE,CAC1H,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":";;;AAAA,+BAAoD;AAEpD,yCAA6C;AAC7C,oFAAqF;AAMxE,QAAA,uBAAuB,GAA0C;IAC5E,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;QACxE,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;gBAChD,WAAW,EAAE,IAAA,qDAA2B,EAAC;oBACvC,KAAK;oBACL,EAAE;iBACH,CAAC;gBACF,OAAO;aACR,CAA+B,CAAC;QACnC,CAAC;QAED,MAAM,YAAY,GAAG,IAAA,0BAAe,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAErD,MAAM,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;YAC/C,WAAW,EAAE,IAAA,qDAA2B,EAAC;gBACvC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,IAAA,yBAAkB,EAAC;oBACvB,GAAG,EAAE,eAAQ;oBACb,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;iBAClB,CAAC;aACH,CAAC;YACF,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;YAChD,WAAW,EAAE,IAAA,qDAA2B,EAAC;gBACvC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,IAAA,yBAAkB,EAAC;oBACvB,GAAG,EAAE,eAAQ;oBACb,YAAY,EAAE,UAAU;oBACxB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;iBAClB,CAAC;aACH,CAAC;YACF,OAAO;SACR,CAA+B,CAAC;IACnC,CAAC;CACF,CAAC"}