@coinbase/cdp-sdk 1.5.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 (191) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +101 -3
  3. package/_cjs/accounts/evm/toEvmServerAccount.js +21 -0
  4. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  5. package/_cjs/accounts/evm/toEvmSmartAccount.js +35 -0
  6. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  7. package/_cjs/accounts/{types.js.map → evm/types.js.map} +1 -1
  8. package/_cjs/accounts/solana/toSolanaAccount.js +41 -0
  9. package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -0
  10. package/_cjs/accounts/solana/types.js +3 -0
  11. package/_cjs/accounts/solana/types.js.map +1 -0
  12. package/_cjs/actions/evm/getUserOperation.js +36 -0
  13. package/_cjs/actions/evm/getUserOperation.js.map +1 -0
  14. package/_cjs/actions/evm/listTokenBalances.js +33 -0
  15. package/_cjs/actions/evm/listTokenBalances.js.map +1 -0
  16. package/_cjs/actions/evm/requestFaucet.js +18 -0
  17. package/_cjs/actions/evm/requestFaucet.js.map +1 -0
  18. package/_cjs/actions/evm/sendTransaction.js +29 -0
  19. package/_cjs/actions/evm/sendTransaction.js.map +1 -0
  20. package/_cjs/actions/evm/sendUserOperation.js +5 -6
  21. package/_cjs/actions/evm/sendUserOperation.js.map +1 -1
  22. package/_cjs/actions/evm/transfer/accountTransferStrategy.js +11 -7
  23. package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  24. package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +13 -8
  25. package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
  26. package/_cjs/actions/evm/transfer/transfer.js +7 -3
  27. package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
  28. package/_cjs/actions/solana/requestFaucet.js +29 -0
  29. package/_cjs/actions/solana/requestFaucet.js.map +1 -0
  30. package/_cjs/actions/solana/signMessage.js +29 -0
  31. package/_cjs/actions/solana/signMessage.js.map +1 -0
  32. package/_cjs/actions/solana/signTransaction.js +46 -0
  33. package/_cjs/actions/solana/signTransaction.js.map +1 -0
  34. package/_cjs/actions/solana/types.js +3 -0
  35. package/_cjs/actions/solana/types.js.map +1 -0
  36. package/_cjs/client/evm/evm.js +10 -52
  37. package/_cjs/client/evm/evm.js.map +1 -1
  38. package/_cjs/client/solana/solana.js +22 -17
  39. package/_cjs/client/solana/solana.js.map +1 -1
  40. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +59 -1
  41. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  42. package/_cjs/openapi-client/generated/index.msw.js +3 -2
  43. package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
  44. package/_cjs/openapi-client/generated/policy-engine/policy-engine.js +56 -0
  45. package/_cjs/openapi-client/generated/policy-engine/policy-engine.js.map +1 -0
  46. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +284 -0
  47. package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -0
  48. package/_cjs/openapi-client/index.js +1 -0
  49. package/_cjs/openapi-client/index.js.map +1 -1
  50. package/_cjs/version.js +1 -1
  51. package/_esm/accounts/evm/toEvmServerAccount.js +21 -0
  52. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  53. package/_esm/accounts/evm/toEvmSmartAccount.js +35 -0
  54. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  55. package/_esm/accounts/{types.js.map → evm/types.js.map} +1 -1
  56. package/_esm/accounts/solana/toSolanaAccount.js +38 -0
  57. package/_esm/accounts/solana/toSolanaAccount.js.map +1 -0
  58. package/_esm/accounts/solana/types.js +2 -0
  59. package/_esm/accounts/solana/types.js.map +1 -0
  60. package/_esm/actions/evm/getUserOperation.js +33 -0
  61. package/_esm/actions/evm/getUserOperation.js.map +1 -0
  62. package/_esm/actions/evm/listTokenBalances.js +30 -0
  63. package/_esm/actions/evm/listTokenBalances.js.map +1 -0
  64. package/_esm/actions/evm/requestFaucet.js +15 -0
  65. package/_esm/actions/evm/requestFaucet.js.map +1 -0
  66. package/_esm/actions/evm/sendTransaction.js +26 -0
  67. package/_esm/actions/evm/sendTransaction.js.map +1 -0
  68. package/_esm/actions/evm/sendUserOperation.js +5 -6
  69. package/_esm/actions/evm/sendUserOperation.js.map +1 -1
  70. package/_esm/actions/evm/transfer/accountTransferStrategy.js +11 -7
  71. package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  72. package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +13 -8
  73. package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
  74. package/_esm/actions/evm/transfer/transfer.js +7 -3
  75. package/_esm/actions/evm/transfer/transfer.js.map +1 -1
  76. package/_esm/actions/solana/requestFaucet.js +26 -0
  77. package/_esm/actions/solana/requestFaucet.js.map +1 -0
  78. package/_esm/actions/solana/signMessage.js +26 -0
  79. package/_esm/actions/solana/signMessage.js.map +1 -0
  80. package/_esm/actions/solana/signTransaction.js +43 -0
  81. package/_esm/actions/solana/signTransaction.js.map +1 -0
  82. package/_esm/actions/solana/types.js +2 -0
  83. package/_esm/actions/solana/types.js.map +1 -0
  84. package/_esm/client/evm/evm.js +10 -52
  85. package/_esm/client/evm/evm.js.map +1 -1
  86. package/_esm/client/solana/solana.js +22 -17
  87. package/_esm/client/solana/solana.js.map +1 -1
  88. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +58 -0
  89. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  90. package/_esm/openapi-client/generated/index.msw.js +3 -2
  91. package/_esm/openapi-client/generated/index.msw.js.map +1 -1
  92. package/_esm/openapi-client/generated/policy-engine/policy-engine.js +48 -0
  93. package/_esm/openapi-client/generated/policy-engine/policy-engine.js.map +1 -0
  94. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +259 -0
  95. package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -0
  96. package/_esm/openapi-client/index.js +1 -0
  97. package/_esm/openapi-client/index.js.map +1 -1
  98. package/_esm/version.js +1 -1
  99. package/_types/accounts/evm/toEvmServerAccount.d.ts +1 -1
  100. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  101. package/_types/accounts/evm/toEvmSmartAccount.d.ts +1 -1
  102. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
  103. package/_types/accounts/{types.d.ts → evm/types.d.ts} +5 -5
  104. package/_types/accounts/evm/types.d.ts.map +1 -0
  105. package/_types/accounts/solana/toSolanaAccount.d.ts +20 -0
  106. package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -0
  107. package/_types/accounts/solana/types.d.ts +12 -0
  108. package/_types/accounts/solana/types.d.ts.map +1 -0
  109. package/_types/actions/evm/getUserOperation.d.ts +22 -0
  110. package/_types/actions/evm/getUserOperation.d.ts.map +1 -0
  111. package/_types/actions/evm/listTokenBalances.d.ts +76 -0
  112. package/_types/actions/evm/listTokenBalances.d.ts.map +1 -0
  113. package/_types/actions/evm/requestFaucet.d.ts +34 -0
  114. package/_types/actions/evm/requestFaucet.d.ts.map +1 -0
  115. package/_types/actions/evm/sendTransaction.d.ts +42 -0
  116. package/_types/actions/evm/sendTransaction.d.ts.map +1 -0
  117. package/_types/actions/evm/sendUserOperation.d.ts +4 -3
  118. package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
  119. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +1 -1
  120. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
  121. package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +1 -1
  122. package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
  123. package/_types/actions/evm/transfer/transfer.d.ts +3 -3
  124. package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
  125. package/_types/actions/evm/transfer/types.d.ts +41 -7
  126. package/_types/actions/evm/transfer/types.d.ts.map +1 -1
  127. package/_types/actions/evm/types.d.ts +168 -3
  128. package/_types/actions/evm/types.d.ts.map +1 -1
  129. package/_types/actions/solana/requestFaucet.d.ts +23 -0
  130. package/_types/actions/solana/requestFaucet.d.ts.map +1 -0
  131. package/_types/actions/solana/signMessage.d.ts +23 -0
  132. package/_types/actions/solana/signMessage.d.ts.map +1 -0
  133. package/_types/actions/solana/signTransaction.d.ts +38 -0
  134. package/_types/actions/solana/signTransaction.d.ts.map +1 -0
  135. package/_types/actions/solana/types.d.ts +80 -0
  136. package/_types/actions/solana/types.d.ts.map +1 -0
  137. package/_types/client/evm/evm.d.ts +6 -3
  138. package/_types/client/evm/evm.d.ts.map +1 -1
  139. package/_types/client/evm/evm.types.d.ts +12 -138
  140. package/_types/client/evm/evm.types.d.ts.map +1 -1
  141. package/_types/client/solana/solana.d.ts +5 -4
  142. package/_types/client/solana/solana.d.ts.map +1 -1
  143. package/_types/client/solana/solana.types.d.ts +8 -11
  144. package/_types/client/solana/solana.types.d.ts.map +1 -1
  145. package/_types/index.d.ts +1 -1
  146. package/_types/index.d.ts.map +1 -1
  147. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +218 -0
  148. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  149. package/_types/openapi-client/generated/index.msw.d.ts +3 -2
  150. package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
  151. package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts +43 -0
  152. package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts.map +1 -0
  153. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +25 -0
  154. package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -0
  155. package/_types/openapi-client/index.d.ts +1 -0
  156. package/_types/openapi-client/index.d.ts.map +1 -1
  157. package/_types/version.d.ts +1 -1
  158. package/accounts/evm/toEvmServerAccount.ts +35 -1
  159. package/accounts/evm/toEvmSmartAccount.ts +63 -1
  160. package/accounts/{types.ts → evm/types.ts} +5 -5
  161. package/accounts/solana/toSolanaAccount.ts +59 -0
  162. package/accounts/solana/types.ts +13 -0
  163. package/actions/evm/getUserOperation.ts +40 -0
  164. package/actions/evm/listTokenBalances.ts +107 -0
  165. package/actions/evm/requestFaucet.ts +46 -0
  166. package/actions/evm/sendTransaction.ts +73 -0
  167. package/actions/evm/sendUserOperation.ts +7 -7
  168. package/actions/evm/transfer/accountTransferStrategy.ts +12 -8
  169. package/actions/evm/transfer/smartAccountTransferStrategy.ts +14 -9
  170. package/actions/evm/transfer/transfer.ts +17 -6
  171. package/actions/evm/transfer/types.ts +55 -12
  172. package/actions/evm/types.ts +191 -3
  173. package/actions/solana/requestFaucet.ts +35 -0
  174. package/actions/solana/signMessage.ts +36 -0
  175. package/actions/solana/signTransaction.ts +53 -0
  176. package/actions/solana/types.ts +87 -0
  177. package/client/evm/evm.ts +28 -77
  178. package/client/evm/evm.types.ts +25 -151
  179. package/client/solana/solana.ts +32 -37
  180. package/client/solana/solana.types.ts +10 -15
  181. package/index.ts +1 -1
  182. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +274 -0
  183. package/openapi-client/generated/index.msw.ts +3 -2
  184. package/openapi-client/generated/policy-engine/policy-engine.msw.ts +404 -0
  185. package/openapi-client/generated/policy-engine/policy-engine.ts +95 -0
  186. package/openapi-client/index.ts +1 -0
  187. package/package.json +1 -1
  188. package/version.ts +1 -1
  189. package/_types/accounts/types.d.ts.map +0 -1
  190. /package/_cjs/accounts/{types.js → evm/types.js} +0 -0
  191. /package/_esm/accounts/{types.js → evm/types.js} +0 -0
@@ -1,6 +1,21 @@
1
- import { TransferOptions, TransferResult } from "./transfer/types.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
- export type Actions = {
5
+ import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "./listTokenBalances.js";
6
+ import type { RequestFaucetOptions, RequestFaucetResult } from "./requestFaucet.js";
7
+ import type { SendTransactionOptions, TransactionResult } from "./sendTransaction.js";
8
+ import type {
9
+ AccountTransferOptions,
10
+ SmartAccountTransferOptions,
11
+ TransferResult,
12
+ } from "./transfer/types.js";
13
+ import type {
14
+ WaitForUserOperationOptions,
15
+ WaitForUserOperationReturnType,
16
+ } from "./waitForUserOperation.js";
17
+
18
+ type Actions<T extends EvmAccount | EvmSmartAccount> = {
4
19
  /**
5
20
  * Transfer an amount of a token from an account to another account.
6
21
  *
@@ -84,5 +99,178 @@ export type Actions = {
84
99
  * });
85
100
  * ```
86
101
  */
87
- transfer: (options: TransferOptions) => Promise<TransferResult>;
102
+ transfer: (
103
+ options: T extends EvmSmartAccount ? SmartAccountTransferOptions : AccountTransferOptions,
104
+ ) => Promise<TransferResult>;
105
+
106
+ /**
107
+ * List the token balances of an account.
108
+ *
109
+ * @param options - The options for the list token balances.
110
+ * @param options.network - The network to list the token balances on.
111
+ *
112
+ * @returns The result of the list token balances.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const balances = await account.listTokenBalances({
117
+ * network: "base-sepolia",
118
+ * });
119
+ * ```
120
+ */
121
+ listTokenBalances: (
122
+ options: Omit<ListTokenBalancesOptions, "address">,
123
+ ) => Promise<ListTokenBalancesResult>;
124
+
125
+ /**
126
+ * Requests funds from an EVM faucet.
127
+ *
128
+ * @param {RequestFaucetOptions} options - Parameters for requesting funds from the EVM faucet.
129
+ * @param {string} options.network - The network to request funds from.
130
+ * @param {string} options.token - The token to request funds for.
131
+ * @param {string} [options.idempotencyKey] - An idempotency key.
132
+ *
133
+ * @returns A promise that resolves to the transaction hash.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const result = await account.requestFaucet({
138
+ * network: "base-sepolia",
139
+ * token: "eth",
140
+ * });
141
+ * ```
142
+ */
143
+ requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<RequestFaucetResult>;
144
+ };
145
+
146
+ export type AccountActions = Actions<EvmAccount> & {
147
+ /**
148
+ * Signs an EVM transaction and sends it to the specified network using the Coinbase API.
149
+ * This method handles nonce management and gas estimation automatically.
150
+ *
151
+ * @param {SendTransactionOptions} options - Configuration options for sending the transaction.
152
+ * @returns A promise that resolves to the transaction hash.
153
+ *
154
+ * @example
155
+ * **Sending an RLP-encoded transaction**
156
+ * ```ts
157
+ * import { parseEther, serializeTransaction } from "viem";
158
+ * import { baseSepolia } from "viem/chains";
159
+ *
160
+ * const { transactionHash } = await account.sendTransaction({
161
+ * transaction: serializeTransaction({
162
+ * to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
163
+ * value: parseEther("0.000001"),
164
+ * chainId: baseSepolia.id,
165
+ * // Fields below are optional, CDP API will populate them if omitted.
166
+ * // nonce
167
+ * // maxPriorityFeePerGas
168
+ * // maxFeePerGas
169
+ * // gas
170
+ * }),
171
+ * network: "base-sepolia",
172
+ * });
173
+ * ```
174
+ * @example
175
+ * **Sending an EIP-1559 transaction request object**
176
+ * ```ts
177
+ * const { transactionHash } = await account.sendTransaction({
178
+ * transaction: {
179
+ * to: "0x4252e0c9A3da5A2700e7d91cb50aEf522D0C6Fe8",
180
+ * value: parseEther("0.000001"),
181
+ * // Fields below are optional, CDP API will populate them if omitted.
182
+ * // nonce
183
+ * // maxPriorityFeePerGas
184
+ * // maxFeePerGas
185
+ * // gas
186
+ * },
187
+ * network: "base-sepolia",
188
+ * });
189
+ * ```
190
+ */
191
+ sendTransaction: (options: Omit<SendTransactionOptions, "address">) => Promise<TransactionResult>;
192
+ };
193
+
194
+ export type SmartAccountActions = Actions<EvmSmartAccount> & {
195
+ /**
196
+ * Sends a user operation.
197
+ *
198
+ * @param {SendUserOperationOptions} options - Parameters for sending the user operation.
199
+ * @param {string} options.network - The network to send the user operation on.
200
+ * @param {EvmCall[]} options.calls - The calls to include in the user operation.
201
+ * @param {string} [options.paymasterUrl] - The optional paymaster URL to use for the user operation.
202
+ * @param {string} [options.idempotencyKey] - An idempotency key.
203
+ *
204
+ * @returns A promise that resolves to an object containing the smart account address,
205
+ * the user operation hash, and the status of the user operation.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * const userOp = await smartAccount.sendUserOperation({
210
+ * network: "base-sepolia",
211
+ * calls: [
212
+ * {
213
+ * to: "0x1234567890123456789012345678901234567890",
214
+ * value: parseEther("0.000001"),
215
+ * data: "0x",
216
+ * },
217
+ * ],
218
+ * });
219
+ * ```
220
+ */
221
+ sendUserOperation: (
222
+ options: Omit<SendUserOperationOptions<unknown[]>, "smartAccount">,
223
+ ) => Promise<SendUserOperationReturnType>;
224
+
225
+ /**
226
+ * Waits for a user operation to complete or fail.
227
+ *
228
+ * @param {WaitForUserOperationOptions} options - Parameters for waiting for the user operation.
229
+ * @param {string} options.userOpHash - The user operation hash.
230
+ * @param {WaitOptions} [options.waitOptions] - Optional parameters for the wait operation.
231
+ *
232
+ * @returns A promise that resolves to the transaction receipt.
233
+ *
234
+ * @example
235
+ * ```ts
236
+ * // Send a user operation and get the user operation hash
237
+ * const { userOpHash } = await smartAccount.sendUserOperation({
238
+ * network: "base-sepolia",
239
+ * calls: [
240
+ * {
241
+ * to: "0x0000000000000000000000000000000000000000",
242
+ * value: parseEther("0.000001"),
243
+ * data: "0x",
244
+ * },
245
+ * ],
246
+ * });
247
+ *
248
+ * // Wait for the user operation to complete or fail
249
+ * const result = await smartAccount.waitForUserOperation({
250
+ * userOpHash: userOp.userOpHash,
251
+ * });
252
+ * ```
253
+ */
254
+ waitForUserOperation: (
255
+ options: Omit<WaitForUserOperationOptions, "smartAccountAddress">,
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>;
88
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
@@ -1,14 +1,11 @@
1
- import { Address, serializeTransaction } from "viem";
1
+ import { Address } from "viem";
2
2
 
3
3
  import {
4
4
  CreateServerAccountOptions,
5
5
  GetServerAccountOptions,
6
6
  ListServerAccountsOptions,
7
7
  CreateSmartAccountOptions,
8
- RequestFaucetOptions,
9
- SendUserOperationOptions,
10
8
  WaitForUserOperationOptions,
11
- RequestFaucetResult,
12
9
  SignHashOptions,
13
10
  SignatureResult,
14
11
  SignMessageOptions,
@@ -23,16 +20,25 @@ import {
23
20
  GetUserOperationOptions,
24
21
  ListSmartAccountResult,
25
22
  ListSmartAccountsOptions,
26
- ListTokenBalancesOptions,
27
- ListTokenBalancesResult,
28
- SendTransactionOptions,
29
- TransactionResult,
30
23
  GetOrCreateServerAccountOptions,
31
24
  } from "./evm.types.js";
32
25
  import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
33
26
  import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
27
+ import { getUserOperation } from "../../actions/evm/getUserOperation.js";
28
+ import {
29
+ listTokenBalances,
30
+ ListTokenBalancesResult,
31
+ ListTokenBalancesOptions,
32
+ } from "../../actions/evm/listTokenBalances.js";
33
+ import {
34
+ RequestFaucetOptions,
35
+ RequestFaucetResult,
36
+ requestFaucet,
37
+ } from "../../actions/evm/requestFaucet.js";
38
+ import { sendTransaction } from "../../actions/evm/sendTransaction.js";
34
39
  import {
35
40
  sendUserOperation,
41
+ SendUserOperationOptions,
36
42
  SendUserOperationReturnType,
37
43
  } from "../../actions/evm/sendUserOperation.js";
38
44
  import {
@@ -43,6 +49,11 @@ import { APIError } from "../../openapi-client/errors.js";
43
49
  import { CdpOpenApiClient } from "../../openapi-client/index.js";
44
50
  import { Hex } from "../../types/misc.js";
45
51
 
52
+ import type {
53
+ TransactionResult,
54
+ SendTransactionOptions,
55
+ } from "../../actions/evm/sendTransaction.js";
56
+
46
57
  /**
47
58
  * The namespace containing all EVM methods.
48
59
  */
@@ -283,22 +294,7 @@ export class EvmClient implements EvmClientInterface {
283
294
  * ```
284
295
  */
285
296
  async getUserOperation(options: GetUserOperationOptions): Promise<UserOperation> {
286
- const userOp = await CdpOpenApiClient.getUserOperation(
287
- options.smartAccount.address,
288
- options.userOpHash,
289
- );
290
-
291
- return {
292
- calls: userOp.calls.map(call => ({
293
- to: call.to as Address,
294
- value: BigInt(call.value),
295
- data: call.data as Hex,
296
- })),
297
- network: userOp.network,
298
- status: userOp.status,
299
- transactionHash: userOp.transactionHash as Hex | undefined,
300
- userOpHash: userOp.userOpHash as Hex,
301
- };
297
+ return getUserOperation(CdpOpenApiClient, options);
302
298
  }
303
299
 
304
300
  /**
@@ -376,28 +372,7 @@ export class EvmClient implements EvmClientInterface {
376
372
  * }
377
373
  */
378
374
  async listTokenBalances(options: ListTokenBalancesOptions): Promise<ListTokenBalancesResult> {
379
- const response = await CdpOpenApiClient.listEvmTokenBalances(options.network, options.address, {
380
- pageSize: options.pageSize,
381
- pageToken: options.pageToken,
382
- });
383
-
384
- const balances = response.balances.map(balance => {
385
- return {
386
- token: {
387
- network: balance.token.network,
388
- contractAddress: balance.token.contractAddress as Address,
389
- },
390
- amount: {
391
- amount: BigInt(balance.amount.amount),
392
- decimals: BigInt(balance.amount.decimals),
393
- },
394
- };
395
- });
396
-
397
- return {
398
- balances,
399
- nextPageToken: response.nextPageToken,
400
- };
375
+ return listTokenBalances(CdpOpenApiClient, options);
401
376
  }
402
377
 
403
378
  /**
@@ -509,14 +484,7 @@ export class EvmClient implements EvmClientInterface {
509
484
  * ```
510
485
  */
511
486
  async requestFaucet(options: RequestFaucetOptions): Promise<RequestFaucetResult> {
512
- const { transactionHash } = await CdpOpenApiClient.requestEvmFaucet(
513
- { address: options.address, network: options.network, token: options.token },
514
- options.idempotencyKey,
515
- );
516
-
517
- return {
518
- transactionHash: transactionHash as Hex,
519
- };
487
+ return requestFaucet(CdpOpenApiClient, options);
520
488
  }
521
489
 
522
490
  /**
@@ -566,27 +534,7 @@ export class EvmClient implements EvmClientInterface {
566
534
  * ```
567
535
  */
568
536
  async sendTransaction(options: SendTransactionOptions): Promise<TransactionResult> {
569
- const { address, network, idempotencyKey } = options;
570
- let transaction = options.transaction;
571
-
572
- if (typeof transaction !== "string") {
573
- transaction = serializeTransaction({
574
- ...transaction,
575
- // chainId is ignored in favor of network
576
- chainId: 1,
577
- type: "eip1559",
578
- });
579
- }
580
-
581
- const result = await CdpOpenApiClient.sendEvmTransaction(
582
- address,
583
- { transaction, network },
584
- idempotencyKey,
585
- );
586
-
587
- return {
588
- transactionHash: result.transactionHash as Hex,
589
- };
537
+ return sendTransaction(CdpOpenApiClient, options);
590
538
  }
591
539
 
592
540
  /**
@@ -617,8 +565,11 @@ export class EvmClient implements EvmClientInterface {
617
565
  * });
618
566
  * ```
619
567
  */
620
- async sendUserOperation(options: SendUserOperationOptions): Promise<SendUserOperationReturnType> {
621
- return sendUserOperation(CdpOpenApiClient, options.smartAccount, {
568
+ async sendUserOperation(
569
+ options: SendUserOperationOptions<unknown[]>,
570
+ ): Promise<SendUserOperationReturnType> {
571
+ return sendUserOperation(CdpOpenApiClient, {
572
+ smartAccount: options.smartAccount,
622
573
  network: options.network,
623
574
  calls: options.calls,
624
575
  paymasterUrl: options.paymasterUrl,