@coin-voyage/shared 2.4.3-beta.0 → 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.
@@ -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;
@@ -25,3 +25,6 @@ export const nonUsdCurrencies = data.map(([name, symbol, currency, decimals]) =>
25
25
  currency,
26
26
  decimals,
27
27
  }));
28
+ export function currencyID(currency) {
29
+ return currency.address ? `${currency.address}:${currency.chain_id}` : currency.chain_id.toString();
30
+ }
@@ -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,4 +1,9 @@
1
- import type { FiatPaymentData, PaymentDataBase, PaymentStep } from "../types/model";
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;
2
6
  export declare function getFiatPaymentData(payment?: PaymentDataBase): FiatPaymentData | undefined;
3
7
  export declare function getPaymentStep(payment?: PaymentDataBase, stepIndex?: number): PaymentStep | undefined;
4
8
  export declare function getDepositAddress(payment?: PaymentDataBase, stepIndex?: number): string | undefined;
9
+ export {};
@@ -1,9 +1,18 @@
1
1
  import { PaymentRail, StepKind } from "../types/enums";
2
+ export function isDepositStepData(data) {
3
+ return Boolean("amount" in data && "currency" in data && "deposit_address" in data);
4
+ }
5
+ export function isCryptoPaymentData(data) {
6
+ return Boolean(!isDepositStepData(data) && !isFiatPaymentData(data));
7
+ }
8
+ export function isFiatPaymentData(data) {
9
+ return Boolean("session_id" in data);
10
+ }
2
11
  export function getFiatPaymentData(payment) {
3
12
  const step = getPaymentStep(payment);
4
13
  if (step?.rail !== PaymentRail.FIAT || step.kind !== StepKind.KIND_STRIPE_ONRAMP)
5
14
  return undefined;
6
- return step.data?.fiat;
15
+ return isFiatPaymentData(step.data) ? step.data : undefined;
7
16
  }
8
17
  export function getPaymentStep(payment, stepIndex) {
9
18
  const steps = payment?.steps ?? [];
@@ -14,11 +23,9 @@ export function getPaymentStep(payment, stepIndex) {
14
23
  }
15
24
  export function getDepositAddress(payment, stepIndex) {
16
25
  const step = getPaymentStep(payment, stepIndex);
17
- if (step?.kind === StepKind.KIND_DEPOSIT) {
18
- return step.deposit_address;
19
- }
20
- if (step?.kind === StepKind.KIND_TRANSACTION) {
26
+ if (step?.kind !== StepKind.KIND_DEPOSIT) {
21
27
  return undefined;
22
28
  }
23
- return payment?.deposit_address;
29
+ const data = isDepositStepData(step.data) ? step.data : undefined;
30
+ return data?.deposit_address;
24
31
  }
@@ -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
  };
@@ -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, ProviderStatus, StepKind } from "./enums";
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?: string;
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?: CurrencyAmount;
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: PaymentRail;
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
- deposit_address?: string;
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 {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/shared",
3
3
  "description": "Shared utilities for Coin Voyage",
4
- "version": "2.4.3-beta.0",
4
+ "version": "2.4.3",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {