@coinbase/cdp-sdk 1.28.0 → 1.29.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 (120) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/_cjs/accounts/evm/toEvmServerAccount.js +1 -1
  3. package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
  4. package/_cjs/accounts/evm/toEvmSmartAccount.js +1 -1
  5. package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
  6. package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
  7. package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +1 -1
  8. package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
  9. package/_cjs/accounts/solana/toSolanaAccount.js +30 -0
  10. package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
  11. package/_cjs/actions/Quote.js +106 -0
  12. package/_cjs/actions/Quote.js.map +1 -0
  13. package/_cjs/actions/evm/fund/fund.js +5 -5
  14. package/_cjs/actions/evm/fund/fund.js.map +1 -1
  15. package/_cjs/actions/evm/fund/quoteFund.js +7 -7
  16. package/_cjs/actions/evm/fund/quoteFund.js.map +1 -1
  17. package/_cjs/actions/evm/transfer/accountTransferStrategy.js +1 -0
  18. package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  19. package/_cjs/actions/solana/fund/fund.js +50 -0
  20. package/_cjs/actions/solana/fund/fund.js.map +1 -0
  21. package/_cjs/actions/solana/fund/quoteFund.js +47 -0
  22. package/_cjs/actions/solana/fund/quoteFund.js.map +1 -0
  23. package/{_esm/actions/evm/fund → _cjs/actions}/types.js.map +1 -1
  24. package/_cjs/actions/{evm/fund/waitForFundOperationReceipt.js → waitForFundOperationReceipt.js} +2 -2
  25. package/_cjs/actions/waitForFundOperationReceipt.js.map +1 -0
  26. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +15 -6
  27. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  28. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +4 -3
  29. package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  30. package/_cjs/version.js +1 -1
  31. package/_esm/accounts/evm/toEvmServerAccount.js +1 -1
  32. package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
  33. package/_esm/accounts/evm/toEvmSmartAccount.js +1 -1
  34. package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
  35. package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
  36. package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +1 -1
  37. package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
  38. package/_esm/accounts/solana/toSolanaAccount.js +30 -0
  39. package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
  40. package/_esm/actions/Quote.js +101 -0
  41. package/_esm/actions/Quote.js.map +1 -0
  42. package/_esm/actions/evm/fund/fund.js +5 -5
  43. package/_esm/actions/evm/fund/fund.js.map +1 -1
  44. package/_esm/actions/evm/fund/quoteFund.js +7 -7
  45. package/_esm/actions/evm/fund/quoteFund.js.map +1 -1
  46. package/_esm/actions/evm/transfer/accountTransferStrategy.js +1 -0
  47. package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
  48. package/_esm/actions/solana/fund/fund.js +47 -0
  49. package/_esm/actions/solana/fund/fund.js.map +1 -0
  50. package/_esm/actions/solana/fund/quoteFund.js +44 -0
  51. package/_esm/actions/solana/fund/quoteFund.js.map +1 -0
  52. package/{_cjs/actions/evm/fund → _esm/actions}/types.js.map +1 -1
  53. package/_esm/actions/{evm/fund/waitForFundOperationReceipt.js → waitForFundOperationReceipt.js} +2 -2
  54. package/_esm/actions/waitForFundOperationReceipt.js.map +1 -0
  55. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +14 -5
  56. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  57. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +4 -3
  58. package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
  59. package/_esm/version.js +1 -1
  60. package/_types/accounts/evm/types.d.ts +9 -9
  61. package/_types/accounts/evm/types.d.ts.map +1 -1
  62. package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
  63. package/_types/actions/Quote.d.ts +97 -0
  64. package/_types/actions/Quote.d.ts.map +1 -0
  65. package/_types/actions/evm/fund/fund.d.ts +3 -7
  66. package/_types/actions/evm/fund/fund.d.ts.map +1 -1
  67. package/_types/actions/evm/fund/quoteFund.d.ts +4 -7
  68. package/_types/actions/evm/fund/quoteFund.d.ts.map +1 -1
  69. package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
  70. package/_types/actions/evm/types.d.ts +7 -7
  71. package/_types/actions/evm/types.d.ts.map +1 -1
  72. package/_types/actions/solana/fund/fund.d.ts +19 -0
  73. package/_types/actions/solana/fund/fund.d.ts.map +1 -0
  74. package/_types/actions/solana/fund/quoteFund.d.ts +20 -0
  75. package/_types/actions/solana/fund/quoteFund.d.ts.map +1 -0
  76. package/_types/actions/solana/types.d.ts +61 -0
  77. package/_types/actions/solana/types.d.ts.map +1 -1
  78. package/_types/actions/types.d.ts +37 -0
  79. package/_types/actions/types.d.ts.map +1 -0
  80. package/_types/actions/{evm/fund/waitForFundOperationReceipt.d.ts → waitForFundOperationReceipt.d.ts} +2 -2
  81. package/_types/actions/waitForFundOperationReceipt.d.ts.map +1 -0
  82. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +26 -22
  83. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  84. package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -1
  85. package/_types/version.d.ts +1 -1
  86. package/accounts/evm/toEvmServerAccount.ts +11 -11
  87. package/accounts/evm/toEvmSmartAccount.ts +11 -11
  88. package/accounts/evm/toNetworkScopedEvmServerAccount.ts +5 -5
  89. package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +6 -6
  90. package/accounts/evm/types.ts +16 -12
  91. package/accounts/solana/toSolanaAccount.ts +41 -0
  92. package/actions/Quote.ts +154 -0
  93. package/actions/evm/fund/fund.ts +10 -14
  94. package/actions/evm/fund/quoteFund.ts +13 -16
  95. package/actions/evm/transfer/accountTransferStrategy.ts +2 -0
  96. package/actions/evm/types.ts +7 -7
  97. package/actions/solana/fund/fund.ts +71 -0
  98. package/actions/solana/fund/quoteFund.ts +77 -0
  99. package/actions/solana/types.ts +69 -0
  100. package/actions/types.ts +39 -0
  101. package/actions/{evm/fund/waitForFundOperationReceipt.ts → waitForFundOperationReceipt.ts} +2 -2
  102. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +30 -30
  103. package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +4 -3
  104. package/package.json +1 -1
  105. package/version.ts +1 -1
  106. package/_cjs/actions/evm/fund/Quote.js +0 -63
  107. package/_cjs/actions/evm/fund/Quote.js.map +0 -1
  108. package/_cjs/actions/evm/fund/waitForFundOperationReceipt.js.map +0 -1
  109. package/_esm/actions/evm/fund/Quote.js +0 -59
  110. package/_esm/actions/evm/fund/Quote.js.map +0 -1
  111. package/_esm/actions/evm/fund/waitForFundOperationReceipt.js.map +0 -1
  112. package/_types/actions/evm/fund/Quote.d.ts +0 -51
  113. package/_types/actions/evm/fund/Quote.d.ts.map +0 -1
  114. package/_types/actions/evm/fund/types.d.ts +0 -16
  115. package/_types/actions/evm/fund/types.d.ts.map +0 -1
  116. package/_types/actions/evm/fund/waitForFundOperationReceipt.d.ts.map +0 -1
  117. package/actions/evm/fund/Quote.ts +0 -83
  118. package/actions/evm/fund/types.ts +0 -16
  119. /package/_cjs/actions/{evm/fund/types.js → types.js} +0 -0
  120. /package/_esm/actions/{evm/fund/types.js → types.js} +0 -0
@@ -8,9 +8,8 @@ import { transferWithViem } from "../../actions/evm/transfer/transferWithViem.js
8
8
  import { Analytics } from "../../analytics.js";
9
9
 
10
10
  import type { EvmServerAccount, NetworkScopedEvmServerAccount } from "./types.js";
11
- import type { FundOptions } from "../../actions/evm/fund/fund.js";
12
- import type { QuoteFundOptions } from "../../actions/evm/fund/quoteFund.js";
13
- import type { WaitForFundOperationOptions } from "../../actions/evm/fund/waitForFundOperationReceipt.js";
11
+ import type { EvmFundOptions } from "../../actions/evm/fund/fund.js";
12
+ import type { EvmQuoteFundOptions } from "../../actions/evm/fund/quoteFund.js";
14
13
  import type { ListTokenBalancesOptions } from "../../actions/evm/listTokenBalances.js";
15
14
  import type { RequestFaucetOptions } from "../../actions/evm/requestFaucet.js";
16
15
  import type {
@@ -19,6 +18,7 @@ import type {
19
18
  } from "../../actions/evm/sendTransaction.js";
20
19
  import type { AccountQuoteSwapOptions, AccountSwapOptions } from "../../actions/evm/swap/types.js";
21
20
  import type { TransferOptions } from "../../actions/evm/transfer/types.js";
21
+ import type { WaitForFundOperationOptions } from "../../actions/waitForFundOperationReceipt.js";
22
22
  import type {
23
23
  ListEvmTokenBalancesNetwork,
24
24
  SendEvmTransactionBodyNetwork,
@@ -156,7 +156,7 @@ export async function toNetworkScopedEvmServerAccount<Network extends string>(
156
156
 
157
157
  if (isMethodSupportedOnNetwork("quoteFund", resolvedNetworkName)) {
158
158
  Object.assign(account, {
159
- quoteFund: async (quoteFundOptions: Omit<QuoteFundOptions, "address">) => {
159
+ quoteFund: async (quoteFundOptions: Omit<EvmQuoteFundOptions, "address">) => {
160
160
  return options.account.quoteFund({
161
161
  ...quoteFundOptions,
162
162
  });
@@ -166,7 +166,7 @@ export async function toNetworkScopedEvmServerAccount<Network extends string>(
166
166
 
167
167
  if (isMethodSupportedOnNetwork("fund", resolvedNetworkName)) {
168
168
  Object.assign(account, {
169
- fund: async (fundOptions: Omit<FundOptions, "address">) => {
169
+ fund: async (fundOptions: Omit<EvmFundOptions, "address">) => {
170
170
  return options.account.fund({
171
171
  ...fundOptions,
172
172
  });
@@ -2,7 +2,6 @@ import { getBaseNodeRpcUrl } from "./getBaseNodeRpcUrl.js";
2
2
  import { isMethodSupportedOnNetwork } from "./networkCapabilities.js";
3
3
  import { fund } from "../../actions/evm/fund/fund.js";
4
4
  import { quoteFund } from "../../actions/evm/fund/quoteFund.js";
5
- import { waitForFundOperationReceipt } from "../../actions/evm/fund/waitForFundOperationReceipt.js";
6
5
  import { getUserOperation } from "../../actions/evm/getUserOperation.js";
7
6
  import { listTokenBalances } from "../../actions/evm/listTokenBalances.js";
8
7
  import { requestFaucet } from "../../actions/evm/requestFaucet.js";
@@ -12,6 +11,7 @@ import { sendSwapOperation } from "../../actions/evm/swap/sendSwapOperation.js";
12
11
  import { smartAccountTransferStrategy } from "../../actions/evm/transfer/smartAccountTransferStrategy.js";
13
12
  import { transfer } from "../../actions/evm/transfer/transfer.js";
14
13
  import { waitForUserOperation } from "../../actions/evm/waitForUserOperation.js";
14
+ import { waitForFundOperationReceipt } from "../../actions/waitForFundOperationReceipt.js";
15
15
  import { Analytics } from "../../analytics.js";
16
16
 
17
17
  import type {
@@ -20,9 +20,8 @@ import type {
20
20
  KnownEvmNetworks,
21
21
  NetworkScopedEvmSmartAccount,
22
22
  } from "./types.js";
23
- import type { FundOptions } from "../../actions/evm/fund/fund.js";
24
- import type { QuoteFundOptions } from "../../actions/evm/fund/quoteFund.js";
25
- import type { WaitForFundOperationOptions } from "../../actions/evm/fund/waitForFundOperationReceipt.js";
23
+ import type { EvmFundOptions } from "../../actions/evm/fund/fund.js";
24
+ import type { EvmQuoteFundOptions } from "../../actions/evm/fund/quoteFund.js";
26
25
  import type { ListTokenBalancesOptions } from "../../actions/evm/listTokenBalances.js";
27
26
  import type { RequestFaucetOptions } from "../../actions/evm/requestFaucet.js";
28
27
  import type { SendUserOperationOptions } from "../../actions/evm/sendUserOperation.js";
@@ -33,6 +32,7 @@ import type {
33
32
  } from "../../actions/evm/swap/types.js";
34
33
  import type { SmartAccountTransferOptions } from "../../actions/evm/transfer/types.js";
35
34
  import type { WaitForUserOperationOptions } from "../../actions/evm/waitForUserOperation.js";
35
+ import type { WaitForFundOperationOptions } from "../../actions/waitForFundOperationReceipt.js";
36
36
  import type { GetUserOperationOptions } from "../../client/evm/evm.types.js";
37
37
  import type {
38
38
  CdpOpenApiClientType,
@@ -195,7 +195,7 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
195
195
 
196
196
  if (isMethodSupportedOnNetwork("quoteFund", options.network)) {
197
197
  Object.assign(account, {
198
- quoteFund: async (quoteOptions: Omit<QuoteFundOptions, "address">) => {
198
+ quoteFund: async (quoteOptions: Omit<EvmQuoteFundOptions, "address">) => {
199
199
  Analytics.trackAction({
200
200
  action: "quote_fund",
201
201
  accountType: "evm_smart",
@@ -214,7 +214,7 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
214
214
 
215
215
  if (isMethodSupportedOnNetwork("fund", options.network)) {
216
216
  Object.assign(account, {
217
- fund: async (fundOptions: Omit<FundOptions, "address">) => {
217
+ fund: async (fundOptions: Omit<EvmFundOptions, "address">) => {
218
218
  Analytics.trackAction({
219
219
  action: "fund",
220
220
  accountType: "evm_smart",
@@ -7,14 +7,8 @@ import {
7
7
  QuoteSwapNetworks,
8
8
  SwapNetworks,
9
9
  } from "./networkCapabilities.js";
10
- import { FundOptions } from "../../actions/evm/fund/fund.js";
11
- import { Quote } from "../../actions/evm/fund/Quote.js";
12
- import { QuoteFundOptions } from "../../actions/evm/fund/quoteFund.js";
13
- import { FundOperationResult } from "../../actions/evm/fund/types.js";
14
- import {
15
- WaitForFundOperationOptions,
16
- WaitForFundOperationResult,
17
- } from "../../actions/evm/fund/waitForFundOperationReceipt.js";
10
+ import { EvmFundOptions } from "../../actions/evm/fund/fund.js";
11
+ import { EvmQuoteFundOptions } from "../../actions/evm/fund/quoteFund.js";
18
12
  import {
19
13
  ListTokenBalancesOptions,
20
14
  ListTokenBalancesResult,
@@ -39,6 +33,11 @@ import {
39
33
  WaitForUserOperationOptions,
40
34
  WaitForUserOperationReturnType,
41
35
  } from "../../actions/evm/waitForUserOperation.js";
36
+ import { FundOperationResult } from "../../actions/types.js";
37
+ import {
38
+ WaitForFundOperationOptions,
39
+ WaitForFundOperationResult,
40
+ } from "../../actions/waitForFundOperationReceipt.js";
42
41
  import { GetUserOperationOptions, UserOperation } from "../../client/evm/evm.types.js";
43
42
 
44
43
  import type {
@@ -46,6 +45,7 @@ import type {
46
45
  TransferOptions,
47
46
  } from "../../actions/evm/transfer/types.js";
48
47
  import type { AccountActions, SmartAccountActions } from "../../actions/evm/types.js";
48
+ import type { EvmQuote } from "../../actions/Quote.js";
49
49
  import type { Address, Hash, Hex } from "../../types/misc.js";
50
50
  import type { Prettify } from "../../types/utils.js";
51
51
  import type {
@@ -211,13 +211,17 @@ export type NetworkSpecificSmartAccountActions<Network extends string> = Prettif
211
211
  // Conditionally include quoteFund
212
212
  (Network extends QuoteFundNetworks
213
213
  ? {
214
- quoteFund: (options: Omit<QuoteFundOptions, "address" | "network">) => Promise<Quote>;
214
+ quoteFund: (
215
+ options: Omit<EvmQuoteFundOptions, "address" | "network">,
216
+ ) => Promise<EvmQuote>;
215
217
  }
216
218
  : EmptyObject) &
217
219
  // Conditionally include fund
218
220
  (Network extends FundNetworks
219
221
  ? {
220
- fund: (options: Omit<FundOptions, "address" | "network">) => Promise<FundOperationResult>;
222
+ fund: (
223
+ options: Omit<EvmFundOptions, "address" | "network">,
224
+ ) => Promise<FundOperationResult>;
221
225
  waitForFundOperationReceipt: (
222
226
  options: Omit<WaitForFundOperationOptions, "network">,
223
227
  ) => Promise<WaitForFundOperationResult>;
@@ -289,13 +293,13 @@ export type NetworkSpecificAccountActions<Network extends string> = Prettify<
289
293
  // Conditionally include quoteFund
290
294
  (Network extends QuoteFundNetworks
291
295
  ? {
292
- quoteFund: (options: Omit<QuoteFundOptions, "address">) => Promise<Quote>;
296
+ quoteFund: (options: Omit<EvmQuoteFundOptions, "address">) => Promise<EvmQuote>;
293
297
  }
294
298
  : EmptyObject) &
295
299
  // Conditionally include fund
296
300
  (Network extends FundNetworks
297
301
  ? {
298
- fund: (options: Omit<FundOptions, "address">) => Promise<FundOperationResult>;
302
+ fund: (options: Omit<EvmFundOptions, "address">) => Promise<FundOperationResult>;
299
303
  waitForFundOperationReceipt: (
300
304
  options: WaitForFundOperationOptions,
301
305
  ) => Promise<WaitForFundOperationResult>;
@@ -1,8 +1,17 @@
1
1
  import { Account, SolanaAccount } from "./types.js";
2
+ import { SolanaQuote } from "../../actions/Quote.js";
3
+ import { SolanaFundOptions, fund } from "../../actions/solana/fund/fund.js";
4
+ import { SolanaQuoteFundOptions, quoteFund } from "../../actions/solana/fund/quoteFund.js";
2
5
  import { requestFaucet } from "../../actions/solana/requestFaucet.js";
3
6
  import { signMessage } from "../../actions/solana/signMessage.js";
4
7
  import { signTransaction } from "../../actions/solana/signTransaction.js";
5
8
  import { transfer, type TransferOptions } from "../../actions/solana/transfer.js";
9
+ import { FundOperationResult } from "../../actions/types.js";
10
+ import {
11
+ WaitForFundOperationOptions,
12
+ WaitForFundOperationResult,
13
+ waitForFundOperationReceipt,
14
+ } from "../../actions/waitForFundOperationReceipt.js";
6
15
  import { Analytics } from "../../analytics.js";
7
16
  import {
8
17
  RequestFaucetOptions,
@@ -85,6 +94,38 @@ export function toSolanaAccount(
85
94
  from: account.address,
86
95
  });
87
96
  },
97
+ async quoteFund(options: Omit<SolanaQuoteFundOptions, "address">): Promise<SolanaQuote> {
98
+ Analytics.trackAction({
99
+ action: "quote_fund",
100
+ accountType: "solana",
101
+ });
102
+
103
+ return quoteFund(apiClient, {
104
+ ...options,
105
+ address: account.address,
106
+ });
107
+ },
108
+ async fund(options: Omit<SolanaFundOptions, "address">): Promise<FundOperationResult> {
109
+ Analytics.trackAction({
110
+ action: "fund",
111
+ accountType: "solana",
112
+ });
113
+
114
+ return fund(apiClient, {
115
+ ...options,
116
+ address: account.address,
117
+ });
118
+ },
119
+ async waitForFundOperationReceipt(
120
+ options: WaitForFundOperationOptions,
121
+ ): Promise<WaitForFundOperationResult> {
122
+ Analytics.trackAction({
123
+ action: "wait_for_fund_operation_receipt",
124
+ accountType: "solana",
125
+ });
126
+
127
+ return waitForFundOperationReceipt(apiClient, options);
128
+ },
88
129
  };
89
130
 
90
131
  return account;
@@ -0,0 +1,154 @@
1
+ import { FundOperationResult } from "./types.js";
2
+ import { CdpOpenApiClientType } from "../openapi-client/index.js";
3
+
4
+ /**
5
+ * Base class representing a funding quote that can be executed.
6
+ */
7
+ abstract class BaseQuote {
8
+ /** Quote for the transfer. */
9
+ public quoteId: string;
10
+ /** The amount in fiat currency. */
11
+ public fiatAmount: string;
12
+ /** The fiat currency. */
13
+ public fiatCurrency: string;
14
+ /** The amount in the token to transfer. */
15
+ public tokenAmount: string;
16
+ /** The token to transfer. */
17
+ public token: string;
18
+ /** Fees in the token to transfer. */
19
+ public fees: {
20
+ /** The type of fee. */
21
+ type: "exchange_fee" | "network_fee";
22
+ amount: string;
23
+ currency: string;
24
+ }[];
25
+
26
+ protected apiClient: CdpOpenApiClientType;
27
+
28
+ /**
29
+ * Creates a new BaseQuote instance.
30
+ *
31
+ * @param apiClient - The API client.
32
+ * @param quoteId - The quote ID.
33
+ * @param fiatAmount - The amount in fiat currency.
34
+ * @param fiatCurrency - The fiat currency.
35
+ * @param tokenAmount - The amount in the token to transfer.
36
+ * @param token - The token to transfer.
37
+ * @param fees - Fees for the transfer.
38
+ */
39
+ constructor(
40
+ apiClient: CdpOpenApiClientType,
41
+ quoteId: string,
42
+ fiatAmount: string,
43
+ fiatCurrency: string,
44
+ tokenAmount: string,
45
+ token: string,
46
+ fees: {
47
+ type: "exchange_fee" | "network_fee";
48
+ amount: string;
49
+ currency: string;
50
+ }[],
51
+ ) {
52
+ this.apiClient = apiClient;
53
+ this.quoteId = quoteId;
54
+ this.fiatAmount = fiatAmount;
55
+ this.fiatCurrency = fiatCurrency;
56
+ this.tokenAmount = tokenAmount;
57
+ this.token = token;
58
+ this.fees = fees;
59
+ }
60
+
61
+ /**
62
+ * Executes the quote to perform the actual fund transfer.
63
+ *
64
+ * @returns A promise that resolves to the result of the executed quote.
65
+ */
66
+ async execute(): Promise<FundOperationResult> {
67
+ const transfer = await this.apiClient.executePaymentTransferQuote(this.quoteId);
68
+
69
+ return {
70
+ id: transfer.id,
71
+ network: transfer.target.network,
72
+ targetAmount: transfer.targetAmount,
73
+ targetCurrency: transfer.targetCurrency,
74
+ status: transfer.status,
75
+ transactionHash: transfer.transactionHash,
76
+ };
77
+ }
78
+ }
79
+
80
+ /**
81
+ * A class representing an EVM funding quote that can be executed.
82
+ */
83
+ export class EvmQuote extends BaseQuote {
84
+ /** Network to transfer the funds to (EVM networks). */
85
+ public network: "base" | "ethereum";
86
+
87
+ /**
88
+ * Creates a new EvmQuote instance.
89
+ *
90
+ * @param apiClient - The API client.
91
+ * @param quoteId - The quote ID.
92
+ * @param network - The EVM network to transfer funds to.
93
+ * @param fiatAmount - The amount in fiat currency.
94
+ * @param fiatCurrency - The fiat currency.
95
+ * @param tokenAmount - The amount in the token to transfer.
96
+ * @param token - The token to transfer.
97
+ * @param fees - Fees for the transfer.
98
+ */
99
+ constructor(
100
+ apiClient: CdpOpenApiClientType,
101
+ quoteId: string,
102
+ network: "base" | "ethereum",
103
+ fiatAmount: string,
104
+ fiatCurrency: string,
105
+ tokenAmount: string,
106
+ token: string,
107
+ fees: {
108
+ type: "exchange_fee" | "network_fee";
109
+ amount: string;
110
+ currency: string;
111
+ }[],
112
+ ) {
113
+ super(apiClient, quoteId, fiatAmount, fiatCurrency, tokenAmount, token, fees);
114
+ this.network = network;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * A class representing a Solana funding quote that can be executed.
120
+ */
121
+ export class SolanaQuote extends BaseQuote {
122
+ /** Network to transfer the funds to (Solana). */
123
+ public network: "solana";
124
+
125
+ /**
126
+ * Creates a new SolanaQuote instance.
127
+ *
128
+ * @param apiClient - The API client.
129
+ * @param quoteId - The quote ID.
130
+ * @param network - The Solana network to transfer funds to.
131
+ * @param fiatAmount - The amount in fiat currency.
132
+ * @param fiatCurrency - The fiat currency.
133
+ * @param tokenAmount - The amount in the token to transfer.
134
+ * @param token - The token to transfer.
135
+ * @param fees - Fees for the transfer.
136
+ */
137
+ constructor(
138
+ apiClient: CdpOpenApiClientType,
139
+ quoteId: string,
140
+ network: "solana",
141
+ fiatAmount: string,
142
+ fiatCurrency: string,
143
+ tokenAmount: string,
144
+ token: string,
145
+ fees: {
146
+ type: "exchange_fee" | "network_fee";
147
+ amount: string;
148
+ currency: string;
149
+ }[],
150
+ ) {
151
+ super(apiClient, quoteId, fiatAmount, fiatCurrency, tokenAmount, token, fees);
152
+ this.network = network;
153
+ }
154
+ }
@@ -1,23 +1,19 @@
1
1
  import { formatUnits } from "viem";
2
2
 
3
- import { FundOperationResult } from "./types.js";
4
3
  import { UserInputValidationError } from "../../../errors.js";
5
4
  import {
6
5
  CreatePaymentTransferQuoteBodySourceType,
7
6
  CreatePaymentTransferQuoteBodyTargetType,
8
7
  type CdpOpenApiClientType,
9
8
  } from "../../../openapi-client/index.js";
9
+ import { BaseFundOptions, FundOperationResult } from "../../types.js";
10
10
 
11
11
  /**
12
12
  * Options for funding an EVM account.
13
13
  */
14
- export interface FundOptions {
15
- /** The address of the account. */
16
- address: string;
14
+ export interface EvmFundOptions extends BaseFundOptions {
17
15
  /** The network to request funds from. */
18
16
  network: "base" | "ethereum";
19
- /** The amount to fund the account with, in atomic units (wei) of the token. */
20
- amount: bigint;
21
17
  /** The token to request funds for. */
22
18
  token: "eth" | "usdc";
23
19
  }
@@ -32,8 +28,15 @@ export interface FundOptions {
32
28
  */
33
29
  export async function fund(
34
30
  apiClient: CdpOpenApiClientType,
35
- options: FundOptions,
31
+ options: EvmFundOptions,
36
32
  ): Promise<FundOperationResult> {
33
+ if (options.token !== "eth" && options.token !== "usdc") {
34
+ throw new UserInputValidationError("Invalid token, must be eth or usdc");
35
+ }
36
+
37
+ const decimals = options.token === "eth" ? 18 : 6;
38
+ const amount = formatUnits(options.amount, decimals);
39
+
37
40
  const paymentMethods = await apiClient.getPaymentMethods();
38
41
  const cardPaymentMethod = paymentMethods.find(
39
42
  method => method.type === "card" && method.actions.includes("source"),
@@ -43,13 +46,6 @@ export async function fund(
43
46
  throw new Error("No card found to fund account");
44
47
  }
45
48
 
46
- if (options.token !== "eth" && options.token !== "usdc") {
47
- throw new UserInputValidationError("Invalid token, must be eth or usdc");
48
- }
49
-
50
- const decimals = options.token === "eth" ? 18 : 6;
51
- const amount = formatUnits(options.amount, decimals);
52
-
53
49
  const response = await apiClient.createPaymentTransferQuote({
54
50
  sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
55
51
  source: {
@@ -1,23 +1,20 @@
1
1
  import { formatUnits } from "viem";
2
2
 
3
- import { Quote } from "./Quote.js";
4
3
  import { UserInputValidationError } from "../../../errors.js";
5
4
  import {
6
5
  CreatePaymentTransferQuoteBodySourceType,
7
6
  CreatePaymentTransferQuoteBodyTargetType,
8
7
  type CdpOpenApiClientType,
9
8
  } from "../../../openapi-client/index.js";
9
+ import { EvmQuote } from "../../Quote.js";
10
+ import { BaseQuoteFundOptions } from "../../types.js";
10
11
 
11
12
  /**
12
13
  * Options for getting a quote to fund an EVM account.
13
14
  */
14
- export interface QuoteFundOptions {
15
- /** The address of the account. */
16
- address: string;
15
+ export interface EvmQuoteFundOptions extends BaseQuoteFundOptions {
17
16
  /** The network to request funds from. */
18
17
  network: "base" | "ethereum";
19
- /** The amount to fund the account with, in atomic units (wei) of the token. */
20
- amount: bigint;
21
18
  /** The token to request funds for. */
22
19
  token: "eth" | "usdc";
23
20
  }
@@ -32,8 +29,15 @@ export interface QuoteFundOptions {
32
29
  */
33
30
  export async function quoteFund(
34
31
  apiClient: CdpOpenApiClientType,
35
- options: QuoteFundOptions,
36
- ): Promise<Quote> {
32
+ options: EvmQuoteFundOptions,
33
+ ): Promise<EvmQuote> {
34
+ if (options.token !== "eth" && options.token !== "usdc") {
35
+ throw new UserInputValidationError("Invalid token, must be eth or usdc");
36
+ }
37
+
38
+ const decimals = options.token === "eth" ? 18 : 6;
39
+ const amount = formatUnits(options.amount, decimals);
40
+
37
41
  const paymentMethods = await apiClient.getPaymentMethods();
38
42
  const cardPaymentMethod = paymentMethods.find(
39
43
  method => method.type === "card" && method.actions.includes("source"),
@@ -43,13 +47,6 @@ export async function quoteFund(
43
47
  throw new Error("No card found to fund account");
44
48
  }
45
49
 
46
- if (options.token !== "eth" && options.token !== "usdc") {
47
- throw new UserInputValidationError("Invalid token, must be eth or usdc");
48
- }
49
-
50
- const decimals = options.token === "eth" ? 18 : 6;
51
- const amount = formatUnits(options.amount, decimals);
52
-
53
50
  const response = await apiClient.createPaymentTransferQuote({
54
51
  sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
55
52
  source: {
@@ -65,7 +62,7 @@ export async function quoteFund(
65
62
  currency: options.token,
66
63
  });
67
64
 
68
- return new Quote(
65
+ return new EvmQuote(
69
66
  apiClient,
70
67
  response.transfer.id,
71
68
  options.network,
@@ -1,6 +1,7 @@
1
1
  import { encodeFunctionData, erc20Abi } from "viem";
2
2
 
3
3
  import { getErc20Address } from "./utils.js";
4
+ import { SendEvmTransactionBodyNetwork } from "../../../openapi-client/index.js";
4
5
  import { serializeEIP1559Transaction } from "../../../utils/serializeTransaction.js";
5
6
 
6
7
  import type { TransferExecutionStrategy } from "./types.js";
@@ -9,6 +10,7 @@ import type { TransactionResult } from "../sendTransaction.js";
9
10
 
10
11
  export const accountTransferStrategy: TransferExecutionStrategy<EvmAccount> = {
11
12
  executeTransfer: async ({ apiClient, from, to, value, token, network }) => {
13
+ network = network as SendEvmTransactionBodyNetwork;
12
14
  if (token === "eth") {
13
15
  return apiClient.sendEvmTransaction(from.address, {
14
16
  transaction: serializeEIP1559Transaction({
@@ -1,11 +1,10 @@
1
- import { FundOptions } from "./fund/fund.js";
2
- import { Quote } from "./fund/Quote.js";
3
- import { QuoteFundOptions } from "./fund/quoteFund.js";
4
- import { FundOperationResult } from "./fund/types.js";
1
+ import { FundOperationResult } from "../types.js";
5
2
  import {
6
3
  WaitForFundOperationOptions,
7
4
  WaitForFundOperationResult,
8
- } from "./fund/waitForFundOperationReceipt.js";
5
+ } from "../waitForFundOperationReceipt.js";
6
+ import { EvmFundOptions } from "./fund/fund.js";
7
+ import { EvmQuoteFundOptions } from "./fund/quoteFund.js";
9
8
  import { SendUserOperationOptions, SendUserOperationReturnType } from "./sendUserOperation.js";
10
9
  import { KnownEvmNetworks } from "../../accounts/evm/types.js";
11
10
  import {
@@ -14,6 +13,7 @@ import {
14
13
  UserOperation,
15
14
  } from "../../client/evm/evm.types.js";
16
15
  import { Hex } from "../../types/misc.js";
16
+ import { EvmQuote } from "../Quote.js";
17
17
 
18
18
  import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "./listTokenBalances.js";
19
19
  import type { RequestFaucetOptions, RequestFaucetResult } from "./requestFaucet.js";
@@ -95,7 +95,7 @@ export type Actions = {
95
95
  * });
96
96
  * ```
97
97
  */
98
- quoteFund: (options: Omit<QuoteFundOptions, "address">) => Promise<Quote>;
98
+ quoteFund: (options: Omit<EvmQuoteFundOptions, "address">) => Promise<EvmQuote>;
99
99
 
100
100
  /**
101
101
  * Funds an EVM account with the specified token amount.
@@ -118,7 +118,7 @@ export type Actions = {
118
118
  * });
119
119
  * ```
120
120
  */
121
- fund: (options: Omit<FundOptions, "address">) => Promise<FundOperationResult>;
121
+ fund: (options: Omit<EvmFundOptions, "address">) => Promise<FundOperationResult>;
122
122
 
123
123
  /**
124
124
  * Waits for a fund operation to complete and returns the transfer receipt.
@@ -0,0 +1,71 @@
1
+ import { formatUnits } from "viem";
2
+
3
+ import { UserInputValidationError } from "../../../errors.js";
4
+ import {
5
+ CreatePaymentTransferQuoteBodySourceType,
6
+ CreatePaymentTransferQuoteBodyTargetType,
7
+ type CdpOpenApiClientType,
8
+ } from "../../../openapi-client/index.js";
9
+ import { BaseFundOptions, FundOperationResult } from "../../types.js";
10
+
11
+ /**
12
+ * Options for funding a Solana account.
13
+ */
14
+ export interface SolanaFundOptions extends BaseFundOptions {
15
+ /** The token to request funds for. */
16
+ token: "sol" | "usdc";
17
+ }
18
+
19
+ /**
20
+ * Funds a Solana account.
21
+ *
22
+ * @param apiClient - The API client.
23
+ * @param options - The options for funding a Solana account.
24
+ *
25
+ * @returns A promise that resolves to the fund operation result.
26
+ */
27
+ export async function fund(
28
+ apiClient: CdpOpenApiClientType,
29
+ options: SolanaFundOptions,
30
+ ): Promise<FundOperationResult> {
31
+ if (options.token !== "sol" && options.token !== "usdc") {
32
+ throw new UserInputValidationError("Invalid token, must be sol or usdc");
33
+ }
34
+
35
+ const decimals = options.token === "sol" ? 9 : 6;
36
+ const amount = formatUnits(options.amount, decimals);
37
+
38
+ const paymentMethods = await apiClient.getPaymentMethods();
39
+ const cardPaymentMethod = paymentMethods.find(
40
+ method => method.type === "card" && method.actions.includes("source"),
41
+ );
42
+
43
+ if (!cardPaymentMethod) {
44
+ throw new Error("No card found to fund account");
45
+ }
46
+
47
+ const response = await apiClient.createPaymentTransferQuote({
48
+ sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
49
+ source: {
50
+ id: cardPaymentMethod.id,
51
+ },
52
+ targetType: CreatePaymentTransferQuoteBodyTargetType.crypto_rail,
53
+ target: {
54
+ currency: options.token,
55
+ network: "solana",
56
+ address: options.address,
57
+ },
58
+ amount,
59
+ currency: options.token,
60
+ execute: true,
61
+ });
62
+
63
+ return {
64
+ id: response.transfer.id,
65
+ network: response.transfer.target.network,
66
+ status: response.transfer.status,
67
+ targetAmount: response.transfer.targetAmount,
68
+ targetCurrency: response.transfer.targetCurrency,
69
+ transactionHash: response.transfer.transactionHash,
70
+ };
71
+ }