@coinbase/cdp-sdk 1.38.4 → 1.38.6
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.
- package/CHANGELOG.md +13 -0
- package/README.md +24 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js +0 -36
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +0 -36
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +0 -42
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +0 -42
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +0 -30
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/sendUserOperation.js +2 -0
- package/_cjs/actions/evm/sendUserOperation.js.map +1 -1
- package/_cjs/analytics.js +164 -2
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/auth/utils/http.js +5 -2
- package/_cjs/auth/utils/http.js.map +1 -1
- package/_cjs/auth/utils/jwt.js +1 -1
- package/_cjs/auth/utils/jwt.js.map +1 -1
- package/_cjs/client/end-user/endUser.js +43 -0
- package/_cjs/client/end-user/endUser.js.map +1 -1
- package/_cjs/client/evm/evm.js +49 -0
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/cdpApiClient.js +4 -0
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +6 -41
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/end-user-accounts/end-user-accounts.js +10 -1
- package/_cjs/openapi-client/generated/end-user-accounts/end-user-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +14 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/sql-api-alpha/sql-api-alpha.js +14 -1
- package/_cjs/openapi-client/generated/sql-api-alpha/sql-api-alpha.js.map +1 -1
- package/_cjs/openapi-client/index.js +0 -3
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +0 -36
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +0 -36
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +0 -42
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +0 -42
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +0 -30
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/sendUserOperation.js +2 -0
- package/_esm/actions/evm/sendUserOperation.js.map +1 -1
- package/_esm/analytics.js +163 -1
- package/_esm/analytics.js.map +1 -1
- package/_esm/auth/utils/http.js +5 -2
- package/_esm/auth/utils/http.js.map +1 -1
- package/_esm/auth/utils/jwt.js +1 -1
- package/_esm/auth/utils/jwt.js.map +1 -1
- package/_esm/client/end-user/endUser.js +44 -1
- package/_esm/client/end-user/endUser.js.map +1 -1
- package/_esm/client/evm/evm.js +49 -0
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/cdpApiClient.js +4 -0
- package/_esm/openapi-client/cdpApiClient.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +5 -39
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/end-user-accounts/end-user-accounts.js +8 -0
- package/_esm/openapi-client/generated/end-user-accounts/end-user-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +12 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/sql-api-alpha/sql-api-alpha.js +12 -0
- package/_esm/openapi-client/generated/sql-api-alpha/sql-api-alpha.js.map +1 -1
- package/_esm/openapi-client/index.js +0 -3
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +3 -18
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/sendUserOperation.d.ts +11 -0
- package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +1 -66
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/types.d.ts +1 -62
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/analytics.d.ts +27 -0
- package/_types/analytics.d.ts.map +1 -1
- package/_types/auth/utils/http.d.ts.map +1 -1
- package/_types/client/end-user/endUser.d.ts +36 -2
- package/_types/client/end-user/endUser.d.ts.map +1 -1
- package/_types/client/end-user/endUser.types.d.ts +5 -0
- package/_types/client/end-user/endUser.types.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +29 -2
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +20 -2
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/index.d.ts +2 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +44 -246
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/end-user-accounts/end-user-accounts.d.ts +8 -1
- package/_types/openapi-client/generated/end-user-accounts/end-user-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +7 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/sql-api-alpha/sql-api-alpha.d.ts +11 -0
- package/_types/openapi-client/generated/sql-api-alpha/sql-api-alpha.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +3 -6
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/types/calls.d.ts +1 -0
- package/_types/types/calls.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +0 -47
- package/accounts/evm/toEvmSmartAccount.ts +0 -47
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +0 -50
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +0 -49
- package/accounts/evm/types.ts +5 -49
- package/accounts/solana/toSolanaAccount.ts +0 -41
- package/actions/evm/sendUserOperation.ts +14 -0
- package/actions/evm/types.ts +1 -74
- package/actions/solana/types.ts +1 -70
- package/analytics.ts +225 -1
- package/auth/utils/http.ts +5 -2
- package/auth/utils/jwt.ts +1 -1
- package/client/end-user/endUser.ts +52 -2
- package/client/end-user/endUser.types.ts +7 -0
- package/client/evm/evm.ts +61 -0
- package/client/evm/evm.types.ts +23 -0
- package/index.ts +2 -1
- package/openapi-client/cdpApiClient.ts +5 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +53 -289
- package/openapi-client/generated/end-user-accounts/end-user-accounts.ts +14 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +23 -0
- package/openapi-client/generated/sql-api-alpha/sql-api-alpha.ts +13 -0
- package/openapi-client/index.ts +0 -3
- package/package.json +1 -1
- package/types/calls.ts +1 -0
- package/version.ts +1 -1
- package/_cjs/actions/Quote.js +0 -106
- package/_cjs/actions/Quote.js.map +0 -1
- package/_cjs/actions/evm/fund/fund.js +0 -51
- package/_cjs/actions/evm/fund/fund.js.map +0 -1
- package/_cjs/actions/evm/fund/quoteFund.js +0 -48
- package/_cjs/actions/evm/fund/quoteFund.js.map +0 -1
- package/_cjs/actions/solana/fund/fund.js +0 -51
- package/_cjs/actions/solana/fund/fund.js.map +0 -1
- package/_cjs/actions/solana/fund/quoteFund.js +0 -48
- package/_cjs/actions/solana/fund/quoteFund.js.map +0 -1
- package/_cjs/actions/types.js +0 -3
- package/_cjs/actions/types.js.map +0 -1
- package/_cjs/actions/waitForFundOperationReceipt.js +0 -65
- package/_cjs/actions/waitForFundOperationReceipt.js.map +0 -1
- package/_cjs/openapi-client/generated/payments-alpha/payments-alpha.js +0 -50
- package/_cjs/openapi-client/generated/payments-alpha/payments-alpha.js.map +0 -1
- package/_esm/actions/Quote.js +0 -101
- package/_esm/actions/Quote.js.map +0 -1
- package/_esm/actions/evm/fund/fund.js +0 -48
- package/_esm/actions/evm/fund/fund.js.map +0 -1
- package/_esm/actions/evm/fund/quoteFund.js +0 -45
- package/_esm/actions/evm/fund/quoteFund.js.map +0 -1
- package/_esm/actions/solana/fund/fund.js +0 -48
- package/_esm/actions/solana/fund/fund.js.map +0 -1
- package/_esm/actions/solana/fund/quoteFund.js +0 -45
- package/_esm/actions/solana/fund/quoteFund.js.map +0 -1
- package/_esm/actions/types.js +0 -2
- package/_esm/actions/types.js.map +0 -1
- package/_esm/actions/waitForFundOperationReceipt.js +0 -62
- package/_esm/actions/waitForFundOperationReceipt.js.map +0 -1
- package/_esm/openapi-client/generated/payments-alpha/payments-alpha.js +0 -42
- package/_esm/openapi-client/generated/payments-alpha/payments-alpha.js.map +0 -1
- package/_types/actions/Quote.d.ts +0 -97
- package/_types/actions/Quote.d.ts.map +0 -1
- package/_types/actions/evm/fund/fund.d.ts +0 -22
- package/_types/actions/evm/fund/fund.d.ts.map +0 -1
- package/_types/actions/evm/fund/quoteFund.d.ts +0 -23
- package/_types/actions/evm/fund/quoteFund.d.ts.map +0 -1
- package/_types/actions/solana/fund/fund.d.ts +0 -20
- package/_types/actions/solana/fund/fund.d.ts.map +0 -1
- package/_types/actions/solana/fund/quoteFund.d.ts +0 -21
- package/_types/actions/solana/fund/quoteFund.d.ts.map +0 -1
- package/_types/actions/types.d.ts +0 -37
- package/_types/actions/types.d.ts.map +0 -1
- package/_types/actions/waitForFundOperationReceipt.d.ts +0 -69
- package/_types/actions/waitForFundOperationReceipt.d.ts.map +0 -1
- package/_types/openapi-client/generated/payments-alpha/payments-alpha.d.ts +0 -42
- package/_types/openapi-client/generated/payments-alpha/payments-alpha.d.ts.map +0 -1
- package/actions/Quote.ts +0 -154
- package/actions/evm/fund/fund.ts +0 -74
- package/actions/evm/fund/quoteFund.ts +0 -80
- package/actions/solana/fund/fund.ts +0 -72
- package/actions/solana/fund/quoteFund.ts +0 -78
- package/actions/types.ts +0 -39
- package/actions/waitForFundOperationReceipt.ts +0 -119
- package/openapi-client/generated/payments-alpha/payments-alpha.ts +0 -96
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generated by orval v7.6.0 🍺
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
* Coinbase Developer Platform APIs
|
|
5
|
-
* The Coinbase Developer Platform APIs - leading the world's transition onchain.
|
|
6
|
-
* OpenAPI spec version: 2.0.0
|
|
7
|
-
*/
|
|
8
|
-
import type { CreatePaymentTransferQuote201, CreatePaymentTransferQuoteBody, CryptoRail, GetCryptoRailsParams, PaymentMethod, Transfer } from "../coinbaseDeveloperPlatformAPIs.schemas.js";
|
|
9
|
-
import { cdpApiClient } from "../../cdpApiClient.js";
|
|
10
|
-
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
|
11
|
-
/**
|
|
12
|
-
* Gets the fiat payment methods that can be used to send funds or receive funds. This is the list of payment methods configured for your account.
|
|
13
|
-
* @summary Get the fiat payment methods
|
|
14
|
-
*/
|
|
15
|
-
export declare const getPaymentMethods: (options?: SecondParameter<typeof cdpApiClient>) => Promise<PaymentMethod[]>;
|
|
16
|
-
/**
|
|
17
|
-
* Gets the crypto rails that can be used to send funds or receive funds.
|
|
18
|
-
* @summary Get the crypto rails
|
|
19
|
-
*/
|
|
20
|
-
export declare const getCryptoRails: (params?: GetCryptoRailsParams, options?: SecondParameter<typeof cdpApiClient>) => Promise<CryptoRail[]>;
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new transfer quote, which can then be executed using the Execute a transfer quote endpoint. If you want to automatically execute the transfer without needing to confirm, specify execute as true.
|
|
23
|
-
* @summary Create a transfer quote
|
|
24
|
-
*/
|
|
25
|
-
export declare const createPaymentTransferQuote: (createPaymentTransferQuoteBody: CreatePaymentTransferQuoteBody, options?: SecondParameter<typeof cdpApiClient>) => Promise<CreatePaymentTransferQuote201>;
|
|
26
|
-
/**
|
|
27
|
-
* Executes a transfer quote which was created using the Create a transfer quote endpoint.
|
|
28
|
-
* @summary Execute a transfer quote
|
|
29
|
-
*/
|
|
30
|
-
export declare const executePaymentTransferQuote: (transferId: string, options?: SecondParameter<typeof cdpApiClient>) => Promise<Transfer>;
|
|
31
|
-
/**
|
|
32
|
-
* Gets a transfer by ID.
|
|
33
|
-
* @summary Get a transfer by ID
|
|
34
|
-
*/
|
|
35
|
-
export declare const getPaymentTransfer: (transferId: string, options?: SecondParameter<typeof cdpApiClient>) => Promise<Transfer>;
|
|
36
|
-
export type GetPaymentMethodsResult = NonNullable<Awaited<ReturnType<typeof getPaymentMethods>>>;
|
|
37
|
-
export type GetCryptoRailsResult = NonNullable<Awaited<ReturnType<typeof getCryptoRails>>>;
|
|
38
|
-
export type CreatePaymentTransferQuoteResult = NonNullable<Awaited<ReturnType<typeof createPaymentTransferQuote>>>;
|
|
39
|
-
export type ExecutePaymentTransferQuoteResult = NonNullable<Awaited<ReturnType<typeof executePaymentTransferQuote>>>;
|
|
40
|
-
export type GetPaymentTransferResult = NonNullable<Awaited<ReturnType<typeof getPaymentTransfer>>>;
|
|
41
|
-
export {};
|
|
42
|
-
//# sourceMappingURL=payments-alpha.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payments-alpha.d.ts","sourceRoot":"","sources":["../../../../openapi-client/generated/payments-alpha/payments-alpha.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,6BAA6B,EAC7B,8BAA8B,EAC9B,UAAU,EACV,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACT,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,KAAK,eAAe,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/E;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU,eAAe,CAAC,OAAO,YAAY,CAAC,6BAK/E,CAAC;AACF;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,oBAAoB,EAC7B,UAAU,eAAe,CAAC,OAAO,YAAY,CAAC,0BAM/C,CAAC;AACF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,GACrC,gCAAgC,8BAA8B,EAC9D,UAAU,eAAe,CAAC,OAAO,YAAY,CAAC,2CAW/C,CAAC;AACF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GACtC,YAAY,MAAM,EAClB,UAAU,eAAe,CAAC,OAAO,YAAY,CAAC,sBAM/C,CAAC;AACF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,MAAM,EAClB,UAAU,eAAe,CAAC,OAAO,YAAY,CAAC,sBAM/C,CAAC;AACF,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC;AACjG,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC;AAC3F,MAAM,MAAM,gCAAgC,GAAG,WAAW,CACxD,OAAO,CAAC,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC,CACvD,CAAC;AACF,MAAM,MAAM,iCAAiC,GAAG,WAAW,CACzD,OAAO,CAAC,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC,CACxD,CAAC;AACF,MAAM,MAAM,wBAAwB,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC"}
|
package/actions/Quote.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
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
|
-
}
|
package/actions/evm/fund/fund.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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 an EVM account.
|
|
13
|
-
*/
|
|
14
|
-
export interface EvmFundOptions extends BaseFundOptions {
|
|
15
|
-
/** The network to request funds from. */
|
|
16
|
-
network: "base" | "ethereum";
|
|
17
|
-
/** The token to request funds for. */
|
|
18
|
-
token: "eth" | "usdc";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Funds an EVM account.
|
|
23
|
-
*
|
|
24
|
-
* @deprecated This method will be removed in a future version. Consider using our Onramp API instead. See https://docs.cdp.coinbase.com/api-reference/v2/rest-api/onramp/create-an-onramp-order.
|
|
25
|
-
* @param apiClient - The API client.
|
|
26
|
-
* @param options - The options for funding an EVM account.
|
|
27
|
-
*
|
|
28
|
-
* @returns A promise that resolves to the fund operation result.
|
|
29
|
-
*/
|
|
30
|
-
export async function fund(
|
|
31
|
-
apiClient: CdpOpenApiClientType,
|
|
32
|
-
options: EvmFundOptions,
|
|
33
|
-
): Promise<FundOperationResult> {
|
|
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
|
-
|
|
41
|
-
const paymentMethods = await apiClient.getPaymentMethods();
|
|
42
|
-
const cardPaymentMethod = paymentMethods.find(
|
|
43
|
-
method => method.type === "card" && method.actions.includes("source"),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
if (!cardPaymentMethod) {
|
|
47
|
-
throw new Error("No card found to fund account");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const response = await apiClient.createPaymentTransferQuote({
|
|
51
|
-
sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
|
|
52
|
-
source: {
|
|
53
|
-
id: cardPaymentMethod.id,
|
|
54
|
-
},
|
|
55
|
-
targetType: CreatePaymentTransferQuoteBodyTargetType.crypto_rail,
|
|
56
|
-
target: {
|
|
57
|
-
currency: options.token,
|
|
58
|
-
network: options.network,
|
|
59
|
-
address: options.address,
|
|
60
|
-
},
|
|
61
|
-
amount,
|
|
62
|
-
currency: options.token,
|
|
63
|
-
execute: true,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
id: response.transfer.id,
|
|
68
|
-
network: response.transfer.target.network,
|
|
69
|
-
status: response.transfer.status,
|
|
70
|
-
targetAmount: response.transfer.targetAmount,
|
|
71
|
-
targetCurrency: response.transfer.targetCurrency,
|
|
72
|
-
transactionHash: response.transfer.transactionHash,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
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 { EvmQuote } from "../../Quote.js";
|
|
10
|
-
import { BaseQuoteFundOptions } from "../../types.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Options for getting a quote to fund an EVM account.
|
|
14
|
-
*/
|
|
15
|
-
export interface EvmQuoteFundOptions extends BaseQuoteFundOptions {
|
|
16
|
-
/** The network to request funds from. */
|
|
17
|
-
network: "base" | "ethereum";
|
|
18
|
-
/** The token to request funds for. */
|
|
19
|
-
token: "eth" | "usdc";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Gets a quote to fund an EVM account.
|
|
24
|
-
*
|
|
25
|
-
* @deprecated This method will be removed in a future version. Consider using our Onramp API instead. See https://docs.cdp.coinbase.com/api-reference/v2/rest-api/onramp/create-an-onramp-order.
|
|
26
|
-
* @param apiClient - The API client.
|
|
27
|
-
* @param options - The options for getting a quote to fund an EVM account.
|
|
28
|
-
*
|
|
29
|
-
* @returns A promise that resolves to the quote.
|
|
30
|
-
*/
|
|
31
|
-
export async function quoteFund(
|
|
32
|
-
apiClient: CdpOpenApiClientType,
|
|
33
|
-
options: EvmQuoteFundOptions,
|
|
34
|
-
): Promise<EvmQuote> {
|
|
35
|
-
if (options.token !== "eth" && options.token !== "usdc") {
|
|
36
|
-
throw new UserInputValidationError("Invalid token, must be eth or usdc");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const decimals = options.token === "eth" ? 18 : 6;
|
|
40
|
-
const amount = formatUnits(options.amount, decimals);
|
|
41
|
-
|
|
42
|
-
const paymentMethods = await apiClient.getPaymentMethods();
|
|
43
|
-
const cardPaymentMethod = paymentMethods.find(
|
|
44
|
-
method => method.type === "card" && method.actions.includes("source"),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
if (!cardPaymentMethod) {
|
|
48
|
-
throw new Error("No card found to fund account");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const response = await apiClient.createPaymentTransferQuote({
|
|
52
|
-
sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
|
|
53
|
-
source: {
|
|
54
|
-
id: cardPaymentMethod.id,
|
|
55
|
-
},
|
|
56
|
-
targetType: CreatePaymentTransferQuoteBodyTargetType.crypto_rail,
|
|
57
|
-
target: {
|
|
58
|
-
currency: options.token,
|
|
59
|
-
network: options.network,
|
|
60
|
-
address: options.address,
|
|
61
|
-
},
|
|
62
|
-
amount,
|
|
63
|
-
currency: options.token,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return new EvmQuote(
|
|
67
|
-
apiClient,
|
|
68
|
-
response.transfer.id,
|
|
69
|
-
options.network,
|
|
70
|
-
response.transfer.sourceAmount,
|
|
71
|
-
response.transfer.sourceCurrency,
|
|
72
|
-
response.transfer.targetAmount,
|
|
73
|
-
response.transfer.targetCurrency,
|
|
74
|
-
response.transfer.fees.map(fee => ({
|
|
75
|
-
type: fee.type,
|
|
76
|
-
amount: fee.amount,
|
|
77
|
-
currency: fee.currency,
|
|
78
|
-
})),
|
|
79
|
-
);
|
|
80
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
* @deprecated This method will be removed in a future version. Consider using our Onramp API instead. See https://docs.cdp.coinbase.com/api-reference/v2/rest-api/onramp/create-an-onramp-order.
|
|
23
|
-
* @param apiClient - The API client.
|
|
24
|
-
* @param options - The options for funding a Solana account.
|
|
25
|
-
*
|
|
26
|
-
* @returns A promise that resolves to the fund operation result.
|
|
27
|
-
*/
|
|
28
|
-
export async function fund(
|
|
29
|
-
apiClient: CdpOpenApiClientType,
|
|
30
|
-
options: SolanaFundOptions,
|
|
31
|
-
): Promise<FundOperationResult> {
|
|
32
|
-
if (options.token !== "sol" && options.token !== "usdc") {
|
|
33
|
-
throw new UserInputValidationError("Invalid token, must be sol or usdc");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const decimals = options.token === "sol" ? 9 : 6;
|
|
37
|
-
const amount = formatUnits(options.amount, decimals);
|
|
38
|
-
|
|
39
|
-
const paymentMethods = await apiClient.getPaymentMethods();
|
|
40
|
-
const cardPaymentMethod = paymentMethods.find(
|
|
41
|
-
method => method.type === "card" && method.actions.includes("source"),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (!cardPaymentMethod) {
|
|
45
|
-
throw new Error("No card found to fund account");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const response = await apiClient.createPaymentTransferQuote({
|
|
49
|
-
sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
|
|
50
|
-
source: {
|
|
51
|
-
id: cardPaymentMethod.id,
|
|
52
|
-
},
|
|
53
|
-
targetType: CreatePaymentTransferQuoteBodyTargetType.crypto_rail,
|
|
54
|
-
target: {
|
|
55
|
-
currency: options.token,
|
|
56
|
-
network: "solana",
|
|
57
|
-
address: options.address,
|
|
58
|
-
},
|
|
59
|
-
amount,
|
|
60
|
-
currency: options.token,
|
|
61
|
-
execute: true,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
id: response.transfer.id,
|
|
66
|
-
network: response.transfer.target.network,
|
|
67
|
-
status: response.transfer.status,
|
|
68
|
-
targetAmount: response.transfer.targetAmount,
|
|
69
|
-
targetCurrency: response.transfer.targetCurrency,
|
|
70
|
-
transactionHash: response.transfer.transactionHash,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { formatUnits } from "viem";
|
|
2
|
-
|
|
3
|
-
import { UserInputValidationError } from "../../../errors.js";
|
|
4
|
-
import {
|
|
5
|
-
CdpOpenApiClientType,
|
|
6
|
-
CreatePaymentTransferQuoteBodySourceType,
|
|
7
|
-
CreatePaymentTransferQuoteBodyTargetType,
|
|
8
|
-
} from "../../../openapi-client/index.js";
|
|
9
|
-
import { SolanaQuote } from "../../Quote.js";
|
|
10
|
-
import { BaseQuoteFundOptions } from "../../types.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Options for getting a quote to fund a Solana account.
|
|
14
|
-
*/
|
|
15
|
-
export interface SolanaQuoteFundOptions extends BaseQuoteFundOptions {
|
|
16
|
-
/** The token to request funds for. */
|
|
17
|
-
token: "sol" | "usdc";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Gets a quote to fund a Solana account.
|
|
22
|
-
*
|
|
23
|
-
* @deprecated This method will be removed in a future version. Consider using our Onramp API instead. See https://docs.cdp.coinbase.com/api-reference/v2/rest-api/onramp/create-an-onramp-order.
|
|
24
|
-
* @param apiClient - The API client.
|
|
25
|
-
* @param options - The options for getting a quote to fund a Solana account.
|
|
26
|
-
*
|
|
27
|
-
* @returns A promise that resolves to the quote.
|
|
28
|
-
*/
|
|
29
|
-
export async function quoteFund(
|
|
30
|
-
apiClient: CdpOpenApiClientType,
|
|
31
|
-
options: SolanaQuoteFundOptions,
|
|
32
|
-
): Promise<SolanaQuote> {
|
|
33
|
-
if (options.token !== "sol" && options.token !== "usdc") {
|
|
34
|
-
throw new UserInputValidationError("Invalid token, must be sol or usdc");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const decimals = options.token === "sol" ? 9 : 6;
|
|
38
|
-
const amount = formatUnits(options.amount, decimals);
|
|
39
|
-
|
|
40
|
-
const paymentMethods = await apiClient.getPaymentMethods();
|
|
41
|
-
const cardPaymentMethod = paymentMethods.find(
|
|
42
|
-
method => method.type === "card" && method.actions.includes("source"),
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (!cardPaymentMethod) {
|
|
46
|
-
throw new Error("No card found to fund account");
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const response = await apiClient.createPaymentTransferQuote({
|
|
50
|
-
sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
|
|
51
|
-
source: {
|
|
52
|
-
id: cardPaymentMethod.id,
|
|
53
|
-
},
|
|
54
|
-
targetType: CreatePaymentTransferQuoteBodyTargetType.crypto_rail,
|
|
55
|
-
target: {
|
|
56
|
-
currency: options.token,
|
|
57
|
-
network: "solana",
|
|
58
|
-
address: options.address,
|
|
59
|
-
},
|
|
60
|
-
amount,
|
|
61
|
-
currency: options.token,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
return new SolanaQuote(
|
|
65
|
-
apiClient,
|
|
66
|
-
response.transfer.id,
|
|
67
|
-
"solana",
|
|
68
|
-
response.transfer.sourceAmount,
|
|
69
|
-
response.transfer.sourceCurrency,
|
|
70
|
-
response.transfer.targetAmount,
|
|
71
|
-
response.transfer.targetCurrency,
|
|
72
|
-
response.transfer.fees.map(fee => ({
|
|
73
|
-
type: fee.type,
|
|
74
|
-
amount: fee.amount,
|
|
75
|
-
currency: fee.currency,
|
|
76
|
-
})),
|
|
77
|
-
);
|
|
78
|
-
}
|
package/actions/types.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { TransferStatus } from "../openapi-client/index.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Base options for getting a quote to fund an account.
|
|
5
|
-
*/
|
|
6
|
-
export interface BaseQuoteFundOptions {
|
|
7
|
-
/** The address of the account. */
|
|
8
|
-
address: string;
|
|
9
|
-
/** The amount to fund the account with, in atomic units (e.g. wei for ETH, lamports for SOL) of the token. */
|
|
10
|
-
amount: bigint;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Base options for funding an account.
|
|
15
|
-
*/
|
|
16
|
-
export interface BaseFundOptions {
|
|
17
|
-
/** The address of the account. */
|
|
18
|
-
address: string;
|
|
19
|
-
/** The amount to fund the account with, in atomic units (e.g. wei for ETH, lamports for SOL) of the token. */
|
|
20
|
-
amount: bigint;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The result of a fund operation.
|
|
25
|
-
*/
|
|
26
|
-
export type FundOperationResult = {
|
|
27
|
-
/** The transfer that was created to fund the account. */
|
|
28
|
-
id: string;
|
|
29
|
-
/** The network that the transfer was created on. */
|
|
30
|
-
network: string;
|
|
31
|
-
/** The target amount that will be received. */
|
|
32
|
-
targetAmount: string;
|
|
33
|
-
/** The currency that will be received. */
|
|
34
|
-
targetCurrency: string;
|
|
35
|
-
/** The status of the fund operation. */
|
|
36
|
-
status: TransferStatus;
|
|
37
|
-
/** The transaction hash of the transfer. */
|
|
38
|
-
transactionHash?: string;
|
|
39
|
-
};
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { CdpOpenApiClientType, Transfer, TransferStatus } from "../openapi-client/index.js";
|
|
2
|
-
import { wait, WaitOptions } from "../utils/wait.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Options for waiting for a fund operation.
|
|
6
|
-
*/
|
|
7
|
-
export type WaitForFundOperationOptions = {
|
|
8
|
-
/** The ID of the transfer to wait for. */
|
|
9
|
-
transferId: string;
|
|
10
|
-
/** Optional options for the wait operation. */
|
|
11
|
-
waitOptions?: WaitOptions;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Represents a failed fund operation.
|
|
16
|
-
*/
|
|
17
|
-
export type FailedFundOperation = {
|
|
18
|
-
/** The ID of the transfer. */
|
|
19
|
-
id: string;
|
|
20
|
-
/** The network that the transfer was created on. */
|
|
21
|
-
network: string;
|
|
22
|
-
/** The target amount that will be received. */
|
|
23
|
-
targetAmount: string;
|
|
24
|
-
/** The currency that will be received. */
|
|
25
|
-
targetCurrency: string;
|
|
26
|
-
/** The status of the transfer. */
|
|
27
|
-
status: typeof TransferStatus.failed;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Represents a completed fund operation.
|
|
32
|
-
*/
|
|
33
|
-
export type CompletedFundOperation = {
|
|
34
|
-
/** The ID of the transfer. */
|
|
35
|
-
id: string;
|
|
36
|
-
/** The network that the transfer was created on. */
|
|
37
|
-
network: string;
|
|
38
|
-
/** The target amount that will be received. */
|
|
39
|
-
targetAmount: string;
|
|
40
|
-
/** The currency that will be received. */
|
|
41
|
-
targetCurrency: string;
|
|
42
|
-
/** The status of the transfer. */
|
|
43
|
-
status: typeof TransferStatus.completed;
|
|
44
|
-
/** The transaction hash of the transfer. */
|
|
45
|
-
transactionHash: string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Represents the return type of the waitForFundOperation function.
|
|
50
|
-
*/
|
|
51
|
-
export type WaitForFundOperationResult = FailedFundOperation | CompletedFundOperation;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Waits for a fund operation to complete or fail.
|
|
55
|
-
*
|
|
56
|
-
* @deprecated This method will be removed in a future version. Consider using our Onramp API instead. See https://docs.cdp.coinbase.com/api-reference/v2/rest-api/onramp/create-an-onramp-order.
|
|
57
|
-
* @example
|
|
58
|
-
* ```ts
|
|
59
|
-
* import { waitForFundOperation } from "@coinbase/cdp-sdk";
|
|
60
|
-
*
|
|
61
|
-
* const result = await waitForFundOperation(client, {
|
|
62
|
-
* transferId: "0x1234567890123456789012345678901234567890",
|
|
63
|
-
* waitOptions: {
|
|
64
|
-
* timeoutSeconds: 30,
|
|
65
|
-
* },
|
|
66
|
-
* });
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* @param {CdpOpenApiClientType} client - The client to use to wait for the fund operation.
|
|
70
|
-
* @param {WaitForFundOperationOptions} options - The options for the wait operation.
|
|
71
|
-
* @returns {Promise<WaitForFundOperationResult>} The result of the fund operation.
|
|
72
|
-
*/
|
|
73
|
-
export async function waitForFundOperationReceipt(
|
|
74
|
-
client: CdpOpenApiClientType,
|
|
75
|
-
options: WaitForFundOperationOptions,
|
|
76
|
-
): Promise<WaitForFundOperationResult> {
|
|
77
|
-
const { transferId } = options;
|
|
78
|
-
|
|
79
|
-
const reload = async () => {
|
|
80
|
-
const response = await client.getPaymentTransfer(transferId);
|
|
81
|
-
return response;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const transform = (operation: Transfer): WaitForFundOperationResult => {
|
|
85
|
-
if (operation.status === TransferStatus.failed) {
|
|
86
|
-
return {
|
|
87
|
-
id: operation.id,
|
|
88
|
-
network: operation.target.network,
|
|
89
|
-
targetAmount: operation.targetAmount,
|
|
90
|
-
targetCurrency: operation.targetCurrency,
|
|
91
|
-
status: operation.status,
|
|
92
|
-
} satisfies FailedFundOperation;
|
|
93
|
-
} else if (operation.status === TransferStatus.completed) {
|
|
94
|
-
return {
|
|
95
|
-
id: operation.id,
|
|
96
|
-
network: operation.target.network,
|
|
97
|
-
targetAmount: operation.targetAmount,
|
|
98
|
-
targetCurrency: operation.targetCurrency,
|
|
99
|
-
status: operation.status,
|
|
100
|
-
transactionHash: operation.transactionHash!,
|
|
101
|
-
} satisfies CompletedFundOperation;
|
|
102
|
-
} else {
|
|
103
|
-
throw new Error("Transfer is not terminal");
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const waitOptions = options.waitOptions || {
|
|
108
|
-
timeoutSeconds: 900,
|
|
109
|
-
intervalSeconds: 1,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
return await wait(reload, isTerminal, transform, waitOptions);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const isTerminal = (operation: Transfer): boolean => {
|
|
116
|
-
return (
|
|
117
|
-
operation.status === TransferStatus.completed || operation.status === TransferStatus.failed
|
|
118
|
-
);
|
|
119
|
-
};
|