@coin-voyage/shared 2.2.5-beta.1 → 2.2.5-beta.4

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,5 +1,5 @@
1
1
  import { type PayOrder, PayOrderMode } from "../types";
2
- import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, QuoteWithBalance, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, UpdateWebhookRequest, WebhookResponse } from "../types/api";
2
+ import type { ClaimFeesRequest, ClaimFeesResponse, CreateWebhookRequest, GetFeeBalancesResponse, OrderStatusSocket, PaymentDetails, PaymentDetailsParams, PayOrderParams, PayOrderQuoteParams, QuoteWithBalance, RouteQuote, SwapDataRequest, SwapDataResponse, SwapQuoteRequest, UpdateWebhookRequest, WebhookResponse } from "../types/api";
3
3
  import { type APIEnvironment } from "./config";
4
4
  import { type APIResponse } from "./fetcher";
5
5
  export declare class ApiClient {
@@ -140,7 +140,7 @@ export declare class ApiClient {
140
140
  *
141
141
  * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
142
142
  * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, `chain_id`.
143
- * @returns {Promise<APIResponse<QuoteWithBalance[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
143
+ * @returns {Promise<APIResponse<RouteQuote[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
144
144
  *
145
145
  * @example
146
146
  * const orderId = 'existingOrderId';
@@ -155,20 +155,21 @@ export declare class ApiClient {
155
155
  * console.log('Available tokens:', response.data);
156
156
  * }
157
157
  */
158
- payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams): Promise<APIResponse<QuoteWithBalance[]>>;
158
+ payOrderQuote(orderId: string, quoteParams: PayOrderQuoteParams): Promise<APIResponse<RouteQuote[]>>;
159
159
  /**
160
160
  * Retrieves payment details for a specific PayOrder.
161
161
  *
162
162
  * This function fetches payment details associated with a specific PayOrder ID.
163
163
  * It allows specifying the token and blockchain network (via `token_address` and `chain_id`)
164
164
  * to retrieve source currency information, as well as a refund address for the transaction.
165
+ * Alternative you can provide a `quote_id` to retrieve the payment details for a specific quote associated with the PayOrder.
165
166
  *
166
167
  * The request is authenticated using the provided API key in the headers.
167
168
  *
168
169
  * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
169
170
  * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched.
170
- * @param {string} [params.token_address] - (Optional) The token address of the source currency.
171
- * @param {ChainId} params.chain_id - The blockchain network ID where the token resides.
171
+ * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information.
172
+ * @param {string} params.quote_id - (Optional) The quote ID for the PayOrder.
172
173
  * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
173
174
  *
174
175
  * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
@@ -176,8 +177,7 @@ export declare class ApiClient {
176
177
  * @example
177
178
  * const response = await payOrderPaymentDetails({
178
179
  * payorder_id: '12345',
179
- * token_address: '0x1234567890abcdef1234567890abcdef12345678',
180
- * chain_id: 1,
180
+ * source_currency: { chain_id: 1, address: '0x1234567890abcdef1234567890abcdef12345678' },
181
181
  * refund_address: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
182
182
  * });
183
183
  *
@@ -278,7 +278,7 @@ export declare class ApiClient {
278
278
  * Subscribe to an order's events after the connection is open:
279
279
  * ```ts
280
280
  * const socket = apiClient.subscribeOrderStatus()
281
- * socket.onOpen(() => socket.subscribe(orderId)) // omit orderId to subscribe to all org orders
281
+ * socket.onOpen(() => socket.subscribe(orderId))
282
282
  * socket.onMessage((msg) => {
283
283
  * if (msg.type === 'event') console.log(msg.data)
284
284
  * })
@@ -219,7 +219,7 @@ export class ApiClient {
219
219
  *
220
220
  * @param {string} orderId - The unique identifier of the PayOrder for which the quote is requested.
221
221
  * @param {PayOrderQuoteParams} quoteParams - Contains `wallet_address`, `chain_type`, `chain_id`.
222
- * @returns {Promise<APIResponse<QuoteWithBalance[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
222
+ * @returns {Promise<APIResponse<RouteQuote[]>>} - An array of PayTokens wrapped in an API response if the request was successful.
223
223
  *
224
224
  * @example
225
225
  * const orderId = 'existingOrderId';
@@ -249,13 +249,14 @@ export class ApiClient {
249
249
  * This function fetches payment details associated with a specific PayOrder ID.
250
250
  * It allows specifying the token and blockchain network (via `token_address` and `chain_id`)
251
251
  * to retrieve source currency information, as well as a refund address for the transaction.
252
+ * Alternative you can provide a `quote_id` to retrieve the payment details for a specific quote associated with the PayOrder.
252
253
  *
253
254
  * The request is authenticated using the provided API key in the headers.
254
255
  *
255
256
  * @param {PaymentDetailsParams} params - Parameters to retrieve the payment details.
256
257
  * @param {string} params.payorder_id - The unique identifier of the PayOrder for which payment details are fetched.
257
- * @param {string} [params.token_address] - (Optional) The token address of the source currency.
258
- * @param {ChainId} params.chain_id - The blockchain network ID where the token resides.
258
+ * @param {CurrencyBase} [params.source_currency] - (Optional) The source currency information.
259
+ * @param {string} params.quote_id - (Optional) The quote ID for the PayOrder.
259
260
  * @param {string} params.refund_address - The address where funds will be refunded in case of a failed transaction.
260
261
  *
261
262
  * @returns {Promise<APIResponse<PaymentDetails>>} - The payment details object wrapped in an API response if the request is successful.
@@ -263,8 +264,7 @@ export class ApiClient {
263
264
  * @example
264
265
  * const response = await payOrderPaymentDetails({
265
266
  * payorder_id: '12345',
266
- * token_address: '0x1234567890abcdef1234567890abcdef12345678',
267
- * chain_id: 1,
267
+ * source_currency: { chain_id: 1, address: '0x1234567890abcdef1234567890abcdef12345678' },
268
268
  * refund_address: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcd',
269
269
  * });
270
270
  *
@@ -273,18 +273,12 @@ export class ApiClient {
273
273
  * }
274
274
  */
275
275
  async payOrderPaymentDetails(params) {
276
- const { payorder_id, token_address, chain_id, refund_address } = params;
276
+ const { payorder_id, ...rest } = params;
277
277
  return this.request({
278
278
  path: `/pay-orders/${payorder_id}/payment-details`,
279
279
  options: {
280
280
  method: "POST",
281
- body: JSON.stringify({
282
- source_currency: {
283
- address: token_address,
284
- chain_id,
285
- },
286
- refund_address: refund_address,
287
- }),
281
+ body: JSON.stringify({ ...rest }),
288
282
  },
289
283
  });
290
284
  }
@@ -471,7 +465,7 @@ export class ApiClient {
471
465
  * Subscribe to an order's events after the connection is open:
472
466
  * ```ts
473
467
  * const socket = apiClient.subscribeOrderStatus()
474
- * socket.onOpen(() => socket.subscribe(orderId)) // omit orderId to subscribe to all org orders
468
+ * socket.onOpen(() => socket.subscribe(orderId))
475
469
  * socket.onMessage((msg) => {
476
470
  * if (msg.type === 'event') console.log(msg.data)
477
471
  * })
@@ -11,3 +11,4 @@ export * from "./organization";
11
11
  export * from "./plural";
12
12
  export * from "./time";
13
13
  export * from "./validation";
14
+ export * from "./token-list";
@@ -11,3 +11,4 @@ export * from "./organization";
11
11
  export * from "./plural";
12
12
  export * from "./time";
13
13
  export * from "./validation";
14
+ export * from "./token-list";
@@ -0,0 +1,30 @@
1
+ import type { ChainId, CurrencyBase } from "../types";
2
+ export interface Token {
3
+ name: string;
4
+ address?: string;
5
+ ticker: string;
6
+ decimals: number;
7
+ chainId: ChainId;
8
+ logoURI: string;
9
+ }
10
+ export interface ChainMetadata {
11
+ chainId: ChainId;
12
+ name: string;
13
+ logoURI: string;
14
+ }
15
+ /**
16
+ * Returns all chains from the token list.
17
+ */
18
+ export declare function getChains(): Promise<ChainMetadata[]>;
19
+ /**
20
+ * Returns all tokens for the given chainId.
21
+ */
22
+ export declare function tokensByChainId(chainId: ChainId): Promise<Token[]>;
23
+ /**
24
+ * Returns chain metadata for the given chainId.
25
+ */
26
+ export declare function getChainMetadata(chainId: ChainId): Promise<ChainMetadata | undefined>;
27
+ /**
28
+ * Returns the token for the given chainId and address (undefined for native asset).
29
+ */
30
+ export declare function getToken(currency: CurrencyBase): Promise<Token | undefined>;
@@ -0,0 +1,43 @@
1
+ const TOKEN_LIST_URL = "https://raw.githubusercontent.com/coin-voyage/token-list/main/tokenlist.json";
2
+ async function fetchTokenList() {
3
+ const res = await fetch(TOKEN_LIST_URL);
4
+ if (!res.ok)
5
+ throw new Error(`Failed to fetch token list: ${res.status}`);
6
+ return (await res.json());
7
+ }
8
+ /**
9
+ * Returns all chains from the token list.
10
+ */
11
+ export async function getChains() {
12
+ const data = await fetchTokenList();
13
+ return data.chains.map((c) => ({
14
+ chainId: c.chainId,
15
+ name: c.name,
16
+ logoURI: c.logoURI,
17
+ }));
18
+ }
19
+ /**
20
+ * Returns all tokens for the given chainId.
21
+ */
22
+ export async function tokensByChainId(chainId) {
23
+ const data = await fetchTokenList();
24
+ const chain = data.chains.find((c) => c.chainId === chainId);
25
+ return chain?.tokens ?? [];
26
+ }
27
+ /**
28
+ * Returns chain metadata for the given chainId.
29
+ */
30
+ export async function getChainMetadata(chainId) {
31
+ const data = await fetchTokenList();
32
+ const chain = data.chains.find((c) => c.chainId === chainId);
33
+ if (!chain)
34
+ return undefined;
35
+ return { chainId: chain.chainId, name: chain.name, logoURI: chain.logoURI };
36
+ }
37
+ /**
38
+ * Returns the token for the given chainId and address (undefined for native asset).
39
+ */
40
+ export async function getToken(currency) {
41
+ const tokens = await tokensByChainId(currency.chain_id);
42
+ return tokens.find((t) => !currency.address ? !t.address : t.address?.toLowerCase() === currency.address.toLowerCase());
43
+ }
@@ -15,132 +15,7 @@ export declare const zPayOrderMetadata: z.ZodObject<{
15
15
  refund_amount: z.ZodOptional<z.ZodNumber>;
16
16
  currency: z.ZodOptional<z.ZodString>;
17
17
  }, z.core.$strip>>;
18
- }, z.core.$catchall<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodAny>, z.ZodObject<{
19
- def: z.core.$ZodAnyDef;
20
- type: "any";
21
- _def: z.core.$ZodAnyDef;
22
- _output: any;
23
- _input: any;
24
- check: (...checks: (z.core.CheckFn<any> | z.core.$ZodCheck<any>)[]) => z.ZodAny;
25
- clone: (def?: z.core.$ZodAnyDef | undefined, params?: {
26
- parent: boolean;
27
- } | undefined) => z.ZodAny;
28
- register: <R extends z.core.$ZodRegistry>(registry: R, ...meta: z.ZodAny extends infer T ? T extends z.ZodAny ? T extends R["_schema"] ? undefined extends R["_meta"] ? [(z.core.$replace<R["_meta"], R["_schema"] & z.ZodAny> | undefined)?] : [z.core.$replace<R["_meta"], R["_schema"] & z.ZodAny>] : ["Incompatible schema"] : never : never) => z.ZodAny;
29
- brand: <T extends PropertyKey = PropertyKey>(value?: T | undefined) => PropertyKey extends T ? z.ZodAny : z.core.$ZodBranded<z.ZodAny, T>;
30
- parse: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => any;
31
- safeParse: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => z.ZodSafeParseResult<any>;
32
- parseAsync: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<any>;
33
- safeParseAsync: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<z.ZodSafeParseResult<any>>;
34
- spa: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<z.ZodSafeParseResult<any>>;
35
- encode: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => any;
36
- decode: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => any;
37
- encodeAsync: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<any>;
38
- decodeAsync: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<any>;
39
- safeEncode: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => z.ZodSafeParseResult<any>;
40
- safeDecode: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => z.ZodSafeParseResult<any>;
41
- safeEncodeAsync: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<z.ZodSafeParseResult<any>>;
42
- safeDecodeAsync: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<z.ZodSafeParseResult<any>>;
43
- refine: (check: (arg: any) => unknown | Promise<unknown>, params?: string | {
44
- abort?: boolean | undefined | undefined;
45
- when?: ((payload: z.core.ParsePayload) => boolean) | undefined | undefined;
46
- path?: PropertyKey[] | undefined | undefined;
47
- params?: Record<string, any> | undefined;
48
- error?: string | z.core.$ZodErrorMap<NonNullable<z.core.$ZodIssue>> | undefined;
49
- message?: string | undefined | undefined;
50
- } | undefined) => z.ZodAny;
51
- superRefine: (refinement: (arg: any, ctx: z.core.$RefinementCtx<any>) => void | Promise<void>) => z.ZodAny;
52
- overwrite: (fn: (x: any) => any) => z.ZodAny;
53
- optional: () => z.ZodOptional<z.ZodAny>;
54
- nonoptional: (params?: string | z.core.$ZodNonOptionalParams) => z.ZodNonOptional<z.ZodAny>;
55
- nullable: () => z.ZodNullable<z.ZodAny>;
56
- nullish: () => z.ZodOptional<z.ZodNullable<z.ZodAny>>;
57
- default: {
58
- (def: any): z.ZodDefault<z.ZodAny>;
59
- (def: () => any): z.ZodDefault<z.ZodAny>;
60
- };
61
- prefault: {
62
- (def: () => any): z.ZodPrefault<z.ZodAny>;
63
- (def: any): z.ZodPrefault<z.ZodAny>;
64
- };
65
- array: () => z.ZodArray<z.ZodAny>;
66
- or: <T extends z.core.SomeType>(option: T) => z.ZodUnion<[z.ZodAny, T]>;
67
- and: <T extends z.core.SomeType>(incoming: T) => z.ZodIntersection<z.ZodAny, T>;
68
- transform: <NewOut>(transform: (arg: any, ctx: z.core.$RefinementCtx<any>) => NewOut | Promise<NewOut>) => z.ZodPipe<z.ZodAny, z.ZodTransform<Awaited<NewOut>, any>>;
69
- catch: {
70
- (def: any): z.ZodCatch<z.ZodAny>;
71
- (def: (ctx: z.core.$ZodCatchCtx) => any): z.ZodCatch<z.ZodAny>;
72
- };
73
- pipe: <T extends z.core.$ZodType<any, any, z.core.$ZodTypeInternals<any, any>>>(target: T | z.core.$ZodType<any, any, z.core.$ZodTypeInternals<any, any>>) => z.ZodPipe<z.ZodAny, T>;
74
- readonly: () => z.ZodReadonly<z.ZodAny>;
75
- describe: (description: string) => z.ZodAny;
76
- description?: string | undefined;
77
- meta: {
78
- (): {
79
- [x: string]: unknown;
80
- id?: string | undefined | undefined;
81
- title?: string | undefined | undefined;
82
- description?: string | undefined | undefined;
83
- deprecated?: boolean | undefined | undefined;
84
- } | undefined;
85
- (data: {
86
- [x: string]: unknown;
87
- id?: string | undefined | undefined;
88
- title?: string | undefined | undefined;
89
- description?: string | undefined | undefined;
90
- deprecated?: boolean | undefined | undefined;
91
- }): z.ZodAny;
92
- };
93
- isOptional: () => boolean;
94
- isNullable: () => boolean;
95
- _zod: z.core.$ZodAnyInternals;
96
- "~standard": z.core.$ZodStandardSchema<z.ZodAny>;
97
- }, z.core.$strip>]>, z.ZodTransform<string, string | number | boolean | any[] | {
98
- def: unknown;
99
- type: unknown;
100
- _def: unknown;
101
- _output: any;
102
- _input: any;
103
- check: unknown;
104
- clone: unknown;
105
- register: unknown;
106
- brand: unknown;
107
- parse: unknown;
108
- safeParse: unknown;
109
- parseAsync: unknown;
110
- safeParseAsync: unknown;
111
- spa: unknown;
112
- encode: unknown;
113
- decode: unknown;
114
- encodeAsync: unknown;
115
- decodeAsync: unknown;
116
- safeEncode: unknown;
117
- safeDecode: unknown;
118
- safeEncodeAsync: unknown;
119
- safeDecodeAsync: unknown;
120
- refine: unknown;
121
- superRefine: unknown;
122
- overwrite: unknown;
123
- optional: unknown;
124
- nonoptional: unknown;
125
- nullable: unknown;
126
- nullish: unknown;
127
- default: unknown;
128
- prefault: unknown;
129
- array: unknown;
130
- or: unknown;
131
- and: unknown;
132
- transform: unknown;
133
- catch: unknown;
134
- pipe: unknown;
135
- readonly: unknown;
136
- describe: unknown;
137
- description?: unknown;
138
- meta: unknown;
139
- isOptional: unknown;
140
- isNullable: unknown;
141
- _zod: unknown;
142
- "~standard": unknown;
143
- }>>>>;
18
+ }, z.core.$catchall<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodAny>, z.ZodObject<{}, z.core.$loose>]>>>;
144
19
  export declare const zPayOrder: z.ZodObject<{
145
20
  metadata: z.ZodOptional<z.ZodObject<{
146
21
  items: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -158,132 +33,7 @@ export declare const zPayOrder: z.ZodObject<{
158
33
  refund_amount: z.ZodOptional<z.ZodNumber>;
159
34
  currency: z.ZodOptional<z.ZodString>;
160
35
  }, z.core.$strip>>;
161
- }, z.core.$catchall<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodAny>, z.ZodObject<{
162
- def: z.core.$ZodAnyDef;
163
- type: "any";
164
- _def: z.core.$ZodAnyDef;
165
- _output: any;
166
- _input: any;
167
- check: (...checks: (z.core.CheckFn<any> | z.core.$ZodCheck<any>)[]) => z.ZodAny;
168
- clone: (def?: z.core.$ZodAnyDef | undefined, params?: {
169
- parent: boolean;
170
- } | undefined) => z.ZodAny;
171
- register: <R extends z.core.$ZodRegistry>(registry: R, ...meta: z.ZodAny extends infer T ? T extends z.ZodAny ? T extends R["_schema"] ? undefined extends R["_meta"] ? [(z.core.$replace<R["_meta"], R["_schema"] & z.ZodAny> | undefined)?] : [z.core.$replace<R["_meta"], R["_schema"] & z.ZodAny>] : ["Incompatible schema"] : never : never) => z.ZodAny;
172
- brand: <T extends PropertyKey = PropertyKey>(value?: T | undefined) => PropertyKey extends T ? z.ZodAny : z.core.$ZodBranded<z.ZodAny, T>;
173
- parse: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => any;
174
- safeParse: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => z.ZodSafeParseResult<any>;
175
- parseAsync: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<any>;
176
- safeParseAsync: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<z.ZodSafeParseResult<any>>;
177
- spa: (data: unknown, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<z.ZodSafeParseResult<any>>;
178
- encode: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => any;
179
- decode: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => any;
180
- encodeAsync: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<any>;
181
- decodeAsync: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<any>;
182
- safeEncode: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => z.ZodSafeParseResult<any>;
183
- safeDecode: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => z.ZodSafeParseResult<any>;
184
- safeEncodeAsync: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<z.ZodSafeParseResult<any>>;
185
- safeDecodeAsync: (data: any, params?: z.core.ParseContext<z.core.$ZodIssue>) => Promise<z.ZodSafeParseResult<any>>;
186
- refine: (check: (arg: any) => unknown | Promise<unknown>, params?: string | {
187
- abort?: boolean | undefined | undefined;
188
- when?: ((payload: z.core.ParsePayload) => boolean) | undefined | undefined;
189
- path?: PropertyKey[] | undefined | undefined;
190
- params?: Record<string, any> | undefined;
191
- error?: string | z.core.$ZodErrorMap<NonNullable<z.core.$ZodIssue>> | undefined;
192
- message?: string | undefined | undefined;
193
- } | undefined) => z.ZodAny;
194
- superRefine: (refinement: (arg: any, ctx: z.core.$RefinementCtx<any>) => void | Promise<void>) => z.ZodAny;
195
- overwrite: (fn: (x: any) => any) => z.ZodAny;
196
- optional: () => z.ZodOptional<z.ZodAny>;
197
- nonoptional: (params?: string | z.core.$ZodNonOptionalParams) => z.ZodNonOptional<z.ZodAny>;
198
- nullable: () => z.ZodNullable<z.ZodAny>;
199
- nullish: () => z.ZodOptional<z.ZodNullable<z.ZodAny>>;
200
- default: {
201
- (def: any): z.ZodDefault<z.ZodAny>;
202
- (def: () => any): z.ZodDefault<z.ZodAny>;
203
- };
204
- prefault: {
205
- (def: () => any): z.ZodPrefault<z.ZodAny>;
206
- (def: any): z.ZodPrefault<z.ZodAny>;
207
- };
208
- array: () => z.ZodArray<z.ZodAny>;
209
- or: <T extends z.core.SomeType>(option: T) => z.ZodUnion<[z.ZodAny, T]>;
210
- and: <T extends z.core.SomeType>(incoming: T) => z.ZodIntersection<z.ZodAny, T>;
211
- transform: <NewOut>(transform: (arg: any, ctx: z.core.$RefinementCtx<any>) => NewOut | Promise<NewOut>) => z.ZodPipe<z.ZodAny, z.ZodTransform<Awaited<NewOut>, any>>;
212
- catch: {
213
- (def: any): z.ZodCatch<z.ZodAny>;
214
- (def: (ctx: z.core.$ZodCatchCtx) => any): z.ZodCatch<z.ZodAny>;
215
- };
216
- pipe: <T extends z.core.$ZodType<any, any, z.core.$ZodTypeInternals<any, any>>>(target: T | z.core.$ZodType<any, any, z.core.$ZodTypeInternals<any, any>>) => z.ZodPipe<z.ZodAny, T>;
217
- readonly: () => z.ZodReadonly<z.ZodAny>;
218
- describe: (description: string) => z.ZodAny;
219
- description?: string | undefined;
220
- meta: {
221
- (): {
222
- [x: string]: unknown;
223
- id?: string | undefined | undefined;
224
- title?: string | undefined | undefined;
225
- description?: string | undefined | undefined;
226
- deprecated?: boolean | undefined | undefined;
227
- } | undefined;
228
- (data: {
229
- [x: string]: unknown;
230
- id?: string | undefined | undefined;
231
- title?: string | undefined | undefined;
232
- description?: string | undefined | undefined;
233
- deprecated?: boolean | undefined | undefined;
234
- }): z.ZodAny;
235
- };
236
- isOptional: () => boolean;
237
- isNullable: () => boolean;
238
- _zod: z.core.$ZodAnyInternals;
239
- "~standard": z.core.$ZodStandardSchema<z.ZodAny>;
240
- }, z.core.$strip>]>, z.ZodTransform<string, string | number | boolean | any[] | {
241
- def: unknown;
242
- type: unknown;
243
- _def: unknown;
244
- _output: any;
245
- _input: any;
246
- check: unknown;
247
- clone: unknown;
248
- register: unknown;
249
- brand: unknown;
250
- parse: unknown;
251
- safeParse: unknown;
252
- parseAsync: unknown;
253
- safeParseAsync: unknown;
254
- spa: unknown;
255
- encode: unknown;
256
- decode: unknown;
257
- encodeAsync: unknown;
258
- decodeAsync: unknown;
259
- safeEncode: unknown;
260
- safeDecode: unknown;
261
- safeEncodeAsync: unknown;
262
- safeDecodeAsync: unknown;
263
- refine: unknown;
264
- superRefine: unknown;
265
- overwrite: unknown;
266
- optional: unknown;
267
- nonoptional: unknown;
268
- nullable: unknown;
269
- nullish: unknown;
270
- default: unknown;
271
- prefault: unknown;
272
- array: unknown;
273
- or: unknown;
274
- and: unknown;
275
- transform: unknown;
276
- catch: unknown;
277
- pipe: unknown;
278
- readonly: unknown;
279
- describe: unknown;
280
- description?: unknown;
281
- meta: unknown;
282
- isOptional: unknown;
283
- isNullable: unknown;
284
- _zod: unknown;
285
- "~standard": unknown;
286
- }>>>>>;
36
+ }, z.core.$catchall<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodAny>, z.ZodObject<{}, z.core.$loose>]>>>>;
287
37
  intent: z.ZodObject<{
288
38
  asset: z.ZodOptional<z.ZodObject<{
289
39
  chain_id: z.ZodNumber;
@@ -1,14 +1,13 @@
1
1
  import { z } from "zod";
2
- import { isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSuiAddress, isTronAddress } from "./address";
3
2
  import { ChainId } from "../types/enums";
3
+ import { isBitcoinAddress, isEthereumAddress, isSolanaAddress, isSuiAddress, isTronAddress } from "./address";
4
4
  import { FIAT_CURRENCIES } from "./currencies";
5
5
  const knownKeys = ["items", "refund"];
6
- const customFieldSchema = z
7
- .union([z.string(), z.number(), z.boolean(), z.array(z.any()), z.object(z.any())])
8
- .transform((val) => String(val))
9
- .refine((val) => val.length <= 500, {
10
- message: "Each custom field value must be 500 characters or less",
11
- });
6
+ const customFieldSchema = z.union([z.string(), z.number(), z.boolean(), z.array(z.any()), z.object({}).loose()]).refine((val) => {
7
+ if (typeof val === "string")
8
+ return val.length <= 500;
9
+ return true;
10
+ }, { message: "Each custom field value must be 500 characters or less" });
12
11
  // NOTE: be careful to modify this type only in backward-compatible ways.
13
12
  // Add OPTIONAL fields, etc. Anything else requires a migration.
14
13
  export const zPayOrderMetadata = z
@@ -1,7 +1,7 @@
1
1
  import { FiatCurrency } from "../common/currencies";
2
2
  import { ChainId, ChainType, PayOrderStatus } from "./enums";
3
3
  import { PayOrderEvent } from "./events";
4
- import { Currency, CurrencyAmount, CurrencyBase, CurrencyWithAmount, PaymentData, PayOrderMetadata, QuoteWithCurrency } from "./model";
4
+ import { CurrencyAmount, CurrencyBase, CurrencyWithAmount, PaymentData, PayOrderMetadata, QuoteWithCurrency } from "./model";
5
5
  export type PayOrderParams = {
6
6
  /**
7
7
  * Intent of the order.
@@ -19,29 +19,15 @@ export type PayOrderQuoteParams = {
19
19
  };
20
20
  export type PaymentDetailsParams = {
21
21
  payorder_id: string;
22
- token_address?: string;
23
- chain_id: ChainId;
24
- refund_address: string;
25
- };
22
+ } & ({
23
+ source_currency: CurrencyBase;
24
+ refund_address?: string;
25
+ } | {
26
+ quote_id: string;
27
+ });
26
28
  export type PaymentDetails = {
27
29
  payorder_id: string;
28
30
  status: PayOrderStatus;
29
- /** @deprecated Use `data.expires_at` instead */
30
- expires_at: Date;
31
- /** @deprecated Use `data.refund_address` instead */
32
- refund_address: string;
33
- /** @deprecated Use `data.deposit_address` instead */
34
- deposit_address: string;
35
- /** @deprecated Use `data.receiving_address` instead */
36
- receiving_address: string;
37
- /** @deprecated Use `data.src` instead */
38
- source_currency: Currency;
39
- /** @deprecated Use `data.src.currency_amount` instead */
40
- source_amount: CurrencyAmount;
41
- /** @deprecated Use `data.dst` instead */
42
- destination_currency: Currency;
43
- /** @deprecated Use `data.dst.currency_amount` instead */
44
- destination_amount: CurrencyAmount;
45
31
  data: PaymentData;
46
32
  };
47
33
  export type PayOrderIntent = {
@@ -113,6 +99,13 @@ export type SwapIntent = {
113
99
  export type SwapQuoteRequest = {
114
100
  intent: SwapIntent;
115
101
  };
102
+ export type RouteQuote = QuoteWithBalance & {
103
+ qoute_id: string;
104
+ output: CurrencyWithAmount;
105
+ swap_mode: SwapMode;
106
+ slippage_bps?: number;
107
+ price_impact?: number;
108
+ };
116
109
  export type QuoteWithBalance = QuoteWithCurrency & {
117
110
  balance?: CurrencyAmount;
118
111
  };
@@ -120,14 +113,7 @@ export type SwapDataRequest = SwapQuoteRequest & {
120
113
  receiving_address: string;
121
114
  refund_address: string;
122
115
  };
123
- export type SwapDataResponse = {
124
- src: QuoteWithCurrency;
125
- dst: CurrencyWithAmount;
126
- deposit_address: string;
127
- receiving_address: string;
128
- refund_address: string;
129
- expires_at: string;
130
- };
116
+ export type SwapDataResponse = PaymentDetails;
131
117
  declare enum WsMessageType {
132
118
  Connected = "connected",
133
119
  Subscription = "subscription",
@@ -1,12 +1,14 @@
1
1
  import { ParsedPayOrderMetadata } from "./model";
2
2
  import { Hex } from "./crypto";
3
3
  import { PaymentData } from "./model";
4
+ import { PayOrderStatus } from "./enums";
4
5
  export type PayOrderCreationErrorEvent = {
5
6
  type: "payorder_creation_error";
6
7
  errorMessage: string;
7
8
  };
8
9
  type EventBase = {
9
10
  payorder_id: string;
11
+ status: PayOrderStatus;
10
12
  metadata?: ParsedPayOrderMetadata;
11
13
  };
12
14
  export type PayOrderCreatedEvent = EventBase & {
@@ -13,11 +13,9 @@ export type PayOrder = {
13
13
  fulfillment: FulfillmentData;
14
14
  payment?: PaymentData;
15
15
  };
16
- type MetadataExtraFields = Record<string, string | number | boolean | any[] | {
17
- [x: string]: any;
18
- } | undefined>;
16
+ type MetadataExtraFields = Record<string, unknown>;
19
17
  export type ParsedPayOrderMetadata = z.output<typeof zPayOrderMetadata> & MetadataExtraFields;
20
- export type PayOrderMetadata = z.input<typeof zPayOrderMetadata> & MetadataExtraFields;
18
+ export type PayOrderMetadata = z.infer<typeof zPayOrderMetadata>;
21
19
  export interface Currency extends CurrencyBase {
22
20
  id?: string;
23
21
  name: string;
@@ -82,10 +80,6 @@ export type PaymentData = {
82
80
  deposit_address: string;
83
81
  receiving_address: string;
84
82
  refund_address: string;
85
- source_tx_hash?: string;
86
- destination_tx_hash?: string;
87
- refund_tx_hash?: string;
88
- execution?: ExecutionStep[];
89
83
  expires_at: Date;
90
84
  };
91
85
  export type ExecutionStep = {
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.2.5-beta.1",
4
+ "version": "2.2.5-beta.4",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {