@coinbase/cdp-sdk 1.25.0 → 1.27.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 (174) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +58 -2
  3. package/_cjs/accounts/evm/networkToChainResolver.js +68 -0
  4. package/_cjs/accounts/evm/networkToChainResolver.js.map +1 -0
  5. package/_cjs/accounts/evm/resolveViemClients.js +6 -32
  6. package/_cjs/accounts/evm/resolveViemClients.js.map +1 -1
  7. package/_cjs/accounts/evm/toEvmServerAccount.js +84 -0
  8. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  9. package/_cjs/accounts/evm/toEvmSmartAccount.js +93 -0
  10. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  11. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +19 -7
  12. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
  13. package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +65 -0
  14. package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
  15. package/_cjs/accounts/solana/toSolanaAccount.js +20 -0
  16. package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
  17. package/_cjs/actions/evm/fund/fund.js +3 -2
  18. package/_cjs/actions/evm/fund/fund.js.map +1 -1
  19. package/_cjs/actions/evm/fund/quoteFund.js +3 -2
  20. package/_cjs/actions/evm/fund/quoteFund.js.map +1 -1
  21. package/_cjs/actions/solana/sendTransaction.js +32 -0
  22. package/_cjs/actions/solana/sendTransaction.js.map +1 -0
  23. package/_cjs/analytics.js +39 -3
  24. package/_cjs/analytics.js.map +1 -1
  25. package/_cjs/auth/utils/jwt.js +6 -5
  26. package/_cjs/auth/utils/jwt.js.map +1 -1
  27. package/_cjs/client/cdp.js +4 -1
  28. package/_cjs/client/cdp.js.map +1 -1
  29. package/_cjs/client/evm/evm.js +116 -10
  30. package/_cjs/client/evm/evm.js.map +1 -1
  31. package/_cjs/client/policies/policies.js +22 -0
  32. package/_cjs/client/policies/policies.js.map +1 -1
  33. package/_cjs/client/solana/solana.js +85 -8
  34. package/_cjs/client/solana/solana.js.map +1 -1
  35. package/_cjs/constants.js +1 -1
  36. package/_cjs/constants.js.map +1 -1
  37. package/_cjs/errors.js +19 -1
  38. package/_cjs/errors.js.map +1 -1
  39. package/_cjs/index.js +3 -1
  40. package/_cjs/index.js.map +1 -1
  41. package/_cjs/openapi-client/cdpApiClient.js +46 -6
  42. package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
  43. package/_cjs/openapi-client/errors.js +38 -9
  44. package/_cjs/openapi-client/errors.js.map +1 -1
  45. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +6 -1
  46. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  47. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +34 -1
  48. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
  49. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +18 -1
  50. package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
  51. package/_cjs/version.js +1 -1
  52. package/_esm/accounts/evm/networkToChainResolver.js +31 -0
  53. package/_esm/accounts/evm/networkToChainResolver.js.map +1 -0
  54. package/_esm/accounts/evm/resolveViemClients.js +4 -30
  55. package/_esm/accounts/evm/resolveViemClients.js.map +1 -1
  56. package/_esm/accounts/evm/toEvmServerAccount.js +84 -0
  57. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  58. package/_esm/accounts/evm/toEvmSmartAccount.js +93 -0
  59. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  60. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +19 -7
  61. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
  62. package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +65 -0
  63. package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
  64. package/_esm/accounts/solana/toSolanaAccount.js +20 -0
  65. package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
  66. package/_esm/actions/evm/fund/fund.js +3 -2
  67. package/_esm/actions/evm/fund/fund.js.map +1 -1
  68. package/_esm/actions/evm/fund/quoteFund.js +3 -2
  69. package/_esm/actions/evm/fund/quoteFund.js.map +1 -1
  70. package/_esm/actions/solana/sendTransaction.js +29 -0
  71. package/_esm/actions/solana/sendTransaction.js.map +1 -0
  72. package/_esm/analytics.js +39 -3
  73. package/_esm/analytics.js.map +1 -1
  74. package/_esm/auth/utils/jwt.js +3 -2
  75. package/_esm/auth/utils/jwt.js.map +1 -1
  76. package/_esm/client/cdp.js +4 -1
  77. package/_esm/client/cdp.js.map +1 -1
  78. package/_esm/client/evm/evm.js +110 -4
  79. package/_esm/client/evm/evm.js.map +1 -1
  80. package/_esm/client/policies/policies.js +22 -0
  81. package/_esm/client/policies/policies.js.map +1 -1
  82. package/_esm/client/solana/solana.js +82 -5
  83. package/_esm/client/solana/solana.js.map +1 -1
  84. package/_esm/constants.js +1 -1
  85. package/_esm/constants.js.map +1 -1
  86. package/_esm/errors.js +17 -0
  87. package/_esm/errors.js.map +1 -1
  88. package/_esm/index.js +1 -0
  89. package/_esm/index.js.map +1 -1
  90. package/_esm/openapi-client/cdpApiClient.js +47 -7
  91. package/_esm/openapi-client/cdpApiClient.js.map +1 -1
  92. package/_esm/openapi-client/errors.js +36 -8
  93. package/_esm/openapi-client/errors.js.map +1 -1
  94. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +5 -0
  95. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  96. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +32 -0
  97. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
  98. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +15 -0
  99. package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
  100. package/_esm/version.js +1 -1
  101. package/_types/accounts/evm/networkToChainResolver.d.ts +14 -0
  102. package/_types/accounts/evm/networkToChainResolver.d.ts.map +1 -0
  103. package/_types/accounts/evm/resolveViemClients.d.ts.map +1 -1
  104. package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
  105. package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
  106. package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
  107. package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
  108. package/_types/accounts/evm/types.d.ts +3 -3
  109. package/_types/accounts/evm/types.d.ts.map +1 -1
  110. package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
  111. package/_types/actions/evm/fund/fund.d.ts.map +1 -1
  112. package/_types/actions/evm/fund/quoteFund.d.ts.map +1 -1
  113. package/_types/actions/evm/types.d.ts +36 -3
  114. package/_types/actions/evm/types.d.ts.map +1 -1
  115. package/_types/actions/solana/sendTransaction.d.ts +23 -0
  116. package/_types/actions/solana/sendTransaction.d.ts.map +1 -0
  117. package/_types/analytics.d.ts +36 -1
  118. package/_types/analytics.d.ts.map +1 -1
  119. package/_types/auth/utils/jwt.d.ts.map +1 -1
  120. package/_types/client/cdp.d.ts.map +1 -1
  121. package/_types/client/evm/evm.d.ts +1 -0
  122. package/_types/client/evm/evm.d.ts.map +1 -1
  123. package/_types/client/policies/policies.d.ts.map +1 -1
  124. package/_types/client/solana/solana.d.ts +21 -2
  125. package/_types/client/solana/solana.d.ts.map +1 -1
  126. package/_types/client/solana/solana.types.d.ts +22 -3
  127. package/_types/client/solana/solana.types.d.ts.map +1 -1
  128. package/_types/constants.d.ts +1 -1
  129. package/_types/constants.d.ts.map +1 -1
  130. package/_types/errors.d.ts +11 -0
  131. package/_types/errors.d.ts.map +1 -1
  132. package/_types/index.d.ts +1 -0
  133. package/_types/index.d.ts.map +1 -1
  134. package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
  135. package/_types/openapi-client/errors.d.ts +46 -9
  136. package/_types/openapi-client/errors.d.ts.map +1 -1
  137. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +18 -0
  138. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  139. package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +27 -1
  140. package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
  141. package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +3 -1
  142. package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
  143. package/_types/openapi-client/index.d.ts +2 -0
  144. package/_types/openapi-client/index.d.ts.map +1 -1
  145. package/_types/version.d.ts +1 -1
  146. package/accounts/evm/networkToChainResolver.ts +34 -0
  147. package/accounts/evm/resolveViemClients.ts +6 -32
  148. package/accounts/evm/toEvmServerAccount.ts +98 -0
  149. package/accounts/evm/toEvmSmartAccount.ts +114 -2
  150. package/accounts/evm/toNetworkScopedEvmServerAccount.ts +22 -8
  151. package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +75 -0
  152. package/accounts/evm/types.ts +3 -3
  153. package/accounts/solana/toSolanaAccount.ts +24 -0
  154. package/actions/evm/fund/fund.ts +3 -2
  155. package/actions/evm/fund/quoteFund.ts +3 -2
  156. package/actions/evm/types.ts +41 -2
  157. package/actions/solana/sendTransaction.ts +38 -0
  158. package/analytics.ts +73 -4
  159. package/auth/utils/jwt.ts +5 -2
  160. package/client/cdp.ts +7 -1
  161. package/client/evm/evm.ts +135 -6
  162. package/client/policies/policies.ts +28 -0
  163. package/client/solana/solana.ts +97 -5
  164. package/client/solana/solana.types.ts +25 -1
  165. package/constants.ts +1 -1
  166. package/errors.ts +18 -0
  167. package/index.ts +1 -0
  168. package/openapi-client/cdpApiClient.ts +87 -17
  169. package/openapi-client/errors.ts +65 -10
  170. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +24 -0
  171. package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +32 -0
  172. package/openapi-client/generated/solana-accounts/solana-accounts.ts +43 -0
  173. package/package.json +1 -1
  174. package/version.ts +1 -1
@@ -1,3 +1,4 @@
1
+ import { resolveNetworkToChain } from "./networkToChainResolver.js";
1
2
  import { toNetworkScopedEvmSmartAccount } from "./toNetworkScopedEvmSmartAccount.js";
2
3
  import { fund, FundOptions } from "../../actions/evm/fund/fund.js";
3
4
  import { Quote } from "../../actions/evm/fund/Quote.js";
@@ -24,6 +25,7 @@ import {
24
25
  type SendUserOperationReturnType,
25
26
  sendUserOperation,
26
27
  } from "../../actions/evm/sendUserOperation.js";
28
+ import { signAndWrapTypedDataForSmartAccount } from "../../actions/evm/signAndWrapTypedDataForSmartAccount.js";
27
29
  import { createSwapQuote } from "../../actions/evm/swap/createSwapQuote.js";
28
30
  import { sendSwapOperation } from "../../actions/evm/swap/sendSwapOperation.js";
29
31
  import { smartAccountTransferStrategy } from "../../actions/evm/transfer/smartAccountTransferStrategy.js";
@@ -33,7 +35,12 @@ import {
33
35
  WaitForUserOperationOptions,
34
36
  WaitForUserOperationReturnType,
35
37
  } from "../../actions/evm/waitForUserOperation.js";
36
- import { GetUserOperationOptions, UserOperation } from "../../client/evm/evm.types.js";
38
+ import { Analytics } from "../../analytics.js";
39
+ import {
40
+ GetUserOperationOptions,
41
+ SignTypedDataOptions,
42
+ UserOperation,
43
+ } from "../../client/evm/evm.types.js";
37
44
 
38
45
  import type { EvmAccount, EvmSmartAccount, KnownEvmNetworks } from "./types.js";
39
46
  import type {
@@ -46,7 +53,7 @@ import type {
46
53
  CdpOpenApiClientType,
47
54
  EvmSmartAccount as EvmSmartAccountModel,
48
55
  } from "../../openapi-client/index.js";
49
- import type { Address } from "../../types/misc.js";
56
+ import type { Address, Hex } from "../../types/misc.js";
50
57
 
51
58
  /**
52
59
  * Options for converting a pre-existing EvmSmartAccount and owner to a EvmSmartAccount
@@ -79,11 +86,27 @@ export function toEvmSmartAccount(
79
86
  owners: [options.owner],
80
87
  policies: options.smartAccount.policies,
81
88
  async transfer(transferArgs): Promise<SendUserOperationReturnType> {
89
+ Analytics.trackAction({
90
+ action: "transfer",
91
+ accountType: "evm_smart",
92
+ properties: {
93
+ network: transferArgs.network,
94
+ },
95
+ });
96
+
82
97
  return transfer(apiClient, account, transferArgs, smartAccountTransferStrategy);
83
98
  },
84
99
  async listTokenBalances(
85
100
  options: Omit<ListTokenBalancesOptions, "address">,
86
101
  ): Promise<ListTokenBalancesResult> {
102
+ Analytics.trackAction({
103
+ action: "list_token_balances",
104
+ accountType: "evm_smart",
105
+ properties: {
106
+ network: options.network,
107
+ },
108
+ });
109
+
87
110
  return listTokenBalances(apiClient, {
88
111
  ...options,
89
112
  address: this.address,
@@ -92,6 +115,14 @@ export function toEvmSmartAccount(
92
115
  async sendUserOperation(
93
116
  options: Omit<SendUserOperationOptions<unknown[]>, "smartAccount">,
94
117
  ): Promise<SendUserOperationReturnType> {
118
+ Analytics.trackAction({
119
+ action: "send_user_operation",
120
+ accountType: "evm_smart",
121
+ properties: {
122
+ network: options.network,
123
+ },
124
+ });
125
+
95
126
  return sendUserOperation(apiClient, {
96
127
  ...options,
97
128
  smartAccount: account,
@@ -100,6 +131,11 @@ export function toEvmSmartAccount(
100
131
  async waitForUserOperation(
101
132
  options: Omit<WaitForUserOperationOptions, "smartAccountAddress">,
102
133
  ): Promise<WaitForUserOperationReturnType> {
134
+ Analytics.trackAction({
135
+ action: "wait_for_user_operation",
136
+ accountType: "evm_smart",
137
+ });
138
+
103
139
  return waitForUserOperation(apiClient, {
104
140
  ...options,
105
141
  smartAccountAddress: account.address,
@@ -108,6 +144,11 @@ export function toEvmSmartAccount(
108
144
  async getUserOperation(
109
145
  options: Omit<GetUserOperationOptions, "smartAccount">,
110
146
  ): Promise<UserOperation> {
147
+ Analytics.trackAction({
148
+ action: "get_user_operation",
149
+ accountType: "evm_smart",
150
+ });
151
+
111
152
  return getUserOperation(apiClient, {
112
153
  ...options,
113
154
  smartAccount: account,
@@ -116,18 +157,42 @@ export function toEvmSmartAccount(
116
157
  async requestFaucet(
117
158
  options: Omit<RequestFaucetOptions, "address">,
118
159
  ): Promise<RequestFaucetResult> {
160
+ Analytics.trackAction({
161
+ action: "request_faucet",
162
+ accountType: "evm_smart",
163
+ properties: {
164
+ network: options.network,
165
+ },
166
+ });
167
+
119
168
  return requestFaucet(apiClient, {
120
169
  ...options,
121
170
  address: account.address,
122
171
  });
123
172
  },
124
173
  async quoteFund(options: Omit<QuoteFundOptions, "address">): Promise<Quote> {
174
+ Analytics.trackAction({
175
+ action: "quote_fund",
176
+ accountType: "evm_smart",
177
+ properties: {
178
+ network: options.network,
179
+ },
180
+ });
181
+
125
182
  return quoteFund(apiClient, {
126
183
  ...options,
127
184
  address: this.address,
128
185
  });
129
186
  },
130
187
  async fund(options: Omit<FundOptions, "address">): Promise<FundOperationResult> {
188
+ Analytics.trackAction({
189
+ action: "fund",
190
+ accountType: "evm_smart",
191
+ properties: {
192
+ network: options.network,
193
+ },
194
+ });
195
+
131
196
  return fund(apiClient, {
132
197
  ...options,
133
198
  address: this.address,
@@ -136,9 +201,22 @@ export function toEvmSmartAccount(
136
201
  async waitForFundOperationReceipt(
137
202
  options: WaitForFundOperationOptions,
138
203
  ): Promise<WaitForFundOperationResult> {
204
+ Analytics.trackAction({
205
+ action: "wait_for_fund_operation_receipt",
206
+ accountType: "evm_smart",
207
+ });
208
+
139
209
  return waitForFundOperationReceipt(apiClient, options);
140
210
  },
141
211
  async quoteSwap(options: SmartAccountQuoteSwapOptions): Promise<SmartAccountQuoteSwapResult> {
212
+ Analytics.trackAction({
213
+ action: "quote_swap",
214
+ accountType: "evm_smart",
215
+ properties: {
216
+ network: options.network,
217
+ },
218
+ });
219
+
142
220
  return createSwapQuote(apiClient, {
143
221
  ...options,
144
222
  taker: this.address, // Always use smart account's address as taker
@@ -147,6 +225,14 @@ export function toEvmSmartAccount(
147
225
  });
148
226
  },
149
227
  async swap(options: SmartAccountSwapOptions): Promise<SmartAccountSwapResult> {
228
+ Analytics.trackAction({
229
+ action: "swap",
230
+ accountType: "evm_smart",
231
+ properties: {
232
+ network: "network" in options ? options.network : undefined,
233
+ },
234
+ });
235
+
150
236
  return sendSwapOperation(apiClient, {
151
237
  ...options,
152
238
  smartAccount: account,
@@ -154,10 +240,36 @@ export function toEvmSmartAccount(
154
240
  signerAddress: this.owners[0].address, // Always use owner's address as signer
155
241
  });
156
242
  },
243
+ async signTypedData(
244
+ options: Omit<SignTypedDataOptions, "address"> & { network: KnownEvmNetworks },
245
+ ): Promise<Hex> {
246
+ Analytics.trackAction({
247
+ action: "sign_typed_data",
248
+ accountType: "evm_smart",
249
+ properties: {
250
+ network: options.network,
251
+ },
252
+ });
253
+
254
+ const result = await signAndWrapTypedDataForSmartAccount(apiClient, {
255
+ chainId: BigInt(resolveNetworkToChain(options.network).id),
256
+ smartAccount: account,
257
+ typedData: options,
258
+ });
259
+ return result.signature;
260
+ },
157
261
 
158
262
  name: options.smartAccount.name,
159
263
  type: "evm-smart",
160
264
  useNetwork: async <Network extends KnownEvmNetworks>(network: Network) => {
265
+ Analytics.trackAction({
266
+ action: "use_network",
267
+ accountType: "evm_smart",
268
+ properties: {
269
+ network,
270
+ },
271
+ });
272
+
161
273
  return toNetworkScopedEvmSmartAccount(apiClient, {
162
274
  smartAccount: account,
163
275
  owner: options.owner,
@@ -5,6 +5,7 @@ import { mapChainToNetwork } from "./chainToNetworkMapper.js";
5
5
  import { isMethodSupportedOnNetwork } from "./networkCapabilities.js";
6
6
  import { resolveViemClients } from "./resolveViemClients.js";
7
7
  import { transferWithViem } from "../../actions/evm/transfer/transferWithViem.js";
8
+ import { Analytics } from "../../analytics.js";
8
9
 
9
10
  import type { EvmServerAccount, NetworkScopedEvmServerAccount } from "./types.js";
10
11
  import type { FundOptions } from "../../actions/evm/fund/fund.js";
@@ -74,6 +75,14 @@ export async function toNetworkScopedEvmServerAccount<Network extends string>(
74
75
  network: mapChainToNetwork(chain) as SendEvmTransactionBodyNetwork,
75
76
  });
76
77
  } else {
78
+ Analytics.trackAction({
79
+ action: "send_transaction",
80
+ accountType: "evm_server",
81
+ properties: {
82
+ network: options.network,
83
+ },
84
+ });
85
+
77
86
  const hash = await walletClient.sendTransaction(
78
87
  txOpts.transaction as TransactionRequestEIP1559,
79
88
  );
@@ -87,12 +96,25 @@ export async function toNetworkScopedEvmServerAccount<Network extends string>(
87
96
  network: mapChainToNetwork(chain) as SendEvmTransactionBodyNetwork,
88
97
  });
89
98
  } else {
99
+ Analytics.trackAction({
100
+ action: "transfer",
101
+ accountType: "evm_server",
102
+ properties: {
103
+ network: options.network,
104
+ },
105
+ });
106
+
90
107
  return transferWithViem(walletClient, account, transferArgs);
91
108
  }
92
109
  },
93
110
  waitForTransactionReceipt: async (
94
111
  waitOptions: WaitForTransactionReceiptParameters | TransactionResult,
95
112
  ) => {
113
+ Analytics.trackAction({
114
+ action: "wait_for_transaction_receipt",
115
+ accountType: "evm_server",
116
+ });
117
+
96
118
  if ("transactionHash" in waitOptions) {
97
119
  return publicClient.waitForTransactionReceipt({
98
120
  hash: waitOptions.transactionHash,
@@ -149,14 +171,6 @@ export async function toNetworkScopedEvmServerAccount<Network extends string>(
149
171
  });
150
172
  }
151
173
 
152
- if (isMethodSupportedOnNetwork("transfer", options.network)) {
153
- Object.assign(account, {
154
- transfer: async (transferOptions: TransferOptions) => {
155
- return options.account.transfer(transferOptions);
156
- },
157
- });
158
- }
159
-
160
174
  if (isMethodSupportedOnNetwork("quoteSwap", options.network)) {
161
175
  Object.assign(account, {
162
176
  quoteSwap: async (quoteSwapOptions: AccountQuoteSwapOptions) => {
@@ -12,6 +12,7 @@ import { sendSwapOperation } from "../../actions/evm/swap/sendSwapOperation.js";
12
12
  import { smartAccountTransferStrategy } from "../../actions/evm/transfer/smartAccountTransferStrategy.js";
13
13
  import { transfer } from "../../actions/evm/transfer/transfer.js";
14
14
  import { waitForUserOperation } from "../../actions/evm/waitForUserOperation.js";
15
+ import { Analytics } from "../../analytics.js";
15
16
 
16
17
  import type {
17
18
  EvmAccount,
@@ -84,6 +85,14 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
84
85
  sendUserOperation: async (
85
86
  userOpOptions: Omit<SendUserOperationOptions<unknown[]>, "smartAccount" | "network">,
86
87
  ) => {
88
+ Analytics.trackAction({
89
+ action: "send_user_operation",
90
+ accountType: "evm_smart",
91
+ properties: {
92
+ network: options.network,
93
+ },
94
+ });
95
+
87
96
  return sendUserOperation(apiClient, {
88
97
  ...userOpOptions,
89
98
  smartAccount: options.smartAccount,
@@ -94,12 +103,22 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
94
103
  waitForUserOperation: async (
95
104
  waitOptions: Omit<WaitForUserOperationOptions, "smartAccountAddress">,
96
105
  ) => {
106
+ Analytics.trackAction({
107
+ action: "wait_for_user_operation",
108
+ accountType: "evm_smart",
109
+ });
110
+
97
111
  return waitForUserOperation(apiClient, {
98
112
  ...waitOptions,
99
113
  smartAccountAddress: options.smartAccount.address,
100
114
  });
101
115
  },
102
116
  getUserOperation: async (getOptions: Omit<GetUserOperationOptions, "smartAccount">) => {
117
+ Analytics.trackAction({
118
+ action: "get_user_operation",
119
+ accountType: "evm_smart",
120
+ });
121
+
103
122
  return getUserOperation(apiClient, {
104
123
  ...getOptions,
105
124
  smartAccount: options.smartAccount,
@@ -110,6 +129,14 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
110
129
  if (isMethodSupportedOnNetwork("transfer", options.network)) {
111
130
  Object.assign(account, {
112
131
  transfer: async (transferOptions: Omit<SmartAccountTransferOptions, "network">) => {
132
+ Analytics.trackAction({
133
+ action: "transfer",
134
+ accountType: "evm_smart",
135
+ properties: {
136
+ network: options.network,
137
+ },
138
+ });
139
+
113
140
  return transfer(
114
141
  apiClient,
115
142
  options.smartAccount,
@@ -129,6 +156,14 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
129
156
  listTokenBalances: async (
130
157
  listOptions: Omit<ListTokenBalancesOptions, "address" | "network">,
131
158
  ) => {
159
+ Analytics.trackAction({
160
+ action: "list_token_balances",
161
+ accountType: "evm_smart",
162
+ properties: {
163
+ network: options.network,
164
+ },
165
+ });
166
+
132
167
  return listTokenBalances(apiClient, {
133
168
  ...listOptions,
134
169
  address: options.smartAccount.address,
@@ -141,6 +176,14 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
141
176
  if (isMethodSupportedOnNetwork("requestFaucet", options.network)) {
142
177
  Object.assign(account, {
143
178
  requestFaucet: async (faucetOptions: Omit<RequestFaucetOptions, "address" | "network">) => {
179
+ Analytics.trackAction({
180
+ action: "request_faucet",
181
+ accountType: "evm_smart",
182
+ properties: {
183
+ network: options.network,
184
+ },
185
+ });
186
+
144
187
  return requestFaucet(apiClient, {
145
188
  ...faucetOptions,
146
189
  address: options.smartAccount.address,
@@ -153,6 +196,14 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
153
196
  if (isMethodSupportedOnNetwork("quoteFund", options.network)) {
154
197
  Object.assign(account, {
155
198
  quoteFund: async (quoteOptions: Omit<QuoteFundOptions, "address">) => {
199
+ Analytics.trackAction({
200
+ action: "quote_fund",
201
+ accountType: "evm_smart",
202
+ properties: {
203
+ network: options.network,
204
+ },
205
+ });
206
+
156
207
  return quoteFund(apiClient, {
157
208
  ...quoteOptions,
158
209
  address: options.smartAccount.address,
@@ -164,6 +215,14 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
164
215
  if (isMethodSupportedOnNetwork("fund", options.network)) {
165
216
  Object.assign(account, {
166
217
  fund: async (fundOptions: Omit<FundOptions, "address">) => {
218
+ Analytics.trackAction({
219
+ action: "fund",
220
+ accountType: "evm_smart",
221
+ properties: {
222
+ network: options.network,
223
+ },
224
+ });
225
+
167
226
  return fund(apiClient, {
168
227
  ...fundOptions,
169
228
  address: options.smartAccount.address,
@@ -178,6 +237,14 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
178
237
  if (isMethodSupportedOnNetwork("quoteSwap", options.network)) {
179
238
  Object.assign(account, {
180
239
  quoteSwap: async (quoteSwapOptions: SmartAccountQuoteSwapOptions) => {
240
+ Analytics.trackAction({
241
+ action: "quote_swap",
242
+ accountType: "evm_smart",
243
+ properties: {
244
+ network: options.network,
245
+ },
246
+ });
247
+
181
248
  return createSwapQuote(apiClient, {
182
249
  ...quoteSwapOptions,
183
250
  taker: options.smartAccount.address,
@@ -192,6 +259,14 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
192
259
  if (isMethodSupportedOnNetwork("swap", options.network)) {
193
260
  Object.assign(account, {
194
261
  swap: async (swapOptions: SmartAccountSwapOptions) => {
262
+ Analytics.trackAction({
263
+ action: "swap",
264
+ accountType: "evm_smart",
265
+ properties: {
266
+ network: options.network,
267
+ },
268
+ });
269
+
195
270
  return sendSwapOperation(apiClient, {
196
271
  ...swapOptions,
197
272
  smartAccount: options.smartAccount,
@@ -132,7 +132,7 @@ export type EvmServerAccount = Prettify<
132
132
  }
133
133
  >;
134
134
 
135
- type EvmSmartAccountProperties = {
135
+ export type EvmSmartAccountProperties = {
136
136
  /** The smart account's address. */
137
137
  address: Address;
138
138
  /** The name of the smart account. */
@@ -173,7 +173,7 @@ type DistributedOmit<T, K extends PropertyKey> = T extends any ? Omit<T, K> : ne
173
173
  /**
174
174
  * Helper type for network-specific smart account actions
175
175
  */
176
- type NetworkSpecificSmartAccountActions<Network extends string> = Prettify<
176
+ export type NetworkSpecificSmartAccountActions<Network extends string> = Prettify<
177
177
  // Always include sendUserOperation, waitForUserOperation and getUserOperation
178
178
  {
179
179
  sendUserOperation: <const callData extends unknown[]>(
@@ -261,7 +261,7 @@ type EmptyObject = {};
261
261
  /**
262
262
  * Conditional account actions based on network
263
263
  */
264
- type NetworkSpecificAccountActions<Network extends string> = Prettify<
264
+ export type NetworkSpecificAccountActions<Network extends string> = Prettify<
265
265
  // Always include sendTransaction, transfer and waitForTransactionReceipt
266
266
  {
267
267
  sendTransaction: (
@@ -3,6 +3,7 @@ import { requestFaucet } from "../../actions/solana/requestFaucet.js";
3
3
  import { signMessage } from "../../actions/solana/signMessage.js";
4
4
  import { signTransaction } from "../../actions/solana/signTransaction.js";
5
5
  import { transfer, type TransferOptions } from "../../actions/solana/transfer.js";
6
+ import { Analytics } from "../../analytics.js";
6
7
  import {
7
8
  RequestFaucetOptions,
8
9
  SignatureResult,
@@ -35,12 +36,22 @@ export function toSolanaAccount(
35
36
  address: options.account.address,
36
37
  name: options.account.name,
37
38
  async requestFaucet(options: Omit<RequestFaucetOptions, "address">): Promise<SignatureResult> {
39
+ Analytics.trackAction({
40
+ action: "request_faucet",
41
+ accountType: "solana",
42
+ });
43
+
38
44
  return requestFaucet(apiClient, {
39
45
  ...options,
40
46
  address: account.address,
41
47
  });
42
48
  },
43
49
  async signMessage(options: Omit<SignMessageOptions, "address">): Promise<SignatureResult> {
50
+ Analytics.trackAction({
51
+ action: "sign_message",
52
+ accountType: "solana",
53
+ });
54
+
44
55
  return signMessage(apiClient, {
45
56
  ...options,
46
57
  address: account.address,
@@ -49,6 +60,11 @@ export function toSolanaAccount(
49
60
  async signTransaction(
50
61
  options: Omit<SignTransactionOptions, "address">,
51
62
  ): Promise<SignatureResult> {
63
+ Analytics.trackAction({
64
+ action: "sign_transaction",
65
+ accountType: "solana",
66
+ });
67
+
52
68
  return signTransaction(apiClient, {
53
69
  ...options,
54
70
  address: account.address,
@@ -56,6 +72,14 @@ export function toSolanaAccount(
56
72
  },
57
73
  policies: options.account.policies,
58
74
  async transfer(options: Omit<TransferOptions, "from">): Promise<SignatureResult> {
75
+ Analytics.trackAction({
76
+ action: "transfer",
77
+ accountType: "solana",
78
+ properties: {
79
+ network: options.network,
80
+ },
81
+ });
82
+
59
83
  return transfer(apiClient, {
60
84
  ...options,
61
85
  from: account.address,
@@ -1,6 +1,7 @@
1
1
  import { formatUnits } from "viem";
2
2
 
3
3
  import { FundOperationResult } from "./types.js";
4
+ import { UserInputValidationError } from "../../../errors.js";
4
5
  import {
5
6
  CreatePaymentTransferQuoteBodySourceType,
6
7
  CreatePaymentTransferQuoteBodyTargetType,
@@ -42,8 +43,8 @@ export async function fund(
42
43
  throw new Error("No card found to fund account");
43
44
  }
44
45
 
45
- if (options.token.toLowerCase() !== "eth" && options.token.toLowerCase() !== "usdc") {
46
- throw new Error("Invalid currency, must be eth or usdc");
46
+ if (options.token !== "eth" && options.token !== "usdc") {
47
+ throw new UserInputValidationError("Invalid token, must be eth or usdc");
47
48
  }
48
49
 
49
50
  const decimals = options.token === "eth" ? 18 : 6;
@@ -1,6 +1,7 @@
1
1
  import { formatUnits } from "viem";
2
2
 
3
3
  import { Quote } from "./Quote.js";
4
+ import { UserInputValidationError } from "../../../errors.js";
4
5
  import {
5
6
  CreatePaymentTransferQuoteBodySourceType,
6
7
  CreatePaymentTransferQuoteBodyTargetType,
@@ -42,8 +43,8 @@ export async function quoteFund(
42
43
  throw new Error("No card found to fund account");
43
44
  }
44
45
 
45
- if (options.token.toLowerCase() !== "eth" && options.token.toLowerCase() !== "usdc") {
46
- throw new Error("Invalid currency, must be eth or usdc");
46
+ if (options.token !== "eth" && options.token !== "usdc") {
47
+ throw new UserInputValidationError("Invalid token, must be eth or usdc");
47
48
  }
48
49
 
49
50
  const decimals = options.token === "eth" ? 18 : 6;
@@ -7,7 +7,12 @@ import {
7
7
  WaitForFundOperationResult,
8
8
  } from "./fund/waitForFundOperationReceipt.js";
9
9
  import { SendUserOperationOptions, SendUserOperationReturnType } from "./sendUserOperation.js";
10
- import { GetUserOperationOptions, UserOperation } from "../../client/evm/evm.types.js";
10
+ import { KnownEvmNetworks } from "../../accounts/evm/types.js";
11
+ import {
12
+ GetUserOperationOptions,
13
+ SignTypedDataOptions,
14
+ UserOperation,
15
+ } from "../../client/evm/evm.types.js";
11
16
  import { Hex } from "../../types/misc.js";
12
17
 
13
18
  import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "./listTokenBalances.js";
@@ -29,7 +34,7 @@ import type {
29
34
  WaitForUserOperationReturnType,
30
35
  } from "./waitForUserOperation.js";
31
36
 
32
- type Actions = {
37
+ export type Actions = {
33
38
  /**
34
39
  * List the token balances of an account.
35
40
  *
@@ -601,4 +606,38 @@ export type SmartAccountActions = Actions & {
601
606
  * ```
602
607
  */
603
608
  swap: (options: SmartAccountSwapOptions) => Promise<SmartAccountSwapResult>;
609
+
610
+ /**
611
+ * Signs a typed data message.
612
+ *
613
+ * @param {SignTypedDataOptions} options - Configuration options for signing the typed data.
614
+ * @param {string} options.network - The network to sign the typed data on
615
+ * @param {string} options.typedData - The typed data to sign
616
+ *
617
+ * @returns A promise that resolves to the signature.
618
+ *
619
+ * @example
620
+ * ```ts
621
+ * const signature = await smartAccount.signTypedData({
622
+ * network: "base-sepolia",
623
+ * typedData: {
624
+ * domain: {
625
+ * name: "Test",
626
+ * chainId: 84532,
627
+ * verifyingContract: "0x0000000000000000000000000000000000000000",
628
+ * },
629
+ * types: {
630
+ * Test: [{ name: "name", type: "string" }],
631
+ * },
632
+ * primaryType: "Test",
633
+ * message: {
634
+ * name: "John Doe",
635
+ * },
636
+ * },
637
+ * });
638
+ * ```
639
+ */
640
+ signTypedData: (
641
+ options: Omit<SignTypedDataOptions, "address"> & { network: KnownEvmNetworks },
642
+ ) => Promise<Hex>;
604
643
  };
@@ -0,0 +1,38 @@
1
+ import { SendTransactionOptions, TransactionResult } from "../../client/solana/solana.types.js";
2
+ import { CdpOpenApiClientType } from "../../openapi-client/index.js";
3
+
4
+ /**
5
+ * Sends a Solana transaction using the Coinbase API.
6
+ *
7
+ * @param {CdpOpenApiClientType} apiClient - The API client to use.
8
+ * @param {SendTransactionOptions} options - Parameters for sending the Solana transaction.
9
+ * @param {string} options.network - The network to send the transaction to.
10
+ * @param {string} options.transaction - The base64 encoded transaction to send.
11
+ * @param {string} [options.idempotencyKey] - An idempotency key.
12
+ *
13
+ * @returns A promise that resolves to the transaction result.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const signature = await sendTransaction({
18
+ * network: "solana-devnet",
19
+ * transaction: "...",
20
+ * });
21
+ * ```
22
+ */
23
+ export async function sendTransaction(
24
+ apiClient: CdpOpenApiClientType,
25
+ options: SendTransactionOptions,
26
+ ): Promise<TransactionResult> {
27
+ const signature = await apiClient.sendSolanaTransaction(
28
+ {
29
+ network: options.network,
30
+ transaction: options.transaction,
31
+ },
32
+ options.idempotencyKey,
33
+ );
34
+
35
+ return {
36
+ signature: signature.transactionSignature,
37
+ };
38
+ }