@coin-voyage/shared 2.4.2 → 2.4.3
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/dist/currency/currencies.d.ts +2 -0
- package/dist/currency/currencies.js +3 -0
- package/dist/currency/token-list.js +2 -0
- package/dist/payment/payment-steps.d.ts +8 -11
- package/dist/payment/payment-steps.js +22 -44
- package/dist/schemas/pay-order.js +4 -2
- package/dist/types/api.d.ts +1 -4
- package/dist/types/model.d.ts +15 -33
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CurrencyBase } from "../types";
|
|
1
2
|
export declare const FIAT_CURRENCIES: readonly ["USD", "EUR"];
|
|
2
3
|
export type FiatCurrency = (typeof FIAT_CURRENCIES)[number];
|
|
3
4
|
export interface CurrencyExchangeRate {
|
|
@@ -14,3 +15,4 @@ export declare const nonUsdCurrencies: {
|
|
|
14
15
|
currency: string;
|
|
15
16
|
decimals: number;
|
|
16
17
|
}[];
|
|
18
|
+
export declare function currencyID(currency: CurrencyBase): string;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { currencyID } from "./currencies";
|
|
1
2
|
const TOKEN_LIST_URL = "https://raw.githubusercontent.com/coin-voyage/token-list/main/tokenlist.json";
|
|
2
3
|
export function tokenToCurrency(token) {
|
|
3
4
|
return {
|
|
5
|
+
id: currencyID({ chain_id: token.chainId, address: token.address }),
|
|
4
6
|
chain_id: token.chainId,
|
|
5
7
|
address: token.address,
|
|
6
8
|
name: token.name,
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { CryptoPaymentData, DepositStepData, FiatPaymentData, PaymentDataBase, PaymentStep } from "../types/model";
|
|
2
|
+
type PaymentStepData = DepositStepData | CryptoPaymentData | FiatPaymentData;
|
|
3
|
+
export declare function isDepositStepData(data: PaymentStepData): data is DepositStepData;
|
|
4
|
+
export declare function isCryptoPaymentData(data: PaymentStepData): data is CryptoPaymentData;
|
|
5
|
+
export declare function isFiatPaymentData(data: PaymentStepData): data is FiatPaymentData;
|
|
3
6
|
export declare function getFiatPaymentData(payment?: PaymentDataBase): FiatPaymentData | undefined;
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export
|
|
7
|
-
export declare function getWalletPaymentData(payment?: PaymentDataBase): CryptoPaymentData | undefined;
|
|
8
|
-
export declare function getDepositAddress(payment?: PaymentDataBase): string | undefined;
|
|
9
|
-
export declare function getEvmPaymentData(paymentData?: CryptoPaymentData): EVMPaymentData | undefined;
|
|
10
|
-
export declare function getBitcoinPaymentData(paymentData?: CryptoPaymentData): BitcoinPaymentData | undefined;
|
|
11
|
-
export declare function getSolanaPaymentData(paymentData?: CryptoPaymentData): SolanaPaymentData | undefined;
|
|
12
|
-
export declare function getSuiPaymentData(paymentData?: CryptoPaymentData): SuiPaymentData | undefined;
|
|
7
|
+
export declare function getPaymentStep(payment?: PaymentDataBase, stepIndex?: number): PaymentStep | undefined;
|
|
8
|
+
export declare function getDepositAddress(payment?: PaymentDataBase, stepIndex?: number): string | undefined;
|
|
9
|
+
export {};
|
|
@@ -1,53 +1,31 @@
|
|
|
1
1
|
import { PaymentRail, StepKind } from "../types/enums";
|
|
2
|
-
export function
|
|
3
|
-
return
|
|
4
|
-
return (step.rail === PaymentRail.FIAT || step.kind === StepKind.KIND_STRIPE_ONRAMP) && step.data?.fiat;
|
|
5
|
-
});
|
|
2
|
+
export function isDepositStepData(data) {
|
|
3
|
+
return Boolean("amount" in data && "currency" in data && "deposit_address" in data);
|
|
6
4
|
}
|
|
7
|
-
export function
|
|
8
|
-
|
|
9
|
-
return data?.fiat;
|
|
10
|
-
}
|
|
11
|
-
export function getCryptoDepositStep(payment) {
|
|
12
|
-
return payment?.steps.find((step) => {
|
|
13
|
-
return step.rail === PaymentRail.CRYPTO && step.kind === StepKind.KIND_DEPOSIT;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
export function getCryptoTransactionStep(payment) {
|
|
17
|
-
return payment?.steps.find((step) => {
|
|
18
|
-
return step.rail === PaymentRail.CRYPTO && step.kind === StepKind.KIND_TRANSACTION && step.data?.crypto;
|
|
19
|
-
});
|
|
5
|
+
export function isCryptoPaymentData(data) {
|
|
6
|
+
return Boolean(!isDepositStepData(data) && !isFiatPaymentData(data));
|
|
20
7
|
}
|
|
21
|
-
export function
|
|
22
|
-
return
|
|
8
|
+
export function isFiatPaymentData(data) {
|
|
9
|
+
return Boolean("session_id" in data);
|
|
23
10
|
}
|
|
24
|
-
export function
|
|
25
|
-
const
|
|
26
|
-
|
|
11
|
+
export function getFiatPaymentData(payment) {
|
|
12
|
+
const step = getPaymentStep(payment);
|
|
13
|
+
if (step?.rail !== PaymentRail.FIAT || step.kind !== StepKind.KIND_STRIPE_ONRAMP)
|
|
14
|
+
return undefined;
|
|
15
|
+
return isFiatPaymentData(step.data) ? step.data : undefined;
|
|
27
16
|
}
|
|
28
|
-
export function
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
return
|
|
17
|
+
export function getPaymentStep(payment, stepIndex) {
|
|
18
|
+
const steps = payment?.steps ?? [];
|
|
19
|
+
if (stepIndex !== undefined) {
|
|
20
|
+
return steps[stepIndex];
|
|
32
21
|
}
|
|
33
|
-
|
|
22
|
+
return steps[0];
|
|
23
|
+
}
|
|
24
|
+
export function getDepositAddress(payment, stepIndex) {
|
|
25
|
+
const step = getPaymentStep(payment, stepIndex);
|
|
26
|
+
if (step?.kind !== StepKind.KIND_DEPOSIT) {
|
|
34
27
|
return undefined;
|
|
35
28
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export function getEvmPaymentData(paymentData) {
|
|
39
|
-
const data = paymentData;
|
|
40
|
-
return data?.evm;
|
|
41
|
-
}
|
|
42
|
-
export function getBitcoinPaymentData(paymentData) {
|
|
43
|
-
const data = paymentData;
|
|
44
|
-
return data?.bitcoin;
|
|
45
|
-
}
|
|
46
|
-
export function getSolanaPaymentData(paymentData) {
|
|
47
|
-
const data = paymentData;
|
|
48
|
-
return data?.solana;
|
|
49
|
-
}
|
|
50
|
-
export function getSuiPaymentData(paymentData) {
|
|
51
|
-
const data = paymentData;
|
|
52
|
-
return data?.sui;
|
|
29
|
+
const data = isDepositStepData(step.data) ? step.data : undefined;
|
|
30
|
+
return data?.deposit_address;
|
|
53
31
|
}
|
|
@@ -43,13 +43,15 @@ export const zPayOrderMetadata = z
|
|
|
43
43
|
});
|
|
44
44
|
// NOTE: be careful to modify this type only in backward-compatible ways.
|
|
45
45
|
// Add OPTIONAL fields, etc. Anything else requires a migration.
|
|
46
|
-
export const zPayOrderSettings = z
|
|
46
|
+
export const zPayOrderSettings = z
|
|
47
|
+
.object({
|
|
47
48
|
hide_footer: z.boolean().optional().describe("Hide the CoinVoyage footer in supported payment UIs."),
|
|
48
49
|
card_payments: z
|
|
49
50
|
.boolean()
|
|
50
51
|
.optional()
|
|
51
52
|
.describe("Whether to enable card payments for this order. Requires approval from CoinVoyage."),
|
|
52
|
-
})
|
|
53
|
+
})
|
|
54
|
+
.catchall(z.unknown());
|
|
53
55
|
// also validate not both token_amount and fiat are present
|
|
54
56
|
export const zPayOrder = z.object({
|
|
55
57
|
metadata: zPayOrderMetadata.optional(),
|
package/dist/types/api.d.ts
CHANGED
|
@@ -55,10 +55,6 @@ export type PayOrderIntent = {
|
|
|
55
55
|
* Optional receiving address to fulfill the order to. If not provided, a settlement address will be selected.
|
|
56
56
|
*/
|
|
57
57
|
receiving_address?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Optional custom fee in basis points.
|
|
60
|
-
*/
|
|
61
|
-
custom_fee_bps?: number;
|
|
62
58
|
};
|
|
63
59
|
export type IntentAmount = {
|
|
64
60
|
/**
|
|
@@ -86,6 +82,7 @@ export type ClaimFeesRequest = {
|
|
|
86
82
|
export type ClaimFeesResponse = {
|
|
87
83
|
claim_order_id: string;
|
|
88
84
|
source_transaction_hash: string;
|
|
85
|
+
transaction_hash: string;
|
|
89
86
|
source_chain_id: ChainId;
|
|
90
87
|
currency: CurrencyAmount;
|
|
91
88
|
};
|
package/dist/types/model.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { FiatCurrency } from "../currency/currencies";
|
|
3
3
|
import { zPayOrderMetadata, zPayOrderSettings } from "../schemas/pay-order";
|
|
4
|
-
import { ChainId, PaymentRail, PayOrderMode, PayOrderStatus,
|
|
4
|
+
import { ChainId, PaymentRail, PayOrderMode, PayOrderStatus, StepKind } from "./enums";
|
|
5
5
|
export type PayOrder = {
|
|
6
6
|
id: string;
|
|
7
7
|
organization_id: string;
|
|
@@ -23,7 +23,7 @@ export type ParsedPayOrderSettings = z.output<typeof zPayOrderSettings> & Settin
|
|
|
23
23
|
export type PayOrderSettings = z.infer<typeof zPayOrderSettings> & SettingsExtraFields;
|
|
24
24
|
export type OrganizationSettings = ParsedPayOrderSettings;
|
|
25
25
|
export interface Currency extends CurrencyBase {
|
|
26
|
-
id
|
|
26
|
+
id: string;
|
|
27
27
|
name: string;
|
|
28
28
|
ticker: string;
|
|
29
29
|
decimals: number;
|
|
@@ -45,7 +45,7 @@ export interface QuoteWithCurrency extends CurrencyWithAmount {
|
|
|
45
45
|
}
|
|
46
46
|
export interface CurrencyWithBalance extends CurrencyWithAmount {
|
|
47
47
|
owner?: string;
|
|
48
|
-
balance
|
|
48
|
+
balance: CurrencyAmount;
|
|
49
49
|
}
|
|
50
50
|
export interface CurrencyAmount {
|
|
51
51
|
ui_amount: number;
|
|
@@ -141,12 +141,21 @@ export type FulfillmentData = {
|
|
|
141
141
|
rate_usd?: string;
|
|
142
142
|
receiving_address?: string;
|
|
143
143
|
custom_fee_bps?: number;
|
|
144
|
+
swap?: SwapContext;
|
|
145
|
+
};
|
|
146
|
+
export type SwapContext = {
|
|
147
|
+
requested_destination_currency?: CurrencyBase;
|
|
148
|
+
requested_source_currency?: CurrencyBase;
|
|
149
|
+
};
|
|
150
|
+
export type DepositStepData = {
|
|
151
|
+
deposit_address: string;
|
|
152
|
+
currency: CurrencyBase;
|
|
153
|
+
amount: BigIntStr;
|
|
144
154
|
};
|
|
145
155
|
export type PaymentDataBase = {
|
|
146
|
-
payment_rail
|
|
156
|
+
payment_rail?: PaymentRail;
|
|
147
157
|
src: QuoteWithCurrency;
|
|
148
158
|
dst: CurrencyWithAmount;
|
|
149
|
-
deposit_address: string;
|
|
150
159
|
receiving_address: string;
|
|
151
160
|
refund_address?: string;
|
|
152
161
|
steps: PaymentStep[];
|
|
@@ -161,38 +170,11 @@ export type PaymentData = PaymentDataBase & {
|
|
|
161
170
|
export type PaymentStep = {
|
|
162
171
|
rail: PaymentRail;
|
|
163
172
|
kind: StepKind;
|
|
164
|
-
|
|
165
|
-
data?: PaymentStepData;
|
|
173
|
+
data: DepositStepData | CryptoPaymentData | FiatPaymentData;
|
|
166
174
|
};
|
|
167
175
|
export type PaymentStepData = {
|
|
168
176
|
crypto?: CryptoPaymentData;
|
|
169
177
|
fiat?: FiatPaymentData;
|
|
170
178
|
};
|
|
171
|
-
export type ExecutionStep = {
|
|
172
|
-
id: string;
|
|
173
|
-
status: ProviderStatus;
|
|
174
|
-
provider: string;
|
|
175
|
-
receiver: string;
|
|
176
|
-
deposit_address: string;
|
|
177
|
-
source_tx_hash?: string;
|
|
178
|
-
destination_tx_hash?: string;
|
|
179
|
-
error?: string;
|
|
180
|
-
cleanup_tx_hash?: Record<string, string>;
|
|
181
|
-
cleanup_error?: string;
|
|
182
|
-
cleanup_recipient?: string;
|
|
183
|
-
source_currency: CurrencyWithAmount;
|
|
184
|
-
destination_currency: CurrencyWithAmount;
|
|
185
|
-
chain_data?: CryptoPaymentData;
|
|
186
|
-
gas?: CurrencyWithAmount;
|
|
187
|
-
fees?: FeeCurrencyBreakdown;
|
|
188
|
-
fee_tx_hash?: string;
|
|
189
|
-
fee_error?: string;
|
|
190
|
-
fee_plan?: FeePlan;
|
|
191
|
-
price_impact?: number;
|
|
192
|
-
};
|
|
193
|
-
export interface FeePlan extends CurrencyWithAmount {
|
|
194
|
-
placement: string;
|
|
195
|
-
fee_bps?: number;
|
|
196
|
-
}
|
|
197
179
|
export type BigIntStr = `${bigint}`;
|
|
198
180
|
export {};
|