@coinbase/cdp-sdk 1.6.0 → 1.7.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 (161) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +62 -0
  3. package/_cjs/accounts/evm/toEvmSmartAccount.js +7 -0
  4. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  5. package/_cjs/accounts/{types.js.map → evm/types.js.map} +1 -1
  6. package/_cjs/accounts/solana/toSolanaAccount.js +41 -0
  7. package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -0
  8. package/_cjs/accounts/solana/types.js +3 -0
  9. package/_cjs/accounts/solana/types.js.map +1 -0
  10. package/_cjs/actions/evm/getUserOperation.js +36 -0
  11. package/_cjs/actions/evm/getUserOperation.js.map +1 -0
  12. package/_cjs/actions/evm/transfer/accountTransferStrategy.js +11 -7
  13. package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  14. package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +9 -6
  15. package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
  16. package/_cjs/actions/evm/transfer/transfer.js +7 -3
  17. package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
  18. package/_cjs/actions/solana/requestFaucet.js +29 -0
  19. package/_cjs/actions/solana/requestFaucet.js.map +1 -0
  20. package/_cjs/actions/solana/signMessage.js +29 -0
  21. package/_cjs/actions/solana/signMessage.js.map +1 -0
  22. package/_cjs/actions/solana/signTransaction.js +46 -0
  23. package/_cjs/actions/solana/signTransaction.js.map +1 -0
  24. package/_cjs/actions/solana/types.js +3 -0
  25. package/_cjs/actions/solana/types.js.map +1 -0
  26. package/_cjs/client/evm/evm.js +2 -12
  27. package/_cjs/client/evm/evm.js.map +1 -1
  28. package/_cjs/client/solana/solana.js +22 -17
  29. package/_cjs/client/solana/solana.js.map +1 -1
  30. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +59 -1
  31. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  32. package/_cjs/openapi-client/generated/index.msw.js +3 -2
  33. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  34. package/_cjs/openapi-client/generated/policy-engine/policy-engine.js +56 -0
  35. package/_cjs/openapi-client/generated/policy-engine/policy-engine.js.map +1 -0
  36. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +284 -0
  37. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -0
  38. package/_cjs/openapi-client/index.js +1 -0
  39. package/_cjs/openapi-client/index.js.map +1 -1
  40. package/_cjs/version.js +1 -1
  41. package/_esm/accounts/evm/toEvmSmartAccount.js +7 -0
  42. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  43. package/_esm/accounts/{types.js.map → evm/types.js.map} +1 -1
  44. package/_esm/accounts/solana/toSolanaAccount.js +38 -0
  45. package/_esm/accounts/solana/toSolanaAccount.js.map +1 -0
  46. package/_esm/accounts/solana/types.js +2 -0
  47. package/_esm/accounts/solana/types.js.map +1 -0
  48. package/_esm/actions/evm/getUserOperation.js +33 -0
  49. package/_esm/actions/evm/getUserOperation.js.map +1 -0
  50. package/_esm/actions/evm/transfer/accountTransferStrategy.js +11 -7
  51. package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  52. package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +9 -6
  53. package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
  54. package/_esm/actions/evm/transfer/transfer.js +7 -3
  55. package/_esm/actions/evm/transfer/transfer.js.map +1 -1
  56. package/_esm/actions/solana/requestFaucet.js +26 -0
  57. package/_esm/actions/solana/requestFaucet.js.map +1 -0
  58. package/_esm/actions/solana/signMessage.js +26 -0
  59. package/_esm/actions/solana/signMessage.js.map +1 -0
  60. package/_esm/actions/solana/signTransaction.js +43 -0
  61. package/_esm/actions/solana/signTransaction.js.map +1 -0
  62. package/_esm/actions/solana/types.js +2 -0
  63. package/_esm/actions/solana/types.js.map +1 -0
  64. package/_esm/client/evm/evm.js +2 -12
  65. package/_esm/client/evm/evm.js.map +1 -1
  66. package/_esm/client/solana/solana.js +22 -17
  67. package/_esm/client/solana/solana.js.map +1 -1
  68. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +58 -0
  69. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  70. package/_esm/openapi-client/generated/index.msw.js +3 -2
  71. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  72. package/_esm/openapi-client/generated/policy-engine/policy-engine.js +48 -0
  73. package/_esm/openapi-client/generated/policy-engine/policy-engine.js.map +1 -0
  74. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +259 -0
  75. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -0
  76. package/_esm/openapi-client/index.js +1 -0
  77. package/_esm/openapi-client/index.js.map +1 -1
  78. package/_esm/version.js +1 -1
  79. package/_types/accounts/evm/toEvmServerAccount.d.ts +1 -1
  80. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  81. package/_types/accounts/evm/toEvmSmartAccount.d.ts +1 -1
  82. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
  83. package/_types/accounts/{types.d.ts → evm/types.d.ts} +5 -5
  84. package/_types/accounts/evm/types.d.ts.map +1 -0
  85. package/_types/accounts/solana/toSolanaAccount.d.ts +20 -0
  86. package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -0
  87. package/_types/accounts/solana/types.d.ts +12 -0
  88. package/_types/accounts/solana/types.d.ts.map +1 -0
  89. package/_types/actions/evm/getUserOperation.d.ts +22 -0
  90. package/_types/actions/evm/getUserOperation.d.ts.map +1 -0
  91. package/_types/actions/evm/sendUserOperation.d.ts +1 -1
  92. package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
  93. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +1 -1
  94. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
  95. package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +1 -1
  96. package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
  97. package/_types/actions/evm/transfer/transfer.d.ts +3 -3
  98. package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
  99. package/_types/actions/evm/transfer/types.d.ts +41 -7
  100. package/_types/actions/evm/transfer/types.d.ts.map +1 -1
  101. package/_types/actions/evm/types.d.ts +28 -5
  102. package/_types/actions/evm/types.d.ts.map +1 -1
  103. package/_types/actions/solana/requestFaucet.d.ts +23 -0
  104. package/_types/actions/solana/requestFaucet.d.ts.map +1 -0
  105. package/_types/actions/solana/signMessage.d.ts +23 -0
  106. package/_types/actions/solana/signMessage.d.ts.map +1 -0
  107. package/_types/actions/solana/signTransaction.d.ts +38 -0
  108. package/_types/actions/solana/signTransaction.d.ts.map +1 -0
  109. package/_types/actions/solana/types.d.ts +80 -0
  110. package/_types/actions/solana/types.d.ts.map +1 -0
  111. package/_types/client/evm/evm.d.ts.map +1 -1
  112. package/_types/client/evm/evm.types.d.ts +3 -3
  113. package/_types/client/evm/evm.types.d.ts.map +1 -1
  114. package/_types/client/solana/solana.d.ts +5 -4
  115. package/_types/client/solana/solana.d.ts.map +1 -1
  116. package/_types/client/solana/solana.types.d.ts +8 -11
  117. package/_types/client/solana/solana.types.d.ts.map +1 -1
  118. package/_types/index.d.ts +1 -1
  119. package/_types/index.d.ts.map +1 -1
  120. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +218 -0
  121. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  122. package/_types/openapi-client/generated/index.msw.d.ts +3 -2
  123. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  124. package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts +43 -0
  125. package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts.map +1 -0
  126. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +25 -0
  127. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -0
  128. package/_types/openapi-client/index.d.ts +1 -0
  129. package/_types/openapi-client/index.d.ts.map +1 -1
  130. package/_types/version.d.ts +1 -1
  131. package/accounts/evm/toEvmServerAccount.ts +1 -1
  132. package/accounts/evm/toEvmSmartAccount.ts +11 -1
  133. package/accounts/{types.ts → evm/types.ts} +5 -5
  134. package/accounts/solana/toSolanaAccount.ts +59 -0
  135. package/accounts/solana/types.ts +13 -0
  136. package/actions/evm/getUserOperation.ts +40 -0
  137. package/actions/evm/sendUserOperation.ts +1 -1
  138. package/actions/evm/transfer/accountTransferStrategy.ts +12 -8
  139. package/actions/evm/transfer/smartAccountTransferStrategy.ts +10 -7
  140. package/actions/evm/transfer/transfer.ts +17 -6
  141. package/actions/evm/transfer/types.ts +55 -12
  142. package/actions/evm/types.ts +37 -5
  143. package/actions/solana/requestFaucet.ts +35 -0
  144. package/actions/solana/signMessage.ts +36 -0
  145. package/actions/solana/signTransaction.ts +53 -0
  146. package/actions/solana/types.ts +87 -0
  147. package/client/evm/evm.ts +3 -16
  148. package/client/evm/evm.types.ts +4 -3
  149. package/client/solana/solana.ts +32 -37
  150. package/client/solana/solana.types.ts +10 -15
  151. package/index.ts +1 -1
  152. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +274 -0
  153. package/openapi-client/generated/index.msw.ts +3 -2
  154. package/openapi-client/generated/policy-engine/policy-engine.msw.ts +404 -0
  155. package/openapi-client/generated/policy-engine/policy-engine.ts +95 -0
  156. package/openapi-client/index.ts +1 -0
  157. package/package.json +1 -1
  158. package/version.ts +1 -1
  159. package/_types/accounts/types.d.ts.map +0 -1
  160. /package/_cjs/accounts/{types.js → evm/types.js} +0 -0
  161. /package/_esm/accounts/{types.js → evm/types.js} +0 -0
@@ -8,23 +8,23 @@ import {
8
8
 
9
9
  import { TransferExecutionStrategy } from "./types.js";
10
10
  import { getErc20Address } from "./utils.js";
11
- import { EvmAccount } from "../../../accounts/types.js";
11
+ import { EvmAccount } from "../../../accounts/evm/types.js";
12
12
  import { serializeEIP1559Transaction } from "../../../utils/serializeTransaction.js";
13
13
 
14
14
  export const accountTransferStrategy: TransferExecutionStrategy<EvmAccount> = {
15
- executeTransfer: async ({ apiClient, from, transferArgs, to, value }) => {
15
+ executeTransfer: async ({ apiClient, from, to, value, token, network }) => {
16
16
  const transactionHash = await (async () => {
17
- if (transferArgs.token === "eth") {
17
+ if (token === "eth") {
18
18
  const result = await apiClient.sendEvmTransaction(from.address, {
19
19
  transaction: serializeEIP1559Transaction({
20
20
  value,
21
21
  to,
22
22
  }),
23
- network: transferArgs.network,
23
+ network,
24
24
  });
25
25
  return result.transactionHash as Hex;
26
26
  } else {
27
- const erc20Address = getErc20Address(transferArgs.token, transferArgs.network);
27
+ const erc20Address = getErc20Address(token, network);
28
28
 
29
29
  await apiClient.sendEvmTransaction(from.address, {
30
30
  transaction: serializeEIP1559Transaction({
@@ -35,7 +35,7 @@ export const accountTransferStrategy: TransferExecutionStrategy<EvmAccount> = {
35
35
  args: [to, value],
36
36
  }),
37
37
  }),
38
- network: transferArgs.network,
38
+ network,
39
39
  });
40
40
 
41
41
  const result = await apiClient.sendEvmTransaction(from.address, {
@@ -47,7 +47,7 @@ export const accountTransferStrategy: TransferExecutionStrategy<EvmAccount> = {
47
47
  args: [to, value],
48
48
  }),
49
49
  }),
50
- network: transferArgs.network,
50
+ network,
51
51
  });
52
52
 
53
53
  return result.transactionHash as Hex;
@@ -57,11 +57,15 @@ export const accountTransferStrategy: TransferExecutionStrategy<EvmAccount> = {
57
57
  return transactionHash;
58
58
  },
59
59
 
60
- waitForResult: async ({ publicClient, hash }) => {
60
+ waitForResult: async ({ publicClient, hash, waitOptions }) => {
61
61
  let receipt: TransactionReceipt;
62
62
  try {
63
63
  receipt = await publicClient.waitForTransactionReceipt({
64
64
  hash,
65
+ pollingInterval: waitOptions?.intervalSeconds
66
+ ? waitOptions.intervalSeconds * 1000
67
+ : undefined,
68
+ timeout: waitOptions?.timeoutSeconds ? waitOptions.timeoutSeconds * 1000 : undefined,
65
69
  });
66
70
  } catch (error) {
67
71
  if (error instanceof WaitForTransactionReceiptTimeoutError) {
@@ -2,17 +2,18 @@ import { encodeFunctionData, erc20Abi } from "viem";
2
2
 
3
3
  import { TransferExecutionStrategy } from "./types.js";
4
4
  import { getErc20Address } from "./utils.js";
5
- import { EvmSmartAccount } from "../../../accounts/types.js";
5
+ import { EvmSmartAccount } from "../../../accounts/evm/types.js";
6
6
  import { sendUserOperation } from "../sendUserOperation.js";
7
7
  import { waitForUserOperation } from "../waitForUserOperation.js";
8
8
 
9
9
  export const smartAccountTransferStrategy: TransferExecutionStrategy<EvmSmartAccount> = {
10
- executeTransfer: async ({ apiClient, from, transferArgs, to, value }) => {
10
+ executeTransfer: async ({ apiClient, from, to, value, token, network, paymasterUrl }) => {
11
11
  const userOpHash = await (async () => {
12
- if (transferArgs.token === "eth") {
12
+ if (token === "eth") {
13
13
  const result = await sendUserOperation(apiClient, {
14
14
  smartAccount: from,
15
- network: transferArgs.network,
15
+ paymasterUrl,
16
+ network,
16
17
  calls: [
17
18
  {
18
19
  to,
@@ -23,11 +24,12 @@ export const smartAccountTransferStrategy: TransferExecutionStrategy<EvmSmartAcc
23
24
  });
24
25
  return result.userOpHash;
25
26
  } else {
26
- const erc20Address = getErc20Address(transferArgs.token, transferArgs.network);
27
+ const erc20Address = getErc20Address(token, network);
27
28
 
28
29
  const result = await sendUserOperation(apiClient, {
29
30
  smartAccount: from,
30
- network: transferArgs.network,
31
+ paymasterUrl,
32
+ network,
31
33
  calls: [
32
34
  {
33
35
  to: erc20Address,
@@ -55,10 +57,11 @@ export const smartAccountTransferStrategy: TransferExecutionStrategy<EvmSmartAcc
55
57
  return userOpHash;
56
58
  },
57
59
 
58
- waitForResult: async ({ apiClient, publicClient, from, hash }) => {
60
+ waitForResult: async ({ apiClient, publicClient, from, hash, waitOptions }) => {
59
61
  const result = await waitForUserOperation(apiClient, {
60
62
  smartAccountAddress: from.address,
61
63
  userOpHash: hash,
64
+ waitOptions,
62
65
  });
63
66
 
64
67
  if (result.status === "complete") {
@@ -1,10 +1,16 @@
1
1
  import { createPublicClient, http, erc20Abi, parseUnits, Address, Chain, Transport } from "viem";
2
2
 
3
- import { TransferResult, TransferOptions, TransferExecutionStrategy } from "./types.js";
4
3
  import { mapNetworkToChain } from "./utils.js";
5
- import { EvmAccount, EvmSmartAccount } from "../../../accounts/types.js";
4
+ import { EvmAccount, EvmSmartAccount } from "../../../accounts/evm/types.js";
6
5
  import { CdpOpenApiClientType } from "../../../openapi-client/index.js";
7
6
 
7
+ import type {
8
+ TransferResult,
9
+ TransferExecutionStrategy,
10
+ SmartAccountTransferOptions,
11
+ AccountTransferOptions,
12
+ } from "./types.js";
13
+
8
14
  /**
9
15
  * Transfer an amount of a token from an account to another account.
10
16
  *
@@ -17,7 +23,7 @@ import { CdpOpenApiClientType } from "../../../openapi-client/index.js";
17
23
  export async function transfer<T extends EvmAccount | EvmSmartAccount>(
18
24
  apiClient: CdpOpenApiClientType,
19
25
  from: T,
20
- transferArgs: TransferOptions,
26
+ transferArgs: T extends EvmSmartAccount ? SmartAccountTransferOptions : AccountTransferOptions,
21
27
  transferStrategy: TransferExecutionStrategy<T>,
22
28
  ): Promise<TransferResult> {
23
29
  const publicClient = createPublicClient<Transport, Chain>({
@@ -52,19 +58,24 @@ export async function transfer<T extends EvmAccount | EvmSmartAccount>(
52
58
  return parseUnits(transferArgs.amount, decimals);
53
59
  })();
54
60
 
55
- const hash = await transferStrategy.executeTransfer({
61
+ const transfer = {
56
62
  apiClient,
57
63
  from,
58
- transferArgs,
59
64
  to,
60
65
  value,
61
- });
66
+ token: transferArgs.token,
67
+ network: transferArgs.network,
68
+ paymasterUrl: "paymasterUrl" in transferArgs ? transferArgs.paymasterUrl : undefined,
69
+ };
70
+
71
+ const hash = await transferStrategy.executeTransfer(transfer);
62
72
 
63
73
  const result = await transferStrategy.waitForResult({
64
74
  apiClient,
65
75
  publicClient,
66
76
  from,
67
77
  hash,
78
+ waitOptions: transferArgs.waitOptions,
68
79
  });
69
80
 
70
81
  return result;
@@ -1,12 +1,22 @@
1
- import { Hex, TransactionReceipt, Address, PublicClient, Chain, Transport } from "viem";
1
+ import {
2
+ Hex,
3
+ TransactionReceipt,
4
+ Address,
5
+ PublicClient,
6
+ Chain,
7
+ Transport,
8
+ WaitForTransactionReceiptParameters,
9
+ } from "viem";
2
10
 
3
11
  import {
4
12
  CdpOpenApiClientType,
5
- EvmAccount,
6
13
  EvmUserOperationNetwork,
7
14
  SendEvmTransactionBodyNetwork,
8
15
  } from "../../../openapi-client/index.js";
9
16
 
17
+ import type { EvmAccount, EvmSmartAccount } from "../../../accounts/evm/types.js";
18
+ import type { WaitForUserOperationOptions } from "../waitForUserOperation.js";
19
+
10
20
  /**
11
21
  * The network to transfer the token on.
12
22
  */
@@ -15,7 +25,7 @@ export type Network = SendEvmTransactionBodyNetwork | EvmUserOperationNetwork;
15
25
  /**
16
26
  * The options for the transfer.
17
27
  */
18
- export type TransferOptions = {
28
+ type TransferOptions = {
19
29
  /** The account to transfer the token to. */
20
30
  to: EvmAccount | Address;
21
31
  /**
@@ -29,6 +39,33 @@ export type TransferOptions = {
29
39
  network: Network;
30
40
  };
31
41
 
42
+ /**
43
+ * The options for the transfer using an account.
44
+ */
45
+ export type AccountTransferOptions = TransferOptions & {
46
+ /** The options for waiting for the result of the transfer. */
47
+ waitOptions?: {
48
+ /**
49
+ * Polling frequency (in seconds). Defaults to 4 seconds.
50
+ */
51
+ intervalSeconds?: WaitForTransactionReceiptParameters["pollingInterval"];
52
+ /**
53
+ * Optional timeout (in seconds) to wait before stopping polling. Defaults to 180 seconds.
54
+ */
55
+ timeoutSeconds?: WaitForTransactionReceiptParameters["timeout"];
56
+ };
57
+ };
58
+
59
+ /**
60
+ * The options for the transfer using a smart account.
61
+ */
62
+ export type SmartAccountTransferOptions = TransferOptions & {
63
+ /** The paymaster URL to use for the transfer. */
64
+ paymasterUrl?: string;
65
+ /** The options for waiting for the result of the transfer. */
66
+ waitOptions?: WaitForUserOperationOptions["waitOptions"];
67
+ };
68
+
32
69
  /**
33
70
  * The result of the transfer.
34
71
  */
@@ -42,25 +79,29 @@ export type TransferResult = {
42
79
  /**
43
80
  * A strategy for executing a transfer.
44
81
  */
45
- export interface TransferExecutionStrategy<T> {
82
+ export interface TransferExecutionStrategy<T extends EvmAccount | EvmSmartAccount> {
46
83
  /**
47
84
  * Executes the transfer.
48
85
  *
49
86
  * @param args - The arguments for the transfer.
50
87
  * @param args.apiClient - The API client to use for the transfer.
51
88
  * @param args.from - The account to transfer the token from.
52
- * @param args.transferArgs - The arguments for the transfer.
53
89
  * @param args.to - The account to transfer the token to.
54
90
  * @param args.value - The value of the transfer.
91
+ * @param args.token - The token to transfer.
92
+ * @param args.network - The network to transfer the token on.
55
93
  * @returns The transaction hash of the transfer.
56
94
  */
57
- executeTransfer(args: {
58
- apiClient: CdpOpenApiClientType;
59
- from: T;
60
- transferArgs: TransferOptions;
61
- to: Address;
62
- value: bigint;
63
- }): Promise<Hex>;
95
+ executeTransfer(
96
+ args: {
97
+ apiClient: CdpOpenApiClientType;
98
+ from: T;
99
+ to: Address;
100
+ value: bigint;
101
+ token: TransferOptions["token"];
102
+ network: TransferOptions["network"];
103
+ } & (T extends EvmSmartAccount ? { paymasterUrl?: string } : object),
104
+ ): Promise<Hex>;
64
105
 
65
106
  /**
66
107
  * Waits for the result of the transfer.
@@ -70,6 +111,7 @@ export interface TransferExecutionStrategy<T> {
70
111
  * @param args.publicClient - The public client to use for the transfer.
71
112
  * @param args.from - The account to transfer the token from.
72
113
  * @param args.hash - The transaction hash of the transfer.
114
+ * @param args.waitOptions - The options for waiting for the result of the transfer.
73
115
  * @returns The result of the transfer.
74
116
  */
75
117
  waitForResult(args: {
@@ -77,5 +119,6 @@ export interface TransferExecutionStrategy<T> {
77
119
  publicClient: PublicClient<Transport, Chain>;
78
120
  from: T;
79
121
  hash: Hex;
122
+ waitOptions?: WaitForUserOperationOptions["waitOptions"];
80
123
  }): Promise<TransferResult>;
81
124
  }
@@ -1,14 +1,21 @@
1
- import { SendUserOperationReturnType, SendUserOperationOptions } from "./sendUserOperation.js";
1
+ import { SendUserOperationOptions, SendUserOperationReturnType } from "./sendUserOperation.js";
2
+ import { GetUserOperationOptions, UserOperation } from "../../client/evm/evm.types.js";
3
+ import { EvmAccount, EvmSmartAccount } from "../../openapi-client/index.js";
2
4
 
3
- import type { ListTokenBalancesResult, ListTokenBalancesOptions } from "./listTokenBalances.js";
5
+ import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "./listTokenBalances.js";
4
6
  import type { RequestFaucetOptions, RequestFaucetResult } from "./requestFaucet.js";
5
7
  import type { SendTransactionOptions, TransactionResult } from "./sendTransaction.js";
6
- import type { TransferOptions, TransferResult } from "./transfer/types.js";
8
+ import type {
9
+ AccountTransferOptions,
10
+ SmartAccountTransferOptions,
11
+ TransferResult,
12
+ } from "./transfer/types.js";
7
13
  import type {
8
14
  WaitForUserOperationOptions,
9
15
  WaitForUserOperationReturnType,
10
16
  } from "./waitForUserOperation.js";
11
- export type Actions = {
17
+
18
+ type Actions<T extends EvmAccount | EvmSmartAccount> = {
12
19
  /**
13
20
  * Transfer an amount of a token from an account to another account.
14
21
  *
@@ -92,7 +99,9 @@ export type Actions = {
92
99
  * });
93
100
  * ```
94
101
  */
95
- transfer: (options: TransferOptions) => Promise<TransferResult>;
102
+ transfer: (
103
+ options: T extends EvmSmartAccount ? SmartAccountTransferOptions : AccountTransferOptions,
104
+ ) => Promise<TransferResult>;
96
105
 
97
106
  /**
98
107
  * List the token balances of an account.
@@ -132,7 +141,9 @@ export type Actions = {
132
141
  * ```
133
142
  */
134
143
  requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<RequestFaucetResult>;
144
+ };
135
145
 
146
+ export type AccountActions = Actions<EvmAccount> & {
136
147
  /**
137
148
  * Signs an EVM transaction and sends it to the specified network using the Coinbase API.
138
149
  * This method handles nonce management and gas estimation automatically.
@@ -178,7 +189,9 @@ export type Actions = {
178
189
  * ```
179
190
  */
180
191
  sendTransaction: (options: Omit<SendTransactionOptions, "address">) => Promise<TransactionResult>;
192
+ };
181
193
 
194
+ export type SmartAccountActions = Actions<EvmSmartAccount> & {
182
195
  /**
183
196
  * Sends a user operation.
184
197
  *
@@ -241,4 +254,23 @@ export type Actions = {
241
254
  waitForUserOperation: (
242
255
  options: Omit<WaitForUserOperationOptions, "smartAccountAddress">,
243
256
  ) => Promise<WaitForUserOperationReturnType>;
257
+
258
+ /**
259
+ * Gets a user operation by its hash.
260
+ *
261
+ * @param {GetUserOperationOptions} options - Parameters for getting the user operation.
262
+ * @param {string} options.userOpHash - The user operation hash.
263
+ *
264
+ * @returns A promise that resolves to the user operation.
265
+ *
266
+ * @example
267
+ * ```ts
268
+ * const userOp = await smartAccount.getUserOperation({
269
+ * userOpHash: "0x1234567890123456789012345678901234567890",
270
+ * });
271
+ * ```
272
+ */
273
+ getUserOperation: (
274
+ options: Omit<GetUserOperationOptions, "smartAccount">,
275
+ ) => Promise<UserOperation>;
244
276
  };
@@ -0,0 +1,35 @@
1
+ import { RequestFaucetOptions, SignatureResult } from "../../client/solana/solana.types.js";
2
+ import { CdpOpenApiClientType } from "../../openapi-client/index.js";
3
+
4
+ /**
5
+ * Requests funds from a Solana faucet.
6
+ *
7
+ * @param apiClient - The API client.
8
+ * @param {RequestFaucetOptions} options - Parameters for requesting funds from the Solana faucet.
9
+ * @param {string} options.address - The address to request funds for.
10
+ * @param {string} options.token - The token to request funds for.
11
+ * @param {string} [options.idempotencyKey] - An idempotency key.
12
+ *
13
+ * @returns A promise that resolves to the transaction signature.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const signature = await requestFaucet(cdp.solana, {
18
+ * address: "1234567890123456789012345678901234567890",
19
+ * token: "sol",
20
+ * });
21
+ * ```
22
+ */
23
+ export async function requestFaucet(
24
+ apiClient: CdpOpenApiClientType,
25
+ options: RequestFaucetOptions,
26
+ ): Promise<SignatureResult> {
27
+ const signature = await apiClient.requestSolanaFaucet(
28
+ { address: options.address, token: options.token },
29
+ options.idempotencyKey,
30
+ );
31
+
32
+ return {
33
+ signature: signature.transactionSignature,
34
+ };
35
+ }
@@ -0,0 +1,36 @@
1
+ import { SignMessageOptions, SignatureResult } from "../../client/solana/solana.types.js";
2
+ import { CdpOpenApiClientType } from "../../openapi-client/index.js";
3
+
4
+ /**
5
+ * Sign a message.
6
+ *
7
+ * @param apiClient - The API client.
8
+ * @param {SignMessageOptions} options - Parameters for signing the message.
9
+ * @param {string} options.address - The address to sign the message for.
10
+ * @param {string} options.message - The message to sign.
11
+ * @param {string} [options.idempotencyKey] - An idempotency key.
12
+ *
13
+ * @returns A promise that resolves to the transaction signature.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const signature = await signMessage(cdp.solana, {
18
+ * address: "1234567890123456789012345678901234567890",
19
+ * message: "Hello, world!",
20
+ * });
21
+ * ```
22
+ */
23
+ export async function signMessage(
24
+ apiClient: CdpOpenApiClientType,
25
+ options: SignMessageOptions,
26
+ ): Promise<SignatureResult> {
27
+ const signature = await apiClient.signSolanaMessage(
28
+ options.address,
29
+ { message: options.message },
30
+ options.idempotencyKey,
31
+ );
32
+
33
+ return {
34
+ signature: signature.signature,
35
+ };
36
+ }
@@ -0,0 +1,53 @@
1
+ import { SignTransactionOptions, SignatureResult } from "../../client/solana/solana.types.js";
2
+ import { CdpOpenApiClientType } from "../../openapi-client/index.js";
3
+
4
+ /**
5
+ * Signs a transaction.
6
+ *
7
+ * @param apiClient - The API client.
8
+ * @param {SignTransactionOptions} options - Parameters for signing the transaction.
9
+ * @param {string} options.address - The address to sign the transaction for.
10
+ * @param {string} options.transaction - The transaction to sign.
11
+ * @param {string} [options.idempotencyKey] - An idempotency key.
12
+ *
13
+ * @returns A promise that resolves to the signature.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * // Create a Solana account
18
+ * const account = await cdp.solana.createAccount();
19
+ *
20
+ * // Add your transaction instructions here
21
+ * const transaction = new Transaction()
22
+ *
23
+ * // Make sure to set requireAllSignatures to false, since signing will be done through the API
24
+ * const serializedTransaction = transaction.serialize({
25
+ * requireAllSignatures: false,
26
+ * });
27
+ *
28
+ * // Base64 encode the serialized transaction
29
+ * const transaction = Buffer.from(serializedTransaction).toString("base64");
30
+ *
31
+ * // When you want to sign a transaction, you can do so by address and base64 encoded transaction
32
+ * const signature = await signTransaction(cdp.solana, {
33
+ * address: account.address,
34
+ * transaction,
35
+ * });
36
+ * ```
37
+ */
38
+ export async function signTransaction(
39
+ apiClient: CdpOpenApiClientType,
40
+ options: SignTransactionOptions,
41
+ ): Promise<SignatureResult> {
42
+ const signature = await apiClient.signSolanaTransaction(
43
+ options.address,
44
+ {
45
+ transaction: options.transaction,
46
+ },
47
+ options.idempotencyKey,
48
+ );
49
+
50
+ return {
51
+ signature: signature.signedTransaction,
52
+ };
53
+ }
@@ -0,0 +1,87 @@
1
+ import {
2
+ RequestFaucetOptions,
3
+ SignatureResult,
4
+ SignMessageOptions,
5
+ SignTransactionOptions,
6
+ } from "../../client/solana/solana.types.js";
7
+
8
+ export type AccountActions = {
9
+ /**
10
+ * Requests funds from a Solana faucet.
11
+ *
12
+ * @param {RequestFaucetOptions} options - Parameters for requesting funds from the Solana faucet.
13
+ * @param {string} options.token - The token to request funds for.
14
+ * @param {string} [options.idempotencyKey] - An idempotency key.
15
+ *
16
+ * @returns A promise that resolves to the transaction hash.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * // Create a Solana account
21
+ * const account = await cdp.solana.createAccount();
22
+ *
23
+ * // Request funds from the Solana faucet
24
+ * const result = await account.requestFaucet({
25
+ * token: "sol",
26
+ * });
27
+ * ```
28
+ */
29
+ requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<SignatureResult>;
30
+
31
+ /**
32
+ * Signs a message.
33
+ *
34
+ * @param {SignMessageOptions} options - Parameters for signing the message.
35
+ * @param {string} options.address - The address to sign the message for.
36
+ * @param {string} options.message - The message to sign.
37
+ * @param {string} [options.idempotencyKey] - An idempotency key.
38
+ *
39
+ * @returns A promise that resolves to the signature.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * // Create a Solana account
44
+ * const account = await cdp.solana.createAccount();
45
+ *
46
+ * // Sign a message
47
+ * const { signature } = await account.signMessage({
48
+ * message: "Hello, world!",
49
+ * });
50
+ * ```
51
+ */
52
+ signMessage: (options: Omit<SignMessageOptions, "address">) => Promise<SignatureResult>;
53
+
54
+ /**
55
+ * Signs a transaction.
56
+ *
57
+ * @param {SignTransactionOptions} options - Parameters for signing the transaction.
58
+ * @param {string} options.address - The address to sign the transaction for.
59
+ * @param {string} options.transaction - The transaction to sign.
60
+ * @param {string} [options.idempotencyKey] - An idempotency key.
61
+ *
62
+ * @returns A promise that resolves to the signature.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * // Create a Solana account
67
+ * const account = await cdp.solana.createAccount();
68
+ *
69
+ * // Add your transaction instructions here
70
+ * const transaction = new Transaction()
71
+ *
72
+ * // Make sure to set requireAllSignatures to false, since signing will be done through the API
73
+ * const serializedTransaction = transaction.serialize({
74
+ * requireAllSignatures: false,
75
+ * });
76
+ *
77
+ * // Base64 encode the serialized transaction
78
+ * const transaction = Buffer.from(serializedTransaction).toString("base64");
79
+ *
80
+ * // When you want to sign a transaction, you can do so by address and base64 encoded transaction
81
+ * const { signature } = await account.signTransaction({
82
+ * transaction,
83
+ * });
84
+ * ```
85
+ */
86
+ signTransaction: (options: Omit<SignTransactionOptions, "address">) => Promise<SignatureResult>;
87
+ };
package/client/evm/evm.ts CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  } from "./evm.types.js";
25
25
  import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
26
26
  import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
27
+ import { getUserOperation } from "../../actions/evm/getUserOperation.js";
27
28
  import {
28
29
  listTokenBalances,
29
30
  ListTokenBalancesResult,
@@ -52,6 +53,7 @@ import type {
52
53
  TransactionResult,
53
54
  SendTransactionOptions,
54
55
  } from "../../actions/evm/sendTransaction.js";
56
+
55
57
  /**
56
58
  * The namespace containing all EVM methods.
57
59
  */
@@ -292,22 +294,7 @@ export class EvmClient implements EvmClientInterface {
292
294
  * ```
293
295
  */
294
296
  async getUserOperation(options: GetUserOperationOptions): Promise<UserOperation> {
295
- const userOp = await CdpOpenApiClient.getUserOperation(
296
- options.smartAccount.address,
297
- options.userOpHash,
298
- );
299
-
300
- return {
301
- calls: userOp.calls.map(call => ({
302
- to: call.to as Address,
303
- value: BigInt(call.value),
304
- data: call.data as Hex,
305
- })),
306
- network: userOp.network,
307
- status: userOp.status,
308
- transactionHash: userOp.transactionHash as Hex | undefined,
309
- userOpHash: userOp.userOpHash as Hex,
310
- };
297
+ return getUserOperation(CdpOpenApiClient, options);
311
298
  }
312
299
 
313
300
  /**
@@ -2,7 +2,7 @@ import type {
2
2
  EvmAccount as Account,
3
3
  EvmServerAccount as ServerAccount,
4
4
  EvmSmartAccount as SmartAccount,
5
- } from "../../accounts/types.js";
5
+ } from "../../accounts/evm/types.js";
6
6
  import type {
7
7
  ListTokenBalancesOptions,
8
8
  ListTokenBalancesResult,
@@ -16,7 +16,7 @@ import type {
16
16
  SendUserOperationOptions,
17
17
  SendUserOperationReturnType,
18
18
  } from "../../actions/evm/sendUserOperation.js";
19
- import type { Actions } from "../../actions/evm/types.js";
19
+ import type { SmartAccountActions } from "../../actions/evm/types.js";
20
20
  import type {
21
21
  EvmUserOperationNetwork,
22
22
  EvmUserOperationStatus,
@@ -181,7 +181,8 @@ export interface ListServerAccountsOptions {
181
181
  /**
182
182
  * A smart account that only contains the owner address.
183
183
  */
184
- export interface ReadonlySmartAccount extends Omit<SmartAccount, "owners" | keyof Actions> {
184
+ export interface ReadonlySmartAccount
185
+ extends Omit<SmartAccount, "owners" | keyof SmartAccountActions> {
185
186
  /** The owners of the smart account. */
186
187
  owners: Address[];
187
188
  }